All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: utils: fix btrfs_wipe_existing_sb probe bug
@ 2021-03-25 13:10 Fox Chen
  2021-04-09  4:32 ` Wang Yugui
  0 siblings, 1 reply; 3+ messages in thread
From: Fox Chen @ 2021-03-25 13:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Fox Chen, gregkh

btrfs_wipe_existing_sb() misses calling blkid_do_fullprobe() to do
the real probe. After calling blkid_new_probe() &
blkid_probe_set_device() to setup blkid_probe context, it directly
calls blkid_probe_lookup_value(). This results in
blkid_probe_lookup_value returning -1, because pr->values is empty.

Signed-off-by: Fox Chen <foxhlchen@gmail.com>
---
 common/device-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/device-utils.c b/common/device-utils.c
index c860b946..f8e2e776 100644
--- a/common/device-utils.c
+++ b/common/device-utils.c
@@ -114,7 +114,7 @@ static int btrfs_wipe_existing_sb(int fd)
 	if (!pr)
 		return -1;
 
-	if (blkid_probe_set_device(pr, fd, 0, 0)) {
+	if (blkid_probe_set_device(pr, fd, 0, 0) || blkid_do_fullprobe(pr)) {
 		ret = -1;
 		goto out;
 	}
-- 
2.31.0


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

* Re: [PATCH] btrfs-progs: utils: fix btrfs_wipe_existing_sb probe bug
  2021-03-25 13:10 [PATCH] btrfs-progs: utils: fix btrfs_wipe_existing_sb probe bug Fox Chen
@ 2021-04-09  4:32 ` Wang Yugui
  2021-04-15  6:19   ` Fox Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Wang Yugui @ 2021-04-09  4:32 UTC (permalink / raw)
  To: Fox Chen; +Cc: linux-btrfs, gregkh

Hi,

> btrfs_wipe_existing_sb() misses calling blkid_do_fullprobe() to do
> the real probe. After calling blkid_new_probe() &
> blkid_probe_set_device() to setup blkid_probe context, it directly
> calls blkid_probe_lookup_value(). This results in
> blkid_probe_lookup_value returning -1, because pr->values is empty.
> 
> Signed-off-by: Fox Chen <foxhlchen@gmail.com>
> ---
>  common/device-utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/device-utils.c b/common/device-utils.c
> index c860b946..f8e2e776 100644
> --- a/common/device-utils.c
> +++ b/common/device-utils.c
> @@ -114,7 +114,7 @@ static int btrfs_wipe_existing_sb(int fd)
>  	if (!pr)
>  		return -1;
>  
> -	if (blkid_probe_set_device(pr, fd, 0, 0)) {
> +	if (blkid_probe_set_device(pr, fd, 0, 0) || blkid_do_fullprobe(pr)) {
>  		ret = -1;
>  		goto out;
>  	}
> -- 
> 2.31.0


With this patch,  'mkfs.btrfs -f /dev/nvme0n1 /dev/sdb' output some
error when /dev/nvme0n1 have 2 partitions.
	ERROR: cannot wipe superblocks on /dev/nvme0n1

# blkid
/dev/nvme0n1: PTUUID="93a54ce8-04b2-470b-8c05-31bfcef02f28" PTTYPE="gpt"
/dev/sda1: LABEL="OS_USB" UUID="2b7f4cb9-3dac-443f-8c96-a907b9276942" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="ee58e9d3-01"
/dev/nvme0n1p1: UUID="1d94dc2b-abd1-47df-bf39-ab31cf579d29" UUID_SUB="577542b7-91f5-48d4-a54c-98cbd4525c00" BLOCK_SIZE="4096" TYPE="btrfs" PARTLABEL="primary" PARTUUID="efed009f-8ae6-4567-9cd3-80a57cdcf225"
/dev/nvme0n1p2: PARTLABEL="primary" PARTUUID="fcab66cd-daad-457f-a53c-110592d8941f"
...


Without this patch,  'mkfs.btrfs -f /dev/nvme0n1 /dev/sdb' have some
issue too when /dev/nvme0n1 and /dev/sdb  have some partitions.

some blkid of partition is still left in the output of blkid. 
'blockdev --rereadpt' will let them disappear.

Best Regards
Wang Yugui (wangyugui@e16-tech.com)
2021/04/09



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

* Re: [PATCH] btrfs-progs: utils: fix btrfs_wipe_existing_sb probe bug
  2021-04-09  4:32 ` Wang Yugui
