DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jerin Jacob <jerinjacobk@gmail.com>
To: David Marchand <david.marchand@redhat.com>
Cc: dpdk-dev <dev@dpdk.org>, Aaron Conole <aconole@redhat.com>,
	 Michael Santana <maicolgabriel@hotmail.com>,
	Bruce Richardson <bruce.richardson@intel.com>,
	 Rasesh Mody <rmody@marvell.com>,
	Shahed Shaikh <shshaikh@marvell.com>,
	 Qiming Yang <qiming.yang@intel.com>,
	Qi Zhang <qi.z.zhang@intel.com>,
	 Heinrich Kuhn <heinrich.kuhn@netronome.com>,
	 Devendra Singh Rawat <dsinghrawat@marvell.com>,
	Igor Russkikh <irusskikh@marvell.com>,
	 Ray Kinsella <mdr@ashroe.eu>,
	Neil Horman <nhorman@tuxdriver.com>,
	 Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	 Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>,
	Dmitry Malloy <dmitrym@microsoft.com>,
	 Pallavi Kadam <pallavi.kadam@intel.com>
Subject: Re: [dpdk-dev] [PATCH 2/2] eal: handle compressed firmwares
Date: Wed, 2 Jun 2021 16:43:12 +0530	[thread overview]
Message-ID: <CALBAE1MmZbpotdLiuVdFSYeyM7hCU7Tw+UYoGHfYT5n6Z6jQrw@mail.gmail.com> (raw)
In-Reply-To: <20210602095836.24901-3-david.marchand@redhat.com>

On Wed, Jun 2, 2021 at 3:29 PM David Marchand <david.marchand@redhat.com> wrote:
>
> Introduce an internal firmware loading helper to remove code duplication
> in our drivers and handle xz compressed firmwares by calling libarchive.
>
> This helper tries to look for .xz suffixes so that drivers are not aware
> the firmwares have been compressed.
>
> libarchive is set as an optional dependency: without libarchive, a
> runtime warning is emitted so that users know there is a compressed
> firmware.
>
> Windows implementation is left as an empty stub.
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

> + */
> +
> +#ifndef __RTE_FIRMWARE_H__
> +#define __RTE_FIRMWARE_H__
> +
> +#include <sys/types.h>
> +
> +#include <rte_compat.h>
> +
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this API may change without prior notice
> + *
> + * Load a firmware in a dynamically allocated buffer, dealing with compressed
> + * files if libarchive is available.
> + *
> + * @param name
> + *      Firmware filename to load.
> + * @param buf

Adding out to express the output useful. i.e
@param[out] buf

> + *      Buffer allocated by this function. If this function succeeds, the
> + *      caller is responsible for freeing the buffer.

I think, we can chnange to "freeing the buffer using free()" to avoid
confusion with rte_free()

> + * @param bufsz

@param[out] bufsz

