nfsd4: fix file open accounting for RDWR opens
authorJ. Bruce Fields <bfields@pad.home.fieldses.org>
Sat, 7 Aug 2010 13:21:41 +0000 (09:21 -0400)
committerJ. Bruce Fields <bfields@pad.home.fieldses.org>
Sat, 7 Aug 2010 13:50:05 +0000 (09:50 -0400)
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>
fs/nfsd/nfs4state.c

index 0b4351f8238a38f546bf2b44b612cb024dbd8b80..0a024917f0528108074f9999e585d616ad95a97b 100644 (file)
@@ -162,13 +162,22 @@ static struct list_head   ownerstr_hashtbl[OWNER_HASH_SIZE];
 static struct list_head file_hashtbl[FILE_HASH_SIZE];
 static struct list_head stateid_hashtbl[STATEID_HASH_SIZE];
 
-static inline void nfs4_file_get_access(struct nfs4_file *fp, int oflag)
+static void __nfs4_file_get_access(struct nfs4_file *fp, int oflag)
 {
        BUG_ON(!(fp->fi_fds[oflag] || fp->fi_fds[O_RDWR]));
        atomic_inc(&fp->fi_access[oflag]);
 }
 
-static inline void nfs4_file_put_fd(struct nfs4_file *fp, int oflag)
+static void nfs4_file_get_access(struct nfs4_file *fp, int oflag)
+{
+       if (oflag == O_RDWR) {
+               __nfs4_file_get_access(fp, O_RDONLY);
+               __nfs4_file_get_access(fp, O_WRONLY);
+       } else
+               __nfs4_file_get_access(fp, oflag);
+}
+
+static void nfs4_file_put_fd(struct nfs4_file *fp, int oflag)
 {
        if (fp->fi_fds[oflag]) {
                fput(fp->fi_fds[oflag]);
@@ -176,7 +185,7 @@ static inline void nfs4_file_put_fd(struct nfs4_file *fp, int oflag)
        }
 }
 
-static inline void nfs4_file_put_access(struct nfs4_file *fp, int oflag)
+static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag)
 {
        if (atomic_dec_and_test(&fp->fi_access[oflag])) {
                nfs4_file_put_fd(fp, O_RDWR);
@@ -184,6 +193,15 @@ static inline void nfs4_file_put_access(struct nfs4_file *fp, int oflag)
        }
 }
 
+static void nfs4_file_put_access(struct nfs4_file *fp, int oflag)
+{
+       if (oflag == O_RDWR) {
+               __nfs4_file_put_access(fp, O_RDONLY);
+               __nfs4_file_put_access(fp, O_WRONLY);
+       } else
+               __nfs4_file_put_access(fp, oflag);
+}
+
 static struct nfs4_delegation *
 alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_fh *current_fh, u32 type)
 {