btrfs: sysfs: handle value associated with read balancing policy

Enable specifying additional configuration values along the RAID1
balancing read policy in a single input string.

Update btrfs_read_policy_to_enum() to parse and handle a value
associated with the policy in the format "policy:value", the value part
if present is converted to 64-bit integer.

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-02 02:06:33 +08:00
committed by David Sterba
parent 38cae63137
commit b6bed20ed3

View File

@@ -1307,15 +1307,34 @@ BTRFS_ATTR(, temp_fsid, btrfs_temp_fsid_show);
static const char * const btrfs_read_policy_name[] = { "pid" };
static int btrfs_read_policy_to_enum(const char *str)
static int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
{
char param[32] = { 0 };
char __maybe_unused *value_str;
if (!str || strlen(str) == 0)
return 0;
strncpy(param, str, sizeof(param) - 1);
#ifdef CONFIG_BTRFS_EXPERIMENTAL
/* Separate value from input in policy:value format. */
value_str = strchr(param, ':');
if (value_str) {
int ret;
*value_str = 0;
value_str++;
if (!value_ret)
return -EINVAL;
ret = kstrtos64(value_str, 10, value_ret);
if (ret)
return -EINVAL;
if (*value_ret < 0)
return -ERANGE;
}
#endif
return sysfs_match_string(btrfs_read_policy_name, param);
}
@@ -1351,8 +1370,9 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj,
{
struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
int index;
s64 value = -1;
index = btrfs_read_policy_to_enum(buf);
index = btrfs_read_policy_to_enum(buf, &value);
if (index < 0)
return -EINVAL;