Commit 911d1aaf authored by Trond Myklebust's avatar Trond Myklebust

NFSv4: locking XDR cleanup

 Get rid of some unnecessary intermediate structures
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 864472e9
...@@ -2935,43 +2935,17 @@ nfs4_set_lock_task_retry(unsigned long timeout) ...@@ -2935,43 +2935,17 @@ nfs4_set_lock_task_retry(unsigned long timeout)
return timeout; return timeout;
} }
static inline int
nfs4_lck_type(int cmd, struct file_lock *request)
{
/* set lock type */
switch (request->fl_type) {
case F_RDLCK:
return IS_SETLKW(cmd) ? NFS4_READW_LT : NFS4_READ_LT;
case F_WRLCK:
return IS_SETLKW(cmd) ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
case F_UNLCK:
return NFS4_WRITE_LT;
}
BUG();
return 0;
}
static inline uint64_t
nfs4_lck_length(struct file_lock *request)
{
if (request->fl_end == OFFSET_MAX)
return ~(uint64_t)0;
return request->fl_end - request->fl_start + 1;
}
static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
{ {
struct inode *inode = state->inode; struct inode *inode = state->inode;
struct nfs_server *server = NFS_SERVER(inode); struct nfs_server *server = NFS_SERVER(inode);
struct nfs4_client *clp = server->nfs4_state; struct nfs4_client *clp = server->nfs4_state;
struct nfs_lockargs arg = { struct nfs_lockt_args arg = {
.fh = NFS_FH(inode), .fh = NFS_FH(inode),
.type = nfs4_lck_type(cmd, request), .fl = request,
.offset = request->fl_start,
.length = nfs4_lck_length(request),
}; };
struct nfs_lockres res = { struct nfs_lockt_res res = {
.server = server, .denied = request,
}; };
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
...@@ -2979,36 +2953,23 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock ...@@ -2979,36 +2953,23 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
.rpc_resp = &res, .rpc_resp = &res,
.rpc_cred = state->owner->so_cred, .rpc_cred = state->owner->so_cred,
}; };
struct nfs_lowner nlo;
struct nfs4_lock_state *lsp; struct nfs4_lock_state *lsp;
int status; int status;
down_read(&clp->cl_sem); down_read(&clp->cl_sem);
nlo.clientid = clp->cl_clientid; arg.lock_owner.clientid = clp->cl_clientid;
status = nfs4_set_lock_state(state, request); status = nfs4_set_lock_state(state, request);
if (status != 0) if (status != 0)
goto out; goto out;
lsp = request->fl_u.nfs4_fl.owner; lsp = request->fl_u.nfs4_fl.owner;
nlo.id = lsp->ls_id; arg.lock_owner.id = lsp->ls_id;
arg.u.lockt = &nlo;
status = rpc_call_sync(server->client, &msg, 0); status = rpc_call_sync(server->client, &msg, 0);
if (!status) { switch (status) {
request->fl_type = F_UNLCK; case 0:
} else if (status == -NFS4ERR_DENIED) { request->fl_type = F_UNLCK;
int64_t len, start, end; break;
start = res.u.denied.offset; case -NFS4ERR_DENIED:
len = res.u.denied.length; status = 0;
end = start + len - 1;
if (end < 0 || len == 0)
request->fl_end = OFFSET_MAX;
else
request->fl_end = (loff_t)end;
request->fl_start = (loff_t)start;
request->fl_type = F_WRLCK;
if (res.u.denied.type & 1)
request->fl_type = F_RDLCK;
request->fl_pid = 0;
status = 0;
} }
out: out:
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
...@@ -3048,17 +3009,42 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl) ...@@ -3048,17 +3009,42 @@ static int do_vfs_lock(struct file *file, struct file_lock *fl)
} }
struct nfs4_unlockdata { struct nfs4_unlockdata {
struct nfs_lockargs arg; struct nfs_locku_args arg;
struct nfs_locku_opargs luargs; struct nfs_locku_res res;
struct nfs_lockres res;
struct nfs4_lock_state *lsp; struct nfs4_lock_state *lsp;
struct nfs_open_context *ctx; struct nfs_open_context *ctx;
struct file_lock fl;
const struct nfs_server *server;
}; };
static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
struct nfs_open_context *ctx,
struct nfs4_lock_state *lsp,
struct nfs_seqid *seqid)
{
struct nfs4_unlockdata *p;
struct inode *inode = lsp->ls_state->inode;
p = kmalloc(sizeof(*p), GFP_KERNEL);
if (p == NULL)
return NULL;
p->arg.fh = NFS_FH(inode);
p->arg.fl = &p->fl;
p->arg.seqid = seqid;
p->arg.stateid = &lsp->ls_stateid;
p->lsp = lsp;
atomic_inc(&lsp->ls_count);
/* Ensure we don't close file until we're done freeing locks! */
p->ctx = get_nfs_open_context(ctx);
memcpy(&p->fl, fl, sizeof(p->fl));
p->server = NFS_SERVER(inode);
return p;
}
static void nfs4_locku_release_calldata(void *data) static void nfs4_locku_release_calldata(void *data)
{ {
struct nfs4_unlockdata *calldata = data; struct nfs4_unlockdata *calldata = data;
nfs_free_seqid(calldata->luargs.seqid); nfs_free_seqid(calldata->arg.seqid);
nfs4_put_lock_state(calldata->lsp); nfs4_put_lock_state(calldata->lsp);
put_nfs_open_context(calldata->ctx); put_nfs_open_context(calldata->ctx);
kfree(calldata); kfree(calldata);
...@@ -3070,19 +3056,19 @@ static void nfs4_locku_done(struct rpc_task *task, void *data) ...@@ -3070,19 +3056,19 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
if (RPC_ASSASSINATED(task)) if (RPC_ASSASSINATED(task))
return; return;
nfs_increment_lock_seqid(task->tk_status, calldata->luargs.seqid); nfs_increment_lock_seqid(task->tk_status, calldata->arg.seqid);
switch (task->tk_status) { switch (task->tk_status) {
case 0: case 0:
memcpy(calldata->lsp->ls_stateid.data, memcpy(calldata->lsp->ls_stateid.data,
calldata->res.u.stateid.data, calldata->res.stateid.data,
sizeof(calldata->lsp->ls_stateid.data)); sizeof(calldata->lsp->ls_stateid.data));
break; break;
case -NFS4ERR_STALE_STATEID: case -NFS4ERR_STALE_STATEID:
case -NFS4ERR_EXPIRED: case -NFS4ERR_EXPIRED:
nfs4_schedule_state_recovery(calldata->res.server->nfs4_state); nfs4_schedule_state_recovery(calldata->server->nfs4_state);
break; break;
default: default:
if (nfs4_async_handle_error(task, calldata->res.server) == -EAGAIN) { if (nfs4_async_handle_error(task, calldata->server) == -EAGAIN) {
rpc_restart_call(task); rpc_restart_call(task);
} }
} }
...@@ -3097,10 +3083,8 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data) ...@@ -3097,10 +3083,8 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data)
.rpc_resp = &calldata->res, .rpc_resp = &calldata->res,
.rpc_cred = calldata->lsp->ls_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 (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
if (status != 0)
return; return;
if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
/* Note: exit _without_ running nfs4_locku_done */ /* Note: exit _without_ running nfs4_locku_done */
...@@ -3121,43 +3105,32 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock * ...@@ -3121,43 +3105,32 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
struct nfs4_unlockdata *calldata; struct nfs4_unlockdata *calldata;
struct inode *inode = state->inode; struct inode *inode = state->inode;
struct nfs_server *server = NFS_SERVER(inode); struct nfs_server *server = NFS_SERVER(inode);
struct nfs_seqid *seqid;
struct nfs4_lock_state *lsp; struct nfs4_lock_state *lsp;
struct rpc_task *task; struct rpc_task *task;
int status = 0; int status = 0;
/* Is this a delegated lock? */ /* Is this a delegated lock? */
if (test_bit(NFS_DELEGATED_STATE, &state->flags)) if (test_bit(NFS_DELEGATED_STATE, &state->flags))
goto out; goto out_unlock;
/* Is this open_owner holding any locks on the server? */
if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
goto out_unlock;
status = nfs4_set_lock_state(state, request); status = nfs4_set_lock_state(state, request);
if (status != 0) if (status != 0)
goto out; goto out_unlock;
lsp = request->fl_u.nfs4_fl.owner; lsp = request->fl_u.nfs4_fl.owner;
/* We might have lost the locks! */
if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0)
goto out;
status = -ENOMEM; status = -ENOMEM;
calldata = kmalloc(sizeof(*calldata), GFP_KERNEL); seqid = nfs_alloc_seqid(&lsp->ls_seqid);
if (seqid == NULL)
goto out_unlock;
calldata = nfs4_alloc_unlockdata(request, request->fl_file->private_data,
lsp, seqid);
if (calldata == NULL) if (calldata == NULL)
goto out; goto out_free_seqid;
calldata->luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid); /* Unlock _before_ we do the RPC call */
if (calldata->luargs.seqid == NULL) { do_vfs_lock(request->fl_file, request);
kfree(calldata);
goto out;
}
calldata->luargs.stateid = &lsp->ls_stateid;
calldata->arg.fh = NFS_FH(inode);
calldata->arg.type = nfs4_lck_type(cmd, request);
calldata->arg.offset = request->fl_start;
calldata->arg.length = nfs4_lck_length(request);
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);
task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_locku_ops, calldata); task = rpc_run_task(server->client, RPC_TASK_ASYNC, &nfs4_locku_ops, calldata);
if (!IS_ERR(task)) { if (!IS_ERR(task)) {
status = nfs4_wait_for_completion_rpc_task(task); status = nfs4_wait_for_completion_rpc_task(task);
...@@ -3166,7 +3139,10 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock * ...@@ -3166,7 +3139,10 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
status = PTR_ERR(task); status = PTR_ERR(task);
nfs4_locku_release_calldata(calldata); nfs4_locku_release_calldata(calldata);
} }
out: return status;
out_free_seqid:
nfs_free_seqid(seqid);
out_unlock:
do_vfs_lock(request->fl_file, request); do_vfs_lock(request->fl_file, request);
return status; return status;
} }
...@@ -3176,27 +3152,19 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r ...@@ -3176,27 +3152,19 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r
struct inode *inode = state->inode; struct inode *inode = state->inode;
struct nfs_server *server = NFS_SERVER(inode); struct nfs_server *server = NFS_SERVER(inode);
struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
struct nfs_lock_opargs largs = { struct nfs_lock_args arg = {
.fh = NFS_FH(inode),
.fl = request,
.lock_stateid = &lsp->ls_stateid, .lock_stateid = &lsp->ls_stateid,
.open_stateid = &state->stateid, .open_stateid = &state->stateid,
.lock_owner = { .lock_owner = {
.clientid = server->nfs4_state->cl_clientid, .clientid = server->nfs4_state->cl_clientid,
.id = lsp->ls_id, .id = lsp->ls_id,
}, },
.block = (IS_SETLKW(cmd)) ? 1 : 0,
.reclaim = reclaim, .reclaim = reclaim,
}; };
struct nfs_lockargs arg = { struct nfs_lock_res res;
.fh = NFS_FH(inode),
.type = nfs4_lck_type(cmd, request),
.offset = request->fl_start,
.length = nfs4_lck_length(request),
.u = {
.lock = &largs,
},
};
struct nfs_lockres res = {
.server = server,
};
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
.rpc_argp = &arg, .rpc_argp = &arg,
...@@ -3205,37 +3173,37 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r ...@@ -3205,37 +3173,37 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r
}; };
int status = -ENOMEM; int status = -ENOMEM;
largs.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
if (largs.lock_seqid == NULL) if (arg.lock_seqid == NULL)
return -ENOMEM; return -ENOMEM;
if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) { if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) {
struct nfs4_state_owner *owner = state->owner; struct nfs4_state_owner *owner = state->owner;
largs.open_seqid = nfs_alloc_seqid(&owner->so_seqid); arg.open_seqid = nfs_alloc_seqid(&owner->so_seqid);
if (largs.open_seqid == NULL) if (arg.open_seqid == NULL)
goto out; goto out;
largs.new_lock_owner = 1; arg.new_lock_owner = 1;
status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
/* increment open seqid on success, and seqid mutating errors */ /* increment open seqid on success, and seqid mutating errors */
if (largs.new_lock_owner != 0) { if (arg.new_lock_owner != 0) {
nfs_increment_open_seqid(status, largs.open_seqid); nfs_increment_open_seqid(status, arg.open_seqid);
if (status == 0) if (status == 0)
nfs_confirm_seqid(&lsp->ls_seqid, 0); nfs_confirm_seqid(&lsp->ls_seqid, 0);
} }
nfs_free_seqid(largs.open_seqid); nfs_free_seqid(arg.open_seqid);
} else } else
status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
/* increment lock seqid on success, and seqid mutating errors*/ /* increment lock seqid on success, and seqid mutating errors*/
nfs_increment_lock_seqid(status, largs.lock_seqid); nfs_increment_lock_seqid(status, arg.lock_seqid);
/* save the returned stateid. */ /* save the returned stateid. */
if (status == 0) { if (status == 0) {
memcpy(lsp->ls_stateid.data, res.u.stateid.data, memcpy(lsp->ls_stateid.data, res.stateid.data,
sizeof(lsp->ls_stateid.data)); sizeof(lsp->ls_stateid.data));
lsp->ls_flags |= NFS_LOCK_INITIALIZED; lsp->ls_flags |= NFS_LOCK_INITIALIZED;
} else if (status == -NFS4ERR_DENIED) } else if (status == -NFS4ERR_DENIED)
status = -EAGAIN; status = -EAGAIN;
out: out:
nfs_free_seqid(largs.lock_seqid); nfs_free_seqid(arg.lock_seqid);
return status; return status;
} }
......
...@@ -742,69 +742,80 @@ static int encode_link(struct xdr_stream *xdr, const struct qstr *name) ...@@ -742,69 +742,80 @@ static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
return 0; return 0;
} }
static inline int nfs4_lock_type(struct file_lock *fl, int block)
{
if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
return block ? NFS4_READW_LT : NFS4_READ_LT;
return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
}
static inline uint64_t nfs4_lock_length(struct file_lock *fl)
{
if (fl->fl_end == OFFSET_MAX)
return ~(uint64_t)0;
return fl->fl_end - fl->fl_start + 1;
}
/* /*
* opcode,type,reclaim,offset,length,new_lock_owner = 32 * opcode,type,reclaim,offset,length,new_lock_owner = 32
* open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
*/ */
static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg) static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
{ {
uint32_t *p; uint32_t *p;
struct nfs_lock_opargs *opargs = arg->u.lock;
RESERVE_SPACE(32); RESERVE_SPACE(32);
WRITE32(OP_LOCK); WRITE32(OP_LOCK);
WRITE32(arg->type); WRITE32(nfs4_lock_type(args->fl, args->block));
WRITE32(opargs->reclaim); WRITE32(args->reclaim);
WRITE64(arg->offset); WRITE64(args->fl->fl_start);
WRITE64(arg->length); WRITE64(nfs4_lock_length(args->fl));
WRITE32(opargs->new_lock_owner); WRITE32(args->new_lock_owner);
if (opargs->new_lock_owner){ if (args->new_lock_owner){
RESERVE_SPACE(40); RESERVE_SPACE(40);
WRITE32(opargs->open_seqid->sequence->counter); WRITE32(args->open_seqid->sequence->counter);
WRITEMEM(opargs->open_stateid->data, sizeof(opargs->open_stateid->data)); WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
WRITE32(opargs->lock_seqid->sequence->counter); WRITE32(args->lock_seqid->sequence->counter);
WRITE64(opargs->lock_owner.clientid); WRITE64(args->lock_owner.clientid);
WRITE32(4); WRITE32(4);
WRITE32(opargs->lock_owner.id); WRITE32(args->lock_owner.id);
} }
else { else {
RESERVE_SPACE(20); RESERVE_SPACE(20);
WRITEMEM(opargs->lock_stateid->data, sizeof(opargs->lock_stateid->data)); WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
WRITE32(opargs->lock_seqid->sequence->counter); WRITE32(args->lock_seqid->sequence->counter);
} }
return 0; return 0;
} }
static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg) static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
{ {
uint32_t *p; uint32_t *p;
struct nfs_lowner *opargs = arg->u.lockt;
RESERVE_SPACE(40); RESERVE_SPACE(40);
WRITE32(OP_LOCKT); WRITE32(OP_LOCKT);
WRITE32(arg->type); WRITE32(nfs4_lock_type(args->fl, 0));
WRITE64(arg->offset); WRITE64(args->fl->fl_start);
WRITE64(arg->length); WRITE64(nfs4_lock_length(args->fl));
WRITE64(opargs->clientid); WRITE64(args->lock_owner.clientid);
WRITE32(4); WRITE32(4);
WRITE32(opargs->id); WRITE32(args->lock_owner.id);
return 0; return 0;
} }
static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg) static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
{ {
uint32_t *p; uint32_t *p;
struct nfs_locku_opargs *opargs = arg->u.locku;
RESERVE_SPACE(44); RESERVE_SPACE(44);
WRITE32(OP_LOCKU); WRITE32(OP_LOCKU);
WRITE32(arg->type); WRITE32(nfs4_lock_type(args->fl, 0));
WRITE32(opargs->seqid->sequence->counter); WRITE32(args->seqid->sequence->counter);
WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data)); WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
WRITE64(arg->offset); WRITE64(args->fl->fl_start);
WRITE64(arg->length); WRITE64(nfs4_lock_length(args->fl));
return 0; return 0;
} }
...@@ -1596,21 +1607,20 @@ out: ...@@ -1596,21 +1607,20 @@ out:
/* /*
* Encode a LOCK request * Encode a LOCK request
*/ */
static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args) static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lock_args *args)
{ {
struct xdr_stream xdr; struct xdr_stream xdr;
struct compound_hdr hdr = { struct compound_hdr hdr = {
.nops = 2, .nops = 2,
}; };
struct nfs_lock_opargs *opargs = args->u.lock;
int status; int status;
status = nfs_wait_on_sequence(opargs->lock_seqid, req->rq_task); status = nfs_wait_on_sequence(args->lock_seqid, req->rq_task);
if (status != 0) if (status != 0)
goto out; goto out;
/* Do we need to do an open_to_lock_owner? */ /* Do we need to do an open_to_lock_owner? */
if (opargs->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED) if (args->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)
opargs->new_lock_owner = 0; args->new_lock_owner = 0;
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);
...@@ -1624,7 +1634,7 @@ out: ...@@ -1624,7 +1634,7 @@ out:
/* /*
* Encode a LOCKT request * Encode a LOCKT request
*/ */
static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args) static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockt_args *args)
{ {
struct xdr_stream xdr; struct xdr_stream xdr;
struct compound_hdr hdr = { struct compound_hdr hdr = {
...@@ -1645,7 +1655,7 @@ out: ...@@ -1645,7 +1655,7 @@ out:
/* /*
* Encode a LOCKU request * Encode a LOCKU request
*/ */
static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args) static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_locku_args *args)
{ {
struct xdr_stream xdr; struct xdr_stream xdr;
struct compound_hdr hdr = { struct compound_hdr hdr = {
...@@ -2949,55 +2959,64 @@ static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo) ...@@ -2949,55 +2959,64 @@ static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
/* /*
* We create the owner, so we know a proper owner.id length is 4. * We create the owner, so we know a proper owner.id length is 4.
*/ */
static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied) static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
{ {
uint64_t offset, length, clientid;
uint32_t *p; uint32_t *p;
uint32_t namelen; uint32_t namelen, type;
READ_BUF(32); READ_BUF(32);
READ64(denied->offset); READ64(offset);
READ64(denied->length); READ64(length);
READ32(denied->type); READ32(type);
READ64(denied->owner.clientid); if (fl != NULL) {
fl->fl_start = (loff_t)offset;
fl->fl_end = fl->fl_start + (loff_t)length - 1;
if (length == ~(uint64_t)0)
fl->fl_end = OFFSET_MAX;
fl->fl_type = F_WRLCK;
if (type & 1)
fl->fl_type = F_RDLCK;
fl->fl_pid = 0;
}
READ64(clientid);
READ32(namelen); READ32(namelen);
READ_BUF(namelen); READ_BUF(namelen);
if (namelen == 4)
READ32(denied->owner.id);
return -NFS4ERR_DENIED; return -NFS4ERR_DENIED;
} }
static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res) static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
{ {
uint32_t *p; uint32_t *p;
int status; int status;
status = decode_op_hdr(xdr, OP_LOCK); status = decode_op_hdr(xdr, OP_LOCK);
if (status == 0) { if (status == 0) {
READ_BUF(sizeof(res->u.stateid.data)); READ_BUF(sizeof(res->stateid.data));
COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data)); COPYMEM(res->stateid.data, sizeof(res->stateid.data));
} else if (status == -NFS4ERR_DENIED) } else if (status == -NFS4ERR_DENIED)
return decode_lock_denied(xdr, &res->u.denied); return decode_lock_denied(xdr, NULL);
return status; return status;
} }
static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res) static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
{ {
int status; int status;
status = decode_op_hdr(xdr, OP_LOCKT); status = decode_op_hdr(xdr, OP_LOCKT);
if (status == -NFS4ERR_DENIED) if (status == -NFS4ERR_DENIED)
return decode_lock_denied(xdr, &res->u.denied); return decode_lock_denied(xdr, res->denied);
return status; return status;
} }
static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res) static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
{ {
uint32_t *p; uint32_t *p;
int status; int status;
status = decode_op_hdr(xdr, OP_LOCKU); status = decode_op_hdr(xdr, OP_LOCKU);
if (status == 0) { if (status == 0) {
READ_BUF(sizeof(res->u.stateid.data)); READ_BUF(sizeof(res->stateid.data));
COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data)); COPYMEM(res->stateid.data, sizeof(res->stateid.data));
} }
return status; return status;
} }
...@@ -3861,7 +3880,7 @@ out: ...@@ -3861,7 +3880,7 @@ out:
/* /*
* Decode LOCK response * Decode LOCK response
*/ */
static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res) static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lock_res *res)
{ {
struct xdr_stream xdr; struct xdr_stream xdr;
struct compound_hdr hdr; struct compound_hdr hdr;
...@@ -3882,7 +3901,7 @@ out: ...@@ -3882,7 +3901,7 @@ out:
/* /*
* Decode LOCKT response * Decode LOCKT response
*/ */
static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res) static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockt_res *res)
{ {
struct xdr_stream xdr; struct xdr_stream xdr;
struct compound_hdr hdr; struct compound_hdr hdr;
...@@ -3903,7 +3922,7 @@ out: ...@@ -3903,7 +3922,7 @@ out:
/* /*
* Decode LOCKU response * Decode LOCKU response
*/ */
static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res) static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_locku_res *res)
{ {
struct xdr_stream xdr; struct xdr_stream xdr;
struct compound_hdr hdr; struct compound_hdr hdr;
......
...@@ -165,50 +165,46 @@ struct nfs_closeres { ...@@ -165,50 +165,46 @@ struct nfs_closeres {
* * Arguments to the lock,lockt, and locku call. * * Arguments to the lock,lockt, and locku call.
* */ * */
struct nfs_lowner { struct nfs_lowner {
__u64 clientid; __u64 clientid;
u32 id; u32 id;
}; };
struct nfs_lock_opargs { struct nfs_lock_args {
struct nfs_fh * fh;
struct file_lock * fl;
struct nfs_seqid * lock_seqid; struct nfs_seqid * lock_seqid;
nfs4_stateid * lock_stateid; nfs4_stateid * lock_stateid;
struct nfs_seqid * open_seqid; struct nfs_seqid * open_seqid;
nfs4_stateid * open_stateid; nfs4_stateid * open_stateid;
struct nfs_lowner lock_owner; struct nfs_lowner lock_owner;
__u32 reclaim; unsigned char block : 1;
__u32 new_lock_owner; unsigned char reclaim : 1;
unsigned char new_lock_owner : 1;
};
struct nfs_lock_res {
nfs4_stateid stateid;
}; };
struct nfs_locku_opargs { struct nfs_locku_args {
struct nfs_fh * fh;
struct file_lock * fl;
struct nfs_seqid * seqid; struct nfs_seqid * seqid;
nfs4_stateid * stateid; nfs4_stateid * stateid;
}; };
struct nfs_lockargs { struct nfs_locku_res {
struct nfs_fh * fh; nfs4_stateid stateid;
__u32 type;
__u64 offset;
__u64 length;
union {
struct nfs_lock_opargs *lock; /* LOCK */
struct nfs_lowner *lockt; /* LOCKT */
struct nfs_locku_opargs *locku; /* LOCKU */
} u;
}; };
struct nfs_lock_denied { struct nfs_lockt_args {
__u64 offset; struct nfs_fh * fh;
__u64 length; struct file_lock * fl;
__u32 type; struct nfs_lowner lock_owner;
struct nfs_lowner owner;
}; };
struct nfs_lockres { struct nfs_lockt_res {
union { struct file_lock * denied; /* LOCK, LOCKT failed */
nfs4_stateid stateid;/* LOCK success, LOCKU */
struct nfs_lock_denied denied; /* LOCK failed, LOCKT success */
} u;
const struct nfs_server * server;
}; };
struct nfs4_delegreturnargs { struct nfs4_delegreturnargs {
......
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