All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to reject fs with dirty log
@ 2022-04-19 11:36 Qu Wenruo
  2022-04-19 11:36 ` [PATCH v2 1/2] btrfs-progs: do not allow setting seed flag on " Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2022-04-19 11:36 UTC (permalink / raw)
  To: linux-btrfs

[CHANGELOG]
v2:
- Add a test case for it


A seed device with dirty log can be rejected by kernel, as kernel will
try to replay log even on RO mount.
But log replay on RO device is strongly prohibited, thus such seed
device will be rejected without a way to sprout.

Fix the problem by letting "btrfstune -S1" to check if the fs has dirty
log first.

Also add a test case for it, using a btrfs-image dump.

Qu Wenruo (2):
  btrfs-progs: do not allow setting seed flag on fs with dirty log
  btrfs-progs: make sure "btrfstune -S1" will reject fs with dirty log

 btrfstune.c                                      |   4 ++++
 .../052-seed-dirty-log/dirty_log.img.xz          | Bin 0 -> 2140 bytes
 tests/misc-tests/052-seed-dirty-log/test.sh      |  12 ++++++++++++
 3 files changed, 16 insertions(+)
 create mode 100644 tests/misc-tests/052-seed-dirty-log/dirty_log.img.xz
 create mode 100755 tests/misc-tests/052-seed-dirty-log/test.sh

-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-19 11:36 [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to reject fs with dirty log Qu Wenruo
@ 2022-04-19 11:36 ` Qu Wenruo
  2022-04-19 11:36 ` [PATCH v2 2/2] btrfs-progs: make sure "btrfstune -S1" will reject " Qu Wenruo
  2022-04-25 12:11 ` [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to " David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2022-04-19 11:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Josef Bacik, Nikolay Borisov

[BUG]
The following sequence operation can lead to a seed fs rejected by
kernel:

 # Generate a fs with dirty log
 mkfs.btrfs -f $file
 mount $dev $mnt
 xfs_io -f -c "pwrite 0 16k" -c fsync $mnt/file
 cp $file $file.backup
 umount $mnt
 mv $file.backup $file

 # now $file has dirty log, set seed flag on it
 btrfstune -S1 $file

 # mount will fail
 mount $file $mnt

The mount failure with the following dmesg:

[  980.363667] loop0: detected capacity change from 0 to 262144
[  980.371177] BTRFS info (device loop0): flagging fs with big metadata feature
[  980.372229] BTRFS info (device loop0): using free space tree
[  980.372639] BTRFS info (device loop0): has skinny extents
[  980.375075] BTRFS info (device loop0): start tree-log replay
[  980.375513] BTRFS warning (device loop0): log replay required on RO media
[  980.381652] BTRFS error (device loop0): open_ctree failed

[CAUSE]
Although btrfs will replay its dirty log even with RO mount, but kernel
will treat seed device as RO device, and dirty log can not be replayed
on RO device.

This rejection is already the better end, just imagine if we don't treat
seed device as RO, and replayed the dirty log.
The filesystem relying on the seed device will be completely screwed up.

[FIX]
Just add extra check on log tree in btrfstune to reject setting seed
flag on filesystems with dirty log.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
---
 btrfstune.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/btrfstune.c b/btrfstune.c
index c9a92349a44c..3824a3d9d8ff 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -59,6 +59,10 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag)
 						device);
 			return 1;
 		}
