diff options
author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2008-01-02 16:27:16 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2008-01-03 09:37:17 -0500 |
commit | e6e21970baff4845de74584e2efc8c964a55d574 (patch) | |
tree | 4a0b5f709ca2892d6babadd47baad7c9f0f8ec7d /fs/nfs | |
parent | bb22629ee87eed5054f8b508dbe7c58abad0a324 (diff) |
NFSv4: Fix open_to_lock_owner sequenceid allocation...
NFSv4 file locking is currently completely broken since it doesn't respect
the OPEN sequencing when it is given an unconfirmed lock_owner and needs to
do an open_to_lock_owner. Worse: it breaks the sunrpc rules by doing a
GFP_KERNEL allocation inside an rpciod callback.
Fix is to preallocate the open seqid structure in nfs4_alloc_lockdata if we
see that the lock_owner is unconfirmed.
Then, in nfs4_lock_prepare() we wait for either the open_seqid, if
the lock_owner is still unconfirmed, or else fall back to waiting on the
standard lock_seqid.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r-- | fs/nfs/nfs4proc.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 571b5ec92132..9e2e1c7291db 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -3331,6 +3331,12 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | |||
3331 | 3331 | ||
3332 | p->arg.fh = NFS_FH(inode); | 3332 | p->arg.fh = NFS_FH(inode); |
3333 | p->arg.fl = &p->fl; | 3333 | p->arg.fl = &p->fl; |
3334 | if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) { | ||
3335 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid); | ||
3336 | if (p->arg.open_seqid == NULL) | ||
3337 | goto out_free; | ||
3338 | |||
3339 | } | ||
3334 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); | 3340 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
3335 | if (p->arg.lock_seqid == NULL) | 3341 | if (p->arg.lock_seqid == NULL) |
3336 | goto out_free; | 3342 | goto out_free; |
@@ -3343,6 +3349,8 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | |||
3343 | memcpy(&p->fl, fl, sizeof(p->fl)); | 3349 | memcpy(&p->fl, fl, sizeof(p->fl)); |
3344 | return p; | 3350 | return p; |
3345 | out_free: | 3351 | out_free: |
3352 | if (p->arg.open_seqid != NULL) | ||
3353 | nfs_free_seqid(p->arg.open_seqid); | ||
3346 | kfree(p); | 3354 | kfree(p); |
3347 | return NULL; | 3355 | return NULL; |
3348 | } | 3356 | } |
@@ -3359,23 +3367,23 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) | |||
3359 | .rpc_cred = sp->so_cred, | 3367 | .rpc_cred = sp->so_cred, |
3360 | }; | 3368 | }; |
3361 | 3369 | ||
3362 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) | ||
3363 | return; | ||
3364 | dprintk("%s: begin!\n", __FUNCTION__); | 3370 | dprintk("%s: begin!\n", __FUNCTION__); |
3365 | /* Do we need to do an open_to_lock_owner? */ | 3371 | /* Do we need to do an open_to_lock_owner? */ |
3366 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { | 3372 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
3367 | data->arg.open_seqid = nfs_alloc_seqid(&sp->so_seqid); | 3373 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
3368 | if (data->arg.open_seqid == NULL) { | 3374 | return; |
3369 | data->rpc_status = -ENOMEM; | ||
3370 | task->tk_action = NULL; | ||
3371 | goto out; | ||
3372 | } | ||
3373 | data->arg.open_stateid = &state->stateid; | 3375 | data->arg.open_stateid = &state->stateid; |
3374 | data->arg.new_lock_owner = 1; | 3376 | data->arg.new_lock_owner = 1; |
3377 | /* Retest in case we raced... */ | ||
3378 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) | ||
3379 | goto do_rpc; | ||
3375 | } | 3380 | } |
3381 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) | ||
3382 | return; | ||
3383 | data->arg.new_lock_owner = 0; | ||
3384 | do_rpc: | ||
3376 | data->timestamp = jiffies; | 3385 | data->timestamp = jiffies; |
3377 | rpc_call_setup(task, &msg, 0); | 3386 | rpc_call_setup(task, &msg, 0); |
3378 | out: | ||
3379 | dprintk("%s: done!, ret = %d\n", __FUNCTION__, data->rpc_status); | 3387 | dprintk("%s: done!, ret = %d\n", __FUNCTION__, data->rpc_status); |
3380 | } | 3388 | } |
3381 | 3389 | ||
@@ -3411,8 +3419,6 @@ static void nfs4_lock_release(void *calldata) | |||
3411 | struct nfs4_lockdata *data = calldata; | 3419 | struct nfs4_lockdata *data = calldata; |
3412 | 3420 | ||
3413 | dprintk("%s: begin!\n", __FUNCTION__); | 3421 | dprintk("%s: begin!\n", __FUNCTION__); |
3414 | if (data->arg.open_seqid != NULL) | ||
3415 | nfs_free_seqid(data->arg.open_seqid); | ||
3416 | if (data->cancelled != 0) { | 3422 | if (data->cancelled != 0) { |
3417 | struct rpc_task *task; | 3423 | struct rpc_task *task; |
3418 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, | 3424 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
@@ -3422,6 +3428,8 @@ static void nfs4_lock_release(void *calldata) | |||
3422 | dprintk("%s: cancelling lock!\n", __FUNCTION__); | 3428 | dprintk("%s: cancelling lock!\n", __FUNCTION__); |
3423 | } else | 3429 | } else |
3424 | nfs_free_seqid(data->arg.lock_seqid); | 3430 | nfs_free_seqid(data->arg.lock_seqid); |
3431 | if (data->arg.open_seqid != NULL) | ||
3432 | nfs_free_seqid(data->arg.open_seqid); | ||
3425 | nfs4_put_lock_state(data->lsp); | 3433 | nfs4_put_lock_state(data->lsp); |
3426 | put_nfs_open_context(data->ctx); | 3434 | put_nfs_open_context(data->ctx); |
3427 | kfree(data); | 3435 | kfree(data); |