+test_27J() {
+ [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.12.51) ]] &&
+ skip "Need MDS version newer than 2.12.51"
+
+ test_mkdir $DIR/$tdir
+ local uuid1=$(cat /proc/sys/kernel/random/uuid)
+ local uuid2=$(cat /proc/sys/kernel/random/uuid)
+
+ # create foreign file (raw way)
+ create_foreign_file -f $DIR/$tdir/$tfile -x "${uuid1}@${uuid2}" \
+ -t 1 -F 0xda08 || error "create_foreign_file failed"
+
+ # verify foreign file (raw way)
+ parse_foreign_file -f $DIR/$tdir/$tfile |
+ grep "lov_foreign_magic: 0x0BD70BD0" ||
+ error "$DIR/$tdir/$tfile: invalid LOV EA foreign magic"
+ parse_foreign_file -f $DIR/$tdir/$tfile | grep "lov_xattr_size: 89" ||
+ error "$DIR/$tdir/$tfile: invalid LOV EA foreign size"
+ parse_foreign_file -f $DIR/$tdir/$tfile |
+ grep "lov_foreign_size: 73" ||
+ error "$DIR/$tdir/$tfile: invalid LOV EA foreign size"
+ parse_foreign_file -f $DIR/$tdir/$tfile |
+ grep "lov_foreign_type: 1" ||
+ error "$DIR/$tdir/$tfile: invalid LOV EA foreign type"
+ parse_foreign_file -f $DIR/$tdir/$tfile |
+ grep "lov_foreign_flags: 0x0000DA08" ||
+ error "$DIR/$tdir/$tfile: invalid LOV EA foreign flags"
+ local lov=$(parse_foreign_file -f $DIR/$tdir/$tfile |
+ grep "lov_foreign_value: 0x" |
+ sed -e 's/lov_foreign_value: 0x//')
+ local lov2=$(echo -n "${uuid1}@${uuid2}" | od -A n -t x1 -w160)
+ [[ $lov = ${lov2// /} ]] ||
+ error "$DIR/$tdir/$tfile: invalid LOV EA foreign value"
+
+ # create foreign file (lfs + API)
+ $LFS setstripe --foreign=daos --flags 0xda08 \
+ -x "${uuid1}@${uuid2}" $DIR/$tdir/${tfile}2 ||
+ error "$DIR/$tdir/${tfile}2: create failed"
+
+ $LFS getstripe -v $DIR/$tdir/${tfile}2 |
+ grep "lfm_magic:.*0x0BD70BD0" ||
+ error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign magic"
+ # lfm_length is LOV EA size - sizeof(lfm_magic) - sizeof(lfm_length)
+ $LFS getstripe -v $DIR/$tdir/${tfile}2 | grep "lfm_length:.*73" ||
+ error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign size"
+ $LFS getstripe -v $DIR/$tdir/${tfile}2 | grep "lfm_type:.*daos" ||
+ error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign type"
+ $LFS getstripe -v $DIR/$tdir/${tfile}2 |
+ grep "lfm_flags:.*0x0000DA08" ||
+ error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign flags"
+ $LFS getstripe $DIR/$tdir/${tfile}2 |
+ grep "lfm_value:.*${uuid1}@${uuid2}" ||
+ error "$DIR/$tdir/${tfile}2: invalid LOV EA foreign value"
+
+ # modify striping should fail
+ $LFS setstripe -c 2 $DIR/$tdir/$tfile &&
+ error "$DIR/$tdir/$tfile: setstripe should fail"
+ $LFS setstripe -c 2 $DIR/$tdir/${tfile}2 &&
+ error "$DIR/$tdir/${tfile}2: setstripe should fail"
+
+ # R/W should fail
+ cat $DIR/$tdir/$tfile && error "$DIR/$tdir/$tfile: read should fail"
+ cat $DIR/$tdir/${tfile}2 &&
+ error "$DIR/$tdir/${tfile}2: read should fail"
+ cat /etc/passwd > $DIR/$tdir/$tfile &&
+ error "$DIR/$tdir/$tfile: write should fail"
+ cat /etc/passwd > $DIR/$tdir/${tfile}2 &&
+ error "$DIR/$tdir/${tfile}2: write should fail"
+
+ # chmod should work
+ chmod 222 $DIR/$tdir/$tfile ||
+ error "$DIR/$tdir/$tfile: chmod failed"
+ chmod 222 $DIR/$tdir/${tfile}2 ||
+ error "$DIR/$tdir/${tfile}2: chmod failed"
+
+ # chown should work
+ chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/$tfile ||
+ error "$DIR/$tdir/$tfile: chown failed"
+ chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tfile}2 ||
+ error "$DIR/$tdir/${tfile}2: chown failed"
+
+ # rename should work
+ mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}.new ||
+ error "$DIR/$tdir/$tfile: rename of foreign file has failed"
+ mv $DIR/$tdir/${tfile}2 $DIR/$tdir/${tfile}2.new ||
+ error "$DIR/$tdir/${tfile}2: rename of foreign file has failed"
+
+ #remove foreign file
+ rm $DIR/$tdir/${tfile}.new ||
+ error "$DIR/$tdir/${tfile}.new: remove of foreign file has failed"
+ rm $DIR/$tdir/${tfile}2.new ||
+ error "$DIR/$tdir/${tfile}2.new: remove of foreign file has failed"
+}
+run_test 27J "basic ops on file with foreign LOV"
+
+test_27K() {
+ [[ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.12.49) ]] &&
+ skip "Need MDS version newer than 2.12.49"
+
+ test_mkdir $DIR/$tdir
+ local uuid1=$(cat /proc/sys/kernel/random/uuid)
+ local uuid2=$(cat /proc/sys/kernel/random/uuid)
+
+ # create foreign dir (raw way)
+ create_foreign_dir -d $DIR/$tdir/$tdir -x "${uuid1}@${uuid2}" -t 1 ||
+ error "create_foreign_dir FAILED"
+
+ # verify foreign dir (raw way)
+ parse_foreign_dir -d $DIR/$tdir/$tdir |
+ grep "lmv_foreign_magic:.*0xcd50cd0" ||
+ error "$DIR/$tdir/$tfile: invalid LMV EA magic"
+ parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_xattr_size:.*89$" ||
+ error "$DIR/$tdir/$tdir: invalid LMV EA size"
+ parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_foreign_type: 1$" ||
+ error "$DIR/$tdir/$tdir: invalid LMV EA type"
+ parse_foreign_dir -d $DIR/$tdir/$tdir | grep "lmv_foreign_flags: 0$" ||
+ error "$DIR/$tdir/$tdir: invalid LMV EA flags"
+ local lmv=$(parse_foreign_dir -d $DIR/$tdir/$tdir |
+ grep "lmv_foreign_value: 0x" |
+ sed 's/lmv_foreign_value: 0x//')
+ local lmv2=$(echo -n "${uuid1}@${uuid2}" | od -A n -t x1 -w160 |
+ sed 's/ //g')
+ [[ $lmv == $lmv2 ]] || error "$DIR/$tdir/$tdir: invalid LMV EA value"
+
+ # create foreign dir (lfs + API)
+ $LFS mkdir --foreign=daos --xattr="${uuid1}@${uuid2}" --flags=0xda05 \
+ $DIR/$tdir/${tdir}2 ||
+ error "$DIR/$tdir/${tdir}2: create failed"
+
+ $LFS getdirstripe -v $DIR/$tdir/${tdir}2 |
+ grep "lfm_magic:.*0x0CD50CD0" ||
+ error "$DIR/$tdir/${tdir}2: invalid LMV EA magic"
+ # lfm_length is LMV EA size - sizeof(lfm_magic) - sizeof(lfm_length)
+ # - sizeof(lfm_type) - sizeof(lfm_flags)
+ $LFS getdirstripe -v $DIR/$tdir/${tdir}2 | grep "lfm_length:.*73" ||
+ error "$DIR/$tdir/${tdir}2: invalid LMV EA size"
+ $LFS getdirstripe -v $DIR/$tdir/${tdir}2 | grep "lfm_type:.*daos" ||
+ error "$DIR/$tdir/${tdir}2: invalid LMV EA type"
+ $LFS getdirstripe -v $DIR/$tdir/${tdir}2 |
+ grep "lfm_flags:.*0x0000DA05" ||
+ error "$DIR/$tdir/${tdir}2: invalid LMV EA flags"
+ $LFS getdirstripe $DIR/$tdir/${tdir}2 |
+ grep "lfm_value.*${uuid1}@${uuid2}" ||
+ error "$DIR/$tdir/${tdir}2: invalid LMV EA value"
+
+ # file create in dir should fail
+ touch $DIR/$tdir/$tdir/$tfile && "$DIR/$tdir: file create should fail"
+ touch $DIR/$tdir/${tdir}2/$tfile &&
+ "$DIR/${tdir}2: file create should fail"
+
+ # chmod should work
+ chmod 777 $DIR/$tdir/$tdir ||
+ error "$DIR/$tdir: chmod failed"
+ chmod 777 $DIR/$tdir/${tdir}2 ||
+ error "$DIR/${tdir}2: chmod failed"
+
+ # chown should work
+ chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/$tdir ||
+ error "$DIR/$tdir: chown failed"
+ chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/${tdir}2 ||
+ error "$DIR/${tdir}2: chown failed"
+
+ # rename should work
+ mv $DIR/$tdir/$tdir $DIR/$tdir/${tdir}.new ||
+ error "$DIR/$tdir/$tdir: rename of foreign dir has failed"
+ mv $DIR/$tdir/${tdir}2 $DIR/$tdir/${tdir}2.new ||
+ error "$DIR/$tdir/${tdir}2: rename of foreign dir has failed"
+
+ #remove foreign dir
+ rmdir $DIR/$tdir/${tdir}.new ||
+ error "$DIR/$tdir/${tdir}.new: remove of foreign dir has failed"
+ rmdir $DIR/$tdir/${tdir}2.new ||
+ error "$DIR/$tdir/${tdir}2.new: remove of foreign dir has failed"
+}
+run_test 27K "basic ops on dir with foreign LMV"
+
+test_27L() {
+ remote_mds_nodsh && skip "remote MDS with nodsh"
+
+ local POOL=${POOL:-$TESTNAME}
+
+ pool_add $POOL || error "pool_add failed"
+
+ lfs pool_list $MOUNT | grep -Fx "${FSNAME}.${POOL}" ||
+ error "pool_list does not contain ${FSNAME}.${POOL}:" \
+ "$(lfs pool_list $MOUNT | grep -F "${POOL}")"
+}
+run_test 27L "lfs pool_list gives correct pool name"
+
+test_27M() {
+ [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.12.57) ]] &&
+ skip "Need MDS version >= than 2.12.57"
+ remote_mds_nodsh && skip "remote MDS with nodsh"
+ [[ $OSTCOUNT -lt 2 ]] && skip_env "need > 1 OST"
+
+ test_mkdir $DIR/$tdir
+
+ # Set default striping on directory
+ $LFS setstripe -C 4 $DIR/$tdir
+
+ echo 1 > $DIR/$tdir/${tfile}.1
+ local count=$($LFS getstripe -c $DIR/$tdir/${tfile}.1)
+ local setcount=4
+ [ $count -eq $setcount ] ||
+ error "(1) stripe count $count, should be $setcount"
+
+ # Capture existing append_stripe_count setting for restore
+ local orig_count=$(do_facet mds1 $LCTL get_param -n mdd.$FSNAME-MDT0000.append_stripe_count)
+ local mdts=$(comma_list $(mdts_nodes))
+ stack_trap "do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=$orig_count" EXIT
+
+ local appendcount=$orig_count
+ echo 1 >> $DIR/$tdir/${tfile}.2_append
+ count=$($LFS getstripe -c $DIR/$tdir/${tfile}.2_append)
+ [ $count -eq $appendcount ] ||
+ error "(2)stripe count $count, should be $appendcount for append"
+
+ # Disable O_APPEND striping, verify it works
+ do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=0
+
+ # Should now get the default striping, which is 4
+ setcount=4
+ echo 1 >> $DIR/$tdir/${tfile}.3_append
+ count=$($LFS getstripe -c $DIR/$tdir/${tfile}.3_append)
+ [ $count -eq $setcount ] ||
+ error "(3) stripe count $count, should be $setcount"
+
+ # Try changing the stripe count for append files
+ do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=2
+
+ # Append striping is now 2 (directory default is still 4)
+ appendcount=2
+ echo 1 >> $DIR/$tdir/${tfile}.4_append
+ count=$($LFS getstripe -c $DIR/$tdir/${tfile}.4_append)
+ [ $count -eq $appendcount ] ||
+ error "(4) stripe count $count, should be $appendcount for append"
+
+ # Test append stripe count of -1
+ do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=-1
+ appendcount=$OSTCOUNT
+ echo 1 >> $DIR/$tdir/${tfile}.5
+ count=$($LFS getstripe -c $DIR/$tdir/${tfile}.5)
+ [ $count -eq $appendcount ] ||
+ error "(5) stripe count $count, should be $appendcount for append"
+
+ # Set append striping back to default of 1
+ do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=1
+
+ # Try a new default striping, PFL + DOM
+ $LFS setstripe -L mdt -E 1M -E -1 -c 2 $DIR/$tdir
+
+ # Create normal DOM file, DOM returns stripe count == 0
+ setcount=0
+ touch $DIR/$tdir/${tfile}.6
+ count=$($LFS getstripe -c $DIR/$tdir/${tfile}.6)
+ [ $count -eq $setcount ] ||
+ error "(6) stripe count $count, should be $setcount"
+
+ # Show
+ appendcount=1
+ echo 1 >> $DIR/$tdir/${tfile}.7_append
+ count=$($LFS getstripe -c $DIR/$tdir/${tfile}.7_append)
+ [ $count -eq $appendcount ] ||
+ error "(7) stripe count $count, should be $appendcount for append"
+
+ # Clean up DOM layout
+ $LFS setstripe -d $DIR/$tdir
+
+ # Now test that append striping works when layout is from root
+ $LFS setstripe -c 2 $MOUNT
+ # Make a special directory for this
+ mkdir $DIR/${tdir}/${tdir}.2
+ stack_trap "$LFS setstripe -d $MOUNT" EXIT
+
+ # Verify for normal file
+ setcount=2
+ echo 1 > $DIR/${tdir}/${tdir}.2/${tfile}.8
+ count=$($LFS getstripe -c $DIR/$tdir/${tdir}.2/${tfile}.8)
+ [ $count -eq $setcount ] ||
+ error "(8) stripe count $count, should be $setcount"
+
+ appendcount=1
+ echo 1 >> $DIR/${tdir}/${tdir}.2/${tfile}.9_append
+ count=$($LFS getstripe -c $DIR/${tdir}/${tdir}.2/${tfile}.9_append)
+ [ $count -eq $appendcount ] ||
+ error "(9) stripe count $count, should be $appendcount for append"
+
+ # Now test O_APPEND striping with pools
+ do_nodes $mdts $LCTL set_param mdd.*.append_pool="$TESTNAME"
+ stack_trap "do_nodes $mdts $LCTL set_param mdd.*.append_pool='none'" EXIT
+
+ # Create the pool
+ pool_add $TESTNAME || error "pool creation failed"
+ pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
+
+ echo 1 >> $DIR/$tdir/${tfile}.10_append
+
+ pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.10_append)
+ [ "$pool" = "$TESTNAME" ] || error "(10) incorrect pool: $pool"
+
+ # Check that count is still correct
+ appendcount=1
+ echo 1 >> $DIR/$tdir/${tfile}.11_append
+ count=$($LFS getstripe -c $DIR/$tdir/${tfile}.11_append)
+ [ $count -eq $appendcount ] ||
+ error "(11) stripe count $count, should be $appendcount for append"
+
+ # Disable O_APPEND stripe count, verify pool works separately
+ do_nodes $mdts $LCTL set_param mdd.*.append_stripe_count=0
+
+ echo 1 >> $DIR/$tdir/${tfile}.12_append
+
+ pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.12_append)
+ [ "$pool" = "$TESTNAME" ] || error "(12) incorrect pool: $pool"
+
+ # Remove pool setting, verify it's not applied
+ do_nodes $mdts $LCTL set_param mdd.*.append_pool='none'
+
+ echo 1 >> $DIR/$tdir/${tfile}.13_append
+
+ pool=$($LFS getstripe -p $DIR/$tdir/${tfile}.13_append)
+ [ "$pool" = "" ] || error "(13) pool found: $pool"
+}
+run_test 27M "test O_APPEND striping"
+
+test_27N() {
+ combined_mgs_mds && skip "needs separate MGS/MDT"
+
+ pool_add $TESTNAME || error "pool_add failed"
+ do_facet mgs "$LCTL pool_list $FSNAME" |
+ grep -Fx "${FSNAME}.${TESTNAME}" ||
+ error "lctl pool_list on MGS failed"
+}
+run_test 27N "lctl pool_list on separate MGS gives correct pool name"
+