dir.c 40.5 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2
#include <linux/ceph/ceph_debug.h>
S
Sage Weil 已提交
3 4 5

#include <linux/spinlock.h>
#include <linux/namei.h>
6
#include <linux/slab.h>
S
Sage Weil 已提交
7
#include <linux/sched.h>
8
#include <linux/xattr.h>
S
Sage Weil 已提交
9 10

#include "super.h"
11
#include "mds_client.h"
S
Sage Weil 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

/*
 * Directory operations: readdir, lookup, create, link, unlink,
 * rename, etc.
 */

/*
 * Ceph MDS operations are specified in terms of a base ino and
 * relative path.  Thus, the client can specify an operation on a
 * specific inode (e.g., a getattr due to fstat(2)), or as a path
 * relative to, say, the root directory.
 *
 * Normally, we limit ourselves to strict inode ops (no path component)
 * or dentry operations (a single path component relative to an ino).  The
 * exception to this is open_root_dentry(), which will open the mount
 * point by name.
 */

S
Sage Weil 已提交
30
const struct dentry_operations ceph_dentry_ops;
S
Sage Weil 已提交
31 32 33 34

/*
 * Initialize ceph dentry state.
 */
A
Al Viro 已提交
35
static int ceph_d_init(struct dentry *dentry)
S
Sage Weil 已提交
36 37 38
{
	struct ceph_dentry_info *di;

G
Geliang Tang 已提交
39
	di = kmem_cache_zalloc(ceph_dentry_cachep, GFP_KERNEL);
S
Sage Weil 已提交
40 41 42 43 44
	if (!di)
		return -ENOMEM;          /* oh well */

	di->dentry = dentry;
	di->lease_session = NULL;
M
Miklos Szeredi 已提交
45
	di->time = jiffies;
46
	dentry->d_fsdata = di;
S
Sage Weil 已提交
47 48 49 50 51
	ceph_dentry_lru_add(dentry);
	return 0;
}

/*
52 53 54 55 56 57
 * for f_pos for readdir:
 * - hash order:
 *	(0xff << 52) | ((24 bits hash) << 28) |
 *	(the nth entry has hash collision);
 * - frag+name order;
 *	((frag value) << 28) | (the nth entry in frag);
S
Sage Weil 已提交
58
 */
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#define OFFSET_BITS	28
#define OFFSET_MASK	((1 << OFFSET_BITS) - 1)
#define HASH_ORDER	(0xffull << (OFFSET_BITS + 24))
loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order)
{
	loff_t fpos = ((loff_t)high << 28) | (loff_t)off;
	if (hash_order)
		fpos |= HASH_ORDER;
	return fpos;
}

static bool is_hash_order(loff_t p)
{
	return (p & HASH_ORDER) == HASH_ORDER;
}

S
Sage Weil 已提交
75 76
static unsigned fpos_frag(loff_t p)
{
77
	return p >> OFFSET_BITS;
S
Sage Weil 已提交
78
}
79 80 81 82 83 84

static unsigned fpos_hash(loff_t p)
{
	return ceph_frag_value(fpos_frag(p));
}

S
Sage Weil 已提交
85 86
static unsigned fpos_off(loff_t p)
{
87
	return p & OFFSET_MASK;
S
Sage Weil 已提交
88 89
}

Y
Yan, Zheng 已提交
90 91 92 93 94 95 96 97
static int fpos_cmp(loff_t l, loff_t r)
{
	int v = ceph_frag_compare(fpos_frag(l), fpos_frag(r));
	if (v)
		return v;
	return (int)(fpos_off(l) - fpos_off(r));
}

Y
Yan, Zheng 已提交
98 99 100 101 102 103
/*
 * make note of the last dentry we read, so we can
 * continue at the same lexicographical point,
 * regardless of what dir changes take place on the
 * server.
 */
