[PATCH dlm/next 3/5] dlm: extend debugfs to manipulate more DLM states

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

To reproduce more issues with the DLM recovery by using the DLM debugfs
developer backdoor to force manipulating the DLM lkb/rsb states.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
fs/dlm/debug_fs.c | 16 +++++++++-------
fs/dlm/dlm_internal.h | 6 ++++++
fs/dlm/lock.c | 43 +++++++++++++++++++++++++++++++++++++++----
fs/dlm/lock.h | 4 +++-
4 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index 49ad31120286..54ad11e1cd2c 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -502,11 +502,11 @@ static int table_open2(struct inode *inode, struct file *file)
static ssize_t table_write2(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos)
{
+ int n, len, lkb_status, error, from_nodeid, dir_nodeid, master_nodeid, rqmode, grmode;
struct seq_file *seq = file->private_data;
- int n, len, lkb_nodeid, lkb_status, error;
char name[DLM_RESNAME_MAXLEN + 1] = {};
+ unsigned int lkb_dflags, lkb_iflags;
struct dlm_ls *ls = seq->private;
- unsigned int lkb_flags;
char buf[256] = {};
uint32_t lkb_id;

@@ -514,14 +514,16 @@ static ssize_t table_write2(struct file *file, const char __user *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)
+ n = sscanf(buf, "%x %" __stringify(DLM_RESNAME_MAXLEN) "s %x %x %d %d %d %d %d %d",
+ &lkb_id, name, &lkb_iflags, &lkb_dflags, &lkb_status, &from_nodeid,
+ &dir_nodeid, &master_nodeid, &rqmode, &grmode);
+ if (n != 10)
return -EINVAL;

len = strnlen(name, DLM_RESNAME_MAXLEN);
- error = dlm_debug_add_lkb(ls, lkb_id, name, len, lkb_flags,
- lkb_nodeid, lkb_status);
+ error = dlm_debug_add_lkb(ls, lkb_id, name, len, lkb_iflags, lkb_dflags,
+ lkb_status, from_nodeid, dir_nodeid,
+ master_nodeid, rqmode, grmode);
if (error)
return error;

diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h
index d534a4bc162b..6ee6179e16a8 100644
--- a/fs/dlm/dlm_internal.h
+++ b/fs/dlm/dlm_internal.h
@@ -794,6 +794,12 @@ static inline void dlm_set_flags_val(unsigned long *addr, uint32_t val,
}
}

+static inline void dlm_set_iflags_val(struct dlm_lkb *lkb, uint32_t val)
+{
+ dlm_set_flags_val(&lkb->lkb_iflags, val, __DLM_IFL_MIN_BIT,
+ __DLM_IFL_MAX_BIT);
+}
+
static inline void dlm_set_dflags_val(struct dlm_lkb *lkb, uint32_t val)
{
dlm_set_flags_val(&lkb->lkb_dflags, val, __DLM_DFL_MIN_BIT,
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index 966a926c301b..4219e0025fa2 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -6271,10 +6271,30 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user_proc *proc,
return error;
}

+static void debug_bastfn(void *astparam, int mode)
+{
+ const struct dlm_lkb *lkb = astparam;
+
+ log_print("%s: lkb_id 0x%x mode %u", __func__, lkb->lkb_id, mode);
+}
+
+static void debug_astfn(void *astparam)
+{
+ const struct dlm_lkb *lkb = astparam;
+ const struct dlm_lksb *lksb;
+
+ lksb = lkb->lkb_lksb;
+
+ log_print("%s: lkb_id 0x%x status %d", __func__, lkb->lkb_id, lksb->sb_status);
+}
+
/* 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_dflags, int lkb_status)
+ unsigned int lkb_iflags, unsigned int lkb_dflags,
+ int lkb_status, int from_nodeid, int dir_nodeid,
+ int master_nodeid, int rqmode, int grmode)
{
+ int our_nodeid = dlm_our_nodeid();
struct dlm_lksb *lksb;
struct dlm_lkb *lkb;
struct dlm_rsb *r;
@@ -6294,14 +6314,18 @@ int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
return error;
}

+ dlm_set_iflags_val(lkb, lkb_iflags);
dlm_set_dflags_val(lkb, lkb_dflags);
- lkb->lkb_nodeid = lkb_nodeid;
lkb->lkb_lksb = lksb;
+ lkb->lkb_rqmode = rqmode;
+ lkb->lkb_grmode = grmode;
+ lkb->lkb_astfn = debug_astfn;
+ lkb->lkb_bastfn = debug_bastfn;
/* user specific pointer, just don't have it NULL for kernel locks */
if (~lkb_dflags & BIT(DLM_DFL_USER_BIT))
- lkb->lkb_astparam = (void *)0xDEADBEEF;
+ lkb->lkb_astparam = lkb;

- error = find_rsb(ls, name, len, 0, R_REQUEST, &r);
+ error = find_rsb(ls, name, len, from_nodeid, R_REQUEST, &r);
if (error) {
kfree(lksb);
__put_lkb(ls, lkb);
@@ -6309,6 +6333,17 @@ int dlm_debug_add_lkb(struct dlm_ls *ls, uint32_t lkb_id, char *name, int len,
}

lock_rsb(r);
+ if (dir_nodeid)
+ r->res_dir_nodeid = dir_nodeid;
+
+ r->res_master_nodeid = master_nodeid;
+ /* stupid second meaning of res_master_nodeid */
+ if (master_nodeid == our_nodeid)
+ r->res_nodeid = 0;
+ else
+ r->res_nodeid = master_nodeid;
+ lkb->lkb_nodeid = r->res_nodeid;
+
attach_lkb(r, lkb);
add_lkb(r, lkb, lkb_status);
unlock_rsb(r);
diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h
index b23d7b854ed4..66ba9688f9c4 100644
--- a/fs/dlm/lock.h
+++ b/fs/dlm/lock.h
@@ -60,7 +60,9 @@ int dlm_user_purge(struct dlm_ls *ls, struct dlm_user_proc *proc,
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);
+ unsigned int lkb_iflags, unsigned int lkb_dflags,
+ int lkb_status, int from_nodeid, int dir_nodeid,
+ int master_nodeid, int rqmode, int grmode);
int dlm_debug_add_lkb_to_waiters(struct dlm_ls *ls, uint32_t lkb_id,
int mstype, int to_nodeid);

--
2.43.0