]> git.baikalelectronics.ru Git - kernel.git/commitdiff
NFSv4: Clean up nfs_delegation_reap_expired()
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 27 Feb 2020 14:15:19 +0000 (09:15 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 16 Mar 2020 12:34:30 +0000 (08:34 -0400)
Convert to use nfs_client_for_each_server() for efficiency.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/delegation.c

index cb03ba99ae51789fd984bb75156fe843e2441a19..01974f17afc9e2451271762f0ea85aaa486288b0 100644 (file)
@@ -1222,62 +1222,59 @@ nfs_delegation_test_free_expired(struct inode *inode,
                nfs_remove_bad_delegation(inode, stateid);
 }
 
-/**
- * nfs_reap_expired_delegations - reap expired delegations
- * @clp: nfs_client to process
- *
- * Iterates through all the delegations associated with this server and
- * checks if they have may have been revoked. This function is usually
- * expected to be called in cases where the server may have lost its
- * lease.
- */
-void nfs_reap_expired_delegations(struct nfs_client *clp)
+static int nfs_server_reap_expired_delegations(struct nfs_server *server,
+               void __always_unused *data)
 {
        struct nfs_delegation *delegation;
-       struct nfs_server *server;
        struct inode *inode;
        const struct cred *cred;
        nfs4_stateid stateid;
-
 restart:
        rcu_read_lock();
-       list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
-               list_for_each_entry_rcu(delegation, &server->delegations,
-                                                               super_list) {
-                       if (test_bit(NFS_DELEGATION_INODE_FREEING,
-                                               &delegation->flags) ||
-                           test_bit(NFS_DELEGATION_RETURNING,
-                                               &delegation->flags) ||
-                           test_bit(NFS_DELEGATION_TEST_EXPIRED,
-                                               &delegation->flags) == 0)
-                               continue;
-                       if (!nfs_sb_active(server->super))
-                               break; /* continue in outer loop */
-                       inode = nfs_delegation_grab_inode(delegation);
-                       if (inode == NULL) {
-                               rcu_read_unlock();
-                               nfs_sb_deactive(server->super);
-                               goto restart;
-                       }
-                       cred = get_cred_rcu(delegation->cred);
-                       nfs4_stateid_copy(&stateid, &delegation->stateid);
-                       clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
-                       rcu_read_unlock();
-                       nfs_delegation_test_free_expired(inode, &stateid, cred);
-                       put_cred(cred);
-                       if (nfs4_server_rebooted(clp)) {
-                               nfs_inode_mark_test_expired_delegation(server,inode);
-                               iput(inode);
-                               nfs_sb_deactive(server->super);
-                               return;
-                       }
+restart_locked:
+       list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
+               if (test_bit(NFS_DELEGATION_INODE_FREEING,
+                                       &delegation->flags) ||
+                   test_bit(NFS_DELEGATION_RETURNING,
+                                       &delegation->flags) ||
+                   test_bit(NFS_DELEGATION_TEST_EXPIRED,
+                                       &delegation->flags) == 0)
+                       continue;
+               inode = nfs_delegation_grab_inode(delegation);
+               if (inode == NULL)
+                       goto restart_locked;
+               cred = get_cred_rcu(delegation->cred);
+               nfs4_stateid_copy(&stateid, &delegation->stateid);
+               clear_bit(NFS_DELEGATION_TEST_EXPIRED, &delegation->flags);
+               rcu_read_unlock();
+               nfs_delegation_test_free_expired(inode, &stateid, cred);
+               put_cred(cred);
+               if (!nfs4_server_rebooted(server->nfs_client)) {
                        iput(inode);
-                       nfs_sb_deactive(server->super);
                        cond_resched();
                        goto restart;
                }
+               nfs_inode_mark_test_expired_delegation(server,inode);
+               iput(inode);
+               return -EAGAIN;
        }
        rcu_read_unlock();
+       return 0;
+}
+
+/**
+ * nfs_reap_expired_delegations - reap expired delegations
+ * @clp: nfs_client to process
+ *
+ * Iterates through all the delegations associated with this server and
+ * checks if they have may have been revoked. This function is usually
+ * expected to be called in cases where the server may have lost its
+ * lease.
+ */
+void nfs_reap_expired_delegations(struct nfs_client *clp)
+{
+       nfs_client_for_each_server(clp, nfs_server_reap_expired_delegations,
+                       NULL);
 }
 
 void nfs_inode_find_delegation_state_and_recover(struct inode *inode,