C
Chengguang Xu 已提交
104
static int note_last_dentry(struct ceph_dir_file_info *dfi, const char *name,
Y
Yan, Zheng 已提交
105 106 107 108 109
		            int len, unsigned next_offset)
{
	char *buf = kmalloc(len+1, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
C
Chengguang Xu 已提交
110 111 112 113 114 115
	kfree(dfi->last_name);
	dfi->last_name = buf;
	memcpy(dfi->last_name, name, len);
	dfi->last_name[len] = 0;
	dfi->next_offset = next_offset;
	dout("note_last_dentry '%s'\n", dfi->last_name);
Y
Yan, Zheng 已提交
116 117 118
	return 0;
}

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

static struct dentry *
__dcache_find_get_entry(struct dentry *parent, u64 idx,
			struct ceph_readdir_cache_control *cache_ctl)
{
	struct inode *dir = d_inode(parent);
	struct dentry *dentry;
	unsigned idx_mask = (PAGE_SIZE / sizeof(struct dentry *)) - 1;
	loff_t ptr_pos = idx * sizeof(struct dentry *);
	pgoff_t ptr_pgoff = ptr_pos >> PAGE_SHIFT;

	if (ptr_pos >= i_size_read(dir))
		return NULL;

	if (!cache_ctl->page || ptr_pgoff != page_index(cache_ctl->page)) {
		ceph_readdir_cache_release(cache_ctl);
		cache_ctl->page = find_lock_page(&dir->i_data, ptr_pgoff);
		if (!cache_ctl->page) {
			dout(" page %lu not found\n", ptr_pgoff);
			return ERR_PTR(-EAGAIN);
		}
		/* reading/filling the cache are serialized by
		   i_mutex, no need to use page lock */
		unlock_page(cache_ctl->page);
		cache_ctl->dentries = kmap(cache_ctl->page);
	}

	cache_ctl->index = idx & idx_mask;

	rcu_read_lock();
	spin_lock(&parent->d_lock);
	/* check i_size again here, because empty directory can be
	 * marked as complete while not holding the i_mutex. */
	if (ceph_dir_is_complete_ordered(dir) && ptr_pos < i_size_read(dir))
		dentry = cache_ctl->dentries[cache_ctl->index];
	else
		dentry = NULL;
	spin_unlock(&parent->d_lock);
	if (dentry && !lockref_get_not_dead(&dentry->d_lockref))
		dentry = NULL;
	rcu_read_unlock();
	return dentry ? : ERR_PTR(-EAGAIN);
}

S
Sage Weil 已提交
163 164 165
/*
 * When possible, we try to satisfy a readdir by peeking at the
 * dcache.  We make this work by carefully ordering dentries on
166
 * d_child when we initially get results back from the MDS, and
S
Sage Weil 已提交
167 168 169
 * falling back to a "normal" sync readdir if any dentries in the dir
 * are dropped.
 *
170
 * Complete dir indicates that we have all dentries in the dir.  It is
S
Sage Weil 已提交
171 172 173
 * defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by
 * the MDS if/when the directory is modified).
 */
174
static int __dcache_readdir(struct file *file,  struct dir_context *ctx,
175
			    int shared_gen)
S
Sage Weil 已提交
176
{
C
Chengguang Xu 已提交
177
	struct ceph_dir_file_info *dfi = file->private_data;
A
Al Viro 已提交
178
	struct dentry *parent = file->f_path.dentry;
179
	struct inode *dir = d_inode(parent);
Y
Yan, Zheng 已提交
180
	struct dentry *dentry, *last = NULL;
S
Sage Weil 已提交
181
	struct ceph_dentry_info *di;
Y
Yan, Zheng 已提交
182
	struct ceph_readdir_cache_control cache_ctl = {};
183 184
	u64 idx = 0;
	int err = 0;
S
Sage Weil 已提交
185

186
	dout("__dcache_readdir %p v%u at %llx\n", dir, (unsigned)shared_gen, ctx->pos);
S
Sage Weil 已提交
187

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
	/* search start position */
	if (ctx->pos > 2) {
		u64 count = div_u64(i_size_read(dir), sizeof(struct dentry *));
		while (count > 0) {
			u64 step = count >> 1;
			dentry = __dcache_find_get_entry(parent, idx + step,
							 &cache_ctl);
			if (!dentry) {
				/* use linar search */
				idx = 0;
				break;
			}
			if (IS_ERR(dentry)) {
				err = PTR_ERR(dentry);
				goto out;
			}
			di = ceph_dentry(dentry);
			spin_lock(&dentry->d_lock);
			if (fpos_cmp(di->offset, ctx->pos) < 0) {
				idx += step + 1;
				count -= step + 1;
			} else {
				count = step;
			}
			spin_unlock(&dentry->d_lock);
			dput(dentry);
		}
S
Sage Weil 已提交
215

216
		dout("__dcache_readdir %p cache idx %llu\n", dir, idx);
S
Sage Weil 已提交
217 218
	}

Y
Yan, Zheng 已提交
219

220 221 222 223
	for (;;) {
		bool emit_dentry = false;
		dentry = __dcache_find_get_entry(parent, idx++, &cache_ctl);
		if (!dentry) {
C
Chengguang Xu 已提交
224
			dfi->file_info.flags |= CEPH_F_ATEND;
Y
Yan, Zheng 已提交
225 226
			err = 0;
			break;
S
Sage Weil 已提交
227
		}
228 229 230
		if (IS_ERR(dentry)) {
			err = PTR_ERR(dentry);
			goto out;
Y
Yan, Zheng 已提交
231 232 233
		}

		spin_lock(&dentry->d_lock);
234 235 236 237 238 239 240 241 242 243
		di = ceph_dentry(dentry);
		if (d_unhashed(dentry) ||
		    d_really_is_negative(dentry) ||
		    di->lease_shared_gen != shared_gen) {
			spin_unlock(&dentry->d_lock);
			dput(dentry);
			err = -EAGAIN;
			goto out;
		}
		if (fpos_cmp(ctx->pos, di->offset) <= 0) {
Y
Yan, Zheng 已提交
244 245
			emit_dentry = true;
		}
N
Nick Piggin 已提交
246
		spin_unlock(&dentry->d_lock);
S
Sage Weil 已提交
247

Y
Yan, Zheng 已提交
248
		if (emit_dentry) {
249
			dout(" %llx dentry %p %pd %p\n", di->offset,
Y
Yan, Zheng 已提交
250 251 252 253 254 255 256 257 258 259 260 261
			     dentry, dentry, d_inode(dentry));
			ctx->pos = di->offset;
			if (!dir_emit(ctx, dentry->d_name.name,
				      dentry->d_name.len,
				      ceph_translate_ino(dentry->d_sb,
							 d_inode(dentry)->i_ino),
				      d_inode(dentry)->i_mode >> 12)) {
				dput(dentry);
				err = 0;
				break;
			}
			ctx->pos++;
262

Y
Yan, Zheng 已提交
263 264 265 266 267
			if (last)
				dput(last);
			last = dentry;
		} else {
			dput(dentry);
S
Sage Weil 已提交
268
		}
Y
Yan, Zheng 已提交
269
	}
270
out:
Y
Yan, Zheng 已提交
271 272 273 274
	ceph_readdir_cache_release(&cache_ctl);
	if (last) {
		int ret;
		di = ceph_dentry(last);
C
Chengguang Xu 已提交
275
		ret = note_last_dentry(dfi, last->d_name.name, last->d_name.len,
Y
Yan, Zheng 已提交
276 277 278
				       fpos_off(di->offset) + 1);
		if (ret < 0)
			err = ret;
S
Sage Weil 已提交
279
		dput(last);
280
		/* last_name no longer match cache index */
C
Chengguang Xu 已提交
281 282 283
		if (dfi->readdir_cache_idx >= 0) {
			dfi->readdir_cache_idx = -1;
			dfi->dir_release_count = 0;
284
		}
Y
Yan, Zheng 已提交
285
	}
S
Sage Weil 已提交
286 287 288
	return err;
}

C
Chengguang Xu 已提交
289
static bool need_send_readdir(struct ceph_dir_file_info *dfi, loff_t pos)
290
{
C
Chengguang Xu 已提交
291
	if (!dfi->last_readdir)
292 293
		return true;
	if (is_hash_order(pos))
C
Chengguang Xu 已提交
294
		return !ceph_frag_contains_value(dfi->frag, fpos_hash(pos));
295
	else
C
Chengguang Xu 已提交
296
		return dfi->frag != fpos_frag(pos);
297 298
}

A
Al Viro 已提交
299
static int ceph_readdir(struct file *file, struct dir_context *ctx)
S
Sage Weil 已提交
300
{
C
Chengguang Xu 已提交
301
	struct ceph_dir_file_info *dfi = file->private_data;
A
Al Viro 已提交
302
	struct inode *inode = file_inode(file);
S
Sage Weil 已提交
303
	struct ceph_inode_info *ci = ceph_inode(inode);
304 305
	struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
	struct ceph_mds_client *mdsc = fsc->mdsc;
306
	int i;
S
Sage Weil 已提交
307
	int err;
308
	unsigned frag = -1;
S
Sage Weil 已提交
309 310
	struct ceph_mds_reply_info_parsed *rinfo;

311
	dout("readdir %p file %p pos %llx\n", inode, file, ctx->pos);
C
Chengguang Xu 已提交
312
	if (dfi->file_info.flags & CEPH_F_ATEND)
S
Sage Weil 已提交
313 314 315
		return 0;

	/* always start with . and .. */
A
Al Viro 已提交
316
	if (ctx->pos == 0) {
S
Sage Weil 已提交
317
		dout("readdir off 0 -> '.'\n");
A
Al Viro 已提交
318
		if (!dir_emit(ctx, ".", 1, 
Y
Yehuda Sadeh 已提交
319
			    ceph_translate_ino(inode->i_sb, inode->i_ino),
A
Al Viro 已提交
320
			    inode->i_mode >> 12))
S
Sage Weil 已提交
321
			return 0;
A
Al Viro 已提交
322
		ctx->pos = 1;
S
Sage Weil 已提交
323
	}
A
Al Viro 已提交
324
	if (ctx->pos == 1) {
A
Al Viro 已提交
325
		ino_t ino = parent_ino(file->f_path.dentry);
S
Sage Weil 已提交
326
		dout("readdir off 1 -> '..'\n");
A
Al Viro 已提交
327
		if (!dir_emit(ctx, "..", 2,
Y
Yehuda Sadeh 已提交
328
			    ceph_translate_ino(inode->i_sb, ino),
A
Al Viro 已提交
329
			    inode->i_mode >> 12))
S
Sage Weil 已提交
330
			return 0;
A
Al Viro 已提交
331
		ctx->pos = 2;
S
Sage Weil 已提交
332 333 334
	}

	/* can we use the dcache? */
335
	spin_lock(&ci->i_ceph_lock);
Y
Yan, Zheng 已提交
336
	if (ceph_test_mount_opt(fsc, DCACHE) &&
337
	    !ceph_test_mount_opt(fsc, NOASYNCREADDIR) &&
338
	    ceph_snap(inode) != CEPH_SNAPDIR &&
339
	    __ceph_dir_is_complete_ordered(ci) &&
S
Sage Weil 已提交
340
	    __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) {
341
		int shared_gen = atomic_read(&ci->i_shared_gen);
342
		spin_unlock(&ci->i_ceph_lock);
343
		err = __dcache_readdir(file, ctx, shared_gen);
344
		if (err != -EAGAIN)
S
Sage Weil 已提交
345
			return err;
346
	} else {
347
		spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
348 349 350 351 352
	}

	/* proceed with a normal readdir */
more:
	/* do we have the correct frag content buffered? */
C
Chengguang Xu 已提交
353
	if (need_send_readdir(dfi, ctx->pos)) {
S
Sage Weil 已提交
354 355 356 357 358
		struct ceph_mds_request *req;
		int op = ceph_snap(inode) == CEPH_SNAPDIR ?
			CEPH_MDS_OP_LSSNAP : CEPH_MDS_OP_READDIR;

		/* discard old result, if any */
C
Chengguang Xu 已提交
359 360 361
		if (dfi->last_readdir) {
			ceph_mdsc_put_request(dfi->last_readdir);
			dfi->last_readdir = NULL;
362
		}
S
Sage Weil 已提交
363

364
		if (is_hash_order(ctx->pos)) {
365 366 367 368 369
			/* fragtree isn't always accurate. choose frag
			 * based on previous reply when possible. */
			if (frag == (unsigned)-1)
				frag = ceph_choose_frag(ci, fpos_hash(ctx->pos),
							NULL, NULL);
370 371 372 373
		} else {
			frag = fpos_frag(ctx->pos);
		}

S
Sage Weil 已提交
374
		dout("readdir fetching %llx.%llx frag %x offset '%s'\n",
C
Chengguang Xu 已提交
375
		     ceph_vinop(inode), frag, dfi->last_name);
S
Sage Weil 已提交
376 377 378
		req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
		if (IS_ERR(req))
			return PTR_ERR(req);
379 380 381 382 383
		err = ceph_alloc_readdir_reply_buffer(req, inode);
		if (err) {
			ceph_mdsc_put_request(req);
			return err;
		}
S
Sage Weil 已提交
384 385
		/* hints to request -> mds selection code */
		req->r_direct_mode = USE_AUTH_MDS;
386 387 388
		if (op == CEPH_MDS_OP_READDIR) {
			req->r_direct_hash = ceph_frag_value(frag);
			__set_bit(CEPH_MDS_R_DIRECT_IS_HASH, &req->r_req_flags);
389
			req->r_inode_drop = CEPH_CAP_FILE_EXCL;
390
		}
C
Chengguang Xu 已提交
391 392
		if (dfi->last_name) {
			req->r_path2 = kstrdup(dfi->last_name, GFP_KERNEL);
393 394 395 396
			if (!req->r_path2) {
				ceph_mdsc_put_request(req);
				return -ENOMEM;
			}
397 398 399
		} else if (is_hash_order(ctx->pos)) {
			req->r_args.readdir.offset_hash =
				cpu_to_le32(fpos_hash(ctx->pos));
400
		}
401

C
Chengguang Xu 已提交
402 403 404 405
		req->r_dir_release_cnt = dfi->dir_release_count;
		req->r_dir_ordered_cnt = dfi->dir_ordered_count;
		req->r_readdir_cache_idx = dfi->readdir_cache_idx;
		req->r_readdir_offset = dfi->next_offset;
S
Sage Weil 已提交
406
		req->r_args.readdir.frag = cpu_to_le32(frag);
407 408
		req->r_args.readdir.flags =
				cpu_to_le16(CEPH_READDIR_REPLY_BITFLAGS);
409 410 411 412

		req->r_inode = inode;
		ihold(inode);
		req->r_dentry = dget(file->f_path.dentry);
S
Sage Weil 已提交
413 414 415 416 417
		err = ceph_mdsc_do_request(mdsc, NULL, req);
		if (err < 0) {
			ceph_mdsc_put_request(req);
			return err;
		}
418 419 420
		dout("readdir got and parsed readdir result=%d on "
		     "frag %x, end=%d, complete=%d, hash_order=%d\n",
		     err, frag,
S
Sage Weil 已提交
421
		     (int)req->r_reply_info.dir_end,
422 423
		     (int)req->r_reply_info.dir_complete,
		     (int)req->r_reply_info.hash_order);
S
Sage Weil 已提交
424

425 426 427
		rinfo = &req->r_reply_info;
		if (le32_to_cpu(rinfo->dir_dir->frag) != frag) {
			frag = le32_to_cpu(rinfo->dir_dir->frag);
428
			if (!rinfo->hash_order) {
C
Chengguang Xu 已提交
429
				dfi->next_offset = req->r_readdir_offset;
430 431
				/* adjust ctx->pos to beginning of frag */
				ctx->pos = ceph_make_fpos(frag,
C
Chengguang Xu 已提交
432
							  dfi->next_offset,
433 434
							  false);
			}
435
		}
Y
Yan, Zheng 已提交
436

C
Chengguang Xu 已提交
437 438
		dfi->frag = frag;
		dfi->last_readdir = req;
S
Sage Weil 已提交
439

440
		if (test_bit(CEPH_MDS_R_DID_PREPOPULATE, &req->r_req_flags)) {
C
Chengguang Xu 已提交
441 442
			dfi->readdir_cache_idx = req->r_readdir_cache_idx;
			if (dfi->readdir_cache_idx < 0) {
Y
Yan, Zheng 已提交
443
				/* preclude from marking dir ordered */
C
Chengguang Xu 已提交
444
				dfi->dir_ordered_count = 0;
445
			} else if (ceph_frag_is_leftmost(frag) &&
C
Chengguang Xu 已提交
446
				   dfi->next_offset == 2) {
Y
Yan, Zheng 已提交
447 448
				/* note dir version at start of readdir so
				 * we can tell if any dentries get dropped */
C
Chengguang Xu 已提交
449 450
				dfi->dir_release_count = req->r_dir_release_cnt;
				dfi->dir_ordered_count = req->r_dir_ordered_cnt;
Y
Yan, Zheng 已提交
451 452
			}
		} else {
453
			dout("readdir !did_prepopulate\n");
Y
Yan, Zheng 已提交
454
			/* disable readdir cache */
C
Chengguang Xu 已提交
455
			dfi->readdir_cache_idx = -1;
Y
Yan, Zheng 已提交
456
			/* preclude from marking dir complete */
C
Chengguang Xu 已提交
457
			dfi->dir_release_count = 0;
Y
Yan, Zheng 已提交
458 459
		}

460 461
		/* note next offset and last dentry name */
		if (rinfo->dir_nr > 0) {
462 463
			struct ceph_mds_reply_dir_entry *rde =
					rinfo->dir_entries + (rinfo->dir_nr-1);
464 465
			unsigned next_offset = req->r_reply_info.dir_end ?
					2 : (fpos_off(rde->offset) + 1);
C
Chengguang Xu 已提交
466
			err = note_last_dentry(dfi, rde->name, rde->name_len,
467
					       next_offset);
S
Sage Weil 已提交
468 469
			if (err)
				return err;
470
		} else if (req->r_reply_info.dir_end) {
C
Chengguang Xu 已提交
471
			dfi->next_offset = 2;
472
			/* keep last name */
S
Sage Weil 已提交
473 474 475
		}
	}

C
Chengguang Xu 已提交
476
	rinfo = &dfi->last_readdir->r_reply_info;
477
	dout("readdir frag %x num %d pos %llx chunk first %llx\n",
C
Chengguang Xu 已提交
478
	     dfi->frag, rinfo->dir_nr, ctx->pos,
479
	     rinfo->dir_nr ? rinfo->dir_entries[0].offset : 0LL);
A
Al Viro 已提交
480

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
	i = 0;
	/* search start position */
	if (rinfo->dir_nr > 0) {
		int step, nr = rinfo->dir_nr;
		while (nr > 0) {
			step = nr >> 1;
			if (rinfo->dir_entries[i + step].offset < ctx->pos) {
				i +=  step + 1;
				nr -= step + 1;
			} else {
				nr = step;
			}
		}
	}
	for (; i < rinfo->dir_nr; i++) {
		struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i;
497 498
		struct ceph_vino vino;
		ino_t ino;
499
		u32 ftype;
500

501 502 503 504 505
		BUG_ON(rde->offset < ctx->pos);

		ctx->pos = rde->offset;
		dout("readdir (%d/%d) -> %llx '%.*s' %p\n",
		     i, rinfo->dir_nr, ctx->pos,
506
		     rde->name_len, rde->name, &rde->inode.in);
507

508 509 510 511
		BUG_ON(!rde->inode.in);
		ftype = le32_to_cpu(rde->inode.in->mode) >> 12;
		vino.ino = le64_to_cpu(rde->inode.in->ino);
		vino.snap = le64_to_cpu(rde->inode.in->snapid);
512
		ino = ceph_vino_to_ino(vino);
513

514 515
		if (!dir_emit(ctx, rde->name, rde->name_len,
			      ceph_translate_ino(inode->i_sb, ino), ftype)) {
S
Sage Weil 已提交
516 517 518
			dout("filldir stopping us...\n");
			return 0;
		}
A
Al Viro 已提交
519
		ctx->pos++;
S
Sage Weil 已提交
520 521
	}

C
Chengguang Xu 已提交
522 523
	ceph_mdsc_put_request(dfi->last_readdir);
	dfi->last_readdir = NULL;
524

C
Chengguang Xu 已提交
525 526
	if (dfi->next_offset > 2) {
		frag = dfi->frag;
S
Sage Weil 已提交
527 528 529 530
		goto more;
	}

	/* more frags? */
C
Chengguang Xu 已提交
531 532
	if (!ceph_frag_is_rightmost(dfi->frag)) {
		frag = ceph_frag_next(dfi->frag);
533 534
		if (is_hash_order(ctx->pos)) {
			loff_t new_pos = ceph_make_fpos(ceph_frag_value(frag),
C
Chengguang Xu 已提交
535
							dfi->next_offset, true);
536 537 538 539
			if (new_pos > ctx->pos)
				ctx->pos = new_pos;
			/* keep last_name */
		} else {
C
Chengguang Xu 已提交
540 541 542 543
			ctx->pos = ceph_make_fpos(frag, dfi->next_offset,
							false);
			kfree(dfi->last_name);
			dfi->last_name = NULL;
544
		}
S
Sage Weil 已提交
545 546 547
		dout("readdir next frag is %x\n", frag);
		goto more;
	}
C
Chengguang Xu 已提交
548
	dfi->file_info.flags |= CEPH_F_ATEND;
S
Sage Weil 已提交
549 550 551 552 553 554

	/*
	 * if dir_release_count still matches the dir, no dentries
	 * were released during the whole readdir, and we should have
	 * the complete dir contents in our cache.
	 */
C
Chengguang Xu 已提交
555 556
	if (atomic64_read(&ci->i_release_count) ==
					dfi->dir_release_count) {
Y
Yan, Zheng 已提交
557
		spin_lock(&ci->i_ceph_lock);
C
Chengguang Xu 已提交
558 559
		if (dfi->dir_ordered_count ==
				atomic64_read(&ci->i_ordered_count)) {
560
			dout(" marking %p complete and ordered\n", inode);
Y
Yan, Zheng 已提交
561 562
			/* use i_size to track number of entries in
			 * readdir cache */
C
Chengguang Xu 已提交
563 564
			BUG_ON(dfi->readdir_cache_idx < 0);
			i_size_write(inode, dfi->readdir_cache_idx *
Y
Yan, Zheng 已提交
565 566
				     sizeof(struct dentry*));
		} else {
567
			dout(" marking %p complete\n", inode);
Y
Yan, Zheng 已提交
568
		}
C
Chengguang Xu 已提交
569 570
		__ceph_dir_set_complete(ci, dfi->dir_release_count,
					dfi->dir_ordered_count);
Y
Yan, Zheng 已提交
571
		spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
572 573
	}

A
Al Viro 已提交
574
	dout("readdir %p file %p done.\n", inode, file);
S
Sage Weil 已提交
575 576 577
	return 0;
}

C
Chengguang Xu 已提交
578
static void reset_readdir(struct ceph_dir_file_info *dfi)
S
Sage Weil 已提交
579
{
C
Chengguang Xu 已提交
580 581 582
	if (dfi->last_readdir) {
		ceph_mdsc_put_request(dfi->last_readdir);
		dfi->last_readdir = NULL;
S
Sage Weil 已提交
583
	}
C
Chengguang Xu 已提交
584 585 586 587 588 589
	kfree(dfi->last_name);
	dfi->last_name = NULL;
	dfi->dir_release_count = 0;
	dfi->readdir_cache_idx = -1;
	dfi->next_offset = 2;  /* compensate for . and .. */
	dfi->file_info.flags &= ~CEPH_F_ATEND;
S
Sage Weil 已提交
590 591
}

592 593 594 595
/*
 * discard buffered readdir content on seekdir(0), or seek to new frag,
 * or seek prior to current chunk
 */
C
Chengguang Xu 已提交
596
static bool need_reset_readdir(struct ceph_dir_file_info *dfi, loff_t new_pos)
597 598
{
	struct ceph_mds_reply_info_parsed *rinfo;
599
	loff_t chunk_offset;
600 601
	if (new_pos == 0)
		return true;
602 603 604
	if (is_hash_order(new_pos)) {
		/* no need to reset last_name for a forward seek when
		 * dentries are sotred in hash order */
C
Chengguang Xu 已提交
605
	} else if (dfi->frag != fpos_frag(new_pos)) {
606
		return true;
607
	}
C
Chengguang Xu 已提交
608
	rinfo = dfi->last_readdir ? &dfi->last_readdir->r_reply_info : NULL;
609 610
	if (!rinfo || !rinfo->dir_nr)
		return true;
611 612 613
	chunk_offset = rinfo->dir_entries[0].offset;
	return new_pos < chunk_offset ||
	       is_hash_order(new_pos) != is_hash_order(chunk_offset);
614 615
}

616
static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence)
S
Sage Weil 已提交
617
{
C
Chengguang Xu 已提交
618
	struct ceph_dir_file_info *dfi = file->private_data;
S
Sage Weil 已提交
619 620 621
	struct inode *inode = file->f_mapping->host;
	loff_t retval;

A
Al Viro 已提交
622
	inode_lock(inode);
623
	retval = -EINVAL;
624
	switch (whence) {
S
Sage Weil 已提交
625 626
	case SEEK_CUR:
		offset += file->f_pos;
627 628
	case SEEK_SET:
		break;
Y
Yan, Zheng 已提交
629 630
	case SEEK_END:
		retval = -EOPNOTSUPP;
631 632
	default:
		goto out;
S
Sage Weil 已提交
633
	}
634

Y
Yan, Zheng 已提交
635
	if (offset >= 0) {
C
Chengguang Xu 已提交
636
		if (need_reset_readdir(dfi, offset)) {
637
			dout("dir_llseek dropping %p content\n", file);
C
Chengguang Xu 已提交
638
			reset_readdir(dfi);
639 640 641
		} else if (is_hash_order(offset) && offset > file->f_pos) {
			/* for hash offset, we don't know if a forward seek
			 * is within same frag */
C
Chengguang Xu 已提交
642 643
			dfi->dir_release_count = 0;
			dfi->readdir_cache_idx = -1;
644 645
		}

S
Sage Weil 已提交
646 647 648
		if (offset != file->f_pos) {
			file->f_pos = offset;
			file->f_version = 0;
C
Chengguang Xu 已提交
649
			dfi->file_info.flags &= ~CEPH_F_ATEND;
S
Sage Weil 已提交
650 651 652
		}
		retval = offset;
	}
653
out:
A
Al Viro 已提交
654
	inode_unlock(inode);
S
Sage Weil 已提交
655 656 657 658
	return retval;
}

