Whamcloud - gitweb
LU-14286 osd-ldiskfs: fallocate() should zero new blocks 19/41119/10
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Thu, 31 Dec 2020 19:40:34 +0000 (01:10 +0530)
committerOleg Drokin <green@whamcloud.com>
Mon, 11 Jan 2021 01:10:00 +0000 (01:10 +0000)
The ldiskfs osd_fallocate() does not correctly zero the
allocated blocks. This is not noticed during autotest and
local developer testing because the underlying storage is
zero-filled due to using a sparse backing file and will
usually read back as zero. Also, the fsx data correctness
test was not properly detecting fallocate() support, and
as a result this behavior was not detected properly.

'fsx' uses test_fallocate() to determine if fallocate()
along with its various FLAGS is enabled and could be
called. It was found that test_fallocate() always returned
false as a bug. Resulting is fallocate being skipped always
for all fsx runs.

This patches fixes test_fallocate() to properly determine
if fallocate calls could be supported or not and return
appropriately and correctly (1 or 0) true/false.

After patch:
~~~~~~~~~~~
$ MOUNT_2="yes" bash ./lustre/tests/llmount.sh

$ lfs setstripe -c -1 /mnt/lustre/f110

$ fsx -c 50 -p 100 -N 2500 -S 0 -l 10485760 /mnt/lustre*/f110
Chance of close/open is 1 in 50
Seed set to 4481
fd 0: /mnt/lustre/f110
fd 1: /mnt/lustre2/f110
fsx: test_fallocate: does not support fallocate mode 0x3, disabling!
fsx: test_fallocate: does not support fallocate mode 0x10, disabling!
skipping zero size read
:
fallocating to largest ever: 0x30ce
:
1900[0] 1609444486.316868 fallocate  0x7f6c thru 0xab3a (0x2bcf bytes)
:
2300[1] 1609444487.241910 fallocate  0x0697 thru 0xed8e (0xe6f8 bytes)
:
All operations completed A-OK!
$

Test-Parameters: trivial testlist=sanity,sanityn,sanity-dom env=COUNT=10000
Fixes: 48457868a02a ("LU-3606 fallocate: Implement fallocate preallocate operation")
Fixes: 853d180121a6 ("LU-3606 fsx: Add fallocate operation to fsx")
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: Idbb092db6bd09cfda129f6077dcbfae4f4c9d0d0
Reviewed-on: https://review.whamcloud.com/41119
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/osd-ldiskfs/osd_io.c
lustre/tests/fsx.c

index b9660d9..77843ff 100644 (file)
@@ -2218,7 +2218,8 @@ static int osd_fallocate(const struct lu_env *env, struct dt_object *dt,
        boff = start >> inode->i_blkbits;
        blen = (ALIGN(end, 1 << inode->i_blkbits) >> inode->i_blkbits) - boff;
 
        boff = start >> inode->i_blkbits;
        blen = (ALIGN(end, 1 << inode->i_blkbits) >> inode->i_blkbits) - boff;
 
-       flags = LDISKFS_GET_BLOCKS_CREATE;
+       /* Create and Write zeros to new extents */
+       flags = LDISKFS_GET_BLOCKS_CREATE_ZERO;
        if (mode & FALLOC_FL_KEEP_SIZE)
                flags |= LDISKFS_GET_BLOCKS_KEEP_SIZE;
 
        if (mode & FALLOC_FL_KEEP_SIZE)
                flags |= LDISKFS_GET_BLOCKS_KEEP_SIZE;
 
index 36b27f7..2f765c0 100644 (file)
@@ -1530,12 +1530,13 @@ test_fallocate(int mode)
                        if (!quiet)
                                warn("%s: filesystem does not support fallocate mode 0x%x, disabling!",
                                     __func__, mode);
                        if (!quiet)
                                warn("%s: filesystem does not support fallocate mode 0x%x, disabling!",
                                     __func__, mode);
+               } else {
+                       ret = 1;
                }
 
                }
 
-               if (ret == 0 && ftruncate(fd, 0) == -1) {
-                       ret = 1;
+               /* Call truncate only when fallocate succeeds */
+               if (ret == 1 && ftruncate(fd, 0) == -1)
                        warn("ftruncate to 0 size failed");
                        warn("ftruncate to 0 size failed");
-               }
        }
        return ret;
 }
        }
        return ret;
 }