mirror of
https://github.com/torvalds/linux.git
synced 2026-01-25 15:03:52 +08:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user