/*
659
 * Handle lookups for the hidden .snap directory.
S
Sage Weil 已提交
660
 */
661 662
int ceph_handle_snapdir(struct ceph_mds_request *req,
			struct dentry *dentry, int err)
S
Sage Weil 已提交
663
{
664
	struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
665
	struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */
S
Sage Weil 已提交
666 667 668

	/* .snap dir? */
	if (err == -ENOENT &&
669
	    ceph_snap(parent) == CEPH_NOSNAP &&
670
	    strcmp(dentry->d_name.name,
671
		   fsc->mount_options->snapdir_name) == 0) {
S
Sage Weil 已提交
672
		struct inode *inode = ceph_get_snapdir(parent);
A
Al Viro 已提交
673 674
		dout("ENOENT on snapdir %p '%pd', linking to snapdir %p\n",
		     dentry, dentry, inode);
675
		BUG_ON(!d_unhashed(dentry));
S
Sage Weil 已提交
676 677 678
		d_add(dentry, inode);
		err = 0;
	}
679 680
	return err;
}
S
Sage Weil 已提交
681

682 683 684 685 686 687 688 689 690 691 692 693 694 695
/*
 * Figure out final result of a lookup/open request.
 *
 * Mainly, make sure we return the final req->r_dentry (if it already
 * existed) in place of the original VFS-provided dentry when they
 * differ.
 *
 * Gracefully handle the case where the MDS replies with -ENOENT and
 * no trace (which it may do, at its discretion, e.g., if it doesn't
 * care to issue a lease on the negative dentry).
 */
struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
				  struct dentry *dentry, int err)
{
S
Sage Weil 已提交
696 697 698 699 700
	if (err == -ENOENT) {
		/* no trace? */
		err = 0;
		if (!req->r_reply_info.head->is_dentry) {
			dout("ENOENT and no trace, dentry %p inode %p\n",
701 702
			     dentry, d_inode(dentry));
			if (d_really_is_positive(dentry)) {
S
Sage Weil 已提交
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
				d_drop(dentry);
				err = -ENOENT;
			} else {
				d_add(dentry, NULL);
			}
		}
	}
	if (err)
		dentry = ERR_PTR(err);
	else if (dentry != req->r_dentry)
		dentry = dget(req->r_dentry);   /* we got spliced */
	else
		dentry = NULL;
	return dentry;
}

719
static bool is_root_ceph_dentry(struct inode *inode, struct dentry *dentry)
S
Sage Weil 已提交
720 721 722 723 724
{
	return ceph_ino(inode) == CEPH_INO_ROOT &&
		strncmp(dentry->d_name.name, ".ceph", 5) == 0;
}

S
Sage Weil 已提交
725 726 727 728 729
/*
 * Look up a single dir entry.  If there is a lookup intent, inform
 * the MDS so that it gets our 'caps wanted' value in a single op.
 */
static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
A
Al Viro 已提交
730
				  unsigned int flags)
