public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: chandan.babu@gmail.com
Cc: linux-xfs@vger.kernel.org, david@fromorbit.com, sandeen@sandeen.net
Subject: [PATCH 5/3] xfs/270: actually test log recovery with unknown rocompat features
Date: Thu, 24 Aug 2023 16:28:05 -0700	[thread overview]
Message-ID: <20230824232805.GC17912@frogsfrogsfrogs> (raw)
In-Reply-To: <169291929524.220104.3844042018007786965.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

Make sure that log recovery will not succeed if there are unknown
rocompat features in the superblock and the log is dirty.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 tests/xfs/270     |   81 ++++++++++++++++++++++++++++++++++++-----------------
 tests/xfs/270.out |    2 +
 2 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/tests/xfs/270 b/tests/xfs/270
index 511dfe9fcd..ee925b0fc6 100755
--- a/tests/xfs/270
+++ b/tests/xfs/270
@@ -21,41 +21,48 @@ _supported_fs xfs
 _require_scratch_nocheck
 # Only V5 XFS disallow rw mount/remount with unknown ro-compat features
 _require_scratch_xfs_crc
-
-_scratch_mkfs_xfs >>$seqres.full 2>&1
-_scratch_mount
-echo moo > $SCRATCH_MNT/testfile
-_scratch_unmount
+_require_scratch_shutdown
 
 # set the highest bit of features_ro_compat, use it as an unknown
 # feature bit. If one day this bit become known feature, please
 # change this case.
+set_bad_rocompat() {
+	ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0")
+	echo $ro_compat | grep -q -E '^0x[[:xdigit:]]$'
+	if [[ $? != 0  ]]; then
+		echo "features_ro_compat has an invalid value."
+		return 1
+	fi
 
-ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0")
-echo $ro_compat | grep -q -E '^0x[[:xdigit:]]$'
-if [[ $? != 0  ]]; then
-	echo "features_ro_compat has an invalid value."
-fi
+	ro_compat=$(echo $ro_compat | \
+			    awk '/^0x[[:xdigit:]]+/ {
+					printf("0x%x\n", or(strtonum($1), 0x80000000))
+				}')
 
-ro_compat=$(echo $ro_compat | \
-		    awk '/^0x[[:xdigit:]]+/ {
-				printf("0x%x\n", or(strtonum($1), 0x80000000))
-			}')
+	# write the new ro compat field to the superblock
+	_scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
+					> $seqres.full 2>&1
 
-# write the new ro compat field to the superblock
-_scratch_xfs_set_metadata_field "features_ro_compat" "$ro_compat" "sb 0" \
-				> $seqres.full 2>&1
+	# read the newly set ro compat filed for verification
+	new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
+							2>/dev/null)
 
-# read the newly set ro compat filed for verification
-new_ro_compat=$(_scratch_xfs_get_metadata_field "features_ro_compat" "sb 0" \
-						2>/dev/null)
+	# verify the new ro_compat field is correct. Without xfsprogs commit
+	# f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()"),
+	# we can't get new_ro_compat value.
+	if [ "$new_ro_compat" != "$ro_compat" ]; then
+		echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat"
+		return 1
+	fi
+	return 0
+}
 
-# verify the new ro_compat field is correct. Without xfsprogs commit
-# f4afdcb0ad ("xfs_db: clean up the salvage read callsites in set_cur()"),
-# we can't get new_ro_compat value.
-if [ "$new_ro_compat" != "$ro_compat" ]; then
-	echo "Unable to set new features_ro_compat. Wanted $ro_compat, got $new_ro_compat"
-fi
+# Once with a clean filesystem...
+_scratch_mkfs_xfs >>$seqres.full 2>&1
+_scratch_mount
+echo moo > $SCRATCH_MNT/testfile
+_scratch_unmount
+set_bad_rocompat
 
 # rw mount with unknown ro-compat feature should fail
 echo "rw mount test"
@@ -85,6 +92,28 @@ fi
 
 _scratch_unmount
 
+# And again with a dirty filesystem...
+_scratch_mkfs_xfs >>$seqres.full 2>&1
+_scratch_mount
+echo moo > $SCRATCH_MNT/testfile
+$XFS_IO_PROG -x -c 'shutdown -f' "${SCRATCH_MNT}"
+_scratch_unmount
+set_bad_rocompat
+
+# rw mount with unknown ro-compat feature should fail
+echo "rw mount test"
+_try_scratch_mount 2>>$seqres.full
+if [ $? -eq 0 ]; then
+	_fail "rw mount test failed"
+fi
+
+# ro mount should not succeed due to log recovery
+echo "ro mount test"
+_try_scratch_mount -o ro 2>>$seqres.full
+if [ $? -eq 0 ]; then
+	_fail "ro mount test succeeded"
+fi
+
 # success, all done
 status=0
 exit
diff --git a/tests/xfs/270.out b/tests/xfs/270.out
index edf4c25489..a519d2f328 100644
--- a/tests/xfs/270.out
+++ b/tests/xfs/270.out
@@ -2,3 +2,5 @@ QA output created by 270
 rw mount test
 ro mount test
 rw remount test
+rw mount test
+ro mount test

      parent reply	other threads:[~2023-08-24 23:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 23:21 [PATCHSET 0/3] xfs: fix ro mounting with unknown rocompat features Darrick J. Wong
2023-08-24 23:21 ` [PATCH 1/3] xfs: allow inode inactivation during a ro mount log recovery Darrick J. Wong
2023-08-24 23:21 ` [PATCH 2/3] xfs: don't allow log recovery when unknown rocompat bits are set Darrick J. Wong
2023-08-25  1:07   ` Dave Chinner
2023-08-25  4:04     ` Darrick J. Wong
2023-08-28 19:08       ` Darrick J. Wong
2023-08-28 21:47         ` Dave Chinner
2023-08-29  3:10           ` Darrick J. Wong
2023-08-24 23:21 ` [PATCH 3/3] xfs: log is not writable if we have unknown rocompat features Darrick J. Wong
2023-08-25  1:08   ` Dave Chinner
2023-08-24 23:27 ` [PATCH 4/3] xfs/270: actually test file readability Darrick J. Wong
2023-08-24 23:28 ` Darrick J. Wong [this message]

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=20230824232805.GC17912@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=chandan.babu@gmail.com \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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