All of lore.kernel.org
 help / color / mirror / Atom feed
* btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
@ 2024-07-10 11:52 Russell Coker
  2024-07-10 16:29 ` Boris Burkov
  2024-07-10 21:13 ` Qu Wenruo
  0 siblings, 2 replies; 8+ messages in thread
From: Russell Coker @ 2024-07-10 11:52 UTC (permalink / raw)
  To: linux-btrfs

Below is the difference between running btrfs dev usa as root and non-root on 
a laptop with kernel 6.8.12-amd64.  When run as non-root it gets everything 
wrong and in my tests I have never been able to see it give nay accurate data 
as non-root.  I think it should just abort with an error in that situation, 
there's no point in giving a wrong answer.

# btrfs dev usa /
/dev/mapper/root, ID: 1
   Device size:           476.37GiB
   Device slack:            1.50KiB
   Data,single:           216.01GiB
   Metadata,DUP:            6.00GiB
   System,DUP:             64.00MiB
   Unallocated:           254.29GiB

$ btrfs dev usa /
WARNING: cannot read detailed chunk info, per-device usage will not be shown, 
run as root
/dev/mapper/root, ID: 1
   Device size:           952.73MiB
   Device slack:           16.00EiB
   Unallocated:           476.37GiB

-- 
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/




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

* Re: btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
  2024-07-10 11:52 btrfs-progs: btrfs dev usa as non-root is wrong and should just abort Russell Coker
@ 2024-07-10 16:29 ` Boris Burkov
  2024-07-11  3:50   ` Russell Coker
  2024-07-10 21:13 ` Qu Wenruo
  1 sibling, 1 reply; 8+ messages in thread
From: Boris Burkov @ 2024-07-10 16:29 UTC (permalink / raw)
  To: Russell Coker; +Cc: linux-btrfs

On Wed, Jul 10, 2024 at 09:52:14PM +1000, Russell Coker wrote:
> Below is the difference between running btrfs dev usa as root and non-root on 
> a laptop with kernel 6.8.12-amd64.  When run as non-root it gets everything 
> wrong and in my tests I have never been able to see it give nay accurate data 
> as non-root.  I think it should just abort with an error in that situation, 
> there's no point in giving a wrong answer.
> 
> # btrfs dev usa /
> /dev/mapper/root, ID: 1
>    Device size:           476.37GiB
>    Device slack:            1.50KiB
>    Data,single:           216.01GiB
>    Metadata,DUP:            6.00GiB
>    System,DUP:             64.00MiB
>    Unallocated:           254.29GiB
> 
> $ btrfs dev usa /
> WARNING: cannot read detailed chunk info, per-device usage will not be shown, 
> run as root
> /dev/mapper/root, ID: 1
>    Device size:           952.73MiB
Hmm..
>    Device slack:           16.00EiB
>    Unallocated:           476.37GiB
Also wrong, but at least it's the "size" number?!

btrfs device usage (and btrfs filesystem usage) usually give
pretty reasonable results without root on my systems, so this is sort of
surprising to me, especially since it looks like we both have the same
trivial raid/volume setup and you are on a relatively new kernel.
e.g., on my system running 6.9:

$ sudo btrfs dev usage /home
/dev/mapper/vol-home, ID: 1
   Device size:           826.50GiB
   Device slack:              0.00B
   Data,single:           117.01GiB
   Metadata,DUP:            2.00GiB
   System,DUP:             16.00MiB
   Unallocated:           707.47GiB

$ btrfs dev usage /home
WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
/dev/mapper/vol-home, ID: 1
   Device size:           826.50GiB
   Device slack:              0.00B
   Unallocated:                 N/A

I suppose my non-root output is lacking usage information, it at least
gets the size right.

Does the same discrepancy happen for you when running
'btrfs filesystem usage /' with and without root? That command gives me
lots of useful, interesting output without root. e.g.,

$ btrfs fi usage /home
WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
Overall:
    Device size:                 826.50GiB
    Device allocated:            119.02GiB
    Device unallocated:          707.47GiB
    Device missing:                  0.00B
    Device slack:                    0.00B
    Used:                        109.38GiB
    Free (estimated):            716.59GiB      (min: 362.85GiB)
    Free (statfs, df):           716.59GiB
    Data ratio:                       1.00
    Metadata ratio:                   2.00
    Global reserve:              168.02MiB      (used: 0.00B)
    Multiple profiles:                  no

Data,single: Size:117.01GiB, Used:107.89GiB (92.21%)

Metadata,DUP: Size:1.00GiB, Used:764.42MiB (74.65%)

System,DUP: Size:8.00MiB, Used:16.00KiB (0.20%)

Thanks,
Boris

> 
> -- 
> My Main Blog         http://etbe.coker.com.au/
> My Documents Blog    http://doc.coker.com.au/
> 
> 
> 

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

* Re: btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
  2024-07-10 11:52 btrfs-progs: btrfs dev usa as non-root is wrong and should just abort Russell Coker
  2024-07-10 16:29 ` Boris Burkov
