NFSv4: Simplify nfs4_retry_setlk()
Simplify the code that retries locks based on notification events. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
parent
e49d033bdd
commit
86438186a7
@ -7250,22 +7250,22 @@ nfs4_retry_setlk_simple(struct nfs4_state *state, int cmd,
|
|||||||
|
|
||||||
#ifdef CONFIG_NFS_V4_1
|
#ifdef CONFIG_NFS_V4_1
|
||||||
struct nfs4_lock_waiter {
|
struct nfs4_lock_waiter {
|
||||||
struct task_struct *task;
|
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
struct nfs_lowner *owner;
|
struct nfs_lowner owner;
|
||||||
|
wait_queue_entry_t wait;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, void *key)
|
nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, void *key)
|
||||||
{
|
{
|
||||||
int ret;
|
struct nfs4_lock_waiter *waiter =
|
||||||
struct nfs4_lock_waiter *waiter = wait->private;
|
container_of(wait, struct nfs4_lock_waiter, wait);
|
||||||
|
|
||||||
/* NULL key means to wake up everyone */
|
/* NULL key means to wake up everyone */
|
||||||
if (key) {
|
if (key) {
|
||||||
struct cb_notify_lock_args *cbnl = key;
|
struct cb_notify_lock_args *cbnl = key;
|
||||||
struct nfs_lowner *lowner = &cbnl->cbnl_owner,
|
struct nfs_lowner *lowner = &cbnl->cbnl_owner,
|
||||||
*wowner = waiter->owner;
|
*wowner = &waiter->owner;
|
||||||
|
|
||||||
/* Only wake if the callback was for the same owner. */
|
/* Only wake if the callback was for the same owner. */
|
||||||
if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev)
|
if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev)
|
||||||
@ -7276,53 +7276,45 @@ nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, vo
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* override "private" so we can use default_wake_function */
|
return woken_wake_function(wait, mode, flags, key);
|
||||||
wait->private = waiter->task;
|
|
||||||
ret = woken_wake_function(wait, mode, flags, key);
|
|
||||||
if (ret)
|
|
||||||
list_del_init(&wait->entry);
|
|
||||||
wait->private = waiter;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
|
nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
|
||||||
{
|
{
|
||||||
int status = -ERESTARTSYS;
|
|
||||||
struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
|
struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
|
||||||
struct nfs_server *server = NFS_SERVER(state->inode);
|
struct nfs_server *server = NFS_SERVER(state->inode);
|
||||||
struct nfs_client *clp = server->nfs_client;
|
struct nfs_client *clp = server->nfs_client;
|
||||||
wait_queue_head_t *q = &clp->cl_lock_waitq;
|
wait_queue_head_t *q = &clp->cl_lock_waitq;
|
||||||
struct nfs_lowner owner = { .clientid = clp->cl_clientid,
|
struct nfs4_lock_waiter waiter = {
|
||||||
.id = lsp->ls_seqid.owner_id,
|
.inode = state->inode,
|
||||||
.s_dev = server->s_dev };
|
.owner = { .clientid = clp->cl_clientid,
|
||||||
struct nfs4_lock_waiter waiter = { .task = current,
|
.id = lsp->ls_seqid.owner_id,
|
||||||
.inode = state->inode,
|
.s_dev = server->s_dev },
|
||||||
.owner = &owner};
|
};
|
||||||
wait_queue_entry_t wait;
|
int status;
|
||||||
|
|
||||||
/* Don't bother with waitqueue if we don't expect a callback */
|
/* Don't bother with waitqueue if we don't expect a callback */
|
||||||
if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags))
|
if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags))
|
||||||
return nfs4_retry_setlk_simple(state, cmd, request);
|
return nfs4_retry_setlk_simple(state, cmd, request);
|
||||||
|
|
||||||
init_wait(&wait);
|
init_wait(&waiter.wait);
|
||||||
wait.private = &waiter;
|
waiter.wait.func = nfs4_wake_lock_waiter;
|
||||||
wait.func = nfs4_wake_lock_waiter;
|
add_wait_queue(q, &waiter.wait);
|
||||||
|
|
||||||
while(!signalled()) {
|
do {
|
||||||
add_wait_queue(q, &wait);
|
|
||||||
status = nfs4_proc_setlk(state, cmd, request);
|
status = nfs4_proc_setlk(state, cmd, request);
|
||||||
if ((status != -EAGAIN) || IS_SETLK(cmd)) {
|
if (status != -EAGAIN || IS_SETLK(cmd))
|
||||||
finish_wait(q, &wait);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
status = -ERESTARTSYS;
|
status = -ERESTARTSYS;
|
||||||
freezer_do_not_count();
|
freezer_do_not_count();
|
||||||
wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT);
|
wait_woken(&waiter.wait, TASK_INTERRUPTIBLE,
|
||||||
|
NFS4_LOCK_MAXTIMEOUT);
|
||||||
freezer_count();
|
freezer_count();
|
||||||
finish_wait(q, &wait);
|
} while (!signalled());
|
||||||
}
|
|
||||||
|
remove_wait_queue(q, &waiter.wait);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user