aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnand Jain <[email protected]>2025-01-29 15:21:46 +0000
committerDavid Sterba <[email protected]>2025-03-18 19:35:48 +0000
commita66b39f699cbd9125c0f248d18fc1381265ee42c (patch)
treedf55212719cb8109d2ee1bd35dc57f822f5e4c84
parentbtrfs: use BTRFS_PATH_AUTO_FREE in load_free_space_tree() (diff)
downloadkernel-a66b39f699cbd9125c0f248d18fc1381265ee42c.tar.gz
kernel-a66b39f699cbd9125c0f248d18fc1381265ee42c.zip
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 <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
-rw-r--r--fs/btrfs/sysfs.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 14f53f757555..974e8a75e3ab 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1342,17 +1342,18 @@ 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);
+ /* There could be any trailing typos after the value. */
+ retptr = skip_spaces(retptr);
+ if (*retptr != 0 || *value_ret <= 0)
return -EINVAL;
- if (*value_ret < 0)
- return -ERANGE;
}
#endif