blob: 7d9851cd51bb4f96cfefee85c6a5ff180d956031 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002#include <linux/ceph/ceph_debug.h>
Sage Weil2817b002009-10-06 11:31:08 -07003
4#include <linux/spinlock.h>
5#include <linux/fs_struct.h>
6#include <linux/namei.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Sage Weil2817b002009-10-06 11:31:08 -07008#include <linux/sched.h>
Andreas Gruenbacher2cdeb1e2016-04-14 00:30:17 +02009#include <linux/xattr.h>
Sage Weil2817b002009-10-06 11:31:08 -070010
11#include "super.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070012#include "mds_client.h"
Sage Weil2817b002009-10-06 11:31:08 -070013
14/*
15 * Directory operations: readdir, lookup, create, link, unlink,
16 * rename, etc.
17 */
18
19/*
20 * Ceph MDS operations are specified in terms of a base ino and
21 * relative path. Thus, the client can specify an operation on a
22 * specific inode (e.g., a getattr due to fstat(2)), or as a path
23 * relative to, say, the root directory.
24 *
25 * Normally, we limit ourselves to strict inode ops (no path component)
26 * or dentry operations (a single path component relative to an ino). The
27 * exception to this is open_root_dentry(), which will open the mount
28 * point by name.
29 */
30
Sage Weil52dfb8a2010-08-03 10:25:30 -070031const struct dentry_operations ceph_dentry_ops;
Sage Weil2817b002009-10-06 11:31:08 -070032
33/*
34 * Initialize ceph dentry state.
35 */
Al Viroad5cb122016-10-28 22:05:13 -040036static int ceph_d_init(struct dentry *dentry)
Sage Weil2817b002009-10-06 11:31:08 -070037{
38 struct ceph_dentry_info *di;
39
Geliang Tang99ec2692016-03-13 15:26:29 +080040 di = kmem_cache_zalloc(ceph_dentry_cachep, GFP_KERNEL);
Sage Weil2817b002009-10-06 11:31:08 -070041 if (!di)
42 return -ENOMEM; /* oh well */
43
Sage Weil2817b002009-10-06 11:31:08 -070044 di->dentry = dentry;
45 di->lease_session = NULL;
Miklos Szeredi9b16f03c2016-06-22 16:35:04 +020046 di->time = jiffies;
Sage Weil48d0cbd2011-07-26 11:30:15 -070047 dentry->d_fsdata = di;
Sage Weil2817b002009-10-06 11:31:08 -070048 ceph_dentry_lru_add(dentry);
Sage Weil2817b002009-10-06 11:31:08 -070049 return 0;
50}
51
Sage Weil2817b002009-10-06 11:31:08 -070052/*
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +080053 * for f_pos for readdir:
54 * - hash order:
55 * (0xff << 52) | ((24 bits hash) << 28) |
56 * (the nth entry has hash collision);
57 * - frag+name order;
58 * ((frag value) << 28) | (the nth entry in frag);
Sage Weil2817b002009-10-06 11:31:08 -070059 */
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +080060#define OFFSET_BITS 28
61#define OFFSET_MASK ((1 << OFFSET_BITS) - 1)
62#define HASH_ORDER (0xffull << (OFFSET_BITS + 24))
63loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order)
64{
65 loff_t fpos = ((loff_t)high << 28) | (loff_t)off;
66 if (hash_order)
67 fpos |= HASH_ORDER;
68 return fpos;
69}
70
71static bool is_hash_order(loff_t p)
72{
73 return (p & HASH_ORDER) == HASH_ORDER;
74}
75
Sage Weil2817b002009-10-06 11:31:08 -070076static unsigned fpos_frag(loff_t p)
77{
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +080078 return p >> OFFSET_BITS;
Sage Weil2817b002009-10-06 11:31:08 -070079}
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +080080
81static unsigned fpos_hash(loff_t p)
82{
83 return ceph_frag_value(fpos_frag(p));
84}
85
Sage Weil2817b002009-10-06 11:31:08 -070086static unsigned fpos_off(loff_t p)
87{
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +080088 return p & OFFSET_MASK;
Sage Weil2817b002009-10-06 11:31:08 -070089}
90
Yan, Zheng4d5f5df2014-02-13 19:40:26 +080091static int fpos_cmp(loff_t l, loff_t r)
92{
93 int v = ceph_frag_compare(fpos_frag(l), fpos_frag(r));
94 if (v)
95 return v;
96 return (int)(fpos_off(l) - fpos_off(r));
97}
98
Sage Weil2817b002009-10-06 11:31:08 -070099/*
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800100 * make note of the last dentry we read, so we can
101 * continue at the same lexicographical point,
102 * regardless of what dir changes take place on the
103 * server.
104 */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800105static int note_last_dentry(struct ceph_dir_file_info *dfi, const char *name,
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800106 int len, unsigned next_offset)
107{
108 char *buf = kmalloc(len+1, GFP_KERNEL);
109 if (!buf)
110 return -ENOMEM;
Chengguang Xubb48bd42018-03-13 10:42:44 +0800111 kfree(dfi->last_name);
112 dfi->last_name = buf;
113 memcpy(dfi->last_name, name, len);
114 dfi->last_name[len] = 0;
115 dfi->next_offset = next_offset;
116 dout("note_last_dentry '%s'\n", dfi->last_name);
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800117 return 0;
118}
119
Yan, Zhengc530cd22016-04-28 17:43:35 +0800120
121static struct dentry *
122__dcache_find_get_entry(struct dentry *parent, u64 idx,
123 struct ceph_readdir_cache_control *cache_ctl)
124{
125 struct inode *dir = d_inode(parent);
126 struct dentry *dentry;
127 unsigned idx_mask = (PAGE_SIZE / sizeof(struct dentry *)) - 1;
128 loff_t ptr_pos = idx * sizeof(struct dentry *);
129 pgoff_t ptr_pgoff = ptr_pos >> PAGE_SHIFT;
130
131 if (ptr_pos >= i_size_read(dir))
132 return NULL;
133
134 if (!cache_ctl->page || ptr_pgoff != page_index(cache_ctl->page)) {
135 ceph_readdir_cache_release(cache_ctl);
136 cache_ctl->page = find_lock_page(&dir->i_data, ptr_pgoff);
137 if (!cache_ctl->page) {
138 dout(" page %lu not found\n", ptr_pgoff);
139 return ERR_PTR(-EAGAIN);
140 }
141 /* reading/filling the cache are serialized by
142 i_mutex, no need to use page lock */
143 unlock_page(cache_ctl->page);
144 cache_ctl->dentries = kmap(cache_ctl->page);
145 }
146
147 cache_ctl->index = idx & idx_mask;
148
149 rcu_read_lock();
150 spin_lock(&parent->d_lock);
151 /* check i_size again here, because empty directory can be
152 * marked as complete while not holding the i_mutex. */
153 if (ceph_dir_is_complete_ordered(dir) && ptr_pos < i_size_read(dir))
154 dentry = cache_ctl->dentries[cache_ctl->index];
155 else
156 dentry = NULL;
157 spin_unlock(&parent->d_lock);
158 if (dentry && !lockref_get_not_dead(&dentry->d_lockref))
159 dentry = NULL;
160 rcu_read_unlock();
161 return dentry ? : ERR_PTR(-EAGAIN);
162}
163
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800164/*
Sage Weil2817b002009-10-06 11:31:08 -0700165 * When possible, we try to satisfy a readdir by peeking at the
166 * dcache. We make this work by carefully ordering dentries on
Al Viro946e51f2014-10-26 19:19:16 -0400167 * d_child when we initially get results back from the MDS, and
Sage Weil2817b002009-10-06 11:31:08 -0700168 * falling back to a "normal" sync readdir if any dentries in the dir
169 * are dropped.
170 *
Yan, Zheng2f276c52013-03-13 19:44:32 +0800171 * Complete dir indicates that we have all dentries in the dir. It is
Sage Weil2817b002009-10-06 11:31:08 -0700172 * defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by
173 * the MDS if/when the directory is modified).
174 */
Yan, Zhenga30be7c2014-04-06 14:10:04 +0800175static int __dcache_readdir(struct file *file, struct dir_context *ctx,
Yan, Zheng97aeb6b2017-11-27 10:47:46 +0800176 int shared_gen)
Sage Weil2817b002009-10-06 11:31:08 -0700177{
Chengguang Xubb48bd42018-03-13 10:42:44 +0800178 struct ceph_dir_file_info *dfi = file->private_data;
Al Virob5830432014-10-31 01:22:04 -0400179 struct dentry *parent = file->f_path.dentry;
David Howells2b0143b2015-03-17 22:25:59 +0000180 struct inode *dir = d_inode(parent);
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800181 struct dentry *dentry, *last = NULL;
Sage Weil2817b002009-10-06 11:31:08 -0700182 struct ceph_dentry_info *di;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800183 struct ceph_readdir_cache_control cache_ctl = {};
Yan, Zhengc530cd22016-04-28 17:43:35 +0800184 u64 idx = 0;
185 int err = 0;
Sage Weil2817b002009-10-06 11:31:08 -0700186
Yan, Zheng97aeb6b2017-11-27 10:47:46 +0800187 dout("__dcache_readdir %p v%u at %llx\n", dir, (unsigned)shared_gen, ctx->pos);
Sage Weil2817b002009-10-06 11:31:08 -0700188
Yan, Zhengc530cd22016-04-28 17:43:35 +0800189 /* search start position */
190 if (ctx->pos > 2) {
191 u64 count = div_u64(i_size_read(dir), sizeof(struct dentry *));
192 while (count > 0) {
193 u64 step = count >> 1;
194 dentry = __dcache_find_get_entry(parent, idx + step,
195 &cache_ctl);
196 if (!dentry) {
197 /* use linar search */
198 idx = 0;
199 break;
200 }
201 if (IS_ERR(dentry)) {
202 err = PTR_ERR(dentry);
203 goto out;
204 }
205 di = ceph_dentry(dentry);
206 spin_lock(&dentry->d_lock);
207 if (fpos_cmp(di->offset, ctx->pos) < 0) {
208 idx += step + 1;
209 count -= step + 1;
210 } else {
211 count = step;
212 }
213 spin_unlock(&dentry->d_lock);
214 dput(dentry);
215 }
216
217 dout("__dcache_readdir %p cache idx %llu\n", dir, idx);
Sage Weil2817b002009-10-06 11:31:08 -0700218 }
219
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800220
Yan, Zhengc530cd22016-04-28 17:43:35 +0800221 for (;;) {
222 bool emit_dentry = false;
223 dentry = __dcache_find_get_entry(parent, idx++, &cache_ctl);
224 if (!dentry) {
Chengguang Xubb48bd42018-03-13 10:42:44 +0800225 dfi->file_info.flags |= CEPH_F_ATEND;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800226 err = 0;
227 break;
Sage Weil2817b002009-10-06 11:31:08 -0700228 }
Yan, Zhengc530cd22016-04-28 17:43:35 +0800229 if (IS_ERR(dentry)) {
230 err = PTR_ERR(dentry);
231 goto out;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800232 }
233
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800234 spin_lock(&dentry->d_lock);
Yan, Zheng5495c2d2017-11-27 11:23:48 +0800235 di = ceph_dentry(dentry);
236 if (d_unhashed(dentry) ||
237 d_really_is_negative(dentry) ||
238 di->lease_shared_gen != shared_gen) {
239 spin_unlock(&dentry->d_lock);
240 dput(dentry);
241 err = -EAGAIN;
242 goto out;
243 }
244 if (fpos_cmp(ctx->pos, di->offset) <= 0) {
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800245 emit_dentry = true;
Sage Weil2817b002009-10-06 11:31:08 -0700246 }
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800247 spin_unlock(&dentry->d_lock);
248
249 if (emit_dentry) {
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800250 dout(" %llx dentry %p %pd %p\n", di->offset,
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800251 dentry, dentry, d_inode(dentry));
252 ctx->pos = di->offset;
253 if (!dir_emit(ctx, dentry->d_name.name,
254 dentry->d_name.len,
255 ceph_translate_ino(dentry->d_sb,
256 d_inode(dentry)->i_ino),
257 d_inode(dentry)->i_mode >> 12)) {
258 dput(dentry);
259 err = 0;
260 break;
261 }
262 ctx->pos++;
263
264 if (last)
265 dput(last);
266 last = dentry;
267 } else {
268 dput(dentry);
269 }
Sage Weil2817b002009-10-06 11:31:08 -0700270 }
Yan, Zhengc530cd22016-04-28 17:43:35 +0800271out:
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800272 ceph_readdir_cache_release(&cache_ctl);
273 if (last) {
274 int ret;
275 di = ceph_dentry(last);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800276 ret = note_last_dentry(dfi, last->d_name.name, last->d_name.len,
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800277 fpos_off(di->offset) + 1);
278 if (ret < 0)
279 err = ret;
Al Viro77acfa22013-05-17 16:52:26 -0400280 dput(last);
Yan, Zheng84583cfb2017-07-06 11:12:21 +0800281 /* last_name no longer match cache index */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800282 if (dfi->readdir_cache_idx >= 0) {
283 dfi->readdir_cache_idx = -1;
284 dfi->dir_release_count = 0;
Yan, Zheng84583cfb2017-07-06 11:12:21 +0800285 }
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800286 }
Sage Weil2817b002009-10-06 11:31:08 -0700287 return err;
288}
289
Chengguang Xubb48bd42018-03-13 10:42:44 +0800290static bool need_send_readdir(struct ceph_dir_file_info *dfi, loff_t pos)
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800291{
Chengguang Xubb48bd42018-03-13 10:42:44 +0800292 if (!dfi->last_readdir)
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800293 return true;
294 if (is_hash_order(pos))
Chengguang Xubb48bd42018-03-13 10:42:44 +0800295 return !ceph_frag_contains_value(dfi->frag, fpos_hash(pos));
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800296 else
Chengguang Xubb48bd42018-03-13 10:42:44 +0800297 return dfi->frag != fpos_frag(pos);
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800298}
299
Al Viro77acfa22013-05-17 16:52:26 -0400300static int ceph_readdir(struct file *file, struct dir_context *ctx)
Sage Weil2817b002009-10-06 11:31:08 -0700301{
Chengguang Xubb48bd42018-03-13 10:42:44 +0800302 struct ceph_dir_file_info *dfi = file->private_data;
Al Viro77acfa22013-05-17 16:52:26 -0400303 struct inode *inode = file_inode(file);
Sage Weil2817b002009-10-06 11:31:08 -0700304 struct ceph_inode_info *ci = ceph_inode(inode);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700305 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
306 struct ceph_mds_client *mdsc = fsc->mdsc;
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800307 int i;
Sage Weil2817b002009-10-06 11:31:08 -0700308 int err;
Yan, Zhengb50c2de2017-04-24 11:56:50 +0800309 unsigned frag = -1;
Sage Weil2817b002009-10-06 11:31:08 -0700310 struct ceph_mds_reply_info_parsed *rinfo;
Sage Weil2817b002009-10-06 11:31:08 -0700311
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800312 dout("readdir %p file %p pos %llx\n", inode, file, ctx->pos);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800313 if (dfi->file_info.flags & CEPH_F_ATEND)
Sage Weil2817b002009-10-06 11:31:08 -0700314 return 0;
315
316 /* always start with . and .. */
Al Viro77acfa22013-05-17 16:52:26 -0400317 if (ctx->pos == 0) {
Sage Weil2817b002009-10-06 11:31:08 -0700318 dout("readdir off 0 -> '.'\n");
Al Viro77acfa22013-05-17 16:52:26 -0400319 if (!dir_emit(ctx, ".", 1,
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800320 ceph_translate_ino(inode->i_sb, inode->i_ino),
Al Viro77acfa22013-05-17 16:52:26 -0400321 inode->i_mode >> 12))
Sage Weil2817b002009-10-06 11:31:08 -0700322 return 0;
Al Viro77acfa22013-05-17 16:52:26 -0400323 ctx->pos = 1;
Sage Weil2817b002009-10-06 11:31:08 -0700324 }
Al Viro77acfa22013-05-17 16:52:26 -0400325 if (ctx->pos == 1) {
Al Virob5830432014-10-31 01:22:04 -0400326 ino_t ino = parent_ino(file->f_path.dentry);
Sage Weil2817b002009-10-06 11:31:08 -0700327 dout("readdir off 1 -> '..'\n");
Al Viro77acfa22013-05-17 16:52:26 -0400328 if (!dir_emit(ctx, "..", 2,
Yehuda Sadehad1fee92011-01-21 16:44:03 -0800329 ceph_translate_ino(inode->i_sb, ino),
Al Viro77acfa22013-05-17 16:52:26 -0400330 inode->i_mode >> 12))
Sage Weil2817b002009-10-06 11:31:08 -0700331 return 0;
Al Viro77acfa22013-05-17 16:52:26 -0400332 ctx->pos = 2;
Sage Weil2817b002009-10-06 11:31:08 -0700333 }
334
335 /* can we use the dcache? */
Sage Weilbe655592011-11-30 09:47:09 -0800336 spin_lock(&ci->i_ceph_lock);
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800337 if (ceph_test_mount_opt(fsc, DCACHE) &&
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700338 !ceph_test_mount_opt(fsc, NOASYNCREADDIR) &&
Sage Weila0dff782010-07-22 13:47:21 -0700339 ceph_snap(inode) != CEPH_SNAPDIR &&
Yan, Zheng70db4f32014-10-21 18:09:56 -0700340 __ceph_dir_is_complete_ordered(ci) &&
Sage Weil2817b002009-10-06 11:31:08 -0700341 __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) {
Yan, Zheng97aeb6b2017-11-27 10:47:46 +0800342 int shared_gen = atomic_read(&ci->i_shared_gen);
Sage Weilbe655592011-11-30 09:47:09 -0800343 spin_unlock(&ci->i_ceph_lock);
Yan, Zhenga30be7c2014-04-06 14:10:04 +0800344 err = __dcache_readdir(file, ctx, shared_gen);
Sage Weilefa4c122010-10-18 14:04:31 -0700345 if (err != -EAGAIN)
Sage Weil2817b002009-10-06 11:31:08 -0700346 return err;
Sage Weilefa4c122010-10-18 14:04:31 -0700347 } else {
Sage Weilbe655592011-11-30 09:47:09 -0800348 spin_unlock(&ci->i_ceph_lock);
Sage Weil2817b002009-10-06 11:31:08 -0700349 }
Sage Weil2817b002009-10-06 11:31:08 -0700350
351 /* proceed with a normal readdir */
Sage Weil2817b002009-10-06 11:31:08 -0700352more:
353 /* do we have the correct frag content buffered? */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800354 if (need_send_readdir(dfi, ctx->pos)) {
Sage Weil2817b002009-10-06 11:31:08 -0700355 struct ceph_mds_request *req;
356 int op = ceph_snap(inode) == CEPH_SNAPDIR ?
357 CEPH_MDS_OP_LSSNAP : CEPH_MDS_OP_READDIR;
358
359 /* discard old result, if any */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800360 if (dfi->last_readdir) {
361 ceph_mdsc_put_request(dfi->last_readdir);
362 dfi->last_readdir = NULL;
Sage Weil393f6622010-03-10 12:03:32 -0800363 }
Sage Weil2817b002009-10-06 11:31:08 -0700364
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800365 if (is_hash_order(ctx->pos)) {
Yan, Zhengb50c2de2017-04-24 11:56:50 +0800366 /* fragtree isn't always accurate. choose frag
367 * based on previous reply when possible. */
368 if (frag == (unsigned)-1)
369 frag = ceph_choose_frag(ci, fpos_hash(ctx->pos),
370 NULL, NULL);
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800371 } else {
372 frag = fpos_frag(ctx->pos);
373 }
374
Sage Weil2817b002009-10-06 11:31:08 -0700375 dout("readdir fetching %llx.%llx frag %x offset '%s'\n",
Chengguang Xubb48bd42018-03-13 10:42:44 +0800376 ceph_vinop(inode), frag, dfi->last_name);
Sage Weil2817b002009-10-06 11:31:08 -0700377 req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
378 if (IS_ERR(req))
379 return PTR_ERR(req);
Yan, Zheng54008392014-03-29 13:41:15 +0800380 err = ceph_alloc_readdir_reply_buffer(req, inode);
381 if (err) {
382 ceph_mdsc_put_request(req);
383 return err;
384 }
Sage Weil2817b002009-10-06 11:31:08 -0700385 /* hints to request -> mds selection code */
386 req->r_direct_mode = USE_AUTH_MDS;
Yan, Zheng5d37ca12017-07-26 12:48:08 +0800387 if (op == CEPH_MDS_OP_READDIR) {
388 req->r_direct_hash = ceph_frag_value(frag);
389 __set_bit(CEPH_MDS_R_DIRECT_IS_HASH, &req->r_req_flags);
Yan, Zheng87c91a92017-11-23 18:28:16 +0800390 req->r_inode_drop = CEPH_CAP_FILE_EXCL;
Yan, Zheng5d37ca12017-07-26 12:48:08 +0800391 }
Chengguang Xubb48bd42018-03-13 10:42:44 +0800392 if (dfi->last_name) {
393 req->r_path2 = kstrdup(dfi->last_name, GFP_KERNEL);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400394 if (!req->r_path2) {
395 ceph_mdsc_put_request(req);
396 return -ENOMEM;
397 }
Yan, Zheng79162542017-04-05 12:54:05 -0400398 } else if (is_hash_order(ctx->pos)) {
399 req->r_args.readdir.offset_hash =
400 cpu_to_le32(fpos_hash(ctx->pos));
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400401 }
Yan, Zheng79162542017-04-05 12:54:05 -0400402
Chengguang Xubb48bd42018-03-13 10:42:44 +0800403 req->r_dir_release_cnt = dfi->dir_release_count;
404 req->r_dir_ordered_cnt = dfi->dir_ordered_count;
405 req->r_readdir_cache_idx = dfi->readdir_cache_idx;
406 req->r_readdir_offset = dfi->next_offset;
Sage Weil2817b002009-10-06 11:31:08 -0700407 req->r_args.readdir.frag = cpu_to_le32(frag);
Yan, Zheng956d39d2016-04-27 17:48:30 +0800408 req->r_args.readdir.flags =
409 cpu_to_le16(CEPH_READDIR_REPLY_BITFLAGS);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400410
411 req->r_inode = inode;
412 ihold(inode);
413 req->r_dentry = dget(file->f_path.dentry);
Sage Weil2817b002009-10-06 11:31:08 -0700414 err = ceph_mdsc_do_request(mdsc, NULL, req);
415 if (err < 0) {
416 ceph_mdsc_put_request(req);
417 return err;
418 }
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800419 dout("readdir got and parsed readdir result=%d on "
420 "frag %x, end=%d, complete=%d, hash_order=%d\n",
421 err, frag,
Sage Weil2817b002009-10-06 11:31:08 -0700422 (int)req->r_reply_info.dir_end,
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800423 (int)req->r_reply_info.dir_complete,
424 (int)req->r_reply_info.hash_order);
Sage Weil2817b002009-10-06 11:31:08 -0700425
Yan, Zheng81c6aea2013-09-18 09:44:13 +0800426 rinfo = &req->r_reply_info;
427 if (le32_to_cpu(rinfo->dir_dir->frag) != frag) {
428 frag = le32_to_cpu(rinfo->dir_dir->frag);
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800429 if (!rinfo->hash_order) {
Chengguang Xubb48bd42018-03-13 10:42:44 +0800430 dfi->next_offset = req->r_readdir_offset;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800431 /* adjust ctx->pos to beginning of frag */
432 ctx->pos = ceph_make_fpos(frag,
Chengguang Xubb48bd42018-03-13 10:42:44 +0800433 dfi->next_offset,
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800434 false);
435 }
Yan, Zheng81c6aea2013-09-18 09:44:13 +0800436 }
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800437
Chengguang Xubb48bd42018-03-13 10:42:44 +0800438 dfi->frag = frag;
439 dfi->last_readdir = req;
Sage Weil2817b002009-10-06 11:31:08 -0700440
Jeff Laytonbc2de10d2017-02-01 13:49:09 -0500441 if (test_bit(CEPH_MDS_R_DID_PREPOPULATE, &req->r_req_flags)) {
Chengguang Xubb48bd42018-03-13 10:42:44 +0800442 dfi->readdir_cache_idx = req->r_readdir_cache_idx;
443 if (dfi->readdir_cache_idx < 0) {
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800444 /* preclude from marking dir ordered */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800445 dfi->dir_ordered_count = 0;
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800446 } else if (ceph_frag_is_leftmost(frag) &&
Chengguang Xubb48bd42018-03-13 10:42:44 +0800447 dfi->next_offset == 2) {
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800448 /* note dir version at start of readdir so
449 * we can tell if any dentries get dropped */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800450 dfi->dir_release_count = req->r_dir_release_cnt;
451 dfi->dir_ordered_count = req->r_dir_ordered_cnt;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800452 }
453 } else {
Chengguang Xu4c069a52018-01-30 16:29:17 +0800454 dout("readdir !did_prepopulate\n");
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800455 /* disable readdir cache */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800456 dfi->readdir_cache_idx = -1;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800457 /* preclude from marking dir complete */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800458 dfi->dir_release_count = 0;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800459 }
460
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800461 /* note next offset and last dentry name */
462 if (rinfo->dir_nr > 0) {
Yan, Zheng2a5beea2016-04-28 09:37:39 +0800463 struct ceph_mds_reply_dir_entry *rde =
464 rinfo->dir_entries + (rinfo->dir_nr-1);
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800465 unsigned next_offset = req->r_reply_info.dir_end ?
466 2 : (fpos_off(rde->offset) + 1);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800467 err = note_last_dentry(dfi, rde->name, rde->name_len,
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800468 next_offset);
Sage Weil2817b002009-10-06 11:31:08 -0700469 if (err)
470 return err;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800471 } else if (req->r_reply_info.dir_end) {
Chengguang Xubb48bd42018-03-13 10:42:44 +0800472 dfi->next_offset = 2;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800473 /* keep last name */
Sage Weil2817b002009-10-06 11:31:08 -0700474 }
475 }
476
Chengguang Xubb48bd42018-03-13 10:42:44 +0800477 rinfo = &dfi->last_readdir->r_reply_info;
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800478 dout("readdir frag %x num %d pos %llx chunk first %llx\n",
Chengguang Xubb48bd42018-03-13 10:42:44 +0800479 dfi->frag, rinfo->dir_nr, ctx->pos,
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800480 rinfo->dir_nr ? rinfo->dir_entries[0].offset : 0LL);
Al Viro77acfa22013-05-17 16:52:26 -0400481
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800482 i = 0;
483 /* search start position */
484 if (rinfo->dir_nr > 0) {
485 int step, nr = rinfo->dir_nr;
486 while (nr > 0) {
487 step = nr >> 1;
488 if (rinfo->dir_entries[i + step].offset < ctx->pos) {
489 i += step + 1;
490 nr -= step + 1;
491 } else {
492 nr = step;
493 }
494 }
495 }
496 for (; i < rinfo->dir_nr; i++) {
497 struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i;
Sage Weil3105c192010-11-18 09:15:07 -0800498 struct ceph_vino vino;
499 ino_t ino;
Yan, Zhengb50c2de2017-04-24 11:56:50 +0800500 u32 ftype;
Sage Weil3105c192010-11-18 09:15:07 -0800501
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800502 BUG_ON(rde->offset < ctx->pos);
503
504 ctx->pos = rde->offset;
505 dout("readdir (%d/%d) -> %llx '%.*s' %p\n",
506 i, rinfo->dir_nr, ctx->pos,
Yan, Zheng2a5beea2016-04-28 09:37:39 +0800507 rde->name_len, rde->name, &rde->inode.in);
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800508
Yan, Zheng2a5beea2016-04-28 09:37:39 +0800509 BUG_ON(!rde->inode.in);
510 ftype = le32_to_cpu(rde->inode.in->mode) >> 12;
511 vino.ino = le64_to_cpu(rde->inode.in->ino);
512 vino.snap = le64_to_cpu(rde->inode.in->snapid);
Sage Weil3105c192010-11-18 09:15:07 -0800513 ino = ceph_vino_to_ino(vino);
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800514
Yan, Zheng2a5beea2016-04-28 09:37:39 +0800515 if (!dir_emit(ctx, rde->name, rde->name_len,
516 ceph_translate_ino(inode->i_sb, ino), ftype)) {
Sage Weil2817b002009-10-06 11:31:08 -0700517 dout("filldir stopping us...\n");
518 return 0;
519 }
Al Viro77acfa22013-05-17 16:52:26 -0400520 ctx->pos++;
Sage Weil2817b002009-10-06 11:31:08 -0700521 }
522
Chengguang Xubb48bd42018-03-13 10:42:44 +0800523 ceph_mdsc_put_request(dfi->last_readdir);
524 dfi->last_readdir = NULL;
Yan, Zhengb50c2de2017-04-24 11:56:50 +0800525
Chengguang Xubb48bd42018-03-13 10:42:44 +0800526 if (dfi->next_offset > 2) {
527 frag = dfi->frag;
Sage Weil2817b002009-10-06 11:31:08 -0700528 goto more;
529 }
530
531 /* more frags? */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800532 if (!ceph_frag_is_rightmost(dfi->frag)) {
533 frag = ceph_frag_next(dfi->frag);
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800534 if (is_hash_order(ctx->pos)) {
535 loff_t new_pos = ceph_make_fpos(ceph_frag_value(frag),
Chengguang Xubb48bd42018-03-13 10:42:44 +0800536 dfi->next_offset, true);
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800537 if (new_pos > ctx->pos)
538 ctx->pos = new_pos;
539 /* keep last_name */
540 } else {
Chengguang Xubb48bd42018-03-13 10:42:44 +0800541 ctx->pos = ceph_make_fpos(frag, dfi->next_offset,
542 false);
543 kfree(dfi->last_name);
544 dfi->last_name = NULL;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800545 }
Sage Weil2817b002009-10-06 11:31:08 -0700546 dout("readdir next frag is %x\n", frag);
547 goto more;
548 }
Chengguang Xubb48bd42018-03-13 10:42:44 +0800549 dfi->file_info.flags |= CEPH_F_ATEND;
Sage Weil2817b002009-10-06 11:31:08 -0700550
551 /*
552 * if dir_release_count still matches the dir, no dentries
553 * were released during the whole readdir, and we should have
554 * the complete dir contents in our cache.
555 */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800556 if (atomic64_read(&ci->i_release_count) ==
557 dfi->dir_release_count) {
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800558 spin_lock(&ci->i_ceph_lock);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800559 if (dfi->dir_ordered_count ==
560 atomic64_read(&ci->i_ordered_count)) {
Yan, Zheng70db4f32014-10-21 18:09:56 -0700561 dout(" marking %p complete and ordered\n", inode);
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800562 /* use i_size to track number of entries in
563 * readdir cache */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800564 BUG_ON(dfi->readdir_cache_idx < 0);
565 i_size_write(inode, dfi->readdir_cache_idx *
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800566 sizeof(struct dentry*));
567 } else {
Yan, Zheng70db4f32014-10-21 18:09:56 -0700568 dout(" marking %p complete\n", inode);
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800569 }
Chengguang Xubb48bd42018-03-13 10:42:44 +0800570 __ceph_dir_set_complete(ci, dfi->dir_release_count,
571 dfi->dir_ordered_count);
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800572 spin_unlock(&ci->i_ceph_lock);
Sage Weil2817b002009-10-06 11:31:08 -0700573 }
Sage Weil2817b002009-10-06 11:31:08 -0700574
Al Viro77acfa22013-05-17 16:52:26 -0400575 dout("readdir %p file %p done.\n", inode, file);
Sage Weil2817b002009-10-06 11:31:08 -0700576 return 0;
577}
578
Chengguang Xubb48bd42018-03-13 10:42:44 +0800579static void reset_readdir(struct ceph_dir_file_info *dfi)
Sage Weil2817b002009-10-06 11:31:08 -0700580{
Chengguang Xubb48bd42018-03-13 10:42:44 +0800581 if (dfi->last_readdir) {
582 ceph_mdsc_put_request(dfi->last_readdir);
583 dfi->last_readdir = NULL;
Sage Weil2817b002009-10-06 11:31:08 -0700584 }
Chengguang Xubb48bd42018-03-13 10:42:44 +0800585 kfree(dfi->last_name);
586 dfi->last_name = NULL;
587 dfi->dir_release_count = 0;
588 dfi->readdir_cache_idx = -1;
589 dfi->next_offset = 2; /* compensate for . and .. */
590 dfi->file_info.flags &= ~CEPH_F_ATEND;
Sage Weil2817b002009-10-06 11:31:08 -0700591}
592
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800593/*
594 * discard buffered readdir content on seekdir(0), or seek to new frag,
595 * or seek prior to current chunk
596 */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800597static bool need_reset_readdir(struct ceph_dir_file_info *dfi, loff_t new_pos)
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800598{
599 struct ceph_mds_reply_info_parsed *rinfo;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800600 loff_t chunk_offset;
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800601 if (new_pos == 0)
602 return true;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800603 if (is_hash_order(new_pos)) {
604 /* no need to reset last_name for a forward seek when
605 * dentries are sotred in hash order */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800606 } else if (dfi->frag != fpos_frag(new_pos)) {
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800607 return true;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800608 }
Chengguang Xubb48bd42018-03-13 10:42:44 +0800609 rinfo = dfi->last_readdir ? &dfi->last_readdir->r_reply_info : NULL;
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800610 if (!rinfo || !rinfo->dir_nr)
611 return true;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800612 chunk_offset = rinfo->dir_entries[0].offset;
613 return new_pos < chunk_offset ||
614 is_hash_order(new_pos) != is_hash_order(chunk_offset);
Yan, Zheng8974eeb2016-04-28 15:17:40 +0800615}
616
Andrew Morton965c8e52012-12-17 15:59:39 -0800617static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence)
Sage Weil2817b002009-10-06 11:31:08 -0700618{
Chengguang Xubb48bd42018-03-13 10:42:44 +0800619 struct ceph_dir_file_info *dfi = file->private_data;
Sage Weil2817b002009-10-06 11:31:08 -0700620 struct inode *inode = file->f_mapping->host;
Sage Weil2817b002009-10-06 11:31:08 -0700621 loff_t retval;
622
Al Viro59551022016-01-22 15:40:57 -0500623 inode_lock(inode);
Josef Bacik06222e42011-07-18 13:21:38 -0400624 retval = -EINVAL;
Andrew Morton965c8e52012-12-17 15:59:39 -0800625 switch (whence) {
Sage Weil2817b002009-10-06 11:31:08 -0700626 case SEEK_CUR:
627 offset += file->f_pos;
Josef Bacik06222e42011-07-18 13:21:38 -0400628 case SEEK_SET:
629 break;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800630 case SEEK_END:
631 retval = -EOPNOTSUPP;
Josef Bacik06222e42011-07-18 13:21:38 -0400632 default:
633 goto out;
Sage Weil2817b002009-10-06 11:31:08 -0700634 }
Josef Bacik06222e42011-07-18 13:21:38 -0400635
Yan, Zhengf0494202014-02-27 16:26:24 +0800636 if (offset >= 0) {
Chengguang Xubb48bd42018-03-13 10:42:44 +0800637 if (need_reset_readdir(dfi, offset)) {
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800638 dout("dir_llseek dropping %p content\n", file);
Chengguang Xubb48bd42018-03-13 10:42:44 +0800639 reset_readdir(dfi);
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800640 } else if (is_hash_order(offset) && offset > file->f_pos) {
641 /* for hash offset, we don't know if a forward seek
642 * is within same frag */
Chengguang Xubb48bd42018-03-13 10:42:44 +0800643 dfi->dir_release_count = 0;
644 dfi->readdir_cache_idx = -1;
Yan, Zhengf3c4ebe2016-04-29 11:27:30 +0800645 }
646
Sage Weil2817b002009-10-06 11:31:08 -0700647 if (offset != file->f_pos) {
648 file->f_pos = offset;
649 file->f_version = 0;
Chengguang Xubb48bd42018-03-13 10:42:44 +0800650 dfi->file_info.flags &= ~CEPH_F_ATEND;
Sage Weil2817b002009-10-06 11:31:08 -0700651 }
652 retval = offset;
Sage Weil2817b002009-10-06 11:31:08 -0700653 }
Josef Bacik06222e42011-07-18 13:21:38 -0400654out:
Al Viro59551022016-01-22 15:40:57 -0500655 inode_unlock(inode);
Sage Weil2817b002009-10-06 11:31:08 -0700656 return retval;
657}
658
659/*
Sage Weil468640e2011-07-26 11:28:11 -0700660 * Handle lookups for the hidden .snap directory.
Sage Weil2817b002009-10-06 11:31:08 -0700661 */
Sage Weil468640e2011-07-26 11:28:11 -0700662int ceph_handle_snapdir(struct ceph_mds_request *req,
663 struct dentry *dentry, int err)
Sage Weil2817b002009-10-06 11:31:08 -0700664{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700665 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
David Howells2b0143b2015-03-17 22:25:59 +0000666 struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */
Sage Weil2817b002009-10-06 11:31:08 -0700667
668 /* .snap dir? */
669 if (err == -ENOENT &&
Sage Weil455cec02011-03-03 13:44:35 -0800670 ceph_snap(parent) == CEPH_NOSNAP &&
Sage Weil6b805182009-10-27 11:50:50 -0700671 strcmp(dentry->d_name.name,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700672 fsc->mount_options->snapdir_name) == 0) {
Sage Weil2817b002009-10-06 11:31:08 -0700673 struct inode *inode = ceph_get_snapdir(parent);
Al Viroa4555892014-10-21 20:11:25 -0400674 dout("ENOENT on snapdir %p '%pd', linking to snapdir %p\n",
675 dentry, dentry, inode);
Sage Weil9358c6d2010-03-30 13:54:41 -0700676 BUG_ON(!d_unhashed(dentry));
Sage Weil2817b002009-10-06 11:31:08 -0700677 d_add(dentry, inode);
678 err = 0;
679 }
Sage Weil468640e2011-07-26 11:28:11 -0700680 return err;
681}
Sage Weil2817b002009-10-06 11:31:08 -0700682
Sage Weil468640e2011-07-26 11:28:11 -0700683/*
684 * Figure out final result of a lookup/open request.
685 *
686 * Mainly, make sure we return the final req->r_dentry (if it already
687 * existed) in place of the original VFS-provided dentry when they
688 * differ.
689 *
690 * Gracefully handle the case where the MDS replies with -ENOENT and
691 * no trace (which it may do, at its discretion, e.g., if it doesn't
692 * care to issue a lease on the negative dentry).
693 */
694struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
695 struct dentry *dentry, int err)
696{
Sage Weil2817b002009-10-06 11:31:08 -0700697 if (err == -ENOENT) {
698 /* no trace? */
699 err = 0;
700 if (!req->r_reply_info.head->is_dentry) {
701 dout("ENOENT and no trace, dentry %p inode %p\n",
David Howells2b0143b2015-03-17 22:25:59 +0000702 dentry, d_inode(dentry));
703 if (d_really_is_positive(dentry)) {
Sage Weil2817b002009-10-06 11:31:08 -0700704 d_drop(dentry);
705 err = -ENOENT;
706 } else {
707 d_add(dentry, NULL);
708 }
709 }
710 }
711 if (err)
712 dentry = ERR_PTR(err);
713 else if (dentry != req->r_dentry)
714 dentry = dget(req->r_dentry); /* we got spliced */
715 else
716 dentry = NULL;
717 return dentry;
718}
719
Zhang Zhuoyu3b33f692016-03-25 05:18:39 -0400720static bool is_root_ceph_dentry(struct inode *inode, struct dentry *dentry)
Sage Weil1d1de9162009-12-02 11:54:25 -0800721{
722 return ceph_ino(inode) == CEPH_INO_ROOT &&
723 strncmp(dentry->d_name.name, ".ceph", 5) == 0;
724}
725
Sage Weil2817b002009-10-06 11:31:08 -0700726/*
727 * Look up a single dir entry. If there is a lookup intent, inform
728 * the MDS so that it gets our 'caps wanted' value in a single op.
729 */
730static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
Al Viro00cd8dd2012-06-10 17:13:09 -0400731 unsigned int flags)
Sage Weil2817b002009-10-06 11:31:08 -0700732{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700733 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
734 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil2817b002009-10-06 11:31:08 -0700735 struct ceph_mds_request *req;
736 int op;
Yan, Zheng315f2402016-03-07 10:34:50 +0800737 int mask;
Sage Weil2817b002009-10-06 11:31:08 -0700738 int err;
739
Al Viroa4555892014-10-21 20:11:25 -0400740 dout("lookup %p dentry %p '%pd'\n",
741 dir, dentry, dentry);
Sage Weil2817b002009-10-06 11:31:08 -0700742
743 if (dentry->d_name.len > NAME_MAX)
744 return ERR_PTR(-ENAMETOOLONG);
745
Sage Weil2817b002009-10-06 11:31:08 -0700746 /* can we conclude ENOENT locally? */
David Howells2b0143b2015-03-17 22:25:59 +0000747 if (d_really_is_negative(dentry)) {
Sage Weil2817b002009-10-06 11:31:08 -0700748 struct ceph_inode_info *ci = ceph_inode(dir);
749 struct ceph_dentry_info *di = ceph_dentry(dentry);
750
Sage Weilbe655592011-11-30 09:47:09 -0800751 spin_lock(&ci->i_ceph_lock);
Sage Weil2817b002009-10-06 11:31:08 -0700752 dout(" dir %p flags are %d\n", dir, ci->i_ceph_flags);
753 if (strncmp(dentry->d_name.name,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700754 fsc->mount_options->snapdir_name,
Sage Weil2817b002009-10-06 11:31:08 -0700755 dentry->d_name.len) &&
Sage Weil1d1de9162009-12-02 11:54:25 -0800756 !is_root_ceph_dentry(dir, dentry) &&
Yan, Zhenge2c3de02015-03-04 16:05:04 +0800757 ceph_test_mount_opt(fsc, DCACHE) &&
Yan, Zheng2f276c52013-03-13 19:44:32 +0800758 __ceph_dir_is_complete(ci) &&
Sage Weil2817b002009-10-06 11:31:08 -0700759 (__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) {
Sage Weilbe655592011-11-30 09:47:09 -0800760 spin_unlock(&ci->i_ceph_lock);
Sage Weil2817b002009-10-06 11:31:08 -0700761 dout(" dir %p complete, -ENOENT\n", dir);
762 d_add(dentry, NULL);
Yan, Zheng97aeb6b2017-11-27 10:47:46 +0800763 di->lease_shared_gen = atomic_read(&ci->i_shared_gen);
Sage Weil2817b002009-10-06 11:31:08 -0700764 return NULL;
765 }
Sage Weilbe655592011-11-30 09:47:09 -0800766 spin_unlock(&ci->i_ceph_lock);
Sage Weil2817b002009-10-06 11:31:08 -0700767 }
768
769 op = ceph_snap(dir) == CEPH_SNAPDIR ?
770 CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP;
771 req = ceph_mdsc_create_request(mdsc, op, USE_ANY_MDS);
772 if (IS_ERR(req))
Julia Lawall7e34bc52010-05-22 12:01:14 +0200773 return ERR_CAST(req);
Sage Weil2817b002009-10-06 11:31:08 -0700774 req->r_dentry = dget(dentry);
775 req->r_num_caps = 2;
Yan, Zheng315f2402016-03-07 10:34:50 +0800776
777 mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED;
778 if (ceph_security_xattr_wanted(dir))
779 mask |= CEPH_CAP_XATTR_SHARED;
780 req->r_args.getattr.mask = cpu_to_le32(mask);
781
Jeff Layton3dd69aa2017-01-31 10:28:26 -0500782 req->r_parent = dir;
783 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weil2817b002009-10-06 11:31:08 -0700784 err = ceph_mdsc_do_request(mdsc, NULL, req);
Sage Weil468640e2011-07-26 11:28:11 -0700785 err = ceph_handle_snapdir(req, dentry, err);
Sage Weil2817b002009-10-06 11:31:08 -0700786 dentry = ceph_finish_lookup(req, dentry, err);
787 ceph_mdsc_put_request(req); /* will dput(dentry) */
788 dout("lookup result=%p\n", dentry);
789 return dentry;
790}
791
792/*
793 * If we do a create but get no trace back from the MDS, follow up with
794 * a lookup (the VFS expects us to link up the provided dentry).
795 */
796int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry)
797{
Al Viro00cd8dd2012-06-10 17:13:09 -0400798 struct dentry *result = ceph_lookup(dir, dentry, 0);
Sage Weil2817b002009-10-06 11:31:08 -0700799
800 if (result && !IS_ERR(result)) {
801 /*
802 * We created the item, then did a lookup, and found
803 * it was already linked to another inode we already
Yan, Zheng4d41cef2015-02-04 15:10:48 +0800804 * had in our cache (and thus got spliced). To not
805 * confuse VFS (especially when inode is a directory),
806 * we don't link our dentry to that inode, return an
807 * error instead.
808 *
809 * This event should be rare and it happens only when
810 * we talk to old MDS. Recent MDS does not send traceless
811 * reply for request that creates new inode.
Sage Weil2817b002009-10-06 11:31:08 -0700812 */
Yan, Zheng5cba3722015-02-02 11:27:56 +0800813 d_drop(result);
Yan, Zheng4d41cef2015-02-04 15:10:48 +0800814 return -ESTALE;
Sage Weil2817b002009-10-06 11:31:08 -0700815 }
816 return PTR_ERR(result);
817}
818
819static int ceph_mknod(struct inode *dir, struct dentry *dentry,
Al Viro1a67aaf2011-07-26 01:52:52 -0400820 umode_t mode, dev_t rdev)
Sage Weil2817b002009-10-06 11:31:08 -0700821{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700822 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
823 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil2817b002009-10-06 11:31:08 -0700824 struct ceph_mds_request *req;
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800825 struct ceph_acls_info acls = {};
Sage Weil2817b002009-10-06 11:31:08 -0700826 int err;
827
828 if (ceph_snap(dir) != CEPH_NOSNAP)
829 return -EROFS;
830
Luis Henriquesb7a29212018-01-05 10:47:19 +0000831 if (ceph_quota_is_max_files_exceeded(dir))
832 return -EDQUOT;
833
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800834 err = ceph_pre_init_acls(dir, &mode, &acls);
835 if (err < 0)
836 return err;
837
Al Viro1a67aaf2011-07-26 01:52:52 -0400838 dout("mknod in dir %p dentry %p mode 0%ho rdev %d\n",
Sage Weil2817b002009-10-06 11:31:08 -0700839 dir, dentry, mode, rdev);
840 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, USE_AUTH_MDS);
841 if (IS_ERR(req)) {
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800842 err = PTR_ERR(req);
843 goto out;
Sage Weil2817b002009-10-06 11:31:08 -0700844 }
845 req->r_dentry = dget(dentry);
846 req->r_num_caps = 2;
Jeff Layton3dd69aa2017-01-31 10:28:26 -0500847 req->r_parent = dir;
848 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weil2817b002009-10-06 11:31:08 -0700849 req->r_args.mknod.mode = cpu_to_le32(mode);
850 req->r_args.mknod.rdev = cpu_to_le32(rdev);
Yan, Zheng222b7f92017-11-23 17:47:15 +0800851 req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL;
Sage Weil2817b002009-10-06 11:31:08 -0700852 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800853 if (acls.pagelist) {
854 req->r_pagelist = acls.pagelist;
855 acls.pagelist = NULL;
856 }
Sage Weil2817b002009-10-06 11:31:08 -0700857 err = ceph_mdsc_do_request(mdsc, dir, req);
858 if (!err && !req->r_reply_info.head->is_dentry)
859 err = ceph_handle_notrace_create(dir, dentry);
860 ceph_mdsc_put_request(req);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800861out:
Guangliang Zhao7221fe42013-11-11 15:18:03 +0800862 if (!err)
David Howells2b0143b2015-03-17 22:25:59 +0000863 ceph_init_inode_acls(d_inode(dentry), &acls);
Yan, Zhengb20a95a2014-02-11 12:55:05 +0800864 else
Sage Weil2817b002009-10-06 11:31:08 -0700865 d_drop(dentry);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800866 ceph_release_acls_info(&acls);
Sage Weil2817b002009-10-06 11:31:08 -0700867 return err;
868}
869
Al Viro4acdaf22011-07-26 01:42:34 -0400870static int ceph_create(struct inode *dir, struct dentry *dentry, umode_t mode,
Al Viroebfc3b42012-06-10 18:05:36 -0400871 bool excl)
Sage Weil2817b002009-10-06 11:31:08 -0700872{
Miklos Szeredi2d83bde2012-06-05 15:10:25 +0200873 return ceph_mknod(dir, dentry, mode, 0);
Sage Weil2817b002009-10-06 11:31:08 -0700874}
875
876static int ceph_symlink(struct inode *dir, struct dentry *dentry,
877 const char *dest)
878{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700879 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
880 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil2817b002009-10-06 11:31:08 -0700881 struct ceph_mds_request *req;
882 int err;
883
884 if (ceph_snap(dir) != CEPH_NOSNAP)
885 return -EROFS;
886
Luis Henriquesb7a29212018-01-05 10:47:19 +0000887 if (ceph_quota_is_max_files_exceeded(dir))
888 return -EDQUOT;
889
Sage Weil2817b002009-10-06 11:31:08 -0700890 dout("symlink in dir %p dentry %p to '%s'\n", dir, dentry, dest);
891 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SYMLINK, USE_AUTH_MDS);
892 if (IS_ERR(req)) {
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800893 err = PTR_ERR(req);
894 goto out;
Sage Weil2817b002009-10-06 11:31:08 -0700895 }
Yan, Zheng687265e2015-06-13 17:27:05 +0800896 req->r_path2 = kstrdup(dest, GFP_KERNEL);
Sanidhya Kashyapa149bb92015-03-21 12:54:58 -0400897 if (!req->r_path2) {
898 err = -ENOMEM;
899 ceph_mdsc_put_request(req);
900 goto out;
901 }
Jeff Layton3dd69aa2017-01-31 10:28:26 -0500902 req->r_parent = dir;
903 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weil2817b002009-10-06 11:31:08 -0700904 req->r_dentry = dget(dentry);
905 req->r_num_caps = 2;
Yan, Zheng222b7f92017-11-23 17:47:15 +0800906 req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL;
Sage Weil2817b002009-10-06 11:31:08 -0700907 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
908 err = ceph_mdsc_do_request(mdsc, dir, req);
909 if (!err && !req->r_reply_info.head->is_dentry)
910 err = ceph_handle_notrace_create(dir, dentry);
911 ceph_mdsc_put_request(req);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800912out:
913 if (err)
Sage Weil2817b002009-10-06 11:31:08 -0700914 d_drop(dentry);
915 return err;
916}
917
Al Viro18bb1db2011-07-26 01:41:39 -0400918static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
Sage Weil2817b002009-10-06 11:31:08 -0700919{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700920 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
921 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil2817b002009-10-06 11:31:08 -0700922 struct ceph_mds_request *req;
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800923 struct ceph_acls_info acls = {};
Sage Weil2817b002009-10-06 11:31:08 -0700924 int err = -EROFS;
925 int op;
926
927 if (ceph_snap(dir) == CEPH_SNAPDIR) {
928 /* mkdir .snap/foo is a MKSNAP */
929 op = CEPH_MDS_OP_MKSNAP;
Al Viroa4555892014-10-21 20:11:25 -0400930 dout("mksnap dir %p snap '%pd' dn %p\n", dir,
931 dentry, dentry);
Sage Weil2817b002009-10-06 11:31:08 -0700932 } else if (ceph_snap(dir) == CEPH_NOSNAP) {
Al Viro18bb1db2011-07-26 01:41:39 -0400933 dout("mkdir dir %p dn %p mode 0%ho\n", dir, dentry, mode);
Sage Weil2817b002009-10-06 11:31:08 -0700934 op = CEPH_MDS_OP_MKDIR;
935 } else {
936 goto out;
937 }
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800938
Luis Henriquesb7a29212018-01-05 10:47:19 +0000939 if (ceph_quota_is_max_files_exceeded(dir)) {
940 err = -EDQUOT;
941 goto out;
942 }
943
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800944 mode |= S_IFDIR;
945 err = ceph_pre_init_acls(dir, &mode, &acls);
946 if (err < 0)
947 goto out;
948
Sage Weil2817b002009-10-06 11:31:08 -0700949 req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
950 if (IS_ERR(req)) {
951 err = PTR_ERR(req);
952 goto out;
953 }
954
955 req->r_dentry = dget(dentry);
956 req->r_num_caps = 2;
Jeff Layton3dd69aa2017-01-31 10:28:26 -0500957 req->r_parent = dir;
958 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weil2817b002009-10-06 11:31:08 -0700959 req->r_args.mkdir.mode = cpu_to_le32(mode);
Yan, Zheng222b7f92017-11-23 17:47:15 +0800960 req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL;
Sage Weil2817b002009-10-06 11:31:08 -0700961 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800962 if (acls.pagelist) {
963 req->r_pagelist = acls.pagelist;
964 acls.pagelist = NULL;
965 }
Sage Weil2817b002009-10-06 11:31:08 -0700966 err = ceph_mdsc_do_request(mdsc, dir, req);
Yan, Zheng275dd192014-12-10 16:17:31 +0800967 if (!err &&
968 !req->r_reply_info.head->is_target &&
969 !req->r_reply_info.head->is_dentry)
Sage Weil2817b002009-10-06 11:31:08 -0700970 err = ceph_handle_notrace_create(dir, dentry);
971 ceph_mdsc_put_request(req);
972out:
Yan, Zhengb20a95a2014-02-11 12:55:05 +0800973 if (!err)
David Howells2b0143b2015-03-17 22:25:59 +0000974 ceph_init_inode_acls(d_inode(dentry), &acls);
Yan, Zhengb20a95a2014-02-11 12:55:05 +0800975 else
Sage Weil2817b002009-10-06 11:31:08 -0700976 d_drop(dentry);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800977 ceph_release_acls_info(&acls);
Sage Weil2817b002009-10-06 11:31:08 -0700978 return err;
979}
980
981static int ceph_link(struct dentry *old_dentry, struct inode *dir,
982 struct dentry *dentry)
983{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700984 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
985 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil2817b002009-10-06 11:31:08 -0700986 struct ceph_mds_request *req;
987 int err;
988
989 if (ceph_snap(dir) != CEPH_NOSNAP)
990 return -EROFS;
991
992 dout("link in dir %p old_dentry %p dentry %p\n", dir,
993 old_dentry, dentry);
994 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LINK, USE_AUTH_MDS);
995 if (IS_ERR(req)) {
996 d_drop(dentry);
997 return PTR_ERR(req);
998 }
999 req->r_dentry = dget(dentry);
1000 req->r_num_caps = 2;
Sage Weil4b58c9b192013-02-05 13:41:23 -08001001 req->r_old_dentry = dget(old_dentry);
Jeff Layton3dd69aa2017-01-31 10:28:26 -05001002 req->r_parent = dir;
1003 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weil2817b002009-10-06 11:31:08 -07001004 req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
1005 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
Yan, Zhengad88f232013-07-21 20:25:25 +08001006 /* release LINK_SHARED on source inode (mds will lock it) */
Yan, Zhengd19a0b52017-11-23 17:59:13 +08001007 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
Sage Weil2817b002009-10-06 11:31:08 -07001008 err = ceph_mdsc_do_request(mdsc, dir, req);
Sage Weil70b666c2011-05-27 09:24:26 -07001009 if (err) {
Sage Weil2817b002009-10-06 11:31:08 -07001010 d_drop(dentry);
Sage Weil70b666c2011-05-27 09:24:26 -07001011 } else if (!req->r_reply_info.head->is_dentry) {
David Howells2b0143b2015-03-17 22:25:59 +00001012 ihold(d_inode(old_dentry));
1013 d_instantiate(dentry, d_inode(old_dentry));
Sage Weil70b666c2011-05-27 09:24:26 -07001014 }
Sage Weil2817b002009-10-06 11:31:08 -07001015 ceph_mdsc_put_request(req);
1016 return err;
1017}
1018
1019/*
Sage Weil2817b002009-10-06 11:31:08 -07001020 * rmdir and unlink are differ only by the metadata op code
1021 */
1022static int ceph_unlink(struct inode *dir, struct dentry *dentry)
1023{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001024 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
1025 struct ceph_mds_client *mdsc = fsc->mdsc;
David Howells2b0143b2015-03-17 22:25:59 +00001026 struct inode *inode = d_inode(dentry);
Sage Weil2817b002009-10-06 11:31:08 -07001027 struct ceph_mds_request *req;
1028 int err = -EROFS;
1029 int op;
1030
1031 if (ceph_snap(dir) == CEPH_SNAPDIR) {
1032 /* rmdir .snap/foo is RMSNAP */
Al Viroa4555892014-10-21 20:11:25 -04001033 dout("rmsnap dir %p '%pd' dn %p\n", dir, dentry, dentry);
Sage Weil2817b002009-10-06 11:31:08 -07001034 op = CEPH_MDS_OP_RMSNAP;
1035 } else if (ceph_snap(dir) == CEPH_NOSNAP) {
1036 dout("unlink/rmdir dir %p dn %p inode %p\n",
1037 dir, dentry, inode);
David Howellse36cb0b2015-01-29 12:02:35 +00001038 op = d_is_dir(dentry) ?
Sage Weil2817b002009-10-06 11:31:08 -07001039 CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK;
1040 } else
1041 goto out;
1042 req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
1043 if (IS_ERR(req)) {
1044 err = PTR_ERR(req);
1045 goto out;
1046 }
1047 req->r_dentry = dget(dentry);
1048 req->r_num_caps = 2;
Jeff Layton3dd69aa2017-01-31 10:28:26 -05001049 req->r_parent = dir;
1050 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weil2817b002009-10-06 11:31:08 -07001051 req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
1052 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
Zhi Zhang6ef0bc62018-01-24 21:24:33 +08001053 req->r_inode_drop = ceph_drop_caps_for_unlink(inode);
Sage Weil2817b002009-10-06 11:31:08 -07001054 err = ceph_mdsc_do_request(mdsc, dir, req);
1055 if (!err && !req->r_reply_info.head->is_dentry)
1056 d_delete(dentry);
1057 ceph_mdsc_put_request(req);
1058out:
1059 return err;
1060}
1061
1062static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +02001063 struct inode *new_dir, struct dentry *new_dentry,
1064 unsigned int flags)
Sage Weil2817b002009-10-06 11:31:08 -07001065{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001066 struct ceph_fs_client *fsc = ceph_sb_to_client(old_dir->i_sb);
1067 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil2817b002009-10-06 11:31:08 -07001068 struct ceph_mds_request *req;
Yan, Zheng0ea611a2015-04-07 15:36:32 +08001069 int op = CEPH_MDS_OP_RENAME;
Sage Weil2817b002009-10-06 11:31:08 -07001070 int err;
1071
Miklos Szeredi1cd66c92016-09-27 11:03:58 +02001072 if (flags)
1073 return -EINVAL;
1074
Sage Weil2817b002009-10-06 11:31:08 -07001075 if (ceph_snap(old_dir) != ceph_snap(new_dir))
1076 return -EXDEV;
Yan, Zheng0ea611a2015-04-07 15:36:32 +08001077 if (ceph_snap(old_dir) != CEPH_NOSNAP) {
1078 if (old_dir == new_dir && ceph_snap(old_dir) == CEPH_SNAPDIR)
1079 op = CEPH_MDS_OP_RENAMESNAP;
1080 else
1081 return -EROFS;
1082 }
Sage Weil2817b002009-10-06 11:31:08 -07001083 dout("rename dir %p dentry %p to dir %p dentry %p\n",
1084 old_dir, old_dentry, new_dir, new_dentry);
Yan, Zheng0ea611a2015-04-07 15:36:32 +08001085 req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
Sage Weil2817b002009-10-06 11:31:08 -07001086 if (IS_ERR(req))
1087 return PTR_ERR(req);
Sage Weil180061a2013-02-05 13:36:05 -08001088 ihold(old_dir);
Sage Weil2817b002009-10-06 11:31:08 -07001089 req->r_dentry = dget(new_dentry);
1090 req->r_num_caps = 2;
1091 req->r_old_dentry = dget(old_dentry);
Sage Weil180061a2013-02-05 13:36:05 -08001092 req->r_old_dentry_dir = old_dir;
Jeff Layton3dd69aa2017-01-31 10:28:26 -05001093 req->r_parent = new_dir;
1094 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weil2817b002009-10-06 11:31:08 -07001095 req->r_old_dentry_drop = CEPH_CAP_FILE_SHARED;
1096 req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL;
1097 req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
1098 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
1099 /* release LINK_RDCACHE on source inode (mds will lock it) */
Yan, Zhengd19a0b52017-11-23 17:59:13 +08001100 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
Zhi Zhang6ef0bc62018-01-24 21:24:33 +08001101 if (d_really_is_positive(new_dentry)) {
1102 req->r_inode_drop =
1103 ceph_drop_caps_for_unlink(d_inode(new_dentry));
1104 }
Sage Weil2817b002009-10-06 11:31:08 -07001105 err = ceph_mdsc_do_request(mdsc, old_dir, req);
1106 if (!err && !req->r_reply_info.head->is_dentry) {
1107 /*
1108 * Normally d_move() is done by fill_trace (called by
1109 * do_request, above). If there is no trace, we need
1110 * to do it here.
1111 */
1112 d_move(old_dentry, new_dentry);
1113 }
1114 ceph_mdsc_put_request(req);
1115 return err;
1116}
1117
Sage Weil81a6cf22010-05-14 09:35:38 -07001118/*
1119 * Ensure a dentry lease will no longer revalidate.
1120 */
1121void ceph_invalidate_dentry_lease(struct dentry *dentry)
1122{
1123 spin_lock(&dentry->d_lock);
Miklos Szeredi9b16f03c2016-06-22 16:35:04 +02001124 ceph_dentry(dentry)->time = jiffies;
Sage Weil81a6cf22010-05-14 09:35:38 -07001125 ceph_dentry(dentry)->lease_shared_gen = 0;
1126 spin_unlock(&dentry->d_lock);
1127}
Sage Weil2817b002009-10-06 11:31:08 -07001128
1129/*
1130 * Check if dentry lease is valid. If not, delete the lease. Try to
1131 * renew if the least is more than half up.
1132 */
Jeff Layton14fb9c92016-07-01 09:39:20 -04001133static int dentry_lease_is_valid(struct dentry *dentry, unsigned int flags,
1134 struct inode *dir)
Sage Weil2817b002009-10-06 11:31:08 -07001135{
1136 struct ceph_dentry_info *di;
1137 struct ceph_mds_session *s;
1138 int valid = 0;
1139 u32 gen;
1140 unsigned long ttl;
1141 struct ceph_mds_session *session = NULL;
Sage Weil2817b002009-10-06 11:31:08 -07001142 u32 seq = 0;
1143
1144 spin_lock(&dentry->d_lock);
1145 di = ceph_dentry(dentry);
Jeff Layton14fb9c92016-07-01 09:39:20 -04001146 if (di && di->lease_session) {
Sage Weil2817b002009-10-06 11:31:08 -07001147 s = di->lease_session;
Alex Elderd8fb02a2012-01-12 17:48:10 -08001148 spin_lock(&s->s_gen_ttl_lock);
Sage Weil2817b002009-10-06 11:31:08 -07001149 gen = s->s_cap_gen;
1150 ttl = s->s_cap_ttl;
Alex Elderd8fb02a2012-01-12 17:48:10 -08001151 spin_unlock(&s->s_gen_ttl_lock);
Sage Weil2817b002009-10-06 11:31:08 -07001152
1153 if (di->lease_gen == gen &&
Miklos Szeredi9b16f03c2016-06-22 16:35:04 +02001154 time_before(jiffies, di->time) &&
Sage Weil2817b002009-10-06 11:31:08 -07001155 time_before(jiffies, ttl)) {
1156 valid = 1;
1157 if (di->lease_renew_after &&
1158 time_after(jiffies, di->lease_renew_after)) {
Jeff Layton14fb9c92016-07-01 09:39:20 -04001159 /*
1160 * We should renew. If we're in RCU walk mode
1161 * though, we can't do that so just return
1162 * -ECHILD.
1163 */
1164 if (flags & LOOKUP_RCU) {
1165 valid = -ECHILD;
1166 } else {
1167 session = ceph_get_mds_session(s);
1168 seq = di->lease_seq;
1169 di->lease_renew_after = 0;
1170 di->lease_renew_from = jiffies;
1171 }
Sage Weil2817b002009-10-06 11:31:08 -07001172 }
Sage Weil2817b002009-10-06 11:31:08 -07001173 }
1174 }
1175 spin_unlock(&dentry->d_lock);
1176
1177 if (session) {
1178 ceph_mdsc_lease_send_msg(session, dir, dentry,
1179 CEPH_MDS_LEASE_RENEW, seq);
1180 ceph_put_mds_session(session);
1181 }
1182 dout("dentry_lease_is_valid - dentry %p = %d\n", dentry, valid);
1183 return valid;
1184}
1185
1186/*
1187 * Check if directory-wide content lease/cap is valid.
1188 */
1189static int dir_lease_is_valid(struct inode *dir, struct dentry *dentry)
1190{
1191 struct ceph_inode_info *ci = ceph_inode(dir);
1192 struct ceph_dentry_info *di = ceph_dentry(dentry);
1193 int valid = 0;
1194
Sage Weilbe655592011-11-30 09:47:09 -08001195 spin_lock(&ci->i_ceph_lock);
Yan, Zheng97aeb6b2017-11-27 10:47:46 +08001196 if (atomic_read(&ci->i_shared_gen) == di->lease_shared_gen)
Sage Weil2817b002009-10-06 11:31:08 -07001197 valid = __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1);
Sage Weilbe655592011-11-30 09:47:09 -08001198 spin_unlock(&ci->i_ceph_lock);
Sage Weil2817b002009-10-06 11:31:08 -07001199 dout("dir_lease_is_valid dir %p v%u dentry %p v%u = %d\n",
Yan, Zheng97aeb6b2017-11-27 10:47:46 +08001200 dir, (unsigned)atomic_read(&ci->i_shared_gen),
1201 dentry, (unsigned)di->lease_shared_gen, valid);
Sage Weil2817b002009-10-06 11:31:08 -07001202 return valid;
1203}
1204
1205/*
1206 * Check if cached dentry can be trusted.
1207 */
Al Viro0b728e12012-06-10 16:03:43 -04001208static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags)
Sage Weil2817b002009-10-06 11:31:08 -07001209{
Sage Weilbf1c6ac2011-07-26 11:30:43 -07001210 int valid = 0;
Yan, Zheng641235d2016-03-16 16:40:23 +08001211 struct dentry *parent;
Nick Piggin34286d62011-01-07 17:49:57 +11001212 struct inode *dir;
1213
Jeff Laytonf49d1e02016-07-01 09:39:21 -04001214 if (flags & LOOKUP_RCU) {
Seraphime Kirkovski52953d52016-12-26 10:26:34 +01001215 parent = READ_ONCE(dentry->d_parent);
Jeff Laytonf49d1e02016-07-01 09:39:21 -04001216 dir = d_inode_rcu(parent);
1217 if (!dir)
1218 return -ECHILD;
1219 } else {
1220 parent = dget_parent(dentry);
1221 dir = d_inode(parent);
1222 }
Nick Piggin34286d62011-01-07 17:49:57 +11001223
Al Viroa4555892014-10-21 20:11:25 -04001224 dout("d_revalidate %p '%pd' inode %p offset %lld\n", dentry,
David Howells2b0143b2015-03-17 22:25:59 +00001225 dentry, d_inode(dentry), ceph_dentry(dentry)->offset);
Sage Weil2817b002009-10-06 11:31:08 -07001226
1227 /* always trust cached snapped dentries, snapdir dentry */
1228 if (ceph_snap(dir) != CEPH_NOSNAP) {
Al Viroa4555892014-10-21 20:11:25 -04001229 dout("d_revalidate %p '%pd' inode %p is SNAPPED\n", dentry,
David Howells2b0143b2015-03-17 22:25:59 +00001230 dentry, d_inode(dentry));
Sage Weilbf1c6ac2011-07-26 11:30:43 -07001231 valid = 1;
David Howells2b0143b2015-03-17 22:25:59 +00001232 } else if (d_really_is_positive(dentry) &&
1233 ceph_snap(d_inode(dentry)) == CEPH_SNAPDIR) {
Sage Weilbf1c6ac2011-07-26 11:30:43 -07001234 valid = 1;
Jeff Layton14fb9c92016-07-01 09:39:20 -04001235 } else {
1236 valid = dentry_lease_is_valid(dentry, flags, dir);
1237 if (valid == -ECHILD)
1238 return valid;
1239 if (valid || dir_lease_is_valid(dir, dentry)) {
1240 if (d_really_is_positive(dentry))
1241 valid = ceph_is_any_caps(d_inode(dentry));
1242 else
1243 valid = 1;
1244 }
Sage Weil2817b002009-10-06 11:31:08 -07001245 }
Sage Weil2817b002009-10-06 11:31:08 -07001246
Yan, Zheng200fd272016-03-17 14:41:59 +08001247 if (!valid) {
1248 struct ceph_mds_client *mdsc =
1249 ceph_sb_to_client(dir->i_sb)->mdsc;
1250 struct ceph_mds_request *req;
Jeff Layton10976802017-01-12 14:42:38 -05001251 int op, err;
1252 u32 mask;
Yan, Zheng200fd272016-03-17 14:41:59 +08001253
Jeff Laytonf49d1e02016-07-01 09:39:21 -04001254 if (flags & LOOKUP_RCU)
1255 return -ECHILD;
1256
Yan, Zheng200fd272016-03-17 14:41:59 +08001257 op = ceph_snap(dir) == CEPH_SNAPDIR ?
Jeff Layton5eb9f602017-01-30 09:47:25 -05001258 CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP;
Yan, Zheng200fd272016-03-17 14:41:59 +08001259 req = ceph_mdsc_create_request(mdsc, op, USE_ANY_MDS);
1260 if (!IS_ERR(req)) {
1261 req->r_dentry = dget(dentry);
Jeff Layton5eb9f602017-01-30 09:47:25 -05001262 req->r_num_caps = 2;
1263 req->r_parent = dir;
Yan, Zheng200fd272016-03-17 14:41:59 +08001264
1265 mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED;
1266 if (ceph_security_xattr_wanted(dir))
1267 mask |= CEPH_CAP_XATTR_SHARED;
Jeff Layton10976802017-01-12 14:42:38 -05001268 req->r_args.getattr.mask = cpu_to_le32(mask);
Yan, Zheng200fd272016-03-17 14:41:59 +08001269
Yan, Zheng200fd272016-03-17 14:41:59 +08001270 err = ceph_mdsc_do_request(mdsc, NULL, req);
Jeff Laytonc3f46882016-11-30 15:56:46 -05001271 switch (err) {
1272 case 0:
1273 if (d_really_is_positive(dentry) &&
1274 d_inode(dentry) == req->r_target_inode)
1275 valid = 1;
1276 break;
1277 case -ENOENT:
1278 if (d_really_is_negative(dentry))
1279 valid = 1;
1280 /* Fallthrough */
1281 default:
1282 break;
Yan, Zheng200fd272016-03-17 14:41:59 +08001283 }
1284 ceph_mdsc_put_request(req);
1285 dout("d_revalidate %p lookup result=%d\n",
1286 dentry, err);
1287 }
1288 }
1289
Sage Weilbf1c6ac2011-07-26 11:30:43 -07001290 dout("d_revalidate %p %s\n", dentry, valid ? "valid" : "invalid");
Yan, Zheng9215aee2013-11-30 12:47:41 +08001291 if (valid) {
Sage Weilbf1c6ac2011-07-26 11:30:43 -07001292 ceph_dentry_lru_touch(dentry);
Yan, Zheng9215aee2013-11-30 12:47:41 +08001293 } else {
1294 ceph_dir_clear_complete(dir);
Yan, Zheng9215aee2013-11-30 12:47:41 +08001295 }
Yan, Zheng641235d2016-03-16 16:40:23 +08001296
Jeff Laytonf49d1e02016-07-01 09:39:21 -04001297 if (!(flags & LOOKUP_RCU))
1298 dput(parent);
Sage Weilbf1c6ac2011-07-26 11:30:43 -07001299 return valid;
Sage Weil2817b002009-10-06 11:31:08 -07001300}
1301
1302/*
Sage Weil147851d2011-03-15 14:57:41 -07001303 * Release our ceph_dentry_info.
Sage Weil2817b002009-10-06 11:31:08 -07001304 */
Sage Weil147851d2011-03-15 14:57:41 -07001305static void ceph_d_release(struct dentry *dentry)
Sage Weil2817b002009-10-06 11:31:08 -07001306{
1307 struct ceph_dentry_info *di = ceph_dentry(dentry);
Sage Weil2817b002009-10-06 11:31:08 -07001308
Sage Weil147851d2011-03-15 14:57:41 -07001309 dout("d_release %p\n", dentry);
Sage Weil3d8eb7a2011-11-11 09:48:53 -08001310 ceph_dentry_lru_del(dentry);
Jeff Layton5b484a52016-07-01 09:39:20 -04001311
1312 spin_lock(&dentry->d_lock);
1313 dentry->d_fsdata = NULL;
1314 spin_unlock(&dentry->d_lock);
1315
Sage Weil3d8eb7a2011-11-11 09:48:53 -08001316 if (di->lease_session)
1317 ceph_put_mds_session(di->lease_session);
1318 kmem_cache_free(ceph_dentry_cachep, di);
Sage Weil2817b002009-10-06 11:31:08 -07001319}
1320
Sage Weilb58dc412011-03-15 15:53:40 -07001321/*
1322 * When the VFS prunes a dentry from the cache, we need to clear the
1323 * complete flag on the parent directory.
1324 *
1325 * Called under dentry->d_lock.
1326 */
1327static void ceph_d_prune(struct dentry *dentry)
1328{
Yan, Zheng5495c2d2017-11-27 11:23:48 +08001329 struct ceph_inode_info *dir_ci;
1330 struct ceph_dentry_info *di;
1331
1332 dout("ceph_d_prune %pd %p\n", dentry, dentry);
Sage Weilb58dc412011-03-15 15:53:40 -07001333
1334 /* do we have a valid parent? */
Sage Weil8842b3b2012-06-07 13:43:35 -07001335 if (IS_ROOT(dentry))
Sage Weilb58dc412011-03-15 15:53:40 -07001336 return;
1337
Yan, Zheng5495c2d2017-11-27 11:23:48 +08001338 /* we hold d_lock, so d_parent is stable */
1339 dir_ci = ceph_inode(d_inode(dentry->d_parent));
1340 if (dir_ci->i_vino.snap == CEPH_SNAPDIR)
Sage Weilb58dc412011-03-15 15:53:40 -07001341 return;
1342
Yan, Zheng5495c2d2017-11-27 11:23:48 +08001343 /* who calls d_delete() should also disable dcache readdir */
1344 if (d_really_is_negative(dentry))
Al Viro18fc8ab2016-10-28 21:52:50 -04001345 return;
1346
Yan, Zheng5495c2d2017-11-27 11:23:48 +08001347 /* d_fsdata does not get cleared until d_release */
1348 if (!d_unhashed(dentry)) {
1349 __ceph_dir_clear_complete(dir_ci);
1350 return;
1351 }
1352
1353 /* Disable dcache readdir just in case that someone called d_drop()
1354 * or d_invalidate(), but MDS didn't revoke CEPH_CAP_FILE_SHARED
1355 * properly (dcache readdir is still enabled) */
1356 di = ceph_dentry(dentry);
1357 if (di->offset > 0 &&
1358 di->lease_shared_gen == atomic_read(&dir_ci->i_shared_gen))
1359 __ceph_dir_clear_ordered(dir_ci);
Sage Weilb58dc412011-03-15 15:53:40 -07001360}
Sage Weil2817b002009-10-06 11:31:08 -07001361
1362/*
1363 * read() on a dir. This weird interface hack only works if mounted
1364 * with '-o dirstat'.
1365 */
1366static ssize_t ceph_read_dir(struct file *file, char __user *buf, size_t size,
1367 loff_t *ppos)
1368{
Chengguang Xubb48bd42018-03-13 10:42:44 +08001369 struct ceph_dir_file_info *dfi = file->private_data;
Al Viro496ad9a2013-01-23 17:07:38 -05001370 struct inode *inode = file_inode(file);
Sage Weil2817b002009-10-06 11:31:08 -07001371 struct ceph_inode_info *ci = ceph_inode(inode);
1372 int left;
Sage Weilae598082011-05-12 14:28:05 -07001373 const int bufsize = 1024;
Sage Weil2817b002009-10-06 11:31:08 -07001374
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001375 if (!ceph_test_mount_opt(ceph_sb_to_client(inode->i_sb), DIRSTAT))
Sage Weil2817b002009-10-06 11:31:08 -07001376 return -EISDIR;
1377
Chengguang Xubb48bd42018-03-13 10:42:44 +08001378 if (!dfi->dir_info) {
1379 dfi->dir_info = kmalloc(bufsize, GFP_KERNEL);
1380 if (!dfi->dir_info)
Sage Weil2817b002009-10-06 11:31:08 -07001381 return -ENOMEM;
Chengguang Xubb48bd42018-03-13 10:42:44 +08001382 dfi->dir_info_len =
1383 snprintf(dfi->dir_info, bufsize,
Sage Weil2817b002009-10-06 11:31:08 -07001384 "entries: %20lld\n"
1385 " files: %20lld\n"
1386 " subdirs: %20lld\n"
1387 "rentries: %20lld\n"
1388 " rfiles: %20lld\n"
1389 " rsubdirs: %20lld\n"
1390 "rbytes: %20lld\n"
1391 "rctime: %10ld.%09ld\n",
1392 ci->i_files + ci->i_subdirs,
1393 ci->i_files,
1394 ci->i_subdirs,
1395 ci->i_rfiles + ci->i_rsubdirs,
1396 ci->i_rfiles,
1397 ci->i_rsubdirs,
1398 ci->i_rbytes,
1399 (long)ci->i_rctime.tv_sec,
1400 (long)ci->i_rctime.tv_nsec);
1401 }
1402
Chengguang Xubb48bd42018-03-13 10:42:44 +08001403 if (*ppos >= dfi->dir_info_len)
Sage Weil2817b002009-10-06 11:31:08 -07001404 return 0;
Chengguang Xubb48bd42018-03-13 10:42:44 +08001405 size = min_t(unsigned, size, dfi->dir_info_len-*ppos);
1406 left = copy_to_user(buf, dfi->dir_info + *ppos, size);
Sage Weil2817b002009-10-06 11:31:08 -07001407 if (left == size)
1408 return -EFAULT;
1409 *ppos += (size - left);
1410 return size - left;
1411}
1412
1413/*
Sage Weil2817b002009-10-06 11:31:08 -07001414 * We maintain a private dentry LRU.
1415 *
1416 * FIXME: this needs to be changed to a per-mds lru to be useful.
1417 */
1418void ceph_dentry_lru_add(struct dentry *dn)
1419{
1420 struct ceph_dentry_info *di = ceph_dentry(dn);
1421 struct ceph_mds_client *mdsc;
Sage Weil2817b002009-10-06 11:31:08 -07001422
Al Viroa4555892014-10-21 20:11:25 -04001423 dout("dentry_lru_add %p %p '%pd'\n", di, dn, dn);
Sage Weil3d8eb7a2011-11-11 09:48:53 -08001424 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
1425 spin_lock(&mdsc->dentry_lru_lock);
1426 list_add_tail(&di->lru, &mdsc->dentry_lru);
1427 mdsc->num_dentry++;
1428 spin_unlock(&mdsc->dentry_lru_lock);
Sage Weil2817b002009-10-06 11:31:08 -07001429}
1430
1431void ceph_dentry_lru_touch(struct dentry *dn)
1432{
1433 struct ceph_dentry_info *di = ceph_dentry(dn);
1434 struct ceph_mds_client *mdsc;
Sage Weil2817b002009-10-06 11:31:08 -07001435
Al Viroa4555892014-10-21 20:11:25 -04001436 dout("dentry_lru_touch %p %p '%pd' (offset %lld)\n", di, dn, dn,
1437 di->offset);
Sage Weil3d8eb7a2011-11-11 09:48:53 -08001438 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
1439 spin_lock(&mdsc->dentry_lru_lock);
1440 list_move_tail(&di->lru, &mdsc->dentry_lru);
1441 spin_unlock(&mdsc->dentry_lru_lock);
Sage Weil2817b002009-10-06 11:31:08 -07001442}
1443
1444void ceph_dentry_lru_del(struct dentry *dn)
1445{
1446 struct ceph_dentry_info *di = ceph_dentry(dn);
1447 struct ceph_mds_client *mdsc;
1448
Al Viroa4555892014-10-21 20:11:25 -04001449 dout("dentry_lru_del %p %p '%pd'\n", di, dn, dn);
Sage Weil3d8eb7a2011-11-11 09:48:53 -08001450 mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
1451 spin_lock(&mdsc->dentry_lru_lock);
1452 list_del_init(&di->lru);
1453 mdsc->num_dentry--;
1454 spin_unlock(&mdsc->dentry_lru_lock);
Sage Weil2817b002009-10-06 11:31:08 -07001455}
1456
Sage Weil6c0f3af2010-11-16 11:14:34 -08001457/*
1458 * Return name hash for a given dentry. This is dependent on
1459 * the parent directory's hash function.
1460 */
Sage Weile5f86dc2011-07-26 11:30:55 -07001461unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn)
Sage Weil6c0f3af2010-11-16 11:14:34 -08001462{
Sage Weil6c0f3af2010-11-16 11:14:34 -08001463 struct ceph_inode_info *dci = ceph_inode(dir);
1464
1465 switch (dci->i_dir_layout.dl_dir_hash) {
1466 case 0: /* for backward compat */
1467 case CEPH_STR_HASH_LINUX:
1468 return dn->d_name.hash;
1469
1470 default:
1471 return ceph_str_hash(dci->i_dir_layout.dl_dir_hash,
1472 dn->d_name.name, dn->d_name.len);
1473 }
1474}
1475
Sage Weil2817b002009-10-06 11:31:08 -07001476const struct file_operations ceph_dir_fops = {
1477 .read = ceph_read_dir,
Al Viro77acfa22013-05-17 16:52:26 -04001478 .iterate = ceph_readdir,
Sage Weil2817b002009-10-06 11:31:08 -07001479 .llseek = ceph_dir_llseek,
1480 .open = ceph_open,
1481 .release = ceph_release,
1482 .unlocked_ioctl = ceph_ioctl,
Yan, Zhengda819c82015-05-27 11:19:34 +08001483 .fsync = ceph_fsync,
Sage Weil2817b002009-10-06 11:31:08 -07001484};
1485
Yan, Zheng38c48b52015-01-14 13:46:04 +08001486const struct file_operations ceph_snapdir_fops = {
1487 .iterate = ceph_readdir,
1488 .llseek = ceph_dir_llseek,
1489 .open = ceph_open,
1490 .release = ceph_release,
1491};
1492
Sage Weil2817b002009-10-06 11:31:08 -07001493const struct inode_operations ceph_dir_iops = {
1494 .lookup = ceph_lookup,
1495 .permission = ceph_permission,
1496 .getattr = ceph_getattr,
1497 .setattr = ceph_setattr,
Sage Weil2817b002009-10-06 11:31:08 -07001498 .listxattr = ceph_listxattr,
Guangliang Zhao7221fe42013-11-11 15:18:03 +08001499 .get_acl = ceph_get_acl,
Sage Weil72466d02014-01-29 06:22:25 -08001500 .set_acl = ceph_set_acl,
Sage Weil2817b002009-10-06 11:31:08 -07001501 .mknod = ceph_mknod,
1502 .symlink = ceph_symlink,
1503 .mkdir = ceph_mkdir,
1504 .link = ceph_link,
1505 .unlink = ceph_unlink,
1506 .rmdir = ceph_unlink,
1507 .rename = ceph_rename,
1508 .create = ceph_create,
Miklos Szeredi2d83bde2012-06-05 15:10:25 +02001509 .atomic_open = ceph_atomic_open,
Sage Weil2817b002009-10-06 11:31:08 -07001510};
1511
Yan, Zheng38c48b52015-01-14 13:46:04 +08001512const struct inode_operations ceph_snapdir_iops = {
1513 .lookup = ceph_lookup,
1514 .permission = ceph_permission,
1515 .getattr = ceph_getattr,
1516 .mkdir = ceph_mkdir,
1517 .rmdir = ceph_unlink,
Yan, Zheng0ea611a2015-04-07 15:36:32 +08001518 .rename = ceph_rename,
Yan, Zheng38c48b52015-01-14 13:46:04 +08001519};
1520
Sage Weil52dfb8a2010-08-03 10:25:30 -07001521const struct dentry_operations ceph_dentry_ops = {
Sage Weil2817b002009-10-06 11:31:08 -07001522 .d_revalidate = ceph_d_revalidate,
Sage Weil147851d2011-03-15 14:57:41 -07001523 .d_release = ceph_d_release,
Sage Weilb58dc412011-03-15 15:53:40 -07001524 .d_prune = ceph_d_prune,
Al Viroad5cb122016-10-28 22:05:13 -04001525 .d_init = ceph_d_init,
Sage Weil2817b002009-10-06 11:31:08 -07001526};