Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _FS_CEPH_MON_CLIENT_H
0003 #define _FS_CEPH_MON_CLIENT_H
0004 
0005 #include <linux/completion.h>
0006 #include <linux/kref.h>
0007 #include <linux/rbtree.h>
0008 
0009 #include <linux/ceph/messenger.h>
0010 
0011 struct ceph_client;
0012 struct ceph_mount_args;
0013 struct ceph_auth_client;
0014 
0015 /*
0016  * The monitor map enumerates the set of all monitors.
0017  */
0018 struct ceph_monmap {
0019     struct ceph_fsid fsid;
0020     u32 epoch;
0021     u32 num_mon;
0022     struct ceph_entity_inst mon_inst[];
0023 };
0024 
0025 struct ceph_mon_client;
0026 struct ceph_mon_generic_request;
0027 
0028 
0029 /*
0030  * Generic mechanism for resending monitor requests.
0031  */
0032 typedef void (*ceph_monc_request_func_t)(struct ceph_mon_client *monc,
0033                      int newmon);
0034 
0035 /* a pending monitor request */
0036 struct ceph_mon_request {
0037     struct ceph_mon_client *monc;
0038     struct delayed_work delayed_work;
0039     unsigned long delay;
0040     ceph_monc_request_func_t do_request;
0041 };
0042 
0043 typedef void (*ceph_monc_callback_t)(struct ceph_mon_generic_request *);
0044 
0045 /*
0046  * ceph_mon_generic_request is being used for the statfs and
0047  * mon_get_version requests which are being done a bit differently
0048  * because we need to get data back to the caller
0049  */
0050 struct ceph_mon_generic_request {
0051     struct ceph_mon_client *monc;
0052     struct kref kref;
0053     u64 tid;
0054     struct rb_node node;
0055     int result;
0056 
0057     struct completion completion;
0058     ceph_monc_callback_t complete_cb;
0059     u64 private_data;          /* r_tid/linger_id */
0060 
0061     struct ceph_msg *request;  /* original request */
0062     struct ceph_msg *reply;    /* and reply */
0063 
0064     union {
0065         struct ceph_statfs *st;
0066         u64 newest;
0067     } u;
0068 };
0069 
0070 struct ceph_mon_client {
0071     struct ceph_client *client;
0072     struct ceph_monmap *monmap;
0073 
0074     struct mutex mutex;
0075     struct delayed_work delayed_work;
0076 
0077     struct ceph_auth_client *auth;
0078     struct ceph_msg *m_auth, *m_auth_reply, *m_subscribe, *m_subscribe_ack;
0079     int pending_auth;
0080 
0081     bool hunting;
0082     int cur_mon;                       /* last monitor i contacted */
0083     unsigned long sub_renew_after;
0084     unsigned long sub_renew_sent;
0085     struct ceph_connection con;
0086 
0087     bool had_a_connection;
0088     int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */
0089 
0090     /* pending generic requests */
0091     struct rb_root generic_request_tree;
0092     u64 last_tid;
0093 
0094     /* subs, indexed with CEPH_SUB_* */
0095     struct {
0096         struct ceph_mon_subscribe_item item;
0097         bool want;
0098         u32 have; /* epoch */
0099     } subs[4];
0100     int fs_cluster_id; /* "mdsmap.<id>" sub */
0101 
0102 #ifdef CONFIG_DEBUG_FS
0103     struct dentry *debugfs_file;
0104 #endif
0105 };
0106 
0107 extern int ceph_monmap_contains(struct ceph_monmap *m,
0108                 struct ceph_entity_addr *addr);
0109 
0110 extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl);
0111 extern void ceph_monc_stop(struct ceph_mon_client *monc);
0112 extern void ceph_monc_reopen_session(struct ceph_mon_client *monc);
0113 
0114 enum {
0115     CEPH_SUB_MONMAP = 0,
0116     CEPH_SUB_OSDMAP,
0117     CEPH_SUB_FSMAP,
0118     CEPH_SUB_MDSMAP,
0119 };
0120 
0121 extern const char *ceph_sub_str[];
0122 
0123 /*
0124  * The model here is to indicate that we need a new map of at least
0125  * epoch @epoch, and also call in when we receive a map.  We will
0126  * periodically rerequest the map from the monitor cluster until we
0127  * get what we want.
0128  */
0129 bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch,
0130             bool continuous);
0131 void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch);
0132 void ceph_monc_renew_subs(struct ceph_mon_client *monc);
0133 
0134 extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
0135                  unsigned long timeout);
0136 
0137 int ceph_monc_do_statfs(struct ceph_mon_client *monc, u64 data_pool,
0138             struct ceph_statfs *buf);
0139 
0140 int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
0141               u64 *newest);
0142 int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
0143                 ceph_monc_callback_t cb, u64 private_data);
0144 
0145 int ceph_monc_blocklist_add(struct ceph_mon_client *monc,
0146                 struct ceph_entity_addr *client_addr);
0147 
0148 extern int ceph_monc_open_session(struct ceph_mon_client *monc);
0149 
0150 extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
0151 
0152 #endif