+		if (btrfs_super_log_root(disk_super)) {
+			error("filesystem with dirty log detected, not setting seed flag");
+			return 1;
+		}
 		super_flags |= BTRFS_SUPER_FLAG_SEEDING;
 	} else {
 		if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] btrfs-progs: make sure "btrfstune -S1" will reject fs with dirty log
  2022-04-19 11:36 [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to reject fs with dirty log Qu Wenruo
  2022-04-19 11:36 ` [PATCH v2 1/2] btrfs-progs: do not allow setting seed flag on " Qu Wenruo
@ 2022-04-19 11:36 ` Qu Wenruo
  2022-04-25 12:11 ` [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to " David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2022-04-19 11:36 UTC (permalink / raw)
  To: linux-btrfs

The new test case will have a image file which has dirty log
(btrfs-image supports dumping log tree).

So we can easily check if "btrfstune -S" will reject fs with dirty log.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 .../052-seed-dirty-log/dirty_log.img.xz          | Bin 0 -> 2140 bytes
 tests/misc-tests/052-seed-dirty-log/test.sh      |  12 ++++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 tests/misc-tests/052-seed-dirty-log/dirty_log.img.xz
 create mode 100755 tests/misc-tests/052-seed-dirty-log/test.sh

diff --git a/tests/misc-tests/052-seed-dirty-log/dirty_log.img.xz b/tests/misc-tests/052-seed-dirty-log/dirty_log.img.xz
new file mode 100644
index 0000000000000000000000000000000000000000..a14b0cb02b8a5e36b4dad49e0cddf5c5dbeebed5
GIT binary patch
literal 2140
zcmV-i2&4D?H+ooF000E$*0e?f03iV!0000G&sfah5B~@oT>wRyj;C3^v%$$4d1wdA
zhA1@4m*CM~3sI}uQQl`0EV)~_#9*kTIt)IL%M4Jy6#*RyWa`sE#Xvfe{bR5#c#WG#
z$>iYF8!>p_v&m6pxv^!%@m6e-LB!o`#e>7^^`#5?vSdfbwsNGId`>Ac77r-QW53AJ
zT*gSCn(AE*>N?sS{UEf%Nr%X#7)}gF@p4!#6jqqZd73k%+c^G3dTk<3lD5`y)p^Fb
z3~{qMQNxa9iEbh_3!u=7`jn<=P(e-%dhnX8C_++$>Gx%-(R1A5BD^aqtkh91LkRRZ
zc6PL$^4OKRO#vN?#LU9xO4n0N4%M|K*{STu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
zJU?+>Gww!l2Jh2-xx17mpzhmrSt7ee->;s2ux_mNvt%J*DXQ7hr)VFIFauG&2B{JM
zppu3R6_7+sqeF$&r5sZQ5mM!u?i}BAF~5YO?6!JStFCpg<;kWtM^oDYUb?K)8n*as
z!aOfL_!2|HRTChd-Y#wdZTs<HOJExbb~l95d1h^C(O%1t9ck7Z4dR%H%DUBU;Xyft
zsPXy#wLg|vXja);)PkGSf}<c=Bp)?qxQM-wS>D0#1fIH482i;z*=2E<C};Ba86BL=
zGcyh4c~^vx3TH3?v}Ti5a{%<L3TX(4iXphFEO_FK0001qismDSQRDjn0k;r<AOHYK
SkZy6Y#Ao{g000001X)@nj3T`N

literal 0
HcmV?d00001

diff --git a/tests/misc-tests/052-seed-dirty-log/test.sh b/tests/misc-tests/052-seed-dirty-log/test.sh
new file mode 100755
index 000000000000..2f16f43a29a2
--- /dev/null
+++ b/tests/misc-tests/052-seed-dirty-log/test.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+#
+# Make sure btrfstune will not set seed flag when the fs has dirty log
+
+source "$TEST_TOP/common"
+
+check_prereq btrfstune
+
+image=$(extract_image "./dirty_log.img.xz")
+
+run_mustfail "btrfstune should reject fs with dirty log for seeding flag" \
+	"$TOP/btrfstune" -S1 "$image"
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to reject fs with dirty log
  2022-04-19 11:36 [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to reject fs with dirty log Qu Wenruo
  2022-04-19 11:36 ` [PATCH v2 1/2] btrfs-progs: do not allow setting seed flag on " Qu Wenruo
  2022-04-19 11:36 ` [PATCH v2 2/2] btrfs-progs: make sure "btrfstune -S1" will reject " Qu Wenruo
@ 2022-04-25 12:11 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2022-04-25 12:11 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Tue, Apr 19, 2022 at 07:36:20PM +0800, Qu Wenruo wrote:
> [CHANGELOG]
> v2:
> - Add a test case for it
> 
> 
> A seed device with dirty log can be rejected by kernel, as kernel will
> try to replay log even on RO mount.
> But log replay on RO device is strongly prohibited, thus such seed
> device will be rejected without a way to sprout.
> 
> Fix the problem by letting "btrfstune -S1" to check if the fs has dirty
> log first.
> 
> Also add a test case for it, using a btrfs-image dump.
> 
> Qu Wenruo (2):
>   btrfs-progs: do not allow setting seed flag on fs with dirty log
>   btrfs-progs: make sure "btrfstune -S1" will reject fs with dirty log

Added to devel, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-25 12:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 11:36 [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to reject fs with dirty log Qu Wenruo
2022-04-19 11:36 ` [PATCH v2 1/2] btrfs-progs: do not allow setting seed flag on " Qu Wenruo
2022-04-19 11:36 ` [PATCH v2 2/2] btrfs-progs: make sure "btrfstune -S1" will reject " Qu Wenruo
2022-04-25 12:11 ` [PATCH v2 0/2] btrfs-progs: make "btrfstune -S1" to " David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.