S
Sage Weil 已提交
731
{
732 733
	struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
734 735
	struct ceph_mds_request *req;
	int op;
Y
Yan, Zheng 已提交
736
	int mask;
S
Sage Weil 已提交
737 738
	int err;

A
Al Viro 已提交
739 740
	dout("lookup %p dentry %p '%pd'\n",
	     dir, dentry, dentry);
S
Sage Weil 已提交
741 742 743 744 745

	if (dentry->d_name.len > NAME_MAX)
		return ERR_PTR(-ENAMETOOLONG);

	/* can we conclude ENOENT locally? */
746
	if (d_really_is_negative(dentry)) {
S
Sage Weil 已提交
747 748 749
		struct ceph_inode_info *ci = ceph_inode(dir);
		struct ceph_dentry_info *di = ceph_dentry(dentry);

750
		spin_lock(&ci->i_ceph_lock);
S
Sage Weil 已提交
751 752
		dout(" dir %p flags are %d\n", dir, ci->i_ceph_flags);
		if (strncmp(dentry->d_name.name,
753
			    fsc->mount_options->snapdir_name,
S
Sage Weil 已提交
754
			    dentry->d_name.len) &&
S
Sage Weil 已提交
755
		    !is_root_ceph_dentry(dir, dentry) &&
756
		    ceph_test_mount_opt(fsc, DCACHE) &&
757
		    __ceph_dir_is_complete(ci) &&
S
Sage Weil 已提交
758
		    (__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) {
759
			spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
760 761
			dout(" dir %p complete, -ENOENT\n", dir);
			d_add(dentry, NULL);
762
			di->lease_shared_gen = atomic_read(&ci->i_shared_gen);
S
Sage Weil 已提交
763 764
			return NULL;
		}
765
		spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
766 767 768 769 770 771
	}

	op = ceph_snap(dir) == CEPH_SNAPDIR ?
		CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP;
	req = ceph_mdsc_create_request(mdsc, op, USE_ANY_MDS);
	if (IS_ERR(req))
J
Julia Lawall 已提交
772
		return ERR_CAST(req);
S
Sage Weil 已提交
773 774
	req->r_dentry = dget(dentry);
	req->r_num_caps = 2;
Y
Yan, Zheng 已提交
775 776 777 778 779 780

	mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED;
	if (ceph_security_xattr_wanted(dir))
		mask |= CEPH_CAP_XATTR_SHARED;
	req->r_args.getattr.mask = cpu_to_le32(mask);

781 782
	req->r_parent = dir;
	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
S
Sage Weil 已提交
783
	err = ceph_mdsc_do_request(mdsc, NULL, req);
784
	err = ceph_handle_snapdir(req, dentry, err);
S
Sage Weil 已提交
785 786 787 788 789 790 791 792 793 794 795 796
	dentry = ceph_finish_lookup(req, dentry, err);
	ceph_mdsc_put_request(req);  /* will dput(dentry) */
	dout("lookup result=%p\n", dentry);
	return dentry;
}

/*
 * If we do a create but get no trace back from the MDS, follow up with
 * a lookup (the VFS expects us to link up the provided dentry).
 */
int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry)
{
A
Al Viro 已提交
797
	struct dentry *result = ceph_lookup(dir, dentry, 0);
S
Sage Weil 已提交
798 799 800 801 802

	if (result && !IS_ERR(result)) {
		/*
		 * We created the item, then did a lookup, and found
		 * it was already linked to another inode we already
803 804 805 806 807 808 809 810
		 * had in our cache (and thus got spliced). To not
		 * confuse VFS (especially when inode is a directory),
		 * we don't link our dentry to that inode, return an
		 * error instead.
		 *
		 * This event should be rare and it happens only when
		 * we talk to old MDS. Recent MDS does not send traceless
		 * reply for request that creates new inode.
S
Sage Weil 已提交
811
		 */
Y
Yan, Zheng 已提交
812
		d_drop(result);
813
		return -ESTALE;
S
Sage Weil 已提交
814 815 816 817 818
	}
	return PTR_ERR(result);
}

static int ceph_mknod(struct inode *dir, struct dentry *dentry,
A
Al Viro 已提交
819
		      umode_t mode, dev_t rdev)
S
Sage Weil 已提交
820
{
821 822
	struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
823
	struct ceph_mds_request *req;
824
	struct ceph_acls_info acls = {};
S
Sage Weil 已提交
825 826 827 828 829
	int err;

	if (ceph_snap(dir) != CEPH_NOSNAP)
		return -EROFS;

830 831 832 833
	if (ceph_quota_is_max_files_exceeded(dir)) {
		err = -EDQUOT;
		goto out;
	}
834

835 836
	err = ceph_pre_init_acls(dir, &mode, &acls);
	if (err < 0)
837
		goto out;
838

A
Al Viro 已提交
839
	dout("mknod in dir %p dentry %p mode 0%ho rdev %d\n",
S
Sage Weil 已提交
840 841 842
	     dir, dentry, mode, rdev);
	req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_MKNOD, USE_AUTH_MDS);
	if (IS_ERR(req)) {
843 844
		err = PTR_ERR(req);
		goto out;
S
Sage Weil 已提交
845 846 847
	}
	req->r_dentry = dget(dentry);
	req->r_num_caps = 2;
848 849
	req->r_parent = dir;
	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
S
Sage Weil 已提交
850 851
	req->r_args.mknod.mode = cpu_to_le32(mode);
	req->r_args.mknod.rdev = cpu_to_le32(rdev);
852
	req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL;
S
Sage Weil 已提交
853
	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
854 855 856 857
	if (acls.pagelist) {
		req->r_pagelist = acls.pagelist;
		acls.pagelist = NULL;
	}
S
Sage Weil 已提交
858 859 860 861
	err = ceph_mdsc_do_request(mdsc, dir, req);
	if (!err && !req->r_reply_info.head->is_dentry)
		err = ceph_handle_notrace_create(dir, dentry);
	ceph_mdsc_put_request(req);
862
out:
G
Guangliang Zhao 已提交
863
	if (!err)
864
		ceph_init_inode_acls(d_inode(dentry), &acls);
865
	else
S
Sage Weil 已提交
866
		d_drop(dentry);
867
	ceph_release_acls_info(&acls);
S
Sage Weil 已提交
868 869 870
	return err;
}

A
Al Viro 已提交
871
static int ceph_create(struct inode *dir, struct dentry *dentry, umode_t mode,
A
Al Viro 已提交
872
		       bool excl)
S
Sage Weil 已提交
873
{
874
	return ceph_mknod(dir, dentry, mode, 0);
S
Sage Weil 已提交
875 876 877 878 879
}

static int ceph_symlink(struct inode *dir, struct dentry *dentry,
			    const char *dest)
{
880 881
	struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
882 883 884 885 886 887
	struct ceph_mds_request *req;
	int err;

	if (ceph_snap(dir) != CEPH_NOSNAP)
		return -EROFS;

888 889 890 891
	if (ceph_quota_is_max_files_exceeded(dir)) {
		err = -EDQUOT;
		goto out;
	}
892

S
Sage Weil 已提交
893 894 895
	dout("symlink in dir %p dentry %p to '%s'\n", dir, dentry, dest);
	req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SYMLINK, USE_AUTH_MDS);
	if (IS_ERR(req)) {
896 897
		err = PTR_ERR(req);
		goto out;
S
Sage Weil 已提交
898
	}
899
	req->r_path2 = kstrdup(dest, GFP_KERNEL);
900 901 902 903 904
	if (!req->r_path2) {
		err = -ENOMEM;
		ceph_mdsc_put_request(req);
		goto out;
	}
905 906
	req->r_parent = dir;
	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
907 908
	req->r_dentry = dget(dentry);
	req->r_num_caps = 2;
909
	req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL;
S
Sage Weil 已提交
910 911 912 913 914
	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
	err = ceph_mdsc_do_request(mdsc, dir, req);
	if (!err && !req->r_reply_info.head->is_dentry)
		err = ceph_handle_notrace_create(dir, dentry);
	ceph_mdsc_put_request(req);
915 916
out:
	if (err)
S
Sage Weil 已提交
917 918 919 920
		d_drop(dentry);
	return err;
}

