1 /* SPDX-License-Identifier: GPL-2.0 */
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 #include <linux/ktime.h>
14
15 #include <linux/ceph/types.h>
16 #include <linux/ceph/messenger.h>
17 #include <linux/ceph/auth.h>
18
19 #include "mdsmap.h"
20 #include "metric.h"
21 #include "subvolume_metrics.h"
22 #include "super.h"
23
24 /* The first 8 bits are reserved for old ceph releases */
25 enum ceph_feature_type {
26 CEPHFS_FEATURE_MIMIC = 8,
27 CEPHFS_FEATURE_REPLY_ENCODING,
28 CEPHFS_FEATURE_RECLAIM_CLIENT,
29 CEPHFS_FEATURE_LAZY_CAP_WANTED,
30 CEPHFS_FEATURE_MULTI_RECONNECT,
31 CEPHFS_FEATURE_DELEG_INO,
32 CEPHFS_FEATURE_METRIC_COLLECT,
33 CEPHFS_FEATURE_ALTERNATE_NAME,
34 CEPHFS_FEATURE_NOTIFY_SESSION_STATE,
35 CEPHFS_FEATURE_OP_GETVXATTR,
36 CEPHFS_FEATURE_32BITS_RETRY_FWD,
37 CEPHFS_FEATURE_NEW_SNAPREALM_INFO,
38 CEPHFS_FEATURE_HAS_OWNER_UIDGID,
39 CEPHFS_FEATURE_MDS_AUTH_CAPS_CHECK,
40 CEPHFS_FEATURE_SUBVOLUME_METRICS,
41
42 CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_SUBVOLUME_METRICS,
43 };
44
45 #define CEPHFS_FEATURES_CLIENT_SUPPORTED { \
46 0, 1, 2, 3, 4, 5, 6, 7, \
47 CEPHFS_FEATURE_MIMIC, \
48 CEPHFS_FEATURE_REPLY_ENCODING, \
49 CEPHFS_FEATURE_LAZY_CAP_WANTED, \
50 CEPHFS_FEATURE_MULTI_RECONNECT, \
51 CEPHFS_FEATURE_DELEG_INO, \
52 CEPHFS_FEATURE_METRIC_COLLECT, \
53 CEPHFS_FEATURE_ALTERNATE_NAME, \
54 CEPHFS_FEATURE_NOTIFY_SESSION_STATE, \
55 CEPHFS_FEATURE_OP_GETVXATTR, \
56 CEPHFS_FEATURE_32BITS_RETRY_FWD, \
57 CEPHFS_FEATURE_HAS_OWNER_UIDGID, \
58 CEPHFS_FEATURE_MDS_AUTH_CAPS_CHECK, \
59 CEPHFS_FEATURE_SUBVOLUME_METRICS, \
60 }
61
62 /*
63 * Some lock dependencies:
64 *
65 * session->s_mutex
66 * mdsc->mutex
67 *
68 * mdsc->snap_rwsem
69 *
70 * ci->i_ceph_lock
71 * mdsc->snap_flush_lock
72 * mdsc->cap_delay_lock
73 *
74 */
75
76 struct ceph_fs_client;
77 struct ceph_cap;
78
79 #define MDS_AUTH_UID_ANY -1
80 #define CEPH_GET_CAPS_WAIT_TIMEOUT (5 * HZ)
81 #define CEPH_CAP_FLUSH_WAIT_TIMEOUT_SEC 60
82 #define CEPH_CAP_FLUSH_MAX_DUMP_ENTRIES 5
83 #define CEPH_CAP_FLUSH_MAX_DUMP_ITERS 5
84 #define CEPH_CLIENT_RESET_REASON_LEN 64
85 #define CEPH_CLIENT_RESET_DRAIN_SEC 30
86 #define CEPH_CLIENT_RESET_CLOSE_GRACE_MS 100
87 #define CEPH_CLIENT_RESET_WAIT_TIMEOUT_SEC 120
88
89 enum ceph_client_reset_phase {
90 CEPH_CLIENT_RESET_IDLE = 0,
91 /*
92 * QUIESCING is set synchronously by schedule_reset() before the
93 * workqueue item is dispatched. It gates new requests (any
94 * phase != IDLE blocks callers) during the window between
95 * scheduling and the work function's transition to DRAINING.
96 */
97 CEPH_CLIENT_RESET_QUIESCING,
98 CEPH_CLIENT_RESET_DRAINING,
99 CEPH_CLIENT_RESET_TEARDOWN,
100 };
101
102 struct ceph_client_reset_state {
103 spinlock_t lock; /* protects all fields below */
104 u64 trigger_count; /* number of resets triggered */
105 u64 success_count; /* number of successful resets */
106 u64 failure_count; /* number of failed resets */
107 unsigned long last_start; /* jiffies when last reset started */
108 unsigned long last_finish; /* jiffies when last reset finished */
109 int last_errno; /* result of most recent reset */
110 enum ceph_client_reset_phase phase; /* current reset phase */
111 bool drain_timed_out; /* drain exceeded timeout */
112 bool shutdown; /* destroy in progress */
113 int sessions_reset; /* sessions torn down in last reset */
114 char last_reason[CEPH_CLIENT_RESET_REASON_LEN]; /* operator-supplied reason */
115
116 /* Request blocking during reset */
117 wait_queue_head_t blocked_wq; /* waitqueue for blocked callers */
118 atomic_t blocked_requests; /* count of blocked callers */
119 };
120
ceph_reset_is_idle(struct ceph_client_reset_state * st)121 static inline bool ceph_reset_is_idle(struct ceph_client_reset_state *st)
122 {
123 return READ_ONCE(st->phase) == CEPH_CLIENT_RESET_IDLE;
124 }
125
126 struct ceph_mds_cap_match {
127 s64 uid; /* default to MDS_AUTH_UID_ANY */
128 u32 num_gids;
129 u32 *gids; /* use these GIDs */
130 char *path; /* require path to be child of this
131 (may be "" or "/" for any) */
132 char *fs_name;
133 bool root_squash; /* default to false */
134 };
135
136 struct ceph_mds_cap_auth {
137 struct ceph_mds_cap_match match;
138 bool readable;
139 bool writeable;
140 };
141
142 /*
143 * parsed info about a single inode. pointers are into the encoded
144 * on-wire structures within the mds reply message payload.
145 */
146 struct ceph_mds_reply_info_in {
147 struct ceph_mds_reply_inode *in;
148 struct ceph_dir_layout dir_layout;
149 u32 symlink_len;
150 char *symlink;
151 u32 xattr_len;
152 char *xattr_data;
153 u64 inline_version;
154 u32 inline_len;
155 char *inline_data;
156 u32 pool_ns_len;
157 char *pool_ns_data;
158 u64 max_bytes;
159 u64 max_files;
160 s32 dir_pin;
161 struct ceph_timespec btime;
162 struct ceph_timespec snap_btime;
163 u8 *fscrypt_auth;
164 u8 *fscrypt_file;
165 u32 fscrypt_auth_len;
166 u32 fscrypt_file_len;
167 u64 rsnaps;
168 u64 change_attr;
169 u64 subvolume_id;
170 };
171
172 struct ceph_mds_reply_dir_entry {
173 bool is_nokey;
174 char *name;
175 u32 name_len;
176 u32 raw_hash;
177 struct ceph_mds_reply_lease *lease;
178 struct ceph_mds_reply_info_in inode;
179 loff_t offset;
180 };
181
182 struct ceph_mds_reply_xattr {
183 char *xattr_value;
184 size_t xattr_value_len;
185 };
186
187 /*
188 * parsed info about an mds reply, including information about
189 * either: 1) the target inode and/or its parent directory and dentry,
190 * and directory contents (for readdir results), or
191 * 2) the file range lock info (for fcntl F_GETLK results).
192 */
193 struct ceph_mds_reply_info_parsed {
194 struct ceph_mds_reply_head *head;
195
196 /* trace */
197 struct ceph_mds_reply_info_in diri, targeti;
198 struct ceph_mds_reply_dirfrag *dirfrag;
199 char *dname;
200 u8 *altname;
201 u32 dname_len;
202 u32 altname_len;
203 struct ceph_mds_reply_lease *dlease;
204 struct ceph_mds_reply_xattr xattr_info;
205
206 /* extra */
207 union {
208 /* for fcntl F_GETLK results */
209 struct ceph_filelock *filelock_reply;
210
211 /* for readdir results */
212 struct {
213 struct ceph_mds_reply_dirfrag *dir_dir;
214 size_t dir_buf_size;
215 int dir_nr;
216 bool dir_end;
217 bool dir_complete;
218 bool hash_order;
219 bool offset_hash;
220 struct ceph_mds_reply_dir_entry *dir_entries;
221 };
222
223 /* for create results */
224 struct {
225 bool has_create_ino;
226 u64 ino;
227 };
228 };
229
230 /* encoded blob describing snapshot contexts for certain
231 operations (e.g., open) */
232 void *snapblob;
233 int snapblob_len;
234 };
235
236
237 /*
238 * cap releases are batched and sent to the MDS en masse.
239 *
240 * Account for per-message overhead of mds_cap_release header
241 * and __le32 for osd epoch barrier trailing field.
242 */
243 #define CEPH_CAPS_PER_RELEASE ((PAGE_SIZE - sizeof(u32) - \
244 sizeof(struct ceph_mds_cap_release)) / \
245 sizeof(struct ceph_mds_cap_item))
246
247
248 /*
249 * state associated with each MDS<->client session
250 */
251 enum {
252 CEPH_MDS_SESSION_NEW = 1,
253 CEPH_MDS_SESSION_OPENING = 2,
254 CEPH_MDS_SESSION_OPEN = 3,
255 CEPH_MDS_SESSION_HUNG = 4,
256 CEPH_MDS_SESSION_RESTARTING = 5,
257 CEPH_MDS_SESSION_RECONNECTING = 6,
258 CEPH_MDS_SESSION_CLOSING = 7,
259 CEPH_MDS_SESSION_CLOSED = 8,
260 CEPH_MDS_SESSION_REJECTED = 9,
261 };
262
263 struct ceph_mds_session {
264 struct ceph_mds_client *s_mdsc;
265 int s_mds;
266 int s_state;
267 unsigned long s_ttl; /* time until mds kills us */
268 unsigned long s_features;
269 u64 s_seq; /* incoming msg seq # */
270 struct mutex s_mutex; /* serialize session messages */
271
272 struct ceph_connection s_con;
273
274 struct ceph_auth_handshake s_auth;
275
276 atomic_t s_cap_gen; /* inc each time we get mds stale msg */
277 unsigned long s_cap_ttl; /* when session caps expire. protected by s_mutex */
278
279 /* protected by s_cap_lock */
280 spinlock_t s_cap_lock;
281 refcount_t s_ref;
282 struct list_head s_caps; /* all caps issued by this session */
283 struct ceph_cap *s_cap_iterator;
284 int s_nr_caps;
285 int s_num_cap_releases;
286 int s_cap_reconnect;
287 int s_readonly;
288 struct list_head s_cap_releases; /* waiting cap_release messages */
289 struct work_struct s_cap_release_work;
290
291 /* See ceph_inode_info->i_dirty_item. */
292 struct list_head s_cap_dirty; /* inodes w/ dirty caps */
293
294 /* See ceph_inode_info->i_flushing_item. */
295 struct list_head s_cap_flushing; /* inodes w/ flushing caps */
296
297 unsigned long s_renew_requested; /* last time we sent a renew req */
298 u64 s_renew_seq;
299
300 struct list_head s_waiting; /* waiting requests */
301 struct list_head s_unsafe; /* unsafe requests */
302 struct xarray s_delegated_inos;
303 };
304
305 /*
306 * modes of choosing which MDS to send a request to
307 */
308 enum {
309 USE_ANY_MDS,
310 USE_RANDOM_MDS,
311 USE_AUTH_MDS, /* prefer authoritative mds for this metadata item */
312 };
313
314 struct ceph_mds_request;
315 struct ceph_mds_client;
316
317 /*
318 * request completion callback
319 */
320 typedef void (*ceph_mds_request_callback_t) (struct ceph_mds_client *mdsc,
321 struct ceph_mds_request *req);
322 /*
323 * wait for request completion callback
324 */
325 typedef int (*ceph_mds_request_wait_callback_t) (struct ceph_mds_client *mdsc,
326 struct ceph_mds_request *req);
327
328 /*
329 * an in-flight mds request
330 */
331 struct ceph_mds_request {
332 u64 r_tid; /* transaction id */
333 struct rb_node r_node;
334 struct ceph_mds_client *r_mdsc;
335
336 struct kref r_kref;
337 int r_op; /* mds op code */
338
339 /* operation on what? */
340 struct inode *r_inode; /* arg1 */
341 struct dentry *r_dentry; /* arg1 */
342 struct dentry *r_old_dentry; /* arg2: rename from or link from */
343 struct inode *r_old_dentry_dir; /* arg2: old dentry's parent dir */
344 char *r_path1, *r_path2;
345 struct ceph_vino r_ino1, r_ino2;
346
347 struct inode *r_parent; /* parent dir inode */
348 struct inode *r_target_inode; /* resulting inode */
349 struct inode *r_new_inode; /* new inode (for creates) */
350
351 const struct qstr *r_dname; /* stable name (for ->d_revalidate) */
352
353 #define CEPH_MDS_R_DIRECT_IS_HASH (1) /* r_direct_hash is valid */
354 #define CEPH_MDS_R_ABORTED (2) /* call was aborted */
355 #define CEPH_MDS_R_GOT_UNSAFE (3) /* got an unsafe reply */
356 #define CEPH_MDS_R_GOT_SAFE (4) /* got a safe reply */
357 #define CEPH_MDS_R_GOT_RESULT (5) /* got a result */
358 #define CEPH_MDS_R_DID_PREPOPULATE (6) /* prepopulated readdir */
359 #define CEPH_MDS_R_PARENT_LOCKED (7) /* is r_parent->i_rwsem wlocked? */
360 #define CEPH_MDS_R_ASYNC (8) /* async request */
361 #define CEPH_MDS_R_FSCRYPT_FILE (9) /* must marshal fscrypt_file field */
362 unsigned long r_req_flags;
363
364 struct mutex r_fill_mutex;
365
366 union ceph_mds_request_args r_args;
367
368 struct ceph_fscrypt_auth *r_fscrypt_auth;
369 u64 r_fscrypt_file;
370
371 u8 *r_altname; /* fscrypt binary crypttext for long filenames */
372 u32 r_altname_len; /* length of r_altname */
373
374 int r_fmode; /* file mode, if expecting cap */
375 int r_request_release_offset;
376 const struct cred *r_cred;
377 struct mnt_idmap *r_mnt_idmap;
378 struct timespec64 r_stamp;
379
380 /* for choosing which mds to send this request to */
381 int r_direct_mode;
382 u32 r_direct_hash; /* choose dir frag based on this dentry hash */
383
384 /* data payload is used for xattr ops */
385 struct ceph_pagelist *r_pagelist;
386
387 /* what caps shall we drop? */
388 int r_inode_drop, r_inode_unless;
389 int r_dentry_drop, r_dentry_unless;
390 int r_old_dentry_drop, r_old_dentry_unless;
391 struct inode *r_old_inode;
392 int r_old_inode_drop, r_old_inode_unless;
393
394 struct ceph_msg *r_request; /* original request */
395 struct ceph_msg *r_reply;
396 struct ceph_mds_reply_info_parsed r_reply_info;
397 int r_err;
398 u32 r_readdir_offset;
399
400 struct page *r_locked_page;
401 int r_dir_caps;
402 int r_num_caps;
403
404 unsigned long r_timeout; /* optional. jiffies, 0 is "wait forever" */
405 unsigned long r_started; /* start time to measure timeout against */
406 unsigned long r_start_latency; /* start time to measure latency */
407 unsigned long r_end_latency; /* finish time to measure latency */
408 unsigned long r_request_started; /* start time for mds request only,
409 used to measure lease durations */
410
411 /* link unsafe requests to parent directory, for fsync */
412 struct inode *r_unsafe_dir;
413 struct list_head r_unsafe_dir_item;
414
415 /* unsafe requests that modify the target inode */
416 struct list_head r_unsafe_target_item;
417
418 struct ceph_mds_session *r_session;
419
420 int r_attempts; /* resend attempts */
421 int r_num_fwd; /* number of forward attempts */
422 int r_resend_mds; /* mds to resend to next, if any*/
423 u32 r_sent_on_mseq; /* cap mseq request was sent at*/
424 u64 r_deleg_ino;
425
426 struct list_head r_wait;
427 struct completion r_completion;
428 struct completion r_safe_completion;
429 ceph_mds_request_callback_t r_callback;
430 struct list_head r_unsafe_item; /* per-session unsafe list item */
431
432 long long r_dir_release_cnt;
433 long long r_dir_ordered_cnt;
434 int r_readdir_cache_idx;
435
436 int r_feature_needed;
437
438 struct ceph_cap_reservation r_caps_reservation;
439 };
440
441 struct ceph_pool_perm {
442 struct rb_node node;
443 int perm;
444 s64 pool;
445 size_t pool_ns_len;
446 char pool_ns[];
447 };
448
449 struct ceph_snapid_map {
450 struct rb_node node;
451 struct list_head lru;
452 atomic_t ref;
453 dev_t dev;
454 u64 snap;
455 unsigned long last_used;
456 };
457
458 /*
459 * node for list of quotarealm inodes that are not visible from the filesystem
460 * mountpoint, but required to handle, e.g. quotas.
461 */
462 struct ceph_quotarealm_inode {
463 struct rb_node node;
464 u64 ino;
465 unsigned long timeout; /* last time a lookup failed for this inode */
466 struct mutex mutex;
467 struct inode *inode;
468 };
469
470 #ifdef CONFIG_DEBUG_FS
471
472 struct cap_wait {
473 struct list_head list;
474 u64 ino;
475 pid_t tgid;
476 int need;
477 int want;
478 };
479
480 #endif
481
482 enum {
483 CEPH_MDSC_STOPPING_BEGIN = 1,
484 CEPH_MDSC_STOPPING_FLUSHING = 2,
485 CEPH_MDSC_STOPPING_FLUSHED = 3,
486 };
487
488 /*
489 * mds client state
490 */
491 struct ceph_mds_client {
492 struct ceph_fs_client *fsc;
493 struct mutex mutex; /* all nested structures */
494
495 struct ceph_mdsmap *mdsmap;
496 struct completion safe_umount_waiters;
497 wait_queue_head_t session_close_wq;
498 struct list_head waiting_for_map;
499 int mdsmap_err;
500
501 struct ceph_mds_session **sessions; /* NULL for mds if no session */
502 atomic_t num_sessions;
503 int max_sessions; /* len of sessions array */
504
505 spinlock_t stopping_lock; /* protect snap_empty */
506 int stopping; /* the stage of shutting down */
507 atomic_t stopping_blockers;
508 struct completion stopping_waiter;
509
510 atomic64_t dirty_folios;
511 wait_queue_head_t flush_end_wq;
512
513 atomic64_t quotarealms_count; /* # realms with quota */
514 /*
515 * We keep a list of inodes we don't see in the mountpoint but that we
516 * need to track quota realms.
517 */
518 struct rb_root quotarealms_inodes;
519 struct mutex quotarealms_inodes_mutex;
520
521 /*
522 * snap_rwsem will cover cap linkage into snaprealms, and
523 * realm snap contexts. (later, we can do per-realm snap
524 * contexts locks..) the empty list contains realms with no
525 * references (implying they contain no inodes with caps) that
526 * should be destroyed.
527 */
528 u64 last_snap_seq;
529 struct rw_semaphore snap_rwsem;
530 struct rb_root snap_realms;
531 struct list_head snap_empty;
532 int num_snap_realms;
533 spinlock_t snap_empty_lock; /* protect snap_empty */
534
535 u64 last_tid; /* most recent mds request */
536 u64 oldest_tid; /* oldest incomplete mds request,
537 excluding setfilelock requests */
538 struct rb_root request_tree; /* pending mds requests */
539 struct delayed_work delayed_work; /* delayed work */
540 unsigned long last_renew_caps; /* last time we renewed our caps */
541 struct list_head cap_delay_list; /* caps with delayed release */
542 struct list_head cap_unlink_delay_list; /* caps with delayed release for unlink */
543 spinlock_t cap_delay_lock; /* protects cap_delay_list and cap_unlink_delay_list */
544 struct list_head snap_flush_list; /* cap_snaps ready to flush */
545 spinlock_t snap_flush_lock;
546
547 u64 last_cap_flush_tid;
548 struct list_head cap_flush_list;
549 struct list_head cap_dirty_migrating; /* ...that are migration... */
550 int num_cap_flushing; /* # caps we are flushing */
551 spinlock_t cap_dirty_lock; /* protects above items */
552 wait_queue_head_t cap_flushing_wq;
553
554 struct work_struct cap_reclaim_work;
555 atomic_t cap_reclaim_pending;
556
557 struct work_struct cap_unlink_work;
558
559 /*
560 * Cap reservations
561 *
562 * Maintain a global pool of preallocated struct ceph_caps, referenced
563 * by struct ceph_caps_reservations. This ensures that we preallocate
564 * memory needed to successfully process an MDS response. (If an MDS
565 * sends us cap information and we fail to process it, we will have
566 * problems due to the client and MDS being out of sync.)
567 *
568 * Reservations are 'owned' by a ceph_cap_reservation context.
569 */
570 spinlock_t caps_list_lock;
571 struct list_head caps_list; /* unused (reserved or
572 unreserved) */
573 #ifdef CONFIG_DEBUG_FS
574 struct list_head cap_wait_list;
575 #endif
576 int caps_total_count; /* total caps allocated */
577 int caps_use_count; /* in use */
578 int caps_use_max; /* max used caps */
579 int caps_reserve_count; /* unused, reserved */
580 int caps_avail_count; /* unused, unreserved */
581 int caps_min_count; /* keep at least this many
582 (unreserved) */
583 spinlock_t dentry_list_lock;
584 struct list_head dentry_leases; /* fifo list */
585 struct list_head dentry_dir_leases; /* lru list */
586
587 struct ceph_client_metric metric;
588 struct work_struct reset_work;
589 struct ceph_client_reset_state reset_state;
590 struct ceph_subvolume_metrics_tracker subvol_metrics;
591
592 /* Subvolume metrics send tracking */
593 struct mutex subvol_metrics_last_mutex;
594 struct ceph_subvol_metric_snapshot *subvol_metrics_last;
595 u32 subvol_metrics_last_nr;
596 u64 subvol_metrics_sent;
597 u64 subvol_metrics_nonzero_sends;
598
599 spinlock_t snapid_map_lock;
600 struct rb_root snapid_map_tree;
601 struct list_head snapid_map_lru;
602
603 struct rw_semaphore pool_perm_rwsem;
604 struct rb_root pool_perm_tree;
605
606 u32 s_cap_auths_num;
607 struct ceph_mds_cap_auth *s_cap_auths;
608
609 char nodename[__NEW_UTS_LEN + 1];
610 };
611
612 extern const char *ceph_mds_op_name(int op);
613
614 extern bool check_session_state(struct ceph_mds_session *s);
615 void inc_session_sequence(struct ceph_mds_session *s);
616
617 extern struct ceph_mds_session *
618 __ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
619
620 extern const char *ceph_session_state_name(int s);
621 extern const char *ceph_reset_phase_name(enum ceph_client_reset_phase phase);
622
623 extern struct ceph_mds_session *
624 ceph_get_mds_session(struct ceph_mds_session *s);
625 extern void ceph_put_mds_session(struct ceph_mds_session *s);
626 int ceph_mdsc_schedule_reset(struct ceph_mds_client *mdsc,
627 const char *reason);
628 int ceph_mdsc_wait_for_reset(struct ceph_mds_client *mdsc);
629
630 extern int ceph_mdsc_init(struct ceph_fs_client *fsc);
631 extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
632 extern void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc);
633 extern void ceph_mdsc_destroy(struct ceph_fs_client *fsc);
634
635 extern void ceph_mdsc_sync(struct ceph_mds_client *mdsc);
636
637 extern void ceph_invalidate_dir_request(struct ceph_mds_request *req);
638 extern int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req,
639 struct inode *dir);
640 extern struct ceph_mds_request *
641 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode);
642 extern int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
643 struct inode *dir,
644 struct ceph_mds_request *req);
645 int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc,
646 struct ceph_mds_request *req,
647 ceph_mds_request_wait_callback_t wait_func);
648 extern int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
649 struct inode *dir,
650 struct ceph_mds_request *req);
651 extern void ceph_mdsc_release_dir_caps(struct ceph_mds_request *req);
652 extern void ceph_mdsc_release_dir_caps_async(struct ceph_mds_request *req);
ceph_mdsc_get_request(struct ceph_mds_request * req)653 static inline void ceph_mdsc_get_request(struct ceph_mds_request *req)
654 {
655 kref_get(&req->r_kref);
656 }
657 extern void ceph_mdsc_release_request(struct kref *kref);
ceph_mdsc_put_request(struct ceph_mds_request * req)658 static inline void ceph_mdsc_put_request(struct ceph_mds_request *req)
659 {
660 kref_put(&req->r_kref, ceph_mdsc_release_request);
661 }
662
663 extern void send_flush_mdlog(struct ceph_mds_session *s);
664 extern void ceph_mdsc_iterate_sessions(struct ceph_mds_client *mdsc,
665 void (*cb)(struct ceph_mds_session *),
666 bool check_state);
667 extern struct ceph_msg *ceph_create_session_msg(u32 op, u64 seq);
668 extern void __ceph_queue_cap_release(struct ceph_mds_session *session,
669 struct ceph_cap *cap);
670 extern void ceph_flush_session_cap_releases(struct ceph_mds_client *mdsc,
671 struct ceph_mds_session *session);
672 extern void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc);
673 extern void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr);
674 extern void ceph_queue_cap_unlink_work(struct ceph_mds_client *mdsc);
675 extern int ceph_iterate_session_caps(struct ceph_mds_session *session,
676 int (*cb)(struct inode *, int mds, void *),
677 void *arg);
678 extern int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath,
679 int mask);
680
681 extern void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc);
682
683 /*
684 * Structure to group path-related output parameters for build_*_path functions
685 */
686 struct ceph_path_info {
687 const char *path;
688 int pathlen;
689 struct ceph_vino vino;
690 bool freepath;
691 };
692
ceph_mdsc_free_path_info(const struct ceph_path_info * path_info)693 static inline void ceph_mdsc_free_path_info(const struct ceph_path_info *path_info)
694 {
695 if (path_info && path_info->freepath && !IS_ERR_OR_NULL(path_info->path))
696 __putname((char *)path_info->path - (PATH_MAX - 1 - path_info->pathlen));
697 }
698
699 extern char *ceph_mdsc_build_path(struct ceph_mds_client *mdsc,
700 struct dentry *dentry, struct ceph_path_info *path_info,
701 int for_wire);
702
703 extern void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry);
704 extern void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
705 struct dentry *dentry, char action,
706 u32 seq);
707
708 extern void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc,
709 struct ceph_msg *msg);
710 extern void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc,
711 struct ceph_msg *msg);
712
713 extern struct ceph_mds_session *
714 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target);
715
716 extern int ceph_trim_caps(struct ceph_mds_client *mdsc,
717 struct ceph_mds_session *session,
718 int max_caps);
719
ceph_wait_on_async_create(struct inode * inode)720 static inline int ceph_wait_on_async_create(struct inode *inode)
721 {
722 struct ceph_inode_info *ci = ceph_inode(inode);
723
724 return wait_on_bit(&ci->i_ceph_flags, CEPH_I_ASYNC_CREATE_BIT,
725 TASK_KILLABLE);
726 }
727
728 extern int ceph_wait_on_conflict_unlink(struct dentry *dentry);
729 extern u64 ceph_get_deleg_ino(struct ceph_mds_session *session);
730 extern int ceph_restore_deleg_ino(struct ceph_mds_session *session, u64 ino);
731
732 extern bool enable_unsafe_idmap;
733 #endif
734