Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0081bd83 authored by Yan, Zheng's avatar Yan, Zheng Committed by Sage Weil
Browse files

ceph: check directory's completeness before emitting directory entry

parent a30be7cb
Loading
Loading
Loading
Loading
+12 −10
Original line number Original line Diff line number Diff line
@@ -182,9 +182,16 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
	spin_unlock(&dentry->d_lock);
	spin_unlock(&dentry->d_lock);
	spin_unlock(&parent->d_lock);
	spin_unlock(&parent->d_lock);


	/* make sure a dentry wasn't dropped while we didn't have parent lock */
	if (!ceph_dir_is_complete(dir)) {
		dout(" lost dir complete on %p; falling back to mds\n", dir);
		dput(dentry);
		err = -EAGAIN;
		goto out;
	}

	dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
	dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
	     dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
	     dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
	ctx->pos = di->offset;
	if (!dir_emit(ctx, dentry->d_name.name,
	if (!dir_emit(ctx, dentry->d_name.name,
		      dentry->d_name.len,
		      dentry->d_name.len,
		      ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
		      ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
@@ -198,19 +205,12 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
		return 0;
		return 0;
	}
	}


	ctx->pos = di->offset + 1;

	if (last)
	if (last)
		dput(last);
		dput(last);
	last = dentry;
	last = dentry;


	ctx->pos++;

	/* make sure a dentry wasn't dropped while we didn't have parent lock */
	if (!ceph_dir_is_complete(dir)) {
		dout(" lost dir complete on %p; falling back to mds\n", dir);
		err = -EAGAIN;
		goto out;
	}

	spin_lock(&parent->d_lock);
	spin_lock(&parent->d_lock);
	p = p->prev;	/* advance to next dentry */
	p = p->prev;	/* advance to next dentry */
	goto more;
	goto more;
@@ -296,6 +296,8 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
		err = __dcache_readdir(file, ctx, shared_gen);
		err = __dcache_readdir(file, ctx, shared_gen);
		if (err != -EAGAIN)
		if (err != -EAGAIN)
			return err;
			return err;
		frag = fpos_frag(ctx->pos);
		off = fpos_off(ctx->pos);
	} else {
	} else {
		spin_unlock(&ci->i_ceph_lock);
		spin_unlock(&ci->i_ceph_lock);
	}
	}