1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
22f2dc053SSage Weil #ifndef _FS_CEPH_MDS_CLIENT_H
32f2dc053SSage Weil #define _FS_CEPH_MDS_CLIENT_H
42f2dc053SSage Weil
52f2dc053SSage Weil #include <linux/completion.h>
6153c8e6bSSage Weil #include <linux/kref.h>
72f2dc053SSage Weil #include <linux/list.h>
82f2dc053SSage Weil #include <linux/mutex.h>
944ca18f2SSage Weil #include <linux/rbtree.h>
102f2dc053SSage Weil #include <linux/spinlock.h>
113997c01dSElena Reshetova #include <linux/refcount.h>
12717e6f28SYan, Zheng #include <linux/utsname.h>
1370c94820SXiubo Li #include <linux/ktime.h>
142f2dc053SSage Weil
153d14c5d2SYehuda Sadeh #include <linux/ceph/types.h>
163d14c5d2SYehuda Sadeh #include <linux/ceph/messenger.h>
173d14c5d2SYehuda Sadeh #include <linux/ceph/mdsmap.h>
186c4a1915SAlex Elder #include <linux/ceph/auth.h>
192f2dc053SSage Weil
20f9009efaSXiubo Li #include "metric.h"
213e699bd8SXiubo Li #include "super.h"
22f9009efaSXiubo Li
23342ce182SYan, Zheng /* The first 8 bits are reserved for old ceph releases */
249ba1e224SXiubo Li enum ceph_feature_type {
259ba1e224SXiubo Li CEPHFS_FEATURE_MIMIC = 8,
269ba1e224SXiubo Li CEPHFS_FEATURE_REPLY_ENCODING,
279ba1e224SXiubo Li CEPHFS_FEATURE_RECLAIM_CLIENT,
289ba1e224SXiubo Li CEPHFS_FEATURE_LAZY_CAP_WANTED,
299ba1e224SXiubo Li CEPHFS_FEATURE_MULTI_RECONNECT,
30d4846487SJeff Layton CEPHFS_FEATURE_DELEG_INO,
3118f473b3SXiubo Li CEPHFS_FEATURE_METRIC_COLLECT,
32300e42a2SXiubo Li CEPHFS_FEATURE_ALTERNATE_NAME,
33300e42a2SXiubo Li CEPHFS_FEATURE_NOTIFY_SESSION_STATE,
34*6eb06c46SXiubo Li CEPHFS_FEATURE_OP_GETVXATTR,
35342ce182SYan, Zheng CEPHFS_FEATURE_32BITS_RETRY_FWD,
36*6eb06c46SXiubo Li
379ba1e224SXiubo Li CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_32BITS_RETRY_FWD,
389ba1e224SXiubo Li };
39d2f8bb27SYan, Zheng
40342ce182SYan, Zheng #define CEPHFS_FEATURES_CLIENT_SUPPORTED { \
41342ce182SYan, Zheng 0, 1, 2, 3, 4, 5, 6, 7, \
42b37fe1f9SYan, Zheng CEPHFS_FEATURE_MIMIC, \
43d2f8bb27SYan, Zheng CEPHFS_FEATURE_REPLY_ENCODING, \
4481c5a148SYan, Zheng CEPHFS_FEATURE_LAZY_CAP_WANTED, \
45d4846487SJeff Layton CEPHFS_FEATURE_MULTI_RECONNECT, \
4618f473b3SXiubo Li CEPHFS_FEATURE_DELEG_INO, \
47300e42a2SXiubo Li CEPHFS_FEATURE_METRIC_COLLECT, \
48*6eb06c46SXiubo Li CEPHFS_FEATURE_ALTERNATE_NAME, \
49342ce182SYan, Zheng CEPHFS_FEATURE_NOTIFY_SESSION_STATE, \
50342ce182SYan, Zheng CEPHFS_FEATURE_OP_GETVXATTR, \
512f2dc053SSage Weil CEPHFS_FEATURE_32BITS_RETRY_FWD, \
522f2dc053SSage Weil }
532f2dc053SSage Weil
542f2dc053SSage Weil /*
552f2dc053SSage Weil * Some lock dependencies:
562f2dc053SSage Weil *
572f2dc053SSage Weil * session->s_mutex
582f2dc053SSage Weil * mdsc->mutex
59be655596SSage Weil *
602f2dc053SSage Weil * mdsc->snap_rwsem
612f2dc053SSage Weil *
622f2dc053SSage Weil * ci->i_ceph_lock
632f2dc053SSage Weil * mdsc->snap_flush_lock
642f2dc053SSage Weil * mdsc->cap_delay_lock
653d14c5d2SYehuda Sadeh *
662f2dc053SSage Weil */
672f2dc053SSage Weil
682f2dc053SSage Weil struct ceph_fs_client;
692f2dc053SSage Weil struct ceph_cap;
702f2dc053SSage Weil
712f2dc053SSage Weil /*
722f2dc053SSage Weil * parsed info about a single inode. pointers are into the encoded
732f2dc053SSage Weil * on-wire structures within the mds reply message payload.
7414303d20SSage Weil */
752f2dc053SSage Weil struct ceph_mds_reply_info_in {
762f2dc053SSage Weil struct ceph_mds_reply_inode *in;
772f2dc053SSage Weil struct ceph_dir_layout dir_layout;
782f2dc053SSage Weil u32 symlink_len;
79fb01d1f8SYan, Zheng char *symlink;
80fb01d1f8SYan, Zheng u32 xattr_len;
81fb01d1f8SYan, Zheng char *xattr_data;
825ea5c5e0SYan, Zheng u64 inline_version;
83779fe0fbSYan, Zheng u32 inline_len;
84fb18a575SLuis Henriques char *inline_data;
85fb18a575SLuis Henriques u32 pool_ns_len;
8608796873SYan, Zheng char *pool_ns_data;
87245ce991SJeff Layton u64 max_bytes;
88193e7b37SDavid Disseldorp u64 max_files;
89e7f72952SYanhu Cao s32 dir_pin;
90a35ead31SJeff Layton struct ceph_timespec btime;
912f2dc053SSage Weil struct ceph_timespec snap_btime;
922f2dc053SSage Weil u8 *fscrypt_auth;
932a5beea3SYan, Zheng u8 *fscrypt_file;
942a5beea3SYan, Zheng u32 fscrypt_auth_len;
952a5beea3SYan, Zheng u32 fscrypt_file_len;
962a5beea3SYan, Zheng u64 rsnaps;
972a5beea3SYan, Zheng u64 change_attr;
988974eebdSYan, Zheng };
992a5beea3SYan, Zheng
1002a5beea3SYan, Zheng struct ceph_mds_reply_dir_entry {
1016ddf5f16SMilind Changire bool is_nokey;
1026ddf5f16SMilind Changire char *name;
1036ddf5f16SMilind Changire u32 name_len;
1046ddf5f16SMilind Changire u32 raw_hash;
1056ddf5f16SMilind Changire struct ceph_mds_reply_lease *lease;
1062f2dc053SSage Weil struct ceph_mds_reply_info_in inode;
10725933abdSHerb Shiu loff_t offset;
10825933abdSHerb Shiu };
10925933abdSHerb Shiu
11025933abdSHerb Shiu struct ceph_mds_reply_xattr {
1112f2dc053SSage Weil char *xattr_value;
1122f2dc053SSage Weil size_t xattr_value_len;
1132f2dc053SSage Weil };
1142f2dc053SSage Weil
11525933abdSHerb Shiu /*
1162f2dc053SSage Weil * parsed info about an mds reply, including information about
1172f2dc053SSage Weil * either: 1) the target inode and/or its parent directory and dentry,
1182f2dc053SSage Weil * and directory contents (for readdir results), or
1192f2dc053SSage Weil * 2) the file range lock info (for fcntl F_GETLK results).
1202f2dc053SSage Weil */
1216ddf5f16SMilind Changire struct ceph_mds_reply_info_parsed {
1222f2dc053SSage Weil struct ceph_mds_reply_head *head;
12325933abdSHerb Shiu
12425933abdSHerb Shiu /* trace */
12525933abdSHerb Shiu struct ceph_mds_reply_info_in diri, targeti;
12625933abdSHerb Shiu struct ceph_mds_reply_dirfrag *dirfrag;
12725933abdSHerb Shiu char *dname;
12825933abdSHerb Shiu u8 *altname;
12925933abdSHerb Shiu u32 dname_len;
1302f2dc053SSage Weil u32 altname_len;
13154008399SYan, Zheng struct ceph_mds_reply_lease *dlease;
1322f2dc053SSage Weil struct ceph_mds_reply_xattr xattr_info;
133f3c4ebe6SYan, Zheng
13479162547SYan, Zheng /* extra */
135f3c4ebe6SYan, Zheng union {
13679162547SYan, Zheng /* for fcntl F_GETLK results */
1372a5beea3SYan, Zheng struct ceph_filelock *filelock_reply;
13825933abdSHerb Shiu
1396e8575faSSam Lang /* for readdir results */
1406e8575faSSam Lang struct {
1416e8575faSSam Lang struct ceph_mds_reply_dirfrag *dir_dir;
1426e8575faSSam Lang size_t dir_buf_size;
1436e8575faSSam Lang int dir_nr;
1446e8575faSSam Lang bool dir_end;
14525933abdSHerb Shiu bool dir_complete;
1462f2dc053SSage Weil bool hash_order;
1472f2dc053SSage Weil bool offset_hash;
1482f2dc053SSage Weil struct ceph_mds_reply_dir_entry *dir_entries;
1492f2dc053SSage Weil };
1502f2dc053SSage Weil
1512f2dc053SSage Weil /* for create results */
1522f2dc053SSage Weil struct {
1532f2dc053SSage Weil bool has_create_ino;
1542f2dc053SSage Weil u64 ino;
1552f2dc053SSage Weil };
15692475f05SJeff Layton };
15792475f05SJeff Layton
15892475f05SJeff Layton /* encoded blob describing snapshot contexts for certain
1592f2dc053SSage Weil operations (e.g., open) */
16092475f05SJeff Layton void *snapblob;
1612f2dc053SSage Weil int snapblob_len;
1622f2dc053SSage Weil };
1632f2dc053SSage Weil
1642f2dc053SSage Weil
1652f2dc053SSage Weil /*
1662f2dc053SSage Weil * cap releases are batched and sent to the MDS en masse.
1672f2dc053SSage Weil *
1682f2dc053SSage Weil * Account for per-message overhead of mds_cap_release header
1692f2dc053SSage Weil * and __le32 for osd epoch barrier trailing field.
1702f2dc053SSage Weil */
1712f2dc053SSage Weil #define CEPH_CAPS_PER_RELEASE ((PAGE_SIZE - sizeof(u32) - \
1722f2dc053SSage Weil sizeof(struct ceph_mds_cap_release)) / \
1737e6906c1SYan, Zheng sizeof(struct ceph_mds_cap_item))
1747e6906c1SYan, Zheng
1757e6906c1SYan, Zheng
1764d681c2fSXiubo Li /*
1774d681c2fSXiubo Li * state associated with each MDS<->client session
1782f2dc053SSage Weil */
1792f2dc053SSage Weil enum {
1802f2dc053SSage Weil CEPH_MDS_SESSION_NEW = 1,
1812f2dc053SSage Weil CEPH_MDS_SESSION_OPENING = 2,
1822f2dc053SSage Weil CEPH_MDS_SESSION_OPEN = 3,
1832f2dc053SSage Weil CEPH_MDS_SESSION_HUNG = 4,
1842f2dc053SSage Weil CEPH_MDS_SESSION_RESTARTING = 5,
18584bf3950SYan, Zheng CEPH_MDS_SESSION_RECONNECTING = 6,
1862f2dc053SSage Weil CEPH_MDS_SESSION_CLOSING = 7,
1872f2dc053SSage Weil CEPH_MDS_SESSION_CLOSED = 8,
1882f2dc053SSage Weil CEPH_MDS_SESSION_REJECTED = 9,
1892f2dc053SSage Weil };
1902f2dc053SSage Weil
1916c4a1915SAlex Elder struct ceph_mds_session {
1924e7a5dcdSSage Weil struct ceph_mds_client *s_mdsc;
19352d60f8eSJeff Layton int s_mds;
19452d60f8eSJeff Layton int s_state;
195d8fb02abSAlex Elder unsigned long s_ttl; /* time until mds kills us */
196d8fb02abSAlex Elder unsigned long s_features;
197d8fb02abSAlex Elder u64 s_seq; /* incoming msg seq # */
198045100cdSJeff Layton struct mutex s_mutex; /* serialize session messages */
1992f2dc053SSage Weil
200e3ec8d68SYan, Zheng struct ceph_connection s_con;
201533a2818SJeff Layton
2022f2dc053SSage Weil struct ceph_auth_handshake s_auth;
20399a9c273SYan, Zheng
20403f4fcb0SYan, Zheng atomic_t s_cap_gen; /* inc each time we get mds stale msg */
2052f2dc053SSage Weil unsigned long s_cap_ttl; /* when session caps expire. protected by s_mutex */
206e3ec8d68SYan, Zheng
2072f2dc053SSage Weil /* protected by s_cap_lock */
208829ad4dbSJeff Layton spinlock_t s_cap_lock;
2091cf03a68SJeff Layton refcount_t s_ref;
210829ad4dbSJeff Layton struct list_head s_caps; /* all caps issued by this session */
211829ad4dbSJeff Layton struct ceph_cap *s_cap_iterator;
2122f2dc053SSage Weil int s_nr_caps;
2131cf03a68SJeff Layton int s_num_cap_releases;
2142f2dc053SSage Weil int s_cap_reconnect;
2152f2dc053SSage Weil int s_readonly;
2162f2dc053SSage Weil struct list_head s_cap_releases; /* waiting cap_release messages */
2172f2dc053SSage Weil struct work_struct s_cap_release_work;
2182f2dc053SSage Weil
219d4846487SJeff Layton /* See ceph_inode_info->i_dirty_item. */
2202f2dc053SSage Weil struct list_head s_cap_dirty; /* inodes w/ dirty caps */
2212f2dc053SSage Weil
2222f2dc053SSage Weil /* See ceph_inode_info->i_flushing_item. */
2232f2dc053SSage Weil struct list_head s_cap_flushing; /* inodes w/ flushing caps */
2242f2dc053SSage Weil
2252f2dc053SSage Weil unsigned long s_renew_requested; /* last time we sent a renew req */
2262f2dc053SSage Weil u64 s_renew_seq;
2272f2dc053SSage Weil
2282f2dc053SSage Weil struct list_head s_waiting; /* waiting requests */
2292f2dc053SSage Weil struct list_head s_unsafe; /* unsafe requests */
2302f2dc053SSage Weil struct xarray s_delegated_inos;
2312f2dc053SSage Weil };
2322f2dc053SSage Weil
2332f2dc053SSage Weil /*
2342f2dc053SSage Weil * modes of choosing which MDS to send a request to
2352f2dc053SSage Weil */
2362f2dc053SSage Weil enum {
2372f2dc053SSage Weil USE_ANY_MDS,
2382f2dc053SSage Weil USE_RANDOM_MDS,
2399280be24SYan, Zheng USE_AUTH_MDS, /* prefer authoritative mds for this metadata item */
2409280be24SYan, Zheng };
2419280be24SYan, Zheng
2429280be24SYan, Zheng struct ceph_mds_request;
2439280be24SYan, Zheng struct ceph_mds_client;
2442f2dc053SSage Weil
2452f2dc053SSage Weil /*
2462f2dc053SSage Weil * request completion callback
2472f2dc053SSage Weil */
2482f2dc053SSage Weil typedef void (*ceph_mds_request_callback_t) (struct ceph_mds_client *mdsc,
2492f2dc053SSage Weil struct ceph_mds_request *req);
25044ca18f2SSage Weil /*
25137151668SYehuda Sadeh * wait for request completion callback
2522f2dc053SSage Weil */
253045100cdSJeff Layton typedef int (*ceph_mds_request_wait_callback_t) (struct ceph_mds_client *mdsc,
2542f2dc053SSage Weil struct ceph_mds_request *req);
2552f2dc053SSage Weil
2562f2dc053SSage Weil /*
2572f2dc053SSage Weil * an in-flight mds request
2582f2dc053SSage Weil */
2592f2dc053SSage Weil struct ceph_mds_request {
26041b02e1fSSage Weil u64 r_tid; /* transaction id */
2612f2dc053SSage Weil struct rb_node r_node;
2622f2dc053SSage Weil struct ceph_mds_client *r_mdsc;
2632f2dc053SSage Weil
2643dd69aabSJeff Layton struct kref r_kref;
2652f2dc053SSage Weil int r_op; /* mds op code */
2662f2dc053SSage Weil
267bc2de10dSJeff Layton /* operation on what? */
268bc2de10dSJeff Layton struct inode *r_inode; /* arg1 */
269bc2de10dSJeff Layton struct dentry *r_dentry; /* arg1 */
270bc2de10dSJeff Layton struct dentry *r_old_dentry; /* arg2: rename from or link from */
271bc2de10dSJeff Layton struct inode *r_old_dentry_dir; /* arg2: old dentry's parent dir */
272bc2de10dSJeff Layton char *r_path1, *r_path2;
2733dd69aabSJeff Layton struct ceph_vino r_ino1, r_ino2;
2743bb48b41SJeff Layton
275bc2de10dSJeff Layton struct inode *r_parent; /* parent dir inode */
276bc2de10dSJeff Layton struct inode *r_target_inode; /* resulting inode */
277b4556396SSage Weil struct inode *r_new_inode; /* new inode (for creates) */
278b4556396SSage Weil
2792f2dc053SSage Weil #define CEPH_MDS_R_DIRECT_IS_HASH (1) /* r_direct_hash is valid */
2802f2dc053SSage Weil #define CEPH_MDS_R_ABORTED (2) /* call was aborted */
281c36d6414SJeff Layton #define CEPH_MDS_R_GOT_UNSAFE (3) /* got an unsafe reply */
2829eaa7b79SJeff Layton #define CEPH_MDS_R_GOT_SAFE (4) /* got a safe reply */
2830ed1e90aSArnd Bergmann #define CEPH_MDS_R_GOT_RESULT (5) /* got a result */
2842f2dc053SSage Weil #define CEPH_MDS_R_DID_PREPOPULATE (6) /* prepopulated readdir */
2852f2dc053SSage Weil #define CEPH_MDS_R_PARENT_LOCKED (7) /* is r_parent->i_rwsem wlocked? */
2862f2dc053SSage Weil #define CEPH_MDS_R_ASYNC (8) /* async request */
2872f2dc053SSage Weil #define CEPH_MDS_R_FSCRYPT_FILE (9) /* must marshal fscrypt_file field */
2882f2dc053SSage Weil unsigned long r_req_flags;
2892f2dc053SSage Weil
29025e6bae3SYan, Zheng struct mutex r_fill_mutex;
2912f2dc053SSage Weil
2922f2dc053SSage Weil union ceph_mds_request_args r_args;
2932f2dc053SSage Weil
2942f2dc053SSage Weil struct ceph_fscrypt_auth *r_fscrypt_auth;
2952f2dc053SSage Weil u64 r_fscrypt_file;
2962f2dc053SSage Weil
2972f2dc053SSage Weil u8 *r_altname; /* fscrypt binary crypttext for long filenames */
2982f2dc053SSage Weil u32 r_altname_len; /* length of r_altname */
2992f2dc053SSage Weil
3002f2dc053SSage Weil int r_fmode; /* file mode, if expecting cap */
3012f2dc053SSage Weil int r_request_release_offset;
3022f2dc053SSage Weil const struct cred *r_cred;
3039eaa7b79SJeff Layton struct timespec64 r_stamp;
304a25949b9SJeff Layton
305a25949b9SJeff Layton /* for choosing which mds to send this request to */
306a25949b9SJeff Layton int r_direct_mode;
307c36d6414SJeff Layton u32 r_direct_hash; /* choose dir frag based on this dentry hash */
3082f2dc053SSage Weil
309a319bf56SIlya Dryomov /* data payload is used for xattr ops */
3102f2dc053SSage Weil struct ceph_pagelist *r_pagelist;
31170c94820SXiubo Li
31270c94820SXiubo Li /* what caps shall we drop? */
3132f2dc053SSage Weil int r_inode_drop, r_inode_unless;
3142f2dc053SSage Weil int r_dentry_drop, r_dentry_unless;
3152f2dc053SSage Weil int r_old_dentry_drop, r_old_dentry_unless;
3162f2dc053SSage Weil struct inode *r_old_inode;
3172f2dc053SSage Weil int r_old_inode_drop, r_old_inode_unless;
3182f2dc053SSage Weil
3192f2dc053SSage Weil struct ceph_msg *r_request; /* original request */
32068cd5b4bSYan, Zheng struct ceph_msg *r_reply;
32168cd5b4bSYan, Zheng struct ceph_mds_reply_info_parsed r_reply_info;
32268cd5b4bSYan, Zheng int r_err;
3232f2dc053SSage Weil u32 r_readdir_offset;
3242f2dc053SSage Weil
3252f2dc053SSage Weil struct page *r_locked_page;
3262f2dc053SSage Weil int r_dir_caps;
3272f2dc053SSage Weil int r_num_caps;
328e55b71f8SGreg Farnum
3296deb8008SJeff Layton unsigned long r_timeout; /* optional. jiffies, 0 is "wait forever" */
3302f2dc053SSage Weil unsigned long r_started; /* start time to measure timeout against */
3312f2dc053SSage Weil unsigned long r_start_latency; /* start time to measure latency */
3322f2dc053SSage Weil unsigned long r_end_latency; /* finish time to measure latency */
3332f2dc053SSage Weil unsigned long r_request_started; /* start time for mds request only,
3342f2dc053SSage Weil used to measure lease durations */
3352f2dc053SSage Weil
3362f2dc053SSage Weil /* link unsafe requests to parent directory, for fsync */
337fdd4e158SYan, Zheng struct inode *r_unsafe_dir;
338fdd4e158SYan, Zheng struct list_head r_unsafe_dir_item;
339fdd4e158SYan, Zheng
3402f2dc053SSage Weil /* unsafe requests that modify the target inode */
341*6eb06c46SXiubo Li struct list_head r_unsafe_target_item;
342*6eb06c46SXiubo Li
3432f2dc053SSage Weil struct ceph_mds_session *r_session;
3442f2dc053SSage Weil
3452f2dc053SSage Weil int r_attempts; /* resend attempts */
34610183a69SYan, Zheng int r_num_fwd; /* number of forward attempts */
34710183a69SYan, Zheng int r_resend_mds; /* mds to resend to next, if any*/
34810183a69SYan, Zheng u32 r_sent_on_mseq; /* cap mseq request was sent at*/
3497627151eSYan, Zheng u64 r_deleg_ino;
350779fe0fbSYan, Zheng
351779fe0fbSYan, Zheng struct list_head r_wait;
35210183a69SYan, Zheng struct completion r_completion;
35310183a69SYan, Zheng struct completion r_safe_completion;
35475c9627eSYan, Zheng ceph_mds_request_callback_t r_callback;
35575c9627eSYan, Zheng struct list_head r_unsafe_item; /* per-session unsafe list item */
35675c9627eSYan, Zheng
35775c9627eSYan, Zheng long long r_dir_release_cnt;
35875c9627eSYan, Zheng long long r_dir_ordered_cnt;
35975c9627eSYan, Zheng int r_readdir_cache_idx;
36075c9627eSYan, Zheng
36175c9627eSYan, Zheng int r_feature_needed;
36275c9627eSYan, Zheng
3632f2dc053SSage Weil struct ceph_cap_reservation r_caps_reservation;
3640c44a8e0SLuis Henriques };
3650c44a8e0SLuis Henriques
3660c44a8e0SLuis Henriques struct ceph_pool_perm {
3670c44a8e0SLuis Henriques struct rb_node node;
3680c44a8e0SLuis Henriques int perm;
3690c44a8e0SLuis Henriques s64 pool;
3700c44a8e0SLuis Henriques size_t pool_ns_len;
3710c44a8e0SLuis Henriques char pool_ns[];
3720c44a8e0SLuis Henriques };
3730c44a8e0SLuis Henriques
3740c44a8e0SLuis Henriques struct ceph_snapid_map {
3753a3430afSJeff Layton struct rb_node node;
3763a3430afSJeff Layton struct list_head lru;
377ebce3eb2SJeff Layton atomic_t ref;
3783a3430afSJeff Layton dev_t dev;
3793a3430afSJeff Layton u64 snap;
3803a3430afSJeff Layton unsigned long last_used;
3813a3430afSJeff Layton };
3823a3430afSJeff Layton
3830c44a8e0SLuis Henriques /*
3842f2dc053SSage Weil * node for list of quotarealm inodes that are not visible from the filesystem
3852f2dc053SSage Weil * mountpoint, but required to handle, e.g. quotas.
3862f2dc053SSage Weil */
3873d14c5d2SYehuda Sadeh struct ceph_quotarealm_inode {
3882f2dc053SSage Weil struct rb_node node;
3892f2dc053SSage Weil u64 ino;
3902f2dc053SSage Weil unsigned long timeout; /* last time a lookup failed for this inode */
391f3c60c59SSage Weil struct mutex mutex;
392f3c60c59SSage Weil struct inode *inode;
3932f2dc053SSage Weil };
394430afbadSYan, Zheng
3952f2dc053SSage Weil struct cap_wait {
3962f2dc053SSage Weil struct list_head list;
39786d8f67bSYan, Zheng u64 ino;
398c74d79afSJeff Layton pid_t tgid;
3992f2dc053SSage Weil int need;
4002f2dc053SSage Weil int want;
401d557c48dSLuis Henriques };
4020c44a8e0SLuis Henriques
4030c44a8e0SLuis Henriques enum {
4040c44a8e0SLuis Henriques CEPH_MDSC_STOPPING_BEGIN = 1,
4050c44a8e0SLuis Henriques CEPH_MDSC_STOPPING_FLUSHING = 2,
4060c44a8e0SLuis Henriques CEPH_MDSC_STOPPING_FLUSHED = 3,
4070c44a8e0SLuis Henriques };
408d557c48dSLuis Henriques
4092f2dc053SSage Weil /*
4102f2dc053SSage Weil * mds client state
4112f2dc053SSage Weil */
4122f2dc053SSage Weil struct ceph_mds_client {
4132f2dc053SSage Weil struct ceph_fs_client *fsc;
4142f2dc053SSage Weil struct mutex mutex; /* all nested structures */
4152f2dc053SSage Weil
416affbc19aSYan, Zheng struct ceph_mdsmap *mdsmap;
4172f2dc053SSage Weil struct completion safe_umount_waiters;
418a105f00cSSage Weil wait_queue_head_t session_close_wq;
4192f2dc053SSage Weil struct list_head waiting_for_map;
42081c5a148SYan, Zheng int mdsmap_err;
4212f2dc053SSage Weil
4222f2dc053SSage Weil struct ceph_mds_session **sessions; /* NULL for mds if no session */
4232f2dc053SSage Weil atomic_t num_sessions;
424e8a7b8b1SYan, Zheng int max_sessions; /* len of sessions array */
425e8a7b8b1SYan, Zheng
42644ca18f2SSage Weil spinlock_t stopping_lock; /* protect snap_empty */
4272f2dc053SSage Weil int stopping; /* the stage of shutting down */
4282f2dc053SSage Weil atomic_t stopping_blockers;
4292f2dc053SSage Weil struct completion stopping_waiter;
4302f2dc053SSage Weil
4312f2dc053SSage Weil atomic64_t quotarealms_count; /* # realms with quota */
4322f2dc053SSage Weil /*
4332f2dc053SSage Weil * We keep a list of inodes we don't see in the mountpoint but that we
434553adfd9SYan, Zheng * need to track quota realms.
435e4500b5eSYan, Zheng */
436db354052SSage Weil struct rb_root quotarealms_inodes;
4372f2dc053SSage Weil struct mutex quotarealms_inodes_mutex;
4382f2dc053SSage Weil
4392f2dc053SSage Weil /*
4402f2dc053SSage Weil * snap_rwsem will cover cap linkage into snaprealms, and
44137c4efc1SYan, Zheng * realm snap contexts. (later, we can do per-realm snap
442fe33032dSYan, Zheng * contexts locks..) the empty list contains realms with no
44337c4efc1SYan, Zheng * references (implying they contain no inodes with caps) that
44437151668SYehuda Sadeh * should be destroyed.
44537151668SYehuda Sadeh */
44637151668SYehuda Sadeh u64 last_snap_seq;
44737151668SYehuda Sadeh struct rw_semaphore snap_rwsem;
44837151668SYehuda Sadeh struct rb_root snap_realms;
44937151668SYehuda Sadeh struct list_head snap_empty;
45037151668SYehuda Sadeh int num_snap_realms;
45137151668SYehuda Sadeh spinlock_t snap_empty_lock; /* protect snap_empty */
45237151668SYehuda Sadeh
45337151668SYehuda Sadeh u64 last_tid; /* most recent mds request */
45437151668SYehuda Sadeh u64 oldest_tid; /* oldest incomplete mds request,
45537151668SYehuda Sadeh excluding setfilelock requests */
45637151668SYehuda Sadeh struct rb_root request_tree; /* pending mds requests */
45737151668SYehuda Sadeh struct delayed_work delayed_work; /* delayed work */
4583a3430afSJeff Layton unsigned long last_renew_caps; /* last time we renewed our caps */
45937151668SYehuda Sadeh struct list_head cap_delay_list; /* caps with delayed release */
46037151668SYehuda Sadeh spinlock_t cap_delay_lock; /* protects cap_delay_list */
461fe33032dSYan, Zheng struct list_head snap_flush_list; /* cap_snaps ready to flush */
46237151668SYehuda Sadeh spinlock_t snap_flush_lock;
46337151668SYehuda Sadeh
46437151668SYehuda Sadeh u64 last_cap_flush_tid;
46537151668SYehuda Sadeh struct list_head cap_flush_list;
46637c4efc1SYan, Zheng struct list_head cap_dirty_migrating; /* ...that are migration... */
46737c4efc1SYan, Zheng int num_cap_flushing; /* # caps we are flushing */
46837c4efc1SYan, Zheng spinlock_t cap_dirty_lock; /* protects above items */
46910183a69SYan, Zheng wait_queue_head_t cap_flushing_wq;
470f9009efaSXiubo Li
471f9009efaSXiubo Li struct work_struct cap_reclaim_work;
47275c9627eSYan, Zheng atomic_t cap_reclaim_pending;
47375c9627eSYan, Zheng
47475c9627eSYan, Zheng /*
47575c9627eSYan, Zheng * Cap reservations
47610183a69SYan, Zheng *
47710183a69SYan, Zheng * Maintain a global pool of preallocated struct ceph_caps, referenced
478717e6f28SYan, Zheng * by struct ceph_caps_reservations. This ensures that we preallocate
479717e6f28SYan, Zheng * memory needed to successfully process an MDS response. (If an MDS
4802f2dc053SSage Weil * sends us cap information and we fail to process it, we will have
4812f2dc053SSage Weil * problems due to the client and MDS being out of sync.)
4822f2dc053SSage Weil *
4832f2dc053SSage Weil * Reservations are 'owned' by a ceph_cap_reservation context.
4843e699bd8SXiubo Li */
48562575e27SJeff Layton spinlock_t caps_list_lock;
4863e699bd8SXiubo Li struct list_head caps_list; /* unused (reserved or
4872f2dc053SSage Weil unreserved) */
4882f2dc053SSage Weil struct list_head cap_wait_list;
4892f2dc053SSage Weil int caps_total_count; /* total caps allocated */
490a687ecafSJohn Spray int caps_use_count; /* in use */
491a687ecafSJohn Spray int caps_use_max; /* max used caps */
4925b3248c6SXiubo Li int caps_reserve_count; /* unused, reserved */
4935b3248c6SXiubo Li int caps_avail_count; /* unused, unreserved */
4942f2dc053SSage Weil int caps_min_count; /* keep at least this many
4952f2dc053SSage Weil (unreserved) */
4962f2dc053SSage Weil spinlock_t dentry_list_lock;
4972f2dc053SSage Weil struct list_head dentry_leases; /* fifo list */
4982f2dc053SSage Weil struct list_head dentry_dir_leases; /* lru list */
4993d14c5d2SYehuda Sadeh
5002f2dc053SSage Weil struct ceph_client_metric metric;
50148fec5d0SYan, Zheng
5023d14c5d2SYehuda Sadeh spinlock_t snapid_map_lock;
5032f2dc053SSage Weil struct rb_root snapid_map_tree;
5042f2dc053SSage Weil struct list_head snapid_map_lru;
5052f2dc053SSage Weil
506167c9e35SSage Weil struct rw_semaphore pool_perm_rwsem;
50754008399SYan, Zheng struct rb_root pool_perm_tree;
50854008399SYan, Zheng
5092f2dc053SSage Weil char nodename[__NEW_UTS_LEN + 1];
5102f2dc053SSage Weil };
51186bda539SJeff Layton
51286bda539SJeff Layton extern const char *ceph_mds_op_name(int op);
5132f2dc053SSage Weil
5149eaa7b79SJeff Layton extern bool check_session_state(struct ceph_mds_session *s);
5159eaa7b79SJeff Layton void inc_session_sequence(struct ceph_mds_session *s);
5169eaa7b79SJeff Layton
5172f2dc053SSage Weil extern struct ceph_mds_session *
5182f2dc053SSage Weil __ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
5192f2dc053SSage Weil
520a25949b9SJeff Layton extern const char *ceph_session_state_name(int s);
521e64f44a8SXiubo Li
5222f2dc053SSage Weil extern struct ceph_mds_session *
5232f2dc053SSage Weil ceph_get_mds_session(struct ceph_mds_session *s);
524153c8e6bSSage Weil extern void ceph_put_mds_session(struct ceph_mds_session *s);
5252f2dc053SSage Weil
526153c8e6bSSage Weil extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc,
527153c8e6bSSage Weil struct ceph_msg *msg, int mds);
528153c8e6bSSage Weil
529153c8e6bSSage Weil extern int ceph_mdsc_init(struct ceph_fs_client *fsc);
530153c8e6bSSage Weil extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
5312f2dc053SSage Weil extern void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc);
532d095559cSXiubo Li extern void ceph_mdsc_destroy(struct ceph_fs_client *fsc);
53359b312f3SXiubo Li
53459b312f3SXiubo Li extern void ceph_mdsc_sync(struct ceph_mds_client *mdsc);
53559b312f3SXiubo Li
536fba97e80SXiubo Li extern void ceph_invalidate_dir_request(struct ceph_mds_request *req);
537e3ec8d68SYan, Zheng extern int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req,
538e3ec8d68SYan, Zheng struct inode *dir);
539e3ec8d68SYan, Zheng extern struct ceph_mds_request *
5403d7ded4dSSage Weil ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode);
54137c4efc1SYan, Zheng extern int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
542fe33032dSYan, Zheng struct inode *dir,
543f5d77269SJeff Layton struct ceph_mds_request *req);
544f5d77269SJeff Layton int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc,
545f5d77269SJeff Layton struct ceph_mds_request *req,
546f5d77269SJeff Layton ceph_mds_request_wait_callback_t wait_func);
5472f2dc053SSage Weil extern int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
5482f2dc053SSage Weil struct inode *dir,
549f77f21bbSJeff Layton struct ceph_mds_request *req);
550f77f21bbSJeff Layton extern void ceph_mdsc_release_dir_caps(struct ceph_mds_request *req);
5512a575f13SJeff Layton extern void ceph_mdsc_release_dir_caps_no_check(struct ceph_mds_request *req);
ceph_mdsc_get_request(struct ceph_mds_request * req)552f77f21bbSJeff Layton static inline void ceph_mdsc_get_request(struct ceph_mds_request *req)
553f77f21bbSJeff Layton {
554f77f21bbSJeff Layton kref_get(&req->r_kref);
5552f2dc053SSage Weil }
5562f2dc053SSage Weil extern void ceph_mdsc_release_request(struct kref *kref);
ceph_mdsc_put_request(struct ceph_mds_request * req)5572f2dc053SSage Weil static inline void ceph_mdsc_put_request(struct ceph_mds_request *req)
5582f2dc053SSage Weil {
5592f2dc053SSage Weil kref_put(&req->r_kref, ceph_mdsc_release_request);
5602f2dc053SSage Weil }
5612f2dc053SSage Weil
5622f2dc053SSage Weil extern void send_flush_mdlog(struct ceph_mds_session *s);
563430afbadSYan, Zheng extern void ceph_mdsc_iterate_sessions(struct ceph_mds_client *mdsc,
564430afbadSYan, Zheng void (*cb)(struct ceph_mds_session *),
565430afbadSYan, Zheng bool check_state);
5662f2dc053SSage Weil extern struct ceph_msg *ceph_create_session_msg(u32 op, u64 seq);
5672f2dc053SSage Weil extern void __ceph_queue_cap_release(struct ceph_mds_session *session,
5685d72d13cSYan, Zheng struct ceph_cap *cap);
5695d72d13cSYan, Zheng extern void ceph_flush_cap_releases(struct ceph_mds_client *mdsc,
570154f42c2SSage Weil struct ceph_mds_session *session);
571154f42c2SSage Weil extern void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc);
572154f42c2SSage Weil extern void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr);
573e30ee581SZhi Zhang extern int ceph_iterate_session_caps(struct ceph_mds_session *session,
574e30ee581SZhi Zhang int (*cb)(struct inode *, int mds, void *),
575e30ee581SZhi Zhang void *arg);
576d4846487SJeff Layton extern void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc);
577891f3f5aSJeff Layton
ceph_mdsc_free_path(char * path,int len)578891f3f5aSJeff Layton static inline void ceph_mdsc_free_path(char *path, int len)
579891f3f5aSJeff Layton {
580891f3f5aSJeff Layton if (!IS_ERR_OR_NULL(path))
581891f3f5aSJeff Layton __putname(path - (PATH_MAX - 1 - len));
5825e56776dSXiubo Li }
583891f3f5aSJeff Layton
584d4846487SJeff Layton extern char *ceph_mdsc_build_path(struct ceph_mds_client *mdsc,
5854868e537SXiubo Li struct dentry *dentry, int *plen, u64 *base,
586d4846487SJeff Layton int for_wire);
587d4846487SJeff Layton
5882f2dc053SSage Weil extern void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry);
589 extern void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
590 struct dentry *dentry, char action,
591 u32 seq);
592
593 extern void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc,
594 struct ceph_msg *msg);
595 extern void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc,
596 struct ceph_msg *msg);
597
598 extern struct ceph_mds_session *
599 ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target);
600 extern void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc,
601 struct ceph_mds_session *session);
602
603 extern int ceph_trim_caps(struct ceph_mds_client *mdsc,
604 struct ceph_mds_session *session,
605 int max_caps);
606
ceph_wait_on_async_create(struct inode * inode)607 static inline int ceph_wait_on_async_create(struct inode *inode)
608 {
609 struct ceph_inode_info *ci = ceph_inode(inode);
610
611 return wait_on_bit(&ci->i_ceph_flags, CEPH_ASYNC_CREATE_BIT,
612 TASK_KILLABLE);
613 }
614
615 extern int ceph_wait_on_conflict_unlink(struct dentry *dentry);
616 extern u64 ceph_get_deleg_ino(struct ceph_mds_session *session);
617 extern int ceph_restore_deleg_ino(struct ceph_mds_session *session, u64 ino);
618 #endif
619