From 90c021417d2a16efb5dd6968b2e0c056b5a897fc Mon Sep 17 00:00:00 2001 From: Elena Gryaznova Date: Sun, 18 Aug 2024 17:08:55 +0300 Subject: [PATCH] LU-18075 tests: fiemap test for sparse files New "Check fiemap for sparse files" test shows the memory corruption without the following fix: LU-17110 llite: fix slab corruption with fm_extent_count=0 Test-Parameters: trivial testlist=sanity env=ONLY=44f,ONLY_REPEAT=10,NUMFILES_44f=20 Signed-off-by: Elena Gryaznova Signed-off-by: Vladimir Saveliev HPE-bug-id: LUS-11952,LUS-12040 Reviewed-by: Andrew Perepechko Reviewed-by: Vladimir Saveliev Change-Id: I22034c7937366d9ea4b2b3f02fd7085d7ebe7e10 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55883 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/tests/multiop.c | 37 +++++++++++++++++++++++++++++++++++++ lustre/tests/sanity.sh | 16 ++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/lustre/tests/multiop.c b/lustre/tests/multiop.c index 69da675..82b91be 100644 --- a/lustre/tests/multiop.c +++ b/lustre/tests/multiop.c @@ -82,6 +82,7 @@ char usage[] = " G gid get grouplock\n" " g gid put grouplock\n" " H[num] create HSM released file with num stripes\n" +" I fiemap\n" " K link path to filename\n" " L link\n" " l symlink filename to path\n" @@ -235,6 +236,39 @@ out_closedir: return rc; } +static int do_fiemap(int fd) +{ + struct fiemap *pf; + int extents; + int save_errno; + int i; + + extents = 0; + for (i = 0; i < 2; i++) { + if ((pf = malloc(sizeof(struct fiemap) + + extents * sizeof(struct fiemap_extent))) == NULL) { + perror("malloc failed"); + exit(1); + } + pf->fm_start = 0; + pf->fm_length = FIEMAP_MAX_OFFSET; + pf->fm_flags = FIEMAP_FLAG_SYNC; + pf->fm_extent_count = extents; + + if (ioctl(fd, FS_IOC_FIEMAP, pf) < 0) { + save_errno = errno; + if (i == 0) + perror("probe fiemap failed"); + else + perror("fiemap failed"); + exit(save_errno); + } + extents = pf->fm_mapped_extents; + free(pf); + } + return 0; +} + #define POP_ARG() (pop_arg(argc, argv)) int main(int argc, char **argv) @@ -478,6 +512,9 @@ int main(int argc, char **argv) } rc = fd; break; + case 'I': + do_fiemap(fd); + break; case 'j': if (flock(fd, LOCK_EX) == -1) errx(-1, "flock()"); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 871c575..31dd8dc 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -6036,6 +6036,22 @@ test_44e() { } run_test 44e "write and read maximal stripes" +test_44f() { + [ "$FSTYPE" != "zfs" ] || + skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" + + local i + # required space: NUMFILES_44f * 20Mb + local NUMFILES_44f=${NUMFILES_44f:-50} + + for (( i=0; i