diff options
| author | J. Bruce Fields <bfields@pad.home.fieldses.org> | 2010-08-07 09:21:41 -0400 |
|---|---|---|
| committer | J. Bruce Fields <bfields@pad.home.fieldses.org> | 2010-08-07 09:50:05 -0400 |
| commit | 998db52c03cd293d16a457f1b396cea932244147 (patch) | |
| tree | 6546b0752c402c458723242e3a03723e2083040b | |
| parent | 7fa53cc872332b265bc5ba1266f39586f218ad4a (diff) | |
nfsd4: fix file open accounting for RDWR opens
Commit f9d7562fdb9dc0ada3a7aba5dbbe9d965e2a105d "nfsd4: share file
descriptors between stateid's" didn't correctly account for O_RDWR opens.
Symptoms include leaked files, resulting in failures to unmount and/or
warnings about orphaned inodes on reboot.
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
| -rw-r--r-- | fs/nfsd/nfs4state.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 0b4351f8238a..0a024917f052 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
| @@ -162,13 +162,22 @@ static struct list_head ownerstr_hashtbl[OWNER_HASH_SIZE]; | |||
| 162 | static struct list_head file_hashtbl[FILE_HASH_SIZE]; | 162 | static struct list_head file_hashtbl[FILE_HASH_SIZE]; |
| 163 | static struct list_head stateid_hashtbl[STATEID_HASH_SIZE]; | 163 | static struct list_head stateid_hashtbl[STATEID_HASH_SIZE]; |
| 164 | 164 | ||
| 165 | static inline void nfs4_file_get_access(struct nfs4_file *fp, int oflag) | 165 | static void __nfs4_file_get_access(struct nfs4_file *fp, int oflag) |
| 166 | { | 166 | { |
| 167 | BUG_ON(!(fp->fi_fds[oflag] || fp->fi_fds[O_RDWR])); | 167 | BUG_ON(!(fp->fi_fds[oflag] || fp->fi_fds[O_RDWR])); |
| 168 | atomic_inc(&fp->fi_access[oflag]); | 168 | atomic_inc(&fp->fi_access[oflag]); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | static inline void nfs4_file_put_fd(struct nfs4_file *fp, int oflag) | 171 | static void nfs4_file_get_access(struct nfs4_file *fp, int oflag) |
| 172 | { | ||
| 173 | if (oflag == O_RDWR) { | ||
| 174 | __nfs4_file_get_access(fp, O_RDONLY); | ||
| 175 | __nfs4_file_get_access(fp, O_WRONLY); | ||
| 176 | } else | ||
| 177 | __nfs4_file_get_access(fp, oflag); | ||
| 178 | } | ||
| 179 | |||
| 180 | static void nfs4_file_put_fd(struct nfs4_file *fp, int oflag) | ||
| 172 | { | 181 | { |
| 173 | if (fp->fi_fds[oflag]) { | 182 | if (fp->fi_fds[oflag]) { |
| 174 | fput(fp->fi_fds[oflag]); | 183 | fput(fp->fi_fds[oflag]); |
| @@ -176,7 +185,7 @@ static inline void nfs4_file_put_fd(struct nfs4_file *fp, int oflag) | |||
| 176 | } | 185 | } |
| 177 | } | 186 | } |
| 178 | 187 | ||
| 179 | static inline void nfs4_file_put_access(struct nfs4_file *fp, int oflag) | 188 | static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag) |
| 180 | { | 189 | { |
| 181 | if (atomic_dec_and_test(&fp->fi_access[oflag])) { | 190 | if (atomic_dec_and_test(&fp->fi_access[oflag])) { |
| 182 | nfs4_file_put_fd(fp, O_RDWR); | 191 | nfs4_file_put_fd(fp, O_RDWR); |
| @@ -184,6 +193,15 @@ static inline void nfs4_file_put_access(struct nfs4_file *fp, int oflag) | |||
| 184 | } | 193 | } |
| 185 | } | 194 | } |
| 186 | 195 | ||
| 196 | static void nfs4_file_put_access(struct nfs4_file *fp, int oflag) | ||
| 197 | { | ||
| 198 | if (oflag == O_RDWR) { | ||
| 199 | __nfs4_file_put_access(fp, O_RDONLY); | ||
| 200 | __nfs4_file_put_access(fp, O_WRONLY); | ||
| 201 | } else | ||
| 202 | __nfs4_file_put_access(fp, oflag); | ||
| 203 | } | ||
| 204 | |||
| 187 | static struct nfs4_delegation * | 205 | static struct nfs4_delegation * |
| 188 | alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_fh *current_fh, u32 type) | 206 | alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_fh *current_fh, u32 type) |
| 189 | { | 207 | { |
