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_sysfs_xprt_switch;
14 struct rpc_xprt_switch {
15 	spinlock_t		xps_lock;
16 	struct kref		xps_kref;
17 
18 	unsigned int		xps_id;
19 	unsigned int		xps_nxprts;
20 	unsigned int		xps_nactive;
21 	unsigned int		xps_nunique_destaddr_xprts;
22 	atomic_long_t		xps_queuelen;
23 	struct list_head	xps_xprt_list;
24 
25 	struct net *		xps_net;
26 
27 	const struct rpc_xprt_iter_ops *xps_iter_ops;
28 
29 	struct rpc_sysfs_xprt_switch *xps_sysfs;
30 	struct rcu_head		xps_rcu;
31 };
32 
33 struct rpc_xprt_iter {
34 	struct rpc_xprt_switch __rcu *xpi_xpswitch;
35 	struct rpc_xprt *	xpi_cursor;
36 
37 	const struct rpc_xprt_iter_ops *xpi_ops;
38 };
39 
40 
41 struct rpc_xprt_iter_ops {
42 	void (*xpi_rewind)(struct rpc_xprt_iter *);
43 	struct rpc_xprt *(*xpi_xprt)(struct rpc_xprt_iter *);
44 	struct rpc_xprt *(*xpi_next)(struct rpc_xprt_iter *);
45 };
46 
47 extern struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt,
48 		gfp_t gfp_flags);
49 
50 extern struct rpc_xprt_switch *xprt_switch_get(struct rpc_xprt_switch *xps);
51 extern void xprt_switch_put(struct rpc_xprt_switch *xps);
52 
53 extern void rpc_xprt_switch_set_roundrobin(struct rpc_xprt_switch *xps);
54 
55 extern void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps,
56 		struct rpc_xprt *xprt);
57 extern void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
58 		struct rpc_xprt *xprt, bool offline);
59 
60 extern void xprt_iter_init(struct rpc_xprt_iter *xpi,
61 		struct rpc_xprt_switch *xps);
62 
63 extern void xprt_iter_init_listall(struct rpc_xprt_iter *xpi,
64 		struct rpc_xprt_switch *xps);
65 
66 extern void xprt_iter_init_listoffline(struct rpc_xprt_iter *xpi,
67 		struct rpc_xprt_switch *xps);
68 
69 extern void xprt_iter_destroy(struct rpc_xprt_iter *xpi);
70 
71 extern void xprt_iter_rewind(struct rpc_xprt_iter *xpi);
72 
73 extern struct rpc_xprt_switch *xprt_iter_xchg_switch(
74 		struct rpc_xprt_iter *xpi,
75 		struct rpc_xprt_switch *newswitch);
76 
77 extern struct rpc_xprt *xprt_iter_xprt(struct rpc_xprt_iter *xpi);
78 extern struct rpc_xprt *xprt_iter_get_xprt(struct rpc_xprt_iter *xpi);
79 extern struct rpc_xprt *xprt_iter_get_next(struct rpc_xprt_iter *xpi);
80 
81 extern bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
82 		const struct sockaddr *sap);
83 
84 extern void xprt_multipath_cleanup_ids(void);
85 
86 #endif
87