@ 2024-07-10 21:13 ` Qu Wenruo
  2024-07-11  3:42   ` Russell Coker
  1 sibling, 1 reply; 8+ messages in thread
From: Qu Wenruo @ 2024-07-10 21:13 UTC (permalink / raw)
  To: Russell Coker, linux-btrfs



在 2024/7/10 21:22, Russell Coker 写道:
> Below is the difference between running btrfs dev usa as root and non-root on
> a laptop with kernel 6.8.12-amd64.  When run as non-root it gets everything
> wrong and in my tests I have never been able to see it give nay accurate data
> as non-root.  I think it should just abort with an error in that situation,
> there's no point in giving a wrong answer.
>
> # btrfs dev usa /
> /dev/mapper/root, ID: 1
>     Device size:           476.37GiB
>     Device slack:            1.50KiB
>     Data,single:           216.01GiB
>     Metadata,DUP:            6.00GiB
>     System,DUP:             64.00MiB
>     Unallocated:           254.29GiB
>
> $ btrfs dev usa /
> WARNING: cannot read detailed chunk info, per-device usage will not be shown,
> run as root
> /dev/mapper/root, ID: 1
>     Device size:           952.73MiB
>     Device slack:           16.00EiB
>     Unallocated:           476.37GiB
>

Mind to post the raw result?

The 16EiB output definitely means something wrong.

So far the result looks like btrfs-progs is interpret the result wrong
with some offset of the result.

In my case, non-root call of "btrfs dev usage" always shows the slack as
0, and unallocated as N/A, so the 16EiB looks like some shift.

And what's the version of the btrfs-progs?

Thanks,
Qu


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

* Re: btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
  2024-07-10 21:13 ` Qu Wenruo
@ 2024-07-11  3:42   ` Russell Coker
  2024-07-11  3:47     ` Qu Wenruo
  0 siblings, 1 reply; 8+ messages in thread
From: Russell Coker @ 2024-07-11  3:42 UTC (permalink / raw)
  To: linux-btrfs, Qu Wenruo

On Thursday, 11 July 2024 07:13:25 AEST Qu Wenruo wrote:
> 在 2024/7/10 21:22, Russell Coker 写道:
> > Below is the difference between running btrfs dev usa as root and non-root
> > on a laptop with kernel 6.8.12-amd64.  When run as non-root it gets
> > everything wrong and in my tests I have never been able to see it give
> > nay accurate data as non-root.  I think it should just abort with an
> > error in that situation, there's no point in giving a wrong answer.
> > 
> > # btrfs dev usa /
> > /dev/mapper/root, ID: 1
> > 
> >     Device size:           476.37GiB
> >     Device slack:            1.50KiB
> >     Data,single:           216.01GiB
> >     Metadata,DUP:            6.00GiB
> >     System,DUP:             64.00MiB
> >     Unallocated:           254.29GiB
> > 
> > $ btrfs dev usa /
> > WARNING: cannot read detailed chunk info, per-device usage will not be
> > shown, run as root
> > /dev/mapper/root, ID: 1
> > 
> >     Device size:           952.73MiB
> >     Device slack:           16.00EiB
> >     Unallocated:           476.37GiB
> 
> Mind to post the raw result?
> 
> The 16EiB output definitely means something wrong.
> 
> So far the result looks like btrfs-progs is interpret the result wrong
> with some offset of the result.
> 
> In my case, non-root call of "btrfs dev usage" always shows the slack as
> 0, and unallocated as N/A, so the 16EiB looks like some shift.

# btrfs dev usa -b /
/dev/mapper/root, ID: 1
   Device size:          511493395968
   Device slack:               1536
   Data,single:          231936622592
   Metadata,DUP:         6442450944
   System,DUP:             67108864
   Unallocated:          273047212032

$ btrfs dev usa -b /
WARNING: cannot read detailed chunk info, per-device usage will not be shown, 
run as root
/dev/mapper/root, ID: 1
   Device size:           999010539
   Device slack:         18446743563215167723
   Unallocated:          511493394432

> And what's the version of the btrfs-progs?

The Debian package version is 6.6.3-1.2+b1.

-- 
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/




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

* Re: btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
  2024-07-11  3:42   ` Russell Coker
