* [PATCH] filelock: add file path in lock_get_status() to show more debug info
@ 2024-07-23 12:38 Yuwei Guan
2024-07-23 13:16 ` Jeff Layton
0 siblings, 1 reply; 2+ messages in thread
From: Yuwei Guan @ 2024-07-23 12:38 UTC (permalink / raw)
To: jlayton, chuck.lever, alex.aring, viro, brauner, jack
Cc: linux-fsdevel, linux-kernel, ssawgyw, Dashi.Luban, Yuwei Guan
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@zeekrlife.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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] filelock: add file path in lock_get_status() to show more debug info
2024-07-23 12:38 [PATCH] filelock: add file path in lock_get_status() to show more debug info Yuwei Guan
@ 2024-07-23 13:16 ` Jeff Layton
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2024-07-23 13:16 UTC (permalink / raw)
To: Yuwei Guan, chuck.lever, alex.aring, viro, brauner, jack
Cc: linux-fsdevel, linux-kernel, ssawgyw, Dashi.Luban
On Tue, 2024-07-23 at 20:38 +0800, Yuwei Guan wrote:
> 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@zeekrlife.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();
This won't work. locks_show is called under the blocked_lock_lock
spinlock, and __getname does a GFP_KERNEL allocation.
The second problem is that the procfiles that this alters (/proc/locks
and /proc/<pid>/fdinfo/*) are considered part of the kernel's ABI, so
we can't just go change the format of them.
If you're interested in getting pathnames, I suggest using the lslocks
program which resolves these pathnames in userland.
> + 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)
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-23 13:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 12:38 [PATCH] filelock: add file path in lock_get_status() to show more debug info Yuwei Guan
2024-07-23 13:16 ` Jeff Layton
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).