]> git.baikalelectronics.ru Git - kernel.git/commitdiff
NFS: Add a helper nfs_client_for_each_server()
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 27 Feb 2020 00:16:09 +0000 (19:16 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 16 Mar 2020 12:34:30 +0000 (08:34 -0400)
Add a helper nfs_client_for_each_server() to iterate through all the
filesystems that are attached to a struct nfs_client, and apply
a function to all the active ones.

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

index f80c47d5ff277203b19344b33ba51c19a46fcf5e..3b6fa9edc9b5af19aa499185a29f36a831d2fefe 100644 (file)
@@ -417,7 +417,9 @@ extern int __init register_nfs_fs(void);
 extern void __exit unregister_nfs_fs(void);
 extern bool nfs_sb_active(struct super_block *sb);
 extern void nfs_sb_deactive(struct super_block *sb);
-
+extern int nfs_client_for_each_server(struct nfs_client *clp,
+                                     int (*fn)(struct nfs_server *, void *),
+                                     void *data);
 /* io.c */
 extern void nfs_start_io_read(struct inode *inode);
 extern void nfs_end_io_read(struct inode *inode);
index dada09b391c653a7f0fa1e6c8dd87daba0b204be..eb3a85492396736fb344133b7b5baef49de280ef 100644 (file)
@@ -176,6 +176,41 @@ void nfs_sb_deactive(struct super_block *sb)
 }
 EXPORT_SYMBOL_GPL(nfs_sb_deactive);
 
+static int __nfs_list_for_each_server(struct list_head *head,
+               int (*fn)(struct nfs_server *, void *),
+               void *data)
+{
+       struct nfs_server *server, *last = NULL;
+       int ret = 0;
+
+       rcu_read_lock();
+       list_for_each_entry_rcu(server, head, client_link) {
+               if (!nfs_sb_active(server->super))
+                       continue;
+               rcu_read_unlock();
+               if (last)
+                       nfs_sb_deactive(last->super);
+               last = server;
+               ret = fn(server, data);
+               if (ret)
+                       goto out;
+               rcu_read_lock();
+       }
+       rcu_read_unlock();
+out:
+       if (last)
+               nfs_sb_deactive(last->super);
+       return ret;
+}
+
+int nfs_client_for_each_server(struct nfs_client *clp,
+               int (*fn)(struct nfs_server *, void *),
+               void *data)
+{
+       return __nfs_list_for_each_server(&clp->cl_superblocks, fn, data);
+}
+EXPORT_SYMBOL_GPL(nfs_client_for_each_server);
+
 /*
  * Deliver file system statistics to userspace
  */