common/metadump: fix _cleanup_verify_metadump system destructor fleet
PATCH 1/1 common/metadump: fix _cleanup_verify_metadump system destructor fleet
From: Darrick J. Wong <[email protected]>
Zorro reported that the cleanup function in common/xfs_metadump_tests zapped one of his test machines because of a well known shell variable expansion + globbing footgun. This can trigger when running fstests on older configurations where a test adds _cleanup_verify_metadump to the local _cleanup function but exits before calling _setup_verify_metadump to set XFS_METADUMP_IMG to a non-empty value.
Redesign the cleanup function to check for non-empty values of XFS_METADUMP_{FILE,IMG} before proceeding with the rm. Change the globbed parameter of "rm -f $XFS_METADUMP_IMG*" to a for loop so that if the glob does not match any files, the loop variable will be set to a path that does not resolve anywhere.
Longer term maybe we ought to set -u or something. Or figure out how to make the root filesystem readonly when we're running a test.
--- common/xfs_metadump_tests | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
common/xfs_metadump_tests +15 -4
@@ -15,12 +15,23 @@ _setup_verify_metadump() _cleanup_verify_metadump() { + local img + _scratch_unmount &>> $seqres.full - losetup -n -a -O BACK-FILE,NAME | grep "^$XFS_METADUMP_IMG" | while read backing ldev; do - losetup -d "$ldev" - done - rm -f "$XFS_METADUMP_FILE" "$XFS_METADUMP_IMG"* + test -n "$XFS_METADUMP_FILE" && rm -f "$XFS_METADUMP_FILE" + + if [ -n "$XFS_METADUMP_IMG" ]; then + losetup -n -a -O BACK-FILE,NAME | grep "^$XFS_METADUMP_IMG" | while read backing ldev; do + losetup -d "$ldev" + done + + # Don't call rm directly with a globbed argument here to avoid + # issues issues with variable expansions. + for img in "$XFS_METADUMP_IMG"*; do + test -e "$img" && rm -f "$img" + done + fi } # Can xfs_metadump snapshot the fs metadata to a v1 metadump file?
Quoted 15 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Zorro reported that the cleanup function in common/xfs_metadump_tests zapped one of his test machines because of a well known shell variable expansion + globbing footgun. This can trigger when running fstests on older configurations where a test adds
_cleanup_verify_metadumpto the local_cleanupfunction but exits before calling_setup_verify_metadumpto setXFS_METADUMP_IMGto a non-empty value.Redesign the cleanup function to check for non-empty values of XFS_METADUMP_{FILE,IMG} before proceeding with the rm. Change the globbed parameter of "rm -f $XFS_METADUMP_IMG*" to a for loop so that if the glob does not match any files, the loop variable will be set to a path that does not resolve anywhere.
Quoted 8 lines
Longer term maybe we ought to set -u or something. Or figure out how to make the root filesystem readonly when we're running a test.
Reported-by Zorro Lang <[email protected]>Link https://lore.kernel.org/fstests/20240205060016.7fgiyafbnrvf5chj@dell-per750-06-vm-08.rhts.eng.pek2.redhat.com/ open hereFixes 85c1e0f518 ("common: refactor metadump v1 and v2 tests")Signed-off-by Darrick J. Wong <[email protected]>---
Hi Darrick,
This change looks good to me, but I've reset the for-next branch, remove the v2024.02.04 totally, to avoid it kills others' systems. Now there's not v2024.02.04 release anymore, so you can resend a V2 of:
[PATCHSET] fstests: random fixes for v2024.01.14
or resend the:
[PATCH 05/10] common: refactor metadump v1 and v2 tests
if you don't have more changes on others.
Quoted 1 line
common/xfs_metadump_tests | 19 +++++++++++++++----
I saw you name this patch as common/metadump, if already have a patchset which changes the common/xfs_metadump_tests to common/metadump, feel free to send to me directly as V2 :)
Thanks,
Zorro
Quoted 35 lines
1 file changed, 15 insertions(+), 4 deletions(-)common/xfs_metadump_tests +15
-4@@ -15,12 +15,23 @@ _setup_verify_metadump() _cleanup_verify_metadump() { + local img + _scratch_unmount &>> $seqres.full - losetup -n -a -O BACK-FILE,NAME | grep "^$XFS_METADUMP_IMG" | while read backing ldev; do - losetup -d "$ldev" - done - rm -f "$XFS_METADUMP_FILE" "$XFS_METADUMP_IMG"* + test -n "$XFS_METADUMP_FILE" && rm -f "$XFS_METADUMP_FILE" + + if [ -n "$XFS_METADUMP_IMG" ]; then + losetup -n -a -O BACK-FILE,NAME | grep "^$XFS_METADUMP_IMG" | while read backing ldev; do + losetup -d "$ldev" + done + + # Don't call rm directly with a globbed argument here to avoid + # issues issues with variable expansions. + for img in "$XFS_METADUMP_IMG"*; do + test -e "$img" && rm -f "$img" + done + fi } # Can xfs_metadump snapshot the fs metadata to a v1 metadump file?