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