From 88438adf02b2eea6f305c20c239df48de10a4bfe Mon Sep 17 00:00:00 2001 From: James Simmons Date: Thu, 12 Dec 2024 08:16:09 -0700 Subject: [PATCH] LU-8066 sysfs: fixup max_dirty_mb Migrate the mdc version of max_dirty_mb to sysfs since its a simple value visible to non-root users. For the osc version update the function with sysfs_memparse(). Change-Id: I1329e7a0848101a1754836832e5c3b76d4db76cc Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57457 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Arshad Hussain Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/mdc/lproc_mdc.c | 43 ++++++++++++++++++------------------------- lustre/osc/lproc_osc.c | 9 ++++----- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c index e5230cb..ac74000 100644 --- a/lustre/mdc/lproc_mdc.c +++ b/lustre/mdc/lproc_mdc.c @@ -135,41 +135,35 @@ LUSTRE_RW_ATTR(max_mod_rpcs_in_flight); LUSTRE_RW_ATTR(max_pages_per_rpc); -static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v) +static ssize_t max_dirty_mb_show(struct kobject *kobj, + struct attribute *attr, + char *buf) { - struct obd_device *obd = m->private; + struct obd_device *obd = container_of(kobj, struct obd_device, + obd_kset.kobj); struct client_obd *cli = &obd->u.cli; - seq_printf(m, "%lu\n", PAGES_TO_MiB(cli->cl_dirty_max_pages)); - return 0; + return scnprintf(buf, PAGE_SIZE, "%lu\n", + PAGES_TO_MiB(cli->cl_dirty_max_pages)); } -static ssize_t mdc_max_dirty_mb_seq_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) +static ssize_t max_dirty_mb_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, + size_t count) { - struct seq_file *sfl = file->private_data; - struct obd_device *obd = sfl->private; + struct obd_device *obd = container_of(kobj, struct obd_device, + obd_kset.kobj); struct client_obd *cli = &obd->u.cli; - char kernbuf[22] = ""; u64 pages_number; int rc; - if (count >= sizeof(kernbuf)) - return -EINVAL; - - if (copy_from_user(kernbuf, buffer, count)) - return -EFAULT; - kernbuf[count] = 0; - - rc = sysfs_memparse(kernbuf, count, &pages_number, "MiB"); - if (rc < 0) + rc = sysfs_memparse(buffer, count, &pages_number, "MiB"); + if (rc) return rc; - /* MB -> pages */ pages_number = round_up(pages_number, 1024 * 1024) >> PAGE_SHIFT; - if (pages_number <= 0 || - pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) || + if (pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) || pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */ return -ERANGE; @@ -180,7 +174,7 @@ static ssize_t mdc_max_dirty_mb_seq_write(struct file *file, return count; } -LPROC_SEQ_FOPS(mdc_max_dirty_mb); +LUSTRE_RW_ATTR(max_dirty_mb); static ssize_t checksums_show(struct kobject *kobj, struct attribute *attr, char *buf) @@ -579,8 +573,6 @@ struct lprocfs_vars lprocfs_mdc_obd_vars[] = { .fops = &mdc_connect_flags_fops }, { .name = "mds_server_uuid", .fops = &mdc_server_uuid_fops }, - { .name = "max_dirty_mb", - .fops = &mdc_max_dirty_mb_fops }, { .name = "mdc_cached_mb", .fops = &mdc_cached_mb_fops }, { .name = "timeouts", @@ -715,6 +707,7 @@ static struct attribute *mdc_attrs[] = { &lustre_attr_max_rpcs_in_flight.attr, &lustre_attr_max_mod_rpcs_in_flight.attr, &lustre_attr_max_pages_per_rpc.attr, + &lustre_attr_max_dirty_mb.attr, &lustre_attr_mds_conn_uuid.attr, &lustre_attr_conn_uuid.attr, &lustre_attr_pinger_recov.attr, diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index 7fe7c7e..e852743 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -139,15 +139,14 @@ static ssize_t max_dirty_mb_store(struct kobject *kobj, struct obd_device *obd = container_of(kobj, struct obd_device, obd_kset.kobj); struct client_obd *cli = &obd->u.cli; - unsigned long pages_number, max_dirty_mb; + u64 pages_number; int rc; - rc = kstrtoul(buffer, 10, &max_dirty_mb); - if (rc) + rc = sysfs_memparse(buffer, count, &pages_number, "MiB"); + if (rc < 0) return rc; - pages_number = MiB_TO_PAGES(max_dirty_mb); - + pages_number = round_up(pages_number, 1024 * 1024) >> PAGE_SHIFT; if (pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) || pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */ return -ERANGE; -- 1.8.3.1