[PATCH] filelock: add file path in lock_get_status() to show more debug info
From: Yuwei Guan
Date: Tue Jul 23 2024 - 08:38:53 EST
The current lock_get_status() function shows ino, but it’s not
intuitive enough for debugging. This patch will add the file’s
path information, making it easier to debug which specific file
is holding the lock.
Signed-off-by: Yuwei Guan <Yuwei.Guan@xxxxxxxxxxxxx>
---
fs/locks.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/fs/locks.c b/fs/locks.c
index bdd94c32256f..feb0a4427a5b 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -2764,6 +2764,8 @@ static void lock_get_status(struct seq_file *f, struct file_lock_core *flc,
struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb);
int type = flc->flc_type;
struct file_lock *fl = file_lock(flc);
+ struct dentry *dentry = NULL;
+ char *path, *pathbuf;
pid = locks_translate_pid(flc, proc_pidns);
@@ -2819,8 +2821,29 @@ static void lock_get_status(struct seq_file *f, struct file_lock_core *flc,
seq_printf(f, "%d %02x:%02x:%lu ", pid,
MAJOR(inode->i_sb->s_dev),
MINOR(inode->i_sb->s_dev), inode->i_ino);
+
+ pathbuf = __getname();
+ if (!pathbuf)
+ seq_printf(f, "%s ", "UNKNOWN");
+ else {
+ ihold(inode);
+ dentry = d_obtain_alias(inode);
+ if (!IS_ERR(dentry)) {
+ path = dentry_path_raw(dentry, pathbuf, PATH_MAX);
+ if (IS_ERR(path)) {
+ strscpy(pathbuf, "UNKNOWN", PATH_MAX);
+ path = pathbuf;
+ }
+ dput(dentry);
+ } else {
+ strscpy(pathbuf, "UNKNOWN", PATH_MAX);
+ path = pathbuf;
+ }
+ seq_printf(f, "%s ", path);
+ __putname(pathbuf);
+ }
} else {
- seq_printf(f, "%d <none>:0 ", pid);
+ seq_printf(f, "%d <none>:0:<none> UNKNOWN ", pid);
}
if (flc->flc_flags & FL_POSIX) {
if (fl->fl_end == OFFSET_MAX)
--
2.17.1