aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/nfs4proc.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2006-01-03 03:55:13 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-01-06 14:58:43 -0500
commite761692381f294ea079d2e869fcd7c0afc79e394 (patch)
tree34ebc00c001cddc94866936c460547d311e5dabb /fs/nfs/nfs4proc.c
parentcdd4e68b5f0ed12c64b3e2be83655d2a47588a74 (diff)
NFSv4: Make nfs4_state track O_RDWR, O_RDONLY and O_WRONLY separately
A closer reading of RFC3530 reveals that OPEN_DOWNGRADE must always specify a access modes that have been the argument of a previous OPEN operation. IOW: doing OPEN(O_RDWR) and then OPEN_DOWNGRADE(O_WRONLY) is forbidden unless the user called OPEN(O_WRONLY) In order to fix that, we really need to track the three possible open states separately. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/nfs4proc.c')
-rw-r--r--fs/nfs/nfs4proc.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 8154f2579469..e494cc2ea986 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -297,6 +297,20 @@ static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
297 return ret; 297 return ret;
298} 298}
299 299
300static inline void update_open_stateflags(struct nfs4_state *state, mode_t open_flags)
301{
302 switch (open_flags) {
303 case FMODE_WRITE:
304 state->n_wronly++;
305 break;
306 case FMODE_READ:
307 state->n_rdonly++;
308 break;
309 case FMODE_READ|FMODE_WRITE:
310 state->n_rdwr++;
311 }
312}
313
300static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags) 314static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags)
301{ 315{
302 struct inode *inode = state->inode; 316 struct inode *inode = state->inode;
@@ -306,10 +320,7 @@ static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid,
306 spin_lock(&state->owner->so_lock); 320 spin_lock(&state->owner->so_lock);
307 spin_lock(&inode->i_lock); 321 spin_lock(&inode->i_lock);
308 memcpy(&state->stateid, stateid, sizeof(state->stateid)); 322 memcpy(&state->stateid, stateid, sizeof(state->stateid));
309 if ((open_flags & FMODE_WRITE)) 323 update_open_stateflags(state, open_flags);
310 state->nwriters++;
311 if (open_flags & FMODE_READ)
312 state->nreaders++;
313 nfs4_state_set_mode_locked(state, state->state | open_flags); 324 nfs4_state_set_mode_locked(state, state->state | open_flags);
314 spin_unlock(&inode->i_lock); 325 spin_unlock(&inode->i_lock);
315 spin_unlock(&state->owner->so_lock); 326 spin_unlock(&state->owner->so_lock);
@@ -822,10 +833,7 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
822 err = -ENOENT; 833 err = -ENOENT;
823 if ((state->state & open_flags) == open_flags) { 834 if ((state->state & open_flags) == open_flags) {
824 spin_lock(&inode->i_lock); 835 spin_lock(&inode->i_lock);
825 if (open_flags & FMODE_READ) 836 update_open_stateflags(state, open_flags);
826 state->nreaders++;
827 if (open_flags & FMODE_WRITE)
828 state->nwriters++;
829 spin_unlock(&inode->i_lock); 837 spin_unlock(&inode->i_lock);
830 goto out_ok; 838 goto out_ok;
831 } else if (state->state != 0) 839 } else if (state->state != 0)
@@ -1082,10 +1090,12 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
1082 spin_lock(&state->owner->so_lock); 1090 spin_lock(&state->owner->so_lock);
1083 spin_lock(&calldata->inode->i_lock); 1091 spin_lock(&calldata->inode->i_lock);
1084 mode = old_mode = state->state; 1092 mode = old_mode = state->state;
1085 if (state->nreaders == 0) 1093 if (state->n_rdwr == 0) {
1086 mode &= ~FMODE_READ; 1094 if (state->n_rdonly == 0)
1087 if (state->nwriters == 0) 1095 mode &= ~FMODE_READ;
1088 mode &= ~FMODE_WRITE; 1096 if (state->n_wronly == 0)
1097 mode &= ~FMODE_WRITE;
1098 }
1089 nfs4_state_set_mode_locked(state, mode); 1099 nfs4_state_set_mode_locked(state, mode);
1090 spin_unlock(&calldata->inode->i_lock); 1100 spin_unlock(&calldata->inode->i_lock);
1091 spin_unlock(&state->owner->so_lock); 1101 spin_unlock(&state->owner->so_lock);