diff mbox series

[v1,05/12] SUNRPC parameterize rpc_clnt_iterate_for_each_xprt with iterator init function

Message ID 20220620152407.63127-6-olga.kornievskaia@gmail.com (mailing list archive)
State New, archived
Headers show
Series Handling session trunking group membership | expand

Commit Message

Olga Kornievskaia June 20, 2022, 3:24 p.m. UTC
From: Olga Kornievskaia <kolga@netapp.com>

Allow for rpc_clnt_iterate_for_each_xprt() to take in an iterator
initialization function if no function passed in a default initiator
is used.

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
---
 fs/nfs/nfs4proc.c           |  2 +-
 include/linux/sunrpc/clnt.h |  1 +
 net/sunrpc/clnt.c           | 17 ++++++++++++-----
 net/sunrpc/debugfs.c        |  2 +-
 net/sunrpc/stats.c          |  2 +-
 5 files changed, 16 insertions(+), 8 deletions(-)

Comments

Trond Myklebust July 12, 2022, 3:43 p.m. UTC | #1
On Mon, 2022-06-20 at 11:24 -0400, Olga Kornievskaia wrote:
> From: Olga Kornievskaia <kolga@netapp.com>
> 
> Allow for rpc_clnt_iterate_for_each_xprt() to take in an iterator
> initialization function if no function passed in a default initiator
> is used.
> 
> Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
> ---
>  fs/nfs/nfs4proc.c           |  2 +-
>  include/linux/sunrpc/clnt.h |  1 +
>  net/sunrpc/clnt.c           | 17 ++++++++++++-----
>  net/sunrpc/debugfs.c        |  2 +-
>  net/sunrpc/stats.c          |  2 +-
>  5 files changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index cf898bea3bfd..5e4c32924347 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -8532,7 +8532,7 @@ int nfs4_proc_bind_conn_to_session(struct
> nfs_client *clp, const struct cred *cr
>                 .clp = clp,
>                 .cred = cred,
>         };
> -       return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient,
> +       return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient,
> NULL,
>                         nfs4_proc_bind_conn_to_session_callback,
> &data);
>  }
>  
> diff --git a/include/linux/sunrpc/clnt.h
> b/include/linux/sunrpc/clnt.h
> index e74a0740603b..20aed14fe222 100644
> --- a/include/linux/sunrpc/clnt.h
> +++ b/include/linux/sunrpc/clnt.h
> @@ -213,6 +213,7 @@ const char  *rpc_peeraddr2str(struct rpc_clnt *,
> enum rpc_display_format_t);
>  int            rpc_localaddr(struct rpc_clnt *, struct sockaddr *,
> size_t);
>  
>  int            rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
> +                       int (*setup)(struct rpc_clnt *, struct
> rpc_xprt_iter *),
>                         int (*fn)(struct rpc_clnt *, struct rpc_xprt
> *, void *),
>                         void *data);
>  
> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
> index 410bd6c352ad..b26267606de0 100644
> --- a/net/sunrpc/clnt.c
> +++ b/net/sunrpc/clnt.c
> @@ -817,6 +817,8 @@ int rpc_clnt_xprt_iter_offline_init(struct
> rpc_clnt *clnt,
>  /**
>   * rpc_clnt_iterate_for_each_xprt - Apply a function to all
> transports
>   * @clnt: pointer to client
> + * @setup: an optional iterator init function to use, if none
> supplied
> + *   default rpc_clnt_xprt_iter_init() iterator is used
>   * @fn: function to apply
>   * @data: void pointer to function data
>   *
> @@ -826,13 +828,17 @@ int rpc_clnt_xprt_iter_offline_init(struct
> rpc_clnt *clnt,
>   * On error, the iteration stops, and the function returns the error
> value.
>   */
>  int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
> +               int (*setup)(struct rpc_clnt *, struct rpc_xprt_iter
> *),
>                 int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void
> *),
>                 void *data)
>  {
>         struct rpc_xprt_iter xpi;
>         int ret;
>  
> -       ret = rpc_clnt_xprt_iter_init(clnt, &xpi);
> +       if (!setup)
> +               ret = rpc_clnt_xprt_iter_init(clnt, &xpi);
> +       else
> +               ret = setup(clnt, &xpi);

Please create an internal function that is not exported outside the RPC
layer for this. It would be fine to share code with
rpc_clnt_iterate_for_each_xprt() where appropriate, but we should not
expose an API that expects the caller to have intimate knowledge of the
rpc client internals.

>         if (ret)
>                 return ret;
>         for (;;) {
> @@ -3052,7 +3058,8 @@ static int rpc_xprt_offline_destroy(struct
> rpc_clnt *clnt,
>  
>  void rpc_clnt_manage_trunked_xprts(struct rpc_clnt *clnt, void
> *data)
>  {
> -       rpc_clnt_iterate_for_each_xprt(clnt,
> rpc_xprt_offline_destroy, data);
> +       rpc_clnt_iterate_for_each_xprt(clnt, NULL,
> rpc_xprt_offline_destroy,
> +                       data);
>  }
>  EXPORT_SYMBOL_GPL(rpc_clnt_manage_trunked_xprts);
>  
> @@ -3084,7 +3091,7 @@ rpc_set_connect_timeout(struct rpc_clnt *clnt,
>                 .connect_timeout = connect_timeout,
>                 .reconnect_timeout = reconnect_timeout,
>         };
> -       rpc_clnt_iterate_for_each_xprt(clnt,
> +       rpc_clnt_iterate_for_each_xprt(clnt, NULL,
>                         rpc_xprt_set_connect_timeout,
>                         &timeout);
>  }
> @@ -3181,7 +3188,7 @@ rpc_clnt_swap_activate(struct rpc_clnt *clnt)
>         while (clnt != clnt->cl_parent)
>                 clnt = clnt->cl_parent;
>         if (atomic_inc_return(&clnt->cl_swapper) == 1)
> -               return rpc_clnt_iterate_for_each_xprt(clnt,
> +               return rpc_clnt_iterate_for_each_xprt(clnt, NULL,
>                                 rpc_clnt_swap_activate_callback,
> NULL);
>         return 0;
>  }
> @@ -3200,7 +3207,7 @@ void
>  rpc_clnt_swap_deactivate(struct rpc_clnt *clnt)
>  {
>         if (atomic_dec_if_positive(&clnt->cl_swapper) == 0)
> -               rpc_clnt_iterate_for_each_xprt(clnt,
> +               rpc_clnt_iterate_for_each_xprt(clnt, NULL,
>                                 rpc_clnt_swap_deactivate_callback,
> NULL);
>  }
>  EXPORT_SYMBOL_GPL(rpc_clnt_swap_deactivate);
> diff --git a/net/sunrpc/debugfs.c b/net/sunrpc/debugfs.c
> index 7dc9cc929bfd..ab60b4d3deb2 100644
> --- a/net/sunrpc/debugfs.c
> +++ b/net/sunrpc/debugfs.c
> @@ -160,7 +160,7 @@ rpc_clnt_debugfs_register(struct rpc_clnt *clnt)
>         debugfs_create_file("tasks", S_IFREG | 0400, clnt-
> >cl_debugfs, clnt,
>                             &tasks_fops);
>  
> -       rpc_clnt_iterate_for_each_xprt(clnt, do_xprt_debugfs,
> &xprtnum);
> +       rpc_clnt_iterate_for_each_xprt(clnt, NULL, do_xprt_debugfs,
> &xprtnum);
>  }
>  
>  void
> diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
> index 52908f9e6eab..e50f73a4aca5 100644
> --- a/net/sunrpc/stats.c
> +++ b/net/sunrpc/stats.c
> @@ -258,7 +258,7 @@ void rpc_clnt_show_stats(struct seq_file *seq,
> struct rpc_clnt *clnt)
>         seq_printf(seq, "p/v: %u/%u (%s)\n",
>                         clnt->cl_prog, clnt->cl_vers, clnt-
> >cl_program->name);
>  
> -       rpc_clnt_iterate_for_each_xprt(clnt, do_print_stats, seq);
> +       rpc_clnt_iterate_for_each_xprt(clnt, NULL, do_print_stats,
> seq);
>  
>         seq_printf(seq, "\tper-op statistics\n");
>         for (op = 0; op < maxproc; op++) {
diff mbox series

Patch

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index cf898bea3bfd..5e4c32924347 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -8532,7 +8532,7 @@  int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, const struct cred *cr
 		.clp = clp,
 		.cred = cred,
 	};
-	return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient,
+	return rpc_clnt_iterate_for_each_xprt(clp->cl_rpcclient, NULL,
 			nfs4_proc_bind_conn_to_session_callback, &data);
 }
 
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index e74a0740603b..20aed14fe222 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -213,6 +213,7 @@  const char	*rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
 int		rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
 
 int 		rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
+			int (*setup)(struct rpc_clnt *, struct rpc_xprt_iter *),
 			int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
 			void *data);
 
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 410bd6c352ad..b26267606de0 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -817,6 +817,8 @@  int rpc_clnt_xprt_iter_offline_init(struct rpc_clnt *clnt,
 /**
  * rpc_clnt_iterate_for_each_xprt - Apply a function to all transports
  * @clnt: pointer to client
+ * @setup: an optional iterator init function to use, if none supplied
+ *   default rpc_clnt_xprt_iter_init() iterator is used
  * @fn: function to apply
  * @data: void pointer to function data
  *
@@ -826,13 +828,17 @@  int rpc_clnt_xprt_iter_offline_init(struct rpc_clnt *clnt,
  * On error, the iteration stops, and the function returns the error value.
  */
 int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
+		int (*setup)(struct rpc_clnt *, struct rpc_xprt_iter *),
 		int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
 		void *data)
 {
 	struct rpc_xprt_iter xpi;
 	int ret;
 
-	ret = rpc_clnt_xprt_iter_init(clnt, &xpi);
+	if (!setup)
+		ret = rpc_clnt_xprt_iter_init(clnt, &xpi);
+	else
+		ret = setup(clnt, &xpi);
 	if (ret)
 		return ret;
 	for (;;) {
@@ -3052,7 +3058,8 @@  static int rpc_xprt_offline_destroy(struct rpc_clnt *clnt,
 
 void rpc_clnt_manage_trunked_xprts(struct rpc_clnt *clnt, void *data)
 {
-	rpc_clnt_iterate_for_each_xprt(clnt, rpc_xprt_offline_destroy, data);
+	rpc_clnt_iterate_for_each_xprt(clnt, NULL, rpc_xprt_offline_destroy,
+			data);
 }
 EXPORT_SYMBOL_GPL(rpc_clnt_manage_trunked_xprts);
 
@@ -3084,7 +3091,7 @@  rpc_set_connect_timeout(struct rpc_clnt *clnt,
 		.connect_timeout = connect_timeout,
 		.reconnect_timeout = reconnect_timeout,
 	};
-	rpc_clnt_iterate_for_each_xprt(clnt,
+	rpc_clnt_iterate_for_each_xprt(clnt, NULL,
 			rpc_xprt_set_connect_timeout,
 			&timeout);
 }
@@ -3181,7 +3188,7 @@  rpc_clnt_swap_activate(struct rpc_clnt *clnt)
 	while (clnt != clnt->cl_parent)
 		clnt = clnt->cl_parent;
 	if (atomic_inc_return(&clnt->cl_swapper) == 1)
-		return rpc_clnt_iterate_for_each_xprt(clnt,
+		return rpc_clnt_iterate_for_each_xprt(clnt, NULL,
 				rpc_clnt_swap_activate_callback, NULL);
 	return 0;
 }
@@ -3200,7 +3207,7 @@  void
 rpc_clnt_swap_deactivate(struct rpc_clnt *clnt)
 {
 	if (atomic_dec_if_positive(&clnt->cl_swapper) == 0)
-		rpc_clnt_iterate_for_each_xprt(clnt,
+		rpc_clnt_iterate_for_each_xprt(clnt, NULL,
 				rpc_clnt_swap_deactivate_callback, NULL);
 }
 EXPORT_SYMBOL_GPL(rpc_clnt_swap_deactivate);
diff --git a/net/sunrpc/debugfs.c b/net/sunrpc/debugfs.c
index 7dc9cc929bfd..ab60b4d3deb2 100644
--- a/net/sunrpc/debugfs.c
+++ b/net/sunrpc/debugfs.c
@@ -160,7 +160,7 @@  rpc_clnt_debugfs_register(struct rpc_clnt *clnt)
 	debugfs_create_file("tasks", S_IFREG | 0400, clnt->cl_debugfs, clnt,
 			    &tasks_fops);
 
-	rpc_clnt_iterate_for_each_xprt(clnt, do_xprt_debugfs, &xprtnum);
+	rpc_clnt_iterate_for_each_xprt(clnt, NULL, do_xprt_debugfs, &xprtnum);
 }
 
 void
diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
index 52908f9e6eab..e50f73a4aca5 100644
--- a/net/sunrpc/stats.c
+++ b/net/sunrpc/stats.c
@@ -258,7 +258,7 @@  void rpc_clnt_show_stats(struct seq_file *seq, struct rpc_clnt *clnt)
 	seq_printf(seq, "p/v: %u/%u (%s)\n",
 			clnt->cl_prog, clnt->cl_vers, clnt->cl_program->name);
 
-	rpc_clnt_iterate_for_each_xprt(clnt, do_print_stats, seq);
+	rpc_clnt_iterate_for_each_xprt(clnt, NULL, do_print_stats, seq);
 
 	seq_printf(seq, "\tper-op statistics\n");
 	for (op = 0; op < maxproc; op++) {