Message ID | a64b4c4d199b822fe72bf4c3752b61e0dc0f3e19.1644217569.git.ojaswin@linux.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | tests/ext4: Ensure resizes with sparse_super2 are handled correctly | expand |
On 22/02/07 01:55PM, Ojaswin Mujoo wrote: > The current implementation of ext4_resize returned 1 whenever > there was an error. Modify this to return the correct error code. > This is important for tests that rely on correct error reporting, by > the kernel, for ext4 resize functionality. > > Additionaly, perform some code cleanup. Thanks for fixing the error return codes. This looks good to me. Feel free to add - Reviewed-by: Ritesh Harjani <riteshh@linux.ibm.com> Stats on running this stats on my dev machine <on old kernels> =================== qemu@qemu:~/src/tools/xfstests-dev$ sudo ./check -s ext4_4k ext4/056 SECTION -- ext4_4k FSTYP -- ext4 PLATFORM -- Linux/ppc64le qemu 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:11 UTC 2022 MKFS_OPTIONS -- -I 256 -O 64bit -F -b 4096 /dev/loop10 MOUNT_OPTIONS -- -o data=ordered /dev/loop10 /mnt1/scratch ext4/056 [failed, exit status 1]- output mismatch (see /home/qemu/src/tools/xfstests-dev/results//ext4_4k/ext4/056.out.bad) --- tests/ext4/056.out 2022-02-19 06:55:22.233659113 +0000 +++ /home/qemu/src/tools/xfstests-dev/results//ext4_4k/ext4/056.out.bad 2022-02-19 06:57:48.931542566 +0000 @@ -1,2 +1,3 @@ QA output created by 056 -Test Succeeded! +_check_generic_filesystem: filesystem on /dev/loop10 is inconsistent +(see /home/qemu/src/tools/xfstests-dev/results//ext4_4k/ext4/056.full for details) ... (Run 'diff -u /home/qemu/src/tools/xfstests-dev/tests/ext4/056.out /home/qemu/src/tools/xfstests-dev/results//ext4_4k/ext4/056.out.bad' to see the entire diff) Ran: ext4/056 Failures: ext4/056 Failed 1 of 1 tests SECTION -- ext4_4k ========================= Ran: ext4/056 Failures: ext4/056 Failed 1 of 1 tests <on 5.16.0-rc4> =================== qemu@qemu:~/src/tools/xfstests-dev$ sudo ./check -s ext4_4k -i 10 ext4/056 SECTION -- ext4_4k FSTYP -- ext4 PLATFORM -- Linux/ppc64le qemu 5.16.0-rc4+ #6 SMP Sat Jan 29 22:07:24 UTC 2022 MKFS_OPTIONS -- -I 256 -O 64bit -F -b 4096 /dev/loop10 MOUNT_OPTIONS -- -o data=ordered /dev/loop10 /mnt1/scratch ext4/056 9s ... 11s Ran: ext4/056 Passed all 1 tests -ritesh
diff --git a/src/ext4_resize.c b/src/ext4_resize.c index 39e16529..78b66432 100644 --- a/src/ext4_resize.c +++ b/src/ext4_resize.c @@ -10,6 +10,7 @@ #include <unistd.h> #include <stdint.h> #include <stdlib.h> +#include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> @@ -19,33 +20,50 @@ typedef unsigned long long __u64; #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64) #endif +#define pr_error(fmt, ...) do { \ + fprintf (stderr, "ext4_resize.c: " fmt, ##__VA_ARGS__); \ +} while (0) + +static void usage(void) +{ + fprintf(stdout, "\nUsage: ext4_resize [mnt_path] [new_size(blocks)]\n"); +} + int main(int argc, char **argv) { __u64 new_size; int error, fd; - char *tmp = NULL; + char *mnt_dir = NULL, *tmp = NULL; if (argc != 3) { - fputs("insufficient arguments\n", stderr); - return 1; - } - fd = open(argv[1], O_RDONLY); - if (!fd) { - perror(argv[1]); - return 1; + error = EINVAL; + pr_error("insufficient arguments\n"); + usage(); + return error; } + mnt_dir = argv[1]; + errno = 0; new_size = strtoull(argv[2], &tmp, 10); if ((errno) || (*tmp != '\0')) { - fprintf(stderr, "%s: invalid new size\n", argv[0]); - return 1; + error = errno; + pr_error("invalid new size\n"); + return error; + } + + fd = open(mnt_dir, O_RDONLY); + if (fd < 0) { + error = errno; + pr_error("open() failed with error: %s\n", strerror(error)); + return error; } - error = ioctl(fd, EXT4_IOC_RESIZE_FS, &new_size); - if (error < 0) { - perror("EXT4_IOC_RESIZE_FS"); - return 1; + if(ioctl(fd, EXT4_IOC_RESIZE_FS, &new_size) < 0) { + error = errno; + pr_error("EXT4_IOC_RESIZE_FS ioctl() failed with error: %s\n", strerror(error)); + return error; } + return 0; }
The current implementation of ext4_resize returned 1 whenever there was an error. Modify this to return the correct error code. This is important for tests that rely on correct error reporting, by the kernel, for ext4 resize functionality. Additionaly, perform some code cleanup. Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> --- src/ext4_resize.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-)