]> git.baikalelectronics.ru Git - kernel.git/commitdiff
sunrpc: remove an offlined xprt using sysfs
authorOlga Kornievskaia <kolga@netapp.com>
Thu, 24 Jun 2021 03:28:53 +0000 (23:28 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 8 Jul 2021 18:03:24 +0000 (14:03 -0400)
Once a transport has been put offline, this transport can be also
removed from the list of transports. Any tasks that have been stuck
on this transport would find the next available active transport
and be re-tried. This transport would be removed from the xprt_switch
list and freed.

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
include/linux/sunrpc/xprt.h
net/sunrpc/clnt.c
net/sunrpc/sysfs.c

index b8ed7fa1b4cae99b6cf25a265825fd392e929d0a..c8c39f22d3b169a7ea3d41f0892fe5562e676377 100644 (file)
@@ -428,6 +428,7 @@ void                        xprt_release_write(struct rpc_xprt *, struct rpc_task *);
 #define XPRT_BINDING           (5)
 #define XPRT_CLOSING           (6)
 #define XPRT_OFFLINE           (7)
+#define XPRT_REMOVE            (8)
 #define XPRT_CONGESTED         (9)
 #define XPRT_CWND_WAIT         (10)
 #define XPRT_WRITE_SPACE       (11)
index 408618765aa54a5bdcde3dbaa00310d29e2f2049..8b4de70e8ead40aa8a4dfb005a0af074e5c74ae0 100644 (file)
@@ -2106,6 +2106,30 @@ call_connect_status(struct rpc_task *task)
        case -ENOTCONN:
        case -EAGAIN:
        case -ETIMEDOUT:
+               if (!(task->tk_flags & RPC_TASK_NO_ROUND_ROBIN) &&
+                   (task->tk_flags & RPC_TASK_MOVEABLE) &&
+                   test_bit(XPRT_REMOVE, &xprt->state)) {
+                       struct rpc_xprt *saved = task->tk_xprt;
+                       struct rpc_xprt_switch *xps;
+
+                       rcu_read_lock();
+                       xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
+                       rcu_read_unlock();
+                       if (xps->xps_nxprts > 1) {
+                               long value;
+
+                               xprt_release(task);
+                               value = atomic_long_dec_return(&xprt->queuelen);
+                               if (value == 0)
+                                       rpc_xprt_switch_remove_xprt(xps, saved);
+                               xprt_put(saved);
+                               task->tk_xprt = NULL;
+                               task->tk_action = call_start;
+                       }
+                       xprt_switch_put(xps);
+                       if (!task->tk_xprt)
+                               return;
+               }
                goto out_retry;
        case -ENOBUFS:
                rpc_delay(task, HZ >> 2);
index b576c7f06829406bd922ce80cb445504e534df12..64da3bfd28e6c2ab30e51b2459dc3bb0f22f2ce6 100644 (file)
@@ -133,7 +133,7 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj,
        struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
        ssize_t ret;
        int locked, connected, connecting, close_wait, bound, binding,
-           closing, congested, cwnd_wait, write_space, offline;
+           closing, congested, cwnd_wait, write_space, offline, remove;
 
        if (!xprt)
                return 0;
@@ -152,8 +152,9 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj,
                cwnd_wait = test_bit(XPRT_CWND_WAIT, &xprt->state);
                write_space = test_bit(XPRT_WRITE_SPACE, &xprt->state);
                offline = test_bit(XPRT_OFFLINE, &xprt->state);
+               remove = test_bit(XPRT_REMOVE, &xprt->state);
 
-               ret = sprintf(buf, "state=%s %s %s %s %s %s %s %s %s %s %s\n",
+               ret = sprintf(buf, "state=%s %s %s %s %s %s %s %s %s %s %s %s\n",
                              locked ? "LOCKED" : "",
                              connected ? "CONNECTED" : "",
                              connecting ? "CONNECTING" : "",
@@ -164,7 +165,8 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj,
                              congested ? "CONGESTED" : "",
                              cwnd_wait ? "CWND_WAIT" : "",
                              write_space ? "WRITE_SPACE" : "",
-                             offline ? "OFFLINE" : "");
+                             offline ? "OFFLINE" : "",
+                             remove ? "REMOVE" : "");
        }
 
        xprt_put(xprt);
@@ -251,7 +253,7 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
                                           const char *buf, size_t count)
 {
        struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
-       int offline = 0, online = 0;
+       int offline = 0, online = 0, remove = 0;
        struct rpc_xprt_switch *xps = rpc_sysfs_xprt_kobj_get_xprt_switch(kobj);
 
        if (!xprt)
@@ -261,6 +263,8 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
                offline = 1;
        else if (!strncmp(buf, "online", 6))
                online = 1;
+       else if (!strncmp(buf, "remove", 6))
+               remove = 1;
        else
                return -EINVAL;
 
@@ -282,6 +286,20 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
                spin_lock(&xps->xps_lock);
                xps->xps_nactive++;
                spin_unlock(&xps->xps_lock);
+       } else if (remove) {
+               if (test_bit(XPRT_OFFLINE, &xprt->state)) {
+                       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 {
+                       count = -EINVAL;
+               }
        }
 
 release_tasks: