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 42d0b19705SIlya Dryomov typedef void (*ceph_monc_callback_t)(struct ceph_mon_generic_request *); 43d0b19705SIlya Dryomov 443d14c5d2SYehuda Sadeh /* 457a6fdeb2SIlya Dryomov * ceph_mon_generic_request is being used for the statfs and 46513a8243SIlya Dryomov * mon_get_version requests which are being done a bit differently 47513a8243SIlya Dryomov * because we need to get data back to the caller 483d14c5d2SYehuda Sadeh */ 493d14c5d2SYehuda Sadeh struct ceph_mon_generic_request { 50d0b19705SIlya Dryomov struct ceph_mon_client *monc; 513d14c5d2SYehuda Sadeh struct kref kref; 523d14c5d2SYehuda Sadeh u64 tid; 533d14c5d2SYehuda Sadeh struct rb_node node; 543d14c5d2SYehuda Sadeh int result; 55d0b19705SIlya Dryomov 563d14c5d2SYehuda Sadeh struct completion completion; 57d0b19705SIlya Dryomov ceph_monc_callback_t complete_cb; 58d0b19705SIlya Dryomov u64 private_data; /* r_tid/linger_id */ 59d0b19705SIlya Dryomov 603d14c5d2SYehuda Sadeh struct ceph_msg *request; /* original request */ 613d14c5d2SYehuda Sadeh struct ceph_msg *reply; /* and reply */ 62d0b19705SIlya Dryomov 63d0b19705SIlya Dryomov union { 64d0b19705SIlya Dryomov struct ceph_statfs *st; 65d0b19705SIlya Dryomov u64 newest; 66d0b19705SIlya Dryomov } u; 673d14c5d2SYehuda Sadeh }; 683d14c5d2SYehuda Sadeh 693d14c5d2SYehuda Sadeh struct ceph_mon_client { 703d14c5d2SYehuda Sadeh struct ceph_client *client; 713d14c5d2SYehuda Sadeh struct ceph_monmap *monmap; 723d14c5d2SYehuda Sadeh 733d14c5d2SYehuda Sadeh struct mutex mutex; 743d14c5d2SYehuda Sadeh struct delayed_work delayed_work; 753d14c5d2SYehuda Sadeh 763d14c5d2SYehuda Sadeh struct ceph_auth_client *auth; 773d14c5d2SYehuda Sadeh struct ceph_msg *m_auth, *m_auth_reply, *m_subscribe, *m_subscribe_ack; 783d14c5d2SYehuda Sadeh int pending_auth; 793d14c5d2SYehuda Sadeh 803d14c5d2SYehuda Sadeh bool hunting; 813d14c5d2SYehuda Sadeh int cur_mon; /* last monitor i contacted */ 8282dcabadSIlya Dryomov unsigned long sub_renew_after; 8382dcabadSIlya Dryomov unsigned long sub_renew_sent; 8467130934SAlex Elder struct ceph_connection con; 853d14c5d2SYehuda Sadeh 86168b9090SIlya Dryomov bool had_a_connection; 87168b9090SIlya Dryomov int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */ 88168b9090SIlya Dryomov 893d14c5d2SYehuda Sadeh /* pending generic requests */ 903d14c5d2SYehuda Sadeh struct rb_root generic_request_tree; 913d14c5d2SYehuda Sadeh u64 last_tid; 923d14c5d2SYehuda Sadeh 9382dcabadSIlya Dryomov /* subs, indexed with CEPH_SUB_* */ 9482dcabadSIlya Dryomov struct { 9582dcabadSIlya Dryomov struct ceph_mon_subscribe_item item; 9682dcabadSIlya Dryomov bool want; 9782dcabadSIlya Dryomov u32 have; /* epoch */ 980cabbd94SYan, Zheng } subs[4]; 99737cc81eSIlya Dryomov int fs_cluster_id; /* "mdsmap.<id>" sub */ 1003d14c5d2SYehuda Sadeh 1013d14c5d2SYehuda Sadeh #ifdef CONFIG_DEBUG_FS 1023d14c5d2SYehuda Sadeh struct dentry *debugfs_file; 1033d14c5d2SYehuda Sadeh #endif 1043d14c5d2SYehuda Sadeh }; 1053d14c5d2SYehuda Sadeh 1063d14c5d2SYehuda Sadeh extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end); 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); 1123d14c5d2SYehuda Sadeh 11382dcabadSIlya Dryomov enum { 1140cabbd94SYan, Zheng CEPH_SUB_MONMAP = 0, 11582dcabadSIlya Dryomov CEPH_SUB_OSDMAP, 1160cabbd94SYan, Zheng CEPH_SUB_FSMAP, 1170cabbd94SYan, Zheng CEPH_SUB_MDSMAP, 11882dcabadSIlya Dryomov }; 11982dcabadSIlya Dryomov 12082dcabadSIlya Dryomov extern const char *ceph_sub_str[]; 12182dcabadSIlya Dryomov 1223d14c5d2SYehuda Sadeh /* 1233d14c5d2SYehuda Sadeh * The model here is to indicate that we need a new map of at least 12482dcabadSIlya Dryomov * epoch @epoch, and also call in when we receive a map. We will 1253d14c5d2SYehuda Sadeh * periodically rerequest the map from the monitor cluster until we 1263d14c5d2SYehuda Sadeh * get what we want. 1273d14c5d2SYehuda Sadeh */ 12882dcabadSIlya Dryomov bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch, 12982dcabadSIlya Dryomov bool continuous); 13082dcabadSIlya Dryomov void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch); 13142c1b124SIlya Dryomov void ceph_monc_renew_subs(struct ceph_mon_client *monc); 1323d14c5d2SYehuda Sadeh 1336044cde6SIlya Dryomov extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch, 1346044cde6SIlya Dryomov unsigned long timeout); 1353d14c5d2SYehuda Sadeh 1363d14c5d2SYehuda Sadeh extern int ceph_monc_do_statfs(struct ceph_mon_client *monc, 1373d14c5d2SYehuda Sadeh struct ceph_statfs *buf); 1383d14c5d2SYehuda Sadeh 139d0b19705SIlya Dryomov int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what, 140d0b19705SIlya Dryomov u64 *newest); 141d0b19705SIlya Dryomov int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what, 142d0b19705SIlya Dryomov ceph_monc_callback_t cb, u64 private_data); 143513a8243SIlya Dryomov 1446305a3b4SDouglas Fuller int ceph_monc_blacklist_add(struct ceph_mon_client *monc, 1456305a3b4SDouglas Fuller struct ceph_entity_addr *client_addr); 1466305a3b4SDouglas Fuller 1473d14c5d2SYehuda Sadeh extern int ceph_monc_open_session(struct ceph_mon_client *monc); 1483d14c5d2SYehuda Sadeh 1493d14c5d2SYehuda Sadeh extern int ceph_monc_validate_auth(struct ceph_mon_client *monc); 1503d14c5d2SYehuda Sadeh 1513d14c5d2SYehuda Sadeh #endif 152