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