Whamcloud - gitweb
LU-14286 osd-ldiskfs: fallocate with unwritten extents
[fs/lustre-release.git] / lustre / tests / sanity.sh
index ff2db35..54ffef7 100755 (executable)
@@ -13406,6 +13406,7 @@ test_150a() {
 
        local TF="$TMP/$tfile"
 
+       stack_trap "rm -f $DIR/$tfile; wait_delete_completed"
        dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
        cp $TF $DIR/$tfile
        cancel_lru_locks $OSC
@@ -13428,29 +13429,48 @@ test_150a() {
        echo "12345" >>$DIR/$tfile
        cancel_lru_locks $OSC
        cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
-
-       rm -f $TF
-       true
 }
 run_test 150a "truncate/append tests"
 
 test_150b() {
-       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
-       [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
-               skip "Need OST version at least 2.13.53"
+       check_for_fallocate
+
        touch $DIR/$tfile
+       stack_trap "rm -f $DIR/$tfile; wait_delete_completed"
        check_fallocate $DIR/$tfile || error "fallocate failed"
 }
 run_test 150b "Verify fallocate (prealloc) functionality"
 
-test_150c() {
-       local bytes
-       local want
+test_150bb() {
+       check_for_fallocate
+
+       touch $DIR/$tfile
+       stack_trap "rm -f $DIR/$tfile; wait_delete_completed"
+       dd if=/dev/urandom of=$DIR/$tfile bs=1M count=20 || error "dd failed"
+       > $DIR/$tfile
+       fallocate -l $((1048576 * 20)) $DIR/$tfile || error "fallocate failed"
+       # precomputed md5sum for 20MB of zeroes
+       local expect="8f4e33f3dc3e414ff94e5fb6905cba8c"
+       local sum=($(md5sum $DIR/$tfile))
+
+       [[ "${sum[0]}" == "$expect" ]] || error "fallocate unwritten is not zero"
+
+       do_nodes $(comma_list $(osts_nodes)) \
+               "$LCTL set_param osd-ldiskfs.*.fallocate_zero_blocks=1" ||
+               error "set osd-ldiskfs.*.fallocate_zero_blocks=1"
+
+       > $DIR/$tfile
+       fallocate -l $((1048576 * 20)) $DIR/$tfile || error "fallocate failed"
+       sum=($(md5sum $DIR/$tfile))
+
+       [[ "${sum[0]}" == "$expect" ]] || error "fallocate zero is not zero"
+}
+run_test 150bb "Verify fallocate modes both zero space"
 
-       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
-       [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
-               skip "Need OST version at least 2.13.53"
+test_150c() {
+       check_for_fallocate
 
+       stack_trap "rm -f $DIR/$tfile; wait_delete_completed"
        $LFS setstripe -c $OSTCOUNT -S1M $DIR/$tfile || error "setstripe failed"
        fallocate -l ${OSTCOUNT}m $DIR/$tfile || error "fallocate failed"
        sync; sync_all_data
@@ -13472,8 +13492,8 @@ test_150c() {
        sync; sync_all_data
        cancel_lru_locks $OSC
        sleep 5
-       bytes=$(($(stat -c '%b * %B' $DIR/$tfile)))
-       want=$((1024 * 1048576))
+       local bytes=$(($(stat -c '%b * %B' $DIR/$tfile)))
+       local want=$((1024 * 1048576))
 
        # Must allocate all requested space, not more than 5% extra
        (( $bytes >= $want && $bytes < $want * 105 / 100 )) ||
@@ -13482,20 +13502,16 @@ test_150c() {
 run_test 150c "Verify fallocate Size and Blocks"
 
 test_150d() {
-       local bytes
-       local want
-
-       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
-       [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
-               skip "Need OST version at least 2.13.53"
+       check_for_fallocate
 
+       stack_trap "rm -f $DIR/$tfile; wait_delete_completed"
        $LFS setstripe -c $OSTCOUNT -S1M $DIR/$tdir || error "setstripe failed"
        fallocate -o 1G -l ${OSTCOUNT}m $DIR/$tdir || error "fallocate failed"
        sync; sync_all_data
        cancel_lru_locks $OSC
        sleep 5
-       bytes=$(($(stat -c '%b * %B' $DIR/$tdir)))
-       want=$((OSTCOUNT * 1048576))
+       local bytes=$(($(stat -c '%b * %B' $DIR/$tdir)))
+       local want=$((OSTCOUNT * 1048576))
 
        # Must allocate all requested space, not more than 5% extra
        (( $bytes >= $want && $bytes < $want * 105 / 100 )) ||
@@ -13504,12 +13520,11 @@ test_150d() {
 run_test 150d "Verify fallocate Size and Blocks - Non zero start"
 
 test_150e() {
-       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
-       [ $OST1_VERSION -ge $(version_code 2.13.55) ] ||
-               skip "Need OST version at least 2.13.55"
+       check_for_fallocate
 
        echo "df before:"
        $LFS df
+       stack_trap "rm -f $DIR/$tfile; wait_delete_completed"
        $LFS setstripe -c${OSTCOUNT} $DIR/$tfile ||
                error "$LFS setstripe -c${OSTCOUNT} $DIR/$tfile failed"