Whamcloud - gitweb
LU-8066 ldlm: move debugfs entries to general sysfs 87/58087/3
authorJames Simmons <jsimmons@infradead.org>
Fri, 14 Feb 2025 16:05:20 +0000 (11:05 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 28 Feb 2025 08:15:18 +0000 (08:15 +0000)
Any simple debugfs files in the top ldlm directory should be
moved to /sys/fs/lustre/ldlm. This ensures these files will
always be available which is not the case for debugfs.

Change-Id: I851923894d8b6c594056d71a891364d5f54988a1
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58087
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/ldlm/ldlm_internal.h
lustre/ldlm/ldlm_lockd.c
lustre/ldlm/ldlm_resource.c

index 4b7a7ec..811475d 100644 (file)
@@ -378,12 +378,13 @@ void ldlm_flock_policy_local_to_wire(const union ldlm_policy_data *lpolicy,
 
 /* ldlm_reclaim.c */
 #ifdef HAVE_SERVER_SUPPORT
-extern __u64 ldlm_reclaim_threshold;
-extern __u64 ldlm_lock_limit;
-extern __u64 ldlm_reclaim_threshold_mb;
-extern __u64 ldlm_lock_limit_mb;
+extern u64 ldlm_reclaim_threshold;
+extern u64 ldlm_lock_limit;
+extern u64 ldlm_reclaim_threshold_mb;
+extern u64 ldlm_lock_limit_mb;
 extern struct percpu_counter ldlm_granted_total;
 #endif
+extern unsigned int ldlm_dump_granted_max;
 int ldlm_reclaim_setup(void);
 void ldlm_reclaim_cleanup(void);
 void ldlm_reclaim_add(struct ldlm_lock *lock);
index 498cb87..809ce3e 100644 (file)
@@ -3226,11 +3226,38 @@ void ldlm_destroy_export(struct obd_export *exp)
 }
 EXPORT_SYMBOL(ldlm_destroy_export);
 
+static ssize_t dump_granted_max_show(struct kobject *kobj,
+                                    struct attribute *attr,
+                                    char *buf)
+{
+       return scnprintf(buf, PAGE_SIZE, "%u\n",
+                        ldlm_dump_granted_max);
+}
+
+static ssize_t dump_granted_max_store(struct kobject *kobj,
+                                     struct attribute *attr,
+                                     const char *buffer,
+                                     size_t count)
+{
+       unsigned int val;
+       int rc;
+
+       rc = kstrtouint(buffer, 10, &val);
+       if (rc)
+               return rc;
+
+       ldlm_dump_granted_max = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(dump_granted_max);
+
 static ssize_t cancel_unused_locks_before_replay_show(struct kobject *kobj,
                                                      struct attribute *attr,
                                                      char *buf)
 {
-       return sprintf(buf, "%d\n", ldlm_cancel_unused_locks_before_replay);
+       return scnprintf(buf, PAGE_SIZE, "%d\n",
+                        ldlm_cancel_unused_locks_before_replay);
 }
 
 static ssize_t cancel_unused_locks_before_replay_store(struct kobject *kobj,
@@ -3251,8 +3278,110 @@ static ssize_t cancel_unused_locks_before_replay_store(struct kobject *kobj,
 }
 LUSTRE_RW_ATTR(cancel_unused_locks_before_replay);
 
+#ifdef HAVE_SERVER_SUPPORT
+static ssize_t lock_reclaim_threshold_mb_show(struct kobject *kobj,
+                                             struct attribute *attr,
+                                             char *buf)
+{
+       return scnprintf(buf, PAGE_SIZE, "%llu\n", ldlm_reclaim_threshold_mb);
+}
+
+static ssize_t lock_reclaim_threshold_mb_store(struct kobject *kobj,
+                                              struct attribute *attr,
+                                              const char *buffer,
+                                              size_t count)
+{
+       u64 watermark, value;
+       int rc;
+
+       rc = sysfs_memparse(buffer, count, &value, "MiB");
+       if (rc < 0) {
+               CERROR("Failed to set lock_reclaim_threshold_mb, rc = %d.\n",
+                      rc);
+               return rc;
+       } else if (value != 0 && value < (1 << 20)) {
+               CERROR("lock_reclaim_threshold_mb should be greater than 1MB.\n");
+               return -EINVAL;
+       }
+       watermark = value >> 20;
+
+       ldlm_reclaim_threshold_mb = watermark;
+       if (watermark != 0) {
+               watermark <<= 20;
+               do_div(watermark, sizeof(struct ldlm_lock));
+       }
+       ldlm_reclaim_threshold = watermark;
+
+       return count;
+}
+LUSTRE_RW_ATTR(lock_reclaim_threshold_mb);
+
+static ssize_t lock_limit_mb_show(struct kobject *kobj,
+                                 struct attribute *attr,
+                                 char *buf)
+{
+       return scnprintf(buf, PAGE_SIZE, "%llu\n", ldlm_lock_limit_mb);
+}
+
+static ssize_t lock_limit_mb_store(struct kobject *kobj,
+                                  struct attribute *attr,
+                                  const char *buffer,
+                                  size_t count)
+{
+       u64 watermark, value;
+       int rc;
+
+       rc = sysfs_memparse(buffer, count, &value, "MiB");
+       if (rc < 0) {
+               CERROR("Failed to set lock_limit_mb, rc = %d.\n", rc);
+               return rc;
+       } else if (value != 0 && value < (1 << 20)) {
+               CERROR("lock_limit_mb should be greater than 1MB.\n");
+               return -EINVAL;
+       }
+       watermark = value >> 20;
+
+       if (ldlm_lock_limit_mb != 0 && watermark > ldlm_lock_limit_mb) {
+               CERROR("lock_reclaim_threshold_mb must be smaller than lock_limit_mb.\n");
+               return -EINVAL;
+       }
+
+       if (ldlm_reclaim_threshold_mb != 0 &&
+           watermark < ldlm_reclaim_threshold_mb) {
+               CERROR("lock_limit_mb must be greater than lock_reclaim_threshold_mb.\n");
+               return -EINVAL;
+       }
+
+       ldlm_lock_limit_mb = watermark;
+       if (watermark != 0) {
+               watermark <<= 20;
+               do_div(watermark, sizeof(struct ldlm_lock));
+       }
+       ldlm_lock_limit = watermark;
+
+       return count;
+}
+LUSTRE_RW_ATTR(lock_limit_mb);
+
+static ssize_t lock_granted_count_show(struct kobject *kobj,
+                                      struct attribute *attr,
+                                      char *buf)
+{
+       u64 sum = percpu_counter_sum_positive(&ldlm_granted_total);
+
+       return scnprintf(buf, PAGE_SIZE, "%llu\n", sum);
+}
+LUSTRE_RO_ATTR(lock_granted_count);
+#endif
+
 static struct attribute *ldlm_attrs[] = {
+       &lustre_attr_dump_granted_max.attr,
        &lustre_attr_cancel_unused_locks_before_replay.attr,
+#ifdef HAVE_SERVER_SUPPORT
+       &lustre_attr_lock_reclaim_threshold_mb.attr,
+       &lustre_attr_lock_limit_mb.attr,
+       &lustre_attr_lock_granted_count.attr,
+#endif
        NULL,
 };
 
index 017f8a5..f471fac 100644 (file)
@@ -44,7 +44,7 @@ static struct dentry *ldlm_ns_debugfs_dir;
 struct dentry *ldlm_svc_debugfs_dir;
 
 /* For debug dump, amount of granted locks for one resource to avoid DDOS. */
-static unsigned int ldlm_dump_granted_max = 256;
+unsigned int ldlm_dump_granted_max = 256;
 
 static ssize_t ldebugfs_dump_ns_seq_write(struct file *file,
                                          const char __user *buffer,
@@ -57,152 +57,10 @@ static ssize_t ldebugfs_dump_ns_seq_write(struct file *file,
 
 LDEBUGFS_FOPS_WR_ONLY(ldlm, dump_ns);
 
-static int ldlm_rw_uint_seq_show(struct seq_file *m, void *v)
-{
-       seq_printf(m, "%u\n", *(unsigned int *)m->private);
-       return 0;
-}
-
-static ssize_t
-ldlm_rw_uint_seq_write(struct file *file, const char __user *buffer,
-                      size_t count, loff_t *off)
-{
-       struct seq_file *seq = file->private_data;
-
-       if (!count)
-               return 0;
-
-       return kstrtouint_from_user(buffer, count, 0,
-                                   (unsigned int *)seq->private);
-}
-
-LDEBUGFS_SEQ_FOPS(ldlm_rw_uint);
-
-#ifdef HAVE_SERVER_SUPPORT
-
-static int seq_watermark_show(struct seq_file *m, void *data)
-{
-       seq_printf(m, "%llu\n", *(__u64 *)m->private);
-       return 0;
-}
-
-static ssize_t seq_watermark_write(struct file *file,
-                                  const char __user *buffer, size_t count,
-                                  loff_t *off)
-{
-       struct seq_file *m = file->private_data;
-       u64 value;
-       __u64 watermark;
-       __u64 *data = m->private;
-       bool wm_low = (data == &ldlm_reclaim_threshold_mb) ? true : false;
-       char kernbuf[22] = "";
-       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, &value, "MiB");
-       if (rc < 0) {
-               CERROR("Failed to set %s, rc = %d.\n",
-                      wm_low ? "lock_reclaim_threshold_mb" : "lock_limit_mb",
-                      rc);
-               return rc;
-       } else if (value != 0 && value < (1 << 20)) {
-               CERROR("%s should be greater than 1MB.\n",
-                      wm_low ? "lock_reclaim_threshold_mb" : "lock_limit_mb");
-               return -EINVAL;
-       }
-       watermark = value >> 20;
-
-       if (wm_low) {
-               if (ldlm_lock_limit_mb != 0 && watermark > ldlm_lock_limit_mb) {
-                       CERROR("lock_reclaim_threshold_mb must be smaller than lock_limit_mb.\n");
-                       return -EINVAL;
-               }
-
-               *data = watermark;
-               if (watermark != 0) {
-                       watermark <<= 20;
-                       do_div(watermark, sizeof(struct ldlm_lock));
-               }
-               ldlm_reclaim_threshold = watermark;
-       } else {
-               if (ldlm_reclaim_threshold_mb != 0 &&
-                   watermark < ldlm_reclaim_threshold_mb) {
-                       CERROR("lock_limit_mb must be greater than "
-                              "lock_reclaim_threshold_mb.\n");
-                       return -EINVAL;
-               }
-
-               *data = watermark;
-               if (watermark != 0) {
-                       watermark <<= 20;
-                       do_div(watermark, sizeof(struct ldlm_lock));
-               }
-               ldlm_lock_limit = watermark;
-       }
-
-       return count;
-}
-
-static int seq_watermark_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, seq_watermark_show, inode->i_private);
-}
-
-static const struct file_operations ldlm_watermark_fops = {
-       .owner          = THIS_MODULE,
-       .open           = seq_watermark_open,
-       .read           = seq_read,
-       .write          = seq_watermark_write,
-       .llseek         = seq_lseek,
-       .release        = lprocfs_single_release,
-};
-
-static int seq_granted_show(struct seq_file *m, void *data)
-{
-       seq_printf(m, "%llu\n", percpu_counter_sum_positive(
-                  (struct percpu_counter *)m->private));
-       return 0;
-}
-
-static int seq_granted_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, seq_granted_show, inode->i_private);
-}
-
-static const struct file_operations ldlm_granted_fops = {
-       .owner  = THIS_MODULE,
-       .open   = seq_granted_open,
-       .read   = seq_read,
-       .llseek = seq_lseek,
-       .release = single_release,
-};
-
-#endif /* HAVE_SERVER_SUPPORT */
-
 static struct ldebugfs_vars ldlm_debugfs_list[] = {
        { .name =       "dump_namespaces",
          .fops =       &ldlm_dump_ns_fops,
          .proc_mode =  0222 },
-       { .name =       "dump_granted_max",
-         .fops =       &ldlm_rw_uint_fops,
-         .data =       &ldlm_dump_granted_max },
-#ifdef HAVE_SERVER_SUPPORT
-       { .name =       "lock_reclaim_threshold_mb",
-         .fops =       &ldlm_watermark_fops,
-         .data =       &ldlm_reclaim_threshold_mb },
-       { .name =       "lock_limit_mb",
-         .fops =       &ldlm_watermark_fops,
-         .data =       &ldlm_lock_limit_mb },
-       { .name =       "lock_granted_count",
-         .fops =       &ldlm_granted_fops,
-         .data =       &ldlm_granted_total },
-#endif
        { NULL }
 };