]> git.ipfire.org Git - people/ms/linux.git/commitdiff
NFSv4: Ensure we reference the inode for return-on-close in delegreturn
authorTrond Myklebust <trond.myklebust@primarydata.com>
Thu, 5 Feb 2015 20:13:24 +0000 (15:13 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Mar 2015 22:52:58 +0000 (14:52 -0800)
commit ea7c38fef0b774a5dc16fb0ca5935f0ae8568176 upstream.

If we have to do a return-on-close in the delegreturn code, then
we must ensure that the inode and super block remain referenced.

Cc: Peng Tao <tao.peng@primarydata.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Reviewed-by: Peng Tao <tao.peng@primarydata.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfs/internal.h
fs/nfs/nfs4proc.c
fs/nfs/super.c

index efaa31c70fbe1c43d265c51bc542a8270348c339..e1acc1c4ce65771f48b28d0042b75bbb39b50e66 100644 (file)
@@ -377,7 +377,7 @@ extern struct rpc_stat nfs_rpcstat;
 
 extern int __init register_nfs_fs(void);
 extern void __exit unregister_nfs_fs(void);
-extern void nfs_sb_active(struct super_block *sb);
+extern bool nfs_sb_active(struct super_block *sb);
 extern void nfs_sb_deactive(struct super_block *sb);
 
 /* namespace.c */
@@ -495,6 +495,26 @@ extern int nfs41_walk_client_list(struct nfs_client *clp,
                                struct nfs_client **result,
                                struct rpc_cred *cred);
 
+static inline struct inode *nfs_igrab_and_active(struct inode *inode)
+{
+       inode = igrab(inode);
+       if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
+               iput(inode);
+               inode = NULL;
+       }
+       return inode;
+}
+
+static inline void nfs_iput_and_deactive(struct inode *inode)
+{
+       if (inode != NULL) {
+               struct super_block *sb = inode->i_sb;
+
+               iput(inode);
+               nfs_sb_deactive(sb);
+       }
+}
+
 /*
  * Determine the device name as a string
  */
index 83f3a7d7466e0bf936281ec281add3c849a4f219..cd617076aeca5ff77d3d65f047a1d08ecd846c60 100644 (file)
@@ -5130,9 +5130,13 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
 static void nfs4_delegreturn_release(void *calldata)
 {
        struct nfs4_delegreturndata *data = calldata;
+       struct inode *inode = data->inode;
 
-       if (data->roc)
-               pnfs_roc_release(data->inode);
+       if (inode) {
+               if (data->roc)
+                       pnfs_roc_release(inode);
+               nfs_iput_and_deactive(inode);
+       }
        kfree(calldata);
 }
 
@@ -5189,9 +5193,9 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
        nfs_fattr_init(data->res.fattr);
        data->timestamp = jiffies;
        data->rpc_status = 0;
-       data->inode = inode;
-       data->roc = list_empty(&NFS_I(inode)->open_files) ?
-                   pnfs_roc(inode) : false;
+       data->inode = nfs_igrab_and_active(inode);
+       if (data->inode)
+               data->roc = nfs4_roc(inode);
 
        task_setup_data.callback_data = data;
        msg.rpc_argp = &data->args;
index 31a11b0e885debd8706ceaf9e5957702f809a7f0..368d9395d2e7f064c9539ff01d9353659ad5197e 100644 (file)
@@ -405,12 +405,15 @@ void __exit unregister_nfs_fs(void)
        unregister_filesystem(&nfs_fs_type);
 }
 
-void nfs_sb_active(struct super_block *sb)
+bool nfs_sb_active(struct super_block *sb)
 {
        struct nfs_server *server = NFS_SB(sb);
 
-       if (atomic_inc_return(&server->active) == 1)
-               atomic_inc(&sb->s_active);
+       if (!atomic_inc_not_zero(&sb->s_active))
+               return false;
+       if (atomic_inc_return(&server->active) != 1)
+               atomic_dec(&sb->s_active);
+       return true;
 }
 EXPORT_SYMBOL_GPL(nfs_sb_active);