diff options
Diffstat (limited to 'fs/nfs/nfs4state.c')
-rw-r--r-- | fs/nfs/nfs4state.c | 85 |
1 files changed, 27 insertions, 58 deletions
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 2d5a6a2b9dec..52a26baa114c 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c | |||
@@ -366,30 +366,21 @@ nfs4_alloc_open_state(void) | |||
366 | return state; | 366 | return state; |
367 | } | 367 | } |
368 | 368 | ||
369 | static struct nfs4_state * | 369 | void |
370 | __nfs4_find_state(struct inode *inode, struct rpc_cred *cred, mode_t mode) | 370 | nfs4_state_set_mode_locked(struct nfs4_state *state, mode_t mode) |
371 | { | 371 | { |
372 | struct nfs_inode *nfsi = NFS_I(inode); | 372 | if (state->state == mode) |
373 | struct nfs4_state *state; | 373 | return; |
374 | 374 | /* NB! List reordering - see the reclaim code for why. */ | |
375 | mode &= (FMODE_READ|FMODE_WRITE); | 375 | if ((mode & FMODE_WRITE) != (state->state & FMODE_WRITE)) { |
376 | list_for_each_entry(state, &nfsi->open_states, inode_states) { | ||
377 | if (state->owner->so_cred != cred) | ||
378 | continue; | ||
379 | if ((mode & FMODE_READ) != 0 && state->nreaders == 0) | ||
380 | continue; | ||
381 | if ((mode & FMODE_WRITE) != 0 && state->nwriters == 0) | ||
382 | continue; | ||
383 | if ((state->state & mode) != mode) | ||
384 | continue; | ||
385 | atomic_inc(&state->count); | ||
386 | if (mode & FMODE_READ) | ||
387 | state->nreaders++; | ||
388 | if (mode & FMODE_WRITE) | 376 | if (mode & FMODE_WRITE) |
389 | state->nwriters++; | 377 | list_move(&state->open_states, &state->owner->so_states); |
390 | return state; | 378 | else |
379 | list_move_tail(&state->open_states, &state->owner->so_states); | ||
391 | } | 380 | } |
392 | return NULL; | 381 | if (mode == 0) |
382 | list_del_init(&state->inode_states); | ||
383 | state->state = mode; | ||
393 | } | 384 | } |
394 | 385 | ||
395 | static struct nfs4_state * | 386 | static struct nfs4_state * |
@@ -400,7 +391,7 @@ __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner) | |||
400 | 391 | ||
401 | list_for_each_entry(state, &nfsi->open_states, inode_states) { | 392 | list_for_each_entry(state, &nfsi->open_states, inode_states) { |
402 | /* Is this in the process of being freed? */ | 393 | /* Is this in the process of being freed? */ |
403 | if (state->nreaders == 0 && state->nwriters == 0) | 394 | if (state->state == 0) |
404 | continue; | 395 | continue; |
405 | if (state->owner == owner) { | 396 | if (state->owner == owner) { |
406 | atomic_inc(&state->count); | 397 | atomic_inc(&state->count); |
@@ -410,17 +401,6 @@ __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner) | |||
410 | return NULL; | 401 | return NULL; |
411 | } | 402 | } |
412 | 403 | ||
413 | struct nfs4_state * | ||
414 | nfs4_find_state(struct inode *inode, struct rpc_cred *cred, mode_t mode) | ||
415 | { | ||
416 | struct nfs4_state *state; | ||
417 | |||
418 | spin_lock(&inode->i_lock); | ||
419 | state = __nfs4_find_state(inode, cred, mode); | ||
420 | spin_unlock(&inode->i_lock); | ||
421 | return state; | ||
422 | } | ||
423 | |||
424 | static void | 404 | static void |
425 | nfs4_free_open_state(struct nfs4_state *state) | 405 | nfs4_free_open_state(struct nfs4_state *state) |
426 | { | 406 | { |
@@ -481,7 +461,6 @@ void nfs4_put_open_state(struct nfs4_state *state) | |||
481 | spin_unlock(&inode->i_lock); | 461 | spin_unlock(&inode->i_lock); |
482 | spin_unlock(&owner->so_lock); | 462 | spin_unlock(&owner->so_lock); |
483 | iput(inode); | 463 | iput(inode); |
484 | BUG_ON (state->state != 0); | ||
485 | nfs4_free_open_state(state); | 464 | nfs4_free_open_state(state); |
486 | nfs4_put_state_owner(owner); | 465 | nfs4_put_state_owner(owner); |
487 | } | 466 | } |
@@ -493,7 +472,7 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode) | |||
493 | { | 472 | { |
494 | struct inode *inode = state->inode; | 473 | struct inode *inode = state->inode; |
495 | struct nfs4_state_owner *owner = state->owner; | 474 | struct nfs4_state_owner *owner = state->owner; |
496 | int newstate; | 475 | int oldstate, newstate = 0; |
497 | 476 | ||
498 | atomic_inc(&owner->so_count); | 477 | atomic_inc(&owner->so_count); |
499 | /* Protect against nfs4_find_state() */ | 478 | /* Protect against nfs4_find_state() */ |
@@ -503,30 +482,20 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode) | |||
503 | state->nreaders--; | 482 | state->nreaders--; |
504 | if (mode & FMODE_WRITE) | 483 | if (mode & FMODE_WRITE) |
505 | state->nwriters--; | 484 | state->nwriters--; |
506 | if (state->nwriters == 0) { | 485 | oldstate = newstate = state->state; |
507 | if (state->nreaders == 0) | 486 | if (state->nreaders == 0) |
508 | list_del_init(&state->inode_states); | 487 | newstate &= ~FMODE_READ; |
509 | /* See reclaim code */ | 488 | if (state->nwriters == 0) |
510 | list_move_tail(&state->open_states, &owner->so_states); | 489 | newstate &= ~FMODE_WRITE; |
490 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { | ||
491 | nfs4_state_set_mode_locked(state, newstate); | ||
492 | oldstate = newstate; | ||
511 | } | 493 | } |
512 | spin_unlock(&inode->i_lock); | 494 | spin_unlock(&inode->i_lock); |
513 | spin_unlock(&owner->so_lock); | 495 | spin_unlock(&owner->so_lock); |
514 | newstate = 0; | 496 | |
515 | if (state->state != 0) { | 497 | if (oldstate != newstate && nfs4_do_close(inode, state) == 0) |
516 | if (state->nreaders) | 498 | return; |
517 | newstate |= FMODE_READ; | ||
518 | if (state->nwriters) | ||
519 | newstate |= FMODE_WRITE; | ||
520 | if (state->state == newstate) | ||
521 | goto out; | ||
522 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { | ||
523 | state->state = newstate; | ||
524 | goto out; | ||
525 | } | ||
526 | if (nfs4_do_close(inode, state, newstate) == 0) | ||
527 | return; | ||
528 | } | ||
529 | out: | ||
530 | nfs4_put_open_state(state); | 499 | nfs4_put_open_state(state); |
531 | nfs4_put_state_owner(owner); | 500 | nfs4_put_state_owner(owner); |
532 | } | 501 | } |
@@ -815,7 +784,7 @@ static int nfs4_reclaim_locks(struct nfs4_state_recovery_ops *ops, struct nfs4_s | |||
815 | int status = 0; | 784 | int status = 0; |
816 | 785 | ||
817 | for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) { | 786 | for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) { |
818 | if (!(fl->fl_flags & FL_POSIX)) | 787 | if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) |
819 | continue; | 788 | continue; |
820 | if (((struct nfs_open_context *)fl->fl_file->private_data)->state != state) | 789 | if (((struct nfs_open_context *)fl->fl_file->private_data)->state != state) |
821 | continue; | 790 | continue; |
@@ -830,7 +799,7 @@ static int nfs4_reclaim_locks(struct nfs4_state_recovery_ops *ops, struct nfs4_s | |||
830 | case -NFS4ERR_NO_GRACE: | 799 | case -NFS4ERR_NO_GRACE: |
831 | case -NFS4ERR_RECLAIM_BAD: | 800 | case -NFS4ERR_RECLAIM_BAD: |
832 | case -NFS4ERR_RECLAIM_CONFLICT: | 801 | case -NFS4ERR_RECLAIM_CONFLICT: |
833 | /* kill_proc(fl->fl_owner, SIGLOST, 1); */ | 802 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
834 | break; | 803 | break; |
835 | case -NFS4ERR_STALE_CLIENTID: | 804 | case -NFS4ERR_STALE_CLIENTID: |
836 | goto out_err; | 805 | goto out_err; |