diff mbox series

[v1,01/12] SUNRPC expose functions for offline remote xprt functionality

Message ID 20220620152407.63127-2-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:23 p.m. UTC
From: Olga Kornievskaia <kolga@netapp.com>

Re-arrange the code that make offline transport and delete transport
callable functions.

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
---
 include/linux/sunrpc/xprt.h |  3 +++
 net/sunrpc/sysfs.c          | 28 +++++-----------------------
 net/sunrpc/xprt.c           | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 23 deletions(-)

Comments

Trond Myklebust July 12, 2022, 3:12 p.m. UTC | #1
On Mon, 2022-06-20 at 11:23 -0400, Olga Kornievskaia wrote:
> From: Olga Kornievskaia <kolga@netapp.com>
> 
> Re-arrange the code that make offline transport and delete transport
> callable functions.
> 
> Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
> ---
>  include/linux/sunrpc/xprt.h |  3 +++
>  net/sunrpc/sysfs.c          | 28 +++++-----------------------
>  net/sunrpc/xprt.c           | 35 +++++++++++++++++++++++++++++++++++
>  3 files changed, 43 insertions(+), 23 deletions(-)
> 
> diff --git a/include/linux/sunrpc/xprt.h
> b/include/linux/sunrpc/xprt.h
> index 522bbf937957..0d51b9f9ea37 100644
> --- a/include/linux/sunrpc/xprt.h
> +++ b/include/linux/sunrpc/xprt.h
> @@ -505,4 +505,7 @@ static inline int
> xprt_test_and_set_binding(struct rpc_xprt *xprt)
>         return test_and_set_bit(XPRT_BINDING, &xprt->state);
>  }
>  
> +void xprt_set_offline_locked(struct rpc_xprt *xprt, struct
> rpc_xprt_switch *xps);
> +void xprt_set_online_locked(struct rpc_xprt *xprt, struct
> rpc_xprt_switch *xps);
> +void xprt_delete_locked(struct rpc_xprt *xprt, struct
> rpc_xprt_switch *xps);
>  #endif /* _LINUX_SUNRPC_XPRT_H */
> diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
> index a3a2f8aeb80e..7330eb9a70cf 100644
> --- a/net/sunrpc/sysfs.c
> +++ b/net/sunrpc/sysfs.c
> @@ -314,32 +314,14 @@ static ssize_t
> rpc_sysfs_xprt_state_change(struct kobject *kobj,
>                 goto release_tasks;
>         }
>         if (offline) {
> -               if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
> -                       spin_lock(&xps->xps_lock);
> -                       xps->xps_nactive--;
> -                       spin_unlock(&xps->xps_lock);
> -               }
> +               xprt_set_offline_locked(xprt, xps);
>         } else if (online) {
> -               if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
> -                       spin_lock(&xps->xps_lock);
> -                       xps->xps_nactive++;
> -                       spin_unlock(&xps->xps_lock);
> -               }
> +               xprt_set_online_locked(xprt, xps);
>         } else if (remove) {
> -               if (test_bit(XPRT_OFFLINE, &xprt->state)) {
> -                       if (!test_and_set_bit(XPRT_REMOVE, &xprt-
> >state)) {
> -                               xprt_force_disconnect(xprt);
> -                               if (test_bit(XPRT_CONNECTED, &xprt-
> >state)) {
> -                                       if (!xprt->sending.qlen &&
> -                                           !xprt->pending.qlen &&
> -                                           !xprt->backlog.qlen &&
> -                                           !atomic_long_read(&xprt-
> >queuelen))
> -
>                                                rpc_xprt_switch_remove_
> xprt(xps, xprt);
> -                               }
> -                       }
> -               } else {
> +               if (test_bit(XPRT_OFFLINE, &xprt->state))
> +                       xprt_delete_locked(xprt, xps);
> +               else
>                         count = -EINVAL;
> -               }
>         }
>  
>  release_tasks:
> diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
> index 86d62cffba0d..6480ae324b27 100644
> --- a/net/sunrpc/xprt.c
> +++ b/net/sunrpc/xprt.c
> @@ -2152,3 +2152,38 @@ void xprt_put(struct rpc_xprt *xprt)
>                 kref_put(&xprt->kref, xprt_destroy_kref);
>  }
>  EXPORT_SYMBOL_GPL(xprt_put);
> +
> +void xprt_set_offline_locked(struct rpc_xprt *xprt, struct
> rpc_xprt_switch *xps)
> +{
> +       if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
> +               spin_lock(&xps->xps_lock);
> +               xps->xps_nactive--;
> +               spin_unlock(&xps->xps_lock);
> +       }
> +}
> +EXPORT_SYMBOL(xprt_set_offline_locked);
> +
> +void xprt_set_online_locked(struct rpc_xprt *xprt, struct
> rpc_xprt_switch *xps)
> +{
> +       if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
> +               spin_lock(&xps->xps_lock);
> +               xps->xps_nactive++;
> +               spin_unlock(&xps->xps_lock);
> +       }
> +}
> +EXPORT_SYMBOL(xprt_set_online_locked);
> +
> +void xprt_delete_locked(struct rpc_xprt *xprt, struct
> rpc_xprt_switch *xps)
> +{
> +       if (test_and_set_bit(XPRT_REMOVE, &xprt->state))
> +               return;
> +
> +       xprt_force_disconnect(xprt);
> +       if (!test_bit(XPRT_CONNECTED, &xprt->state))
> +               return;
> +
> +       if (!xprt->sending.qlen && !xprt->pending.qlen &&
> +           !xprt->backlog.qlen && !atomic_long_read(&xprt-
> >queuelen))
> +               rpc_xprt_switch_remove_xprt(xps, xprt);
> +}
> +EXPORT_SYMBOL(xprt_delete_locked);

