mon_client.h 3.8 KB

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