From 93258b9d93611e75b79c30f3ddfc2c9c21f25917 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Fri, 9 Apr 2021 12:53:07 +0800 Subject: [PATCH] LU-14597 flr: allow multiple primary mirrors Users can set "prefer" flag on any mirror/component, so the IO should not report error if multiple mirrors are encountered. Rename lod_mirror_entry::lme_primary to lme_prefer to avoid confusion. Signed-off-by: Bobi Jam Change-Id: I45748e56e38985a0d9028792ba3d976a4e03efb8 Reviewed-on: https://review.whamcloud.com/43247 Reviewed-by: Wang Shilong Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Jian Yu --- lustre/lod/lod_internal.h | 2 +- lustre/lod/lod_lov.c | 4 ++-- lustre/lod/lod_object.c | 19 ++++++------------- lustre/tests/sanity-flr.sh | 25 +++++++++++++++++++++++-- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 7a913a0..241a77c 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -191,7 +191,7 @@ struct lod_default_striping { struct lod_mirror_entry { __u16 lme_stale:1, - lme_primary:1; + lme_prefer:1; /* mirror id */ __u16 lme_id; /* start,end index of this mirror in ldo_comp_entries */ diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index 849414b..9dacc8b 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -607,7 +607,7 @@ int lod_fill_mirrors(struct lod_object *lo) if (mirror_id_of(lod_comp->llc_id) == mirror_id) { lo->ldo_mirrors[mirror_idx].lme_stale |= stale; - lo->ldo_mirrors[mirror_idx].lme_primary |= preferred; + lo->ldo_mirrors[mirror_idx].lme_prefer |= preferred; lo->ldo_mirrors[mirror_idx].lme_end = i; continue; } @@ -621,7 +621,7 @@ int lod_fill_mirrors(struct lod_object *lo) lo->ldo_mirrors[mirror_idx].lme_id = mirror_id; lo->ldo_mirrors[mirror_idx].lme_stale = stale; - lo->ldo_mirrors[mirror_idx].lme_primary = preferred; + lo->ldo_mirrors[mirror_idx].lme_prefer = preferred; lo->ldo_mirrors[mirror_idx].lme_start = i; lo->ldo_mirrors[mirror_idx].lme_end = i; } diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index a1cdfc7..f24539c 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -7336,7 +7336,7 @@ static int lod_primary_pick(const struct lu_env *env, struct lod_object *lo, } /* 2nd pick is for the primary mirror containing unavail OST */ - if (lo->ldo_mirrors[index].lme_primary && second_pick < 0) + if (lo->ldo_mirrors[index].lme_prefer && second_pick < 0) second_pick = index; /* 3rd pick is for non-primary mirror containing unavail OST */ @@ -7347,7 +7347,7 @@ static int lod_primary_pick(const struct lu_env *env, struct lod_object *lo, * we found a non-primary 1st pick, we'd like to find a * potential pirmary mirror. */ - if (picked >= 0 && !lo->ldo_mirrors[index].lme_primary) + if (picked >= 0 && !lo->ldo_mirrors[index].lme_prefer) continue; /* check the availability of OSTs */ @@ -7384,7 +7384,7 @@ static int lod_primary_pick(const struct lu_env *env, struct lod_object *lo, * primary with all OSTs are available, this is the perfect * 1st pick. */ - if (lo->ldo_mirrors[index].lme_primary) + if (lo->ldo_mirrors[index].lme_prefer) break; } /* for all mirrors */ @@ -7628,22 +7628,15 @@ static int lod_declare_update_write_pending(const struct lu_env *env, LASSERT(mlc->mlc_opc == MD_LAYOUT_WRITE || mlc->mlc_opc == MD_LAYOUT_RESYNC); - /* look for the primary mirror */ + /* look for the first preferred mirror */ for (i = 0; i < lo->ldo_mirror_count; i++) { if (lo->ldo_mirrors[i].lme_stale) continue; - if (lo->ldo_mirrors[i].lme_primary == 0) + if (lo->ldo_mirrors[i].lme_prefer == 0) continue; - if (unlikely(primary >= 0)) { - CERROR(DFID " has multiple primary: %u / %u\n", - PFID(lod_object_fid(lo)), - lo->ldo_mirrors[i].lme_id, - lo->ldo_mirrors[primary].lme_id); - RETURN(-EIO); - } - primary = i; + break; } if (primary < 0) { /* no primary, use any in-sync */ diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index b15e70f..531b5a05 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -1894,7 +1894,7 @@ write_file_43() { [ $flags = wp ] || error "file mirror state $flags != wp" } -test_43() { +test_43a() { [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return local tf=$DIR/$tfile @@ -1941,7 +1941,28 @@ test_43() { verify_comp_attr lcme_flags $tf 0x20002 init,stale verify_comp_attr lcme_flags $tf 0x30003 init,stale } -run_test 43 "mirror pick on write" +run_test 43a "mirror pick on write" + +test_43b() { + local tf=$DIR/$tdir/$tfile + + test_mkdir $DIR/$tdir + rm -f $tf + + # create 3 mirrors FLR file, the first 2 mirrors are preferred + $LFS setstripe -N -Eeof --flags=prefer -N -Eeof --flags=prefer \ + -N -Eeof $tf || error "create 3 mirrors file $tf failed" + verify_flr_state $tf "ro" + + echo " ** write to $tf" + dd if=/dev/zero of=$tf bs=1M count=1 || error "write $tf failed" + verify_flr_state $tf "wp" + + echo " ** resync $tf" + $LFS mirror resync $tf || error "resync $tf failed" + verify_flr_state $tf "ro" +} +run_test 43b "allow writing to multiple preferred mirror file" test_44() { [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return -- 1.8.3.1