921
static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
S
Sage Weil 已提交
922
{
923 924
	struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
925
	struct ceph_mds_request *req;
926
	struct ceph_acls_info acls = {};
S
Sage Weil 已提交
927 928 929 930 931 932
	int err = -EROFS;
	int op;

	if (ceph_snap(dir) == CEPH_SNAPDIR) {
		/* mkdir .snap/foo is a MKSNAP */
		op = CEPH_MDS_OP_MKSNAP;
A
Al Viro 已提交
933 934
		dout("mksnap dir %p snap '%pd' dn %p\n", dir,
		     dentry, dentry);
S
Sage Weil 已提交
935
	} else if (ceph_snap(dir) == CEPH_NOSNAP) {
936
		dout("mkdir dir %p dn %p mode 0%ho\n", dir, dentry, mode);
S
Sage Weil 已提交
937 938 939 940
		op = CEPH_MDS_OP_MKDIR;
	} else {
		goto out;
	}
941

942 943
	if (op == CEPH_MDS_OP_MKDIR &&
	    ceph_quota_is_max_files_exceeded(dir)) {
944 945 946 947
		err = -EDQUOT;
		goto out;
	}

948 949 950 951 952
	mode |= S_IFDIR;
	err = ceph_pre_init_acls(dir, &mode, &acls);
	if (err < 0)
		goto out;

S
Sage Weil 已提交
953 954 955 956 957 958 959 960
	req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
	if (IS_ERR(req)) {
		err = PTR_ERR(req);
		goto out;
	}

	req->r_dentry = dget(dentry);
	req->r_num_caps = 2;
961 962
	req->r_parent = dir;
	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
S
Sage Weil 已提交
963
	req->r_args.mkdir.mode = cpu_to_le32(mode);
964
	req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL;
S
Sage Weil 已提交
965
	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
966 967 968 969
	if (acls.pagelist) {
		req->r_pagelist = acls.pagelist;
		acls.pagelist = NULL;
	}
S
Sage Weil 已提交
970
	err = ceph_mdsc_do_request(mdsc, dir, req);
Y
Yan, Zheng 已提交
971 972 973
	if (!err &&
	    !req->r_reply_info.head->is_target &&
	    !req->r_reply_info.head->is_dentry)
S
Sage Weil 已提交
974 975 976
		err = ceph_handle_notrace_create(dir, dentry);
	ceph_mdsc_put_request(req);
out:
977
	if (!err)
978
		ceph_init_inode_acls(d_inode(dentry), &acls);
979
	else
S
Sage Weil 已提交
980
		d_drop(dentry);
981
	ceph_release_acls_info(&acls);
S
Sage Weil 已提交
982 983 984 985 986 987
	return err;
}

static int ceph_link(struct dentry *old_dentry, struct inode *dir,
		     struct dentry *dentry)
{
988 989
	struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
	struct ceph_mds_request *req;
	int err;

	if (ceph_snap(dir) != CEPH_NOSNAP)
		return -EROFS;

	dout("link in dir %p old_dentry %p dentry %p\n", dir,
	     old_dentry, dentry);
	req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LINK, USE_AUTH_MDS);
	if (IS_ERR(req)) {
		d_drop(dentry);
		return PTR_ERR(req);
	}
	req->r_dentry = dget(dentry);
	req->r_num_caps = 2;
1005
	req->r_old_dentry = dget(old_dentry);
1006 1007
	req->r_parent = dir;
	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
S
Sage Weil 已提交
1008 1009
	req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
1010
	/* release LINK_SHARED on source inode (mds will lock it) */
1011
	req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
S
Sage Weil 已提交
1012
	err = ceph_mdsc_do_request(mdsc, dir, req);
1013
	if (err) {
S
Sage Weil 已提交
1014
		d_drop(dentry);
1015
	} else if (!req->r_reply_info.head->is_dentry) {
1016 1017
		ihold(d_inode(old_dentry));
		d_instantiate(dentry, d_inode(old_dentry));
1018
	}
S
Sage Weil 已提交
1019 1020 1021 1022 1023 1024 1025 1026 1027
	ceph_mdsc_put_request(req);
	return err;
}

/*
 * rmdir and unlink are differ only by the metadata op code
 */
static int ceph_unlink(struct inode *dir, struct dentry *dentry)
{
1028 1029
	struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
1030
	struct inode *inode = d_inode(dentry);
S
Sage Weil 已提交
1031 1032 1033 1034 1035 1036
	struct ceph_mds_request *req;
	int err = -EROFS;
	int op;

	if (ceph_snap(dir) == CEPH_SNAPDIR) {
		/* rmdir .snap/foo is RMSNAP */
A
Al Viro 已提交
1037
		dout("rmsnap dir %p '%pd' dn %p\n", dir, dentry, dentry);
S
Sage Weil 已提交
1038 1039 1040 1041
		op = CEPH_MDS_OP_RMSNAP;
	} else if (ceph_snap(dir) == CEPH_NOSNAP) {
		dout("unlink/rmdir dir %p dn %p inode %p\n",
		     dir, dentry, inode);
1042
		op = d_is_dir(dentry) ?
S
Sage Weil 已提交
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
			CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK;
	} else
		goto out;
	req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
	if (IS_ERR(req)) {
		err = PTR_ERR(req);
		goto out;
	}
	req->r_dentry = dget(dentry);
	req->r_num_caps = 2;
1053 1054
	req->r_parent = dir;
	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
S
Sage Weil 已提交
1055 1056
	req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
1057
	req->r_inode_drop = ceph_drop_caps_for_unlink(inode);
S
Sage Weil 已提交
1058 1059 1060 1061 1062 1063 1064 1065 1066
	err = ceph_mdsc_do_request(mdsc, dir, req);
	if (!err && !req->r_reply_info.head->is_dentry)
		d_delete(dentry);
	ceph_mdsc_put_request(req);
out:
	return err;
}

static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
1067 1068
		       struct inode *new_dir, struct dentry *new_dentry,
		       unsigned int flags)
S
Sage Weil 已提交
1069
{
1070 1071
	struct ceph_fs_client *fsc = ceph_sb_to_client(old_dir->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
S
Sage Weil 已提交
1072
	struct ceph_mds_request *req;
Y
Yan, Zheng 已提交
1073
	int op = CEPH_MDS_OP_RENAME;
S
Sage Weil 已提交
1074 1075
	int err;

1076 1077 1078
	if (flags)
		return -EINVAL;

S
Sage Weil 已提交
1079 1080
	if (ceph_snap(old_dir) != ceph_snap(new_dir))
		return -EXDEV;
Y
Yan, Zheng 已提交
1081 1082 1083 1084 1085 1086
	if (ceph_snap(old_dir) != CEPH_NOSNAP) {
		if (old_dir == new_dir && ceph_snap(old_dir) == CEPH_SNAPDIR)
			op = CEPH_MDS_OP_RENAMESNAP;
		else
			return -EROFS;
	}
1087 1088 1089 1090 1091
	/* don't allow cross-quota renames */
	if ((old_dir != new_dir) &&
	    (!ceph_quota_is_same_realm(old_dir, new_dir)))
		return -EXDEV;

S
Sage Weil 已提交
1092 1093
	dout("rename dir %p dentry %p to dir %p dentry %p\n",
	     old_dir, old_dentry, new_dir, new_dentry);
Y
Yan, Zheng 已提交
1094
	req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
S
Sage Weil 已提交
1095 1096
	if (IS_ERR(req))
		return PTR_ERR(req);
1097
	ihold(old_dir);
S
Sage Weil 已提交
1098 1099 1100
	req->r_dentry = dget(new_dentry);
	req->r_num_caps = 2;
	req->r_old_dentry = dget(old_dentry);
1101
	req->r_old_dentry_dir = old_dir;
1102 1103
	req->r_parent = new_dir;
	set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
S
Sage Weil 已提交
1104 1105 1106 1107 1108
	req->r_old_dentry_drop = CEPH_CAP_FILE_SHARED;
	req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL;
	req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
	req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
	/* release LINK_RDCACHE on source inode (mds will lock it) */
1109
	req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
1110 1111 1112 1113
	if (d_really_is_positive(new_dentry)) {
		req->r_inode_drop =
			ceph_drop_caps_for_unlink(d_inode(new_dentry));
	}
S
Sage Weil 已提交
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
	err = ceph_mdsc_do_request(mdsc, old_dir, req);
	if (!err && !req->r_reply_info.head->is_dentry) {
		/*
		 * Normally d_move() is done by fill_trace (called by
		 * do_request, above).  If there is no trace, we need
		 * to do it here.
		 */
		d_move(old_dentry, new_dentry);
	}
	ceph_mdsc_put_request(req);
	return err;
}

1127 1128 1129 1130 1131 1132
/*
 * Ensure a dentry lease will no longer revalidate.
 */
void ceph_invalidate_dentry_lease(struct dentry *dentry)
{
	spin_lock(&dentry->d_lock);
M
Miklos Szeredi 已提交
1133
	ceph_dentry(dentry)->time = jiffies;
1134 1135 1136
	ceph_dentry(dentry)->lease_shared_gen = 0;
	spin_unlock(&dentry->d_lock);
}
S
Sage Weil 已提交
1137 1138 1139 1140 1141

/*
 * Check if dentry lease is valid.  If not, delete the lease.  Try to
 * renew if the least is more than half up.
 */
1142 1143
static int dentry_lease_is_valid(struct dentry *dentry, unsigned int flags,
				 struct inode *dir)
S
Sage Weil 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
{
	struct ceph_dentry_info *di;
	struct ceph_mds_session *s;
	int valid = 0;
	u32 gen;
	unsigned long ttl;
	struct ceph_mds_session *session = NULL;
	u32 seq = 0;

	spin_lock(&dentry->d_lock);
	di = ceph_dentry(dentry);
1155
	if (di && di->lease_session) {
S
Sage Weil 已提交
1156
		s = di->lease_session;
1157
		spin_lock(&s->s_gen_ttl_lock);
S
Sage Weil 已提交
1158 1159
		gen = s->s_cap_gen;
		ttl = s->s_cap_ttl;
1160
		spin_unlock(&s->s_gen_ttl_lock);
S
Sage Weil 已提交
1161 1162

		if (di->lease_gen == gen &&
M
Miklos Szeredi 已提交
1163
		    time_before(jiffies, di->time) &&
S
Sage Weil 已提交
1164 1165 1166 1167
		    time_before(jiffies, ttl)) {
			valid = 1;
			if (di->lease_renew_after &&
			    time_after(jiffies, di->lease_renew_after)) {
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
				/*
				 * We should renew. If we're in RCU walk mode
				 * though, we can't do that so just return
				 * -ECHILD.
				 */
				if (flags & LOOKUP_RCU) {
					valid = -ECHILD;
				} else {
					session = ceph_get_mds_session(s);
					seq = di->lease_seq;
					di->lease_renew_after = 0;
					di->lease_renew_from = jiffies;
				}
S
Sage Weil 已提交
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
			}
		}
	}
	spin_unlock(&dentry->d_lock);

	if (session) {
		ceph_mdsc_lease_send_msg(session, dir, dentry,
					 CEPH_MDS_LEASE_RENEW, seq);
		ceph_put_mds_session(session);
	}
	dout("dentry_lease_is_valid - dentry %p = %d\n", dentry, valid);
	return valid;
}

/*
 * Check if directory-wide content lease/cap is valid.
 */
static int dir_lease_is_valid(struct inode *dir, struct dentry *dentry)
{
	struct ceph_inode_info *ci = ceph_inode(dir);
	struct ceph_dentry_info *di = ceph_dentry(dentry);
	int valid = 0;

1204
	spin_lock(&ci->i_ceph_lock);
1205
	if (atomic_read(&ci->i_shared_gen) == di->lease_shared_gen)
S
Sage Weil 已提交
1206
		valid = __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1);
1207
	spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
1208
	dout("dir_lease_is_valid dir %p v%u dentry %p v%u = %d\n",
1209 1210
	     dir, (unsigned)atomic_read(&ci->i_shared_gen),
	     dentry, (unsigned)di->lease_shared_gen, valid);
S
Sage Weil 已提交
1211 1212 1213 1214 1215 1216
	return valid;
}

