• Andrey Vagin's avatar
    proc: show locks in /proc/pid/fdinfo/X · 6c8c9031
    Andrey Vagin authored
    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.
    Signed-off-by: default avatarAndrey Vagin <avagin@openvz.org>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Acked-by: default avatarJeff Layton <jlayton@poochiereds.net>
    Acked-by: default avatar"J. Bruce Fields" <bfields@fieldses.org>
    Acked-by: default avatarCyrill Gorcunov <gorcunov@openvz.org>
    Cc: Pavel Emelyanov <xemul@parallels.com>
    Cc: Joe Perches <joe@perches.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    6c8c9031
fd.c 7.54 KB