Skip to content

Commit 3953704

Browse files
bcodding-rhjtlayton
authored andcommitted
locks: restore a warn for leaked locks on close
When locks.c moved to using file_lock_context, the check for any locks that were not released was moved from the __fput() to destroy_inode() path in commit 8634b51 ("locks: convert lease handling to file_lock_context"). This warning has been quite useful for catching bugs, particularly in NFS where lock handling still sees some churn. Let's bring back the warning for leaked locks on __fput, as this warning is much more likely to be seen and reported by users. Signed-off-by: Benjamin Coddington <[email protected]> Signed-off-by: Jeff Layton <[email protected]>
1 parent 9d5b86a commit 3953704

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

fs/locks.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ locks_check_ctx_lists(struct inode *inode)
271271
}
272272
}
273273

274+
static void
275+
locks_check_ctx_file_list(struct file *filp, struct list_head *list,
276+
char *list_type)
277+
{
278+
struct file_lock *fl;
279+
struct inode *inode = locks_inode(filp);
280+
281+
list_for_each_entry(fl, list, fl_list)
282+
if (fl->fl_file == filp)
283+
pr_warn("Leaked %s lock on dev=0x%x:0x%x ino=0x%lx "
284+
" fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n",
285+
list_type, MAJOR(inode->i_sb->s_dev),
286+
MINOR(inode->i_sb->s_dev), inode->i_ino,
287+
fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid);
288+
}
289+
274290
void
275291
locks_free_lock_context(struct inode *inode)
276292
{
@@ -2549,6 +2565,12 @@ void locks_remove_file(struct file *filp)
25492565

25502566
/* remove any leases */
25512567
locks_remove_lease(filp, ctx);
2568+
2569+
spin_lock(&ctx->flc_lock);
2570+
locks_check_ctx_file_list(filp, &ctx->flc_posix, "POSIX");
2571+
locks_check_ctx_file_list(filp, &ctx->flc_flock, "FLOCK");
2572+
locks_check_ctx_file_list(filp, &ctx->flc_lease, "LEASE");
2573+
spin_unlock(&ctx->flc_lock);
25522574
}
25532575

25542576
/**

0 commit comments

Comments
 (0)