Whamcloud - gitweb
LU-12661 tests: skip sanity 817 if kernel version >= 4.14
[fs/lustre-release.git] / lustre / tests / sanity-pfl.sh
index d72d00f..24446a0 100644 (file)
@@ -12,9 +12,6 @@ ONLY=${ONLY:-"$*"}
 ALWAYS_EXCEPT="$SANITY_PFL_EXCEPT"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
-[ "$ALWAYS_EXCEPT$EXCEPT" ] &&
-       echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
-
 TMP=${TMP:-/tmp}
 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
 
@@ -30,6 +27,9 @@ if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.51) ]]; then
        skip_env "Need MDS version at least 2.9.51"
 fi
 
+[ "$ALWAYS_EXCEPT$EXCEPT" ] &&
+       echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
+
 build_test_filter
 
 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
@@ -345,7 +345,7 @@ test_9() {
        test_mkdir $DIR/$tdir
        rm -f $comp_file
 
-       $LFS setstripe -E 1M -S 1M -E 2M -c 1 $comp_file ||
+       $LFS setstripe -E 1M -S 1M -E -1 -c 1 $comp_file ||
                error "Create $comp_file failed"
 
        local comp_cnt=$($LFS getstripe --component-count $comp_file)
@@ -440,7 +440,8 @@ test_11() {
        [[ -n $f4 ]] && error "1: 4th component instantiated"
 
        # the first 2 components instantiated
-       $TRUNCATE $comp_file $((1024*1024*1+1))
+       # Truncate to exact start of new component - LU-12586
+       $TRUNCATE $comp_file $((1024*1024*1))
 
        f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
        [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
@@ -450,7 +451,7 @@ test_11() {
        [[ -n $f4 ]] && error "2: 4th component instantiated"
 
        # the first 3 components instantiated
-       $TRUNCATE $comp_file $((1024*1024*3))
+       $TRUNCATE $comp_file $((1024*1024*3 - 1))
        $TRUNCATE $comp_file $((1024*1024*1+1))
 
        f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
@@ -586,7 +587,7 @@ test_15() {
        $LFS setstripe -E 1M -S 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 $parent/subdir
-       $LFS setstripe -E 6M -S 1M -E 30M -E eof $parent/subdir ||
+       $LFS setstripe -E 6M -S 1M -c1 -E 30M -c4 -E eof -c -1 $parent/subdir ||
                error "setstripe to subdir"
        $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
        $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
@@ -636,27 +637,17 @@ test_15() {
        found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
        [ $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"
+       # check last component stripe count
+       if [ $OSTCOUNT -gt 1 ]; then
+               touch $parent/subdir/f5
+               $TRUNCATE $parent/subdir/f5 $((32*1024*1024))
+               found=$($LFS find $parent/subdir -c $OSTCOUNT)
+               [[ "$found" == "$parent/subdir/f5" ]] ||
+                       error "got '$found' with stripe_count=$OSTCOUNT, not f5"
+       fi
 }
+run_test 15 "Verify component options for lfs find"
 
 test_16() {
        [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
@@ -674,7 +665,7 @@ test_16() {
                $file || error "Create $file failed"
 
        echo "1. PFL file"
-       verify_16 $file $file.copy $temp "1. PFL file"
+       verify_yaml_layout $file $file.copy $temp "1. PFL file"
 
        #####################################################################
        #                           2. plain file
@@ -684,7 +675,7 @@ test_16() {
 
        rm -f $file.copy
        echo "2. plain file"
-       verify_16 $file $file.copy $temp "2. plain file"
+       verify_yaml_layout $file $file.copy $temp "2. plain file"
 
        #####################################################################
        #                           3. PFL dir
@@ -695,7 +686,7 @@ test_16() {
 
        test_mkdir $dir.copy
        echo "3. PFL dir"
-       verify_16 $dir $dir.copy $temp.dir "3. PFL dir"
+       verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
 
        #####################################################################
        #                           4. plain dir
@@ -703,7 +694,7 @@ test_16() {
        $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
 
        echo "4. plain dir"
-       verify_16 $dir $dir.copy $temp.dir "4. plain dir"
+       verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
 }
 run_test 16 "Verify setstripe/getstripe with YAML config file"
 
@@ -743,6 +734,80 @@ test_17() {
 }
 run_test 17 "Verify LOVEA grows with more component inited"
 
+check_distribution() {
+       local file=$1
+       local objs
+       local ave
+       local obj_min_one=$((OSTCOUNT - 1))
+
+       objs=$($LFS getstripe $file |
+               awk '/l_ost_idx:/ { print $5 }' | wc -l)
+       let ave=$((objs / OSTCOUNT))
+
+       # collect objects per OST distribution
+       $LFS getstripe $file | awk '/l_ost_idx:/ { print $5 }' | tr -d "," |
+               (inuse=( $(for i in $(seq 0 $obj_min_one); do echo 0; done) )
+               while read O; do
+                       let inuse[$O]=$((1 + ${inuse[$O]}))
+               done;
+
+               # verify object distribution varies no more than +-1
+               for idx in $(seq 0 $obj_min_one); do
+                       let dif=$((${inuse[$idx]} - ave))
+                       let dif=${dif#-}
+                       if [ "$dif" -gt 1 ]; then
+                               echo "OST${idx}: ${inuse[$idx]} objects"
+                               error "bad distribution on OST${idx}"
+                       fi
+               done)
+}
+
+test_18() {
+       local file1=$DIR/${tfile}-1
+       local file2=$DIR/${tfile}-2
+       local file3=$DIR/${tfile}-3
+
+       rm -f $file1 $file2 $file3
+
+       $LFS setstripe -E 1m -S 1m $file1 ||
+               error "Create $file1 failed"
+       $LFS setstripe -E 1m -S 1m $file2 ||
+               error "Create $file2 failed"
+       $LFS setstripe -E 1m -S 1m $file3 ||
+               error "Create $file3 failed"
+
+       local objs=$((OSTCOUNT+1))
+       for comp in $(seq 1 $OSTCOUNT); do
+               $LFS setstripe --component-add -E $((comp+1))M -c 1 $file1 ||
+                       error "Add component to $file1 failed 2"
+               $LFS setstripe --component-add -E $((comp+1))M -c 1 $file2 ||
+                       error "Add component to $file2 failed 2"
+               $LFS setstripe --component-add -E $((comp+1))M -c 1 $file3 ||
+                       error "Add component to $file3 failed 2"
+       done
+
+       $LFS setstripe --component-add -E -1 -c -1 $file1 ||
+               error "Add component to $file1 failed 3"
+       $LFS setstripe --component-add -E -1 -c -1 $file2 ||
+               error "Add component to $file2 failed 3"
+       $LFS setstripe --component-add -E -1 -c -1 $file3 ||
+               error "Add component to $file3 failed 3"
+
+       # Instantiate all components
+       dd if=/dev/urandom of=$file1 bs=1M count=$((objs+1)) ||
+               error "dd failed for $file1"
+       dd if=/dev/urandom of=$file2 bs=1M count=$((objs+1)) ||
+               error "dd failed for $file2"
+       dd if=/dev/urandom of=$file3 bs=1M count=$((objs+1)) ||
+               error "dd failed for $file3"
+
+       check_distribution $file1
+       check_distribution $file2
+       check_distribution $file3
+
+}
+run_test 18 "check component distribution"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status