Whamcloud - gitweb
LU-14286 osd-ldiskfs: don't read unwritten blocks 16/41216/4
authorAlex Zhuravlev <bzzz@whamcloud.com>
Wed, 13 Jan 2021 15:48:54 +0000 (18:48 +0300)
committerOleg Drokin <green@whamcloud.com>
Fri, 22 Jan 2021 20:14:10 +0000 (20:14 +0000)
which were allocated using fallocate(2), instead fill
the pages with zeroes.

Add a test to verify that fallocated blocks read as zeroes.

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I9c0c90f93fd33f26f834144e225b2643cf9fffb7
Reviewed-on: https://review.whamcloud.com/41216
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/osd-ldiskfs/osd_io.c
lustre/tests/sanity.sh

index 77843ff..66db3f5 100644 (file)
@@ -1156,6 +1156,14 @@ cont_map:
                                        total++;
                                        break;
                                }
+                               if ((map.m_flags & LDISKFS_MAP_UNWRITTEN) &&
+                                   !create) {
+                                       /* don't try to read allocated, but
+                                        * unwritten blocks, instead fill the
+                                        * patches with zeros in osd_do_bio() */
+                                       *(blocks + total) = 0;
+                                       continue;
+                               }
                                *(blocks + total) = map.m_pblk + c;
                                /* unmap any possible underlying
                                 * metadata from the block device
index ff2db35..fcde344 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,9 +13429,6 @@ 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"
 
@@ -13439,10 +13437,27 @@ test_150b() {
        [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
                skip "Need OST version at least 2.13.53"
        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_150bb() {
+       [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
+       [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
+               skip "Need OST version at least 2.13.53"
+       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"
+       local sum=($(md5sum $DIR/$tfile))
+       local expect="8f4e33f3dc3e414ff94e5fb6905cba8c"
+
+       [[ "${sum[0]}" == "$expect" ]] || error "fallocated file is not zero"
+}
+run_test 150bb "Verify fallocate zeroes space"
+
 test_150c() {
        local bytes
        local want
@@ -13451,6 +13466,7 @@ test_150c() {
        [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
                skip "Need OST version at least 2.13.53"
 
+       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
@@ -13489,6 +13505,7 @@ test_150d() {
        [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
                skip "Need OST version at least 2.13.53"
 
+       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
@@ -13510,6 +13527,7 @@ test_150e() {
 
        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"