On Tue, Feb 08, 2022 at 10:54:03PM -0800, Stephen Hemminger wrote:
> Both Linux and FreeBSD have same code for creating runtime
> directory and reading sysfs files. Put them in the new lib/eal/unix
> subdirectory.
> 
> Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
LGTM, apart from one minor nit inline below.

Acked-by: Bruce Richardson <bruce.richard...@intel.com>

> ---
>  lib/eal/freebsd/eal.c         |  88 ---------------------------
>  lib/eal/linux/eal.c           |  90 ----------------------------
>  lib/eal/unix/eal_filesystem.c | 110 ++++++++++++++++++++++++++++++++++
>  lib/eal/unix/meson.build      |   1 +
>  4 files changed, 111 insertions(+), 178 deletions(-)
>  create mode 100644 lib/eal/unix/eal_filesystem.c
> 
<snip>
> +
> +     /* create the path if it doesn't exist. no "mkdir -p" here, so do it
> +      * step by step.
> +      */
> +     ret = mkdir(tmp, 0700);
> +     if (ret < 0 && errno != EEXIST) {
> +             RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
> +                     tmp, strerror(errno));
> +             return -1;
> +     }
> +
> +     ret = mkdir(run_dir, 0700);
> +     if (ret < 0 && errno != EEXIST) {
> +             RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
> +                     run_dir, strerror(errno));
> +             return -1;
> +     }
> +
> +     if (eal_set_runtime_dir(run_dir))
> +             return -1;
> +
> +     return 0;
> +}

Missing a blank line here between the two functions.

> +/* parse a sysfs (or other) file containing one integer value */
> +int
> +eal_parse_sysfs_value(const char *filename, unsigned long *val)
> +{
> +     FILE *f;
> +     char buf[BUFSIZ];
> +     char *end = NULL;
> +
> +     if ((f = fopen(filename, "r")) == NULL) {
> +             RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> +                     __func__, filename);
> +             return -1;
> +     }
> +
> +     if (fgets(buf, sizeof(buf), f) == NULL) {
> +             RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> +                     __func__, filename);
> +             fclose(f);
> +             return -1;
> +     }
> +     *val = strtoul(buf, &end, 0);
> +     if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> +             RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
> +                             __func__, filename);
> +             fclose(f);
> +             return -1;
> +     }
> +     fclose(f);
> +     return 0;
> +}
> diff --git a/lib/eal/unix/meson.build b/lib/eal/unix/meson.build
> index e3ecd3e956b2..a22ea7cabc46 100644
> --- a/lib/eal/unix/meson.build
> +++ b/lib/eal/unix/meson.build
> @@ -6,5 +6,6 @@ sources += files(
>          'eal_unix_memory.c',
>          'eal_unix_timer.c',
>          'eal_firmware.c',
> +        'eal_filesystem.c',
>          'rte_thread.c',
>  )
> -- 
> 2.34.1
> 

Reply via email to