@ 2021-04-15  6:19   ` Fox Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Fox Chen @ 2021-04-15  6:19 UTC (permalink / raw)
  To: wangyugui, dsterba; +Cc: linux-btrfs, Greg KH

On Fri, Apr 9, 2021 at 12:32 PM Wang Yugui <wangyugui@e16-tech.com> wrote:
>
> Hi,
>
> > btrfs_wipe_existing_sb() misses calling blkid_do_fullprobe() to do
> > the real probe. After calling blkid_new_probe() &
> > blkid_probe_set_device() to setup blkid_probe context, it directly
> > calls blkid_probe_lookup_value(). This results in
> > blkid_probe_lookup_value returning -1, because pr->values is empty.
> >
> > Signed-off-by: Fox Chen <foxhlchen@gmail.com>
> > ---
> >  common/device-utils.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/common/device-utils.c b/common/device-utils.c
> > index c860b946..f8e2e776 100644
> > --- a/common/device-utils.c
> > +++ b/common/device-utils.c
> > @@ -114,7 +114,7 @@ static int btrfs_wipe_existing_sb(int fd)
> >       if (!pr)
> >               return -1;
> >
> > -     if (blkid_probe_set_device(pr, fd, 0, 0)) {
> > +     if (blkid_probe_set_device(pr, fd, 0, 0) || blkid_do_fullprobe(pr)) {
> >               ret = -1;
> >               goto out;
> >       }
> > --
> > 2.31.0
>
>
> With this patch,  'mkfs.btrfs -f /dev/nvme0n1 /dev/sdb' output some
> error when /dev/nvme0n1 have 2 partitions.
>         ERROR: cannot wipe superblocks on /dev/nvme0n1

I am not sure this error is caused by my improper fix, or bugs lie
somewhere else on mkfs.btrfs path.

But without this patch, I think, btrfs_wipe_existing_sb will not do
what is supposed to do -- wiping out existing superblocks.
Instead, it does nothing and always returns 1. Since it has no effect
and nobody complaints about it, that brings a question, do we really
need to call it in btrfs_prepare_device?

> # blkid
> /dev/nvme0n1: PTUUID="93a54ce8-04b2-470b-8c05-31bfcef02f28" PTTYPE="gpt"
> /dev/sda1: LABEL="OS_USB" UUID="2b7f4cb9-3dac-443f-8c96-a907b9276942" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="ee58e9d3-01"
> /dev/nvme0n1p1: UUID="1d94dc2b-abd1-47df-bf39-ab31cf579d29" UUID_SUB="577542b7-91f5-48d4-a54c-98cbd4525c00" BLOCK_SIZE="4096" TYPE="btrfs" PARTLABEL="primary" PARTUUID="efed009f-8ae6-4567-9cd3-80a57cdcf225"
> /dev/nvme0n1p2: PARTLABEL="primary" PARTUUID="fcab66cd-daad-457f-a53c-110592d8941f"
> ...
>
>
> Without this patch,  'mkfs.btrfs -f /dev/nvme0n1 /dev/sdb' have some
> issue too when /dev/nvme0n1 and /dev/sdb  have some partitions.
>
> some blkid of partition is still left in the output of blkid.
> 'blockdev --rereadpt' will let them disappear.
>
> Best Regards
> Wang Yugui (wangyugui@e16-tech.com)
> 2021/04/09
>
>

thanks,
fox

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 13:10 [PATCH] btrfs-progs: utils: fix btrfs_wipe_existing_sb probe bug Fox Chen
2021-04-09  4:32 ` Wang Yugui
2021-04-15  6:19   ` Fox Chen

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.