/*
 * Check if cached dentry can be trusted.
 */
1217
static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags)
S
Sage Weil 已提交
1218
{
1219
	int valid = 0;
1220
	struct dentry *parent;
1221 1222
	struct inode *dir;

1223
	if (flags & LOOKUP_RCU) {
1224
		parent = READ_ONCE(dentry->d_parent);
1225 1226 1227 1228 1229 1230 1231
		dir = d_inode_rcu(parent);
		if (!dir)
			return -ECHILD;
	} else {
		parent = dget_parent(dentry);
		dir = d_inode(parent);
	}
1232

A
Al Viro 已提交
1233
	dout("d_revalidate %p '%pd' inode %p offset %lld\n", dentry,
1234
	     dentry, d_inode(dentry), ceph_dentry(dentry)->offset);
S
Sage Weil 已提交
1235 1236 1237

	/* always trust cached snapped dentries, snapdir dentry */
	if (ceph_snap(dir) != CEPH_NOSNAP) {
A
Al Viro 已提交
1238
		dout("d_revalidate %p '%pd' inode %p is SNAPPED\n", dentry,
1239
		     dentry, d_inode(dentry));
1240
		valid = 1;
1241 1242
	} else if (d_really_is_positive(dentry) &&
		   ceph_snap(d_inode(dentry)) == CEPH_SNAPDIR) {
1243
		valid = 1;
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
	} else {
		valid = dentry_lease_is_valid(dentry, flags, dir);
		if (valid == -ECHILD)
			return valid;
		if (valid || dir_lease_is_valid(dir, dentry)) {
			if (d_really_is_positive(dentry))
				valid = ceph_is_any_caps(d_inode(dentry));
			else
				valid = 1;
		}
S
Sage Weil 已提交
1254 1255
	}

1256 1257 1258 1259
	if (!valid) {
		struct ceph_mds_client *mdsc =
			ceph_sb_to_client(dir->i_sb)->mdsc;
		struct ceph_mds_request *req;
1260 1261
		int op, err;
		u32 mask;
1262

1263 1264 1265
		if (flags & LOOKUP_RCU)
			return -ECHILD;

1266
		op = ceph_snap(dir) == CEPH_SNAPDIR ?
1267
			CEPH_MDS_OP_LOOKUPSNAP : CEPH_MDS_OP_LOOKUP;
1268 1269 1270
		req = ceph_mdsc_create_request(mdsc, op, USE_ANY_MDS);
		if (!IS_ERR(req)) {
			req->r_dentry = dget(dentry);
1271 1272
			req->r_num_caps = 2;
			req->r_parent = dir;
1273 1274 1275 1276

			mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED;
			if (ceph_security_xattr_wanted(dir))
				mask |= CEPH_CAP_XATTR_SHARED;
1277
			req->r_args.getattr.mask = cpu_to_le32(mask);
1278 1279

			err = ceph_mdsc_do_request(mdsc, NULL, req);
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
			switch (err) {
			case 0:
				if (d_really_is_positive(dentry) &&
				    d_inode(dentry) == req->r_target_inode)
					valid = 1;
				break;
			case -ENOENT:
				if (d_really_is_negative(dentry))
					valid = 1;
				/* Fallthrough */
			default:
				break;
1292 1293 1294 1295 1296 1297 1298
			}
			ceph_mdsc_put_request(req);
			dout("d_revalidate %p lookup result=%d\n",
			     dentry, err);
		}
	}

1299
	dout("d_revalidate %p %s\n", dentry, valid ? "valid" : "invalid");
1300
	if (valid) {
1301
		ceph_dentry_lru_touch(dentry);
1302 1303 1304
	} else {
		ceph_dir_clear_complete(dir);
	}
1305

1306 1307
	if (!(flags & LOOKUP_RCU))
		dput(parent);
1308
	return valid;
S
Sage Weil 已提交
1309 1310 1311
}

/*
1312
 * Release our ceph_dentry_info.
S
Sage Weil 已提交
1313
 */
1314
static void ceph_d_release(struct dentry *dentry)
S
Sage Weil 已提交
1315 1316 1317
{
	struct ceph_dentry_info *di = ceph_dentry(dentry);

1318
	dout("d_release %p\n", dentry);
1319
	ceph_dentry_lru_del(dentry);
1320 1321 1322 1323 1324

	spin_lock(&dentry->d_lock);
	dentry->d_fsdata = NULL;
	spin_unlock(&dentry->d_lock);

1325 1326 1327
	if (di->lease_session)
		ceph_put_mds_session(di->lease_session);
	kmem_cache_free(ceph_dentry_cachep, di);
S
Sage Weil 已提交
1328 1329
}

1330 1331 1332 1333 1334 1335 1336 1337
/*
 * When the VFS prunes a dentry from the cache, we need to clear the
 * complete flag on the parent directory.
 *
 * Called under dentry->d_lock.
 */
static void ceph_d_prune(struct dentry *dentry)
{
1338 1339 1340 1341
	struct ceph_inode_info *dir_ci;
	struct ceph_dentry_info *di;

	dout("ceph_d_prune %pd %p\n", dentry, dentry);
1342 1343

	/* do we have a valid parent? */
1344
	if (IS_ROOT(dentry))
1345 1346
		return;

1347 1348 1349
	/* we hold d_lock, so d_parent is stable */
	dir_ci = ceph_inode(d_inode(dentry->d_parent));
	if (dir_ci->i_vino.snap == CEPH_SNAPDIR)
1350
		return;
S
Sage Weil 已提交
1351

1352 1353
	/* who calls d_delete() should also disable dcache readdir */
	if (d_really_is_negative(dentry))
A
Al Viro 已提交
1354 1355
		return;

1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
	/* d_fsdata does not get cleared until d_release */
	if (!d_unhashed(dentry)) {
		__ceph_dir_clear_complete(dir_ci);
		return;
	}

	/* Disable dcache readdir just in case that someone called d_drop()
	 * or d_invalidate(), but MDS didn't revoke CEPH_CAP_FILE_SHARED
	 * properly (dcache readdir is still enabled) */
	di = ceph_dentry(dentry);
	if (di->offset > 0 &&
	    di->lease_shared_gen == atomic_read(&dir_ci->i_shared_gen))
		__ceph_dir_clear_ordered(dir_ci);
1369
}
S
Sage Weil 已提交
1370 1371 1372 1373 1374 1375 1376 1377

