Whamcloud - gitweb
LU-14362 tests: sanity-flr to prepare stuff before checks
[fs/lustre-release.git] / lustre / tests / sanity-flr.sh
index 8a93e26..f9bbf7f 100644 (file)
@@ -15,25 +15,35 @@ init_logging
 
 ALWAYS_EXCEPT="$SANITY_FLR_EXCEPT "
 # Bug number for skipped test:    LU-11381
-ALWAYS_EXCEPT+="                  201"
+ALWAYS_EXCEPT+="                  201 "
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
+# skip all tests for PPC until we can get sanity-pfl to pass
+if [[ $(uname -m) = ppc64 ]]; then
+       skip "Skip FLR testing for PPC clients"
+fi
+
+if [[ "$ost1_FSTYPE" == "zfs" ]]; then
+       # bug #:        LU-1941
+       ALWAYS_EXCEPT+="49a"
+fi
+
 build_test_filter
 
 [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
        skip "Need MDS version at least 2.10.56"
 
-[ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
-       error "\$RUNAS_ID set to 0, but \$UID is also 0!"
-check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
-
 check_and_setup_lustre
 DIR=${DIR:-$MOUNT}
 assert_DIR
-
-assert_DIR
 rm -rf $DIR/[Rdfs][0-9]*
 
+[ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
+       error "\$RUNAS_ID set to 0, but \$UID is also 0!"
+
+check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
+
+
 # global array to store mirror IDs
 declare -a mirror_array
 get_mirror_ids() {
@@ -273,6 +283,16 @@ verify_comp_attrs() {
        verify_comp_attr_with_parent pool $tf $comp_id
 }
 
+verify_flr_state()
+{
+       local tf=$1
+       local expected_state=$2
+
+       local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
+       [ $expected_state = $state ] ||
+               error "expected: $expected_state, actual $state"
+}
+
 # command line test cases
 test_0a() {
        local td=$DIR/$tdir
@@ -384,7 +404,7 @@ test_0b() {
                # LU-11022 - remove mirror by pool name
                local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l)
                [ "$cnt" != "1" ] && error "unexpected mirror count $cnt"
-               $LFS mirror split --pool archive -d $tf || error "delete mirror"
+               $LFS mirror delete --pool archive $tf || error "delete mirror"
                cnt=$($LFS getstripe $tf | grep archive | wc -l)
                [ "$cnt" != "0" ] && error "mirror count after removal: $cnt"
        fi
@@ -593,11 +613,12 @@ test_0f() {
                error "create mirrored file $tf failed"
 
        # extend the mirrored file with composite layout mirrors
-       $mirror_cmd -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
+       $mirror_cmd -N -p archive \
+                   -N2 -E 4M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
                    -N -c -1 -p none \
                    -N3 -E 512M -S 16M -p archive -E -1 -i -1 -c -1 $tf ||
                error "extend mirrored file $tf failed"
-       verify_mirror_count $tf 7
+       verify_mirror_count $tf 8
        ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
 
        # verify component ${ids[0]}
@@ -612,8 +633,14 @@ test_0f() {
        verify_comp_attr pool $tf ${ids[1]} ssd
        verify_comp_extent $tf ${ids[1]} 33554432 EOF
 
-       # verify components ${ids[2]} and ${ids[4]}
-       for i in 2 4; do
+       # verify component ${ids[2]}
+       verify_comp_attr stripe-size $tf ${ids[0]} 16777216
+       verify_comp_attr_with_default stripe-count $tf ${ids[2]}
+       verify_comp_attr pool $tf ${ids[2]} archive
+       verify_comp_extent $tf ${ids[2]} 0 EOF
+
+       # verify components ${ids[3]} and ${ids[5]}
+       for i in 3 5; do
                verify_comp_attr_with_default stripe-size $tf ${ids[$i]}
                verify_comp_attr stripe-count $tf ${ids[$i]} 2
                verify_comp_attr stripe-index $tf ${ids[$i]} 1
@@ -621,30 +648,30 @@ test_0f() {
                verify_comp_extent $tf ${ids[$i]} 0 4194304
        done
 
-       # verify components ${ids[3]} and ${ids[5]}
-       for i in 3 5; do
+       # verify components ${ids[4]} and ${ids[6]}
+       for i in 4 6; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 4194304
                verify_comp_attr stripe-count $tf ${ids[$i]} 2
                verify_comp_attr pool $tf ${ids[$i]} flash
                verify_comp_extent $tf ${ids[$i]} 4194304 EOF
        done
 
-       # verify component ${ids[6]}
-       verify_comp_attr stripe-size $tf ${ids[6]} 4194304
-       verify_comp_attr stripe-count $tf ${ids[6]} $OSTCOUNT
-       verify_comp_attr_with_parent pool $tf ${ids[6]}
-       verify_comp_extent $tf ${ids[6]} 0 EOF
+       # verify component ${ids[7]}
+       verify_comp_attr stripe-size $tf ${ids[7]} 4194304
+       verify_comp_attr stripe-count $tf ${ids[7]} $OSTCOUNT
+       verify_comp_attr_with_parent pool $tf ${ids[7]}
+       verify_comp_extent $tf ${ids[7]} 0 EOF
 
-       # verify components ${ids[7]}, ${ids[9]} and ${ids[11]}
-       for i in 7 9 11; do
+       # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
+       for i in 8 10 12; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
                verify_comp_attr stripe-count $tf ${ids[$i]} $OSTCOUNT
                verify_comp_attr pool $tf ${ids[$i]} archive
                verify_comp_extent $tf ${ids[$i]} 0 536870912
        done
 
-       # verify components ${ids[8]}, ${ids[10]} and ${ids[12]}
-       for i in 8 10 12; do
+       # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
+       for i in 9 11 13; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
                verify_comp_attr stripe-count $tf ${ids[$i]} -1
                verify_comp_attr pool $tf ${ids[$i]} archive
@@ -752,6 +779,24 @@ test_0h() {
 }
 run_test 0h "set, clear and test flags for FLR files"
 
+test_0j() {
+       $LFS mirror create -N2 $DIR/$tfile || error "create $DIR/$tfile failed"
+
+       cp /etc/hosts $DIR/$tfile || error "write to $DIR/$tfile failed"
+       $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
+       cmp /etc/hosts $DIR/$tfile || error "cmp with /etc/hosts failed"
+
+       $LFS mirror read -N2 -o $TMP/$tfile $DIR/$tfile || "read mirror failed"
+       stack_trap "rm -f $TMP/$tfile"
+       cmp $TMP/$tfile $DIR/$tfile || error "cmp with $TMP/$tfile failed"
+       $LFS mirror write -N2 -i /etc/passwd $DIR/$tfile || "write failed"
+       $LFS setstripe --comp-set -I 65537 --comp-flags=stale $DIR/$tfile ||
+               error "set component 1 stale failed"
+       $LFS mirror resync $DIR/$tfile || error "resync $DIR/$tfile failed"
+       cmp /etc/passwd $DIR/$tfile || error "cmp with /etc/passwd failed"
+}
+run_test 0j "test lfs mirror read/write commands"
+
 test_1() {
        local tf=$DIR/$tfile
        local mirror_count=16 # LUSTRE_MIRROR_COUNT_MAX
@@ -1040,7 +1085,7 @@ test_32() {
 }
 run_test 32 "data should be mirrored to newly created mirror"
 
-test_33() {
+test_33a() {
        [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
 
        rm -f $DIR/$tfile $DIR/$tfile-2
@@ -1114,7 +1159,114 @@ test_33() {
 
        start_osts 2
 }
-run_test 33 "read can choose available mirror to read"
+run_test 33a "read can choose available mirror to read"
+
+test_33b() {
+       [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
+
+       rm -f $DIR/$tfile
+
+       stack_trap "rm -f $DIR/$tfile" EXIT
+
+       # create a file with two mirrors on OST0000 and OST0001
+       $LFS setstripe -N -Eeof -o0 -N -Eeof -o1 $DIR/$tfile
+
+       # make sure that $tfile has two mirrors
+       [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
+               { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
+
+       # write 50M
+       dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
+               error "write failed for $DIR/$tfile"
+       $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
+       verify_flr_state $DIR/$tfile "ro"
+       drop_client_cache
+
+       ls -l $DIR/$tfile
+
+       # read file - all OSTs are available
+       echo "reading file (data can be provided by any ost)... "
+       local t1=$SECONDS
+       time cat $DIR/$tfile > /dev/null || error "read all"
+       local t2=$SECONDS
+       ra=$((t2 - t1))
+
+       # read file again with ost1 {OST0000} failed
+       stop_osts 1
+       drop_client_cache
+       echo "reading file (data should be provided by ost2)..."
+       t1=$SECONDS
+       time cat $DIR/$tfile > /dev/null || error "read ost2"
+       t2=$SECONDS
+       r1=$((t2 - t1))
+
+       # remount ost1
+       start_osts 1
+
+       # read file again with ost2 {OST0001} failed
+       stop_osts 2
+       drop_client_cache
+
+       echo "reading file (data should be provided by ost1)..."
+       t1=$SECONDS
+       time cat $DIR/$tfile > /dev/null || error "read ost1"
+       t2=$SECONDS
+       r2=$((t2 - t1))
+
+       # remount ost2
+       start_osts 2
+
+       [ $((r1 * 100)) -gt $((ra * 105)) -a $r1 -gt $((ra + 2)) ] &&
+               error "read mirror too slow without ost1, from $ra to $r1"
+       [ $((r2 * 100)) -gt $((ra * 105)) -a $r2 -gt $((ra + 2)) ] &&
+               error "read mirror too slow without ost2, from $ra to $r2"
+
+       wait_osc_import_ready client ost2
+}
+run_test 33b "avoid reading from unhealthy mirror"
+
+test_33c() {
+       [[ $OSTCOUNT -lt 3 ]] && skip "need >= 3 OSTs" && return
+
+       rm -f $DIR/$tfile
+
+       stack_trap "rm -f $DIR/$tfile" EXIT
+
+       # create a file with two mirrors
+       # mirror1: {OST0000, OST0001}
+       # mirror2: {OST0001, OST0002}
+       $LFS setstripe -N -Eeof -c2 -o0,1 -N -Eeof -c2 -o1,2 $DIR/$tfile
+
+       # make sure that $tfile has two mirrors
+       [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] ||
+               { $LFS getstripe $DIR/$tfile; error "expected count 2"; }
+
+       # write 50M
+       dd if=/dev/urandom of=$DIR/$tfile bs=2M count=25 ||
+               error "write failed for $DIR/$tfile"
+       $LFS mirror resync $DIR/$tfile || error "resync failed for $DIR/$tfile"
+       verify_flr_state $DIR/$tfile "ro"
+       drop_client_cache
+
+       ls -l $DIR/$tfile
+
+       # read file - all OSTs are available
+       echo "reading file (data can be provided by any ost)... "
+       time cat $DIR/$tfile > /dev/null || error "read all"
+
+       # read file again with ost2 (OST0001) failed
+       stop_osts 2
+       drop_client_cache
+
+       echo "reading file (data should be provided by ost1 and ost3)..."
+       time cat $DIR/$tfile > /dev/null || error "read ost1 & ost3"
+
+       # remount ost2
+       start_osts 2
+
+       wait_osc_import_ready client ost2
+}
+run_test 33c "keep reading among unhealthy mirrors"
 
 test_34a() {
        [[ $OSTCOUNT -lt 4 ]] && skip "need >= 4 OSTs" && return
@@ -1376,16 +1528,6 @@ test_37()
 }
 run_test 37 "mirror I/O API verification"
 
-verify_flr_state()
-{
-       local tf=$1
-       local expected_state=$2
-
-       local state=$($LFS getstripe -v $tf | awk '/lcm_flags/{ print $2 }')
-       [ $expected_state = $state ] ||
-               error "expected: $expected_state, actual $state"
-}
-
 test_38() {
        local tf=$DIR/$tfile
        local ref=$DIR/${tfile}-ref
@@ -1812,7 +1954,7 @@ test_44() {
        verify_flr_state $tf "wp"
 
        # disallow destroying the last non-stale mirror
-       ! $LFS mirror split --mirror-id 1 -d $tf > /dev/null 2>&1 ||
+       ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 ||
                error "destroying mirror 1 should fail"
 
        # synchronize all mirrors of the file
@@ -1924,6 +2066,7 @@ test_46() {
 
        ########################### 3. FLR file #############################
        echo "  ** 3. FLR file"
+       rm -f $file
        $LFS setstripe -N -E1m -S 1M -c2 -o0,1 -E4m -c1 -Eeof -N -E16m -Eeof \
                $file || error "3. Create FLR $file failed"
 
@@ -1952,6 +2095,38 @@ test_46() {
                error "6. setstripe FLR $dir failed"
 
        verify_46 $dir $dir.copy "6. FLR dir"
+
+       ########################### 7. SEL file ##############################
+       echo "  ** 7. SEL file"
+       rm -f $file
+       $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
+               $file || error "Create $file failed"
+
+       rm -f $file.copy
+       verify_46 $file $file.copy "7. SEL file"
+
+       ########################### 8. SEL dir ##############################
+       echo "  ** 8. SEL dir"
+       $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
+               $dir || error "setstripe $dir failed"
+
+       verify_46 $dir $dir.copy "8. SEL dir"
+
+       ########################### 9. FLR SEL file ##########################
+       echo "  ** 9. FLR SEL file"
+       rm -f $file
+       $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
+               -N -E1G -c4 -z128M -E-1 -z256M $file || error "Create $file failed"
+
+       rm -f $file.copy
+       verify_46 $file $file.copy "9. SEL file"
+
+       ########################### 10. FLR SEL dir #########################
+       echo "  ** 10. FLR SEL dir"
+       $LFS setstripe -N -E256M -c2 -z 64M -E-1 -z 128M \
+               -N -E1G -c4 -z128M -E-1 -z256M $dir || error "Create $file failed"
+
+       verify_46 $dir $dir.copy "10. SEL dir"
 }
 run_test 46 "Verify setstripe --copy option"
 
@@ -2090,6 +2265,92 @@ test_48() {
 }
 run_test 48 "Verify snapshot mirror"
 
+OLDIFS="$IFS"
+cleanup_49() {
+       trap 0
+       IFS="$OLDIFS"
+}
+
+test_49a() {
+       [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
+
+       trap cleanup_49 EXIT RETURN
+
+       local file=$DIR/$tfile
+
+       $LFS setstripe -N -E eof -c1 -o1 -N -E eof -c1 -o0 $file ||
+               error "setstripe on $file"
+
+       dd if=/dev/zero of=$file bs=1M count=1 || error "dd failed for $file"
+       $LFS mirror resync $file
+
+       filefrag -ves $file || error "filefrag $file failed"
+       filefrag_op=$(filefrag -ve -k $file |
+                     sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
+
+#Filesystem type is: bd00bd0
+#File size of /mnt/lustre/f49a.sanity-flr is 1048576 (1024 blocks of 1024 bytes)
+# ext:     device_logical:        physical_offset: length:  dev: flags:
+#   0:        0..    1023:    1572864..   1573887:   1024: 0001: net,eof
+#   1:        0..    1023:    1572864..   1573887:   1024: 0000: last,net,eof
+#/mnt/lustre/f49a.sanity-flr: 2 extents found
+
+       last_lun=$(echo $filefrag_op | cut -d: -f5)
+       IFS=$'\n'
+       tot_len=0
+       num_luns=1
+       for line in $filefrag_op; do
+               frag_lun=$(echo $line | cut -d: -f5)
+               ext_len=$(echo $line | cut -d: -f4)
+               if [[ "$frag_lun" != "$last_lun" ]]; then
+                       if (( tot_len != 1024 )); then
+                               cleanup_49
+                               error "$file: OST$last_lun $tot_len != 1024"
+                       else
+                               (( num_luns += 1 ))
+                               tot_len=0
+                       fi
+               fi
+               (( tot_len += ext_len ))
+               last_lun=$frag_lun
+       done
+       if (( num_luns != 2 || tot_len != 1024 )); then
+               cleanup_49
+               error "$file: $num_luns != 2, $tot_len != 1024 on OST$last_lun"
+       fi
+
+       echo "FIEMAP on $file succeeded"
+}
+run_test 49a "FIEMAP upon FLR file"
+
+test_50() {    # EX-2179
+       mkdir -p $DIR/$tdir
+
+       local file=$DIR/$tdir/$tfile
+
+       $LFS setstripe -c1 -i0 $file || error "setstripe $file failed"
+
+       $LFS mirror extend -N -c1 -i1 $file ||
+               error "extending mirror for $file failed"
+
+       local olv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
+
+       fail mds1
+
+       $LFS mirror split -d --mirror-id=1 $file || error "split $file failed"
+
+       local flv=$($LFS getstripe $file | awk '/lcm_layout_gen/{print $2}')
+
+       echo "$file layout generation from $olv to $flv"
+       (( $flv != ($olv + 1) )) &&
+               error "split does not increase layout gen from $olv to $flv"
+
+       dd if=/dev/zero of=$file bs=1M count=1 || error "write $file failed"
+
+       $LFS getstripe -v $file || error "getstripe $file failed"
+}
+run_test 50 "mirror split update layout generation"
+
 ctrl_file=$(mktemp /tmp/CTRL.XXXXXX)
 lock_file=$(mktemp /var/lock/FLR.XXXXXX)
 
@@ -2312,7 +2573,7 @@ test_203() {
        #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 mirror delete --mirror-id=1 $tf || error "delete first mirror"
 
        $LFS getstripe $tf
        local old_id=$($LFS getstripe --mirror-id=2 -I $tf)
@@ -2521,7 +2782,7 @@ run_test 204c "FLR write/stale/resync test with component removal"
 test_204d() {
        [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
        [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
-               skip "skipped for lustre < $SEL_VERSION"
+               skip "skipped for lustre < $SEL_VER"
 
        local comp_file=$DIR/$tdir/$tfile
        local found=""
@@ -2590,7 +2851,7 @@ run_test 204d "FLR write/stale/resync sel test with repeated comp"
 test_204e() {
        [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
        [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
-               skip "skipped for lustre < $SEL_VERSION"
+               skip "skipped for lustre < $SEL_VER"
 
        local comp_file=$DIR/$tdir/$tfile
        local found=""
@@ -2671,7 +2932,7 @@ run_test 204e "FLR write/stale/resync sel test with repeated comp"
 test_204f() {
        [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
        [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
-               skip "skipped for lustre < $SEL_VERSION"
+               skip "skipped for lustre < $SEL_VER"
 
        local comp_file=$DIR/$tdir/$tfile
        local found=""
@@ -2736,6 +2997,24 @@ test_204f() {
 }
 run_test 204f "FLR write/stale/resync sel w/forced extension"
 
+function test_205() {
+       local tf=$DIR/$tfile
+       local mirrors
+
+       $LFS setstripe -c1 $tf
+       $LFS mirror extend -N $tf
+       mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
+       (( $mirrors == 2 )) || error "no new mirror was created?"
+
+       $LFS mirror extend -N --flags=prefer $tf
+       mirrors=$($LFS getstripe $tf | grep lcme_mirror_id | wc -l )
+       (( $mirrors == 3 )) || error "no new mirror was created?"
+
+       $($LFS getstripe $tf | grep lcme_flags: | tail -1 | grep -q prefer) ||
+               error "prefer flag was not set on the new mirror"
+}
+run_test 205 "lfs mirror extend to set prefer flag"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status