Merge branch 'for-3.5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[firefly-linux-kernel-4.4.55.git] / fs / nfs / delegation.c
index 89af1d269274f3a91401f704226dec43f9c02528..bd3a9601d32d9915a70e1888ab5a710671e00aac 100644 (file)
@@ -316,6 +316,10 @@ out:
  * nfs_client_return_marked_delegations - return previously marked delegations
  * @clp: nfs_client to process
  *
+ * Note that this function is designed to be called by the state
+ * manager thread. For this reason, it cannot flush the dirty data,
+ * since that could deadlock in case of a state recovery error.
+ *
  * Returns zero on success, or a negative errno value.
  */
 int nfs_client_return_marked_delegations(struct nfs_client *clp)
@@ -340,11 +344,9 @@ restart:
                                                                server);
                        rcu_read_unlock();
 
-                       if (delegation != NULL) {
-                               filemap_flush(inode->i_mapping);
+                       if (delegation != NULL)
                                err = __nfs_inode_return_delegation(inode,
                                                                delegation, 0);
-                       }
                        iput(inode);
                        if (!err)
                                goto restart;
@@ -380,6 +382,10 @@ void nfs_inode_return_delegation_noreclaim(struct inode *inode)
  * nfs_inode_return_delegation - synchronously return a delegation
  * @inode: inode to process
  *
+ * This routine will always flush any dirty data to disk on the
+ * assumption that if we need to return the delegation, then
+ * we should stop caching.
+ *
  * Returns zero on success, or a negative errno value.
  */
 int nfs_inode_return_delegation(struct inode *inode)
@@ -389,10 +395,10 @@ int nfs_inode_return_delegation(struct inode *inode)
        struct nfs_delegation *delegation;
        int err = 0;
 
+       nfs_wb_all(inode);
        if (rcu_access_pointer(nfsi->delegation) != NULL) {
                delegation = nfs_detach_delegation(nfsi, server);
                if (delegation != NULL) {
-                       nfs_wb_all(inode);
                        err = __nfs_inode_return_delegation(inode, delegation, 1);
                }
        }
@@ -538,6 +544,8 @@ int nfs_async_inode_return_delegation(struct inode *inode,
        struct nfs_client *clp = server->nfs_client;
        struct nfs_delegation *delegation;
 
+       filemap_flush(inode->i_mapping);
+
        rcu_read_lock();
        delegation = rcu_dereference(NFS_I(inode)->delegation);