Why are these functions being exported? There is nothing outside the
main sunrpc layer that should be using them.
Olga Kornievskaia July 12, 2022, 3:57 p.m. UTC | #2
On Tue, Jul 12, 2022 at 11:12 AM Trond Myklebust
<trondmy@hammerspace.com> wrote:
>
> On Mon, 2022-06-20 at 11:23 -0400, Olga Kornievskaia wrote:
> > From: Olga Kornievskaia <kolga@netapp.com>
> >
> > Re-arrange the code that make offline transport and delete transport
> > callable functions.
> >
> > Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
> > ---
> >  include/linux/sunrpc/xprt.h |  3 +++
> >  net/sunrpc/sysfs.c          | 28 +++++-----------------------
> >  net/sunrpc/xprt.c           | 35 +++++++++++++++++++++++++++++++++++
> >  3 files changed, 43 insertions(+), 23 deletions(-)
> >
> > diff --git a/include/linux/sunrpc/xprt.h
> > b/include/linux/sunrpc/xprt.h
> > index 522bbf937957..0d51b9f9ea37 100644
> > --- a/include/linux/sunrpc/xprt.h
> > +++ b/include/linux/sunrpc/xprt.h
> > @@ -505,4 +505,7 @@ static inline int
> > xprt_test_and_set_binding(struct rpc_xprt *xprt)
> >         return test_and_set_bit(XPRT_BINDING, &xprt->state);
> >  }
> >
> > +void xprt_set_offline_locked(struct rpc_xprt *xprt, struct
> > rpc_xprt_switch *xps);
> > +void xprt_set_online_locked(struct rpc_xprt *xprt, struct
> > rpc_xprt_switch *xps);
> > +void xprt_delete_locked(struct rpc_xprt *xprt, struct
> > rpc_xprt_switch *xps);
> >  #endif /* _LINUX_SUNRPC_XPRT_H */
> > diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
> > index a3a2f8aeb80e..7330eb9a70cf 100644
> > --- a/net/sunrpc/sysfs.c
> > +++ b/net/sunrpc/sysfs.c
> > @@ -314,32 +314,14 @@ static ssize_t
> > rpc_sysfs_xprt_state_change(struct kobject *kobj,
> >                 goto release_tasks;
> >         }
> >         if (offline) {
> > -               if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
> > -                       spin_lock(&xps->xps_lock);
> > -                       xps->xps_nactive--;
> > -                       spin_unlock(&xps->xps_lock);
> > -               }
> > +               xprt_set_offline_locked(xprt, xps);
> >         } else if (online) {
> > -               if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
> > -                       spin_lock(&xps->xps_lock);
> > -                       xps->xps_nactive++;
> > -                       spin_unlock(&xps->xps_lock);
> > -               }
> > +               xprt_set_online_locked(xprt, xps);
> >         } else if (remove) {
> > -               if (test_bit(XPRT_OFFLINE, &xprt->state)) {
> > -                       if (!test_and_set_bit(XPRT_REMOVE, &xprt-
> > >state)) {
> > -                               xprt_force_disconnect(xprt);
> > -                               if (test_bit(XPRT_CONNECTED, &xprt-
> > >state)) {
> > -                                       if (!xprt->sending.qlen &&
> > -                                           !xprt->pending.qlen &&
> > -                                           !xprt->backlog.qlen &&
> > -                                           !atomic_long_read(&xprt-
> > >queuelen))
> > -
> >                                                rpc_xprt_switch_remove_
> > xprt(xps, xprt);
> > -                               }
> > -                       }
> > -               } else {
> > +               if (test_bit(XPRT_OFFLINE, &xprt->state))
> > +                       xprt_delete_locked(xprt, xps);
> > +               else
> >                         count = -EINVAL;
> > -               }
> >         }
> >
> >  release_tasks:
> > diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
> > index 86d62cffba0d..6480ae324b27 100644
> > --- a/net/sunrpc/xprt.c
> > +++ b/net/sunrpc/xprt.c
> > @@ -2152,3 +2152,38 @@ void xprt_put(struct rpc_xprt *xprt)
> >                 kref_put(&xprt->kref, xprt_destroy_kref);
> >  }
> >  EXPORT_SYMBOL_GPL(xprt_put);
> > +
> > +void xprt_set_offline_locked(struct rpc_xprt *xprt, struct
> > rpc_xprt_switch *xps)
> > +{
> > +       if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
> > +               spin_lock(&xps->xps_lock);
> > +               xps->xps_nactive--;
> > +               spin_unlock(&xps->xps_lock);
> > +       }
> > +}
> > +EXPORT_SYMBOL(xprt_set_offline_locked);
> > +
> > +void xprt_set_online_locked(struct rpc_xprt *xprt, struct
> > rpc_xprt_switch *xps)
> > +{
> > +       if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
> > +               spin_lock(&xps->xps_lock);
> > +               xps->xps_nactive++;
> > +               spin_unlock(&xps->xps_lock);
> > +       }
> > +}
> > +EXPORT_SYMBOL(xprt_set_online_locked);
> > +
> > +void xprt_delete_locked(struct rpc_xprt *xprt, struct
> > rpc_xprt_switch *xps)
> > +{
> > +       if (test_and_set_bit(XPRT_REMOVE, &xprt->state))
> > +               return;
> > +
> > +       xprt_force_disconnect(xprt);
> > +       if (!test_bit(XPRT_CONNECTED, &xprt->state))
> > +               return;
> > +
> > +       if (!xprt->sending.qlen && !xprt->pending.qlen &&
> > +           !xprt->backlog.qlen && !atomic_long_read(&xprt-
> > >queuelen))
> > +               rpc_xprt_switch_remove_xprt(xps, xprt);
> > +}
> > +EXPORT_SYMBOL(xprt_delete_locked);
>
> Why are these functions being exported? There is nothing outside the
> main sunrpc layer that should be using them.
>

