aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/nfs4state.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/nfs4state.c')
-rw-r--r--fs/nfs/nfs4state.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 2d5a6a2b9dec..959374d833a7 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -366,6 +366,23 @@ nfs4_alloc_open_state(void)
366 return state; 366 return state;
367} 367}
368 368
369void
370nfs4_state_set_mode_locked(struct nfs4_state *state, mode_t mode)
371{
372 if (state->state == mode)
373 return;
374 /* NB! List reordering - see the reclaim code for why. */
375 if ((mode & FMODE_WRITE) != (state->state & FMODE_WRITE)) {
376 if (mode & FMODE_WRITE)
377 list_move(&state->open_states, &state->owner->so_states);
378 else
379 list_move_tail(&state->open_states, &state->owner->so_states);
380 }
381 if (mode == 0)
382 list_del_init(&state->inode_states);
383 state->state = mode;
384}
385
369static struct nfs4_state * 386static struct nfs4_state *
370__nfs4_find_state(struct inode *inode, struct rpc_cred *cred, mode_t mode) 387__nfs4_find_state(struct inode *inode, struct rpc_cred *cred, mode_t mode)
371{ 388{
@@ -376,10 +393,6 @@ __nfs4_find_state(struct inode *inode, struct rpc_cred *cred, mode_t mode)
376 list_for_each_entry(state, &nfsi->open_states, inode_states) { 393 list_for_each_entry(state, &nfsi->open_states, inode_states) {
377 if (state->owner->so_cred != cred) 394 if (state->owner->so_cred != cred)
378 continue; 395 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) 396 if ((state->state & mode) != mode)
384 continue; 397 continue;
385 atomic_inc(&state->count); 398 atomic_inc(&state->count);
@@ -400,7 +413,7 @@ __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner)
400 413
401 list_for_each_entry(state, &nfsi->open_states, inode_states) { 414 list_for_each_entry(state, &nfsi->open_states, inode_states) {
402 /* Is this in the process of being freed? */ 415 /* Is this in the process of being freed? */
403 if (state->nreaders == 0 && state->nwriters == 0) 416 if (state->state == 0)
404 continue; 417 continue;
405 if (state->owner == owner) { 418 if (state->owner == owner) {
406 atomic_inc(&state->count); 419 atomic_inc(&state->count);
@@ -481,7 +494,6 @@ void nfs4_put_open_state(struct nfs4_state *state)
481 spin_unlock(&inode->i_lock); 494 spin_unlock(&inode->i_lock);
482 spin_unlock(&owner->so_lock); 495 spin_unlock(&owner->so_lock);
483 iput(inode); 496 iput(inode);
484 BUG_ON (state->state != 0);
485 nfs4_free_open_state(state); 497 nfs4_free_open_state(state);
486 nfs4_put_state_owner(owner); 498 nfs4_put_state_owner(owner);
487} 499}
@@ -493,7 +505,7 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode)
493{ 505{
494 struct inode *inode = state->inode; 506 struct inode *inode = state->inode;
495 struct nfs4_state_owner *owner = state->owner; 507 struct nfs4_state_owner *owner = state->owner;
496 int newstate; 508 int oldstate, newstate = 0;
497 509
498 atomic_inc(&owner->so_count); 510 atomic_inc(&owner->so_count);
499 /* Protect against nfs4_find_state() */ 511 /* Protect against nfs4_find_state() */
@@ -503,30 +515,20 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode)
503 state->nreaders--; 515 state->nreaders--;
504 if (mode & FMODE_WRITE) 516 if (mode & FMODE_WRITE)
505 state->nwriters--; 517 state->nwriters--;
506 if (state->nwriters == 0) { 518 oldstate = newstate = state->state;
507 if (state->nreaders == 0) 519 if (state->nreaders == 0)
508 list_del_init(&state->inode_states); 520 newstate &= ~FMODE_READ;
509 /* See reclaim code */ 521 if (state->nwriters == 0)
510 list_move_tail(&state->open_states, &owner->so_states); 522 newstate &= ~FMODE_WRITE;
523 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
524 nfs4_state_set_mode_locked(state, newstate);
525 oldstate = newstate;
511 } 526 }
512 spin_unlock(&inode->i_lock); 527 spin_unlock(&inode->i_lock);
513 spin_unlock(&owner->so_lock); 528 spin_unlock(&owner->so_lock);
514 newstate = 0; 529
515 if (state->state != 0) { 530 if (oldstate != newstate && nfs4_do_close(inode, state) == 0)
516 if (state->nreaders) 531 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 }
529out:
530 nfs4_put_open_state(state); 532 nfs4_put_open_state(state);
531 nfs4_put_state_owner(owner); 533 nfs4_put_state_owner(owner);
532} 534}