hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/fs/ceph/mds_client.h
....@@ -10,23 +10,39 @@
1010 #include <linux/spinlock.h>
1111 #include <linux/refcount.h>
1212 #include <linux/utsname.h>
13
+#include <linux/ktime.h>
1314
1415 #include <linux/ceph/types.h>
1516 #include <linux/ceph/messenger.h>
1617 #include <linux/ceph/mdsmap.h>
1718 #include <linux/ceph/auth.h>
1819
20
+#include "metric.h"
21
+#include "super.h"
22
+
1923 /* The first 8 bits are reserved for old ceph releases */
20
-#define CEPHFS_FEATURE_MIMIC 8
24
+enum ceph_feature_type {
25
+ CEPHFS_FEATURE_MIMIC = 8,
26
+ CEPHFS_FEATURE_REPLY_ENCODING,
27
+ CEPHFS_FEATURE_RECLAIM_CLIENT,
28
+ CEPHFS_FEATURE_LAZY_CAP_WANTED,
29
+ CEPHFS_FEATURE_MULTI_RECONNECT,
30
+ CEPHFS_FEATURE_DELEG_INO,
31
+ CEPHFS_FEATURE_METRIC_COLLECT,
2132
22
-#define CEPHFS_FEATURES_ALL { \
23
- 0, 1, 2, 3, 4, 5, 6, 7, \
24
- CEPHFS_FEATURE_MIMIC, \
33
+ CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_METRIC_COLLECT,
34
+};
35
+
36
+#define CEPHFS_FEATURES_CLIENT_SUPPORTED { \
37
+ 0, 1, 2, 3, 4, 5, 6, 7, \
38
+ CEPHFS_FEATURE_MIMIC, \
39
+ CEPHFS_FEATURE_REPLY_ENCODING, \
40
+ CEPHFS_FEATURE_LAZY_CAP_WANTED, \
41
+ CEPHFS_FEATURE_MULTI_RECONNECT, \
42
+ CEPHFS_FEATURE_DELEG_INO, \
43
+ CEPHFS_FEATURE_METRIC_COLLECT, \
2544 }
26
-
27
-#define CEPHFS_FEATURES_CLIENT_SUPPORTED CEPHFS_FEATURES_ALL
2845 #define CEPHFS_FEATURES_CLIENT_REQUIRED {}
29
-
3046
3147 /*
3248 * Some lock dependencies:
....@@ -63,6 +79,10 @@
6379 char *pool_ns_data;
6480 u64 max_bytes;
6581 u64 max_files;
82
+ s32 dir_pin;
83
+ struct ceph_timespec btime;
84
+ struct ceph_timespec snap_btime;
85
+ u64 change_attr;
6686 };
6787
6888 struct ceph_mds_reply_dir_entry {
....@@ -139,10 +159,11 @@
139159 CEPH_MDS_SESSION_OPENING = 2,
140160 CEPH_MDS_SESSION_OPEN = 3,
141161 CEPH_MDS_SESSION_HUNG = 4,
142
- CEPH_MDS_SESSION_CLOSING = 5,
143
- CEPH_MDS_SESSION_RESTARTING = 6,
144
- CEPH_MDS_SESSION_RECONNECTING = 7,
145
- CEPH_MDS_SESSION_REJECTED = 8,
162
+ CEPH_MDS_SESSION_RESTARTING = 5,
163
+ CEPH_MDS_SESSION_RECONNECTING = 6,
164
+ CEPH_MDS_SESSION_CLOSING = 7,
165
+ CEPH_MDS_SESSION_CLOSED = 8,
166
+ CEPH_MDS_SESSION_REJECTED = 9,
146167 };
147168
148169 struct ceph_mds_session {
....@@ -150,6 +171,7 @@
150171 int s_mds;
151172 int s_state;
152173 unsigned long s_ttl; /* time until mds kills us */
174
+ unsigned long s_features;
153175 u64 s_seq; /* incoming msg seq # */
154176 struct mutex s_mutex; /* serialize session messages */
155177
....@@ -164,22 +186,28 @@
164186
165187 /* protected by s_cap_lock */
166188 spinlock_t s_cap_lock;
189
+ refcount_t s_ref;
167190 struct list_head s_caps; /* all caps issued by this session */
168
- int s_nr_caps, s_trim_caps;
191
+ struct ceph_cap *s_cap_iterator;
192
+ int s_nr_caps;
169193 int s_num_cap_releases;
170194 int s_cap_reconnect;
171195 int s_readonly;
172196 struct list_head s_cap_releases; /* waiting cap_release messages */
173
- struct ceph_cap *s_cap_iterator;
197
+ struct work_struct s_cap_release_work;
174198
175
- /* protected by mutex */
199
+ /* See ceph_inode_info->i_dirty_item. */
200
+ struct list_head s_cap_dirty; /* inodes w/ dirty caps */
201
+
202
+ /* See ceph_inode_info->i_flushing_item. */
176203 struct list_head s_cap_flushing; /* inodes w/ flushing caps */
204
+
177205 unsigned long s_renew_requested; /* last time we sent a renew req */
178206 u64 s_renew_seq;
179207
180
- refcount_t s_ref;
181208 struct list_head s_waiting; /* waiting requests */
182209 struct list_head s_unsafe; /* unsafe requests */
210
+ struct xarray s_delegated_inos;
183211 };
184212
185213 /*
....@@ -213,6 +241,7 @@
213241 struct rb_node r_node;
214242 struct ceph_mds_client *r_mdsc;
215243
244
+ struct kref r_kref;
216245 int r_op; /* mds op code */
217246
218247 /* operation on what? */
....@@ -233,6 +262,7 @@
233262 #define CEPH_MDS_R_GOT_RESULT (5) /* got a result */
234263 #define CEPH_MDS_R_DID_PREPOPULATE (6) /* prepopulated readdir */
235264 #define CEPH_MDS_R_PARENT_LOCKED (7) /* is r_parent->i_rwsem wlocked? */
265
+#define CEPH_MDS_R_ASYNC (8) /* async request */
236266 unsigned long r_req_flags;
237267
238268 struct mutex r_fill_mutex;
....@@ -241,6 +271,7 @@
241271 int r_fmode; /* file mode, if expecting cap */
242272 kuid_t r_uid;
243273 kgid_t r_gid;
274
+ int r_request_release_offset;
244275 struct timespec64 r_stamp;
245276
246277 /* for choosing which mds to send this request to */
....@@ -258,14 +289,20 @@
258289 int r_old_inode_drop, r_old_inode_unless;
259290
260291 struct ceph_msg *r_request; /* original request */
261
- int r_request_release_offset;
262292 struct ceph_msg *r_reply;
263293 struct ceph_mds_reply_info_parsed r_reply_info;
264
- struct page *r_locked_page;
265294 int r_err;
295
+
296
+
297
+ struct page *r_locked_page;
298
+ int r_dir_caps;
299
+ int r_num_caps;
300
+ u32 r_readdir_offset;
266301
267302 unsigned long r_timeout; /* optional. jiffies, 0 is "wait forever" */
268303 unsigned long r_started; /* start time to measure timeout against */
304
+ unsigned long r_start_latency; /* start time to measure latency */
305
+ unsigned long r_end_latency; /* finish time to measure latency */
269306 unsigned long r_request_started; /* start time for mds request only,
270307 used to measure lease durations */
271308
....@@ -282,8 +319,8 @@
282319 int r_num_fwd; /* number of forward attempts */
283320 int r_resend_mds; /* mds to resend to next, if any*/
284321 u32 r_sent_on_mseq; /* cap mseq request was sent at*/
322
+ u64 r_deleg_ino;
285323
286
- struct kref r_kref;
287324 struct list_head r_wait;
288325 struct completion r_completion;
289326 struct completion r_safe_completion;
....@@ -294,10 +331,8 @@
294331 long long r_dir_release_cnt;
295332 long long r_dir_ordered_cnt;
296333 int r_readdir_cache_idx;
297
- u32 r_readdir_offset;
298334
299335 struct ceph_cap_reservation r_caps_reservation;
300
- int r_num_caps;
301336 };
302337
303338 struct ceph_pool_perm {
....@@ -306,6 +341,40 @@
306341 s64 pool;
307342 size_t pool_ns_len;
308343 char pool_ns[];
344
+};
345
+
346
+struct ceph_snapid_map {
347
+ struct rb_node node;
348
+ struct list_head lru;
349
+ atomic_t ref;
350
+ u64 snap;
351
+ dev_t dev;
352
+ unsigned long last_used;
353
+};
354
+
355
+/*
356
+ * node for list of quotarealm inodes that are not visible from the filesystem
357
+ * mountpoint, but required to handle, e.g. quotas.
358
+ */
359
+struct ceph_quotarealm_inode {
360
+ struct rb_node node;
361
+ u64 ino;
362
+ unsigned long timeout; /* last time a lookup failed for this inode */
363
+ struct mutex mutex;
364
+ struct inode *inode;
365
+};
366
+
367
+struct cap_wait {
368
+ struct list_head list;
369
+ u64 ino;
370
+ pid_t tgid;
371
+ int need;
372
+ int want;
373
+};
374
+
375
+enum {
376
+ CEPH_MDSC_STOPPING_BEGIN = 1,
377
+ CEPH_MDSC_STOPPING_FLUSHED = 2,
309378 };
310379
311380 /*
....@@ -323,10 +392,16 @@
323392
324393 struct ceph_mds_session **sessions; /* NULL for mds if no session */
325394 atomic_t num_sessions;
326
- int max_sessions; /* len of s_mds_sessions */
395
+ int max_sessions; /* len of sessions array */
327396 int stopping; /* true if shutting down */
328397
329398 atomic64_t quotarealms_count; /* # realms with quota */
399
+ /*
400
+ * We keep a list of inodes we don't see in the mountpoint but that we
401
+ * need to track quota realms.
402
+ */
403
+ struct rb_root quotarealms_inodes;
404
+ struct mutex quotarealms_inodes_mutex;
330405
331406 /*
332407 * snap_rwsem will cover cap linkage into snaprealms, and
....@@ -339,6 +414,7 @@
339414 struct rw_semaphore snap_rwsem;
340415 struct rb_root snap_realms;
341416 struct list_head snap_empty;
417
+ int num_snap_realms;
342418 spinlock_t snap_empty_lock; /* protect snap_empty */
343419
344420 u64 last_tid; /* most recent mds request */
....@@ -354,11 +430,13 @@
354430
355431 u64 last_cap_flush_tid;
356432 struct list_head cap_flush_list;
357
- struct list_head cap_dirty; /* inodes with dirty caps */
358433 struct list_head cap_dirty_migrating; /* ...that are migration... */
359434 int num_cap_flushing; /* # caps we are flushing */
360435 spinlock_t cap_dirty_lock; /* protects above items */
361436 wait_queue_head_t cap_flushing_wq;
437
+
438
+ struct work_struct cap_reclaim_work;
439
+ atomic_t cap_reclaim_pending;
362440
363441 /*
364442 * Cap reservations
....@@ -374,15 +452,23 @@
374452 spinlock_t caps_list_lock;
375453 struct list_head caps_list; /* unused (reserved or
376454 unreserved) */
455
+ struct list_head cap_wait_list;
377456 int caps_total_count; /* total caps allocated */
378457 int caps_use_count; /* in use */
458
+ int caps_use_max; /* max used caps */
379459 int caps_reserve_count; /* unused, reserved */
380460 int caps_avail_count; /* unused, unreserved */
381461 int caps_min_count; /* keep at least this many
382462 (unreserved) */
383
- spinlock_t dentry_lru_lock;
384
- struct list_head dentry_lru;
385
- int num_dentry;
463
+ spinlock_t dentry_list_lock;
464
+ struct list_head dentry_leases; /* fifo list */
465
+ struct list_head dentry_dir_leases; /* lru list */
466
+
467
+ struct ceph_client_metric metric;
468
+
469
+ spinlock_t snapid_map_lock;
470
+ struct rb_root snapid_map_tree;
471
+ struct list_head snapid_map_lru;
386472
387473 struct rw_semaphore pool_perm_rwsem;
388474 struct rb_root pool_perm_tree;
....@@ -392,18 +478,16 @@
392478
393479 extern const char *ceph_mds_op_name(int op);
394480
481
+extern bool check_session_state(struct ceph_mds_session *s);
482
+void inc_session_sequence(struct ceph_mds_session *s);
483
+
395484 extern struct ceph_mds_session *
396485 __ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
397486
398
-static inline struct ceph_mds_session *
399
-ceph_get_mds_session(struct ceph_mds_session *s)
400
-{
401
- refcount_inc(&s->s_ref);
402
- return s;
403
-}
404
-
405487 extern const char *ceph_session_state_name(int s);
406488
489
+extern struct ceph_mds_session *
490
+ceph_get_mds_session(struct ceph_mds_session *s);
407491 extern void ceph_put_mds_session(struct ceph_mds_session *s);
408492
409493 extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc,
....@@ -421,11 +505,14 @@
421505 struct inode *dir);
422506 extern struct ceph_mds_request *
423507 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode);
424
-extern void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
425
- struct ceph_mds_request *req);
508
+extern int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
509
+ struct inode *dir,
510
+ struct ceph_mds_request *req);
426511 extern int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
427512 struct inode *dir,
428513 struct ceph_mds_request *req);
514
+extern void ceph_mdsc_release_dir_caps(struct ceph_mds_request *req);
515
+extern void ceph_mdsc_release_dir_caps_no_check(struct ceph_mds_request *req);
429516 static inline void ceph_mdsc_get_request(struct ceph_mds_request *req)
430517 {
431518 kref_get(&req->r_kref);
....@@ -436,17 +523,34 @@
436523 kref_put(&req->r_kref, ceph_mdsc_release_request);
437524 }
438525
439
-extern void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
440
- struct ceph_mds_session *session);
441
-
526
+extern void send_flush_mdlog(struct ceph_mds_session *s);
527
+extern void ceph_mdsc_iterate_sessions(struct ceph_mds_client *mdsc,
528
+ void (*cb)(struct ceph_mds_session *),
529
+ bool check_state);
530
+extern struct ceph_msg *ceph_create_session_msg(u32 op, u64 seq);
531
+extern void __ceph_queue_cap_release(struct ceph_mds_session *session,
532
+ struct ceph_cap *cap);
533
+extern void ceph_flush_cap_releases(struct ceph_mds_client *mdsc,
534
+ struct ceph_mds_session *session);
535
+extern void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc);
536
+extern void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr);
537
+extern int ceph_iterate_session_caps(struct ceph_mds_session *session,
538
+ int (*cb)(struct inode *,
539
+ struct ceph_cap *, void *),
540
+ void *arg);
442541 extern void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc);
542
+
543
+static inline void ceph_mdsc_free_path(char *path, int len)
544
+{
545
+ if (!IS_ERR_OR_NULL(path))
546
+ __putname(path - (PATH_MAX - 1 - len));
547
+}
443548
444549 extern char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
445550 int stop_on_nosnap);
446551
447552 extern void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry);
448553 extern void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
449
- struct inode *inode,
450554 struct dentry *dentry, char action,
451555 u32 seq);
452556
....@@ -463,4 +567,15 @@
463567 extern int ceph_trim_caps(struct ceph_mds_client *mdsc,
464568 struct ceph_mds_session *session,
465569 int max_caps);
570
+
571
+static inline int ceph_wait_on_async_create(struct inode *inode)
572
+{
573
+ struct ceph_inode_info *ci = ceph_inode(inode);
574
+
575
+ return wait_on_bit(&ci->i_ceph_flags, CEPH_ASYNC_CREATE_BIT,
576
+ TASK_INTERRUPTIBLE);
577
+}
578
+
579
+extern u64 ceph_get_deleg_ino(struct ceph_mds_session *session);
580
+extern int ceph_restore_deleg_ino(struct ceph_mds_session *session, u64 ino);
466581 #endif