btrfs: enable RAID1 balancing configuration via modprobe parameter

This update allows configuring the `raid1-balancing` methods using a
modprobe parameter when experimental mode CONFIG_BTRFS_EXPERIMENTAL
is enabled.

Examples:

- Set the RAID1 balancing method to round-robin with a custom
`min_contiguous_read` of 192k:
  $ modprobe btrfs raid1-balancing=round-robin:196608

- Set the round-robin balancing method with the default
`min_contiguous_read` of 256k:
  $ modprobe btrfs raid1-balancing=round-robin

- Set the `devid` balancing method, defaulting to the latest
device:
  $ modprobe btrfs raid1-balancing=devid

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Anand Jain 2024-12-17 02:13:16 +08:00 committed by David Sterba
parent e2f11776f9
commit e51f52e1d3
4 changed files with 41 additions and 2 deletions

View File

@ -2527,6 +2527,11 @@ static const struct init_sequence mod_init_seq[] = {
}, {
.init_func = extent_map_init,
.exit_func = extent_map_exit,
#ifdef CONFIG_BTRFS_EXPERIMENTAL
}, {
.init_func = btrfs_raid1_balancing_init,
.exit_func = NULL,
#endif
}, {
.init_func = ordered_data_init,
.exit_func = ordered_data_exit,

View File

@ -1313,7 +1313,21 @@ static const char *btrfs_read_policy_name[] = {
#endif
};
static int btrfs_read_policy_to_enum(const char *str, s64 *value)
#ifdef CONFIG_BTRFS_EXPERIMENTAL
/* Global module configuration parameters */
static char *raid1_balancing;
char *btrfs_get_raid1_balancing(void)
{
return raid1_balancing;
}
/* Set perm 0, disable sys/module/btrfs/parameter/raid1_balancing interface */
module_param(raid1_balancing, charp, 0);
MODULE_PARM_DESC(raid1_balancing,
"Global read policy; pid (default), round-robin:[min_contiguous_read], devid:[[devid]|[latest-gen]|[oldest-gen]]");
#endif
int btrfs_read_policy_to_enum(const char *str, s64 *value)
{
char param[32] = {'\0'};
char *__maybe_unused value_str;
@ -1348,6 +1362,18 @@ static int btrfs_read_policy_to_enum(const char *str, s64 *value)
return -EINVAL;
}
#ifdef CONFIG_BTRFS_EXPERIMENTAL
int __init btrfs_raid1_balancing_init(void)
{
if (btrfs_read_policy_to_enum(raid1_balancing, NULL) == -EINVAL) {
btrfs_err(NULL, "Invalid raid1_balancing %s", raid1_balancing);
return -EINVAL;
}
return 0;
}
#endif
static ssize_t btrfs_read_policy_show(struct kobject *kobj,
struct kobj_attribute *a, char *buf)
{

View File

@ -47,5 +47,10 @@ void btrfs_sysfs_del_qgroups(struct btrfs_fs_info *fs_info);
int btrfs_sysfs_add_qgroups(struct btrfs_fs_info *fs_info);
void btrfs_sysfs_del_one_qgroup(struct btrfs_fs_info *fs_info,
struct btrfs_qgroup *qgroup);
int btrfs_read_policy_to_enum(const char *str, s64 *value);
#ifdef CONFIG_BTRFS_EXPERIMENTAL
int __init btrfs_raid1_balancing_init(void);
char *btrfs_get_raid1_balancing(void);
#endif
#endif

View File

@ -1328,10 +1328,13 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
fs_devices->latest_dev = latest_dev;
fs_devices->total_rw_bytes = 0;
fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR;
fs_devices->read_policy = BTRFS_READ_POLICY_PID;
#ifdef CONFIG_BTRFS_EXPERIMENTAL
fs_devices->rr_min_contiguous_read = BTRFS_DEFAULT_RR_MIN_CONTIGUOUS_READ;
fs_devices->read_devid = latest_dev->devid;
fs_devices->read_policy =
btrfs_read_policy_to_enum(btrfs_get_raid1_balancing(), NULL);
#else
fs_devices->read_policy = BTRFS_READ_POLICY_PID;
#endif
return 0;