Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Multipath support for RPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2015, 2016, Primary Data, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Trond Myklebust <trond.myklebust@primarydata.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/cmpxchg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/sunrpc/xprt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sunrpc/addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sunrpc/xprtmultipath.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) typedef struct rpc_xprt *(*xprt_switch_find_xprt_t)(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		const struct rpc_xprt *cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static const struct rpc_xprt_iter_ops rpc_xprt_iter_singular;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static const struct rpc_xprt_iter_ops rpc_xprt_iter_roundrobin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static const struct rpc_xprt_iter_ops rpc_xprt_iter_listall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static void xprt_switch_add_xprt_locked(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		struct rpc_xprt *xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (unlikely(xprt_get(xprt) == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	list_add_tail_rcu(&xprt->xprt_switch, &xps->xps_xprt_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (xps->xps_nxprts == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		xps->xps_net = xprt->xprt_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	xps->xps_nxprts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	xps->xps_nactive++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * rpc_xprt_switch_add_xprt - Add a new rpc_xprt to an rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * @xps: pointer to struct rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @xprt: pointer to struct rpc_xprt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Adds xprt to the end of the list of struct rpc_xprt in xps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		struct rpc_xprt *xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (xprt == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	spin_lock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (xps->xps_net == xprt->xprt_net || xps->xps_net == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		xprt_switch_add_xprt_locked(xps, xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	spin_unlock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static void xprt_switch_remove_xprt_locked(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		struct rpc_xprt *xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (unlikely(xprt == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	xps->xps_nactive--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	xps->xps_nxprts--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (xps->xps_nxprts == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		xps->xps_net = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	list_del_rcu(&xprt->xprt_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * rpc_xprt_switch_remove_xprt - Removes an rpc_xprt from a rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * @xps: pointer to struct rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @xprt: pointer to struct rpc_xprt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Removes xprt from the list of struct rpc_xprt in xps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		struct rpc_xprt *xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	spin_lock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	xprt_switch_remove_xprt_locked(xps, xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	spin_unlock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	xprt_put(xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * xprt_switch_alloc - Allocate a new struct rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * @xprt: pointer to struct rpc_xprt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * @gfp_flags: allocation flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * On success, returns an initialised struct rpc_xprt_switch, containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * the entry xprt. Returns NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct rpc_xprt_switch *xps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	xps = kmalloc(sizeof(*xps), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (xps != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		spin_lock_init(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		kref_init(&xps->xps_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		xps->xps_nxprts = xps->xps_nactive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		atomic_long_set(&xps->xps_queuelen, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		xps->xps_net = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		INIT_LIST_HEAD(&xps->xps_xprt_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		xps->xps_iter_ops = &rpc_xprt_iter_singular;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		xprt_switch_add_xprt_locked(xps, xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return xps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void xprt_switch_free_entries(struct rpc_xprt_switch *xps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	spin_lock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	while (!list_empty(&xps->xps_xprt_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		struct rpc_xprt *xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		xprt = list_first_entry(&xps->xps_xprt_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				struct rpc_xprt, xprt_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		xprt_switch_remove_xprt_locked(xps, xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		spin_unlock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		xprt_put(xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		spin_lock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	spin_unlock(&xps->xps_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void xprt_switch_free(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct rpc_xprt_switch *xps = container_of(kref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			struct rpc_xprt_switch, xps_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	xprt_switch_free_entries(xps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	kfree_rcu(xps, xps_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * xprt_switch_get - Return a reference to a rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * @xps: pointer to struct rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * Returns a reference to xps unless the refcount is already zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct rpc_xprt_switch *xprt_switch_get(struct rpc_xprt_switch *xps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (xps != NULL && kref_get_unless_zero(&xps->xps_kref))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return xps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * xprt_switch_put - Release a reference to a rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * @xps: pointer to struct rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * Release the reference to xps, and free it once the refcount is zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) void xprt_switch_put(struct rpc_xprt_switch *xps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (xps != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		kref_put(&xps->xps_kref, xprt_switch_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * rpc_xprt_switch_set_roundrobin - Set a round-robin policy on rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  * @xps: pointer to struct rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * Sets a round-robin default policy for iterators acting on xps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) void rpc_xprt_switch_set_roundrobin(struct rpc_xprt_switch *xps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (READ_ONCE(xps->xps_iter_ops) != &rpc_xprt_iter_roundrobin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		WRITE_ONCE(xps->xps_iter_ops, &rpc_xprt_iter_roundrobin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) const struct rpc_xprt_iter_ops *xprt_iter_ops(const struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (xpi->xpi_ops != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return xpi->xpi_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return rcu_dereference(xpi->xpi_xpswitch)->xps_iter_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) void xprt_iter_no_rewind(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) void xprt_iter_default_rewind(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	WRITE_ONCE(xpi->xpi_cursor, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) bool xprt_is_active(const struct rpc_xprt *xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return kref_read(&xprt->kref) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct rpc_xprt *xprt_switch_find_first_entry(struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct rpc_xprt *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	list_for_each_entry_rcu(pos, head, xprt_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if (xprt_is_active(pos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct rpc_xprt *xprt_iter_first_entry(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct rpc_xprt_switch *xps = rcu_dereference(xpi->xpi_xpswitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (xps == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return xprt_switch_find_first_entry(&xps->xps_xprt_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct rpc_xprt *xprt_switch_find_current_entry(struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		const struct rpc_xprt *cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct rpc_xprt *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	list_for_each_entry_rcu(pos, head, xprt_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		if (cur == pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (found && xprt_is_active(pos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct rpc_xprt *xprt_iter_current_entry(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct rpc_xprt_switch *xps = rcu_dereference(xpi->xpi_xpswitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (xps == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	head = &xps->xps_xprt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (xpi->xpi_cursor == NULL || xps->xps_nxprts < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return xprt_switch_find_first_entry(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return xprt_switch_find_current_entry(head, xpi->xpi_cursor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			      const struct sockaddr *sap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct rpc_xprt *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (xps == NULL || sap == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	head = &xps->xps_xprt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	list_for_each_entry_rcu(pos, head, xprt_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if (rpc_cmp_addr_port(sap, (struct sockaddr *)&pos->addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			pr_info("RPC:   addr %s already in xprt switch\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				pos->address_strings[RPC_DISPLAY_ADDR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct rpc_xprt *xprt_switch_find_next_entry(struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		const struct rpc_xprt *cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct rpc_xprt *pos, *prev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	list_for_each_entry_rcu(pos, head, xprt_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		if (cur == prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (found && xprt_is_active(pos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		prev = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct rpc_xprt *xprt_switch_set_next_cursor(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		struct rpc_xprt **cursor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		xprt_switch_find_xprt_t find_next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct rpc_xprt *pos, *old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	old = smp_load_acquire(cursor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	pos = find_next(xps, old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	smp_store_release(cursor, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct rpc_xprt *xprt_iter_next_entry_multiple(struct rpc_xprt_iter *xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		xprt_switch_find_xprt_t find_next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	struct rpc_xprt_switch *xps = rcu_dereference(xpi->xpi_xpswitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (xps == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	return xprt_switch_set_next_cursor(xps, &xpi->xpi_cursor, find_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct rpc_xprt *__xprt_switch_find_next_entry_roundrobin(struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		const struct rpc_xprt *cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	struct rpc_xprt *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	ret = xprt_switch_find_next_entry(head, cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (ret != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return xprt_switch_find_first_entry(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct rpc_xprt *xprt_switch_find_next_entry_roundrobin(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		const struct rpc_xprt *cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct list_head *head = &xps->xps_xprt_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	struct rpc_xprt *xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	unsigned int nactive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		unsigned long xprt_queuelen, xps_queuelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		xprt = __xprt_switch_find_next_entry_roundrobin(head, cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		if (!xprt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		xprt_queuelen = atomic_long_read(&xprt->queuelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		xps_queuelen = atomic_long_read(&xps->xps_queuelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		nactive = READ_ONCE(xps->xps_nactive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		/* Exit loop if xprt_queuelen <= average queue length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		if (xprt_queuelen * nactive <= xps_queuelen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		cur = xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct rpc_xprt *xprt_iter_next_entry_roundrobin(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	return xprt_iter_next_entry_multiple(xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			xprt_switch_find_next_entry_roundrobin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct rpc_xprt *xprt_switch_find_next_entry_all(struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		const struct rpc_xprt *cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return xprt_switch_find_next_entry(&xps->xps_xprt_list, cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct rpc_xprt *xprt_iter_next_entry_all(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	return xprt_iter_next_entry_multiple(xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			xprt_switch_find_next_entry_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  * xprt_iter_rewind - Resets the xprt iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  * Resets xpi to ensure that it points to the first entry in the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  * of transports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) void xprt_iter_rewind(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	xprt_iter_ops(xpi)->xpi_rewind(xpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static void __xprt_iter_init(struct rpc_xprt_iter *xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		struct rpc_xprt_switch *xps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		const struct rpc_xprt_iter_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	rcu_assign_pointer(xpi->xpi_xpswitch, xprt_switch_get(xps));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	xpi->xpi_cursor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	xpi->xpi_ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * xprt_iter_init - Initialise an xprt iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * @xps: pointer to rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * Initialises the iterator to use the default iterator ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * as set in xps. This function is mainly intended for internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * use in the rpc_client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) void xprt_iter_init(struct rpc_xprt_iter *xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		struct rpc_xprt_switch *xps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	__xprt_iter_init(xpi, xps, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * xprt_iter_init_listall - Initialise an xprt iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  * @xps: pointer to rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  * Initialises the iterator to iterate once through the entire list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  * of entries in xps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) void xprt_iter_init_listall(struct rpc_xprt_iter *xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		struct rpc_xprt_switch *xps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	__xprt_iter_init(xpi, xps, &rpc_xprt_iter_listall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  * xprt_iter_xchg_switch - Atomically swap out the rpc_xprt_switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  * @newswitch: pointer to a new rpc_xprt_switch or NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  * Swaps out the existing xpi->xpi_xpswitch with a new value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct rpc_xprt_switch *xprt_iter_xchg_switch(struct rpc_xprt_iter *xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		struct rpc_xprt_switch *newswitch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct rpc_xprt_switch __rcu *oldswitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	/* Atomically swap out the old xpswitch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	oldswitch = xchg(&xpi->xpi_xpswitch, RCU_INITIALIZER(newswitch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if (newswitch != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		xprt_iter_rewind(xpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	return rcu_dereference_protected(oldswitch, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * xprt_iter_destroy - Destroys the xprt iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) void xprt_iter_destroy(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	xprt_switch_put(xprt_iter_xchg_switch(xpi, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  * xprt_iter_xprt - Returns the rpc_xprt pointed to by the cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  * Returns a pointer to the struct rpc_xprt that is currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  * pointed to by the cursor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * Caller must be holding rcu_read_lock().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct rpc_xprt *xprt_iter_xprt(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	WARN_ON_ONCE(!rcu_read_lock_held());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return xprt_iter_ops(xpi)->xpi_xprt(xpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct rpc_xprt *xprt_iter_get_helper(struct rpc_xprt_iter *xpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		struct rpc_xprt *(*fn)(struct rpc_xprt_iter *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	struct rpc_xprt *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		ret = fn(xpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		if (ret == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		ret = xprt_get(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	} while (ret == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)  * xprt_iter_get_xprt - Returns the rpc_xprt pointed to by the cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)  * Returns a reference to the struct rpc_xprt that is currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  * pointed to by the cursor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct rpc_xprt *xprt_iter_get_xprt(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	struct rpc_xprt *xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	xprt = xprt_iter_get_helper(xpi, xprt_iter_ops(xpi)->xpi_xprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	return xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  * xprt_iter_get_next - Returns the next rpc_xprt following the cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  * @xpi: pointer to rpc_xprt_iter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  * Returns a reference to the struct rpc_xprt that immediately follows the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * entry pointed to by the cursor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct rpc_xprt *xprt_iter_get_next(struct rpc_xprt_iter *xpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	struct rpc_xprt *xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	xprt = xprt_iter_get_helper(xpi, xprt_iter_ops(xpi)->xpi_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	return xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* Policy for always returning the first entry in the rpc_xprt_switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) const struct rpc_xprt_iter_ops rpc_xprt_iter_singular = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	.xpi_rewind = xprt_iter_no_rewind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	.xpi_xprt = xprt_iter_first_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	.xpi_next = xprt_iter_first_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /* Policy for round-robin iteration of entries in the rpc_xprt_switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) const struct rpc_xprt_iter_ops rpc_xprt_iter_roundrobin = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	.xpi_rewind = xprt_iter_default_rewind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	.xpi_xprt = xprt_iter_current_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	.xpi_next = xprt_iter_next_entry_roundrobin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* Policy for once-through iteration of entries in the rpc_xprt_switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) const struct rpc_xprt_iter_ops rpc_xprt_iter_listall = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	.xpi_rewind = xprt_iter_default_rewind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	.xpi_xprt = xprt_iter_current_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	.xpi_next = xprt_iter_next_entry_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) };