mon_client.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #ifndef _FS_CEPH_MON_CLIENT_H
  2. #define _FS_CEPH_MON_CLIENT_H
  3. #include <linux/completion.h>
  4. #include <linux/kref.h>
  5. #include <linux/rbtree.h>
  6. #include <linux/ceph/messenger.h>
  7. struct ceph_client;
  8. struct ceph_mount_args;
  9. struct ceph_auth_client;
  10. /*
  11. * The monitor map enumerates the set of all monitors.
  12. */
  13. struct ceph_monmap {
  14. struct ceph_fsid fsid;
  15. u32 epoch;
  16. u32 num_mon;
  17. struct ceph_entity_inst mon_inst[0];
  18. };
  19. struct ceph_mon_client;
  20. struct ceph_mon_generic_request;
  21. /*
  22. * Generic mechanism for resending monitor requests.
  23. */
  24. typedef void (*ceph_monc_request_func_t)(struct ceph_mon_client *monc,
  25. int newmon);
  26. /* a pending monitor request */
  27. struct ceph_mon_request {
  28. struct ceph_mon_client *monc;
  29. struct delayed_work delayed_work;
  30. unsigned long delay;
  31. ceph_monc_request_func_t do_request;
  32. };
  33. typedef void (*ceph_monc_callback_t)(struct ceph_mon_generic_request *);
  34. /*
  35. * ceph_mon_generic_request is being used for the statfs and
  36. * mon_get_version requests which are being done a bit differently
  37. * because we need to get data back to the caller
  38. */
  39. struct ceph_mon_generic_request {
  40. struct ceph_mon_client *monc;
  41. struct kref kref;
  42. u64 tid;
  43. struct rb_node node;
  44. int result;
  45. struct completion completion;
  46. ceph_monc_callback_t complete_cb;
  47. u64 private_data; /* r_tid/linger_id */
  48. struct ceph_msg *request; /* original request */
  49. struct ceph_msg *reply; /* and reply */
  50. union {
  51. struct ceph_statfs *st;
  52. u64 newest;
  53. } u;
  54. };
  55. struct ceph_mon_client {
  56. struct ceph_client *client;
  57. struct ceph_monmap *monmap;
  58. struct mutex mutex;
  59. struct delayed_work delayed_work;
  60. struct ceph_auth_client *auth;
  61. struct ceph_msg *m_auth, *m_auth_reply, *m_subscribe, *m_subscribe_ack;
  62. int pending_auth;
  63. bool hunting;
  64. int cur_mon; /* last monitor i contacted */
  65. unsigned long sub_renew_after;
  66. unsigned long sub_renew_sent;
  67. struct ceph_connection con;
  68. bool had_a_connection;
  69. int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */
  70. /* pending generic requests */
  71. struct rb_root generic_request_tree;
  72. u64 last_tid;
  73. /* subs, indexed with CEPH_SUB_* */
  74. struct {
  75. struct ceph_mon_subscribe_item item;
  76. bool want;
  77. u32 have; /* epoch */
  78. } subs[4];
  79. int fs_cluster_id; /* "mdsmap.<id>" sub */
  80. #ifdef CONFIG_DEBUG_FS
  81. struct dentry *debugfs_file;
  82. #endif
  83. };
  84. extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end);
  85. extern int ceph_monmap_contains(struct ceph_monmap *m,
  86. struct ceph_entity_addr *addr);
  87. extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl);
  88. extern void ceph_monc_stop(struct ceph_mon_client *monc);
  89. enum {
  90. CEPH_SUB_MONMAP = 0,
  91. CEPH_SUB_OSDMAP,
  92. CEPH_SUB_FSMAP,
  93. CEPH_SUB_MDSMAP,
  94. };
  95. extern const char *ceph_sub_str[];
  96. /*
  97. * The model here is to indicate that we need a new map of at least
  98. * epoch @epoch, and also call in when we receive a map. We will
  99. * periodically rerequest the map from the monitor cluster until we
  100. * get what we want.
  101. */
  102. bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch,
  103. bool continuous);
  104. void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch);
  105. void ceph_monc_renew_subs(struct ceph_mon_client *monc);
  106. extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
  107. unsigned long timeout);
  108. extern int ceph_monc_do_statfs(struct ceph_mon_client *monc,
  109. struct ceph_statfs *buf);
  110. int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
  111. u64 *newest);
  112. int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
  113. ceph_monc_callback_t cb, u64 private_data);
  114. int ceph_monc_blacklist_add(struct ceph_mon_client *monc,
  115. struct ceph_entity_addr *client_addr);
  116. extern int ceph_monc_open_session(struct ceph_mon_client *monc);
  117. extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
  118. #endif