/*
 * read() on a dir.  This weird interface hack only works if mounted
 * with '-o dirstat'.
 */
static ssize_t ceph_read_dir(struct file *file, char __user *buf, size_t size,
			     loff_t *ppos)
{
C
Chengguang Xu 已提交
1378
	struct ceph_dir_file_info *dfi = file->private_data;
A
Al Viro 已提交
1379
	struct inode *inode = file_inode(file);
S
Sage Weil 已提交
1380 1381
	struct ceph_inode_info *ci = ceph_inode(inode);
	int left;
1382
	const int bufsize = 1024;
S
Sage Weil 已提交
1383

1384
	if (!ceph_test_mount_opt(ceph_sb_to_client(inode->i_sb), DIRSTAT))
S
Sage Weil 已提交
1385 1386
		return -EISDIR;

C
Chengguang Xu 已提交
1387 1388 1389
	if (!dfi->dir_info) {
		dfi->dir_info = kmalloc(bufsize, GFP_KERNEL);
		if (!dfi->dir_info)
S
Sage Weil 已提交
1390
			return -ENOMEM;
C
Chengguang Xu 已提交
1391 1392
		dfi->dir_info_len =
			snprintf(dfi->dir_info, bufsize,
S
Sage Weil 已提交
1393 1394 1395 1396 1397 1398 1399
				"entries:   %20lld\n"
				" files:    %20lld\n"
				" subdirs:  %20lld\n"
				"rentries:  %20lld\n"
				" rfiles:   %20lld\n"
				" rsubdirs: %20lld\n"
				"rbytes:    %20lld\n"
1400
				"rctime:    %10lld.%09ld\n",
S
Sage Weil 已提交
1401 1402 1403 1404 1405 1406 1407
				ci->i_files + ci->i_subdirs,
				ci->i_files,
				ci->i_subdirs,
				ci->i_rfiles + ci->i_rsubdirs,
				ci->i_rfiles,
				ci->i_rsubdirs,
				ci->i_rbytes,
1408 1409
				ci->i_rctime.tv_sec,
				ci->i_rctime.tv_nsec);
S
Sage Weil 已提交
1410 1411
	}

C
Chengguang Xu 已提交
1412
	if (*ppos >= dfi->dir_info_len)
S
Sage Weil 已提交
1413
		return 0;
C
Chengguang Xu 已提交
1414 1415
	size = min_t(unsigned, size, dfi->dir_info_len-*ppos);
	left = copy_to_user(buf, dfi->dir_info + *ppos, size);
S
Sage Weil 已提交
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
	if (left == size)
		return -EFAULT;
	*ppos += (size - left);
	return size - left;
}

/*
 * We maintain a private dentry LRU.
 *
 * FIXME: this needs to be changed to a per-mds lru to be useful.
 */
void ceph_dentry_lru_add(struct dentry *dn)
{
	struct ceph_dentry_info *di = ceph_dentry(dn);
	struct ceph_mds_client *mdsc;

A
Al Viro 已提交
1432
	dout("dentry_lru_add %p %p '%pd'\n", di, dn, dn);
1433 1434 1435 1436 1437
	mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
	spin_lock(&mdsc->dentry_lru_lock);
	list_add_tail(&di->lru, &mdsc->dentry_lru);
	mdsc->num_dentry++;
	spin_unlock(&mdsc->dentry_lru_lock);
S
Sage Weil 已提交
1438 1439 1440 1441 1442 1443 1444
}

void ceph_dentry_lru_touch(struct dentry *dn)
{
	struct ceph_dentry_info *di = ceph_dentry(dn);
	struct ceph_mds_client *mdsc;

A
Al Viro 已提交
1445 1446
	dout("dentry_lru_touch %p %p '%pd' (offset %lld)\n", di, dn, dn,
	     di->offset);
1447 1448 1449 1450
	mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
	spin_lock(&mdsc->dentry_lru_lock);
	list_move_tail(&di->lru, &mdsc->dentry_lru);
	spin_unlock(&mdsc->dentry_lru_lock);
S
Sage Weil 已提交
1451 1452 1453 1454 1455 1456 1457
}

void ceph_dentry_lru_del(struct dentry *dn)
{
	struct ceph_dentry_info *di = ceph_dentry(dn);
	struct ceph_mds_client *mdsc;

A
Al Viro 已提交
1458
	dout("dentry_lru_del %p %p '%pd'\n", di, dn, dn);
1459 1460 1461 1462 1463
	mdsc = ceph_sb_to_client(dn->d_sb)->mdsc;
	spin_lock(&mdsc->dentry_lru_lock);
	list_del_init(&di->lru);
	mdsc->num_dentry--;
	spin_unlock(&mdsc->dentry_lru_lock);
S
Sage Weil 已提交
1464 1465
}

S
Sage Weil 已提交
1466 1467 1468 1469
/*
 * Return name hash for a given dentry.  This is dependent on
 * the parent directory's hash function.
 */
1470
unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn)
S
Sage Weil 已提交
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
{
	struct ceph_inode_info *dci = ceph_inode(dir);

	switch (dci->i_dir_layout.dl_dir_hash) {
	case 0:	/* for backward compat */
	case CEPH_STR_HASH_LINUX:
		return dn->d_name.hash;

	default:
		return ceph_str_hash(dci->i_dir_layout.dl_dir_hash,
				     dn->d_name.name, dn->d_name.len);
	}
}

S
Sage Weil 已提交
1485 1486
const struct file_operations ceph_dir_fops = {
	.read = ceph_read_dir,
A
Al Viro 已提交
1487
	.iterate = ceph_readdir,
S
Sage Weil 已提交
1488 1489 1490 1491
	.llseek = ceph_dir_llseek,
	.open = ceph_open,
	.release = ceph_release,
	.unlocked_ioctl = ceph_ioctl,
Y
Yan, Zheng 已提交
1492
	.fsync = ceph_fsync,
1493 1494
	.lock = ceph_lock,
	.flock = ceph_flock,
S
Sage Weil 已提交
1495 1496
};

1497 1498 1499 1500 1501 1502 1503
const struct file_operations ceph_snapdir_fops = {
	.iterate = ceph_readdir,
	.llseek = ceph_dir_llseek,
	.open = ceph_open,
	.release = ceph_release,
};

S
Sage Weil 已提交
1504 1505 1506 1507 1508 1509
const struct inode_operations ceph_dir_iops = {
	.lookup = ceph_lookup,
	.permission = ceph_permission,
	.getattr = ceph_getattr,
	.setattr = ceph_setattr,
	.listxattr = ceph_listxattr,
G
Guangliang Zhao 已提交
1510
	.get_acl = ceph_get_acl,
S
Sage Weil 已提交
1511
	.set_acl = ceph_set_acl,
S
Sage Weil 已提交
1512 1513 1514 1515 1516 1517 1518 1519
	.mknod = ceph_mknod,
	.symlink = ceph_symlink,
	.mkdir = ceph_mkdir,
	.link = ceph_link,
	.unlink = ceph_unlink,
	.rmdir = ceph_unlink,
	.rename = ceph_rename,
	.create = ceph_create,
1520
	.atomic_open = ceph_atomic_open,
S
Sage Weil 已提交
1521 1522
};

1523 1524 1525 1526 1527 1528
const struct inode_operations ceph_snapdir_iops = {
	.lookup = ceph_lookup,
	.permission = ceph_permission,
	.getattr = ceph_getattr,
	.mkdir = ceph_mkdir,
	.rmdir = ceph_unlink,
Y
Yan, Zheng 已提交
1529
	.rename = ceph_rename,
1530 1531
};

S
Sage Weil 已提交
1532
const struct dentry_operations ceph_dentry_ops = {
S
Sage Weil 已提交
1533
	.d_revalidate = ceph_d_revalidate,
1534
	.d_release = ceph_d_release,
1535
	.d_prune = ceph_d_prune,
A
Al Viro 已提交
1536
	.d_init = ceph_d_init,
S
Sage Weil 已提交
1537
};