[PATCH dlm/next 2/5] dlm: introduce lockspace control debugfs entry

Alexander Aring
2024-11-13T16:46:53Z

To create nowadays a kernel lockspace we need to call the kernel API.
This will provide a debugfs entry to do so. It is named "__ctrl" as the
debugfs entries my collide with lockspace names. It still can but it is
more unlikely as it has a "__" prefix.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
fs/dlm/debug_fs.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)

diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index c76320acefc1..49ad31120286 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -26,6 +26,7 @@ static struct mutex debug_buf_lock;

static struct dentry *dlm_root;
static struct dentry *dlm_comms;
+static struct dentry *dlm_ctrl;

static char *print_lockmode(int mode)
{
@@ -759,6 +760,36 @@ void dlm_delete_debug_comms_file(void *ctx)
debugfs_remove(ctx);
}

+static ssize_t dlm_ctrl_write(struct file *fp, const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ char clname[DLM_LOCKSPACE_LEN + 1] = {};
+ char lsname[DLM_LOCKSPACE_LEN + 1] = {};
+ dlm_lockspace_t *ls;
+ char buf[512] = {};
+ int rv, n;
+
+ if (copy_from_user(buf, user_buf,
+ min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ n = sscanf(buf, "%" __stringify(DLM_LOCKSPACE_LEN) "s %" __stringify(DLM_LOCKSPACE_LEN) "s",
+ lsname, clname);
+ if (n != 2)
+ return -EINVAL;
+
+ rv = dlm_new_lockspace(lsname, clname, 0, 0, NULL, NULL, NULL, &ls);
+ if (rv)
+ return rv;
+
+ return count;
+}
+
+static const struct file_operations dlm_ctrl_fops = {
+ .open = simple_open,
+ .write = dlm_ctrl_write,
+};
+
void dlm_create_debug_file(struct dlm_ls *ls)
{
/* Reserve enough space for the longest file name */
@@ -816,6 +847,8 @@ void __init dlm_register_debugfs(void)
mutex_init(&debug_buf_lock);
dlm_root = debugfs_create_dir("dlm", NULL);
dlm_comms = debugfs_create_dir("comms", dlm_root);
+ dlm_ctrl = debugfs_create_file("__ctrl", 0644, dlm_root, NULL,
+ &dlm_ctrl_fops);
}

void dlm_unregister_debugfs(void)
--
2.43.0