Re: [PATCH] proc: show locks in /proc/pid/fdinfo/X

From: Andrew Vagin
Date: Fri Mar 06 2015 - 09:20:05 EST


On Thu, Mar 05, 2015 at 02:11:40PM -0500, Jeff Layton wrote:
> On Thu, 5 Mar 2015 18:37:18 +0300
> Andrey Vagin <avagin@xxxxxxxxxx> wrote:
>
> > Let's show locks which are associated with a file descriptor in
> > its fdinfo file.
> >
> > Currently we don't have a reliable way to determine who holds a lock.
> > We can find some information in /proc/locks, but PID which is reported
> > there can be wrong. For example, a process takes a lock, then forks a
> > child and dies. In this case /proc/locks contains the parent pid, which
> > can be reused by another process.
> >
> > $ cat /proc/locks
> > ...
> > 6: FLOCK ADVISORY WRITE 324 00:13:13431 0 EOF
> > ...
> >
> > $ ps -C rpcbind
> > PID TTY TIME CMD
> > 332 ? 00:00:00 rpcbind
> >
> > $ cat /proc/332/fdinfo/4
> > pos: 0
> > flags: 0100000
> > mnt_id: 22
> > lock: 1: FLOCK ADVISORY WRITE 324 00:13:13431 0 EOF
> >
> > $ ls -l /proc/332/fd/4
> > lr-x------ 1 root root 64 Mar 5 14:43 /proc/332/fd/4 -> /run/rpcbind.lock
> >
> > $ ls -l /proc/324/fd/
> > total 0
> > lrwx------ 1 root root 64 Feb 27 14:50 0 -> /dev/pts/0
> > lrwx------ 1 root root 64 Feb 27 14:50 1 -> /dev/pts/0
> > lrwx------ 1 root root 64 Feb 27 14:49 2 -> /dev/pts/0
> >
> > You can see that the process with the 324 pid doesn't hold the lock.
> >
> > This information is required for proper dumping and restoring file
> > locks.
> >
> > Cc: Jonathan Corbet <corbet@xxxxxxx>
> > Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
> > Cc: Jeff Layton <jlayton@xxxxxxxxxxxxxxx>
> > Cc: "J. Bruce Fields" <bfields@xxxxxxxxxxxx>
> > Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > Cc: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
> > Cc: Pavel Emelyanov <xemul@xxxxxxxxxxxxx>
> > Signed-off-by: Andrey Vagin <avagin@xxxxxxxxxx>
> > ---
> > Documentation/filesystems/proc.txt | 4 ++++
> > fs/locks.c | 38 ++++++++++++++++++++++++++++++++++++++
> > fs/proc/fd.c | 27 ++++++++++++++++++---------
> > include/linux/fs.h | 7 +++++++
> > 4 files changed, 67 insertions(+), 9 deletions(-)
> >

...

> > +struct files_struct;
> > +static inline void show_fd_locks(struct seq_file *f,
> > + struct file *filp, struct files_struct *files) {}
> > #endif /* !CONFIG_FILE_LOCKING */
> >
> >
>
> Looks reasonably sane to me. Via what tree should this go in?

I don't know. I think all previous patches about fdinfo went through
linux-mm. Andrew, what do you think?

>
> Acked-by: Jeff Layton <jlayton@xxxxxxxxxxxxxxx>

Thanks,
Andrey
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/