All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
@ 2022-04-15 11:37 Qu Wenruo
  2022-04-18  6:41 ` Nikolay Borisov
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Qu Wenruo @ 2022-04-15 11:37 UTC (permalink / raw)
  To: linux-btrfs

[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>
---
 btrfstune.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/btrfstune.c b/btrfstune.c
index 33c83bf16291..7e4ad30a1cbd 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("this filesystem has dirty log, can not set 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] 8+ messages in thread

* Re: [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-15 11:37 [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log Qu Wenruo
@ 2022-04-18  6:41 ` Nikolay Borisov
  2022-04-18  6:44   ` Qu Wenruo
  2022-04-18 15:30 ` Josef Bacik
  2022-04-19 12:07 ` Anand Jain
  2 siblings, 1 reply; 8+ messages in thread
From: Nikolay Borisov @ 2022-04-18  6:41 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs



On 15.04.22 г. 14:37 ч., Qu Wenruo wrote:
> [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>

LGTM:

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

One minor nit below but it can be rectified by David at merge time. Why 
don't you also add a btrfs-progs test for this functionality.

> ---
>   btrfstune.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/btrfstune.c b/btrfstune.c
> index 33c83bf16291..7e4ad30a1cbd 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("this filesystem has dirty log, can not set seed flag");


nit: I'd probably put something less colloquial such as:

"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)) {

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

* Re: [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-18  6:41 ` Nikolay Borisov
@ 2022-04-18  6:44   ` Qu Wenruo
  2022-04-18 11:58     ` Nikolay Borisov
  0 siblings, 1 reply; 8+ messages in thread
From: Qu Wenruo @ 2022-04-18  6:44 UTC (permalink / raw)
  To: Nikolay Borisov, Qu Wenruo, linux-btrfs



On 2022/4/18 14:41, Nikolay Borisov wrote:
>
>
> On 15.04.22 г. 14:37 ч., Qu Wenruo wrote:
>> [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>
>
> LGTM:
>
> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
>
> One minor nit below but it can be rectified by David at merge time. Why
> don't you also add a btrfs-progs test for this functionality.

The major concern is, I'm using a very ugly way to create a dirty journal.

But I'm not sure if btrfs-progs really wants a complicated dm based
solution to do the same thing.

Or maybe I can just use an raw image for that?

Thanks,
Qu

>
>> ---
>>   btrfstune.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/btrfstune.c b/btrfstune.c
>> index 33c83bf16291..7e4ad30a1cbd 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("this filesystem has dirty log, can not set seed
>> flag");
>
>
> nit: I'd probably put something less colloquial such as:
>
> "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)) {

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

* Re: [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-18  6:44   ` Qu Wenruo
@ 2022-04-18 11:58     ` Nikolay Borisov
  0 siblings, 0 replies; 8+ messages in thread
From: Nikolay Borisov @ 2022-04-18 11:58 UTC (permalink / raw)
  To: Qu Wenruo, Nikolay Borisov, Qu Wenruo, linux-btrfs



On 18.04.22 г. 9:44 ч., Qu Wenruo wrote:
> y way to create a dirty journal.
> 
> But I'm not sure if btrfs-progs really wants a complicated dm based
> solution to do the same thing.
> 
> Or maybe I can just use an raw image for that?


It doesn't matter what way you use to create the journal, what's 
important is that you have a dirty journal and verify a particular 
functionality involving it. You can either encode the steps to create 
the dirty journal image in the test itself, or simply provide an image 
with a dirty journal.

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

* Re: [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-15 11:37 [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log Qu Wenruo
  2022-04-18  6:41 ` Nikolay Borisov
@ 2022-04-18 15:30 ` Josef Bacik
  2022-04-18 23:31   ` Qu Wenruo
  2022-04-19 12:07 ` Anand Jain
  2 siblings, 1 reply; 8+ messages in thread
From: Josef Bacik @ 2022-04-18 15:30 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Fri, Apr 15, 2022 at 07:37:43PM +0800, Qu Wenruo wrote:
> [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>

Can we get a progs test for this as well?

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef

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

* Re: [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-18 15:30 ` Josef Bacik
@ 2022-04-18 23:31   ` Qu Wenruo
  0 siblings, 0 replies; 8+ messages in thread
From: Qu Wenruo @ 2022-04-18 23:31 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs



On 2022/4/18 23:30, Josef Bacik wrote:
> On Fri, Apr 15, 2022 at 07:37:43PM +0800, Qu Wenruo wrote:
>> [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>
> 
> Can we get a progs test for this as well?

Thanks to the suggestion from Nik, I finally remember we can use raw 
image for fs with dirty journal.

Test case will come soon.

Thanks,
Qu
> 
> Reviewed-by: Josef Bacik <josef@toxicpanda.com>
> 
> Thanks,
> 
> Josef
> 


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

* Re: [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-15 11:37 [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log Qu Wenruo
  2022-04-18  6:41 ` Nikolay Borisov
  2022-04-18 15:30 ` Josef Bacik
@ 2022-04-19 12:07 ` Anand Jain
  2022-04-19 12:10   ` Qu Wenruo
  2 siblings, 1 reply; 8+ messages in thread
From: Anand Jain @ 2022-04-19 12:07 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs

On 4/15/22 19:37, Qu Wenruo wrote:
> [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>

LGTM.

Reviewed-by: Anand Jain <anand.jain@oracle.com>

a small nit below.

> ---
>   btrfstune.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/btrfstune.c b/btrfstune.c
> index 33c83bf16291..7e4ad30a1cbd 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("this filesystem has dirty log, can not set seed flag");

Also, add a note on how to overcome dirty log. Mount / unmount?

Thanks, Anand

> +			return 1;
> +		}
>   		super_flags |= BTRFS_SUPER_FLAG_SEEDING;
>   	} else {
>   		if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) {


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

* Re: [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log
  2022-04-19 12:07 ` Anand Jain
@ 2022-04-19 12:10   ` Qu Wenruo
  0 siblings, 0 replies; 8+ messages in thread
From: Qu Wenruo @ 2022-04-19 12:10 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs



On 2022/4/19 20:07, Anand Jain wrote:
> On 4/15/22 19:37, Qu Wenruo wrote:
>> [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>
>
> LGTM.
>
> Reviewed-by: Anand Jain <anand.jain@oracle.com>
>
> a small nit below.
>
>> ---
>>   btrfstune.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/btrfstune.c b/btrfstune.c
>> index 33c83bf16291..7e4ad30a1cbd 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("this filesystem has dirty log, can not set seed
>> flag");
>
> Also, add a note on how to overcome dirty log. Mount / unmount?

Mount/unmount or zero log.

I guess if a user has a dirty log (by itself is not that rare) and still
want to set seed flag on it (if the user doesn't understand what she/he
is doing, then it's a big problem), it's worthy to ask in the mailing
list already.

Thanks,
Qu
>
> Thanks, Anand
>
>> +            return 1;
>> +        }
>>           super_flags |= BTRFS_SUPER_FLAG_SEEDING;
>>       } else {
>>           if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) {
>

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-15 11:37 [PATCH] btrfs-progs: do not allow setting seed flag on fs with dirty log Qu Wenruo
2022-04-18  6:41 ` Nikolay Borisov
2022-04-18  6:44   ` Qu Wenruo
2022-04-18 11:58     ` Nikolay Borisov
2022-04-18 15:30 ` Josef Bacik
2022-04-18 23:31   ` Qu Wenruo
2022-04-19 12:07 ` Anand Jain
2022-04-19 12:10   ` Qu Wenruo

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.