Skip to contentSkip to conversation

common: add proper btrfs log tree detection to _has_metadata_journaling

PATCH In review Qu Wenruo 3 participants 4 messages Jun 30, 2025 – Jul 2, 2025 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 common: add proper btrfs log tree detection to _has_metadata_journaling

[BUG]
With the incoming btrfs shutdown ioctl/remove_bdev callback support, btrfs can be tested with the shutdown group.

But test case generic/050 still fails on btrfs with shutdown support:

generic/050 1s ... - output mismatch (see /home/adam/xfstests/results//generic/050.out.bad)
--- tests/generic/050.out 2022-05-11 11:25:30.763333331 +0930
+++ /home/adam/xfstests/results//generic/050.out.bad 2025-06-30 10:22:21.752068622 +0930
@@ -13,9 +13,7 @@
setting device read-only
mounting filesystem that needs recovery on a read-only device:
mount: device write-protected, mounting read-only
-mount: cannot mount device read-only
unmounting read-only filesystem
-umount: SCRATCH_DEV: not mounted
mounting filesystem with -o norecovery on a read-only device:
...
(Run 'diff -u /home/adam/xfstests/tests/generic/050.out /home/adam/xfstests/results//generic/050.out.bad' to see the entire diff)
Ran: generic/050

[CAUSE]
The test case generic/050 has several different golden output depending on the fs features.

For fses which requires data write (e.g. replay the journal) during mount, mounting a read-only block device should fail. And that is the default golden output.

However there are cases that the fs doesn't need to write anything, e.g. the fs has no metadata journal support at all, or the fs has no dirty journal to replay.

In that case, there is the generic/050.nojournal golden output.

The test case is using the helper _has_metadata_journaling() to determine the feature.

Unfortunately that helper doesn't support btrfs, thus the default behavior is to assume the fs has journal to replay, thus for btrfs it always assume there is a journal to replay and results the wrong golden output to be used.

[FIX]
Add btrfs specific log tree check into _has_metadata_journaling(), so that if there is no log tree to replay, expose the "nojournal" feature correctly to pass generic/050.

---
 common/rc | 8 ++++++++
 1 file changed, 8 insertions(+)
common/rc +8 -0
index 2d8e7167..a78b779a 100644
@@ -4283,6 +4283,14 @@ _has_metadata_journaling()
 			return 1
 		fi
 		;;
+	btrfs)
+		_require_btrfs_command inspect-internal dump-super
+		if "$BTRFS_UTIL_PROG" inspect-internal dump-super $dev | \
+		   grep -q "log_root\s\+0" ; then
+			echo "$FSTYPE on $dev has empty log tree"
+			return 1
+		fi
+		;;
 	*)
 		# by default we pass; if you need to, add your fs above!
 		;;
Signature · 1 line
2.50.0
author
#1 lore raw
Quoted 3 lines · Qu Wenruo

[BUG]
With the incoming btrfs shutdown ioctl/remove_bdev callback support, btrfs can be tested with the shutdown group.

Forgot to mention, if someone is going to test btrfs with shutdown support, here is the branch:

https://github.com/adam900710/linux.git shutdown

Thanks,
Qu

Quoted 69 lines

But test case generic/050 still fails on btrfs with shutdown support:

generic/050 1s ... - output mismatch (see /home/adam/xfstests/results//generic/050.out.bad)
--- tests/generic/050.out 2022-05-11 11:25:30.763333331 +0930
+++ /home/adam/xfstests/results//generic/050.out.bad 2025-06-30 10:22:21.752068622 +0930
@@ -13,9 +13,7 @@
setting device read-only
mounting filesystem that needs recovery on a read-only device:
mount: device write-protected, mounting read-only
-mount: cannot mount device read-only
unmounting read-only filesystem
-umount: SCRATCH_DEV: not mounted
mounting filesystem with -o norecovery on a read-only device:
...
(Run 'diff -u /home/adam/xfstests/tests/generic/050.out /home/adam/xfstests/results//generic/050.out.bad' to see the entire diff)
Ran: generic/050

[CAUSE]
The test case generic/050 has several different golden output depending on the fs features.

For fses which requires data write (e.g. replay the journal) during mount, mounting a read-only block device should fail. And that is the default golden output.

However there are cases that the fs doesn't need to write anything, e.g. the fs has no metadata journal support at all, or the fs has no dirty journal to replay.

In that case, there is the generic/050.nojournal golden output.

The test case is using the helper _has_metadata_journaling() to determine the feature.

Unfortunately that helper doesn't support btrfs, thus the default behavior is to assume the fs has journal to replay, thus for btrfs it always assume there is a journal to replay and results the wrong golden output to be used.

[FIX]
Add btrfs specific log tree check into _has_metadata_journaling(), so that if there is no log tree to replay, expose the "nojournal" feature correctly to pass generic/050.

---
  common/rc | 8 ++++++++
  1 file changed, 8 insertions(+)
common/rc +8 -0
index 2d8e7167..a78b779a 100644
@@ -4283,6 +4283,14 @@ _has_metadata_journaling()
  			return 1
  		fi
  		;;
+	btrfs)
+		_require_btrfs_command inspect-internal dump-super
+		if "$BTRFS_UTIL_PROG" inspect-internal dump-super $dev | \
+		   grep -q "log_root\s\+0" ; then
+			echo "$FSTYPE on $dev has empty log tree"
+			return 1
+		fi
+		;;
  	*)
  		# by default we pass; if you need to, add your fs above!
  		;;
#2 lore raw
In reply to Qu Wenruo
Quoted 58 lines · Qu Wenruo

[BUG]
With the incoming btrfs shutdown ioctl/remove_bdev callback support, btrfs can be tested with the shutdown group.

