Whamcloud - gitweb
LU-8066 ofd: migrate files out of procfs 42/58742/8
authorJames Simmons <jsimmons@infradead.org>
Wed, 7 May 2025 12:41:55 +0000 (08:41 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 21 May 2025 05:17:24 +0000 (05:17 +0000)
Move all the simple proc files to sysfs. The more complex files
get moved to debugfs.

Change-Id: I357418f795549b238ca3d3e7da217e6d98dad8fb
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58742
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/include/lprocfs_status.h
lustre/obdclass/lprocfs_status_server.c
lustre/ofd/lproc_ofd.c

index 1821c2f..56634f5 100644 (file)
@@ -617,6 +617,8 @@ lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
 extern ssize_t
 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
                                size_t count, loff_t *off);
+ssize_t evict_client_store(struct kobject *kobj, struct attribute *attr,
+                          const char *buffer, size_t count);
 #endif
 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
                   const char *buffer, size_t count);
@@ -661,7 +663,25 @@ unsigned long lprocfs_oh_counter_pcpu(struct obd_hist_pcpu *oh,
 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
                           struct lprocfs_counter *cnt);
 
+/* lprocfs_status.c: dump pages on cksum error */
+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);
 #ifdef HAVE_SERVER_SUPPORT
+ssize_t dt_checksum_type_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf);
+ssize_t dt_checksum_dump_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf);
+ssize_t dt_checksum_dump_store(struct kobject *kobj, struct attribute *attr,
+                              const char *buffer, size_t count);
+#ifdef CONFIG_PROC_FS
+int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
+#endif
+ssize_t
+lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
+                               size_t count, loff_t *off);
+
 /* lprocfs_status.c: recovery status */
 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
 
@@ -678,16 +698,6 @@ ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
                        const char *buffer, size_t count);
 #endif
 
-/* lprocfs_status.c: dump pages on cksum error */
-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);
 
index 07141fb..d64cf14 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <cfs_hash.h>
 #include <obd_class.h>
+#include <obd_cksum.h>
 #include <lprocfs_status.h>
 #include <lustre_nodemap.h>
 
@@ -96,6 +97,29 @@ int lprocfs_recovery_stale_clients_seq_show(struct seq_file *m, void *data)
 }
 EXPORT_SYMBOL(lprocfs_recovery_stale_clients_seq_show);
 
+ssize_t evict_client_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);
+       char *tmpbuf = skip_spaces(buffer);
+
+       tmpbuf = strsep(&tmpbuf, " \t\n\f\v\r");
+       class_incref(obd, __func__, current);
+
+       if (strncmp(tmpbuf, "nid:", 4) == 0)
+               obd_export_evict_by_nid(obd, tmpbuf + 4);
+       else if (strncmp(tmpbuf, "uuid:", 5) == 0)
+               obd_export_evict_by_uuid(obd, tmpbuf + 5);
+       else
+               obd_export_evict_by_uuid(obd, tmpbuf);
+
+       class_decref(obd, __func__, current);
+
+       return count;
+}
+EXPORT_SYMBOL(evict_client_store);
+
 #ifdef CONFIG_PROC_FS
 #define BUFLEN LNET_NIDSTR_SIZE
 
@@ -141,6 +165,7 @@ out:
 EXPORT_SYMBOL(lprocfs_evict_client_seq_write);
 
 #undef BUFLEN
+#endif /* CONFIG_PROC_FS*/
 
 ssize_t eviction_count_show(struct kobject *kobj, struct attribute *attr,
                         char *buf)
@@ -987,6 +1012,7 @@ ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
 }
 EXPORT_SYMBOL(ir_factor_store);
 
+#ifdef CONFIG_PROC_FS
 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
@@ -1015,6 +1041,70 @@ lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
        return count;
 }
 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_write);
