Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

locks: ensure vfs_test_lock() never returns FILE_LOCK_DEFERRED

FILE_LOCK_DEFERRED can be returned when creating or removing a lock, but
not when testing for a lock. This support was explicitly removed in
Commit 09802fd2a8ca ("lockd: rip out deferred lock handling from testlock codepath")

However the test in nlmsvc_testlock() suggests that it *can* be returned,
only nlm cannot handle it.

To aid clarity, remove the test and instead put a similar test and
warning in vfs_test_lock(). If the impossible happens, convert
FILE_LOCK_DEFERRED to -EIO.

Signed-off-by: NeilBrown <neil@brown.name>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

authored by

NeilBrown and committed by
Chuck Lever
96f04d24 4329010a

+14 -7
-4
fs/lockd/svclock.c
··· 641 641 conflock->fl.c.flc_owner = lock->fl.c.flc_owner; 642 642 error = vfs_test_lock(file->f_file[mode], &conflock->fl); 643 643 if (error) { 644 - /* We can't currently deal with deferred test requests */ 645 - if (error == FILE_LOCK_DEFERRED) 646 - WARN_ON_ONCE(1); 647 - 648 644 ret = nlm_lck_denied_nolocks; 649 645 goto out; 650 646 }
+14 -3
fs/locks.c
··· 2253 2253 */ 2254 2254 int vfs_test_lock(struct file *filp, struct file_lock *fl) 2255 2255 { 2256 + int error = 0; 2257 + 2256 2258 WARN_ON_ONCE(fl->fl_ops || fl->fl_lmops); 2257 2259 WARN_ON_ONCE(filp != fl->c.flc_file); 2258 2260 if (filp->f_op->lock) 2259 - return filp->f_op->lock(filp, F_GETLK, fl); 2260 - posix_test_lock(filp, fl); 2261 - return 0; 2261 + error = filp->f_op->lock(filp, F_GETLK, fl); 2262 + else 2263 + posix_test_lock(filp, fl); 2264 + 2265 + /* 2266 + * We don't expect FILE_LOCK_DEFERRED and callers cannot 2267 + * handle it. 2268 + */ 2269 + if (WARN_ON_ONCE(error == FILE_LOCK_DEFERRED)) 2270 + error = -EIO; 2271 + 2272 + return error; 2262 2273 } 2263 2274 EXPORT_SYMBOL_GPL(vfs_test_lock); 2264 2275