From aabfaebd887bf3a31bbf6d17546442d718e1de4d Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 20 Mar 2019 12:53:22 -0400 Subject: [PATCH] locks: rewalk and dump the dep chain when we hit a deadlock Signed-off-by: Jeff Layton --- fs/locks.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index ff6af2c32601..3d122a425eb5 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1009,7 +1009,8 @@ static struct file_lock *what_owner_is_waiting_for(struct file_lock *block_fl) static int posix_locks_deadlock(struct file_lock *caller_fl, struct file_lock *block_fl) { - int i = 0; + int i; + bool found = false; lockdep_assert_held(&blocked_lock_lock); @@ -1020,12 +1021,25 @@ static int posix_locks_deadlock(struct file_lock *caller_fl, if (IS_OFDLCK(caller_fl)) return 0; +restart: + i = 0; while ((block_fl = what_owner_is_waiting_for(block_fl))) { + if (found) + pr_warn("fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u fl_start=%lld fl_end=%lld\n", + block_fl->fl_owner, block_fl->fl_flags, + block_fl->fl_type, block_fl->fl_pid, + block_fl->fl_start, block_fl->fl_end); + if (i++ > MAX_DEADLK_ITERATIONS) return 0; - if (posix_same_owner(caller_fl, block_fl)) - return 1; + if (posix_same_owner(caller_fl, block_fl)) { + if (found) + return 1; + found = true; + goto restart; + } } + WARN_ON(found); return 0; } -- 2.20.1