From: "Darrick J. Wong" <djwong@kernel.org>
To: Zorro Lang <zlang@kernel.org>
Cc: fstests@vger.kernel.org
Subject: [PATCH] common/metadump: fix _cleanup_verify_metadump system destructor fleet
Date: Mon, 5 Feb 2024 09:55:52 -0800 [thread overview]
Message-ID: <20240205175552.GJ6188@frogsfrogsfrogs> (raw)
From: Darrick J. Wong <djwong@kernel.org>
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.
Reported-by: Zorro Lang <zlang@redhat.com>
Link: https://lore.kernel.org/fstests/20240205060016.7fgiyafbnrvf5chj@dell-per750-06-vm-08.rhts.eng.pek2.redhat.com/
Fixes: 85c1e0f518 ("common: refactor metadump v1 and v2 tests")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
common/xfs_metadump_tests | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/common/xfs_metadump_tests b/common/xfs_metadump_tests
index 5a5579b6b9..c8652f16ea 100644
--- a/common/xfs_metadump_tests
+++ b/common/xfs_metadump_tests
@@ -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?
next reply other threads:[~2024-02-05 17:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 17:55 Darrick J. Wong [this message]
2024-02-05 20:04 ` [PATCH] common/metadump: fix _cleanup_verify_metadump system destructor fleet Zorro Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240205175552.GJ6188@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=zlang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).