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 */ 7182dcabadSIlya Dryomov unsigned long sub_renew_after; 7282dcabadSIlya Dryomov unsigned long sub_renew_sent; 7367130934SAlex Elder struct ceph_connection con; 743d14c5d2SYehuda Sadeh 753d14c5d2SYehuda Sadeh /* pending generic requests */ 763d14c5d2SYehuda Sadeh struct rb_root generic_request_tree; 773d14c5d2SYehuda Sadeh int num_generic_requests; 783d14c5d2SYehuda Sadeh u64 last_tid; 793d14c5d2SYehuda Sadeh 8082dcabadSIlya Dryomov /* subs, indexed with CEPH_SUB_* */ 8182dcabadSIlya Dryomov struct { 8282dcabadSIlya Dryomov struct ceph_mon_subscribe_item item; 8382dcabadSIlya Dryomov bool want; 8482dcabadSIlya Dryomov u32 have; /* epoch */ 8582dcabadSIlya Dryomov } subs[3]; 863d14c5d2SYehuda Sadeh 873d14c5d2SYehuda Sadeh #ifdef CONFIG_DEBUG_FS 883d14c5d2SYehuda Sadeh struct dentry *debugfs_file; 893d14c5d2SYehuda Sadeh #endif 903d14c5d2SYehuda Sadeh }; 913d14c5d2SYehuda Sadeh 923d14c5d2SYehuda Sadeh extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end); 933d14c5d2SYehuda Sadeh extern int ceph_monmap_contains(struct ceph_monmap *m, 943d14c5d2SYehuda Sadeh struct ceph_entity_addr *addr); 953d14c5d2SYehuda Sadeh 963d14c5d2SYehuda Sadeh extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl); 973d14c5d2SYehuda Sadeh extern void ceph_monc_stop(struct ceph_mon_client *monc); 983d14c5d2SYehuda Sadeh 9982dcabadSIlya Dryomov enum { 10082dcabadSIlya Dryomov CEPH_SUB_MDSMAP = 0, 10182dcabadSIlya Dryomov CEPH_SUB_MONMAP, 10282dcabadSIlya Dryomov CEPH_SUB_OSDMAP, 10382dcabadSIlya Dryomov }; 10482dcabadSIlya Dryomov 10582dcabadSIlya Dryomov extern const char *ceph_sub_str[]; 10682dcabadSIlya Dryomov 1073d14c5d2SYehuda Sadeh /* 1083d14c5d2SYehuda Sadeh * The model here is to indicate that we need a new map of at least 10982dcabadSIlya Dryomov * epoch @epoch, and also call in when we receive a map. We will 1103d14c5d2SYehuda Sadeh * periodically rerequest the map from the monitor cluster until we 1113d14c5d2SYehuda Sadeh * get what we want. 1123d14c5d2SYehuda Sadeh */ 11382dcabadSIlya Dryomov bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch, 11482dcabadSIlya Dryomov bool continuous); 11582dcabadSIlya Dryomov void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch); 1163d14c5d2SYehuda Sadeh 1173d14c5d2SYehuda Sadeh extern void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc); 1186044cde6SIlya Dryomov extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch, 1196044cde6SIlya Dryomov unsigned long timeout); 1203d14c5d2SYehuda Sadeh 1213d14c5d2SYehuda Sadeh extern int ceph_monc_do_statfs(struct ceph_mon_client *monc, 1223d14c5d2SYehuda Sadeh struct ceph_statfs *buf); 1233d14c5d2SYehuda Sadeh 124513a8243SIlya Dryomov extern int ceph_monc_do_get_version(struct ceph_mon_client *monc, 125513a8243SIlya Dryomov const char *what, u64 *newest); 126513a8243SIlya Dryomov 1273d14c5d2SYehuda Sadeh extern int ceph_monc_open_session(struct ceph_mon_client *monc); 1283d14c5d2SYehuda Sadeh 1293d14c5d2SYehuda Sadeh extern int ceph_monc_validate_auth(struct ceph_mon_client *monc); 1303d14c5d2SYehuda Sadeh 1313d14c5d2SYehuda Sadeh #endif 132