return rc;
}
+/**
+ * Exchange MOF_LOV_CREATED flags between two objects after a
+ * layout swap. No assumption is made on whether o1 or o2 have
+ * created objects or not.
+ *
+ * \param[in,out] o1 First swap layout object
+ * \param[in,out] o2 Second swap layout object
+ */
+static void mdt_swap_lov_flag(struct mdt_object *o1, struct mdt_object *o2)
+{
+ __u64 o1_flags;
+
+ mutex_lock(&o1->mot_lov_mutex);
+ mutex_lock(&o2->mot_lov_mutex);
+
+ o1_flags = o1->mot_flags;
+ o1->mot_flags = (o1->mot_flags & ~MOF_LOV_CREATED) |
+ (o2->mot_flags & MOF_LOV_CREATED);
+
+ o2->mot_flags = (o2->mot_flags & ~MOF_LOV_CREATED) |
+ (o1_flags & MOF_LOV_CREATED);
+
+ mutex_unlock(&o2->mot_lov_mutex);
+ mutex_unlock(&o1->mot_lov_mutex);
+}
+
static int mdt_swap_layouts(struct tgt_session_info *tsi)
{
struct mdt_thread_info *info;
rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
mdt_object_child(o2), msl->msl_flags);
- GOTO(unlock2, rc);
+ if (rc < 0)
+ GOTO(unlock2, rc);
+
+ mdt_swap_lov_flag(o1, o2);
+
unlock2:
mdt_object_unlock(info, o2, lh2, rc);
unlock1:
}
run_test 184d "allow stripeless layouts swap"
+test_184e() {
+ check_swap_layouts_support && return 0
+ [ -z "$(which getfattr 2>/dev/null)" ] &&
+ skip "no getfattr command" && return 0
+
+ local file1=$DIR/$tdir/$tfile-1
+ local file2=$DIR/$tdir/$tfile-2
+ local file3=$DIR/$tdir/$tfile-3
+ local lovea
+
+ mkdir -p $DIR/$tdir
+ touch $file1 || error "create $file1 failed"
+ $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
+ error "create $file2 failed"
+ $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
+ error "create $file3 failed"
+
+ $LFS swap_layouts $file1 $file2 ||
+ error "swap $file1 $file2 layouts failed"
+
+ lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
+ [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
+
+ echo 123 > $file1 || error "Should be able to write into $file1"
+
+ $LFS swap_layouts $file1 $file3 ||
+ error "swap $file1 $file3 layouts failed"
+
+ echo 123 > $file1 || error "Should be able to write into $file1"
+
+ rm -rf $file1 $file2 $file3
+}
+run_test 184e "Recreate layout after stripeless layout swaps"
test_185() { # LU-2441
# LU-3553 - no volatile file support in old servers