Whamcloud - gitweb
LU-17053 libcfs: make a debugfs equivalent for markers 63/54363/7
authorJames Simmons <jsimmons@infradead.org>
Mon, 18 Mar 2024 14:53:53 +0000 (08:53 -0600)
committerOleg Drokin <green@whamcloud.com>
Tue, 2 Apr 2024 21:05:50 +0000 (21:05 +0000)
Most of the ioctl handlding that was LNet related has been moved
from libcfs to LNet. One left over are markers which allow
injection of strings into the lustre debug buffer located in
libcfs_ioctl(). This is the only functionality which exist in
libcfs yet it is only available in lnet module. We can create
an debugfs equivalent that also allows injection of strings
into the Lustre debug buffers with scripts.

Change-Id: I22395b6b19f94de3c95ba8517a14d2ea251fe37a
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54363
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/module.c
lnet/lnet/module.c
lustre/utils/debug.c

index 293f786..4e0440b 100644 (file)
@@ -72,6 +72,12 @@ struct lnet_debugfs_symlink_def {
 
 static struct dentry *lnet_debugfs_root;
 
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 18, 53, 0)
+/* remove deprecated libcfs ioctl handling, since /dev/lnet has
+ * moved to lnet and there is no way to call these ioctls until
+ * after the lnet module is loaded.  They are replaced by writing
+ * to "debug_marker", handled by libcfs_debug_marker() below.
+ */
 int libcfs_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
 {
        switch (cmd) {
@@ -93,6 +99,7 @@ int libcfs_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
        return 0;
 }
 EXPORT_SYMBOL(libcfs_ioctl);
+#endif
 
 static int proc_dobitmasks(struct ctl_table *table, int write,
                           void __user *buffer, size_t *lenp, loff_t *ppos)
@@ -214,6 +221,36 @@ static int proc_fail_loc(struct ctl_table *table, int write,
        return rc;
 }
 
+static int libcfs_debug_marker(struct ctl_table *table, int write,
+                              void __user *buffer,
+                              size_t *lenp, loff_t *ppos)
+{
+       size_t len = min(*lenp, 4000UL);
+       char *kbuf;
+
+       if (!*lenp || *ppos) {
+               *lenp = 0;
+               return 0;
+       }
+
+       if (!write)
+               return 0;
+
+       kbuf = strndup_user(buffer, len);
+       if (IS_ERR(kbuf))
+               return PTR_ERR(kbuf);
+
+       if (strcmp(kbuf, "clear") == 0)
+               libcfs_debug_clear_buffer();
+       else
+               libcfs_debug_mark_buffer(kbuf);
+
+       kfree(kbuf);
+       *ppos += len;
+
+       return *lenp > 4000 ? -EOVERFLOW : 0;
+}
+
 int debugfs_doint(struct ctl_table *table, int write,
                  void __user *buffer, size_t *lenp, loff_t *ppos)
 {
@@ -392,6 +429,11 @@ static struct ctl_table lnet_table[] = {
                .extra2         = &max_watchdog_ratelimit,
        },
        {
+               .procname       = "debug_marker",
+               .mode           = 0200,
+               .proc_handler   = &libcfs_debug_marker
+       },
+       {
                .procname       = "force_lbug",
                .data           = NULL,
                .maxlen         = 0,
index 7802702..6046362 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/miscdevice.h>
 #include <lnet/lib-lnet.h>
 #include <uapi/linux/lnet/lnet-dlc.h>
+#include <uapi/linux/lustre/lustre_ver.h>
 
 static int config_on_load = 0;
 module_param(config_on_load, int, 0444);
@@ -375,8 +376,10 @@ lnet_psdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
        CDEBUG(D_IOCTL, "lnet ioctl cmd %u\n", cmd);
 
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 18, 53, 0)
        err = libcfs_ioctl(cmd, data);
        if (err == -EINVAL)
+#endif
                err = lnet_ioctl(cmd, hdr);
        if (err == -EINVAL) {
                err = blocking_notifier_call_chain(&lnet_ioctl_list,
index 0bec2f2..fa2494e 100644 (file)
@@ -732,14 +732,30 @@ out:
 
 int jt_dbg_clear_debug_buf(int argc, char **argv)
 {
-       int                      rc;
        struct libcfs_ioctl_data data;
+       glob_t path;
+       int fd, rc;
 
        if (argc != 1) {
                fprintf(stderr, "usage: %s\n", argv[0]);
                return 0;
        }
 
+       if (cfs_get_param_paths(&path, "debug_marker") != 0)
+               goto use_ioctl;
+
+       fd = open(path.gl_pathv[0], O_WRONLY);
+       if (fd < 0) {
+               cfs_free_param_data(&path);
+               goto use_ioctl;
+       }
+
+       rc = write(fd, "clear", strlen("clear") + 1);
+       cfs_free_param_data(&path);
+       close(fd);
+       return rc > 0 ? 0 : rc;
+
+use_ioctl:
        memset(&data, 0, sizeof(data));
        if (libcfs_ioctl_pack(&data, &buf, max) != 0) {
                fprintf(stderr, "libcfs_ioctl_pack failed.\n");
@@ -757,12 +773,11 @@ int jt_dbg_clear_debug_buf(int argc, char **argv)
 
 int jt_dbg_mark_debug_buf(int argc, char **argv)
 {
-       static char              scratch[MAX_MARK_SIZE] = "";
+       static char scratch[MAX_MARK_SIZE] = "";
        struct libcfs_ioctl_data data;
-       char                    *text;
-       int                      rc;
-
-       memset(&data, 0, sizeof(data));
+       glob_t path;
+       char *text;
+       int fd, rc;
 
        if (argc > 1) {
                int count, max_size = sizeof(scratch) - 1;
@@ -782,6 +797,22 @@ int jt_dbg_mark_debug_buf(int argc, char **argv)
                text = ctime(&now);
        }
 
+       if (cfs_get_param_paths(&path, "debug_marker") != 0)
+               goto use_ioctl;
+
+       fd = open(path.gl_pathv[0], O_WRONLY);
+       if (fd < 0) {
+               cfs_free_param_data(&path);
+               goto use_ioctl;
+       }
+
+       rc = write(fd, text, strlen(text) + 1);
+       cfs_free_param_data(&path);
+       close(fd);
+       return rc > 0 ? 0 : rc;
+
+use_ioctl:
+       memset(&data, 0, sizeof(data));
        data.ioc_inllen1 = strlen(text) + 1;
        data.ioc_inlbuf1 = text;