diff mbox

[RFC,Version,1,2/6] SUNRPC fix rpc_clnt_xprt_iter_init infinite loop

Message ID 1454706518-4641-3-git-send-email-andros@netapp.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andy Adamson Feb. 5, 2016, 9:08 p.m. UTC
From: Andy Adamson <andros@netapp.com>

xprt_iter_get_next() will restart at top of list and never stop.
Only process xps_nxprts xprts.

Signed-off-by: Andy Adamson <andros@netapp.com>
---
 net/sunrpc/clnt.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Trond Myklebust Feb. 6, 2016, 1:18 a.m. UTC | #1
On Fri, Feb 5, 2016 at 4:08 PM,  <andros@netapp.com> wrote:
> From: Andy Adamson <andros@netapp.com>
>
> xprt_iter_get_next() will restart at top of list and never stop.
> Only process xps_nxprts xprts.
>
> Signed-off-by: Andy Adamson <andros@netapp.com>
> ---
>  net/sunrpc/clnt.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
> index c0469d1..a56a44c8 100644
> --- a/net/sunrpc/clnt.c
> +++ b/net/sunrpc/clnt.c
> @@ -740,6 +740,7 @@ static
>  int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
>  {
>         struct rpc_xprt_switch *xps;
> +       int nxprt;
>
>         rcu_read_lock();
>         xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
> @@ -747,8 +748,9 @@ int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
>         if (xps == NULL)
>                 return -EAGAIN;
>         xprt_iter_init_listall(xpi, xps);
> +       nxprt = xps->xps_nxprts;
>         xprt_switch_put(xps);
> -       return 0;
> +       return nxprt;
>  }
>
>  /**
> @@ -767,10 +769,11 @@ int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
>                 void *data)
>  {
>         struct rpc_xprt_iter xpi;
> -       int ret;
> +       int ret = 0, nxprts, i;
>
> -       ret = rpc_clnt_xprt_iter_init(clnt, &xpi);
> -       for (;;) {
> +       nxprts = rpc_clnt_xprt_iter_init(clnt, &xpi);
> +       dprintk("RPC:   processing nxprts %d\n", nxprts);
> +       for (i = 0; i < nxprts; i++) {
>                 struct rpc_xprt *xprt = xprt_iter_get_next(&xpi);
>
>                 if (!xprt)
> --

I'd prefer not to export xps->xps_nxprts. It's not guaranteed to
remain stable unless you hold the spinlock.
Please see the change to xprt_switch_set_next_cursor().
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index c0469d1..a56a44c8 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -740,6 +740,7 @@  static
 int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
 {
 	struct rpc_xprt_switch *xps;
+	int nxprt;
 
 	rcu_read_lock();
 	xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
@@ -747,8 +748,9 @@  int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
 	if (xps == NULL)
 		return -EAGAIN;
 	xprt_iter_init_listall(xpi, xps);
+	nxprt = xps->xps_nxprts;
 	xprt_switch_put(xps);
-	return 0;
+	return nxprt;
 }
 
 /**
@@ -767,10 +769,11 @@  int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
 		void *data)
 {
 	struct rpc_xprt_iter xpi;
-	int ret;
+	int ret = 0, nxprts, i;
 
-	ret = rpc_clnt_xprt_iter_init(clnt, &xpi);
-	for (;;) {
+	nxprts = rpc_clnt_xprt_iter_init(clnt, &xpi);
+	dprintk("RPC:   processing nxprts %d\n", nxprts);
+	for (i = 0; i < nxprts; i++) {
 		struct rpc_xprt *xprt = xprt_iter_get_next(&xpi);
 
 		if (!xprt)