mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 19:21:31 -04:00
proc: show locks in /proc/pid/fdinfo/X
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: Andrey Vagin <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Alexander Viro <[email protected]> Acked-by: Jeff Layton <[email protected]> Acked-by: "J. Bruce Fields" <[email protected]> Acked-by: Cyrill Gorcunov <[email protected]> Cc: Pavel Emelyanov <[email protected]> Cc: Joe Perches <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
15eb42d674
commit
6c8c90319c
4 changed files with 66 additions and 10 deletions
27
fs/proc/fd.c
27
fs/proc/fd.c
|
|
@ -8,6 +8,7 @@
|
|||
#include <linux/security.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include <linux/proc_fs.h>
|
||||
|
||||
|
|
@ -48,17 +49,23 @@ static int seq_show(struct seq_file *m, void *v)
|
|||
put_files_struct(files);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\n",
|
||||
(long long)file->f_pos, f_flags,
|
||||
real_mount(file->f_path.mnt)->mnt_id);
|
||||
if (file->f_op->show_fdinfo)
|
||||
file->f_op->show_fdinfo(m, file);
|
||||
ret = seq_has_overflowed(m);
|
||||
fput(file);
|
||||
}
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\n",
|
||||
(long long)file->f_pos, f_flags,
|
||||
real_mount(file->f_path.mnt)->mnt_id);
|
||||
|
||||
show_fd_locks(m, file, files);
|
||||
if (seq_has_overflowed(m))
|
||||
goto out;
|
||||
|
||||
if (file->f_op->show_fdinfo)
|
||||
file->f_op->show_fdinfo(m, file);
|
||||
|
||||
out:
|
||||
fput(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int seq_fdinfo_open(struct inode *inode, struct file *file)
|
||||
|
|
|
|||
Loading…
Reference in a new issue