But test case generic/050 still fails on btrfs with shutdown support:

generic/050 1s ... - output mismatch (see /home/adam/xfstests/results//generic/050.out.bad)
--- tests/generic/050.out 2022-05-11 11:25:30.763333331 +0930
+++ /home/adam/xfstests/results//generic/050.out.bad 2025-06-30 10:22:21.752068622 +0930
@@ -13,9 +13,7 @@
setting device read-only
mounting filesystem that needs recovery on a read-only device:
mount: device write-protected, mounting read-only
-mount: cannot mount device read-only
unmounting read-only filesystem
-umount: SCRATCH_DEV: not mounted
mounting filesystem with -o norecovery on a read-only device:
...
(Run 'diff -u /home/adam/xfstests/tests/generic/050.out /home/adam/xfstests/results//generic/050.out.bad' to see the entire diff)
Ran: generic/050

[CAUSE]
The test case generic/050 has several different golden output depending on the fs features.

For fses which requires data write (e.g. replay the journal) during mount, mounting a read-only block device should fail. And that is the default golden output.

However there are cases that the fs doesn't need to write anything, e.g. the fs has no metadata journal support at all, or the fs has no dirty journal to replay.

In that case, there is the generic/050.nojournal golden output.

The test case is using the helper _has_metadata_journaling() to determine the feature.

Unfortunately that helper doesn't support btrfs, thus the default behavior is to assume the fs has journal to replay, thus for btrfs it always assume there is a journal to replay and results the wrong golden output to be used.

[FIX]
Add btrfs specific log tree check into _has_metadata_journaling(), so that if there is no log tree to replay, expose the "nojournal" feature correctly to pass generic/050.

---
 common/rc | 8 ++++++++
 1 file changed, 8 insertions(+)
common/rc +0 -0
index 2d8e7167..a78b779a 100644

common/rc _has_metadata_journaling() · line 4290

Quoted 8 lines
common/rc +5 -0
@@ -4283,6 +4283,14 @@ _has_metadata_journaling()
 			return 1
 		fi
 		;;
+	btrfs)
+		_require_btrfs_command inspect-internal dump-super
+		if "$BTRFS_UTIL_PROG" inspect-internal dump-super $dev | \
+		   grep -q "log_root\s\+0" ; then
+			echo "$FSTYPE on $dev has empty log tree"
                               ^^^^^^
                               FSTYP
Quoted 10 lines
common/rc +3 -0
+			return 1
+		fi
+		;;
 	*)
 		# by default we pass; if you need to, add your fs above!
 		;;
Signature · 1 line
2.50.0
#3 lore raw
Quoted 54 lines · Zorro Lang
Quoted 53 lines · Qu Wenruo

[BUG]
With the incoming btrfs shutdown ioctl/remove_bdev callback support, btrfs can be tested with the shutdown group.

But test case generic/050 still fails on btrfs with shutdown support:

generic/050 1s ... - output mismatch (see /home/adam/xfstests/results//generic/050.out.bad)
--- tests/generic/050.out 2022-05-11 11:25:30.763333331 +0930
+++ /home/adam/xfstests/results//generic/050.out.bad 2025-06-30 10:22:21.752068622 +0930
@@ -13,9 +13,7 @@
setting device read-only
mounting filesystem that needs recovery on a read-only device:
mount: device write-protected, mounting read-only
-mount: cannot mount device read-only
unmounting read-only filesystem
-umount: SCRATCH_DEV: not mounted
mounting filesystem with -o norecovery on a read-only device:
...
(Run 'diff -u /home/adam/xfstests/tests/generic/050.out /home/adam/xfstests/results//generic/050.out.bad' to see the entire diff)
Ran: generic/050

[CAUSE]
The test case generic/050 has several different golden output depending on the fs features.

For fses which requires data write (e.g. replay the journal) during mount, mounting a read-only block device should fail. And that is the default golden output.

However there are cases that the fs doesn't need to write anything, e.g. the fs has no metadata journal support at all, or the fs has no dirty journal to replay.

In that case, there is the generic/050.nojournal golden output.

The test case is using the helper _has_metadata_journaling() to determine the feature.

Unfortunately that helper doesn't support btrfs, thus the default behavior is to assume the fs has journal to replay, thus for btrfs it always assume there is a journal to replay and results the wrong golden output to be used.

[FIX]
Add btrfs specific log tree check into _has_metadata_journaling(), so that if there is no log tree to replay, expose the "nojournal" feature correctly to pass generic/050.

---
  common/rc | 8 ++++++++
  1 file changed, 8 insertions(+)
Quoted 15 lines

common/rc _has_metadata_journaling() · line 4290

Quoted 13 lines
common/rc +5 -0
index 2d8e7167..a78b779a 100644
@@ -4283,6 +4283,14 @@ _has_metadata_journaling()
  			return 1
  		fi
  		;;
+	btrfs)
+		_require_btrfs_command inspect-internal dump-super
+		if "$BTRFS_UTIL_PROG" inspect-internal dump-super $dev | \
+		   grep -q "log_root\s\+0" ; then
+			echo "$FSTYPE on $dev has empty log tree"
                                ^^^^^^
                                FSTYP

Despite the typo, this change is causing other test cases to be skipped.

As _require_metadata_journaling() relies on _has_metadata_journaling() to check if the fs has metadata journal support.

I'll need to find a way to tell the test case that even a fs support metadata journaling, the fs can still be mounted RO when there is no dirty journal.

This will be more complex than just modifying _has_metadata_journaling().

Thanks,
Qu

Quoted 16 lines
Quoted 14 lines
common/rc +3 -0
+			return 1
+		fi
+		;;
  	*)
  		# by default we pass; if you need to, add your fs above!
  		;;
Signature · 1 line
2.50.0