NFSD: Clean up forgetting clients
authorBryan Schumaker <bjschuma@netapp.com>
Thu, 29 Nov 2012 16:40:39 +0000 (11:40 -0500)
committerJ. Bruce Fields <bfields@redhat.com>
Mon, 3 Dec 2012 14:58:55 +0000 (09:58 -0500)
I added in a generic for-each loop that takes a pass over the client_lru
list for the current net namespace and calls some function.  The next few
patches will update other operations to use this function as well.  A value
of 0 still means "forget everything that is found".

Signed-off-by: Bryan Schumaker <bjschuma@netapp.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/netns.h
fs/nfsd/nfs4state.c

index 2c4b2e2..964b554 100644 (file)
@@ -92,5 +92,8 @@ struct nfsd_net {
        time_t nfsd4_grace;
 };
 
+/* Simple check to find out if a given net was properly initialized */
+#define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
+
 extern int nfsd_net_id;
 #endif /* __NFSD_NETNS_H__ */
index 8e19c69..2478c89 100644 (file)
@@ -4605,19 +4605,34 @@ nfs4_check_open_reclaim(clientid_t *clid, bool sessions, struct nfsd_net *nn)
 
 #ifdef CONFIG_NFSD_FAULT_INJECTION
 
-void nfsd_forget_clients(u64 num)
+u64 nfsd_forget_client(struct nfs4_client *clp, u64 max)
+{
+       expire_client(clp);
+       return 1;
+}
+
+u64 nfsd_for_n_state(u64 max, u64 (*func)(struct nfs4_client *, u64))
 {
        struct nfs4_client *clp, *next;
-       int count = 0;
+       u64 count = 0;
        struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, nfsd_net_id);
 
+       if (!nfsd_netns_ready(nn))
+               return 0;
+
        list_for_each_entry_safe(clp, next, &nn->client_lru, cl_lru) {
-               expire_client(clp);
-               if (++count == num)
+               count += func(clp, max - count);
+               if ((max != 0) && (count >= max))
                        break;
        }
 
-       printk(KERN_INFO "NFSD: Forgot %d clients", count);
+       return count;
+}
+
+void nfsd_forget_clients(u64 num)
+{
+       u64 count = nfsd_for_n_state(num, nfsd_forget_client);
+       printk(KERN_INFO "NFSD: Forgot %llu clients", count);
 }
 
 static void release_lockowner_sop(struct nfs4_stateowner *sop)