1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * RPC client multipathing definitions
4  *
5  * Copyright (c) 2015, 2016, Primary Data, Inc. All rights reserved.
6  *
7  * Trond Myklebust <trond.myklebust@primarydata.com>
8  */
9 #ifndef _NET_SUNRPC_XPRTMULTIPATH_H
10 #define _NET_SUNRPC_XPRTMULTIPATH_H
11 
12 struct rpc_xprt_iter_ops;
13 struct rpc_xprt_switch {
14 	spinlock_t		xps_lock;
15 	struct kref		xps_kref;
16 
17 	unsigned int		xps_nxprts;
18 	struct list_head	xps_xprt_list;
19 
20 	struct net *		xps_net;
21 
22 	const struct rpc_xprt_iter_ops *xps_iter_ops;
23 
24 	struct rcu_head		xps_rcu;
25 };
26 
27 struct rpc_xprt_iter {
28 	struct rpc_xprt_switch __rcu *xpi_xpswitch;
29 	struct rpc_xprt *	xpi_cursor;
30 
31 	const struct rpc_xprt_iter_ops *xpi_ops;
32 };
33 
34 
35 struct rpc_xprt_iter_ops {
36 	void (*xpi_rewind)(struct rpc_xprt_iter *);
37 	struct rpc_xprt *(*xpi_xprt)(struct rpc_xprt_iter *);
38 	struct rpc_xprt *(*xpi_next)(struct rpc_xprt_iter *);
39 };
40 
41 extern struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt,
42 		gfp_t gfp_flags);
43 
44 extern struct rpc_xprt_switch *xprt_switch_get(struct rpc_xprt_switch *xps);
45 extern void xprt_switch_put(struct rpc_xprt_switch *xps);
46 
47 extern void rpc_xprt_switch_set_roundrobin(struct rpc_xprt_switch *xps);
48 
49 extern void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps,
50 		struct rpc_xprt *xprt);
51 extern void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
52 		struct rpc_xprt *xprt);
53 
54 extern void xprt_iter_init(struct rpc_xprt_iter *xpi,
55 		struct rpc_xprt_switch *xps);
56 
57 extern void xprt_iter_init_listall(struct rpc_xprt_iter *xpi,
58 		struct rpc_xprt_switch *xps);
59 
60 extern void xprt_iter_destroy(struct rpc_xprt_iter *xpi);
61 
62 extern struct rpc_xprt_switch *xprt_iter_xchg_switch(
63 		struct rpc_xprt_iter *xpi,
64 		struct rpc_xprt_switch *newswitch);
65 
66 extern struct rpc_xprt *xprt_iter_xprt(struct rpc_xprt_iter *xpi);
67 extern struct rpc_xprt *xprt_iter_get_xprt(struct rpc_xprt_iter *xpi);
68 extern struct rpc_xprt *xprt_iter_get_next(struct rpc_xprt_iter *xpi);
69 
70 extern bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
71 		const struct sockaddr *sap);
72 #endif
73