+#endif /* CONFIG_PROC_FS */
+
+ssize_t dt_checksum_dump_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf)
+{
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+
+       return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_checksum_dump);
+}
+EXPORT_SYMBOL(dt_checksum_dump_show);
+
+ssize_t dt_checksum_dump_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);
+       bool val;
+       int rc;
+
+       rc = kstrtobool(buffer, &val);
+       if (rc < 0)
+               return rc;
+
+       obd->obd_checksum_dump = val;
+
+       return count;
+}
+EXPORT_SYMBOL(dt_checksum_dump_store);
+
+/*
+ * checksum_type(server) sysfs handling
+ */
+ssize_t dt_checksum_type_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf)
+{
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+       struct lu_target *lut;
+       enum cksum_types pref;
+       int count = 0, i;
+
+       lut = obd2obt(obd)->obt_lut;
+       /* select fastest checksum type on the server */
+       pref = obd_cksum_type_select(obd->obd_name,
+                                    lut->lut_cksum_types_supported,
+                                    lut->lut_dt_conf.ddp_t10_cksum_type);
+
+       for (i = 0; cksum_name[i] != NULL; i++) {
+               if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
+                       continue;
+
+               if (pref == BIT(i))
+                       count += scnprintf(buf + count, PAGE_SIZE, "[%s] ",
+                                          cksum_name[i]);
+               else
+                       count += scnprintf(buf + count, PAGE_SIZE, "%s ",
+                                          cksum_name[i]);
+       }
+       count += scnprintf(buf + count, PAGE_SIZE, "\n");
+
+       return count;
+}
+EXPORT_SYMBOL(dt_checksum_type_show);
 
 ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
                                char *buf)
@@ -1083,5 +1173,3 @@ ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
        return scnprintf(buf, PAGE_SIZE, "%u\n", obd2obt(obd)->obt_instance);
 }
 EXPORT_SYMBOL(instance_show);
-
-#endif /* CONFIG_PROC_FS*/
index c7a27ad..b254a9f 100644 (file)
@@ -187,7 +187,7 @@ LUSTRE_RW_ATTR(atime_diff);
  * \retval             0 on success
  * \retval             negative value on error
  */
-static int ofd_last_id_seq_show(struct seq_file *m, void *data)
+static int last_id_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device       *obd = m->private;
        struct ofd_device       *ofd;
@@ -197,6 +197,8 @@ static int ofd_last_id_seq_show(struct seq_file *m, void *data)
                return 0;
 
        ofd = ofd_dev(obd->obd_lu_dev);
+       if (IS_ERR_OR_NULL(ofd))
+               return -ENODEV;
 
        read_lock(&ofd->ofd_seq_list_lock);
        list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
@@ -212,7 +214,7 @@ static int ofd_last_id_seq_show(struct seq_file *m, void *data)
        return 0;
 }
 
