diff mbox series

btrfs: sysfs: accept size suffixes for read policy values

Message ID 8f77c6490a181cb0bb16c6b11131723e46c41108.1737566842.git.anand.jain@oracle.com (mailing list archive)
State New
Headers show
Series btrfs: sysfs: accept size suffixes for read policy values | expand

Commit Message

Anand Jain Jan. 22, 2025, 5:30 p.m. UTC
We now parse human-friendly size values (e.g. '1G', '2M') when setting
read policies.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
Note that only read_policy accepts these suffixed values - show() displays
values without suffixes, consistent with other sysfs knobs like chunk_size.

 fs/btrfs/sysfs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

David Sterba Jan. 27, 2025, 6:08 p.m. UTC | #1
On Thu, Jan 23, 2025 at 01:30:34AM +0800, Anand Jain wrote:
> We now parse human-friendly size values (e.g. '1G', '2M') when setting
> read policies.
> 
> Suggested-by: David Sterba <dsterba@suse.com>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> Note that only read_policy accepts these suffixed values - show() displays
> values without suffixes, consistent with other sysfs knobs like chunk_size.

Yeah, the input format is for convenience, the output in sysfs files
shold be consistent as it's expected to be processed by scripts so the
formatting to suffixed values should be done there if needed.

Reviewed-by: David Sterba <dsterba@suse.com>

> 
>  fs/btrfs/sysfs.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 53b846d99ece..66aac3aae2e9 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -1342,17 +1342,17 @@ int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
>  	/* Separate value from input in policy:value format. */
>  	value_str = strchr(param, ':');
>  	if (value_str) {
> -		int ret;
> +		char *retptr;
>  
>  		*value_str = 0;
>  		value_str++;
>  		if (!value_ret)
>  			return -EINVAL;
> -		ret = kstrtos64(value_str, 10, value_ret);
> -		if (ret)
> +
> +		*value_ret = memparse(value_str, &retptr);
> +		retptr = skip_spaces(retptr);

The other places that do skip_space() have a comment why it's there, so
also add it here.
diff mbox series

Patch

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 53b846d99ece..66aac3aae2e9 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1342,17 +1342,17 @@  int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
 	/* Separate value from input in policy:value format. */
 	value_str = strchr(param, ':');
 	if (value_str) {
-		int ret;
+		char *retptr;
 
 		*value_str = 0;
 		value_str++;
 		if (!value_ret)
 			return -EINVAL;
-		ret = kstrtos64(value_str, 10, value_ret);
-		if (ret)
+
+		*value_ret = memparse(value_str, &retptr);
+		retptr = skip_spaces(retptr);
+		if (*retptr != 0 || *value_ret <= 0)
 			return -EINVAL;
-		if (*value_ret < 0)
-			return -ERANGE;
 	}
 #endif