From 826d7bc9f013d01e92997883d2fd0c25f4af1f1c Mon Sep 17 00:00:00 2001 From: Konstantin Khorenko Date: Fri, 8 Jun 2018 17:27:11 +0300 Subject: fs/lock: skip lock owner pid translation in case we are in init_pid_ns If the flock owner process is dead and its pid has been already freed, pid translation won't work, but we still want to show flock owner pid number when expecting /proc/$PID/fdinfo/$FD in init pidns. Reproducer: process A process A1 process A2 fork()---------> exit() open() flock() fork()---------> exit() sleep() Before the patch: ================ (root@vz7)/: cat /proc/${PID_A2}/fdinfo/3 pos: 4 flags: 02100002 mnt_id: 257 lock: (root@vz7)/: After the patch: =============== (root@vz7)/:cat /proc/${PID_A2}/fdinfo/3 pos: 4 flags: 02100002 mnt_id: 295 lock: 1: FLOCK ADVISORY WRITE ${PID_A1} b6:f8a61:529946 0 EOF Fixes: 9d5b86ac13c5 ("fs/locks: Remove fl_nspid and use fs-specific l_pid for remote locks") Signed-off-by: Konstantin Khorenko Acked-by: Andrey Vagin Reviewed-by: Benjamin Coddington Signed-off-by: Jeff Layton --- fs/locks.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index 05e211be8684..bfee5b7f2862 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -2072,6 +2072,13 @@ static pid_t locks_translate_pid(struct file_lock *fl, struct pid_namespace *ns) return -1; if (IS_REMOTELCK(fl)) return fl->fl_pid; + /* + * If the flock owner process is dead and its pid has been already + * freed, the translation below won't work, but we still want to show + * flock owner pid number in init pidns. + */ + if (ns == &init_pid_ns) + return (pid_t)fl->fl_pid; rcu_read_lock(); pid = find_pid_ns(fl->fl_pid, &init_pid_ns); -- cgit v1.2.3-59-g8ed1b From 1cf8e5de4055f85383405a21a0a7c3c4348bf2ed Mon Sep 17 00:00:00 2001 From: Konstantin Khorenko Date: Fri, 8 Jun 2018 17:27:12 +0300 Subject: fs/lock: show locks taken by processes from another pidns Currently if we face a lock taken by a process invisible in the current pidns we skip the lock completely, but this 1) makes the output not that nice (root@vz7)/: cat /proc/${PID_A2}/fdinfo/3 pos: 4 flags: 02100002 mnt_id: 257 lock: (root@vz7)/: 2) makes it more difficult to debug issues with leaked flocks if you get error on lock, but don't see any locks in /proc/$id/fdinfo/$file Let's show information about such locks again as previously, but show zero in the owner pid field. After the patch: =============== (root@vz7)/:cat /proc/${PID_A2}/fdinfo/3 pos: 4 flags: 02100002 mnt_id: 295 lock: 1: FLOCK ADVISORY WRITE 0 b6:f8a61:529946 0 EOF Fixes: 9d5b86ac13c5 ("fs/locks: Remove fl_nspid and use fs-specific l_pid for remote locks") Signed-off-by: Konstantin Khorenko Acked-by: Andrey Vagin Reviewed-by: Benjamin Coddington Signed-off-by: Jeff Layton --- fs/locks.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index bfee5b7f2862..e533623e2e99 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -2633,12 +2633,10 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl, fl_pid = locks_translate_pid(fl, proc_pidns); /* - * If there isn't a fl_pid don't display who is waiting on - * the lock if we are called from locks_show, or if we are - * called from __show_fd_info - skip lock entirely + * If lock owner is dead (and pid is freed) or not visible in current + * pidns, zero is shown as a pid value. Check lock info from + * init_pid_ns to get saved lock pid value. */ - if (fl_pid == 0) - return; if (fl->fl_file != NULL) inode = locks_inode(fl->fl_file); -- cgit v1.2.3-59-g8ed1b From c883da313ebf459efd33d262ca963e3a5f0ac024 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Mon, 30 Jul 2018 07:54:56 -0400 Subject: locks: add tracepoint in flock codepath Signed-off-by: Jeff Layton --- fs/locks.c | 1 + include/trace/events/filelock.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/locks.c b/fs/locks.c index e533623e2e99..6138a9bcd924 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -990,6 +990,7 @@ out: if (new_fl) locks_free_lock(new_fl); locks_dispose_list(&dispose); + trace_flock_lock_inode(inode, request, error); return error; } diff --git a/include/trace/events/filelock.h b/include/trace/events/filelock.h index d1faf3597b9d..68b17c116907 100644 --- a/include/trace/events/filelock.h +++ b/include/trace/events/filelock.h @@ -112,8 +112,11 @@ DEFINE_EVENT(filelock_lock, locks_remove_posix, TP_PROTO(struct inode *inode, struct file_lock *fl, int ret), TP_ARGS(inode, fl, ret)); -DECLARE_EVENT_CLASS(filelock_lease, +DEFINE_EVENT(filelock_lock, flock_lock_inode, + TP_PROTO(struct inode *inode, struct file_lock *fl, int ret), + TP_ARGS(inode, fl, ret)); +DECLARE_EVENT_CLASS(filelock_lease, TP_PROTO(struct inode *inode, struct file_lock *fl), TP_ARGS(inode, fl), -- cgit v1.2.3-59-g8ed1b From 96c25b777442d3a875b1921b1f047ea00d96c8ea Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Sun, 17 Jun 2018 05:31:17 -0400 Subject: mailmap: remap some of my email addresses to kernel.org address Signed-off-by: Jeff Layton --- .mailmap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.mailmap b/.mailmap index 29ddeb1bf015..d96147eb1a68 100644 --- a/.mailmap +++ b/.mailmap @@ -81,6 +81,9 @@ Javi Merino Jean Tourrilhes Jeff Garzik +Jeff Layton +Jeff Layton +Jeff Layton Jens Axboe Jens Osterkamp Johan Hovold -- cgit v1.2.3-59-g8ed1b From da33a871ba178dbe81da7d755818d3c2088cae32 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 8 Aug 2018 12:54:09 -0400 Subject: locks: remove misleading obsolete comment The spinlock handling in this file has changed significantly since this comment was written, and the file_lock_lock is no more. In addition, this overall comment no longer applies. Deleting an entry now requires both locks. Signed-off-by: Jeff Layton --- fs/locks.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 6138a9bcd924..11a4d698aba8 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -202,10 +202,6 @@ static DEFINE_HASHTABLE(blocked_hash, BLOCKED_HASH_BITS); * we often hold the flc_lock as well. In certain cases, when reading the fields * protected by this lock, we can skip acquiring it iff we already hold the * flc_lock. - * - * In particular, adding an entry to the fl_block list requires that you hold - * both the flc_lock and the blocked_lock_lock (acquired in that order). - * Deleting an entry from the list however only requires the file_lock_lock. */ static DEFINE_SPINLOCK(blocked_lock_lock); -- cgit v1.2.3-59-g8ed1b