aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2011-09-28 11:37:56 -0400
committerJ. Bruce Fields <bfields@redhat.com>2011-10-10 18:04:45 -0400
commit6409a5a65d2b959c3f5e2b8adfa67c349e294652 (patch)
tree82a765fd44662f4c334d0e639aa2e86341b847ba /fs/nfsd
parent71c3bcd71393a9e67d5b77597a612537f89c30ed (diff)
nfsd4: clean up downgrading code
In response to some review comments, get rid of the somewhat obscure for-loop with bitops, and improve a comment. Reported-by: Steve Dickson <steved@redhat.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r--fs/nfsd/nfs4state.c31
-rw-r--r--fs/nfsd/state.h8
2 files changed, 27 insertions, 12 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 8e253a347649..683885b18ceb 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -3523,16 +3523,29 @@ out:
3523 return status; 3523 return status;
3524} 3524}
3525 3525
3526static inline void nfs4_file_downgrade(struct nfs4_ol_stateid *stp, unsigned int to_access) 3526static inline void nfs4_stateid_downgrade_bit(struct nfs4_ol_stateid *stp, u32 access)
3527{ 3527{
3528 int i; 3528 if (!test_bit(access, &stp->st_access_bmap))
3529 return;
3530 nfs4_file_put_access(stp->st_file, nfs4_access_to_omode(access));
3531 __clear_bit(access, &stp->st_access_bmap);
3532}
3529 3533
3530 for (i = 1; i < 4; i++) { 3534static inline void nfs4_stateid_downgrade(struct nfs4_ol_stateid *stp, u32 to_access)
3531 if (test_bit(i, &stp->st_access_bmap) 3535{
3532 && ((i & to_access) != i)) { 3536 switch (to_access) {
3533 nfs4_file_put_access(stp->st_file, nfs4_access_to_omode(i)); 3537 case NFS4_SHARE_ACCESS_READ:
3534 __clear_bit(i, &stp->st_access_bmap); 3538 nfs4_stateid_downgrade_bit(stp, NFS4_SHARE_ACCESS_WRITE);
3535 } 3539 nfs4_stateid_downgrade_bit(stp, NFS4_SHARE_ACCESS_BOTH);
3540 break;
3541 case NFS4_SHARE_ACCESS_WRITE:
3542 nfs4_stateid_downgrade_bit(stp, NFS4_SHARE_ACCESS_READ);
3543 nfs4_stateid_downgrade_bit(stp, NFS4_SHARE_ACCESS_BOTH);
3544 break;
3545 case NFS4_SHARE_ACCESS_BOTH:
3546 break;
3547 default:
3548 BUG();
3536 } 3549 }
3537} 3550}
3538 3551
@@ -3578,7 +3591,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
3578 stp->st_deny_bmap, od->od_share_deny); 3591 stp->st_deny_bmap, od->od_share_deny);
3579 goto out; 3592 goto out;
3580 } 3593 }
3581 nfs4_file_downgrade(stp, od->od_share_access); 3594 nfs4_stateid_downgrade(stp, od->od_share_access);
3582 3595
3583 reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap); 3596 reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap);
3584 3597
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 13f6f9f5ceec..22b065a55ea0 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -403,9 +403,11 @@ struct nfs4_file {
403 /* One each for O_RDONLY, O_WRONLY, O_RDWR: */ 403 /* One each for O_RDONLY, O_WRONLY, O_RDWR: */
404 struct file * fi_fds[3]; 404 struct file * fi_fds[3];
405 /* 405 /*
406 * Each open or lock stateid contributes 1 to either 406 * Each open or lock stateid contributes 0-4 to the counts
407 * fi_access[O_RDONLY], fi_access[O_WRONLY], or both, depending 407 * below depending on which bits are set in st_access_bitmap:
408 * on open or lock mode: 408 * 1 to fi_access[O_RDONLY] if NFS4_SHARE_ACCES_READ is set
409 * + 1 to fi_access[O_WRONLY] if NFS4_SHARE_ACCESS_WRITE is set
410 * + 1 to both of the above if NFS4_SHARE_ACCESS_BOTH is set.
409 */ 411 */
410 atomic_t fi_access[2]; 412 atomic_t fi_access[2];
411 struct file *fi_deleg_file; 413 struct file *fi_deleg_file;