blob: b658961156a036d88950d8d7ebc96f146ff4c2b6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sage Weilba75bb92009-10-06 11:31:11 -07002#ifndef _FS_CEPH_MON_CLIENT_H
3#define _FS_CEPH_MON_CLIENT_H
4
5#include <linux/completion.h>
Sage Weil3143edd2010-03-24 21:43:33 -07006#include <linux/kref.h>
Sage Weil85ff03f2010-02-15 14:47:28 -08007#include <linux/rbtree.h>
Sage Weilba75bb92009-10-06 11:31:11 -07008
David Howellsa1ce3922012-10-02 18:01:25 +01009#include <linux/ceph/messenger.h>
Sage Weilba75bb92009-10-06 11:31:11 -070010
11struct ceph_client;
12struct ceph_mount_args;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080013struct ceph_auth_client;
Sage Weilba75bb92009-10-06 11:31:11 -070014
15/*
16 * The monitor map enumerates the set of all monitors.
17 */
18struct ceph_monmap {
19 struct ceph_fsid fsid;
20 u32 epoch;
21 u32 num_mon;
Gustavo A. R. Silva53ab8e72020-05-07 13:51:38 -050022 struct ceph_entity_inst mon_inst[];
Sage Weilba75bb92009-10-06 11:31:11 -070023};
24
25struct ceph_mon_client;
Yehuda Sadehf8c76f62010-04-22 15:40:37 -070026struct ceph_mon_generic_request;
Sage Weilba75bb92009-10-06 11:31:11 -070027
28
29/*
30 * Generic mechanism for resending monitor requests.
31 */
32typedef void (*ceph_monc_request_func_t)(struct ceph_mon_client *monc,
33 int newmon);
34
35/* a pending monitor request */
36struct ceph_mon_request {
37 struct ceph_mon_client *monc;
38 struct delayed_work delayed_work;
39 unsigned long delay;
40 ceph_monc_request_func_t do_request;
41};
42
Ilya Dryomovd0b19702016-04-28 16:07:27 +020043typedef void (*ceph_monc_callback_t)(struct ceph_mon_generic_request *);
44
Sage Weilba75bb92009-10-06 11:31:11 -070045/*
Ilya Dryomov7a6fdeb2014-12-22 19:14:26 +030046 * ceph_mon_generic_request is being used for the statfs and
Ilya Dryomov513a8242014-05-13 11:19:26 +040047 * mon_get_version requests which are being done a bit differently
48 * because we need to get data back to the caller
Sage Weilba75bb92009-10-06 11:31:11 -070049 */
Yehuda Sadehf8c76f62010-04-22 15:40:37 -070050struct ceph_mon_generic_request {
Ilya Dryomovd0b19702016-04-28 16:07:27 +020051 struct ceph_mon_client *monc;
Sage Weil3143edd2010-03-24 21:43:33 -070052 struct kref kref;
Sage Weilba75bb92009-10-06 11:31:11 -070053 u64 tid;
Sage Weil85ff03f2010-02-15 14:47:28 -080054 struct rb_node node;
Sage Weilba75bb92009-10-06 11:31:11 -070055 int result;
Ilya Dryomovd0b19702016-04-28 16:07:27 +020056
Sage Weilba75bb92009-10-06 11:31:11 -070057 struct completion completion;
Ilya Dryomovd0b19702016-04-28 16:07:27 +020058 ceph_monc_callback_t complete_cb;
59 u64 private_data; /* r_tid/linger_id */
60
Sage Weilba75bb92009-10-06 11:31:11 -070061 struct ceph_msg *request; /* original request */
Sage Weil3143edd2010-03-24 21:43:33 -070062 struct ceph_msg *reply; /* and reply */
Ilya Dryomovd0b19702016-04-28 16:07:27 +020063
64 union {
65 struct ceph_statfs *st;
66 u64 newest;
67 } u;
Sage Weilba75bb92009-10-06 11:31:11 -070068};
69
70struct ceph_mon_client {
71 struct ceph_client *client;
72 struct ceph_monmap *monmap;
73
74 struct mutex mutex;
75 struct delayed_work delayed_work;
76
Sage Weil4e7a5dc2009-11-18 16:19:57 -080077 struct ceph_auth_client *auth;
Sage Weil240ed682010-05-21 14:57:25 -070078 struct ceph_msg *m_auth, *m_auth_reply, *m_subscribe, *m_subscribe_ack;
Sage Weil9bd2e6f2010-02-02 16:21:06 -080079 int pending_auth;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080080
Sage Weilba75bb92009-10-06 11:31:11 -070081 bool hunting;
82 int cur_mon; /* last monitor i contacted */
Ilya Dryomov82dcaba2016-01-19 16:19:06 +010083 unsigned long sub_renew_after;
84 unsigned long sub_renew_sent;
Alex Elder67130932012-05-26 23:26:43 -050085 struct ceph_connection con;
Sage Weilba75bb92009-10-06 11:31:11 -070086
Ilya Dryomov168b9092016-01-21 16:33:19 +010087 bool had_a_connection;
88 int hunt_mult; /* [1..CEPH_MONC_HUNT_MAX_MULT] */
89
Yehuda Sadehf8c76f62010-04-22 15:40:37 -070090 /* pending generic requests */
91 struct rb_root generic_request_tree;
Sage Weilba75bb92009-10-06 11:31:11 -070092 u64 last_tid;
93
Ilya Dryomov82dcaba2016-01-19 16:19:06 +010094 /* subs, indexed with CEPH_SUB_* */
95 struct {
96 struct ceph_mon_subscribe_item item;
97 bool want;
98 u32 have; /* epoch */
Yan, Zheng0cabbd92016-04-07 11:34:43 +080099 } subs[4];
Ilya Dryomov737cc81e2016-05-26 00:05:01 +0200100 int fs_cluster_id; /* "mdsmap.<id>" sub */
Sage Weilba75bb92009-10-06 11:31:11 -0700101
Sage Weil039934b2009-11-12 15:05:52 -0800102#ifdef CONFIG_DEBUG_FS
Sage Weilba75bb92009-10-06 11:31:11 -0700103 struct dentry *debugfs_file;
Sage Weil039934b2009-11-12 15:05:52 -0800104#endif
Sage Weilba75bb92009-10-06 11:31:11 -0700105};
106
Sage Weilba75bb92009-10-06 11:31:11 -0700107extern int ceph_monmap_contains(struct ceph_monmap *m,
108 struct ceph_entity_addr *addr);
109
110extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl);
111extern void ceph_monc_stop(struct ceph_mon_client *monc);
Yan, Zheng120a75e2019-07-25 20:16:39 +0800112extern void ceph_monc_reopen_session(struct ceph_mon_client *monc);
Sage Weilba75bb92009-10-06 11:31:11 -0700113
Ilya Dryomov82dcaba2016-01-19 16:19:06 +0100114enum {
Yan, Zheng0cabbd92016-04-07 11:34:43 +0800115 CEPH_SUB_MONMAP = 0,
Ilya Dryomov82dcaba2016-01-19 16:19:06 +0100116 CEPH_SUB_OSDMAP,
Yan, Zheng0cabbd92016-04-07 11:34:43 +0800117 CEPH_SUB_FSMAP,
118 CEPH_SUB_MDSMAP,
Ilya Dryomov82dcaba2016-01-19 16:19:06 +0100119};
120
121extern const char *ceph_sub_str[];
122
Sage Weilba75bb92009-10-06 11:31:11 -0700123/*
124 * The model here is to indicate that we need a new map of at least
Ilya Dryomov82dcaba2016-01-19 16:19:06 +0100125 * epoch @epoch, and also call in when we receive a map. We will
Sage Weilba75bb92009-10-06 11:31:11 -0700126 * periodically rerequest the map from the monitor cluster until we
127 * get what we want.
128 */
Ilya Dryomov82dcaba2016-01-19 16:19:06 +0100129bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch,
130 bool continuous);
131void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch);
Ilya Dryomov42c1b122016-04-28 16:07:25 +0200132void ceph_monc_renew_subs(struct ceph_mon_client *monc);
Sage Weilba75bb92009-10-06 11:31:11 -0700133
Ilya Dryomov6044cde2014-05-13 11:19:27 +0400134extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
135 unsigned long timeout);
Sage Weilba75bb92009-10-06 11:31:11 -0700136
Douglas Fuller06d74372017-08-16 10:19:27 -0400137int ceph_monc_do_statfs(struct ceph_mon_client *monc, u64 data_pool,
138 struct ceph_statfs *buf);
Sage Weilba75bb92009-10-06 11:31:11 -0700139
Ilya Dryomovd0b19702016-04-28 16:07:27 +0200140int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
141 u64 *newest);
142int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
143 ceph_monc_callback_t cb, u64 private_data);
Ilya Dryomov513a8242014-05-13 11:19:26 +0400144
Ilya Dryomov0b98acd2020-09-14 13:39:19 +0200145int ceph_monc_blocklist_add(struct ceph_mon_client *monc,
Douglas Fuller6305a3b2015-07-22 20:59:52 -0400146 struct ceph_entity_addr *client_addr);
147
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800148extern int ceph_monc_open_session(struct ceph_mon_client *monc);
149
Sage Weil9bd2e6f2010-02-02 16:21:06 -0800150extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
151
Sage Weilba75bb92009-10-06 11:31:11 -0700152#endif