Thank you for the comment. Make sense, will fix. It probably came from
looking at xprt_put above that code.

> --
> Trond Myklebust
> Linux NFS client maintainer, Hammerspace
> trond.myklebust@hammerspace.com
>
>
diff mbox series

Patch

diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index 522bbf937957..0d51b9f9ea37 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -505,4 +505,7 @@  static inline int xprt_test_and_set_binding(struct rpc_xprt *xprt)
 	return test_and_set_bit(XPRT_BINDING, &xprt->state);
 }
 
+void xprt_set_offline_locked(struct rpc_xprt *xprt, struct rpc_xprt_switch *xps);
+void xprt_set_online_locked(struct rpc_xprt *xprt, struct rpc_xprt_switch *xps);
+void xprt_delete_locked(struct rpc_xprt *xprt, struct rpc_xprt_switch *xps);
 #endif /* _LINUX_SUNRPC_XPRT_H */
diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index a3a2f8aeb80e..7330eb9a70cf 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -314,32 +314,14 @@  static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
 		goto release_tasks;
 	}
 	if (offline) {
-		if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
-			spin_lock(&xps->xps_lock);
-			xps->xps_nactive--;
-			spin_unlock(&xps->xps_lock);
-		}
+		xprt_set_offline_locked(xprt, xps);
 	} else if (online) {
-		if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
-			spin_lock(&xps->xps_lock);
-			xps->xps_nactive++;
-			spin_unlock(&xps->xps_lock);
-		}
+		xprt_set_online_locked(xprt, xps);
 	} else if (remove) {
-		if (test_bit(XPRT_OFFLINE, &xprt->state)) {
-			if (!test_and_set_bit(XPRT_REMOVE, &xprt->state)) {
-				xprt_force_disconnect(xprt);
-				if (test_bit(XPRT_CONNECTED, &xprt->state)) {
-					if (!xprt->sending.qlen &&
-					    !xprt->pending.qlen &&
-					    !xprt->backlog.qlen &&
-					    !atomic_long_read(&xprt->queuelen))
-						rpc_xprt_switch_remove_xprt(xps, xprt);
-				}
-			}
-		} else {
+		if (test_bit(XPRT_OFFLINE, &xprt->state))
+			xprt_delete_locked(xprt, xps);
+		else
 			count = -EINVAL;
-		}
 	}
 
 release_tasks:
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index 86d62cffba0d..6480ae324b27 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -2152,3 +2152,38 @@  void xprt_put(struct rpc_xprt *xprt)
 		kref_put(&xprt->kref, xprt_destroy_kref);
 }
 EXPORT_SYMBOL_GPL(xprt_put);