-LPROC_SEQ_FOPS_RO(ofd_last_id);
+LDEBUGFS_SEQ_FOPS_RO(last_id);
 
 /**
  * Show if the OFD is in degraded mode.
@@ -462,34 +464,33 @@ static ssize_t sync_journal_store(struct kobject *kobj, struct attribute *attr,
 }
 LUSTRE_RW_ATTR(sync_journal);
 
-static int ofd_brw_size_seq_show(struct seq_file *m, void *data)
+static ssize_t brw_size_show(struct kobject *kobj, struct attribute *attr,
+                            char *buf)
 {
-       struct obd_device       *obd = m->private;
-       struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+       struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
 
-       seq_printf(m, "%u\n", ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
-       return 0;
+       if (IS_ERR_OR_NULL(ofd))
+               return -ENODEV;
+
+       return  scnprintf(buf, PAGE_SIZE, "%u\n",
+                         ofd->ofd_brw_size / ONE_MB_BRW_SIZE);
 }
 
-static ssize_t
-ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
-                      size_t count, loff_t *off)
+static ssize_t brw_size_store(struct kobject *kobj, struct attribute *attr,
+                             const char *buffer, size_t count)
 {
-       struct seq_file *m = file->private_data;
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
-       char kernbuf[22] = "";
        u64 val;
        int rc;
 
-       if (count >= sizeof(kernbuf))
-               return -EINVAL;
-
-       if (copy_from_user(kernbuf, buffer, count))
-               return -EFAULT;
-       kernbuf[count] = 0;
+       if (IS_ERR_OR_NULL(ofd))
+               return -ENODEV;
 
-       rc = sysfs_memparse(kernbuf, count, &val, "MiB");
+       rc = sysfs_memparse(buffer, count, &val, "MiB");
        if (rc < 0)
                return rc;
 
@@ -506,43 +507,7 @@ ofd_brw_size_seq_write(struct file *file, const char __user *buffer,
 
        return count;
 }
-LPROC_SEQ_FOPS(ofd_brw_size);
-
-/*
- * ofd_checksum_type(server) proc handling
- */
-static int ofd_checksum_type_seq_show(struct seq_file *m, void *data)
-{
-       struct obd_device *obd = m->private;
-       struct lu_target *lut;
-       enum cksum_types pref;
-       int i;
-
-       if (!obd)
-               return 0;
-
-       lut = obd2obt(obd)->obt_lut;
-       /* select fastest checksum type on the server */
-       pref = obd_cksum_type_select(obd->obd_name,
-                                    lut->lut_cksum_types_supported,
-                                    lut->lut_dt_conf.ddp_t10_cksum_type);
-
-       for (i = 0; cksum_name[i] != NULL; i++) {
-               if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
-                       continue;
-
-               if (pref == BIT(i))
-                       seq_printf(m, "[%s] ", cksum_name[i]);
-               else
-                       seq_printf(m, "%s ", cksum_name[i]);
-       }
-       seq_puts(m, "\n");
-
-       return 0;
-}
-
-LPROC_SEQ_FOPS_RO(ofd_checksum_type);
-
+LUSTRE_RW_ATTR(brw_size);
 
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
 static ssize_t sync_on_lock_cancel_show(struct kobject *kobj,
@@ -686,15 +651,18 @@ LUSTRE_RW_ATTR(lfsck_speed_limit);
  * \retval             0 on success
  * \retval             negative value on error
  */
-static int ofd_lfsck_layout_seq_show(struct seq_file *m, void *data)
+static int lfsck_layout_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
        struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
 
+       if (IS_ERR_OR_NULL(ofd))
+               return -ENODEV;
+
        return lfsck_dump(m, ofd->ofd_osd, LFSCK_TYPE_LAYOUT);
 }
 
-LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
+LDEBUGFS_SEQ_FOPS_RO(lfsck_layout);
 
 /**
  * Show if LFSCK performed parent FID verification.
@@ -705,11 +673,14 @@ LPROC_SEQ_FOPS_RO(ofd_lfsck_layout);
  * \retval             0 on success
  * \retval             negative value on error
  */
-static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
+static int lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
        struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
 
+       if (IS_ERR_OR_NULL(ofd))
+               return -ENODEV;
+
        seq_printf(m, "switch: %s\ndetected: %llu\nrepaired: %llu\n",
                   ofd->ofd_lfsck_verify_pfid ? "on" : "off",
                   ofd->ofd_inconsistency_self_detected,
@@ -734,8 +705,8 @@ static int ofd_lfsck_verify_pfid_seq_show(struct seq_file *m, void *data)
  * \retval             negative number on error
  */
 static ssize_t
-ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
-                               size_t count, loff_t *off)
+lfsck_verify_pfid_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;
@@ -743,6 +714,9 @@ ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
        bool val;
        int rc;
 
+       if (IS_ERR_OR_NULL(ofd))
+               return -ENODEV;
+
        rc = kstrtobool_from_user(buffer, count, &val);
        if (rc)
                return rc;
@@ -756,7 +730,7 @@ ofd_lfsck_verify_pfid_seq_write(struct file *file, const char __user *buffer,
        return count;
 }
 
-LPROC_SEQ_FOPS(ofd_lfsck_verify_pfid);
+LDEBUGFS_SEQ_FOPS(lfsck_verify_pfid);
 
 static ssize_t access_log_mask_show(struct kobject *kobj,
                        struct attribute *attr, char *buf)
@@ -857,14 +831,14 @@ static ssize_t access_log_size_store(struct kobject *kobj,
 }
 LUSTRE_RW_ATTR(access_log_size);
 
-static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
+static int site_stats_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *obd = m->private;
 
        return lu_site_stats_seq_print(obd->obd_lu_dev->ld_site, m);
 }
 
