diff mbox series

[RFC,1/3] SUNRPC provide accessible functions for offline remote xprt functionality

Message ID 20220228203804.61803-2-olga.kornievskaia@gmail.com (mailing list archive)
State New, archived
Headers show
Series approach to deal with changes in trunking membership | expand

Commit Message

Olga Kornievskaia Feb. 28, 2022, 8:38 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 |  2 ++
 net/sunrpc/sysfs.c          | 23 +++++------------------
 net/sunrpc/xprt.c           | 25 +++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index 955ea4d7af0b..201c58991d4a 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -502,4 +502,6 @@  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_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 05c758da6a92..4a6488dd1608 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -6,6 +6,7 @@ 
 #include <linux/kobject.h>
 #include <linux/sunrpc/addr.h>
 #include <linux/sunrpc/xprtsock.h>
+//#include <linux/sunrpc/xprt.h>
 
 #include "sysfs.h"
 
@@ -312,11 +313,7 @@  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);
@@ -324,20 +321,10 @@  static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
 			spin_unlock(&xps->xps_lock);
 		}
 	} 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 9f0025e0742c..16d4435b61b4 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -2151,3 +2151,28 @@  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_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);