linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Yuwei Guan <Yuwei.Guan@zeekrlife.com>,
	chuck.lever@oracle.com,  alex.aring@gmail.com,
	viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	 ssawgyw@gmail.com, Dashi.Luban@zeekrlife.com
Subject: Re: [PATCH] filelock: add file path in lock_get_status() to show more debug info
Date: Tue, 23 Jul 2024 09:16:10 -0400	[thread overview]
Message-ID: <7ce8cadfc432368924134ae96f8d9710282a15d6.camel@kernel.org> (raw)
In-Reply-To: <20240723123816.3676322-1-Yuwei.Guan@zeekrlife.com>

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>

      reply	other threads:[~2024-07-23 13:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ce8cadfc432368924134ae96f8d9710282a15d6.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dashi.Luban@zeekrlife.com \
    --cc=Yuwei.Guan@zeekrlife.com \
    --cc=alex.aring@gmail.com \
    --cc=brauner@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ssawgyw@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).