1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _FS_CEPH_MON_CLIENT_H
3 #define _FS_CEPH_MON_CLIENT_H
4 
5 #include <linux/completion.h>
6 #include <linux/kref.h>
7 #include <linux/rbtree.h>
8 
9 #include <linux/ceph/messenger.h>
10 
11 struct ceph_client;
12 struct ceph_mount_args;
13 struct ceph_auth_client;
14 
15 /*
16  * The monitor map enumerates the set of all monitors.
17  */
18 struct ceph_monmap {
19 	struct ceph_fsid fsid;
20 	u32 epoch;
21 	u32 num_mon;
22 	struct ceph_entity_inst mon_inst[0];
23 };
24 
25 struct ceph_mon_client;
26 struct ceph_mon_generic_request;
27 
28 
29 /*
30  * Generic mechanism for resending monitor requests.
31  */
32 typedef void (*ceph_monc_request_func_t)(struct ceph_mon_client *monc,
33 					 int newmon);
34 
35 /* a pending monitor request */
36 struct ceph_mon_request {
37 	struct ceph_mon_client *monc;
38 	struct delayed_work delayed_work;
39 	unsigned long delay;
40 	ceph_monc_request_func_t do_request;
41 };
42 
43 typedef void (*ceph_monc_callback_t)(struct ceph_mon_generic_request *);
44 
45 /*
46  * ceph_mon_generic_request is being used for the statfs and
47  * mon_get_version requests which are being done a bit differently
48  * because we need to get data back to the caller
49  */
50 struct ceph_mon_generic_request {
51 	struct ceph_mon_client *monc;
52 	struct kref kref;
53 	u64 tid;
54 	struct rb_node node;
55 	int result;
56 
57 	struct completion completion;
58 	ceph_monc_callback_t complete_cb;
59 	u64 private_data;          /* r_tid/linger_id */
60 
61 	struct ceph_msg *request;  /* original request */
62 	struct ceph_msg *reply;    /* and reply */
63 
64 	union {
65 		struct ceph_statfs *st;
66 		u64 newest;
67 	} u;
68 };
69 
70 struct ceph_mon_client {
71 	struct ceph_client *client;
72 	struct ceph_monmap *monmap;
73 
74 	struct mutex mutex;
75 	struct delayed_work delayed_work;
76 
77 	struct ceph_auth_client *auth;
78 	struct ceph_msg *m_auth, *m_auth_reply, *m_subscribe, *m_subscribe_ack;
79 	int pending_auth;
80 
81 	bool hunting;
82 	int cur_mon;                       /* last monitor i contacted */
83 	unsigned long sub_renew_after;
84 	unsigned long sub_renew_sent;
85 	struct ceph_connection con;
86 
87 	bool had_a_connection;
88 	int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */
89 
90 	/* pending generic requests */
91 	struct rb_root generic_request_tree;
92 	u64 last_tid;
93 
94 	/* subs, indexed with CEPH_SUB_* */
95 	struct {
96 		struct ceph_mon_subscribe_item item;
97 		bool want;
98 		u32 have; /* epoch */
99 	} subs[4];
100 	int fs_cluster_id; /* "mdsmap.<id>" sub */
101 
102 #ifdef CONFIG_DEBUG_FS
103 	struct dentry *debugfs_file;
104 #endif
105 };
106 
107 extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end);
108 extern int ceph_monmap_contains(struct ceph_monmap *m,
109 				struct ceph_entity_addr *addr);
110 
111 extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl);
112 extern void ceph_monc_stop(struct ceph_mon_client *monc);
113 
114 enum {
115 	CEPH_SUB_MONMAP = 0,
116 	CEPH_SUB_OSDMAP,
117 	CEPH_SUB_FSMAP,
118 	CEPH_SUB_MDSMAP,
119 };
120 
121 extern const char *ceph_sub_str[];
122 
123 /*
124  * The model here is to indicate that we need a new map of at least
125  * epoch @epoch, and also call in when we receive a map.  We will
126  * periodically rerequest the map from the monitor cluster until we
127  * get what we want.
128  */
129 bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch,
130 			bool continuous);
131 void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch);
132 void ceph_monc_renew_subs(struct ceph_mon_client *monc);
133 
134 extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
135 				 unsigned long timeout);
136 
137 int ceph_monc_do_statfs(struct ceph_mon_client *monc, u64 data_pool,
138 			struct ceph_statfs *buf);
139 
140 int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
141 			  u64 *newest);
142 int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
143 				ceph_monc_callback_t cb, u64 private_data);
144 
145 int ceph_monc_blacklist_add(struct ceph_mon_client *monc,
146 			    struct ceph_entity_addr *client_addr);
147 
148 extern int ceph_monc_open_session(struct ceph_mon_client *monc);
149 
150 extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
151 
152 #endif
153