From: James Simmons Date: Mon, 18 Mar 2024 14:53:53 +0000 (-0600) Subject: LU-17053 libcfs: make a debugfs equivalent for markers X-Git-Tag: 2.15.62~24 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=bb6a2d2e80f04645b488ecca6ba14cb628e3eeb3;p=fs%2Flustre-release.git LU-17053 libcfs: make a debugfs equivalent for markers 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 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54363 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Shaun Tancheff Reviewed-by: Oleg Drokin --- diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 293f786..4e0440b 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -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, diff --git a/lnet/lnet/module.c b/lnet/lnet/module.c index 7802702..6046362 100644 --- a/lnet/lnet/module.c +++ b/lnet/lnet/module.c @@ -13,6 +13,7 @@ #include #include #include +#include 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, diff --git a/lustre/utils/debug.c b/lustre/utils/debug.c index 0bec2f2..fa2494e 100644 --- a/lustre/utils/debug.c +++ b/lustre/utils/debug.c @@ -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;