Message ID | 20220720000256.239531-1-bongiojp@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | [v5] ext4/056: add a check to make sure ext4 uuid ioctls get/set during fsstress. | expand |
On Tue, Jul 19, 2022 at 05:02:56PM -0700, Jeremy Bongio wrote: > Adds a utility to set/get uuid through ext4 ioctl. Executes the ioctls > while running fsstress. These ioctls are used by tune2fs to safely change > the uuid without racing other filesystem modifications. > > Reviewed-by: Darrick J. Wong <djwong@kernel.org> > Signed-off-by: Jeremy Bongio <bongiojp@gmail.com> > --- > > Changes in v5: > > Added reviewed-by tag. > > Added wait after killing fsstress pids. > > Removed _scratch_mount output redirection. > > .gitignore | 1 + > src/Makefile | 4 +- > src/uuid_ioctl.c | 105 +++++++++++++++++++++++++++++++++++++++++++++ > tests/ext4/056 | 64 +++++++++++++++++++++++++++ > tests/ext4/056.out | 2 + > 5 files changed, 174 insertions(+), 2 deletions(-) > create mode 100644 src/uuid_ioctl.c > create mode 100755 tests/ext4/056 > create mode 100644 tests/ext4/056.out > > diff --git a/.gitignore b/.gitignore > index ba0c572b..dab24d68 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -169,6 +169,7 @@ tags > /src/unwritten_mmap > /src/unwritten_sync > /src/usemem > +/src/uuid_ioctl > /src/writemod > /src/writev_on_pagefault > /src/xfsctl > diff --git a/src/Makefile b/src/Makefile > index 111ce1d9..e33e04de 100644 > --- a/src/Makefile > +++ b/src/Makefile > @@ -31,14 +31,14 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ > dio-invalidate-cache stat_test t_encrypted_d_revalidate \ > attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ > fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ > - detached_mounts_propagation ext4_resize > + detached_mounts_propagation ext4_resize uuid_ioctl > > EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ > btrfs_crc32c_forged_name.py > > SUBDIRS = log-writes perf > > -LLDLIBS = $(LIBHANDLE) $(LIBACL) -lpthread -lrt > +LLDLIBS = $(LIBHANDLE) $(LIBACL) -lpthread -lrt -luuid > > ifeq ($(HAVE_XLOG_ASSIGN_LSN), true) > LINUX_TARGETS += loggen > diff --git a/src/uuid_ioctl.c b/src/uuid_ioctl.c > new file mode 100644 > index 00000000..89a9b5d8 > --- /dev/null > +++ b/src/uuid_ioctl.c > @@ -0,0 +1,105 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2022 Google, Inc. All Rights Reserved. > + * > + * Test program which uses the raw ext4 set_fsuuid ioctl directly. > + * SYNOPSIS: > + * $0 COMMAND MOUNT_POINT [UUID] > + * > + * COMMAND must be either "get" or "set". > + * The UUID must be a 16 octet sequence represented as 32 hexadecimal digits in > + * canonical textual representation, e.g. output from `uuidgen`. > + * > + */ > + > +#include <stdio.h> > +#include <fcntl.h> > +#include <errno.h> > +#include <unistd.h> > +#include <stdint.h> > +#include <stdlib.h> > +#include <string.h> > +#include <sys/ioctl.h> > +#include <uuid/uuid.h> > +#include <linux/fs.h> > + > +struct fsuuid { > + __u32 fsu_len; > + __u32 fsu_flags; > + __u8 fsu_uuid[]; > +}; > + > +#ifndef EXT4_IOC_GETFSUUID > +#define EXT4_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) > +#endif > + > +#ifndef EXT4_IOC_SETFSUUID > +#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid) > +#endif > + > +int main(int argc, char **argv) > +{ > + int error, fd; > + struct fsuuid *fsuuid = NULL; > + > + if (argc < 3) { > + fprintf(stderr, "Invalid arguments\n"); > + return 1; > + } > + > + fd = open(argv[2], O_RDONLY); > + if (!fd) { > + perror(argv[2]); > + return 1; > + } > + > + fsuuid = malloc(sizeof(*fsuuid) + sizeof(uuid_t)); > + if (!fsuuid) { > + perror("malloc"); > + return 1; > + } > + fsuuid->fsu_len = sizeof(uuid_t); > + fsuuid->fsu_flags = 0; > + > + if (strcmp(argv[1], "get") == 0) { > + uuid_t uuid; > + char uuid_str[37]; > + > + if (ioctl(fd, EXT4_IOC_GETFSUUID, fsuuid)) { > + fprintf(stderr, "%s while trying to get fs uuid\n", > + strerror(errno)); > + return 1; > + } > + > + memcpy(&uuid, fsuuid->fsu_uuid, sizeof(uuid)); > + uuid_unparse(uuid, uuid_str); > + printf("%s\n", uuid_str); > + } else if (strcmp(argv[1], "set") == 0) { > + uuid_t uuid; > + > + if (argc != 4) { > + fprintf(stderr, "UUID argument missing.\n"); > + return 1; > + } > + > + error = uuid_parse(argv[3], uuid); > + if (error < 0) { > + fprintf(stderr, "Invalid UUID. The UUID should be in " > + "canonical format. Example: " > + "8c628557-6987-42b2-ba16-b7cc79ddfb43\n"); > + return 1; > + } > + > + memcpy(&fsuuid->fsu_uuid, uuid, sizeof(uuid)); > + if (ioctl(fd, EXT4_IOC_SETFSUUID, fsuuid)) { > + fprintf(stderr, "%s while trying to set fs uuid\n", > + strerror(errno)); > + return 1; > + } > + } else { > + fprintf(stderr, "Invalid command\n"); > + return 1; > + } > + > + return 0; > +} > diff --git a/tests/ext4/056 b/tests/ext4/056 > new file mode 100755 > index 00000000..376f2972 > --- /dev/null > +++ b/tests/ext4/056 > @@ -0,0 +1,64 @@ > +#! /bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# Copyright (c) 2022 Google, Inc. All Rights Reserved. > +# > +# Test the set/get UUID ioctl. > +# > + > +. ./common/preamble > +_begin_fstest auto ioctl > + > +# Override the default cleanup function. > +_cleanup() > +{ > + cd / > + rm -r -f $tmp.* > + kill -9 $fsstress_pid 2>/dev/null; > + wait $fsstress_pid > /dev/null 2>&1 I think "wait" is enough. With this change, it's good to me. Reviewed-by: Zorro Lang <zlang@redhat.com> > +} > + > +# Import common functions. > +. ./common/filter > + > +# real QA test starts here > +_supported_fs ext4 > +_require_scratch > +_require_test_program uuid_ioctl > +_require_command $UUIDGEN_PROG uuidgen > + > +UUID_IOCTL=$here/src/uuid_ioctl > + > +# If the ioctl is not supported by the kernel, then skip test. > +current_uuid=$($UUID_IOCTL get $SCRATCH_MNT 2>&1) > +if [[ "$current_uuid" =~ ^Inappropriate[[:space:]]ioctl ]]; then > + _notrun "UUID ioctls are not supported by kernel." > +fi > + > +# metadata_csum_seed must be set to decouple checksums from the uuid. > +# Otherwise, checksums need to be recomputed when the uuid changes, which > +# is not supported by the ioctl. > +_scratch_mkfs_ext4 -O metadata_csum_seed >> $seqres.full 2>&1 > +_scratch_mount > + > +# Begin fsstress while modifying UUID > +fsstress_args=$(_scale_fsstress_args -d $SCRATCH_MNT -p 15 -n 999999) > +$FSSTRESS_PROG $fsstress_args > /dev/null 2>&1 & > +fsstress_pid=$! > + > +for n in $(seq 1 20); do > + new_uuid=$($UUIDGEN_PROG) > + > + echo "Setting UUID to ${new_uuid}" >> $seqres.full 2>&1 > + $UUID_IOCTL set $SCRATCH_MNT $new_uuid > + > + current_uuid=$($UUID_IOCTL get $SCRATCH_MNT) > + echo "$UUID_IOCTL get $SCARTCH_MNT: $current_uuid" >> $seqres.full 2>&1 > + if [[ "$current_uuid" != "$new_uuid" ]]; then > + echo "Current UUID ($current_uuid) does not equal what was sent with the ioctl ($new_uuid)" > + fi > +done > + > +# success, all done > +echo "Silence is golden" > +status=0 > +exit > diff --git a/tests/ext4/056.out b/tests/ext4/056.out > new file mode 100644 > index 00000000..6142fcd2 > --- /dev/null > +++ b/tests/ext4/056.out > @@ -0,0 +1,2 @@ > +QA output created by 056 > +Silence is golden > -- > 2.37.0.170.g444d1eabd0-goog >
On Wed, Jul 20, 2022 at 06:09:49PM +0800, Zorro Lang wrote: > On Tue, Jul 19, 2022 at 05:02:56PM -0700, Jeremy Bongio wrote: > > +# Override the default cleanup function. > > +_cleanup() > > +{ > > + cd / > > + rm -r -f $tmp.* > > + kill -9 $fsstress_pid 2>/dev/null; > > + wait $fsstress_pid > /dev/null 2>&1 > > I think "wait" is enough. With this change, it's good to me. The kill -9 is needed, because otherwise the test will run for a **very** long time. The reason for it is because of the -n 999999 in fstress_args: > > +# Begin fsstress while modifying UUID > > +fsstress_args=$(_scale_fsstress_args -d $SCRATCH_MNT -p 15 -n 999999) > > +$FSSTRESS_PROG $fsstress_args > /dev/null 2>&1 & > > +fsstress_pid=$! We could adjust the number of loops to a more reasonable number, but then test becomes less reliable, since depending on the storage device (e.g., cheap USB thumb drive found in the checkout counter at a convenience store, vs. a high-end NVMe SSD) and the overall speed of the system, a different number of loops will be needed. Given that we're *only* using the fsstress as an antogonist while we are changing the UUID of the file system 20 times, killing the fsstress once we're done with the UUID runs is sufficient, I would argue. Also, Jeremy, it looks like you haven't updated your xfstests-dev repository in a few weeks. Since you started this project, ext4/056 has been assigned, and there has been some new helper programs added which caused patch conflicts in src/Makefile and in .gitignore. They were pretty trivial to fix up the patch conflicts (which I've done in my xfstests-dev tree), but it's best practice to rebase on top of origin/for-next and re-test just to make sure there haven't been some major change in the fstests common scripts that might catch your test out. Also, feel free to add my: Reviewed-by: Theodore Ts'o <tytso@mit.edu> Cheers, - Ted
On Wed, Jul 20, 2022 at 07:42:25AM -0400, Theodore Ts'o wrote: > On Wed, Jul 20, 2022 at 06:09:49PM +0800, Zorro Lang wrote: > > On Tue, Jul 19, 2022 at 05:02:56PM -0700, Jeremy Bongio wrote: > > > +# Override the default cleanup function. > > > +_cleanup() > > > +{ > > > + cd / > > > + rm -r -f $tmp.* > > > + kill -9 $fsstress_pid 2>/dev/null; > > > + wait $fsstress_pid > /dev/null 2>&1 > > > > I think "wait" is enough. With this change, it's good to me. > > The kill -9 is needed, because otherwise the test will run for a > **very** long time. The reason for it is because of the -n 999999 in Sure, I mean: kill -9 $fsstress_pid 2>/dev/null wait Not remove the "kill" line :) > fstress_args: > > > > +# Begin fsstress while modifying UUID > > > +fsstress_args=$(_scale_fsstress_args -d $SCRATCH_MNT -p 15 -n 999999) > > > +$FSSTRESS_PROG $fsstress_args > /dev/null 2>&1 & > > > +fsstress_pid=$! > > We could adjust the number of loops to a more reasonable number, but > then test becomes less reliable, since depending on the storage device > (e.g., cheap USB thumb drive found in the checkout counter at a > convenience store, vs. a high-end NVMe SSD) and the overall speed of > the system, a different number of loops will be needed. > > Given that we're *only* using the fsstress as an antogonist while we > are changing the UUID of the file system 20 times, killing the > fsstress once we're done with the UUID runs is sufficient, I would > argue. > > Also, Jeremy, it looks like you haven't updated your xfstests-dev > repository in a few weeks. Since you started this project, ext4/056 > has been assigned, and there has been some new helper programs added > which caused patch conflicts in src/Makefile and in .gitignore. They > were pretty trivial to fix up the patch conflicts (which I've done in > my xfstests-dev tree), but it's best practice to rebase on top of > origin/for-next and re-test just to make sure there haven't been some > major change in the fstests common scripts that might catch your test > out. Thanks for pointing out that, yes, better to rebase to latest fstests for-next branch. > > Also, feel free to add my: > > Reviewed-by: Theodore Ts'o <tytso@mit.edu> Sure, Thanks, Zorro > > Cheers, > > - Ted >
On Wed, Jul 20, 2022 at 11:06:36PM +0800, Zorro Lang wrote: > > The kill -9 is needed, because otherwise the test will run for a > > **very** long time. The reason for it is because of the -n 999999 in > > Sure, I mean: > > kill -9 $fsstress_pid 2>/dev/null > wait > > Not remove the "kill" line :) Ah yes, sorry, I misunderstood what you meant. > > Also, Jeremy, it looks like you haven't updated your xfstests-dev > > repository in a few weeks. Since you started this project, ext4/056 > > has been assigned, and there has been some new helper programs added > > which caused patch conflicts in src/Makefile and in .gitignore. They > > were pretty trivial to fix up the patch conflicts (which I've done in > > my xfstests-dev tree), but it's best practice to rebase on top of > > origin/for-next and re-test just to make sure there haven't been some > > major change in the fstests common scripts that might catch your test > > out. > > Thanks for pointing out that, yes, better to rebase to latest fstests > for-next branch. Jeremy, for your convenience, my version of the change which is rebased on for-next, fixes the merge conflicts and uses ext4/057 instead of ext4/056 can be found here: https://github.com/tytso/xfstests/commit/330bf72dc67dd39e0fd413ecea78ab18b5405fb9 - Ted
On Wed, Jul 20, 2022 at 8:30 AM Theodore Ts'o <tytso@mit.edu> wrote: > > On Wed, Jul 20, 2022 at 11:06:36PM +0800, Zorro Lang wrote: > > > The kill -9 is needed, because otherwise the test will run for a > > > **very** long time. The reason for it is because of the -n 999999 in > > > > Sure, I mean: > > > > kill -9 $fsstress_pid 2>/dev/null > > wait > > > > Not remove the "kill" line :) > > Ah yes, sorry, I misunderstood what you meant. > > > > Also, Jeremy, it looks like you haven't updated your xfstests-dev > > > repository in a few weeks. Since you started this project, ext4/056 > > > has been assigned, and there has been some new helper programs added > > > which caused patch conflicts in src/Makefile and in .gitignore. They > > > were pretty trivial to fix up the patch conflicts (which I've done in > > > my xfstests-dev tree), but it's best practice to rebase on top of > > > origin/for-next and re-test just to make sure there haven't been some > > > major change in the fstests common scripts that might catch your test > > > out. > > > > Thanks for pointing out that, yes, better to rebase to latest fstests > > for-next branch. > > Jeremy, for your convenience, my version of the change which is > rebased on for-next, fixes the merge conflicts and uses ext4/057 > instead of ext4/056 can be found here: > > https://github.com/tytso/xfstests/commit/330bf72dc67dd39e0fd413ecea78ab18b5405fb9 Great. Thank you everyone! I'll use your merged version, fix the wait line, and add Reviewed-by: Zorro Lang <zlang@redhat.com>. > > - Ted
diff --git a/.gitignore b/.gitignore index ba0c572b..dab24d68 100644 --- a/.gitignore +++ b/.gitignore @@ -169,6 +169,7 @@ tags /src/unwritten_mmap /src/unwritten_sync /src/usemem +/src/uuid_ioctl /src/writemod /src/writev_on_pagefault /src/xfsctl diff --git a/src/Makefile b/src/Makefile index 111ce1d9..e33e04de 100644 --- a/src/Makefile +++ b/src/Makefile @@ -31,14 +31,14 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ dio-invalidate-cache stat_test t_encrypted_d_revalidate \ attr_replace_test swapon mkswap t_attr_corruption t_open_tmpfiles \ fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \ - detached_mounts_propagation ext4_resize + detached_mounts_propagation ext4_resize uuid_ioctl EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \ btrfs_crc32c_forged_name.py SUBDIRS = log-writes perf -LLDLIBS = $(LIBHANDLE) $(LIBACL) -lpthread -lrt +LLDLIBS = $(LIBHANDLE) $(LIBACL) -lpthread -lrt -luuid ifeq ($(HAVE_XLOG_ASSIGN_LSN), true) LINUX_TARGETS += loggen diff --git a/src/uuid_ioctl.c b/src/uuid_ioctl.c new file mode 100644 index 00000000..89a9b5d8 --- /dev/null +++ b/src/uuid_ioctl.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Google, Inc. All Rights Reserved. + * + * Test program which uses the raw ext4 set_fsuuid ioctl directly. + * SYNOPSIS: + * $0 COMMAND MOUNT_POINT [UUID] + * + * COMMAND must be either "get" or "set". + * The UUID must be a 16 octet sequence represented as 32 hexadecimal digits in + * canonical textual representation, e.g. output from `uuidgen`. + * + */ + +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <unistd.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <uuid/uuid.h> +#include <linux/fs.h> + +struct fsuuid { + __u32 fsu_len; + __u32 fsu_flags; + __u8 fsu_uuid[]; +}; + +#ifndef EXT4_IOC_GETFSUUID +#define EXT4_IOC_GETFSUUID _IOR('f', 44, struct fsuuid) +#endif + +#ifndef EXT4_IOC_SETFSUUID +#define EXT4_IOC_SETFSUUID _IOW('f', 44, struct fsuuid) +#endif + +int main(int argc, char **argv) +{ + int error, fd; + struct fsuuid *fsuuid = NULL; + + if (argc < 3) { + fprintf(stderr, "Invalid arguments\n"); + return 1; + } + + fd = open(argv[2], O_RDONLY); + if (!fd) { + perror(argv[2]); + return 1; + } + + fsuuid = malloc(sizeof(*fsuuid) + sizeof(uuid_t)); + if (!fsuuid) { + perror("malloc"); + return 1; + } + fsuuid->fsu_len = sizeof(uuid_t); + fsuuid->fsu_flags = 0; + + if (strcmp(argv[1], "get") == 0) { + uuid_t uuid; + char uuid_str[37]; + + if (ioctl(fd, EXT4_IOC_GETFSUUID, fsuuid)) { + fprintf(stderr, "%s while trying to get fs uuid\n", + strerror(errno)); + return 1; + } + + memcpy(&uuid, fsuuid->fsu_uuid, sizeof(uuid)); + uuid_unparse(uuid, uuid_str); + printf("%s\n", uuid_str); + } else if (strcmp(argv[1], "set") == 0) { + uuid_t uuid; + + if (argc != 4) { + fprintf(stderr, "UUID argument missing.\n"); + return 1; + } + + error = uuid_parse(argv[3], uuid); + if (error < 0) { + fprintf(stderr, "Invalid UUID. The UUID should be in " + "canonical format. Example: " + "8c628557-6987-42b2-ba16-b7cc79ddfb43\n"); + return 1; + } + + memcpy(&fsuuid->fsu_uuid, uuid, sizeof(uuid)); + if (ioctl(fd, EXT4_IOC_SETFSUUID, fsuuid)) { + fprintf(stderr, "%s while trying to set fs uuid\n", + strerror(errno)); + return 1; + } + } else { + fprintf(stderr, "Invalid command\n"); + return 1; + } + + return 0; +} diff --git a/tests/ext4/056 b/tests/ext4/056 new file mode 100755 index 00000000..376f2972 --- /dev/null +++ b/tests/ext4/056 @@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Google, Inc. All Rights Reserved. +# +# Test the set/get UUID ioctl. +# + +. ./common/preamble +_begin_fstest auto ioctl + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* + kill -9 $fsstress_pid 2>/dev/null; + wait $fsstress_pid > /dev/null 2>&1 +} + +# Import common functions. +. ./common/filter + +# real QA test starts here +_supported_fs ext4 +_require_scratch +_require_test_program uuid_ioctl +_require_command $UUIDGEN_PROG uuidgen + +UUID_IOCTL=$here/src/uuid_ioctl + +# If the ioctl is not supported by the kernel, then skip test. +current_uuid=$($UUID_IOCTL get $SCRATCH_MNT 2>&1) +if [[ "$current_uuid" =~ ^Inappropriate[[:space:]]ioctl ]]; then + _notrun "UUID ioctls are not supported by kernel." +fi + +# metadata_csum_seed must be set to decouple checksums from the uuid. +# Otherwise, checksums need to be recomputed when the uuid changes, which +# is not supported by the ioctl. +_scratch_mkfs_ext4 -O metadata_csum_seed >> $seqres.full 2>&1 +_scratch_mount + +# Begin fsstress while modifying UUID +fsstress_args=$(_scale_fsstress_args -d $SCRATCH_MNT -p 15 -n 999999) +$FSSTRESS_PROG $fsstress_args > /dev/null 2>&1 & +fsstress_pid=$! + +for n in $(seq 1 20); do + new_uuid=$($UUIDGEN_PROG) + + echo "Setting UUID to ${new_uuid}" >> $seqres.full 2>&1 + $UUID_IOCTL set $SCRATCH_MNT $new_uuid + + current_uuid=$($UUID_IOCTL get $SCRATCH_MNT) + echo "$UUID_IOCTL get $SCARTCH_MNT: $current_uuid" >> $seqres.full 2>&1 + if [[ "$current_uuid" != "$new_uuid" ]]; then + echo "Current UUID ($current_uuid) does not equal what was sent with the ioctl ($new_uuid)" + fi +done + +# success, all done +echo "Silence is golden" +status=0 +exit diff --git a/tests/ext4/056.out b/tests/ext4/056.out new file mode 100644 index 00000000..6142fcd2 --- /dev/null +++ b/tests/ext4/056.out @@ -0,0 +1,2 @@ +QA output created by 056 +Silence is golden