From: James Simmons Date: Mon, 14 Oct 2024 15:31:34 +0000 (-0400) Subject: LU-8066 sysfs: migrate checksum_type to sys/fs tree X-Git-Tag: 2.16.51~59 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=908417ce209f51b8f17475f304bcf5b2bafcb7b8;p=fs%2Flustre-release.git LU-8066 sysfs: migrate checksum_type to sys/fs tree The checksum_type file is simple so the logical place is sys/fs which is accessible to everyone. This more complex file is one of thew few allowed in the general sysfs tree. Change-Id: I6ce89416ef64058f911e18a3f743944f0a6a8f4e Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56667 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index f7b9f6d..ff905d0 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -685,6 +685,10 @@ int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data); ssize_t lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer, size_t count, loff_t *off); +ssize_t checksum_type_show(struct kobject *kobj, struct attribute *attr, + char *buf); +ssize_t checksum_type_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count); extern int lprocfs_single_release(struct inode *i, struct file *f); extern int lprocfs_seq_release(struct inode *i, struct file *f); diff --git a/lustre/include/obd_cksum.h b/lustre/include/obd_cksum.h index 9301f66..6862b14 100644 --- a/lustre/include/obd_cksum.h +++ b/lustre/include/obd_cksum.h @@ -116,9 +116,9 @@ enum cksum_types obd_cksum_type_select(const char *obd_name, } /* Checksum algorithm names. Must be defined in the same order as the - * OBD_CKSUM_* flags. */ -#define DECLARE_CKSUM_NAME const char *const cksum_name[] = {"crc32", "adler", \ - "crc32c", "reserved", "t10ip512", "t10ip4K", "t10crc512", "t10crc4K"} + * OBD_CKSUM_* flags. + */ +extern const char *const cksum_name[]; typedef __be16 (obd_dif_csum_fn) (void *, unsigned int); diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c index 035ff6b..75a4c75 100644 --- a/lustre/mdc/lproc_mdc.c +++ b/lustre/mdc/lproc_mdc.c @@ -182,69 +182,6 @@ static ssize_t mdc_max_dirty_mb_seq_write(struct file *file, } LPROC_SEQ_FOPS(mdc_max_dirty_mb); -DECLARE_CKSUM_NAME; - -static int mdc_checksum_type_seq_show(struct seq_file *m, void *v) -{ - struct obd_device *obd = m->private; - int i; - - if (obd == NULL) - return 0; - - for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { - if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0) - continue; - if (obd->u.cli.cl_cksum_type == BIT(i)) - seq_printf(m, "[%s] ", cksum_name[i]); - else - seq_printf(m, "%s ", cksum_name[i]); - } - seq_puts(m, "\n"); - - return 0; -} - -static ssize_t mdc_checksum_type_seq_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) -{ - struct seq_file *m = file->private_data; - struct obd_device *obd = m->private; - char kernbuf[10]; - int rc = -EINVAL; - int i; - - if (obd == NULL) - return 0; - - if (count > sizeof(kernbuf) - 1) - return -EINVAL; - if (copy_from_user(kernbuf, buffer, count)) - return -EFAULT; - - if (count > 0 && kernbuf[count - 1] == '\n') - kernbuf[count - 1] = '\0'; - else - kernbuf[count] = '\0'; - - for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { - if (strcasecmp(kernbuf, cksum_name[i]) == 0) { - obd->u.cli.cl_preferred_cksum_type = BIT(i); - if (obd->u.cli.cl_supp_cksum_types & BIT(i)) { - obd->u.cli.cl_cksum_type = BIT(i); - rc = count; - } else { - rc = -EOPNOTSUPP; - } - break; - } - } - - return rc; -} -LPROC_SEQ_FOPS(mdc_checksum_type); - static ssize_t checksums_show(struct kobject *kobj, struct attribute *attr, char *buf) { @@ -274,6 +211,8 @@ static ssize_t checksums_store(struct kobject *kobj, } LUSTRE_RW_ATTR(checksums); +LUSTRE_RW_ATTR(checksum_type); + static ssize_t checksum_dump_show(struct kobject *kobj, struct attribute *attr, char *buf) { @@ -644,8 +583,6 @@ struct lprocfs_vars lprocfs_mdc_obd_vars[] = { .fops = &mdc_max_dirty_mb_fops }, { .name = "mdc_cached_mb", .fops = &mdc_cached_mb_fops }, - { .name = "checksum_type", - .fops = &mdc_checksum_type_fops }, { .name = "timeouts", .fops = &mdc_timeouts_fops }, { .name = "import", @@ -777,6 +714,7 @@ LUSTRE_OBD_UINT_PARAM_ATTR(at_unhealthy_factor); static struct attribute *mdc_attrs[] = { &lustre_attr_active.attr, &lustre_attr_checksums.attr, + &lustre_attr_checksum_type.attr, &lustre_attr_checksum_dump.attr, &lustre_attr_max_rpcs_in_flight.attr, &lustre_attr_max_mod_rpcs_in_flight.attr, diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index 953badb..21f5ed2 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -52,6 +52,7 @@ #include /* struct obd_device */ #include +#include #include #include #include @@ -1279,8 +1280,6 @@ LUSTRE_RW_ATTR(max_mod_rpcs_in_flight); /* * mdt_checksum_type(server) proc handling */ -DECLARE_CKSUM_NAME; - static int mdt_checksum_type_seq_show(struct seq_file *m, void *data) { struct obd_device *obd = m->private; @@ -1297,7 +1296,7 @@ static int mdt_checksum_type_seq_show(struct seq_file *m, void *data) lut->lut_cksum_types_supported, lut->lut_dt_conf.ddp_t10_cksum_type); - for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { + for (i = 0; cksum_name[i] != NULL; i++) { if ((BIT(i) & lut->lut_cksum_types_supported) == 0) continue; diff --git a/lustre/obdclass/integrity.c b/lustre/obdclass/integrity.c index 54906b8..9d2b06d 100644 --- a/lustre/obdclass/integrity.c +++ b/lustre/obdclass/integrity.c @@ -183,8 +183,6 @@ obd_t10_cksum2type(enum cksum_types cksum_type) static const char *obd_t10_cksum_name(enum obd_t10_cksum_type index) { - DECLARE_CKSUM_NAME; - /* Need to skip "crc32", "adler", "crc32c", "reserved" */ return cksum_name[3 + index]; } diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index ce38c21..fec1007 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -2559,6 +2559,66 @@ out: } EXPORT_SYMBOL(short_io_bytes_store); +const char *const cksum_name[] = { + "crc32", "adler", "crc32c", "reserved", "t10ip512", "t10ip4K", + "t10crc512", "t10crc4K", NULL +}; +EXPORT_SYMBOL(cksum_name); + +ssize_t checksum_type_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct obd_device *obd = container_of(kobj, struct obd_device, + obd_kset.kobj); + ssize_t len = 0; + int i; + + if (!obd) + return 0; + + for (i = 0; cksum_name[i] != NULL; i++) { + if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0) + continue; + if (obd->u.cli.cl_cksum_type == BIT(i)) + len += scnprintf(buf + len, PAGE_SIZE, "[%s] ", + cksum_name[i]); + else + len += scnprintf(buf + len, PAGE_SIZE, "%s ", + cksum_name[i]); + } + len += scnprintf(buf + len, PAGE_SIZE, "\n"); + + return len; +} +EXPORT_SYMBOL(checksum_type_show); + +ssize_t checksum_type_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) +{ + struct obd_device *obd = container_of(kobj, struct obd_device, + obd_kset.kobj); + int rc = -EINVAL; + int i; + + if (!obd) + return 0; + + for (i = 0; cksum_name[i] != NULL; i++) { + if (strcasecmp(buffer, cksum_name[i]) == 0) { + obd->u.cli.cl_preferred_cksum_type = BIT(i); + if (obd->u.cli.cl_supp_cksum_types & BIT(i)) { + obd->u.cli.cl_cksum_type = BIT(i); + rc = count; + } else { + rc = -EOPNOTSUPP; + } + break; + } + } + return rc; +} +EXPORT_SYMBOL(checksum_type_store); + int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count, struct root_squash_info *squash, char *name) { diff --git a/lustre/ofd/lproc_ofd.c b/lustre/ofd/lproc_ofd.c index 15b4934..2ad183b 100644 --- a/lustre/ofd/lproc_ofd.c +++ b/lustre/ofd/lproc_ofd.c @@ -531,8 +531,6 @@ LPROC_SEQ_FOPS(ofd_brw_size); /* * ofd_checksum_type(server) proc handling */ -DECLARE_CKSUM_NAME; - static int ofd_checksum_type_seq_show(struct seq_file *m, void *data) { struct obd_device *obd = m->private; @@ -549,7 +547,7 @@ static int ofd_checksum_type_seq_show(struct seq_file *m, void *data) lut->lut_cksum_types_supported, lut->lut_dt_conf.ddp_t10_cksum_type); - for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { + for (i = 0; cksum_name[i] != NULL; i++) { if ((BIT(i) & lut->lut_cksum_types_supported) == 0) continue; diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index f5a829c..7fe7c7e 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -453,67 +453,7 @@ static ssize_t checksums_store(struct kobject *kobj, } LUSTRE_RW_ATTR(checksums); -DECLARE_CKSUM_NAME; - -static int osc_checksum_type_seq_show(struct seq_file *m, void *v) -{ - struct obd_device *obd = m->private; - int i; - - if (obd == NULL) - return 0; - - for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { - if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0) - continue; - if (obd->u.cli.cl_cksum_type == BIT(i)) - seq_printf(m, "[%s] ", cksum_name[i]); - else - seq_printf(m, "%s ", cksum_name[i]); - } - seq_puts(m, "\n"); - - return 0; -} - -static ssize_t osc_checksum_type_seq_write(struct file *file, - const char __user *buffer, - size_t count, loff_t *off) -{ - struct seq_file *m = file->private_data; - struct obd_device *obd = m->private; - char kernbuf[10]; - int rc = -EINVAL; - int i; - - if (obd == NULL) - return 0; - - if (count > sizeof(kernbuf) - 1) - return -EINVAL; - if (copy_from_user(kernbuf, buffer, count)) - return -EFAULT; - - if (count > 0 && kernbuf[count - 1] == '\n') - kernbuf[count - 1] = '\0'; - else - kernbuf[count] = '\0'; - - for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { - if (strcasecmp(kernbuf, cksum_name[i]) == 0) { - obd->u.cli.cl_preferred_cksum_type = BIT(i); - if (obd->u.cli.cl_supp_cksum_types & BIT(i)) { - obd->u.cli.cl_cksum_type = BIT(i); - rc = count; - } else { - rc = -EOPNOTSUPP; - } - break; - } - } - return rc; -} -LPROC_SEQ_FOPS(osc_checksum_type); +LUSTRE_RW_ATTR(checksum_type); static ssize_t resend_count_show(struct kobject *kobj, struct attribute *attr, @@ -746,8 +686,6 @@ struct lprocfs_vars lprocfs_osc_obd_vars[] = { .fops = &osc_unevict_cached_mb_fops }, { .name = "cur_grant_bytes", .fops = &osc_cur_grant_bytes_fops }, - { .name = "checksum_type", - .fops = &osc_checksum_type_fops }, { .name = "timeouts", .fops = &osc_timeouts_fops }, { .name = "import", @@ -928,6 +866,7 @@ static struct attribute *osc_attrs[] = { &lustre_attr_active.attr, &lustre_attr_enable_page_cache_shrink.attr, &lustre_attr_checksums.attr, + &lustre_attr_checksum_type.attr, &lustre_attr_checksum_dump.attr, &lustre_attr_cur_dirty_bytes.attr, &lustre_attr_cur_lost_grant_bytes.attr,