@ 2024-07-11  3:47     ` Qu Wenruo
  2024-07-11  3:55       ` Russell Coker
  0 siblings, 1 reply; 8+ messages in thread
From: Qu Wenruo @ 2024-07-11  3:47 UTC (permalink / raw)
  To: Russell Coker, linux-btrfs



在 2024/7/11 13:12, Russell Coker 写道:
> On Thursday, 11 July 2024 07:13:25 AEST Qu Wenruo wrote:
>> 在 2024/7/10 21:22, Russell Coker 写道:
>>> Below is the difference between running btrfs dev usa as root and non-root
>>> on a laptop with kernel 6.8.12-amd64.  When run as non-root it gets
>>> everything wrong and in my tests I have never been able to see it give
>>> nay accurate data as non-root.  I think it should just abort with an
>>> error in that situation, there's no point in giving a wrong answer.
>>>
>>> # btrfs dev usa /
>>> /dev/mapper/root, ID: 1
>>>
>>>      Device size:           476.37GiB
>>>      Device slack:            1.50KiB
>>>      Data,single:           216.01GiB
>>>      Metadata,DUP:            6.00GiB
>>>      System,DUP:             64.00MiB
>>>      Unallocated:           254.29GiB
>>>
>>> $ btrfs dev usa /
>>> WARNING: cannot read detailed chunk info, per-device usage will not be
>>> shown, run as root
>>> /dev/mapper/root, ID: 1
>>>
>>>      Device size:           952.73MiB
>>>      Device slack:           16.00EiB
>>>      Unallocated:           476.37GiB
>>
>> Mind to post the raw result?
>>
>> The 16EiB output definitely means something wrong.
>>
>> So far the result looks like btrfs-progs is interpret the result wrong
>> with some offset of the result.
>>
>> In my case, non-root call of "btrfs dev usage" always shows the slack as
>> 0, and unallocated as N/A, so the 16EiB looks like some shift.
>
> # btrfs dev usa -b /
> /dev/mapper/root, ID: 1
>     Device size:          511493395968

The device size is 4K aligned.

I guess it's some older fs? As newer mkfs would always round down to the
sector size.


>     Device slack:               1536
>     Data,single:          231936622592
>     Metadata,DUP:         6442450944
>     System,DUP:             67108864
>     Unallocated:          273047212032
>
> $ btrfs dev usa -b /
> WARNING: cannot read detailed chunk info, per-device usage will not be shown,
> run as root
> /dev/mapper/root, ID: 1
>     Device size:           999010539
>     Device slack:         18446743563215167723
>     Unallocated:          511493394432
>
>> And what's the version of the btrfs-progs?
>
> The Debian package version is 6.6.3-1.2+b1.
>

It may be easier to debug by trying a newer version of btrfs-progs.

And since I'm not sure if it's the unalignment causing problems, you may
want to resize the fs by:

# btrfs device resize -1M <mnt>

Then resize to max (which should always align the fs correctly):

# btrfs device resize max <mnt>

And then check if the size is aligned to 4K and if the problem has changed.

Thanks,
Qu

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

* Re: btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
  2024-07-10 16:29 ` Boris Burkov
@ 2024-07-11  3:50   ` Russell Coker
  0 siblings, 0 replies; 8+ messages in thread
From: Russell Coker @ 2024-07-11  3:50 UTC (permalink / raw)
  To: Boris Burkov; +Cc: linux-btrfs

On Thursday, 11 July 2024 02:29:38 AEST Boris Burkov wrote:
> Also wrong, but at least it's the "size" number?!
> 
> btrfs device usage (and btrfs filesystem usage) usually give
> pretty reasonable results without root on my systems, so this is sort of
> surprising to me, especially since it looks like we both have the same
> trivial raid/volume setup and you are on a relatively new kernel.
> e.g., on my system running 6.9:

