On Wed, Apr 09, 2025 at 02:29:13PM -0400, Stefan Hajnoczi wrote:
> Populate the pdiscard_alignment block limit so the block layer is able
> align discard requests correctly.
> 
> Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com>
> ---
>  block/file-posix.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 55 insertions(+), 1 deletion(-)
> 
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 56d1972d15..2a1e1f48c0 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -1276,10 +1276,10 @@ static int get_sysfs_zoned_model(struct stat *st, 
> BlockZoneModel *zoned)
>  }
>  #endif /* defined(CONFIG_BLKZONED) */
>  
> +#ifdef CONFIG_LINUX
>  /*
>   * Get a sysfs attribute value as a long integer.
>   */
> -#ifdef CONFIG_LINUX
>  static long get_sysfs_long_val(struct stat *st, const char *attribute)

Random change to pull the comment inside of the #if, but tangentially
related so I don't mind keeping it here.

>  {
>      g_autofree char *str = NULL;
> @@ -1299,6 +1299,30 @@ static long get_sysfs_long_val(struct stat *st, const 
> char *attribute)
>      }
>      return ret;
>  }
> +
> +/*
> + * Get a sysfs attribute value as a uint32_t.
> + */
> +static int get_sysfs_u32_val(struct stat *st, const char *attribute,
> +                             uint32_t *u32)
> +{
> +    g_autofree char *str = NULL;
> +    const char *end;
> +    unsigned int val;
> +    int ret;
> +
> +    ret = get_sysfs_str_val(st, attribute, &str);
> +    if (ret < 0) {
> +        return ret;
> +    }
> +
> +    /* The file is ended with '\n', pass 'end' to accept that. */
> +    ret = qemu_strtoui(str, &end, 10, &val);
> +    if (ret == 0 && end && *end == '\0') {
> +        *u32 = val;
> +    }
> +    return ret;
> +}
>  #endif

May be worth amending this line to "#endif /* CONFIG_LINUX */" now
that it is further from the opening #if.

Reviewed-by: Eric Blake <ebl...@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to