Whamcloud - gitweb
LU-9324 lfs: add setstripe --copy=lustre_file_or_dir parameter
[fs/lustre-release.git] / lustre / tests / sanity-pfl.sh
index e893344..98c148a 100644 (file)
@@ -36,6 +36,9 @@ build_test_filter
        error "\$RUNAS_ID set to 0, but \$UID is also 0!"
 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
 
+assert_DIR
+rm -rf $DIR/[Rdfs][0-9]*
+
 test_0() {
        [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
 
@@ -196,7 +199,7 @@ test_5() {
        local subdir=$parent/subdir
 
        rm -fr $parent
-       test_mkdir $parent || error "Create dir $parent failed"
+       test_mkdir $parent
 
        # set default layout to parent directory
        $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
@@ -235,7 +238,7 @@ test_5() {
                error "Delete default layout from $parent failed"
 
        comp_cnt=$($LFS getstripe -d --component-count $parent)
-       [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
+       [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
 
        rm -f $comp_file || error "Delete $comp_file failed"
        rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
@@ -254,7 +257,7 @@ test_6() {
                error "Create v1 $comp_file failed"
 
        local comp_cnt=$($LFS getstripe --component-count $comp_file)
-       [ ! -z "$comp_cnt" ] && error "Wrong component count $comp_cnt"
+       [ $comp_cnt -ne 0 ] && error "Wrong component count $comp_cnt"
 
        dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
                error "Write to v1 $comp_file failed"
@@ -289,7 +292,7 @@ test_6() {
                error "Migrate(composite -> v1) $comp_file failed"
 
        comp_cnt=$($LFS getstripe --component-count $comp_file)
-       [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
+       [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
 
        chksum=$(md5sum $comp_file)
        [ "$old_chksum" != "$chksum" ] &&
@@ -300,7 +303,7 @@ test_6() {
 run_test 6 "Migrate composite file"
 
 test_7() {
-       test_mkdir -p $DIR/$tdir || error "mkdir failed"
+       test_mkdir $DIR/$tdir
        chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
 
        local comp_file=$DIR/$tdir/$tfile
@@ -324,7 +327,7 @@ test_8() {
        local parent=$DIR/$tdir
 
        rm -fr $parent
-       test_mkdir -p $parent || error "Create dir $parent failed"
+       test_mkdir $parent
 
        $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
                -E -1 -c 4 -S 4M $parent ||
@@ -361,7 +364,7 @@ test_9() {
        local f2=$($LFS getstripe -I2 $comp_file |
                        awk '/l_fid:/ {print $7}')
        echo "after MDS recovery, the ost fid of 2nd component is $f2"
-       [ $f1 == $f2 ] || error "$f1 != $f2"
+       [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
 }
 run_test 9 "Replay layout extend object instantiation"
 
@@ -374,7 +377,8 @@ component_dump() {
 
 test_10() {
        local parent=$DIR/$tdir
-       local root_layout=$(get_layout_param $MOUNT)
+
+       save_layout_restore_at_exit $MOUNT
 
        rm -rf $parent
        $LFS setstripe -d $MOUNT || error "clear root layout"
@@ -384,7 +388,7 @@ test_10() {
                -E -1 -c 4 -S 4M $MOUNT ||
                error "Set root layout failed"
 
-       test_mkdir -p $parent || error "Create dir $parent failed"
+       test_mkdir $parent
        # set a different layout for parent
        $LFS setstripe -E -1 -c 1 -S 1M $parent ||
                error "set $parent layout failed"
@@ -413,7 +417,6 @@ test_10() {
        [  x$f2_expect != x$f2_entry ] &&
                error "$parent/file2 does not inherite root layout"
 
-       $LFS setstripe $root_layout $MOUNT
        return 0
 }
 run_test 10 "Inherit composite template from root"
@@ -451,7 +454,7 @@ test_11() {
        $TRUNCATE $comp_file $((1024*1024*1+1))
 
        f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
-       [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
+       [[ -z $f2 ]] && error "3: 2nd component uninstantiated"
        f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
        [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
        f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
@@ -479,8 +482,14 @@ test_12() {
 
        # specify ost list for component
        $LFS setstripe -E1m -c2 -o0,1 -E2m -c2 -o1,2 -E3m -c2 -o2,1 \
-               -E4m -c2 -o2,0 -E-1 $file ||
+               -E4m -c1 -i2 -E-1 $file ||
                error "Create $file failed"
+
+       # clear lod component cache
+       stop $SINGLEMDS || error "stop MDS"
+       local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
+       start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
+
        # instantiate all components
        $TRUNCATE $file $((1024*1024*4+1))
 
@@ -499,7 +508,7 @@ test_12() {
 
        local o4=$($LFS getstripe -I4 $file |
                        awk '/l_ost_idx:/ {printf("%d",$5)}')
-       [[ $o4 != "20" ]] && error "$o4 is not 20"
+       [[ $o4 != "2" ]] && error "$o4 is not 2"
 
        return 0
 }
@@ -570,13 +579,13 @@ test_15() {
        local parent=$DIR/$tdir
 
        rm -fr $parent
-       test_mkdir -p $parent || error "Create dir $parent failed"
+       test_mkdir $parent
 
        $LFS setstripe -d $parent || error "delete default layout"
 
        $LFS setstripe -E 1M -E 10M -E eof $parent/f1 || error "create f1"
        $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
-       test_mkdir -p $parent/subdir || error "create subdir"
+       test_mkdir $parent/subdir
        $LFS setstripe -E 6M -E 30M -E eof $parent/subdir ||
                error "setstripe to subdir"
        $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
@@ -609,9 +618,9 @@ test_15() {
                error "after write: start=1M, end=10M, flag=init, $found != 1"
 
        local ext_opts="--component-start -1M -E +5M"
-       # subdir, f3
+       # parent, subdir, f3, f4
        found=$($LFS find $ext_opts $parent | wc -l)
-       [ $found -eq 2 ] || error "start-1M, end+5M, $found != 2"
+       [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
 
        local cnt_opts="--component-count +2"
        # subdir
@@ -623,13 +632,117 @@ test_15() {
        [ $found -eq 0 ] ||
                error "start-1M, end+5M, count+2, flag=init, $found != 0"
 
-       # f3
+       # f3, f4
        found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
-       [ $found -eq 1 ] ||
-               error "start-1M, end+5M, !count+2, flag=init, $found != 1"
+       [ $found -eq 2 ] ||
+               error "start-1M, end+5M, !count+2, flag=init, $found != 2"
 }
 run_test 15 "Verify component options for lfs find"
 
+verify_16() {
+       local src=$1
+       local dst=$2
+       local temp=$3
+       local msg_prefix=$4
+
+       echo "getstripe --yaml $src"
+       $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
+       echo "setstripe --yaml=$temp $dst"
+       $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
+
+       echo "compare"
+       local layout1=$(get_layout_param $src)
+       local layout2=$(get_layout_param $dst)
+       # compare their layout info
+       [ "$layout1" == "$layout2" ] ||
+               error "$msg_prefix $src/$dst layouts are not equal"
+}
+
+test_16() {
+       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
+
+       local file=$DIR/$tdir/$tfile
+       local dir=$DIR/$tdir/dir
+       local temp=$DIR/$tdir/template
+       rm -rf $DIR/$tdir
+       test_mkdir $DIR/$tdir
+
+       #####################################################################
+       #                           1. PFL file
+       # set stripe for source file
+       $LFS setstripe -E1m -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 $file ||
+               error "Create $file failed"
+
+       echo "1. PFL file"
+       verify_16 $file $file.copy $temp "1. PFL file"
+
+       #####################################################################
+       #                           2. plain file
+       # set stripe for source file
+       rm -f $file
+       $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
+
+       rm -f $file.copy
+       echo "2. plain file"
+       verify_16 $file $file.copy $temp "2. plain file"
+
+       #####################################################################
+       #                           3. PFL dir
+       # set stripe for source dir
+       test_mkdir $dir
+       $LFS setstripe -E1m -c2 -E2m -c1 -E-1 $dir ||
+               error "setstripe $dir failed"
+
+       test_mkdir $dir.copy
+       echo "3. PFL dir"
+       verify_16 $dir $dir.copy $temp.dir "3. PFL dir"
+
+       #####################################################################
+       #                           4. plain dir
+       # set stripe for source dir
+       $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
+
+       echo "4. plain dir"
+       verify_16 $dir $dir.copy $temp.dir "4. plain dir"
+}
+run_test 16 "Verify setstripe/getstripe with YAML config file"
+
+test_17() {
+       [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
+       local file=$DIR/$tdir/$tfile
+       test_mkdir -p $DIR/$tdir
+       rm -f $file
+
+       $LFS setstripe -E1m -E2m -c2 -E-1 -c-1 $file ||
+               error "Create $file failed"
+
+       local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
+       local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
+       local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
+       echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
+
+       # init 2nd component
+       $TRUNCATE $file $((1024*1024+1))
+       local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
+       local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
+       echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
+
+       [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
+       [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
+
+       # init 3rd component
+       $TRUNCATE $file $((1024*1024*2+1))
+       s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
+       s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
+       local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
+       echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
+
+       [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
+       [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
+       [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
+}
+run_test 17 "Verify LOVEA grows with more component inited"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status