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)
+ continue;
- LASSERTF(primary < 0, DFID " has multiple primary: %u / %u\n",
- PFID(lod_object_fid(lo)),
- lo->ldo_mirrors[i].lme_id,
- lo->ldo_mirrors[primary].lme_id);
+ 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;
}
if (primary < 0) {
- CERROR(DFID ": doesn't have a primary mirror\n",
- PFID(lod_object_fid(lo)));
- GOTO(out, rc = -ENODATA);
+ /* no primary, use any in-sync */
+ for (i = 0; i < lo->ldo_mirror_count; i++) {
+ if (lo->ldo_mirrors[i].lme_stale)
+ continue;
+ primary = i;
+ break;
+ }
+ if (primary < 0) {
+ CERROR(DFID ": doesn't have a primary mirror\n",
+ PFID(lod_object_fid(lo)));
+ GOTO(out, rc = -ENODATA);
+ }
}
CDEBUG(D_LAYOUT, DFID": found primary %u\n",
}
run_test 206 "lfs setstripe -pool .. --comp-flags=.. "
+test_207() {
+ local file=$DIR/$tfile
+ local tmpfile=$DIR/$tfile-tt
+
+ [ $MDS1_VERSION -lt $(version_code 2.14.50) ] &&
+ skip "Need MDS version at least 2.14.50"
+
+ stack_trap "rm -f $tmpfile $file"
+
+ # generate data for verification
+ dd if=/dev/urandom of=$tmpfile bs=1M count=1 ||
+ error "can't generate file with random data"
+
+ # create a mirrored file with one stale replica
+ $LFS mirror create -N -S 4M -c 2 -N -S 1M -c -1 $file ||
+ error "create mirrored file $file failed"
+ get_mirror_ids $file
+ echo "mirror IDs: ${mirror_array[@]}"
+
+ dd if=$tmpfile of=$file bs=1M || error "can't copy"
+ get_mirror_ids $file
+ echo "mirror IDs: ${mirror_array[@]}"
+
+ drop_client_cache
+ cmp $tmpfile $file || error "files don't match"
+ get_mirror_ids $file
+ echo "mirror IDs: ${mirror_array[@]}"
+
+ # mirror creation should work fine
+ $LFS mirror extend -N -S 8M -c -1 $file ||
+ error "mirror extend $file failed"
+
+ get_mirror_ids $file
+ echo "mirror IDs: ${mirror_array[@]}"
+
+ drop_client_cache
+ $LFS mirror verify -v $file || error "verification failed"
+ cmp $tmpfile $file || error "files don't match"
+}
+run_test 207 "create another replica with existing out-of-sync one"
+
complete $SECONDS
check_and_cleanup_lustre
exit_status