diff options
author | J. Bruce Fields <bfields@redhat.com> | 2011-06-29 08:23:50 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2011-07-15 18:58:49 -0400 |
commit | f197c27196a5e7631b89e2e92daa096fcf7c302c (patch) | |
tree | 1f5b3678d323f439d9660187579775c5f01d813f /fs/nfsd | |
parent | 499f3edc23ca0431f3a0a6736b3a40944c81bf3b (diff) |
nfsd4: fix file leak on open_downgrade
Stateid's hold a read reference for a read open, a write reference for a
write open, and an additional one of each for each read+write open. The
latter wasn't getting put on a downgrade, so something like:
open RW
open R
downgrade to R
was resulting in a file leak.
Also fix an imbalance in an error path.
Regression from 7d94784293096c0a46897acdb83be5abd9278ece "nfsd4: fix
downgrade/lock logic".
Cc: stable@kernel.org
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r-- | fs/nfsd/nfs4state.c | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 5e8806a9ef4e..e252aa79c94f 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
@@ -2336,15 +2336,6 @@ out: | |||
2336 | return ret; | 2336 | return ret; |
2337 | } | 2337 | } |
2338 | 2338 | ||
2339 | static inline void | ||
2340 | nfs4_file_downgrade(struct nfs4_file *fp, unsigned int share_access) | ||
2341 | { | ||
2342 | if (share_access & NFS4_SHARE_ACCESS_WRITE) | ||
2343 | nfs4_file_put_access(fp, O_WRONLY); | ||
2344 | if (share_access & NFS4_SHARE_ACCESS_READ) | ||
2345 | nfs4_file_put_access(fp, O_RDONLY); | ||
2346 | } | ||
2347 | |||
2348 | static void nfsd_break_one_deleg(struct nfs4_delegation *dp) | 2339 | static void nfsd_break_one_deleg(struct nfs4_delegation *dp) |
2349 | { | 2340 | { |
2350 | /* We're assuming the state code never drops its reference | 2341 | /* We're assuming the state code never drops its reference |
@@ -2625,7 +2616,7 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c | |||
2625 | status = nfsd4_truncate(rqstp, cur_fh, open); | 2616 | status = nfsd4_truncate(rqstp, cur_fh, open); |
2626 | if (status) { | 2617 | if (status) { |
2627 | if (new_access) { | 2618 | if (new_access) { |
2628 | int oflag = nfs4_access_to_omode(new_access); | 2619 | int oflag = nfs4_access_to_omode(op_share_access); |
2629 | nfs4_file_put_access(fp, oflag); | 2620 | nfs4_file_put_access(fp, oflag); |
2630 | } | 2621 | } |
2631 | return status; | 2622 | return status; |
@@ -3489,18 +3480,15 @@ out: | |||
3489 | return status; | 3480 | return status; |
3490 | } | 3481 | } |
3491 | 3482 | ||
3492 | 3483 | static inline void nfs4_file_downgrade(struct nfs4_stateid *stp, unsigned int to_access) | |
3493 | /* | ||
3494 | * unset all bits in union bitmap (bmap) that | ||
3495 | * do not exist in share (from successful OPEN_DOWNGRADE) | ||
3496 | */ | ||
3497 | static void | ||
3498 | reset_union_bmap_access(unsigned long access, unsigned long *bmap) | ||
3499 | { | 3484 | { |
3500 | int i; | 3485 | int i; |
3486 | |||
3501 | for (i = 1; i < 4; i++) { | 3487 | for (i = 1; i < 4; i++) { |
3502 | if ((i & access) != i) | 3488 | if (test_bit(i, &stp->st_access_bmap) && !(i & to_access)) { |
3503 | __clear_bit(i, bmap); | 3489 | nfs4_file_put_access(stp->st_file, i); |
3490 | __clear_bit(i, &stp->st_access_bmap); | ||
3491 | } | ||
3504 | } | 3492 | } |
3505 | } | 3493 | } |
3506 | 3494 | ||
@@ -3521,7 +3509,6 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp, | |||
3521 | { | 3509 | { |
3522 | __be32 status; | 3510 | __be32 status; |
3523 | struct nfs4_stateid *stp; | 3511 | struct nfs4_stateid *stp; |
3524 | unsigned int share_access; | ||
3525 | 3512 | ||
3526 | dprintk("NFSD: nfsd4_open_downgrade on file %.*s\n", | 3513 | dprintk("NFSD: nfsd4_open_downgrade on file %.*s\n", |
3527 | (int)cstate->current_fh.fh_dentry->d_name.len, | 3514 | (int)cstate->current_fh.fh_dentry->d_name.len, |
@@ -3550,10 +3537,8 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp, | |||
3550 | stp->st_deny_bmap, od->od_share_deny); | 3537 | stp->st_deny_bmap, od->od_share_deny); |
3551 | goto out; | 3538 | goto out; |
3552 | } | 3539 | } |
3553 | set_access(&share_access, stp->st_access_bmap); | 3540 | nfs4_file_downgrade(stp, od->od_share_access); |
3554 | nfs4_file_downgrade(stp->st_file, share_access & ~od->od_share_access); | ||
3555 | 3541 | ||
3556 | reset_union_bmap_access(od->od_share_access, &stp->st_access_bmap); | ||
3557 | reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap); | 3542 | reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap); |
3558 | 3543 | ||
3559 | update_stateid(&stp->st_stateid); | 3544 | update_stateid(&stp->st_stateid); |