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 75168b9090SIlya Dryomov bool had_a_connection; 76168b9090SIlya Dryomov int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */ 77168b9090SIlya Dryomov 783d14c5d2SYehuda Sadeh /* pending generic requests */ 793d14c5d2SYehuda Sadeh struct rb_root generic_request_tree; 803d14c5d2SYehuda Sadeh u64 last_tid; 813d14c5d2SYehuda Sadeh 8282dcabadSIlya Dryomov /* subs, indexed with CEPH_SUB_* */ 8382dcabadSIlya Dryomov struct { 8482dcabadSIlya Dryomov struct ceph_mon_subscribe_item item; 8582dcabadSIlya Dryomov bool want; 8682dcabadSIlya Dryomov u32 have; /* epoch */ 8782dcabadSIlya Dryomov } subs[3]; 883d14c5d2SYehuda Sadeh 893d14c5d2SYehuda Sadeh #ifdef CONFIG_DEBUG_FS 903d14c5d2SYehuda Sadeh struct dentry *debugfs_file; 913d14c5d2SYehuda Sadeh #endif 923d14c5d2SYehuda Sadeh }; 933d14c5d2SYehuda Sadeh 943d14c5d2SYehuda Sadeh extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end); 953d14c5d2SYehuda Sadeh extern int ceph_monmap_contains(struct ceph_monmap *m, 963d14c5d2SYehuda Sadeh struct ceph_entity_addr *addr); 973d14c5d2SYehuda Sadeh 983d14c5d2SYehuda Sadeh extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl); 993d14c5d2SYehuda Sadeh extern void ceph_monc_stop(struct ceph_mon_client *monc); 1003d14c5d2SYehuda Sadeh 10182dcabadSIlya Dryomov enum { 10282dcabadSIlya Dryomov CEPH_SUB_MDSMAP = 0, 10382dcabadSIlya Dryomov CEPH_SUB_MONMAP, 10482dcabadSIlya Dryomov CEPH_SUB_OSDMAP, 10582dcabadSIlya Dryomov }; 10682dcabadSIlya Dryomov 10782dcabadSIlya Dryomov extern const char *ceph_sub_str[]; 10882dcabadSIlya Dryomov 1093d14c5d2SYehuda Sadeh /* 1103d14c5d2SYehuda Sadeh * The model here is to indicate that we need a new map of at least 11182dcabadSIlya Dryomov * epoch @epoch, and also call in when we receive a map. We will 1123d14c5d2SYehuda Sadeh * periodically rerequest the map from the monitor cluster until we 1133d14c5d2SYehuda Sadeh * get what we want. 1143d14c5d2SYehuda Sadeh */ 11582dcabadSIlya Dryomov bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch, 11682dcabadSIlya Dryomov bool continuous); 11782dcabadSIlya Dryomov void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch); 11842c1b124SIlya Dryomov void ceph_monc_renew_subs(struct ceph_mon_client *monc); 1193d14c5d2SYehuda Sadeh 1203d14c5d2SYehuda Sadeh extern void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc); 1216044cde6SIlya Dryomov extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch, 1226044cde6SIlya Dryomov unsigned long timeout); 1233d14c5d2SYehuda Sadeh 1243d14c5d2SYehuda Sadeh extern int ceph_monc_do_statfs(struct ceph_mon_client *monc, 1253d14c5d2SYehuda Sadeh struct ceph_statfs *buf); 1263d14c5d2SYehuda Sadeh 127513a8243SIlya Dryomov extern int ceph_monc_do_get_version(struct ceph_mon_client *monc, 128513a8243SIlya Dryomov const char *what, u64 *newest); 129513a8243SIlya Dryomov 1303d14c5d2SYehuda Sadeh extern int ceph_monc_open_session(struct ceph_mon_client *monc); 1313d14c5d2SYehuda Sadeh 1323d14c5d2SYehuda Sadeh extern int ceph_monc_validate_auth(struct ceph_mon_client *monc); 1333d14c5d2SYehuda Sadeh 1343d14c5d2SYehuda Sadeh #endif 135