xref: /openbmc/linux/include/linux/ceph/mon_client.h (revision 7a6fdeb2)
13d14c5d2SYehuda Sadeh #ifndef _FS_CEPH_MON_CLIENT_H
23d14c5d2SYehuda Sadeh #define _FS_CEPH_MON_CLIENT_H
33d14c5d2SYehuda Sadeh 
43d14c5d2SYehuda Sadeh #include <linux/completion.h>
53d14c5d2SYehuda Sadeh #include <linux/kref.h>
63d14c5d2SYehuda Sadeh #include <linux/rbtree.h>
73d14c5d2SYehuda Sadeh 
8a1ce3928SDavid Howells #include <linux/ceph/messenger.h>
93d14c5d2SYehuda Sadeh 
103d14c5d2SYehuda Sadeh struct ceph_client;
113d14c5d2SYehuda Sadeh struct ceph_mount_args;
123d14c5d2SYehuda Sadeh struct ceph_auth_client;
133d14c5d2SYehuda Sadeh 
143d14c5d2SYehuda Sadeh /*
153d14c5d2SYehuda Sadeh  * The monitor map enumerates the set of all monitors.
163d14c5d2SYehuda Sadeh  */
173d14c5d2SYehuda Sadeh struct ceph_monmap {
183d14c5d2SYehuda Sadeh 	struct ceph_fsid fsid;
193d14c5d2SYehuda Sadeh 	u32 epoch;
203d14c5d2SYehuda Sadeh 	u32 num_mon;
213d14c5d2SYehuda Sadeh 	struct ceph_entity_inst mon_inst[0];
223d14c5d2SYehuda Sadeh };
233d14c5d2SYehuda Sadeh 
243d14c5d2SYehuda Sadeh struct ceph_mon_client;
253d14c5d2SYehuda Sadeh struct ceph_mon_generic_request;
263d14c5d2SYehuda Sadeh 
273d14c5d2SYehuda Sadeh 
283d14c5d2SYehuda Sadeh /*
293d14c5d2SYehuda Sadeh  * Generic mechanism for resending monitor requests.
303d14c5d2SYehuda Sadeh  */
313d14c5d2SYehuda Sadeh typedef void (*ceph_monc_request_func_t)(struct ceph_mon_client *monc,
323d14c5d2SYehuda Sadeh 					 int newmon);
333d14c5d2SYehuda Sadeh 
343d14c5d2SYehuda Sadeh /* a pending monitor request */
353d14c5d2SYehuda Sadeh struct ceph_mon_request {
363d14c5d2SYehuda Sadeh 	struct ceph_mon_client *monc;
373d14c5d2SYehuda Sadeh 	struct delayed_work delayed_work;
383d14c5d2SYehuda Sadeh 	unsigned long delay;
393d14c5d2SYehuda Sadeh 	ceph_monc_request_func_t do_request;
403d14c5d2SYehuda Sadeh };
413d14c5d2SYehuda Sadeh 
423d14c5d2SYehuda Sadeh /*
437a6fdeb2SIlya Dryomov  * ceph_mon_generic_request is being used for the statfs and
44513a8243SIlya Dryomov  * mon_get_version requests which are being done a bit differently
45513a8243SIlya Dryomov  * because we need to get data back to the caller
463d14c5d2SYehuda Sadeh  */
473d14c5d2SYehuda Sadeh struct ceph_mon_generic_request {
483d14c5d2SYehuda Sadeh 	struct kref kref;
493d14c5d2SYehuda Sadeh 	u64 tid;
503d14c5d2SYehuda Sadeh 	struct rb_node node;
513d14c5d2SYehuda Sadeh 	int result;
523d14c5d2SYehuda Sadeh 	void *buf;
533d14c5d2SYehuda Sadeh 	struct completion completion;
543d14c5d2SYehuda Sadeh 	struct ceph_msg *request;  /* original request */
553d14c5d2SYehuda Sadeh 	struct ceph_msg *reply;    /* and reply */
563d14c5d2SYehuda Sadeh };
573d14c5d2SYehuda Sadeh 
583d14c5d2SYehuda Sadeh struct ceph_mon_client {
593d14c5d2SYehuda Sadeh 	struct ceph_client *client;
603d14c5d2SYehuda Sadeh 	struct ceph_monmap *monmap;
613d14c5d2SYehuda Sadeh 
623d14c5d2SYehuda Sadeh 	struct mutex mutex;
633d14c5d2SYehuda Sadeh 	struct delayed_work delayed_work;
643d14c5d2SYehuda Sadeh 
653d14c5d2SYehuda Sadeh 	struct ceph_auth_client *auth;
663d14c5d2SYehuda Sadeh 	struct ceph_msg *m_auth, *m_auth_reply, *m_subscribe, *m_subscribe_ack;
673d14c5d2SYehuda Sadeh 	int pending_auth;
683d14c5d2SYehuda Sadeh 
693d14c5d2SYehuda Sadeh 	bool hunting;
703d14c5d2SYehuda Sadeh 	int cur_mon;                       /* last monitor i contacted */
713d14c5d2SYehuda Sadeh 	unsigned long sub_sent, sub_renew_after;
7267130934SAlex Elder 	struct ceph_connection con;
733d14c5d2SYehuda Sadeh 
743d14c5d2SYehuda Sadeh 	/* pending generic requests */
753d14c5d2SYehuda Sadeh 	struct rb_root generic_request_tree;
763d14c5d2SYehuda Sadeh 	int num_generic_requests;
773d14c5d2SYehuda Sadeh 	u64 last_tid;
783d14c5d2SYehuda Sadeh 
793d14c5d2SYehuda Sadeh 	/* mds/osd map */
803d14c5d2SYehuda Sadeh 	int want_mdsmap;
813d14c5d2SYehuda Sadeh 	int want_next_osdmap; /* 1 = want, 2 = want+asked */
823d14c5d2SYehuda Sadeh 	u32 have_osdmap, have_mdsmap;
833d14c5d2SYehuda Sadeh 
843d14c5d2SYehuda Sadeh #ifdef CONFIG_DEBUG_FS
853d14c5d2SYehuda Sadeh 	struct dentry *debugfs_file;
863d14c5d2SYehuda Sadeh #endif
873d14c5d2SYehuda Sadeh };
883d14c5d2SYehuda Sadeh 
893d14c5d2SYehuda Sadeh extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end);
903d14c5d2SYehuda Sadeh extern int ceph_monmap_contains(struct ceph_monmap *m,
913d14c5d2SYehuda Sadeh 				struct ceph_entity_addr *addr);
923d14c5d2SYehuda Sadeh 
933d14c5d2SYehuda Sadeh extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl);
943d14c5d2SYehuda Sadeh extern void ceph_monc_stop(struct ceph_mon_client *monc);
953d14c5d2SYehuda Sadeh 
963d14c5d2SYehuda Sadeh /*
973d14c5d2SYehuda Sadeh  * The model here is to indicate that we need a new map of at least
983d14c5d2SYehuda Sadeh  * epoch @want, and also call in when we receive a map.  We will
993d14c5d2SYehuda Sadeh  * periodically rerequest the map from the monitor cluster until we
1003d14c5d2SYehuda Sadeh  * get what we want.
1013d14c5d2SYehuda Sadeh  */
1023d14c5d2SYehuda Sadeh extern int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 have);
1033d14c5d2SYehuda Sadeh extern int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 have);
1043d14c5d2SYehuda Sadeh 
1053d14c5d2SYehuda Sadeh extern void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc);
1066044cde6SIlya Dryomov extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
1076044cde6SIlya Dryomov 				 unsigned long timeout);
1083d14c5d2SYehuda Sadeh 
1093d14c5d2SYehuda Sadeh extern int ceph_monc_do_statfs(struct ceph_mon_client *monc,
1103d14c5d2SYehuda Sadeh 			       struct ceph_statfs *buf);
1113d14c5d2SYehuda Sadeh 
112513a8243SIlya Dryomov extern int ceph_monc_do_get_version(struct ceph_mon_client *monc,
113513a8243SIlya Dryomov 				    const char *what, u64 *newest);
114513a8243SIlya Dryomov 
1153d14c5d2SYehuda Sadeh extern int ceph_monc_open_session(struct ceph_mon_client *monc);
1163d14c5d2SYehuda Sadeh 
1173d14c5d2SYehuda Sadeh extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
1183d14c5d2SYehuda Sadeh 
1193d14c5d2SYehuda Sadeh #endif
120