+
+void xprt_set_offline_locked(struct rpc_xprt *xprt, struct rpc_xprt_switch *xps)
+{
+	if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
+		spin_lock(&xps->xps_lock);
+		xps->xps_nactive--;
+		spin_unlock(&xps->xps_lock);
+	}
+}
+EXPORT_SYMBOL(xprt_set_offline_locked);
+
+void xprt_set_online_locked(struct rpc_xprt *xprt, struct rpc_xprt_switch *xps)
+{
+	if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
+		spin_lock(&xps->xps_lock);
+		xps->xps_nactive++;
+		spin_unlock(&xps->xps_lock);
+	}
+}
+EXPORT_SYMBOL(xprt_set_online_locked);
+
+void xprt_delete_locked(struct rpc_xprt *xprt, struct rpc_xprt_switch *xps)
+{
+	if (test_and_set_bit(XPRT_REMOVE, &xprt->state))
+		return;
+
+	xprt_force_disconnect(xprt);
+	if (!test_bit(XPRT_CONNECTED, &xprt->state))
+		return;
+
+	if (!xprt->sending.qlen && !xprt->pending.qlen &&
+	    !xprt->backlog.qlen && !atomic_long_read(&xprt->queuelen))
+		rpc_xprt_switch_remove_xprt(xps, xprt);
+}
+EXPORT_SYMBOL(xprt_delete_locked);