I'm surprised that it worked for anyone, my experience was that it fails on 
all systems and I had assumed that was the general experience.

> Does the same discrepancy happen for you when running
> 'btrfs filesystem usage /' with and without root? That command gives me
> lots of useful, interesting output without root. e.g.,

For me btrfs fi usa gives me almost everything as non-root.  A bogus value for 
device slack is the only thing wrong.

# btrfs fi usa /
Overall:
    Device size:		476.37GiB
    Device allocated:		222.07GiB
    Device unallocated:		254.29GiB
    Device missing:		    0.00B
    Device slack:		  1.50KiB
    Used:			209.94GiB
    Free (estimated):		263.99GiB	(min: 136.84GiB)
    Free (statfs, df):		263.99GiB
    Data ratio:			     1.00
    Metadata ratio:		     2.00
    Global reserve:		385.50MiB	(used: 0.00B)
    Multiple profiles:		       no

Data,single: Size:216.01GiB, Used:206.31GiB (95.51%)
   /dev/mapper/root	216.01GiB

Metadata,DUP: Size:3.00GiB, Used:1.81GiB (60.50%)
   /dev/mapper/root	  6.00GiB

System,DUP: Size:32.00MiB, Used:48.00KiB (0.15%)
   /dev/mapper/root	 64.00MiB

Unallocated:
   /dev/mapper/root	254.29GiB

$ btrfs fi usa /
WARNING: cannot read detailed chunk info, per-device usage will not be shown, 
run as root
Overall:
    Device size:		476.37GiB
    Device allocated:		222.07GiB
    Device unallocated:		254.29GiB
    Device missing:		    0.00B
    Device slack:		 16.00EiB
    Used:			209.94GiB
    Free (estimated):		263.99GiB	(min: 136.84GiB)
    Free (statfs, df):		263.99GiB
    Data ratio:			     1.00
    Metadata ratio:		     2.00
    Global reserve:		385.50MiB	(used: 0.00B)
    Multiple profiles:		       no

Data,single: Size:216.01GiB, Used:206.31GiB (95.51%)

Metadata,DUP: Size:3.00GiB, Used:1.81GiB (60.50%)

System,DUP: Size:32.00MiB, Used:48.00KiB (0.15%)

-- 
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/




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

* Re: btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
  2024-07-11  3:47     ` Qu Wenruo
@ 2024-07-11  3:55       ` Russell Coker
  2024-07-11  3:58         ` Qu Wenruo
  0 siblings, 1 reply; 8+ messages in thread
From: Russell Coker @ 2024-07-11  3:55 UTC (permalink / raw)
  To: linux-btrfs, Qu Wenruo

On Thursday, 11 July 2024 13:47:59 AEST Qu Wenruo wrote:
> > # btrfs dev usa -b /
> > /dev/mapper/root, ID: 1
> > 
> >     Device size:          511493395968
> 
> The device size is 4K aligned.
> 
> I guess it's some older fs? As newer mkfs would always round down to the
> sector size.

My recollection is that I had run mkfs on a system running Debian/Bookworm 
which had different hardware and then used dd to copy it to this one.

> >     Device slack:               1536
> >     Data,single:          231936622592
> >     Metadata,DUP:         6442450944
> >     System,DUP:             67108864
> >     Unallocated:          273047212032
> > 
> > $ btrfs dev usa -b /
> > WARNING: cannot read detailed chunk info, per-device usage will not be
> > shown, run as root
> > /dev/mapper/root, ID: 1
> > 
> >     Device size:           999010539
> >     Device slack:         18446743563215167723
> >     Unallocated:          511493394432
> >> 
> >> And what's the version of the btrfs-progs?
> > 
> > The Debian package version is 6.6.3-1.2+b1.
> 
> It may be easier to debug by trying a newer version of btrfs-progs.
> 
> And since I'm not sure if it's the unalignment causing problems, you may
> want to resize the fs by:
> 
> # btrfs device resize -1M <mnt>
> 
> Then resize to max (which should always align the fs correctly):
> 
> # btrfs device resize max <mnt>

root@cupcakke:/tmp# btrfs fi resize 1:-1M  /
Resize device id 1 (/dev/mapper/root) from 476.37GiB to 476.36GiB
root@cupcakke:/tmp# btrfs fi resize 1:max  /
Resize device id 1 (/dev/mapper/root) from 476.36GiB to max

etbe@cupcakke:/tmp$ btrfs dev usa -b /
WARNING: cannot read detailed chunk info, per-device usage will not be shown, 
run as root
/dev/mapper/root, ID: 1
   Device size:           999010539
   Device slack:         18446743563215167723
   Unallocated:          511493394432

etbe@cupcakke:/tmp$ btrfs dev usa /
WARNING: cannot read detailed chunk info, per-device usage will not be shown, 
run as root
/dev/mapper/root, ID: 1
   Device size:           952.73MiB
   Device slack:           16.00EiB
   Unallocated:           476.37GiB

That doesn't seem to have changed anything.

-- 
My Main Blog         http://etbe.coker.com.au/
My Documents Blog    http://doc.coker.com.au/




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

* Re: btrfs-progs: btrfs dev usa as non-root is wrong and should just abort
  2024-07-11  3:55       ` Russell Coker
