Skip to content

Commit 8c3cac5

Browse files
committed
locks: eliminate BUG() call when there's an unexpected lock on file close
A leftover lock on the list is surely a sign of a problem of some sort, but it's not necessarily a reason to panic the box. Instead, just log a warning with some info about the lock, and then delete it like we would any other lock. In the event that the filesystem declares a ->lock f_op, we may end up leaking something, but that's generally preferable to an immediate panic. Acked-by: J. Bruce Fields <bfields@fieldses.org> Signed-off-by: Jeff Layton <jlayton@redhat.com>
1 parent b03dfde commit 8c3cac5

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

‎fs/locks.c‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,16 +2281,28 @@ void locks_remove_flock(struct file *filp)
22812281

22822282
while ((fl = *before) != NULL) {
22832283
if (fl->fl_file == filp) {
2284-
if (IS_FLOCK(fl)) {
2285-
locks_delete_lock(before);
2286-
continue;
2287-
}
22882284
if (IS_LEASE(fl)) {
22892285
lease_modify(before, F_UNLCK);
22902286
continue;
22912287
}
2292-
/* What? */
2293-
BUG();
2288+
2289+
/*
2290+
* There's a leftover lock on the list of a type that
2291+
* we didn't expect to see. Most likely a classic
2292+
* POSIX lock that ended up not getting released
2293+
* properly, or that raced onto the list somehow. Log
2294+
* some info about it and then just remove it from
2295+
* the list.
2296+
*/
2297+
WARN(!IS_FLOCK(fl),
2298+
"leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n",
2299+
MAJOR(inode->i_sb->s_dev),
2300+
MINOR(inode->i_sb->s_dev), inode->i_ino,
2301+
fl->fl_type, fl->fl_flags,
2302+
fl->fl_start, fl->fl_end);
2303+
2304+
locks_delete_lock(before);
2305+
continue;
22942306
}
22952307
before = &fl->fl_next;
22962308
}

0 commit comments

Comments
 (0)