btrfs: sysfs: accept size suffixes for read policy values

We now parse human-friendly size values (e.g. '1G', '2M') when setting
read policies.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Anand Jain 2025-01-29 23:21:46 +08:00 committed by David Sterba
parent 19eaf5fd8c
commit a66b39f699
1 changed files with 6 additions and 5 deletions

View File

@ -1342,17 +1342,18 @@ int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
/* Separate value from input in policy:value format. */ /* Separate value from input in policy:value format. */
value_str = strchr(param, ':'); value_str = strchr(param, ':');
if (value_str) { if (value_str) {
int ret; char *retptr;
*value_str = 0; *value_str = 0;
value_str++; value_str++;
if (!value_ret) if (!value_ret)
return -EINVAL; return -EINVAL;
ret = kstrtos64(value_str, 10, value_ret);
if (ret) *value_ret = memparse(value_str, &retptr);
/* There could be any trailing typos after the value. */
retptr = skip_spaces(retptr);
if (*retptr != 0 || *value_ret <= 0)
return -EINVAL; return -EINVAL;
if (*value_ret < 0)
return -ERANGE;
} }
#endif #endif