> + *      Size of the data in the buffer.
> + *
> + * @return
> + *      0 if successful.
> + *      Negative otherwise, buf and bufsize contents are invalid.
> + */
> +__rte_internal
> +int
> +rte_firmware_read(const char *name, void **buf, size_t *bufsz);
> +
> +#endif
> diff --git a/lib/eal/unix/eal_firmware.c b/lib/eal/unix/eal_firmware.c
> new file mode 100644
> index 0000000000..ea66fecfe9
> --- /dev/null
> +++ b/lib/eal/unix/eal_firmware.c
> @@ -0,0 +1,106 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2021 Red Hat, Inc.
> + */
> +
> +#ifdef RTE_HAS_LIBARCHIVE
> +#include <archive.h>
> +#endif
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#include <rte_common.h>
> +#include <rte_firmware.h>
> +#include <rte_log.h>
> +
> +static int
> +firmware_read(const char *name, void **buf, size_t *bufsz)
> +{
> +       const size_t blocksize = 4096;
> +       int ret = -1;
> +       int err;
> +#ifdef RTE_HAS_LIBARCHIVE


I think, better to have small inline functions for libarchive variant
vs normal file accessors
in the group for open, access, read etc to avoid the ifdef clutter and
manage with one ifdef.



> +       struct archive_entry *entry;
> +       struct archive *a;
> +#else
> +       int fd;
> +#endif
> +
> +       *buf = NULL;
> +       *bufsz = 0;
> +
> +#ifdef RTE_HAS_LIBARCHIVE

See above

> +       a = archive_read_new();
> +       if (a == NULL || archive_read_support_format_raw(a) != ARCHIVE_OK ||
> +                       archive_read_support_filter_xz(a) != ARCHIVE_OK ||
> +                       archive_read_open_filename(a, name, blocksize) != ARCHIVE_OK ||
> +                       archive_read_next_header(a, &entry) != ARCHIVE_OK)
> +               goto out;
> +#else
> +       fd = open(name, O_RDONLY);
> +       if (fd < 0)
> +               goto out;
> +#endif
> +
> +       do {
> +               void *tmp;
> +
> +               tmp = realloc(*buf, *bufsz + blocksize);
> +               if (tmp == NULL) {
> +                       free(*buf);
> +                       *buf = NULL;
> +                       *bufsz = 0;
> +                       break;
> +               }
> +               *buf = tmp;
> +
> +#ifdef RTE_HAS_LIBARCHIVE

See above

> +               err = archive_read_data(a, RTE_PTR_ADD(*buf, *bufsz), blocksize);
> +#else
> +               err = read(fd, RTE_PTR_ADD(*buf, *bufsz), blocksize);
> +#endif
> +               if (err < 0) {
> +                       free(*buf);
> +                       *buf = NULL;
> +                       *bufsz = 0;
> +                       break;
> +               }
> +               *bufsz += err;
> +
> +       } while (err != 0);
> +
> +       if (*buf != NULL)
> +               ret = 0;
> +out:
> +#ifdef RTE_HAS_LIBARCHIVE

See above

> +       if (a != NULL)
> +               archive_read_free(a);
> +#else
> +       if (fd >= 0)
> +               close(fd);
> +#endif
> +       return ret;
> +}
> +
> +int
> +rte_firmware_read(const char *name, void **buf, size_t *bufsz)
> +{
> +       char path[PATH_MAX];
> +       int ret;
> +
> +       ret = firmware_read(name, buf, bufsz);
> +       if (ret < 0) {
> +               snprintf(path, sizeof(path), "%s.xz", name);
> +               path[PATH_MAX - 1] = '\0';
> +#ifndef RTE_HAS_LIBARCHIVE

See above

> +               if (access(path, F_OK) == 0) {
> +                       RTE_LOG(WARNING, EAL, "libarchive not available, %s cannot be decompressed\n",
> +                               path);
> +               }
> +#else
> +               ret = firmware_read(path, buf, bufsz);
> +#endif
>

  reply	other threads:[~2021-06-02 11:13 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-02  9:58 [dpdk-dev] [PATCH 0/2] Support " David Marchand
2021-06-02  9:58 ` [dpdk-dev] [PATCH 1/2] net/ice: factorize firmware loading David Marchand
2021-06-02  9:58 ` [dpdk-dev] [PATCH 2/2] eal: handle compressed firmwares David Marchand
2021-06-02 11:13   ` Jerin Jacob [this message]
2021-06-02 15:46     ` David Marchand
2021-06-02 11:30   ` [dpdk-dev] [EXT] " Igor Russkikh
2021-06-02 21:19   ` [dpdk-dev] " Dmitry Kozlyuk
2021-06-03  7:23     ` David Marchand
2021-06-03  7:53       ` David Marchand
2021-06-03  8:14         ` Bruce Richardson
2021-06-02 10:35 ` [dpdk-dev] [EXT] [PATCH 0/2] Support " Igor Russkikh
2021-06-02 11:05   ` David Marchand
2021-06-02 11:23     ` Igor Russkikh
2021-06-03 16:55 ` [dpdk-dev] [PATCH v2 " David Marchand
2021-06-03 16:55   ` [dpdk-dev] [PATCH v2 1/2] net/ice: factorize firmware loading David Marchand
2021-06-28  7:58     ` David Marchand
2021-06-03 16:55   ` [dpdk-dev] [PATCH v2 2/2] eal: handle compressed firmwares David Marchand
2021-06-03 22:29     ` Dmitry Kozlyuk
2021-06-04  7:27       ` David Marchand
2021-06-04 21:40         ` Dmitry Kozlyuk
2021-06-07  9:28           ` David Marchand
2021-06-14 13:17   ` [dpdk-dev] [PATCH v2 0/2] Support " David Marchand
2021-06-29  8:06 ` [dpdk-dev] [PATCH v3 " David Marchand
2021-06-29  8:06   ` [dpdk-dev] [PATCH v3 1/2] net/ice: factorize firmware loading David Marchand
2021-07-05  1:43     ` Wang, Haiyue
2021-07-05  3:33       ` Wang, Haiyue
2021-07-05  7:08       ` David Marchand
2021-07-05  8:02         ` Wang, Haiyue
2021-07-05  8:33           ` David Marchand
2021-07-05  9:59             ` Zhang, Qi Z
2021-07-05 11:46               ` Wang, Haiyue
2021-07-05 11:44             ` Wang, Haiyue
2021-07-05 13:18     ` Wang, Haiyue
2021-07-05 13:34       ` David Marchand
2021-06-29  8:06   ` [dpdk-dev] [PATCH v3 2/2] eal: handle compressed firmwares David Marchand
2021-06-29 12:45     ` Aaron Conole
2021-07-05  6:35     ` Wang, Haiyue
2021-07-05  6:54       ` David Marchand
2021-07-05 13:19     ` Wang, Haiyue
2021-07-06 14:29 ` [dpdk-dev] [PATCH v4 0/2] Support " David Marchand
2021-07-06 14:29   ` [dpdk-dev] [PATCH v4 1/2] net/ice: factorize firmware loading David Marchand
2021-07-06 14:29   ` [dpdk-dev] [PATCH v4 2/2] eal: handle compressed firmwares David Marchand
2021-07-07 12:08 ` [dpdk-dev] [PATCH v5 0/2] Support " David Marchand
2021-07-07 12:08   ` [dpdk-dev] [PATCH v5 1/2] net/ice: factorize firmware loading David Marchand
2021-07-07 12:08   ` [dpdk-dev] [PATCH v5 2/2] eal: handle compressed firmware David Marchand
2021-07-07 15:03   ` [dpdk-dev] [PATCH v5 0/2] Support compressed firmwares David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALBAE1MmZbpotdLiuVdFSYeyM7hCU7Tw+UYoGHfYT5n6Z6jQrw@mail.gmail.com \
    --to=jerinjacobk@gmail.com \
    --cc=aconole@redhat.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=dmitrym@microsoft.com \
    --cc=dsinghrawat@marvell.com \
    --cc=heinrich.kuhn@netronome.com \
    --cc=irusskikh@marvell.com \
    --cc=maicolgabriel@hotmail.com \
    --cc=mdr@ashroe.eu \
    --cc=navasile@linux.microsoft.com \
    --cc=nhorman@tuxdriver.com \
    --cc=pallavi.kadam@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=rmody@marvell.com \
    --cc=shshaikh@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).