[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240723123816.3676322-1-Yuwei.Guan@zeekrlife.com>
Date: Tue, 23 Jul 2024 20:38:16 +0800
From: Yuwei Guan <Yuwei.Guan@...krlife.com>
To: <jlayton@...nel.org>, <chuck.lever@...cle.com>, <alex.aring@...il.com>,
<viro@...iv.linux.org.uk>, <brauner@...nel.org>, <jack@...e.cz>
CC: <linux-fsdevel@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<ssawgyw@...il.com>, <Dashi.Luban@...krlife.com>, Yuwei Guan
<Yuwei.Guan@...krlife.com>
Subject: [PATCH] filelock: add file path in lock_get_status() to show more debug info
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@...krlife.com>
---
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
Powered by blists - more mailing lists