fs/locks: merge posix_unblock_lock() and locks_delete_block()

posix_unblock_lock() is not specific to posix locks, and behaves
nearly identically to locks_delete_block() - the former returning a
status while the later doesn't.

So discard posix_unblock_lock() and use locks_delete_block() instead,
after giving that function an appropriate return value.

Signed-off-by: NeilBrown <neilb@suse.com>
Reviewed-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
This commit is contained in:
NeilBrown 2018-11-30 10:04:08 +11:00 committed by Jeff Layton
parent fd7732e033
commit cb03f94ffb
5 changed files with 21 additions and 31 deletions

View File

@ -1106,7 +1106,7 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock)
rc = wait_event_interruptible(flock->fl_wait, !flock->fl_blocker); rc = wait_event_interruptible(flock->fl_wait, !flock->fl_blocker);
if (!rc) if (!rc)
goto try_again; goto try_again;
posix_unblock_lock(flock); locks_delete_block(flock);
} }
return rc; return rc;
} }

View File

@ -276,7 +276,7 @@ static int nlmsvc_unlink_block(struct nlm_block *block)
dprintk("lockd: unlinking block %p...\n", block); dprintk("lockd: unlinking block %p...\n", block);
/* Remove block from list */ /* Remove block from list */
status = posix_unblock_lock(&block->b_call->a_args.lock.fl); status = locks_delete_block(&block->b_call->a_args.lock.fl);
nlmsvc_remove_block(block); nlmsvc_remove_block(block);
return status; return status;
} }

View File

@ -748,8 +748,16 @@ static void __locks_wake_up_blocks(struct file_lock *blocker)
} }
} }
static void locks_delete_block(struct file_lock *waiter) /**
* locks_delete_lock - stop waiting for a file lock
* @waiter: the lock which was waiting
*
* lockd/nfsd need to disconnect the lock while working on it.
*/
int locks_delete_block(struct file_lock *waiter)
{ {
int status = -ENOENT;
/* /*
* If fl_blocker is NULL, it won't be set again as this thread * If fl_blocker is NULL, it won't be set again as this thread
* "owns" the lock and is the only one that might try to claim * "owns" the lock and is the only one that might try to claim
@ -763,12 +771,16 @@ static void locks_delete_block(struct file_lock *waiter)
*/ */
if (waiter->fl_blocker == NULL && if (waiter->fl_blocker == NULL &&
list_empty(&waiter->fl_blocked_requests)) list_empty(&waiter->fl_blocked_requests))
return; return status;
spin_lock(&blocked_lock_lock); spin_lock(&blocked_lock_lock);
if (waiter->fl_blocker)
status = 0;
__locks_wake_up_blocks(waiter); __locks_wake_up_blocks(waiter);
__locks_delete_block(waiter); __locks_delete_block(waiter);
spin_unlock(&blocked_lock_lock); spin_unlock(&blocked_lock_lock);
return status;
} }
EXPORT_SYMBOL(locks_delete_block);
/* Insert waiter into blocker's block list. /* Insert waiter into blocker's block list.
* We use a circular list so that processes can be easily woken up in * We use a circular list so that processes can be easily woken up in
@ -2675,28 +2687,6 @@ void locks_remove_file(struct file *filp)
spin_unlock(&ctx->flc_lock); spin_unlock(&ctx->flc_lock);
} }
/**
* posix_unblock_lock - stop waiting for a file lock
* @waiter: the lock which was waiting
*
* lockd needs to block waiting for locks.
*/
int
posix_unblock_lock(struct file_lock *waiter)
{
int status = -ENOENT;
spin_lock(&blocked_lock_lock);
if (waiter->fl_blocker) {
__locks_wake_up_blocks(waiter);
__locks_delete_block(waiter);
status = 0;
}
spin_unlock(&blocked_lock_lock);
return status;
}
EXPORT_SYMBOL(posix_unblock_lock);
/** /**
* vfs_cancel_lock - file byte range unblock lock * vfs_cancel_lock - file byte range unblock lock
* @filp: The file to apply the unblock to * @filp: The file to apply the unblock to

View File

@ -238,7 +238,7 @@ find_blocked_lock(struct nfs4_lockowner *lo, struct knfsd_fh *fh,
} }
spin_unlock(&nn->blocked_locks_lock); spin_unlock(&nn->blocked_locks_lock);
if (found) if (found)
posix_unblock_lock(&found->nbl_lock); locks_delete_block(&found->nbl_lock);
return found; return found;
} }
@ -293,7 +293,7 @@ remove_blocked_locks(struct nfs4_lockowner *lo)
nbl = list_first_entry(&reaplist, struct nfsd4_blocked_lock, nbl = list_first_entry(&reaplist, struct nfsd4_blocked_lock,
nbl_lru); nbl_lru);
list_del_init(&nbl->nbl_lru); list_del_init(&nbl->nbl_lru);
posix_unblock_lock(&nbl->nbl_lock); locks_delete_block(&nbl->nbl_lock);
free_blocked_lock(nbl); free_blocked_lock(nbl);
} }
} }
@ -4863,7 +4863,7 @@ nfs4_laundromat(struct nfsd_net *nn)
nbl = list_first_entry(&reaplist, nbl = list_first_entry(&reaplist,
struct nfsd4_blocked_lock, nbl_lru); struct nfsd4_blocked_lock, nbl_lru);
list_del_init(&nbl->nbl_lru); list_del_init(&nbl->nbl_lru);
posix_unblock_lock(&nbl->nbl_lock); locks_delete_block(&nbl->nbl_lock);
free_blocked_lock(nbl); free_blocked_lock(nbl);
} }
out: out:

View File

@ -1124,7 +1124,7 @@ extern void locks_remove_file(struct file *);
extern void locks_release_private(struct file_lock *); extern void locks_release_private(struct file_lock *);
extern void posix_test_lock(struct file *, struct file_lock *); extern void posix_test_lock(struct file *, struct file_lock *);
extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *); extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
extern int posix_unblock_lock(struct file_lock *); extern int locks_delete_block(struct file_lock *);
extern int vfs_test_lock(struct file *, struct file_lock *); extern int vfs_test_lock(struct file *, struct file_lock *);
extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *); extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl); extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
@ -1214,7 +1214,7 @@ static inline int posix_lock_file(struct file *filp, struct file_lock *fl,
return -ENOLCK; return -ENOLCK;
} }
static inline int posix_unblock_lock(struct file_lock *waiter) static inline int locks_delete_block(struct file_lock *waiter)
{ {
return -ENOENT; return -ENOENT;
} }