Commit faf5f49c authored by Trond Myklebust's avatar Trond Myklebust

NFSv4: Make NFS clean up byte range locks asynchronously

 Currently we fail to do so if the process was signalled.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 0a8838f9
...@@ -249,6 +249,7 @@ extern void nfs4_put_open_state(struct nfs4_state *); ...@@ -249,6 +249,7 @@ extern void nfs4_put_open_state(struct nfs4_state *);
extern void nfs4_close_state(struct nfs4_state *, mode_t); extern void nfs4_close_state(struct nfs4_state *, mode_t);
extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode); extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
extern void nfs4_schedule_state_recovery(struct nfs4_client *); extern void nfs4_schedule_state_recovery(struct nfs4_client *);
extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t); extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
......
...@@ -58,9 +58,9 @@ ...@@ -58,9 +58,9 @@
static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid); static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid);
static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
static int nfs4_async_handle_error(struct rpc_task *, struct nfs_server *); static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *);
static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception); static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
extern struct rpc_procinfo nfs4_procedures[]; extern struct rpc_procinfo nfs4_procedures[];
...@@ -2422,7 +2422,7 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen ...@@ -2422,7 +2422,7 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
} }
static int static int
nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server) nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server)
{ {
struct nfs4_client *clp = server->nfs4_state; struct nfs4_client *clp = server->nfs4_state;
...@@ -2500,7 +2500,7 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) ...@@ -2500,7 +2500,7 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
/* This is the error handling routine for processes that are allowed /* This is the error handling routine for processes that are allowed
* to sleep. * to sleep.
*/ */
int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
{ {
struct nfs4_client *clp = server->nfs4_state; struct nfs4_client *clp = server->nfs4_state;
int ret = errorcode; int ret = errorcode;
...@@ -2763,68 +2763,127 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl) ...@@ -2763,68 +2763,127 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl)
return res; return res;
} }
static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) struct nfs4_unlockdata {
struct nfs_lockargs arg;
struct nfs_locku_opargs luargs;
struct nfs_lockres res;
struct nfs4_lock_state *lsp;
struct nfs_open_context *ctx;
atomic_t refcount;
struct completion completion;
};
static void nfs4_locku_release_calldata(struct nfs4_unlockdata *calldata)
{ {
struct inode *inode = state->inode; if (atomic_dec_and_test(&calldata->refcount)) {
struct nfs_server *server = NFS_SERVER(inode); nfs_free_seqid(calldata->luargs.seqid);
struct nfs_lockargs arg = { nfs4_put_lock_state(calldata->lsp);
.fh = NFS_FH(inode), put_nfs_open_context(calldata->ctx);
.type = nfs4_lck_type(cmd, request), kfree(calldata);
.offset = request->fl_start, }
.length = nfs4_lck_length(request), }
};
struct nfs_lockres res = { static void nfs4_locku_complete(struct nfs4_unlockdata *calldata)
.server = server, {
}; complete(&calldata->completion);
nfs4_locku_release_calldata(calldata);
}
static void nfs4_locku_done(struct rpc_task *task)
{
struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
nfs_increment_lock_seqid(task->tk_status, calldata->luargs.seqid);
switch (task->tk_status) {
case 0:
memcpy(calldata->lsp->ls_stateid.data,
calldata->res.u.stateid.data,
sizeof(calldata->lsp->ls_stateid.data));
break;
case -NFS4ERR_STALE_STATEID:
case -NFS4ERR_EXPIRED:
nfs4_schedule_state_recovery(calldata->res.server->nfs4_state);
break;
default:
if (nfs4_async_handle_error(task, calldata->res.server) == -EAGAIN) {
rpc_restart_call(task);
return;
}
}
nfs4_locku_complete(calldata);
}
static void nfs4_locku_begin(struct rpc_task *task)
{
struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
.rpc_argp = &arg, .rpc_argp = &calldata->arg,
.rpc_resp = &res, .rpc_resp = &calldata->res,
.rpc_cred = state->owner->so_cred, .rpc_cred = calldata->lsp->ls_state->owner->so_cred,
}; };
int status;
status = nfs_wait_on_sequence(calldata->luargs.seqid, task);
if (status != 0)
return;
if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
nfs4_locku_complete(calldata);
task->tk_exit = NULL;
rpc_exit(task, 0);
return;
}
rpc_call_setup(task, &msg, 0);
}
static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
{
struct nfs4_unlockdata *calldata;
struct inode *inode = state->inode;
struct nfs_server *server = NFS_SERVER(inode);
struct nfs4_lock_state *lsp; struct nfs4_lock_state *lsp;
struct nfs_locku_opargs luargs;
int status; int status;
status = nfs4_set_lock_state(state, request); status = nfs4_set_lock_state(state, request);
if (status != 0) if (status != 0)
goto out; return status;
lsp = request->fl_u.nfs4_fl.owner; lsp = request->fl_u.nfs4_fl.owner;
/* We might have lost the locks! */ /* We might have lost the locks! */
if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0)
goto out; return 0;
luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid); calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
status = -ENOMEM; if (calldata == NULL)
if (luargs.seqid == NULL) return -ENOMEM;
goto out; calldata->luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid);
memcpy(luargs.stateid.data, lsp->ls_stateid.data, sizeof(luargs.stateid.data)); if (calldata->luargs.seqid == NULL) {
arg.u.locku = &luargs; kfree(calldata);
status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); return -ENOMEM;
nfs_increment_lock_seqid(status, luargs.seqid); }
calldata->luargs.stateid = &lsp->ls_stateid;
if (status == 0) calldata->arg.fh = NFS_FH(inode);
memcpy(lsp->ls_stateid.data, res.u.stateid.data, calldata->arg.type = nfs4_lck_type(cmd, request);
sizeof(lsp->ls_stateid.data)); calldata->arg.offset = request->fl_start;
nfs_free_seqid(luargs.seqid); calldata->arg.length = nfs4_lck_length(request);
out: calldata->arg.u.locku = &calldata->luargs;
calldata->res.server = server;
calldata->lsp = lsp;
atomic_inc(&lsp->ls_count);
/* Ensure we don't close file until we're done freeing locks! */
calldata->ctx = get_nfs_open_context((struct nfs_open_context*)request->fl_file->private_data);
atomic_set(&calldata->refcount, 2);
init_completion(&calldata->completion);
status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_locku_begin,
nfs4_locku_done, calldata);
if (status == 0) if (status == 0)
do_vfs_lock(request->fl_file, request); wait_for_completion_interruptible(&calldata->completion);
do_vfs_lock(request->fl_file, request);
nfs4_locku_release_calldata(calldata);
return status; return status;
} }
static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
{
struct nfs4_exception exception = { };
int err;
do {
err = nfs4_handle_exception(NFS_SERVER(state->inode),
_nfs4_proc_unlck(state, cmd, request),
&exception);
} while (exception.retry);
return err;
}
static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim) static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim)
{ {
struct inode *inode = state->inode; struct inode *inode = state->inode;
......
...@@ -600,7 +600,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_ ...@@ -600,7 +600,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_
* Release reference to lock_state, and free it if we see that * Release reference to lock_state, and free it if we see that
* it is no longer in use * it is no longer in use
*/ */
static void nfs4_put_lock_state(struct nfs4_lock_state *lsp) void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
{ {
struct nfs4_state *state; struct nfs4_state *state;
......
...@@ -776,7 +776,7 @@ static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg) ...@@ -776,7 +776,7 @@ static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
WRITE32(OP_LOCKU); WRITE32(OP_LOCKU);
WRITE32(arg->type); WRITE32(arg->type);
WRITE32(opargs->seqid->sequence->counter); WRITE32(opargs->seqid->sequence->counter);
WRITEMEM(&opargs->stateid, sizeof(opargs->stateid)); WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data));
WRITE64(arg->offset); WRITE64(arg->offset);
WRITE64(arg->length); WRITE64(arg->length);
...@@ -1587,9 +1587,6 @@ static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lock ...@@ -1587,9 +1587,6 @@ static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lock
}; };
int status; int status;
status = nfs_wait_on_sequence(args->u.locku->seqid, req->rq_task);
if (status != 0)
goto out;
xdr_init_encode(&xdr, &req->rq_snd_buf, p); xdr_init_encode(&xdr, &req->rq_snd_buf, p);
encode_compound_hdr(&xdr, &hdr); encode_compound_hdr(&xdr, &hdr);
status = encode_putfh(&xdr, args->fh); status = encode_putfh(&xdr, args->fh);
...@@ -2934,8 +2931,8 @@ static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res) ...@@ -2934,8 +2931,8 @@ static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
status = decode_op_hdr(xdr, OP_LOCKU); status = decode_op_hdr(xdr, OP_LOCKU);
if (status == 0) { if (status == 0) {
READ_BUF(sizeof(nfs4_stateid)); READ_BUF(sizeof(res->u.stateid.data));
COPYMEM(&res->u.stateid, sizeof(res->u.stateid)); COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
} }
return status; return status;
} }
......
...@@ -188,7 +188,7 @@ struct nfs_lock_opargs { ...@@ -188,7 +188,7 @@ struct nfs_lock_opargs {
struct nfs_locku_opargs { struct nfs_locku_opargs {
struct nfs_seqid * seqid; struct nfs_seqid * seqid;
nfs4_stateid stateid; nfs4_stateid * stateid;
}; };
struct nfs_lockargs { struct nfs_lockargs {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment