From 72617588ac8cb2e3e5a7b8e5ebc201cab524d938 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Fri, 1 Jan 2021 01:10:34 +0530 Subject: [PATCH 1/1] LU-14286 osd-ldiskfs: fallocate() should zero new blocks 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 Change-Id: Idbb092db6bd09cfda129f6077dcbfae4f4c9d0d0 Reviewed-on: https://review.whamcloud.com/41119 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Andreas Dilger --- lustre/osd-ldiskfs/osd_io.c | 3 ++- lustre/tests/fsx.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index b9660d9..77843ff 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -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; - 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; diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index 36b27f7..2f765c0 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -1530,12 +1530,13 @@ test_fallocate(int 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"); - } } return ret; } -- 1.8.3.1