[Cluster-devel] [PATCH dlm/next 1/2] fs: dlm: plock debugfs to check for pending operations

Alexander Aring aahringo at redhat.com
Wed May 24 17:19:31 UTC 2023


In the past issues were found that there were still ongoing plock
operations in the kernel but it should cleanup routines should clear
them up because there were no plock activity by the user anymore. To
check that "dlm_tool plocks $LS" can be used, but this only shows
pending operations in dlm_controld daemon. To check the kernel part, if
the kernel waits for an answer of the user space, this patch introduces
a debugfs entry which reports if there are ongoing plock operations or
not.

Signed-off-by: Alexander Aring <aahringo at redhat.com>
---
 fs/dlm/debug_fs.c     | 26 ++++++++++++++++++++++++++
 fs/dlm/dlm_internal.h |  5 +++++
 fs/dlm/plock.c        | 15 +++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index a1aca41c49d0..494a6e73f8e8 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -25,6 +25,7 @@ static struct mutex debug_buf_lock;
 
 static struct dentry *dlm_root;
 static struct dentry *dlm_comms;
+static struct dentry *dlm_plock;
 
 static char *print_lockmode(int mode)
 {
@@ -883,6 +884,30 @@ void dlm_delete_debug_comms_file(void *ctx)
 	debugfs_remove(ctx);
 }
 
+static int dlm_plock_ops_pending_show(struct seq_file *file, void *offset)
+{
+	seq_printf(file, "%d\n", dlm_plock_ops_pending());
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(dlm_plock_ops_pending);
+
+void dlm_create_debug_plock_file(void)
+{
+	/* TODO currently use case if only to look if everything got cleaned
+	 * up probably if user space dlm_tool plocks $LS shows no activity
+	 * anymore on all lockspaces.
+	 *
+	 * However in future a dump could be useful as well.
+	 */
+	debugfs_create_file("plock_ops_pending", 0444, dlm_plock, NULL,
+			    &dlm_plock_ops_pending_fops);
+}
+
+void dlm_remove_debug_plock_file(void)
+{
+	debugfs_remove(dlm_plock);
+}
+
 void dlm_create_debug_file(struct dlm_ls *ls)
 {
 	char name[DLM_LOCKSPACE_LEN + 8];
@@ -943,6 +968,7 @@ 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_plock = debugfs_create_dir("plock", dlm_root);
 }
 
 void dlm_unregister_debugfs(void)
diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h
index 986a9d7b1f33..f5f741ee527b 100644
--- a/fs/dlm/dlm_internal.h
+++ b/fs/dlm/dlm_internal.h
@@ -805,6 +805,7 @@ static inline void dlm_set_sbflags_val(struct dlm_lkb *lkb, uint32_t val)
 			  __DLM_SBF_MAX_BIT);
 }
 
+int dlm_plock_ops_pending(void);
 int dlm_plock_init(void);
 void dlm_plock_exit(void);
 
@@ -815,6 +816,8 @@ void dlm_create_debug_file(struct dlm_ls *ls);
 void dlm_delete_debug_file(struct dlm_ls *ls);
 void *dlm_create_debug_comms_file(int nodeid, void *data);
 void dlm_delete_debug_comms_file(void *ctx);
+void dlm_create_debug_plock_file(void);
+void dlm_remove_debug_plock_file(void);
 #else
 static inline void dlm_register_debugfs(void) { }
 static inline void dlm_unregister_debugfs(void) { }
@@ -822,6 +825,8 @@ static inline void dlm_create_debug_file(struct dlm_ls *ls) { }
 static inline void dlm_delete_debug_file(struct dlm_ls *ls) { }
 static inline void *dlm_create_debug_comms_file(int nodeid, void *data) { return NULL; }
 static inline void dlm_delete_debug_comms_file(void *ctx) { }
+static inline void dlm_create_debug_plock_file(void) { };
+static inline void dlm_remove_debug_plock_file(void) { };
 #endif
 
 #endif				/* __DLM_INTERNAL_DOT_H__ */
diff --git a/fs/dlm/plock.c b/fs/dlm/plock.c
index 53d17dbbb716..d6ec70547b77 100644
--- a/fs/dlm/plock.c
+++ b/fs/dlm/plock.c
@@ -35,6 +35,18 @@ struct plock_op {
 	struct plock_async_data *data;
 };
 
+int dlm_plock_ops_pending(void)
+{
+	int rv;
+
+	spin_lock(&ops_lock);
+	rv = !list_empty(&send_list);
+	rv |= !list_empty(&recv_list);
+	spin_unlock(&ops_lock);
+
+	return rv;
+}
+
 static inline void set_version(struct dlm_plock_info *info)
 {
 	info->version[0] = DLM_PLOCK_VERSION_MAJOR;
@@ -509,11 +521,14 @@ int dlm_plock_init(void)
 	rv = misc_register(&plock_dev_misc);
 	if (rv)
 		log_print("dlm_plock_init: misc_register failed %d", rv);
+
+	dlm_create_debug_plock_file();
 	return rv;
 }
 
 void dlm_plock_exit(void)
 {
+	dlm_remove_debug_plock_file();
 	misc_deregister(&plock_dev_misc);
 }
 
-- 
2.31.1



More information about the Cluster-devel mailing list