1
2#ifndef _FS_CEPH_MDS_CLIENT_H
3#define _FS_CEPH_MDS_CLIENT_H
4
5#include <linux/completion.h>
6#include <linux/kref.h>
7#include <linux/list.h>
8#include <linux/mutex.h>
9#include <linux/rbtree.h>
10#include <linux/spinlock.h>
11#include <linux/refcount.h>
12#include <linux/utsname.h>
13
14#include <linux/ceph/types.h>
15#include <linux/ceph/messenger.h>
16#include <linux/ceph/mdsmap.h>
17#include <linux/ceph/auth.h>
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33struct ceph_fs_client;
34struct ceph_cap;
35
36
37
38
39
40struct ceph_mds_reply_info_in {
41 struct ceph_mds_reply_inode *in;
42 struct ceph_dir_layout dir_layout;
43 u32 symlink_len;
44 char *symlink;
45 u32 xattr_len;
46 char *xattr_data;
47 u64 inline_version;
48 u32 inline_len;
49 char *inline_data;
50 u32 pool_ns_len;
51 char *pool_ns_data;
52 u64 max_bytes;
53 u64 max_files;
54};
55
56struct ceph_mds_reply_dir_entry {
57 char *name;
58 u32 name_len;
59 struct ceph_mds_reply_lease *lease;
60 struct ceph_mds_reply_info_in inode;
61 loff_t offset;
62};
63
64
65
66
67
68
69
70struct ceph_mds_reply_info_parsed {
71 struct ceph_mds_reply_head *head;
72
73
74 struct ceph_mds_reply_info_in diri, targeti;
75 struct ceph_mds_reply_dirfrag *dirfrag;
76 char *dname;
77 u32 dname_len;
78 struct ceph_mds_reply_lease *dlease;
79
80
81 union {
82
83 struct ceph_filelock *filelock_reply;
84
85
86 struct {
87 struct ceph_mds_reply_dirfrag *dir_dir;
88 size_t dir_buf_size;
89 int dir_nr;
90 bool dir_end;
91 bool dir_complete;
92 bool hash_order;
93 bool offset_hash;
94 struct ceph_mds_reply_dir_entry *dir_entries;
95 };
96
97
98 struct {
99 bool has_create_ino;
100 u64 ino;
101 };
102 };
103
104
105
106 void *snapblob;
107 int snapblob_len;
108};
109
110
111
112
113
114
115
116
117#define CEPH_CAPS_PER_RELEASE ((PAGE_SIZE - sizeof(u32) - \
118 sizeof(struct ceph_mds_cap_release)) / \
119 sizeof(struct ceph_mds_cap_item))
120
121
122
123
124
125enum {
126 CEPH_MDS_SESSION_NEW = 1,
127 CEPH_MDS_SESSION_OPENING = 2,
128 CEPH_MDS_SESSION_OPEN = 3,
129 CEPH_MDS_SESSION_HUNG = 4,
130 CEPH_MDS_SESSION_CLOSING = 5,
131 CEPH_MDS_SESSION_RESTARTING = 6,
132 CEPH_MDS_SESSION_RECONNECTING = 7,
133 CEPH_MDS_SESSION_REJECTED = 8,
134};
135
136struct ceph_mds_session {
137 struct ceph_mds_client *s_mdsc;
138 int s_mds;
139 int s_state;
140 unsigned long s_ttl;
141 u64 s_seq;
142 struct mutex s_mutex;
143
144 struct ceph_connection s_con;
145
146 struct ceph_auth_handshake s_auth;
147
148
149 spinlock_t s_gen_ttl_lock;
150 u32 s_cap_gen;
151 unsigned long s_cap_ttl;
152
153
154 spinlock_t s_cap_lock;
155 struct list_head s_caps;
156 int s_nr_caps, s_trim_caps;
157 int s_num_cap_releases;
158 int s_cap_reconnect;
159 int s_readonly;
160 struct list_head s_cap_releases;
161 struct ceph_cap *s_cap_iterator;
162
163
164 struct list_head s_cap_flushing;
165 unsigned long s_renew_requested;
166 u64 s_renew_seq;
167
168 refcount_t s_ref;
169 struct list_head s_waiting;
170 struct list_head s_unsafe;
171};
172
173
174
175
176enum {
177 USE_ANY_MDS,
178 USE_RANDOM_MDS,
179 USE_AUTH_MDS,
180};
181
182struct ceph_mds_request;
183struct ceph_mds_client;
184
185
186
187
188typedef void (*ceph_mds_request_callback_t) (struct ceph_mds_client *mdsc,
189 struct ceph_mds_request *req);
190
191
192
193typedef int (*ceph_mds_request_wait_callback_t) (struct ceph_mds_client *mdsc,
194 struct ceph_mds_request *req);
195
196
197
198
199struct ceph_mds_request {
200 u64 r_tid;
201 struct rb_node r_node;
202 struct ceph_mds_client *r_mdsc;
203
204 int r_op;
205
206
207 struct inode *r_inode;
208 struct dentry *r_dentry;
209 struct dentry *r_old_dentry;
210 struct inode *r_old_dentry_dir;
211 char *r_path1, *r_path2;
212 struct ceph_vino r_ino1, r_ino2;
213
214 struct inode *r_parent;
215 struct inode *r_target_inode;
216
217#define CEPH_MDS_R_DIRECT_IS_HASH (1)
218#define CEPH_MDS_R_ABORTED (2)
219#define CEPH_MDS_R_GOT_UNSAFE (3)
220#define CEPH_MDS_R_GOT_SAFE (4)
221#define CEPH_MDS_R_GOT_RESULT (5)
222#define CEPH_MDS_R_DID_PREPOPULATE (6)
223#define CEPH_MDS_R_PARENT_LOCKED (7)
224 unsigned long r_req_flags;
225
226 struct mutex r_fill_mutex;
227
228 union ceph_mds_request_args r_args;
229 int r_fmode;
230 kuid_t r_uid;
231 kgid_t r_gid;
232 struct timespec r_stamp;
233
234
235 int r_direct_mode;
236 u32 r_direct_hash;
237
238
239 struct ceph_pagelist *r_pagelist;
240
241
242 int r_inode_drop, r_inode_unless;
243 int r_dentry_drop, r_dentry_unless;
244 int r_old_dentry_drop, r_old_dentry_unless;
245 struct inode *r_old_inode;
246 int r_old_inode_drop, r_old_inode_unless;
247
248 struct ceph_msg *r_request;
249 int r_request_release_offset;
250 struct ceph_msg *r_reply;
251 struct ceph_mds_reply_info_parsed r_reply_info;
252 struct page *r_locked_page;
253 int r_err;
254
255 unsigned long r_timeout;
256 unsigned long r_started;
257 unsigned long r_request_started;
258
259
260
261 struct inode *r_unsafe_dir;
262 struct list_head r_unsafe_dir_item;
263
264
265 struct list_head r_unsafe_target_item;
266
267 struct ceph_mds_session *r_session;
268
269 int r_attempts;
270 int r_num_fwd;
271 int r_resend_mds;
272 u32 r_sent_on_mseq;
273
274 struct kref r_kref;
275 struct list_head r_wait;
276 struct completion r_completion;
277 struct completion r_safe_completion;
278 ceph_mds_request_callback_t r_callback;
279 ceph_mds_request_wait_callback_t r_wait_for_completion;
280 struct list_head r_unsafe_item;
281
282 long long r_dir_release_cnt;
283 long long r_dir_ordered_cnt;
284 int r_readdir_cache_idx;
285 u32 r_readdir_offset;
286
287 struct ceph_cap_reservation r_caps_reservation;
288 int r_num_caps;
289};
290
291struct ceph_pool_perm {
292 struct rb_node node;
293 int perm;
294 s64 pool;
295 size_t pool_ns_len;
296 char pool_ns[];
297};
298
299
300
301
302struct ceph_mds_client {
303 struct ceph_fs_client *fsc;
304 struct mutex mutex;
305
306 struct ceph_mdsmap *mdsmap;
307 struct completion safe_umount_waiters;
308 wait_queue_head_t session_close_wq;
309 struct list_head waiting_for_map;
310 int mdsmap_err;
311
312 struct ceph_mds_session **sessions;
313 atomic_t num_sessions;
314 int max_sessions;
315 int stopping;
316
317 atomic64_t quotarealms_count;
318
319
320
321
322
323
324
325
326 u64 last_snap_seq;
327 struct rw_semaphore snap_rwsem;
328 struct rb_root snap_realms;
329 struct list_head snap_empty;
330 spinlock_t snap_empty_lock;
331
332 u64 last_tid;
333 u64 oldest_tid;
334
335 struct rb_root request_tree;
336 struct delayed_work delayed_work;
337 unsigned long last_renew_caps;
338 struct list_head cap_delay_list;
339 spinlock_t cap_delay_lock;
340 struct list_head snap_flush_list;
341 spinlock_t snap_flush_lock;
342
343 u64 last_cap_flush_tid;
344 struct list_head cap_flush_list;
345 struct list_head cap_dirty;
346 struct list_head cap_dirty_migrating;
347 int num_cap_flushing;
348 spinlock_t cap_dirty_lock;
349 wait_queue_head_t cap_flushing_wq;
350
351
352
353
354
355
356
357
358
359
360
361
362 spinlock_t caps_list_lock;
363 struct list_head caps_list;
364
365 int caps_total_count;
366 int caps_use_count;
367 int caps_reserve_count;
368 int caps_avail_count;
369 int caps_min_count;
370
371 spinlock_t dentry_lru_lock;
372 struct list_head dentry_lru;
373 int num_dentry;
374
375 struct rw_semaphore pool_perm_rwsem;
376 struct rb_root pool_perm_tree;
377
378 char nodename[__NEW_UTS_LEN + 1];
379};
380
381extern const char *ceph_mds_op_name(int op);
382
383extern struct ceph_mds_session *
384__ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
385
386static inline struct ceph_mds_session *
387ceph_get_mds_session(struct ceph_mds_session *s)
388{
389 refcount_inc(&s->s_ref);
390 return s;
391}
392
393extern const char *ceph_session_state_name(int s);
394
395extern void ceph_put_mds_session(struct ceph_mds_session *s);
396
397extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc,
398 struct ceph_msg *msg, int mds);
399
400extern int ceph_mdsc_init(struct ceph_fs_client *fsc);
401extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
402extern void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc);
403extern void ceph_mdsc_destroy(struct ceph_fs_client *fsc);
404
405extern void ceph_mdsc_sync(struct ceph_mds_client *mdsc);
406
407extern void ceph_invalidate_dir_request(struct ceph_mds_request *req);
408extern int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req,
409 struct inode *dir);
410extern struct ceph_mds_request *
411ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode);
412extern void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
413 struct ceph_mds_request *req);
414extern int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
415 struct inode *dir,
416 struct ceph_mds_request *req);
417static inline void ceph_mdsc_get_request(struct ceph_mds_request *req)
418{
419 kref_get(&req->r_kref);
420}
421extern void ceph_mdsc_release_request(struct kref *kref);
422static inline void ceph_mdsc_put_request(struct ceph_mds_request *req)
423{
424 kref_put(&req->r_kref, ceph_mdsc_release_request);
425}
426
427extern void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
428 struct ceph_mds_session *session);
429
430extern void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc);
431
432extern char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
433 int stop_on_nosnap);
434
435extern void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry);
436extern void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
437 struct inode *inode,
438 struct dentry *dentry, char action,
439 u32 seq);
440
441extern void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc,
442 struct ceph_msg *msg);
443extern void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc,
444 struct ceph_msg *msg);
445
446extern struct ceph_mds_session *
447ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target);
448extern void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc,
449 struct ceph_mds_session *session);
450
451extern int ceph_trim_caps(struct ceph_mds_client *mdsc,
452 struct ceph_mds_session *session,
453 int max_caps);
454#endif
455