blob: 16c03188578ea7eee4fee4fdbb7de38fd4e7b3a9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sage Weilde576062009-10-06 11:31:07 -07002#ifndef _FS_CEPH_SUPER_H
3#define _FS_CEPH_SUPER_H
4
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07005#include <linux/ceph/ceph_debug.h>
Sage Weilde576062009-10-06 11:31:07 -07006
7#include <asm/unaligned.h>
8#include <linux/backing-dev.h>
9#include <linux/completion.h>
10#include <linux/exportfs.h>
11#include <linux/fs.h>
12#include <linux/mempool.h>
13#include <linux/pagemap.h>
14#include <linux/wait.h>
Stephen Rothwellf1a3d572010-01-18 11:53:08 +110015#include <linux/writeback.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Guangliang Zhaoc969d9b2014-02-16 08:35:52 -080017#include <linux/posix_acl.h>
Elena Reshetova805692d2017-03-03 11:15:07 +020018#include <linux/refcount.h>
Sage Weilde576062009-10-06 11:31:07 -070019
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070020#include <linux/ceph/libceph.h>
Sage Weilde576062009-10-06 11:31:07 -070021
Milosz Tanski99ccbd22013-08-21 17:29:54 -040022#ifdef CONFIG_CEPH_FSCACHE
23#include <linux/fscache.h>
24#endif
25
Sage Weilde576062009-10-06 11:31:07 -070026/* f_type in struct statfs */
27#define CEPH_SUPER_MAGIC 0x00c36400
28
29/* large granularity for statfs utilization stats to facilitate
30 * large volume sizes on 32-bit machines. */
Sage Weil92a49fb2013-02-22 15:31:00 -080031#define CEPH_BLOCK_SHIFT 22 /* 4 MB */
Sage Weilde576062009-10-06 11:31:07 -070032#define CEPH_BLOCK (1 << CEPH_BLOCK_SHIFT)
33
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070034#define CEPH_MOUNT_OPT_DIRSTAT (1<<4) /* `cat dirname` for stats */
35#define CEPH_MOUNT_OPT_RBYTES (1<<5) /* dir st_bytes = rbytes */
36#define CEPH_MOUNT_OPT_NOASYNCREADDIR (1<<7) /* no dcache readdir */
Yehuda Sadehad1fee92011-01-21 16:44:03 -080037#define CEPH_MOUNT_OPT_INO32 (1<<8) /* 32 bit inos */
Sage Weila40dc6c2012-01-10 09:12:55 -080038#define CEPH_MOUNT_OPT_DCACHE (1<<9) /* use dcache for readdir etc */
Milosz Tanski99ccbd22013-08-21 17:29:54 -040039#define CEPH_MOUNT_OPT_FSCACHE (1<<10) /* use fscache */
Yan, Zheng10183a62015-04-27 15:33:28 +080040#define CEPH_MOUNT_OPT_NOPOOLPERM (1<<11) /* no pool permission check */
Yan, Zhenge9e427f2016-11-10 16:02:06 +080041#define CEPH_MOUNT_OPT_MOUNTWAIT (1<<12) /* mount waits if no mds is up */
Luis Henriques9122eed2018-01-31 10:53:13 +000042#define CEPH_MOUNT_OPT_NOQUOTADF (1<<13) /* no root dir quota in statfs */
Luis Henriquesea4cdc52018-10-15 16:46:00 +010043#define CEPH_MOUNT_OPT_NOCOPYFROM (1<<14) /* don't use RADOS 'copy-from' op */
Sage Weil6a259382010-07-07 09:06:08 -070044
Luis Henriques6f9718f2018-12-10 10:23:12 +000045#define CEPH_MOUNT_OPT_DEFAULT \
46 (CEPH_MOUNT_OPT_DCACHE | \
47 CEPH_MOUNT_OPT_NOCOPYFROM)
Sage Weilde576062009-10-06 11:31:07 -070048
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070049#define ceph_set_mount_opt(fsc, opt) \
50 (fsc)->mount_options->flags |= CEPH_MOUNT_OPT_##opt;
51#define ceph_test_mount_opt(fsc, opt) \
52 (!!((fsc)->mount_options->flags & CEPH_MOUNT_OPT_##opt))
Sage Weilde576062009-10-06 11:31:07 -070053
Yan, Zhengaa187922017-07-11 15:56:09 +080054/* max size of osd read request, limited by libceph */
55#define CEPH_MAX_READ_SIZE CEPH_MSG_MAX_DATA_LEN
Yan, Zheng95cca2b2017-07-11 17:34:46 +080056/* osd has a configurable limitaion of max write size.
57 * CEPH_MSG_MAX_DATA_LEN should be small enough. */
58#define CEPH_MAX_WRITE_SIZE CEPH_MSG_MAX_DATA_LEN
Andreas Gerstmayr7c94ba22017-01-10 14:17:56 +010059#define CEPH_RASIZE_DEFAULT (8192*1024) /* max readahead */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070060#define CEPH_MAX_READDIR_DEFAULT 1024
61#define CEPH_MAX_READDIR_BYTES_DEFAULT (512*1024)
62#define CEPH_SNAPDIRNAME_DEFAULT ".snap"
Sage Weilde576062009-10-06 11:31:07 -070063
Yan, Zheng4214fb12017-07-11 18:49:44 +080064/*
65 * Delay telling the MDS we no longer want caps, in case we reopen
66 * the file. Delay a minimum amount of time, even if we send a cap
67 * message for some other reason. Otherwise, take the oppotunity to
68 * update the mds to avoid sending another message later.
69 */
70#define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
71#define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
72
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070073struct ceph_mount_options {
Sage Weilde576062009-10-06 11:31:07 -070074 int flags;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070075 int sb_flags;
76
Sage Weil83817e32011-08-04 08:03:44 -070077 int wsize; /* max write size */
78 int rsize; /* max read size */
79 int rasize; /* max readahead */
Sage Weil6e19a162010-04-29 16:38:32 -070080 int congestion_kb; /* max writeback in flight */
81 int caps_wanted_delay_min, caps_wanted_delay_max;
Yan, Zhengfe330322019-02-01 14:57:15 +080082 int caps_max;
Sage Weil23804d92010-05-14 13:06:30 -070083 int max_readdir; /* max readdir result (entires) */
84 int max_readdir_bytes; /* max readdir result (bytes) */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070085
86 /*
87 * everything above this point can be memcmp'd; everything below
88 * is handled in compare_mount_options()
89 */
90
Sage Weilde576062009-10-06 11:31:07 -070091 char *snapdir_name; /* default ".snap" */
Yan, Zheng430afba2016-07-08 11:25:38 +080092 char *mds_namespace; /* default NULL */
Yan, Zheng3f384952016-04-21 11:09:55 +080093 char *server_path; /* default "/" */
Yan, Zheng1d8f8362017-06-27 11:57:56 +080094 char *fscache_uniq; /* default NULL */
Sage Weilde576062009-10-06 11:31:07 -070095};
96
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070097struct ceph_fs_client {
Sage Weilde576062009-10-06 11:31:07 -070098 struct super_block *sb;
99
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700100 struct ceph_mount_options *mount_options;
101 struct ceph_client *client;
102
Sage Weilde576062009-10-06 11:31:07 -0700103 unsigned long mount_state;
Chengguang Xu719784b2018-07-19 22:15:24 +0800104 loff_t max_file_size;
Sage Weil85ccce42010-02-17 10:02:43 -0800105
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700106 struct ceph_mds_client *mdsc;
Sage Weilde576062009-10-06 11:31:07 -0700107
108 /* writeback */
109 mempool_t *wb_pagevec_pool;
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800110 atomic_long_t writeback_count;
111
Sage Weilde576062009-10-06 11:31:07 -0700112 struct workqueue_struct *wb_wq;
113 struct workqueue_struct *pg_inv_wq;
114 struct workqueue_struct *trunc_wq;
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800115 struct workqueue_struct *cap_wq;
Sage Weilde576062009-10-06 11:31:07 -0700116
Sage Weil07433042009-11-18 16:50:41 -0800117#ifdef CONFIG_DEBUG_FS
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700118 struct dentry *debugfs_dentry_lru, *debugfs_caps;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800119 struct dentry *debugfs_congestion_kb;
Sage Weil06edf042009-12-15 14:44:32 -0800120 struct dentry *debugfs_bdi;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700121 struct dentry *debugfs_mdsc, *debugfs_mdsmap;
John Spray14ed9702014-09-12 16:58:49 +0100122 struct dentry *debugfs_mds_sessions;
Sage Weil07433042009-11-18 16:50:41 -0800123#endif
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400124
125#ifdef CONFIG_CEPH_FSCACHE
126 struct fscache_cookie *fscache;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400127#endif
Sage Weilde576062009-10-06 11:31:07 -0700128};
129
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700130
Sage Weilde576062009-10-06 11:31:07 -0700131/*
132 * File i/o capability. This tracks shared state with the metadata
133 * server that allows us to cache or writeback attributes or to read
134 * and write data. For any given inode, we should have one or more
135 * capabilities, one issued by each metadata server, and our
136 * cumulative access is the OR of all issued capabilities.
137 *
138 * Each cap is referenced by the inode's i_caps rbtree and by per-mds
139 * session capability lists.
140 */
141struct ceph_cap {
142 struct ceph_inode_info *ci;
143 struct rb_node ci_node; /* per-ci cap tree */
144 struct ceph_mds_session *session;
145 struct list_head session_caps; /* per-session caplist */
Sage Weilde576062009-10-06 11:31:07 -0700146 u64 cap_id; /* unique cap id (mds provided) */
Yan, Zheng745a8e32015-05-14 17:22:42 +0800147 union {
148 /* in-use caps */
149 struct {
150 int issued; /* latest, from the mds */
151 int implemented; /* implemented superset of
152 issued (for revocation) */
153 int mds, mds_wanted;
154 };
155 /* caps to release */
156 struct {
157 u64 cap_ino;
158 int queue_release;
159 };
160 };
Sage Weil685f9a5d2009-11-09 12:05:48 -0800161 u32 seq, issue_seq, mseq;
162 u32 cap_gen; /* active/stale cycle */
Sage Weilde576062009-10-06 11:31:07 -0700163 unsigned long last_used;
164 struct list_head caps_item;
165};
166
167#define CHECK_CAPS_NODELAY 1 /* do not delay any further */
168#define CHECK_CAPS_AUTHONLY 2 /* only check auth cap */
169#define CHECK_CAPS_FLUSH 4 /* flush any dirty caps */
170
Yan, Zheng0e294382016-07-04 18:06:41 +0800171struct ceph_cap_flush {
172 u64 tid;
173 int caps; /* 0 means capsnap */
Yan, Zhengc8799fc2016-07-07 15:22:38 +0800174 bool wake; /* wake up flush waiters when finish ? */
Yan, Zheng0e294382016-07-04 18:06:41 +0800175 struct list_head g_list; // global
176 struct list_head i_list; // per inode
177};
178
Sage Weilde576062009-10-06 11:31:07 -0700179/*
180 * Snapped cap state that is pending flush to mds. When a snapshot occurs,
181 * we first complete any in-process sync writes and writeback any dirty
182 * data before flushing the snapped state (tracked here) back to the MDS.
183 */
184struct ceph_cap_snap {
Elena Reshetova805692d2017-03-03 11:15:07 +0200185 refcount_t nref;
Yan, Zheng0e294382016-07-04 18:06:41 +0800186 struct list_head ci_item;
Sage Weilde576062009-10-06 11:31:07 -0700187
Yan, Zheng0e294382016-07-04 18:06:41 +0800188 struct ceph_cap_flush cap_flush;
189
190 u64 follows;
Sage Weilde576062009-10-06 11:31:07 -0700191 int issued, dirty;
192 struct ceph_snap_context *context;
193
Al Viro5706b272011-07-26 04:52:22 -0400194 umode_t mode;
Eric W. Biederman05cb11c2013-01-31 02:56:19 -0800195 kuid_t uid;
196 kgid_t gid;
Sage Weilde576062009-10-06 11:31:07 -0700197
Sage Weil4a625be2010-08-22 15:03:56 -0700198 struct ceph_buffer *xattr_blob;
Sage Weilde576062009-10-06 11:31:07 -0700199 u64 xattr_version;
200
201 u64 size;
Arnd Bergmann9bbeab42018-07-13 22:18:36 +0200202 struct timespec64 mtime, atime, ctime;
Sage Weilde576062009-10-06 11:31:07 -0700203 u64 time_warp_seq;
Yan, Zheng5f743e42016-11-15 16:04:37 +0800204 u64 truncate_size;
205 u32 truncate_seq;
Sage Weilde576062009-10-06 11:31:07 -0700206 int writing; /* a sync write is still in progress */
207 int dirty_pages; /* dirty pages awaiting writeback */
Yan, Zhenge20d2582014-11-14 22:39:13 +0800208 bool inline_data;
Yan, Zheng86056092015-05-01 16:57:16 +0800209 bool need_flush;
Sage Weilde576062009-10-06 11:31:07 -0700210};
211
212static inline void ceph_put_cap_snap(struct ceph_cap_snap *capsnap)
213{
Elena Reshetova805692d2017-03-03 11:15:07 +0200214 if (refcount_dec_and_test(&capsnap->nref)) {
Sage Weil4a625be2010-08-22 15:03:56 -0700215 if (capsnap->xattr_blob)
216 ceph_buffer_put(capsnap->xattr_blob);
Sage Weilde576062009-10-06 11:31:07 -0700217 kfree(capsnap);
Sage Weil4a625be2010-08-22 15:03:56 -0700218 }
Sage Weilde576062009-10-06 11:31:07 -0700219}
220
221/*
222 * The frag tree describes how a directory is fragmented, potentially across
223 * multiple metadata servers. It is also used to indicate points where
224 * metadata authority is delegated, and whether/where metadata is replicated.
225 *
226 * A _leaf_ frag will be present in the i_fragtree IFF there is
227 * delegation info. That is, if mds >= 0 || ndist > 0.
228 */
229#define CEPH_MAX_DIRFRAG_REP 4
230
231struct ceph_inode_frag {
232 struct rb_node node;
233
234 /* fragtree state */
235 u32 frag;
236 int split_by; /* i.e. 2^(split_by) children */
237
238 /* delegation and replication info */
239 int mds; /* -1 if same authority as parent */
240 int ndist; /* >0 if replicated */
241 int dist[CEPH_MAX_DIRFRAG_REP];
242};
243
244/*
245 * We cache inode xattrs as an encoded blob until they are first used,
246 * at which point we parse them into an rbtree.
247 */
248struct ceph_inode_xattr {
249 struct rb_node node;
250
251 const char *name;
252 int name_len;
253 const char *val;
254 int val_len;
255 int dirty;
256
257 int should_free_name;
258 int should_free_val;
259};
260
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700261/*
262 * Ceph dentry state
263 */
264struct ceph_dentry_info {
Yan, Zheng37c4efc2019-01-31 16:55:51 +0800265 struct dentry *dentry;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700266 struct ceph_mds_session *lease_session;
Yan, Zheng37c4efc2019-01-31 16:55:51 +0800267 struct list_head lease_list;
268 unsigned flags;
Yan, Zheng97aeb6b2017-11-27 10:47:46 +0800269 int lease_shared_gen;
270 u32 lease_gen;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700271 u32 lease_seq;
272 unsigned long lease_renew_after, lease_renew_from;
Miklos Szeredi9b16f03c2016-06-22 16:35:04 +0200273 unsigned long time;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700274 u64 offset;
275};
276
Yan, Zheng37c4efc2019-01-31 16:55:51 +0800277#define CEPH_DENTRY_REFERENCED 1
278#define CEPH_DENTRY_LEASE_LIST 2
279#define CEPH_DENTRY_SHRINK_LIST 4
280
Sage Weilde576062009-10-06 11:31:07 -0700281struct ceph_inode_xattrs_info {
282 /*
283 * (still encoded) xattr blob. we avoid the overhead of parsing
284 * this until someone actually calls getxattr, etc.
285 *
286 * blob->vec.iov_len == 4 implies there are no xattrs; blob ==
287 * NULL means we don't know.
288 */
289 struct ceph_buffer *blob, *prealloc_blob;
290
291 struct rb_root index;
292 bool dirty;
293 int count;
294 int names_size;
295 int vals_size;
296 u64 version, index_version;
297};
298
299/*
300 * Ceph inode.
301 */
Sage Weilde576062009-10-06 11:31:07 -0700302struct ceph_inode_info {
303 struct ceph_vino i_vino; /* ceph ino + snap */
304
Sage Weilbe655592011-11-30 09:47:09 -0800305 spinlock_t i_ceph_lock;
306
Sage Weilde576062009-10-06 11:31:07 -0700307 u64 i_version;
Yan, Zheng31c542a2014-11-14 21:41:55 +0800308 u64 i_inline_version;
Sage Weilde576062009-10-06 11:31:07 -0700309 u32 i_time_warp_seq;
310
311 unsigned i_ceph_flags;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800312 atomic64_t i_release_count;
313 atomic64_t i_ordered_count;
314 atomic64_t i_complete_seq[2];
Sage Weilde576062009-10-06 11:31:07 -0700315
Sage Weil6c0f3af2010-11-16 11:14:34 -0800316 struct ceph_dir_layout i_dir_layout;
Sage Weilde576062009-10-06 11:31:07 -0700317 struct ceph_file_layout i_layout;
318 char *i_symlink;
319
320 /* for dirs */
Arnd Bergmann9bbeab42018-07-13 22:18:36 +0200321 struct timespec64 i_rctime;
Sage Weilde576062009-10-06 11:31:07 -0700322 u64 i_rbytes, i_rfiles, i_rsubdirs;
323 u64 i_files, i_subdirs;
Sage Weilde576062009-10-06 11:31:07 -0700324
Luis Henriquesfb18a572018-01-05 10:47:18 +0000325 /* quotas */
326 u64 i_max_bytes, i_max_files;
327
Yan, Zheng08796872019-01-09 11:07:02 +0800328 s32 i_dir_pin;
329
Sage Weilde576062009-10-06 11:31:07 -0700330 struct rb_root i_fragtree;
Yan, Zheng1b1bc162016-05-04 11:40:30 +0800331 int i_fragtree_nsplits;
Sage Weilde576062009-10-06 11:31:07 -0700332 struct mutex i_fragtree_mutex;
333
334 struct ceph_inode_xattrs_info i_xattrs;
335
Sage Weilbe655592011-11-30 09:47:09 -0800336 /* capabilities. protected _both_ by i_ceph_lock and cap->session's
Sage Weilde576062009-10-06 11:31:07 -0700337 * s_mutex. */
338 struct rb_root i_caps; /* cap list */
339 struct ceph_cap *i_auth_cap; /* authoritative cap, if any */
340 unsigned i_dirty_caps, i_flushing_caps; /* mask of dirtied fields */
341 struct list_head i_dirty_item, i_flushing_item;
Sage Weilde576062009-10-06 11:31:07 -0700342 /* we need to track cap writeback on a per-cap-bit basis, to allow
343 * overlapping, pipelined cap flushes to the mds. we can probably
344 * reduce the tid to 8 bits if we're concerned about inode size. */
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800345 struct ceph_cap_flush *i_prealloc_cap_flush;
Yan, Zhenge4500b52016-07-06 11:12:56 +0800346 struct list_head i_cap_flush_list;
Sage Weilde576062009-10-06 11:31:07 -0700347 wait_queue_head_t i_cap_wq; /* threads waiting on a capability */
348 unsigned long i_hold_caps_min; /* jiffies */
349 unsigned long i_hold_caps_max; /* jiffies */
350 struct list_head i_cap_delay_list; /* for delayed cap release to mds */
Sage Weilde576062009-10-06 11:31:07 -0700351 struct ceph_cap_reservation i_cap_migration_resv;
352 struct list_head i_cap_snaps; /* snapped state pending flush to mds */
Sage Weil7d8cb262010-08-24 08:44:16 -0700353 struct ceph_snap_context *i_head_snapc; /* set if wr_buffer_head > 0 or
354 dirty|flushing caps */
Sage Weilde576062009-10-06 11:31:07 -0700355 unsigned i_snap_caps; /* cap bits for snapped files */
356
Yan, Zheng774a6a12016-06-06 16:01:39 +0800357 int i_nr_by_mode[CEPH_FILE_MODE_BITS]; /* open file counts */
Sage Weilde576062009-10-06 11:31:07 -0700358
Yan, Zhengb0d7c222013-08-12 21:42:15 -0700359 struct mutex i_truncate_mutex;
Sage Weilde576062009-10-06 11:31:07 -0700360 u32 i_truncate_seq; /* last truncate to smaller size */
361 u64 i_truncate_size; /* and the size we last truncated down to */
362 int i_truncate_pending; /* still need to call vmtruncate */
363
364 u64 i_max_size; /* max file size authorized by mds */
365 u64 i_reported_size; /* (max_)size reported to or requested of mds */
366 u64 i_wanted_max_size; /* offset we'd like to write too */
367 u64 i_requested_max_size; /* max_size we've requested */
368
369 /* held references to caps */
370 int i_pin_ref;
Henry C Changd3d07202011-05-11 10:29:54 +0000371 int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref;
Sage Weilde576062009-10-06 11:31:07 -0700372 int i_wrbuffer_ref, i_wrbuffer_ref_head;
Yan, Zheng89aa5932017-09-08 15:23:18 +0800373 atomic_t i_filelock_ref;
Yan, Zheng97aeb6b2017-11-27 10:47:46 +0800374 atomic_t i_shared_gen; /* increment each time we get FILE_SHARED */
Sage Weilcd045cb2010-11-04 11:05:05 -0700375 u32 i_rdcache_gen; /* incremented each time we get FILE_CACHE. */
Sage Weilde576062009-10-06 11:31:07 -0700376 u32 i_rdcache_revoking; /* RDCACHE gen to async invalidate, if any */
377
Sage Weilde576062009-10-06 11:31:07 -0700378 struct list_head i_unsafe_dirops; /* uncommitted mds dir ops */
Yan, Zheng68cd5b42015-10-27 18:36:06 +0800379 struct list_head i_unsafe_iops; /* uncommitted mds inode ops */
Sage Weilde576062009-10-06 11:31:07 -0700380 spinlock_t i_unsafe_lock;
381
Yan, Zheng75c96272017-12-14 15:11:09 +0800382 union {
383 struct ceph_snap_realm *i_snap_realm; /* snap realm (if caps) */
384 struct ceph_snapid_map *i_snapid_map; /* snapid -> dev_t */
385 };
Sage Weilde576062009-10-06 11:31:07 -0700386 int i_snap_realm_counter; /* snap realm (if caps) */
387 struct list_head i_snap_realm_item;
388 struct list_head i_snap_flush_item;
389
390 struct work_struct i_wb_work; /* writeback work */
391 struct work_struct i_pg_inv_work; /* page invalidation work */
392
393 struct work_struct i_vmtruncate_work;
394
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400395#ifdef CONFIG_CEPH_FSCACHE
396 struct fscache_cookie *fscache;
Yan, Zhengf7f7e7a2016-05-18 20:31:55 +0800397 u32 i_fscache_gen;
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400398#endif
Sage Weilde576062009-10-06 11:31:07 -0700399 struct inode vfs_inode; /* at end */
400};
401
402static inline struct ceph_inode_info *ceph_inode(struct inode *inode)
403{
Noah Watkinsfbbccec2009-10-28 11:54:49 -0700404 return container_of(inode, struct ceph_inode_info, vfs_inode);
Sage Weilde576062009-10-06 11:31:07 -0700405}
406
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800407static inline struct ceph_fs_client *ceph_inode_to_client(struct inode *inode)
408{
409 return (struct ceph_fs_client *)inode->i_sb->s_fs_info;
410}
411
412static inline struct ceph_fs_client *ceph_sb_to_client(struct super_block *sb)
413{
414 return (struct ceph_fs_client *)sb->s_fs_info;
415}
416
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700417static inline struct ceph_vino ceph_vino(struct inode *inode)
418{
419 return ceph_inode(inode)->i_vino;
420}
421
422/*
423 * ino_t is <64 bits on many architectures, blech.
424 *
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800425 * i_ino (kernel inode) st_ino (userspace)
426 * i386 32 32
427 * x86_64+ino32 64 32
428 * x86_64 64 64
429 */
Amon Ott3310f752011-10-20 13:04:07 -0700430static inline u32 ceph_ino_to_ino32(__u64 vino)
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800431{
Amon Ott3310f752011-10-20 13:04:07 -0700432 u32 ino = vino & 0xffffffff;
433 ino ^= vino >> 32;
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800434 if (!ino)
Amon Otta661fc52012-01-23 09:25:23 -0800435 ino = 2;
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800436 return ino;
437}
438
439/*
440 * kernel i_ino value
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700441 */
442static inline ino_t ceph_vino_to_ino(struct ceph_vino vino)
443{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700444#if BITS_PER_LONG == 32
Amon Ott3310f752011-10-20 13:04:07 -0700445 return ceph_ino_to_ino32(vino.ino);
446#else
447 return (ino_t)vino.ino;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700448#endif
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700449}
450
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800451/*
452 * user-visible ino (stat, filldir)
453 */
454#if BITS_PER_LONG == 32
455static inline ino_t ceph_translate_ino(struct super_block *sb, ino_t ino)
456{
457 return ino;
458}
459#else
460static inline ino_t ceph_translate_ino(struct super_block *sb, ino_t ino)
461{
462 if (ceph_test_mount_opt(ceph_sb_to_client(sb), INO32))
463 ino = ceph_ino_to_ino32(ino);
464 return ino;
465}
466#endif
467
468
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700469/* for printf-style formatting */
470#define ceph_vinop(i) ceph_inode(i)->i_vino.ino, ceph_inode(i)->i_vino.snap
471
472static inline u64 ceph_ino(struct inode *inode)
473{
474 return ceph_inode(inode)->i_vino.ino;
475}
476static inline u64 ceph_snap(struct inode *inode)
477{
478 return ceph_inode(inode)->i_vino.snap;
479}
480
481static inline int ceph_ino_compare(struct inode *inode, void *data)
482{
483 struct ceph_vino *pvino = (struct ceph_vino *)data;
484 struct ceph_inode_info *ci = ceph_inode(inode);
485 return ci->i_vino.ino == pvino->ino &&
486 ci->i_vino.snap == pvino->snap;
487}
488
489static inline struct inode *ceph_find_inode(struct super_block *sb,
490 struct ceph_vino vino)
491{
492 ino_t t = ceph_vino_to_ino(vino);
493 return ilookup5(sb, t, ceph_ino_compare, &vino);
494}
495
496
497/*
498 * Ceph inode.
499 */
Yan, Zheng10183a62015-04-27 15:33:28 +0800500#define CEPH_I_DIR_ORDERED (1 << 0) /* dentries in dir are ordered */
501#define CEPH_I_NODELAY (1 << 1) /* do not delay cap release */
502#define CEPH_I_FLUSH (1 << 2) /* do not delay flush of dirty metadata */
503#define CEPH_I_NOFLUSH (1 << 3) /* do not flush dirty caps */
504#define CEPH_I_POOL_PERM (1 << 4) /* pool rd/wr bits are valid */
505#define CEPH_I_POOL_RD (1 << 5) /* can read from pool */
506#define CEPH_I_POOL_WR (1 << 6) /* can write to pool */
Yan, Zheng315f2402016-03-07 10:34:50 +0800507#define CEPH_I_SEC_INITED (1 << 7) /* security initialized */
Yan, Zheng77310322016-04-08 15:27:16 +0800508#define CEPH_I_CAP_DROPPED (1 << 8) /* caps were forcibly dropped */
Yan, Zheng13c2b572016-07-05 16:45:21 +0800509#define CEPH_I_KICK_FLUSH (1 << 9) /* kick flushing caps */
Yan, Zheng70220ac2016-07-06 16:21:30 +0800510#define CEPH_I_FLUSH_SNAPS (1 << 10) /* need flush snapss */
Jeff Layton26544c622017-04-04 08:39:46 -0400511#define CEPH_I_ERROR_WRITE (1 << 11) /* have seen write errors */
Yan, Zhengb3f8d682017-09-11 10:58:55 +0800512#define CEPH_I_ERROR_FILELOCK (1 << 12) /* have seen file lock errors */
513
Jeff Layton26544c622017-04-04 08:39:46 -0400514
515/*
516 * We set the ERROR_WRITE bit when we start seeing write errors on an inode
517 * and then clear it when they start succeeding. Note that we do a lockless
518 * check first, and only take the lock if it looks like it needs to be changed.
519 * The write submission code just takes this as a hint, so we're not too
520 * worried if a few slip through in either direction.
521 */
522static inline void ceph_set_error_write(struct ceph_inode_info *ci)
523{
524 if (!(READ_ONCE(ci->i_ceph_flags) & CEPH_I_ERROR_WRITE)) {
525 spin_lock(&ci->i_ceph_lock);
526 ci->i_ceph_flags |= CEPH_I_ERROR_WRITE;
527 spin_unlock(&ci->i_ceph_lock);
528 }
529}
530
531static inline void ceph_clear_error_write(struct ceph_inode_info *ci)
532{
533 if (READ_ONCE(ci->i_ceph_flags) & CEPH_I_ERROR_WRITE) {
534 spin_lock(&ci->i_ceph_lock);
535 ci->i_ceph_flags &= ~CEPH_I_ERROR_WRITE;
536 spin_unlock(&ci->i_ceph_lock);
537 }
538}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700539
Yan, Zheng2f276c52013-03-13 19:44:32 +0800540static inline void __ceph_dir_set_complete(struct ceph_inode_info *ci,
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800541 long long release_count,
542 long long ordered_count)
Sage Weilde576062009-10-06 11:31:07 -0700543{
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800544 smp_mb__before_atomic();
545 atomic64_set(&ci->i_complete_seq[0], release_count);
546 atomic64_set(&ci->i_complete_seq[1], ordered_count);
Sage Weilde576062009-10-06 11:31:07 -0700547}
548
Yan, Zheng2f276c52013-03-13 19:44:32 +0800549static inline void __ceph_dir_clear_complete(struct ceph_inode_info *ci)
Sage Weilde576062009-10-06 11:31:07 -0700550{
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800551 atomic64_inc(&ci->i_release_count);
552}
553
554static inline void __ceph_dir_clear_ordered(struct ceph_inode_info *ci)
555{
556 atomic64_inc(&ci->i_ordered_count);
Sage Weilde576062009-10-06 11:31:07 -0700557}
558
Yan, Zheng2f276c52013-03-13 19:44:32 +0800559static inline bool __ceph_dir_is_complete(struct ceph_inode_info *ci)
Sage Weilde576062009-10-06 11:31:07 -0700560{
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800561 return atomic64_read(&ci->i_complete_seq[0]) ==
562 atomic64_read(&ci->i_release_count);
Yan, Zheng2f276c52013-03-13 19:44:32 +0800563}
Sage Weilde576062009-10-06 11:31:07 -0700564
Yan, Zheng70db4f32014-10-21 18:09:56 -0700565static inline bool __ceph_dir_is_complete_ordered(struct ceph_inode_info *ci)
566{
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800567 return atomic64_read(&ci->i_complete_seq[0]) ==
568 atomic64_read(&ci->i_release_count) &&
569 atomic64_read(&ci->i_complete_seq[1]) ==
570 atomic64_read(&ci->i_ordered_count);
Yan, Zheng70db4f32014-10-21 18:09:56 -0700571}
572
Yan, Zheng2f276c52013-03-13 19:44:32 +0800573static inline void ceph_dir_clear_complete(struct inode *inode)
574{
575 __ceph_dir_clear_complete(ceph_inode(inode));
576}
577
Yan, Zheng70db4f32014-10-21 18:09:56 -0700578static inline void ceph_dir_clear_ordered(struct inode *inode)
Yan, Zheng2f276c52013-03-13 19:44:32 +0800579{
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800580 __ceph_dir_clear_ordered(ceph_inode(inode));
Sage Weilde576062009-10-06 11:31:07 -0700581}
582
Yan, Zheng70db4f32014-10-21 18:09:56 -0700583static inline bool ceph_dir_is_complete_ordered(struct inode *inode)
584{
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800585 bool ret = __ceph_dir_is_complete_ordered(ceph_inode(inode));
586 smp_rmb();
Yan, Zheng70db4f32014-10-21 18:09:56 -0700587 return ret;
588}
Sage Weilde576062009-10-06 11:31:07 -0700589
590/* find a specific frag @f */
591extern struct ceph_inode_frag *__ceph_find_frag(struct ceph_inode_info *ci,
592 u32 f);
593
594/*
595 * choose fragment for value @v. copy frag content to pfrag, if leaf
596 * exists
597 */
598extern u32 ceph_choose_frag(struct ceph_inode_info *ci, u32 v,
599 struct ceph_inode_frag *pfrag,
600 int *found);
601
Yan, Zheng1e9c2eb2019-01-28 20:43:55 +0800602static inline struct ceph_dentry_info *ceph_dentry(const struct dentry *dentry)
Sage Weilde576062009-10-06 11:31:07 -0700603{
604 return (struct ceph_dentry_info *)dentry->d_fsdata;
605}
606
Sage Weilde576062009-10-06 11:31:07 -0700607/*
608 * caps helpers
609 */
610static inline bool __ceph_is_any_real_caps(struct ceph_inode_info *ci)
611{
612 return !RB_EMPTY_ROOT(&ci->i_caps);
613}
614
615extern int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented);
616extern int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int t);
617extern int __ceph_caps_issued_other(struct ceph_inode_info *ci,
618 struct ceph_cap *cap);
619
620static inline int ceph_caps_issued(struct ceph_inode_info *ci)
621{
622 int issued;
Sage Weilbe655592011-11-30 09:47:09 -0800623 spin_lock(&ci->i_ceph_lock);
Sage Weilde576062009-10-06 11:31:07 -0700624 issued = __ceph_caps_issued(ci, NULL);
Sage Weilbe655592011-11-30 09:47:09 -0800625 spin_unlock(&ci->i_ceph_lock);
Sage Weilde576062009-10-06 11:31:07 -0700626 return issued;
627}
628
629static inline int ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask,
630 int touch)
631{
632 int r;
Sage Weilbe655592011-11-30 09:47:09 -0800633 spin_lock(&ci->i_ceph_lock);
Sage Weilde576062009-10-06 11:31:07 -0700634 r = __ceph_caps_issued_mask(ci, mask, touch);
Sage Weilbe655592011-11-30 09:47:09 -0800635 spin_unlock(&ci->i_ceph_lock);
Sage Weilde576062009-10-06 11:31:07 -0700636 return r;
637}
638
639static inline int __ceph_caps_dirty(struct ceph_inode_info *ci)
640{
641 return ci->i_dirty_caps | ci->i_flushing_caps;
642}
Yan, Zhengf66fd9f2015-06-10 17:26:13 +0800643extern struct ceph_cap_flush *ceph_alloc_cap_flush(void);
644extern void ceph_free_cap_flush(struct ceph_cap_flush *cf);
645extern int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask,
646 struct ceph_cap_flush **pcf);
Sage Weilde576062009-10-06 11:31:07 -0700647
Yan, Zheng9563f882013-11-22 13:50:45 +0800648extern int __ceph_caps_revoking_other(struct ceph_inode_info *ci,
649 struct ceph_cap *ocap, int mask);
Sage Weilde576062009-10-06 11:31:07 -0700650extern int ceph_caps_revoking(struct ceph_inode_info *ci, int mask);
651extern int __ceph_caps_used(struct ceph_inode_info *ci);
652
653extern int __ceph_caps_file_wanted(struct ceph_inode_info *ci);
654
655/*
656 * wanted, by virtue of open file modes AND cap refs (buffered/cached data)
657 */
658static inline int __ceph_caps_wanted(struct ceph_inode_info *ci)
659{
660 int w = __ceph_caps_file_wanted(ci) | __ceph_caps_used(ci);
661 if (w & CEPH_CAP_FILE_BUFFER)
662 w |= CEPH_CAP_FILE_EXCL; /* we want EXCL if dirty data */
663 return w;
664}
665
666/* what the mds thinks we want */
Yan, Zhengc1944fe2017-01-29 22:15:47 +0800667extern int __ceph_caps_mds_wanted(struct ceph_inode_info *ci, bool check);
Sage Weilde576062009-10-06 11:31:07 -0700668
Yehuda Sadeh37151662010-06-17 16:16:12 -0700669extern void ceph_caps_init(struct ceph_mds_client *mdsc);
670extern void ceph_caps_finalize(struct ceph_mds_client *mdsc);
Yan, Zhengfe330322019-02-01 14:57:15 +0800671extern void ceph_adjust_caps_max_min(struct ceph_mds_client *mdsc,
672 struct ceph_mount_options *fsopt);
Zhi Zhange30ee582018-01-24 21:24:33 +0800673extern int ceph_reserve_caps(struct ceph_mds_client *mdsc,
Yehuda Sadeh37151662010-06-17 16:16:12 -0700674 struct ceph_cap_reservation *ctx, int need);
Chengguang Xu7bf8f732018-07-28 23:15:35 +0800675extern void ceph_unreserve_caps(struct ceph_mds_client *mdsc,
Yehuda Sadeh37151662010-06-17 16:16:12 -0700676 struct ceph_cap_reservation *ctx);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700677extern void ceph_reservation_status(struct ceph_fs_client *client,
Sage Weilde576062009-10-06 11:31:07 -0700678 int *total, int *avail, int *used,
Sage Weil85ccce42010-02-17 10:02:43 -0800679 int *reserved, int *min);
Sage Weilde576062009-10-06 11:31:07 -0700680
Sage Weilde576062009-10-06 11:31:07 -0700681
Sage Weilde576062009-10-06 11:31:07 -0700682
683/*
684 * we keep buffered readdir results attached to file->private_data
685 */
Sage Weil4918b6d2011-07-26 11:26:07 -0700686#define CEPH_F_SYNC 1
Sage Weil9cfa1092011-07-26 11:26:18 -0700687#define CEPH_F_ATEND 2
Sage Weil4918b6d2011-07-26 11:26:07 -0700688
Sage Weilde576062009-10-06 11:31:07 -0700689struct ceph_file_info {
Sage Weil252c6722011-07-26 11:25:27 -0700690 short fmode; /* initialized on open */
691 short flags; /* CEPH_F_* */
Sage Weilde576062009-10-06 11:31:07 -0700692
Yan, Zheng5d988302017-12-15 11:15:36 +0800693 spinlock_t rw_contexts_lock;
694 struct list_head rw_contexts;
Chengguang Xubb48bd42018-03-13 10:42:44 +0800695};
696
697struct ceph_dir_file_info {
698 struct ceph_file_info file_info;
Yan, Zheng5d988302017-12-15 11:15:36 +0800699
Sage Weilde576062009-10-06 11:31:07 -0700700 /* readdir: position within the dir */
701 u32 frag;
702 struct ceph_mds_request *last_readdir;
Sage Weilde576062009-10-06 11:31:07 -0700703
704 /* readdir: position within a frag */
Yan, Zhengf0494202014-02-27 16:26:24 +0800705 unsigned next_offset; /* offset of next chunk (last_name's + 1) */
Sage Weilde576062009-10-06 11:31:07 -0700706 char *last_name; /* last entry in previous chunk */
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800707 long long dir_release_count;
708 long long dir_ordered_count;
709 int readdir_cache_idx;
Sage Weilde576062009-10-06 11:31:07 -0700710
711 /* used for -o dirstat read() on directory thing */
712 char *dir_info;
713 int dir_info_len;
714};
715
Yan, Zheng5d988302017-12-15 11:15:36 +0800716struct ceph_rw_context {
717 struct list_head list;
718 struct task_struct *thread;
719 int caps;
720};
721
722#define CEPH_DEFINE_RW_CONTEXT(_name, _caps) \
723 struct ceph_rw_context _name = { \
724 .thread = current, \
725 .caps = _caps, \
726 }
727
728static inline void ceph_add_rw_context(struct ceph_file_info *cf,
729 struct ceph_rw_context *ctx)
730{
731 spin_lock(&cf->rw_contexts_lock);
732 list_add(&ctx->list, &cf->rw_contexts);
733 spin_unlock(&cf->rw_contexts_lock);
734}
735
736static inline void ceph_del_rw_context(struct ceph_file_info *cf,
737 struct ceph_rw_context *ctx)
738{
739 spin_lock(&cf->rw_contexts_lock);
740 list_del(&ctx->list);
741 spin_unlock(&cf->rw_contexts_lock);
742}
743
744static inline struct ceph_rw_context*
745ceph_find_rw_context(struct ceph_file_info *cf)
746{
747 struct ceph_rw_context *ctx, *found = NULL;
748 spin_lock(&cf->rw_contexts_lock);
749 list_for_each_entry(ctx, &cf->rw_contexts, list) {
750 if (ctx->thread == current) {
751 found = ctx;
752 break;
753 }
754 }
755 spin_unlock(&cf->rw_contexts_lock);
756 return found;
757}
758
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800759struct ceph_readdir_cache_control {
760 struct page *page;
761 struct dentry **dentries;
762 int index;
763};
Sage Weilde576062009-10-06 11:31:07 -0700764
765/*
Sage Weilde576062009-10-06 11:31:07 -0700766 * A "snap realm" describes a subset of the file hierarchy sharing
767 * the same set of snapshots that apply to it. The realms themselves
768 * are organized into a hierarchy, such that children inherit (some of)
769 * the snapshots of their parents.
770 *
771 * All inodes within the realm that have capabilities are linked into a
772 * per-realm list.
773 */
774struct ceph_snap_realm {
775 u64 ino;
Luis Henriquese3161f12018-01-12 17:19:28 +0000776 struct inode *inode;
Sage Weilde576062009-10-06 11:31:07 -0700777 atomic_t nref;
Sage Weila105f002010-02-15 14:37:55 -0800778 struct rb_node node;
779
Sage Weilde576062009-10-06 11:31:07 -0700780 u64 created, seq;
781 u64 parent_ino;
782 u64 parent_since; /* snapid when our current parent became so */
783
784 u64 *prior_parent_snaps; /* snaps inherited from any parents we */
Alex Elderaa711ee32012-07-13 20:35:11 -0500785 u32 num_prior_parent_snaps; /* had prior to parent_since */
Sage Weilde576062009-10-06 11:31:07 -0700786 u64 *snaps; /* snaps specific to this realm */
Alex Elderaa711ee32012-07-13 20:35:11 -0500787 u32 num_snaps;
Sage Weilde576062009-10-06 11:31:07 -0700788
789 struct ceph_snap_realm *parent;
790 struct list_head children; /* list of child realms */
791 struct list_head child_item;
792
793 struct list_head empty_item; /* if i have ref==0 */
794
Sage Weilae00d4f2010-09-16 16:26:51 -0700795 struct list_head dirty_item; /* if realm needs new context */
796
Sage Weilde576062009-10-06 11:31:07 -0700797 /* the current set of snaps for this realm */
798 struct ceph_snap_context *cached_context;
799
800 struct list_head inodes_with_caps;
801 spinlock_t inodes_with_caps_lock;
802};
803
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700804static inline int default_congestion_kb(void)
Sage Weilde576062009-10-06 11:31:07 -0700805{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700806 int congestion_kb;
807
808 /*
809 * Copied from NFS
810 *
811 * congestion size, scale with available memory.
812 *
813 * 64MB: 8192k
814 * 128MB: 11585k
815 * 256MB: 16384k
816 * 512MB: 23170k
817 * 1GB: 32768k
818 * 2GB: 46340k
819 * 4GB: 65536k
820 * 8GB: 92681k
821 * 16GB: 131072k
822 *
823 * This allows larger machines to have larger/more transfers.
824 * Limit the default to 256M
825 */
Arun KSca79b0c2018-12-28 00:34:29 -0800826 congestion_kb = (16*int_sqrt(totalram_pages())) << (PAGE_SHIFT-10);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700827 if (congestion_kb > 256*1024)
828 congestion_kb = 256*1024;
829
830 return congestion_kb;
Sage Weilde576062009-10-06 11:31:07 -0700831}
832
833
834
835/* snap.c */
836struct ceph_snap_realm *ceph_lookup_snap_realm(struct ceph_mds_client *mdsc,
837 u64 ino);
838extern void ceph_get_snap_realm(struct ceph_mds_client *mdsc,
839 struct ceph_snap_realm *realm);
840extern void ceph_put_snap_realm(struct ceph_mds_client *mdsc,
841 struct ceph_snap_realm *realm);
842extern int ceph_update_snap_trace(struct ceph_mds_client *m,
Yan, Zheng982d6012014-12-23 15:30:54 +0800843 void *p, void *e, bool deletion,
844 struct ceph_snap_realm **realm_ret);
Sage Weilde576062009-10-06 11:31:07 -0700845extern void ceph_handle_snap(struct ceph_mds_client *mdsc,
Sage Weil2600d2d2010-02-22 15:12:16 -0800846 struct ceph_mds_session *session,
Sage Weilde576062009-10-06 11:31:07 -0700847 struct ceph_msg *msg);
Sage Weilfc837c8f2010-04-13 11:41:22 -0700848extern void ceph_queue_cap_snap(struct ceph_inode_info *ci);
Sage Weilde576062009-10-06 11:31:07 -0700849extern int __ceph_finish_cap_snap(struct ceph_inode_info *ci,
850 struct ceph_cap_snap *capsnap);
851extern void ceph_cleanup_empty_realms(struct ceph_mds_client *mdsc);
852
Yan, Zheng75c96272017-12-14 15:11:09 +0800853extern struct ceph_snapid_map *ceph_get_snapid_map(struct ceph_mds_client *mdsc,
854 u64 snap);
855extern void ceph_put_snapid_map(struct ceph_mds_client* mdsc,
856 struct ceph_snapid_map *sm);
857extern void ceph_trim_snapid_map(struct ceph_mds_client *mdsc);
858extern void ceph_cleanup_snapid_map(struct ceph_mds_client *mdsc);
859
860
Sage Weilde576062009-10-06 11:31:07 -0700861/*
862 * a cap_snap is "pending" if it is still awaiting an in-progress
863 * sync write (that may/may not still update size, mtime, etc.).
864 */
865static inline bool __ceph_have_pending_cap_snap(struct ceph_inode_info *ci)
866{
867 return !list_empty(&ci->i_cap_snaps) &&
Yan, Zheng86056092015-05-01 16:57:16 +0800868 list_last_entry(&ci->i_cap_snaps, struct ceph_cap_snap,
869 ci_item)->writing;
Sage Weilde576062009-10-06 11:31:07 -0700870}
871
Sage Weilde576062009-10-06 11:31:07 -0700872/* inode.c */
873extern const struct inode_operations ceph_file_iops;
874
875extern struct inode *ceph_alloc_inode(struct super_block *sb);
876extern void ceph_destroy_inode(struct inode *inode);
Yan, Zheng9f12bd12013-09-20 19:55:31 +0800877extern int ceph_drop_inode(struct inode *inode);
Sage Weilde576062009-10-06 11:31:07 -0700878
879extern struct inode *ceph_get_inode(struct super_block *sb,
880 struct ceph_vino vino);
881extern struct inode *ceph_get_snapdir(struct inode *parent);
882extern int ceph_fill_file_size(struct inode *inode, int issued,
883 u32 truncate_seq, u64 truncate_size, u64 size);
884extern void ceph_fill_file_time(struct inode *inode, int issued,
Arnd Bergmann9bbeab42018-07-13 22:18:36 +0200885 u64 time_warp_seq, struct timespec64 *ctime,
886 struct timespec64 *mtime,
887 struct timespec64 *atime);
Sage Weilde576062009-10-06 11:31:07 -0700888extern int ceph_fill_trace(struct super_block *sb,
Jeff Laytonf5a03b02017-01-31 11:06:13 -0500889 struct ceph_mds_request *req);
Sage Weilde576062009-10-06 11:31:07 -0700890extern int ceph_readdir_prepopulate(struct ceph_mds_request *req,
891 struct ceph_mds_session *session);
892
893extern int ceph_inode_holds_cap(struct inode *inode, int mask);
894
Yan, Zhengefb0ca72017-05-22 12:03:32 +0800895extern bool ceph_inode_set_size(struct inode *inode, loff_t size);
Yan, Zhengb415bf42013-07-02 12:40:19 +0800896extern void __ceph_do_pending_vmtruncate(struct inode *inode);
Sage Weil3c6f6b72010-02-09 15:24:44 -0800897extern void ceph_queue_vmtruncate(struct inode *inode);
898
899extern void ceph_queue_invalidate(struct inode *inode);
900extern void ceph_queue_writeback(struct inode *inode);
Sage Weilde576062009-10-06 11:31:07 -0700901
Yan, Zheng01deead2014-11-14 21:56:29 +0800902extern int __ceph_do_getattr(struct inode *inode, struct page *locked_page,
903 int mask, bool force);
904static inline int ceph_do_getattr(struct inode *inode, int mask, bool force)
905{
906 return __ceph_do_getattr(inode, NULL, mask, force);
907}
Al Viro10556cb22011-06-20 19:28:19 -0400908extern int ceph_permission(struct inode *inode, int mask);
Andreas Gruenbachera26fecc2016-04-14 00:30:16 +0200909extern int __ceph_setattr(struct inode *inode, struct iattr *attr);
Sage Weilde576062009-10-06 11:31:07 -0700910extern int ceph_setattr(struct dentry *dentry, struct iattr *attr);
David Howellsa528d352017-01-31 16:46:22 +0000911extern int ceph_getattr(const struct path *path, struct kstat *stat,
912 u32 request_mask, unsigned int flags);
Sage Weilde576062009-10-06 11:31:07 -0700913
914/* xattr.c */
Andreas Gruenbachera26fecc2016-04-14 00:30:16 +0200915int __ceph_setxattr(struct inode *, const char *, const void *, size_t, int);
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800916ssize_t __ceph_getxattr(struct inode *, const char *, void *, size_t);
Sage Weilde576062009-10-06 11:31:07 -0700917extern ssize_t ceph_listxattr(struct dentry *, char *, size_t);
Sage Weilde576062009-10-06 11:31:07 -0700918extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);
919extern void __ceph_destroy_xattrs(struct ceph_inode_info *ci);
Alex Elder3ce6cd12012-01-23 15:49:28 -0600920extern void __init ceph_xattr_init(void);
921extern void ceph_xattr_exit(void);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800922extern const struct xattr_handler *ceph_xattr_handlers[];
Sage Weilde576062009-10-06 11:31:07 -0700923
Yan, Zheng315f2402016-03-07 10:34:50 +0800924#ifdef CONFIG_SECURITY
925extern bool ceph_security_xattr_deadlock(struct inode *in);
926extern bool ceph_security_xattr_wanted(struct inode *in);
927#else
928static inline bool ceph_security_xattr_deadlock(struct inode *in)
929{
930 return false;
931}
932static inline bool ceph_security_xattr_wanted(struct inode *in)
933{
934 return false;
935}
936#endif
937
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800938/* acl.c */
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800939struct ceph_acls_info {
940 void *default_acl;
941 void *acl;
942 struct ceph_pagelist *pagelist;
943};
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800944
945#ifdef CONFIG_CEPH_FS_POSIX_ACL
946
947struct posix_acl *ceph_get_acl(struct inode *, int);
Sage Weil72466d02014-01-29 06:22:25 -0800948int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800949int ceph_pre_init_acls(struct inode *dir, umode_t *mode,
950 struct ceph_acls_info *info);
951void ceph_init_inode_acls(struct inode *inode, struct ceph_acls_info *info);
952void ceph_release_acls_info(struct ceph_acls_info *info);
Guangliang Zhaoc969d9b2014-02-16 08:35:52 -0800953
954static inline void ceph_forget_all_cached_acls(struct inode *inode)
955{
956 forget_all_cached_acls(inode);
957}
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800958
959#else
960
961#define ceph_get_acl NULL
Sage Weil72466d02014-01-29 06:22:25 -0800962#define ceph_set_acl NULL
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800963
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800964static inline int ceph_pre_init_acls(struct inode *dir, umode_t *mode,
965 struct ceph_acls_info *info)
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800966{
967 return 0;
968}
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800969static inline void ceph_init_inode_acls(struct inode *inode,
970 struct ceph_acls_info *info)
971{
972}
973static inline void ceph_release_acls_info(struct ceph_acls_info *info)
974{
975}
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800976static inline int ceph_acl_chmod(struct dentry *dentry, struct inode *inode)
977{
978 return 0;
979}
980
981static inline void ceph_forget_all_cached_acls(struct inode *inode)
982{
983}
984
985#endif
986
Sage Weilde576062009-10-06 11:31:07 -0700987/* caps.c */
988extern const char *ceph_cap_string(int c);
989extern void ceph_handle_caps(struct ceph_mds_session *session,
990 struct ceph_msg *msg);
Yan, Zhengd9df2782014-04-18 09:57:11 +0800991extern struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc,
992 struct ceph_cap_reservation *ctx);
993extern void ceph_add_cap(struct inode *inode,
994 struct ceph_mds_session *session, u64 cap_id,
995 int fmode, unsigned issued, unsigned wanted,
996 unsigned cap, unsigned seq, u64 realmino, int flags,
997 struct ceph_cap **new_cap);
Yan, Zhenga096b092013-09-22 10:15:58 +0800998extern void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release);
Yan, Zhenge3ec8d62019-01-14 17:21:19 +0800999extern void __ceph_remove_caps(struct inode* inode);
Yehuda Sadeh37151662010-06-17 16:16:12 -07001000extern void ceph_put_cap(struct ceph_mds_client *mdsc,
1001 struct ceph_cap *cap);
Yan, Zheng9215aee2013-11-30 12:47:41 +08001002extern int ceph_is_any_caps(struct inode *inode);
Sage Weilde576062009-10-06 11:31:07 -07001003
Stephen Rothwellf1a3d572010-01-18 11:53:08 +11001004extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc);
Josef Bacik02c24a82011-07-16 20:44:56 -04001005extern int ceph_fsync(struct file *file, loff_t start, loff_t end,
1006 int datasync);
Yan, Zhenge548e9b2015-06-10 15:17:56 +08001007extern void ceph_early_kick_flushing_caps(struct ceph_mds_client *mdsc,
1008 struct ceph_mds_session *session);
Sage Weilde576062009-10-06 11:31:07 -07001009extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc,
1010 struct ceph_mds_session *session);
Greg Farnum2bc50252010-06-30 12:44:34 -07001011extern struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci,
1012 int mds);
Sage Weilde576062009-10-06 11:31:07 -07001013extern int ceph_get_cap_mds(struct inode *inode);
1014extern void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps);
1015extern void ceph_put_cap_refs(struct ceph_inode_info *ci, int had);
1016extern void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
1017 struct ceph_snap_context *snapc);
Yan, Zhenged9b4302016-07-05 21:08:07 +08001018extern void ceph_flush_snaps(struct ceph_inode_info *ci,
1019 struct ceph_mds_session **psession);
Yan, Zhengefb0ca72017-05-22 12:03:32 +08001020extern bool __ceph_should_report_size(struct ceph_inode_info *ci);
Sage Weilde576062009-10-06 11:31:07 -07001021extern void ceph_check_caps(struct ceph_inode_info *ci, int flags,
1022 struct ceph_mds_session *session);
Sage Weilafcdaea2009-10-14 14:27:38 -07001023extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc);
1024extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc);
Zhi Zhang6ef0bc62018-01-24 21:24:33 +08001025extern int ceph_drop_caps_for_unlink(struct inode *inode);
Sage Weilde576062009-10-06 11:31:07 -07001026extern int ceph_encode_inode_release(void **p, struct inode *inode,
1027 int mds, int drop, int unless, int force);
1028extern int ceph_encode_dentry_release(void **p, struct dentry *dn,
Jeff Laytonca6c8ae2016-12-15 08:37:59 -05001029 struct inode *dir,
Sage Weilde576062009-10-06 11:31:07 -07001030 int mds, int drop, int unless);
1031
1032extern int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
Yan, Zheng31c542a2014-11-14 21:41:55 +08001033 loff_t endoff, int *got, struct page **pinned_page);
Yan, Zheng2b1ac852016-10-25 10:51:55 +08001034extern int ceph_try_get_caps(struct ceph_inode_info *ci,
Luis Henriques2ee9dd92018-10-15 16:45:57 +01001035 int need, int want, bool nonblock, int *got);
Sage Weilde576062009-10-06 11:31:07 -07001036
1037/* for counting open files by mode */
Yan, Zheng774a6a12016-06-06 16:01:39 +08001038extern void __ceph_get_fmode(struct ceph_inode_info *ci, int mode);
Sage Weilde576062009-10-06 11:31:07 -07001039extern void ceph_put_fmode(struct ceph_inode_info *ci, int mode);
1040
1041/* addr.c */
1042extern const struct address_space_operations ceph_aops;
1043extern int ceph_mmap(struct file *file, struct vm_area_struct *vma);
Yan, Zheng10183a62015-04-27 15:33:28 +08001044extern int ceph_uninline_data(struct file *filp, struct page *locked_page);
1045extern int ceph_pool_perm_check(struct ceph_inode_info *ci, int need);
1046extern void ceph_pool_perm_destroy(struct ceph_mds_client* mdsc);
Sage Weilde576062009-10-06 11:31:07 -07001047
1048/* file.c */
1049extern const struct file_operations ceph_file_fops;
Alex Elder9e0eb852013-02-06 13:11:38 -06001050
Yan, Zheng77310322016-04-08 15:27:16 +08001051extern int ceph_renew_caps(struct inode *inode);
Sage Weilde576062009-10-06 11:31:07 -07001052extern int ceph_open(struct inode *inode, struct file *file);
Sage Weil5ef50c32012-07-31 11:27:36 -07001053extern int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
Al Viro44907d72018-06-08 13:32:02 -04001054 struct file *file, unsigned flags, umode_t mode);
Sage Weilde576062009-10-06 11:31:07 -07001055extern int ceph_release(struct inode *inode, struct file *filp);
Yan, Zheng31c542a2014-11-14 21:41:55 +08001056extern void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
1057 char *data, size_t len);
Ilya Dryomov55f2a042017-02-13 14:44:19 +01001058
Sage Weilde576062009-10-06 11:31:07 -07001059/* dir.c */
1060extern const struct file_operations ceph_dir_fops;
Yan, Zheng38c48b52015-01-14 13:46:04 +08001061extern const struct file_operations ceph_snapdir_fops;
Sage Weilde576062009-10-06 11:31:07 -07001062extern const struct inode_operations ceph_dir_iops;
Yan, Zheng38c48b52015-01-14 13:46:04 +08001063extern const struct inode_operations ceph_snapdir_iops;
Al Viro18fc8ab2016-10-28 21:52:50 -04001064extern const struct dentry_operations ceph_dentry_ops;
Sage Weilde576062009-10-06 11:31:07 -07001065
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +08001066extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order);
Sage Weilde576062009-10-06 11:31:07 -07001067extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
Sage Weil468640e2011-07-26 11:28:11 -07001068extern int ceph_handle_snapdir(struct ceph_mds_request *req,
1069 struct dentry *dentry, int err);
Sage Weilde576062009-10-06 11:31:07 -07001070extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
1071 struct dentry *dentry, int err);
1072
Yan, Zheng37c4efc2019-01-31 16:55:51 +08001073extern void __ceph_dentry_lease_touch(struct ceph_dentry_info *di);
1074extern void __ceph_dentry_dir_lease_touch(struct ceph_dentry_info *di);
Sage Weil81a6cf22010-05-14 09:35:38 -07001075extern void ceph_invalidate_dentry_lease(struct dentry *dentry);
Yan, Zheng37c4efc2019-01-31 16:55:51 +08001076extern int ceph_trim_dentries(struct ceph_mds_client *mdsc);
Sage Weile5f86dc2011-07-26 11:30:55 -07001077extern unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn);
Yan, Zhengfdd4e152015-06-16 20:48:56 +08001078extern void ceph_readdir_cache_release(struct ceph_readdir_cache_control *ctl);
Sage Weilde576062009-10-06 11:31:07 -07001079
Sage Weilde576062009-10-06 11:31:07 -07001080/* ioctl.c */
1081extern long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1082
1083/* export.c */
1084extern const struct export_operations ceph_export_ops;
1085
Greg Farnum40819f62010-08-02 15:34:23 -07001086/* locks.c */
Yan, Zhengeb13e832014-03-09 23:16:40 +08001087extern __init void ceph_flock_init(void);
Greg Farnum40819f62010-08-02 15:34:23 -07001088extern int ceph_lock(struct file *file, int cmd, struct file_lock *fl);
1089extern int ceph_flock(struct file *file, int cmd, struct file_lock *fl);
1090extern void ceph_count_locks(struct inode *inode, int *p_num, int *f_num);
Jim Schutt39be95e2013-05-15 13:03:35 -05001091extern int ceph_encode_locks_to_buffer(struct inode *inode,
1092 struct ceph_filelock *flocks,
1093 int num_fcntl_locks,
1094 int num_flock_locks);
1095extern int ceph_locks_to_pagelist(struct ceph_filelock *flocks,
1096 struct ceph_pagelist *pagelist,
1097 int num_fcntl_locks, int num_flock_locks);
Greg Farnum40819f62010-08-02 15:34:23 -07001098
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001099/* debugfs.c */
1100extern int ceph_fs_debugfs_init(struct ceph_fs_client *client);
1101extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);
1102
Luis Henriquesfb18a572018-01-05 10:47:18 +00001103/* quota.c */
Luis Henriquesd557c482018-01-12 17:19:29 +00001104static inline bool __ceph_has_any_quota(struct ceph_inode_info *ci)
1105{
1106 return ci->i_max_files || ci->i_max_bytes;
1107}
1108
1109extern void ceph_adjust_quota_realms_count(struct inode *inode, bool inc);
1110
1111static inline void __ceph_update_quota(struct ceph_inode_info *ci,
1112 u64 max_bytes, u64 max_files)
1113{
1114 bool had_quota, has_quota;
1115 had_quota = __ceph_has_any_quota(ci);
1116 ci->i_max_bytes = max_bytes;
1117 ci->i_max_files = max_files;
1118 has_quota = __ceph_has_any_quota(ci);
1119
1120 if (had_quota != has_quota)
1121 ceph_adjust_quota_realms_count(&ci->vfs_inode, has_quota);
1122}
1123
Luis Henriquesfb18a572018-01-05 10:47:18 +00001124extern void ceph_handle_quota(struct ceph_mds_client *mdsc,
1125 struct ceph_mds_session *session,
1126 struct ceph_msg *msg);
Luis Henriquesb7a29212018-01-05 10:47:19 +00001127extern bool ceph_quota_is_max_files_exceeded(struct inode *inode);
Luis Henriquescafe21a2018-01-05 10:47:20 +00001128extern bool ceph_quota_is_same_realm(struct inode *old, struct inode *new);
Luis Henriques2b838452018-01-05 10:47:21 +00001129extern bool ceph_quota_is_max_bytes_exceeded(struct inode *inode,
1130 loff_t newlen);
Luis Henriques1ab302a2018-01-05 10:47:22 +00001131extern bool ceph_quota_is_max_bytes_approaching(struct inode *inode,
1132 loff_t newlen);
Luis Henriques9122eed2018-01-31 10:53:13 +00001133extern bool ceph_quota_update_statfs(struct ceph_fs_client *fsc,
1134 struct kstatfs *buf);
Luis Henriquesfb18a572018-01-05 10:47:18 +00001135
Sage Weilde576062009-10-06 11:31:07 -07001136#endif /* _FS_CEPH_SUPER_H */