-LPROC_SEQ_FOPS_RO(ofd_site_stats);
+LDEBUGFS_SEQ_FOPS_RO(site_stats);
 
 /**
  * Show if the OFD enforces T10PI checksum.
@@ -928,13 +902,13 @@ static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
 }
 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
 
-LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
 LUSTRE_RW_ATTR(recovery_time_hard);
 LUSTRE_RW_ATTR(recovery_time_soft);
 LUSTRE_RW_ATTR(ir_factor);
 
-LPROC_SEQ_FOPS_WR_ONLY(ofd, evict_client);
-LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
+LUSTRE_WO_ATTR(evict_client);
+LUSTRE_ATTR(checksum_dump, 0644, dt_checksum_dump_show, dt_checksum_dump_store);
+LUSTRE_ATTR(checksum_type, 0444, dt_checksum_type_show, NULL);
 LUSTRE_RW_ATTR(job_cleanup_interval);
 
 LUSTRE_RO_ATTR(tot_dirty);
@@ -947,33 +921,22 @@ LUSTRE_RO_ATTR(num_exports);
 LUSTRE_RW_ATTR(grant_check_threshold);
 LUSTRE_RO_ATTR(eviction_count);
 
-struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
+LDEBUGFS_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
+LDEBUGFS_SEQ_FOPS_RO_TYPE(ofd, recovery_stale_clients);
+
+static struct ldebugfs_vars ldebugfs_ofd_obd_vars[] = {
        { .name =       "last_id",
-         .fops =       &ofd_last_id_fops               },
-       { .name =       "recovery_status",
-         .fops =       &ofd_recovery_status_fops       },
-       { .name =       "evict_client",
-         .fops =       &ofd_evict_client_fops          },
-       { .name =       "brw_size",
-         .fops =       &ofd_brw_size_fops              },
-       { .name =       "checksum_dump",
-         .fops =       &ofd_checksum_dump_fops         },
+         .fops =       &last_id_fops                   },
        { .name =       "lfsck_layout",
-         .fops =       &ofd_lfsck_layout_fops          },
+         .fops =       &lfsck_layout_fops              },
        { .name =       "lfsck_verify_pfid",
-         .fops =       &ofd_lfsck_verify_pfid_fops     },
-       { .name =       "site_stats",
-         .fops =       &ofd_site_stats_fops            },
-       { .name =       "checksum_type",
-         .fops =       &ofd_checksum_type_fops         },
-       { NULL }
-};
-
-LDEBUGFS_SEQ_FOPS_RO_TYPE(ofd, recovery_stale_clients);
-
-struct ldebugfs_vars ldebugfs_ofd_obd_vars[] = {
+         .fops =       &lfsck_verify_pfid_fops },
+       { .name =       "recovery_status",
+         .fops =       &ofd_recovery_status_fops       },
        { .name =       "recovery_stale_clients",
          .fops =       &ofd_recovery_stale_clients_fops},
+       { .name =       "site_stats",
+         .fops =       &site_stats_fops                },
        { NULL }
 };
 
@@ -1040,8 +1003,12 @@ static struct attribute *ofd_attrs[] = {
        &lustre_attr_access_log_mask.attr,
        &lustre_attr_access_log_size.attr,
        &lustre_attr_atime_diff.attr,
+       &lustre_attr_brw_size.attr,
+       &lustre_attr_checksum_dump.attr,
        &lustre_attr_checksum_t10pi_enforce.attr,
+       &lustre_attr_checksum_type.attr,
        &lustre_attr_degraded.attr,
+       &lustre_attr_evict_client.attr,
        &lustre_attr_eviction_count.attr,
        &lustre_attr_fstype.attr,
        &lustre_attr_grant_check_threshold.attr,
@@ -1096,7 +1063,6 @@ int ofd_tunables_init(struct ofd_device *ofd)
         */
        obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(ofd);
        obd->obd_debugfs_vars = ldebugfs_ofd_obd_vars;
-       obd->obd_vars = lprocfs_ofd_obd_vars;
        rc = lprocfs_obd_setup(obd, false);
        if (rc) {
                CERROR("%s: lprocfs_obd_setup failed: %d.\n",