@ 2024-07-11  3:58         ` Qu Wenruo
  0 siblings, 0 replies; 8+ messages in thread
From: Qu Wenruo @ 2024-07-11  3:58 UTC (permalink / raw)
  To: Russell Coker, linux-btrfs



在 2024/7/11 13:25, Russell Coker 写道:
> On Thursday, 11 July 2024 13:47:59 AEST Qu Wenruo wrote:
>>> # btrfs dev usa -b /
>>> /dev/mapper/root, ID: 1
>>>
>>>      Device size:          511493395968
>>
>> The device size is 4K aligned.
>>
>> I guess it's some older fs? As newer mkfs would always round down to the
>> sector size.
>
> My recollection is that I had run mkfs on a system running Debian/Bookworm
> which had different hardware and then used dd to copy it to this one.
>
>>>      Device slack:               1536
>>>      Data,single:          231936622592
>>>      Metadata,DUP:         6442450944
>>>      System,DUP:             67108864
>>>      Unallocated:          273047212032
>>>
>>> $ btrfs dev usa -b /
>>> WARNING: cannot read detailed chunk info, per-device usage will not be
>>> shown, run as root
>>> /dev/mapper/root, ID: 1
>>>
>>>      Device size:           999010539
>>>      Device slack:         18446743563215167723
>>>      Unallocated:          511493394432
>>>>
>>>> And what's the version of the btrfs-progs?
>>>
>>> The Debian package version is 6.6.3-1.2+b1.
>>
>> It may be easier to debug by trying a newer version of btrfs-progs.
>>
>> And since I'm not sure if it's the unalignment causing problems, you may
>> want to resize the fs by:
>>
>> # btrfs device resize -1M <mnt>
>>
>> Then resize to max (which should always align the fs correctly):
>>
>> # btrfs device resize max <mnt>
>
> root@cupcakke:/tmp# btrfs fi resize 1:-1M  /
> Resize device id 1 (/dev/mapper/root) from 476.37GiB to 476.36GiB
> root@cupcakke:/tmp# btrfs fi resize 1:max  /
> Resize device id 1 (/dev/mapper/root) from 476.36GiB to max
>
> etbe@cupcakke:/tmp$ btrfs dev usa -b /
> WARNING: cannot read detailed chunk info, per-device usage will not be shown,
> run as root
> /dev/mapper/root, ID: 1
>     Device size:           999010539
>     Device slack:         18446743563215167723
>     Unallocated:          511493394432

What about the usage output using root privilege?

Just want to be sure that the fs is properly resized to be 4K aligned.

>
> etbe@cupcakke:/tmp$ btrfs dev usa /
> WARNING: cannot read detailed chunk info, per-device usage will not be shown,
> run as root
> /dev/mapper/root, ID: 1
>     Device size:           952.73MiB
>     Device slack:           16.00EiB
>     Unallocated:           476.37GiB
>
> That doesn't seem to have changed anything.
>
And what about newer progs?

Thanks,
Qu

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

end of thread, other threads:[~2024-07-11  3:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-10 11:52 btrfs-progs: btrfs dev usa as non-root is wrong and should just abort Russell Coker
2024-07-10 16:29 ` Boris Burkov
2024-07-11  3:50   ` Russell Coker
2024-07-10 21:13 ` Qu Wenruo
2024-07-11  3:42   ` Russell Coker
2024-07-11  3:47     ` Qu Wenruo
2024-07-11  3:55       ` Russell Coker
2024-07-11  3:58         ` 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.