offset += le32_to_cpu(lcme->lcme_size);
- if (mirror_count == 1) {
- /* new mirrored file, create new mirror ID */
+ if (mirror_count == 1 &&
+ mirror_id_of(le32_to_cpu(lcme->lcme_id)) == 0) {
+ /* Add mirror from a non-flr file, create new mirror ID.
+ * Otherwise, keep existing mirror's component ID, used
+ * for mirror extension.
+ */
id = pflr_id(1, i + 1);
lcme->lcme_id = cpu_to_le32(id);
}
LASSERT(lo->ldo_comp_cnt != 0 && lo->ldo_comp_entries != NULL);
- mirror_id = lo->ldo_mirror_count > 1 ? 1 : 0;
+ mirror_id = 0; /* non-flr file's mirror_id is 0 */
+ if (lo->ldo_mirror_count > 1) {
+ for (i = 0; i < lo->ldo_comp_cnt; i++) {
+ lod_comp = &lo->ldo_comp_entries[i];
+ if (lod_comp->llc_id != LCME_ID_INVAL &&
+ mirror_id_of(lod_comp->llc_id) > mirror_id)
+ mirror_id = mirror_id_of(lod_comp->llc_id);
+ }
+ }
/* create all underlying objects */
for (i = 0; i < lo->ldo_comp_cnt; i++) {
lod_comp = &lo->ldo_comp_entries[i];
- if (lod_comp->llc_extent.e_start == 0 && i > 0) /* new mirror */
- ++mirror_id;
-
if (lod_comp->llc_id == LCME_ID_INVAL) {
+ /* only the component of FLR layout with more than 1
+ * mirror has mirror ID in its component ID.
+ */
+ if (lod_comp->llc_extent.e_start == 0 &&
+ lo->ldo_mirror_count > 1)
+ ++mirror_id;
+
lod_comp->llc_id = lod_gen_component_id(lo,
mirror_id, i);
if (lod_comp->llc_id == LCME_ID_INVAL)
}
run_test 202 "lfs setstripe --add-component wide striping"
+test_203() {
+ [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
+
+ local tf=$DIR/$tfile
+
+ #create 2 mirrors
+ $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf"
+ #delete first mirror
+ $LFS mirror split --mirror-id=1 -d $tf || error "delete first mirror"
+
+ $LFS getstripe $tf
+ local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
+ local count=$($LFS getstripe --mirror-id=2 -c $tf) ||
+ error "getstripe count of mirror 2"
+ [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
+
+ #extend a mirror with 2 OSTs
+ $LFS mirror extend -N -c2 $tf || error "extend mirror"
+ $LFS getstripe $tf
+
+ local new_id=$($LFS getstripe --mirror-id=2 -I $tf)
+ count=$($LFS getstripe --mirror-id=2 -c $tf) ||
+ error "getstripe count of mirror 2"
+ [[ x$oldid = x$newid ]] ||
+ error "mirror 2 changed ID from $old_id to $new_id"
+ [[ x$count = x1 ]] || error "mirror 2 stripe count $count is not 1"
+
+ count=$($LFS getstripe --mirror-id=3 -c $tf) ||
+ error "getstripe count of mirror 3"
+ [[ x$count = x2 ]] || error "mirror 3 stripe count $count is not 2"
+}
+run_test 203 "mirror file preserve mirror ID"
+
complete $SECONDS
check_and_cleanup_lustre
exit_status