Skip to content

Commit b50c2de

Browse files
ukernelidryomov
authored andcommitted
ceph: choose readdir frag based on previous readdir reply
The dirfragtree is lazily updated, it's not always accurate. Infinite loops happens in following circumstance. - client send request to read frag A - frag A has been fragmented into frag B and C. So mds fills the reply with contents of frag B - client wants to read next frag C. ceph_choose_frag(frag value of C) return frag A. The fix is using previous readdir reply to calculate next readdir frag when possible. Signed-off-by: "Yan, Zheng" <zyan@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent e010dd0 commit b50c2de

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

‎fs/ceph/dir.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
294294
struct ceph_mds_client *mdsc = fsc->mdsc;
295295
int i;
296296
int err;
297-
u32 ftype;
297+
unsigned frag = -1;
298298
struct ceph_mds_reply_info_parsed *rinfo;
299299

300300
dout("readdir %p file %p pos %llx\n", inode, file, ctx->pos);
@@ -341,7 +341,6 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
341341
/* do we have the correct frag content buffered? */
342342
if (need_send_readdir(fi, ctx->pos)) {
343343
struct ceph_mds_request *req;
344-
unsigned frag;
345344
int op = ceph_snap(inode) == CEPH_SNAPDIR ?
346345
CEPH_MDS_OP_LSSNAP : CEPH_MDS_OP_READDIR;
347346

@@ -352,8 +351,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
352351
}
353352

354353
if (is_hash_order(ctx->pos)) {
355-
frag = ceph_choose_frag(ci, fpos_hash(ctx->pos),
356-
NULL, NULL);
354+
/* fragtree isn't always accurate. choose frag
355+
* based on previous reply when possible. */
356+
if (frag == (unsigned)-1)
357+
frag = ceph_choose_frag(ci, fpos_hash(ctx->pos),
358+
NULL, NULL);
357359
} else {
358360
frag = fpos_frag(ctx->pos);
359361
}
@@ -480,6 +482,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
480482
struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i;
481483
struct ceph_vino vino;
482484
ino_t ino;
485+
u32 ftype;
483486

484487
BUG_ON(rde->offset < ctx->pos);
485488

@@ -502,15 +505,17 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
502505
ctx->pos++;
503506
}
504507

508+
ceph_mdsc_put_request(fi->last_readdir);
509+
fi->last_readdir = NULL;
510+
505511
if (fi->next_offset > 2) {
506-
ceph_mdsc_put_request(fi->last_readdir);
507-
fi->last_readdir = NULL;
512+
frag = fi->frag;
508513
goto more;
509514
}
510515

511516
/* more frags? */
512517
if (!ceph_frag_is_rightmost(fi->frag)) {
513-
unsigned frag = ceph_frag_next(fi->frag);
518+
frag = ceph_frag_next(fi->frag);
514519
if (is_hash_order(ctx->pos)) {
515520
loff_t new_pos = ceph_make_fpos(ceph_frag_value(frag),
516521
fi->next_offset, true);

0 commit comments

Comments
 (0)