cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Alexander Aring <aahringo@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH RESEND v5.15-rc7 16/18] fs: dlm: add lkb debugfs functionality
Date: Tue,  2 Nov 2021 15:17:22 -0400	[thread overview]
Message-ID: <20211102191724.210095-17-aahringo@redhat.com> (raw)
In-Reply-To: <20211102191724.210095-1-aahringo@redhat.com>

This patch adds functionality to add an lkb during runtime. This is a
highly debugging feature only, wrong input can crash the kernel. It is a
early state feature as well. The goal is to provide a user interface for
manipulate dlm state and combine it with the rawmsg feature. It is
debugfs functionality, we don't care about UAPI breakage. Even it's
possible to add lkb's/rsb's which could never be exists in such wat by
using normal DLM operation. The user of this interface always need to
think before using this feature, not every crash which happens can really
occur during normal dlm operation.

Future there should be more functionality to add a more realistic lkb
which reflects normal DLM state inside the kernel. For now this is
enough.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
 fs/dlm/debug_fs.c | 32 +++++++++++++++++++++++++++++++-
 fs/dlm/lock.c     | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/dlm/lock.h     |  2 ++
 3 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index 555904eeea8e..2ead4751d655 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -635,6 +635,35 @@ static int table_open2(struct inode *inode, struct file *file)
 	return 0;
 }
 
+static ssize_t table_write2(struct file *file, const char __user *user_buf,
+			    size_t count, loff_t *ppos)
+{
+	struct seq_file *seq = file->private_data;
+	int n, len, lkb_nodeid, lkb_status, error;
+	char name[DLM_RESNAME_MAXLEN] = {};
+	struct dlm_ls *ls = seq->private;
+	unsigned int lkb_flags;
+	char buf[256] = {};
+	uint32_t lkb_id;
+
+	if (copy_from_user(buf, user_buf,
+			   min_t(size_t, sizeof(buf) - 1, count)))
+		return -EFAULT;
+
+	n = sscanf(buf, "%x %" __stringify(DLM_RESNAME_MAXLEN) "s %x %d %d",
+		   &lkb_id, name, &lkb_flags, &lkb_nodeid, &lkb_status);
+	if (n != 5)
+		return -EINVAL;
+
+	len = strnlen(name, DLM_RESNAME_MAXLEN);
+	error = dlm_debug_add_lkb(ls, lkb_id, name, len, lkb_flags,
+				  lkb_nodeid, lkb_status);
+	if (error)
+		return error;
+
+	return count;
+}
+
 static int table_open3(struct inode *inode, struct file *file)
 {
 	struct seq_file *seq;
@@ -675,6 +704,7 @@ static const struct file_operations format2_fops = {
 	.owner   = THIS_MODULE,
 	.open    = table_open2,
 	.read    = seq_read,
+	.write   = table_write2,
 	.llseek  = seq_lseek,
 	.release = seq_release
 };
@@ -846,7 +876,7 @@ void dlm_create_debug_file(struct dlm_ls *ls)
 	snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_locks", ls->ls_name);
 
 	ls->ls_debug_locks_dentry = debugfs_create_file(name,
-							S_IFREG | S_IRUGO,
+							0644,
 							dlm_root,
 							ls,
 							&format2_fops);
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index 8b30c9d9e545..aeb793693d8c 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -6317,3 +6317,49 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user_proc *proc,
 	return error;
 }
 
+/* debug functionality */
+int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
+		      int lkb_nodeid, unsigned int lkb_flags, int lkb_status)
+{
+	struct dlm_lksb *lksb;
+	struct dlm_lkb *lkb;
+	struct dlm_rsb *r;
+	int error;
+
+	/* we currently can't set a valid user lock */
+	if (lkb_flags & DLM_IFL_USER)
+		return -EOPNOTSUPP;
+
+	lksb = kzalloc(sizeof(*lksb), GFP_NOFS);
+	if (!lksb)
+		return -ENOMEM;
+
+	error = _create_lkb(ls, &lkb, lkb_id, lkb_id + 1);
+	if (error) {
+		kfree(lksb);
+		return error;
+	}
+
+	lkb->lkb_flags = lkb_flags;
+	lkb->lkb_nodeid = lkb_nodeid;
+	lkb->lkb_lksb = lksb;
+	/* user specific pointer, just don't have it NULL for kernel locks */
+	if (~lkb_flags & DLM_IFL_USER)
+		lkb->lkb_astparam = (void *)0xDEADBEEF;
+
+	error = find_rsb(ls, name, len, 0, R_REQUEST, &r);
+	if (error) {
+		kfree(lksb);
+		__put_lkb(ls, lkb);
+		return error;
+	}
+
+	lock_rsb(r);
+	attach_lkb(r, lkb);
+	add_lkb(r, lkb, lkb_status);
+	unlock_rsb(r);
+	put_rsb(r);
+
+	return 0;
+}
+
diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h
index 456c6ec3ef6f..863a66e128a2 100644
--- a/fs/dlm/lock.h
+++ b/fs/dlm/lock.h
@@ -58,6 +58,8 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user_proc *proc,
 	int nodeid, int pid);
 int dlm_user_deadlock(struct dlm_ls *ls, uint32_t flags, uint32_t lkid);
 void dlm_clear_proc_locks(struct dlm_ls *ls, struct dlm_user_proc *proc);
+int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
+		      int lkb_nodeid, unsigned int lkb_flags, int lkb_status);
 
 static inline int is_master(struct dlm_rsb *r)
 {
-- 
2.27.0



  parent reply	other threads:[~2021-11-02 19:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 19:17 [Cluster-devel] [PATCH RESEND v5.15-rc7 00/18] fs: dlm: cleanups, trace and debugfs Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 01/18] fs: dlm: remove obsolete INBUF define Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 02/18] fs: dlm: fix small lockspace typo Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 03/18] fs: dlm: debug improvements print nodeid Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 04/18] fs: dlm: remove check SCTP is loaded message Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 05/18] fs: dlm: move version conversion to compile time Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 06/18] fs: dlm: use dlm_recovery_stopped instead of test_bit Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 07/18] fs: dlm: use dlm_recovery_stopped in condition Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 08/18] fs: dlm: make dlm_callback_resume quite Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 09/18] fs: dlm: initial support for tracepoints Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 10/18] fs: dlm: trace socket handling Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 11/18] fs: dlm: requestqueue busy wait to event based wait Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 12/18] fs: dlm: ls_count " Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 13/18] fs: dlm: let handle callback data as void Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 14/18] fs: dlm: add debugfs rawmsg send functionality Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 15/18] fs: dlm: allow create lkb with specific id range Alexander Aring
2021-11-02 19:17 ` Alexander Aring [this message]
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 17/18] fs: dlm: add lkb waiters debugfs functionality Alexander Aring
2021-11-02 19:17 ` [Cluster-devel] [PATCH RESEND v5.15-rc7 18/18] fs: dlm: filter user dlm messages for kernel locks Alexander Aring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211102191724.210095-17-aahringo@redhat.com \
    --to=aahringo@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).