xref: /openbmc/linux/include/linux/ceph/mon_client.h (revision 0b98acd6)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
23d14c5d2SYehuda Sadeh #ifndef _FS_CEPH_MON_CLIENT_H
33d14c5d2SYehuda Sadeh #define _FS_CEPH_MON_CLIENT_H
43d14c5d2SYehuda Sadeh 
53d14c5d2SYehuda Sadeh #include <linux/completion.h>
63d14c5d2SYehuda Sadeh #include <linux/kref.h>
73d14c5d2SYehuda Sadeh #include <linux/rbtree.h>
83d14c5d2SYehuda Sadeh 
9a1ce3928SDavid Howells #include <linux/ceph/messenger.h>
103d14c5d2SYehuda Sadeh 
113d14c5d2SYehuda Sadeh struct ceph_client;
123d14c5d2SYehuda Sadeh struct ceph_mount_args;
133d14c5d2SYehuda Sadeh struct ceph_auth_client;
143d14c5d2SYehuda Sadeh 
153d14c5d2SYehuda Sadeh /*
163d14c5d2SYehuda Sadeh  * The monitor map enumerates the set of all monitors.
173d14c5d2SYehuda Sadeh  */
183d14c5d2SYehuda Sadeh struct ceph_monmap {
193d14c5d2SYehuda Sadeh 	struct ceph_fsid fsid;
203d14c5d2SYehuda Sadeh 	u32 epoch;
213d14c5d2SYehuda Sadeh 	u32 num_mon;
2253ab8e7cSGustavo A. R. Silva 	struct ceph_entity_inst mon_inst[];
233d14c5d2SYehuda Sadeh };
243d14c5d2SYehuda Sadeh 
253d14c5d2SYehuda Sadeh struct ceph_mon_client;
263d14c5d2SYehuda Sadeh struct ceph_mon_generic_request;
273d14c5d2SYehuda Sadeh 
283d14c5d2SYehuda Sadeh 
293d14c5d2SYehuda Sadeh /*
303d14c5d2SYehuda Sadeh  * Generic mechanism for resending monitor requests.
313d14c5d2SYehuda Sadeh  */
323d14c5d2SYehuda Sadeh typedef void (*ceph_monc_request_func_t)(struct ceph_mon_client *monc,
333d14c5d2SYehuda Sadeh 					 int newmon);
343d14c5d2SYehuda Sadeh 
353d14c5d2SYehuda Sadeh /* a pending monitor request */
363d14c5d2SYehuda Sadeh struct ceph_mon_request {
373d14c5d2SYehuda Sadeh 	struct ceph_mon_client *monc;
383d14c5d2SYehuda Sadeh 	struct delayed_work delayed_work;
393d14c5d2SYehuda Sadeh 	unsigned long delay;
403d14c5d2SYehuda Sadeh 	ceph_monc_request_func_t do_request;
413d14c5d2SYehuda Sadeh };
423d14c5d2SYehuda Sadeh 
43d0b19705SIlya Dryomov typedef void (*ceph_monc_callback_t)(struct ceph_mon_generic_request *);
44d0b19705SIlya Dryomov 
453d14c5d2SYehuda Sadeh /*
467a6fdeb2SIlya Dryomov  * ceph_mon_generic_request is being used for the statfs and
47513a8243SIlya Dryomov  * mon_get_version requests which are being done a bit differently
48513a8243SIlya Dryomov  * because we need to get data back to the caller
493d14c5d2SYehuda Sadeh  */
503d14c5d2SYehuda Sadeh struct ceph_mon_generic_request {
51d0b19705SIlya Dryomov 	struct ceph_mon_client *monc;
523d14c5d2SYehuda Sadeh 	struct kref kref;
533d14c5d2SYehuda Sadeh 	u64 tid;
543d14c5d2SYehuda Sadeh 	struct rb_node node;
553d14c5d2SYehuda Sadeh 	int result;
56d0b19705SIlya Dryomov 
573d14c5d2SYehuda Sadeh 	struct completion completion;
58d0b19705SIlya Dryomov 	ceph_monc_callback_t complete_cb;
59d0b19705SIlya Dryomov 	u64 private_data;          /* r_tid/linger_id */
60d0b19705SIlya Dryomov 
613d14c5d2SYehuda Sadeh 	struct ceph_msg *request;  /* original request */
623d14c5d2SYehuda Sadeh 	struct ceph_msg *reply;    /* and reply */
63d0b19705SIlya Dryomov 
64d0b19705SIlya Dryomov 	union {
65d0b19705SIlya Dryomov 		struct ceph_statfs *st;
66d0b19705SIlya Dryomov 		u64 newest;
67d0b19705SIlya Dryomov 	} u;
683d14c5d2SYehuda Sadeh };
693d14c5d2SYehuda Sadeh 
703d14c5d2SYehuda Sadeh struct ceph_mon_client {
713d14c5d2SYehuda Sadeh 	struct ceph_client *client;
723d14c5d2SYehuda Sadeh 	struct ceph_monmap *monmap;
733d14c5d2SYehuda Sadeh 
743d14c5d2SYehuda Sadeh 	struct mutex mutex;
753d14c5d2SYehuda Sadeh 	struct delayed_work delayed_work;
763d14c5d2SYehuda Sadeh 
773d14c5d2SYehuda Sadeh 	struct ceph_auth_client *auth;
783d14c5d2SYehuda Sadeh 	struct ceph_msg *m_auth, *m_auth_reply, *m_subscribe, *m_subscribe_ack;
793d14c5d2SYehuda Sadeh 	int pending_auth;
803d14c5d2SYehuda Sadeh 
813d14c5d2SYehuda Sadeh 	bool hunting;
823d14c5d2SYehuda Sadeh 	int cur_mon;                       /* last monitor i contacted */
8382dcabadSIlya Dryomov 	unsigned long sub_renew_after;
8482dcabadSIlya Dryomov 	unsigned long sub_renew_sent;
8567130934SAlex Elder 	struct ceph_connection con;
863d14c5d2SYehuda Sadeh 
87168b9090SIlya Dryomov 	bool had_a_connection;
88168b9090SIlya Dryomov 	int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */
89168b9090SIlya Dryomov 
903d14c5d2SYehuda Sadeh 	/* pending generic requests */
913d14c5d2SYehuda Sadeh 	struct rb_root generic_request_tree;
923d14c5d2SYehuda Sadeh 	u64 last_tid;
933d14c5d2SYehuda Sadeh 
9482dcabadSIlya Dryomov 	/* subs, indexed with CEPH_SUB_* */
9582dcabadSIlya Dryomov 	struct {
9682dcabadSIlya Dryomov 		struct ceph_mon_subscribe_item item;
9782dcabadSIlya Dryomov 		bool want;
9882dcabadSIlya Dryomov 		u32 have; /* epoch */
990cabbd94SYan, Zheng 	} subs[4];
100737cc81eSIlya Dryomov 	int fs_cluster_id; /* "mdsmap.<id>" sub */
1013d14c5d2SYehuda Sadeh 
1023d14c5d2SYehuda Sadeh #ifdef CONFIG_DEBUG_FS
1033d14c5d2SYehuda Sadeh 	struct dentry *debugfs_file;
1043d14c5d2SYehuda Sadeh #endif
1053d14c5d2SYehuda Sadeh };
1063d14c5d2SYehuda Sadeh 
1073d14c5d2SYehuda Sadeh extern int ceph_monmap_contains(struct ceph_monmap *m,
1083d14c5d2SYehuda Sadeh 				struct ceph_entity_addr *addr);
1093d14c5d2SYehuda Sadeh 
1103d14c5d2SYehuda Sadeh extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl);
1113d14c5d2SYehuda Sadeh extern void ceph_monc_stop(struct ceph_mon_client *monc);
112120a75eaSYan, Zheng extern void ceph_monc_reopen_session(struct ceph_mon_client *monc);
1133d14c5d2SYehuda Sadeh 
11482dcabadSIlya Dryomov enum {
1150cabbd94SYan, Zheng 	CEPH_SUB_MONMAP = 0,
11682dcabadSIlya Dryomov 	CEPH_SUB_OSDMAP,
1170cabbd94SYan, Zheng 	CEPH_SUB_FSMAP,
1180cabbd94SYan, Zheng 	CEPH_SUB_MDSMAP,
11982dcabadSIlya Dryomov };
12082dcabadSIlya Dryomov 
12182dcabadSIlya Dryomov extern const char *ceph_sub_str[];
12282dcabadSIlya Dryomov 
1233d14c5d2SYehuda Sadeh /*
1243d14c5d2SYehuda Sadeh  * The model here is to indicate that we need a new map of at least
12582dcabadSIlya Dryomov  * epoch @epoch, and also call in when we receive a map.  We will
1263d14c5d2SYehuda Sadeh  * periodically rerequest the map from the monitor cluster until we
1273d14c5d2SYehuda Sadeh  * get what we want.
1283d14c5d2SYehuda Sadeh  */
12982dcabadSIlya Dryomov bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch,
13082dcabadSIlya Dryomov 			bool continuous);
13182dcabadSIlya Dryomov void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch);
13242c1b124SIlya Dryomov void ceph_monc_renew_subs(struct ceph_mon_client *monc);
1333d14c5d2SYehuda Sadeh 
1346044cde6SIlya Dryomov extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
1356044cde6SIlya Dryomov 				 unsigned long timeout);
1363d14c5d2SYehuda Sadeh 
13706d74376SDouglas Fuller int ceph_monc_do_statfs(struct ceph_mon_client *monc, u64 data_pool,
1383d14c5d2SYehuda Sadeh 			struct ceph_statfs *buf);
1393d14c5d2SYehuda Sadeh 
140d0b19705SIlya Dryomov int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
141d0b19705SIlya Dryomov 			  u64 *newest);
142d0b19705SIlya Dryomov int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
143d0b19705SIlya Dryomov 				ceph_monc_callback_t cb, u64 private_data);
144513a8243SIlya Dryomov 
1450b98acd6SIlya Dryomov int ceph_monc_blocklist_add(struct ceph_mon_client *monc,
1466305a3b4SDouglas Fuller 			    struct ceph_entity_addr *client_addr);
1476305a3b4SDouglas Fuller 
1483d14c5d2SYehuda Sadeh extern int ceph_monc_open_session(struct ceph_mon_client *monc);
1493d14c5d2SYehuda Sadeh 
1503d14c5d2SYehuda Sadeh extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
1513d14c5d2SYehuda Sadeh 
1523d14c5d2SYehuda Sadeh #endif
153