btrfs-progs/cmds
Goffredo Baroncelli fdf7f35d3e btrfs-progs: fi usage: wrong values in case of raid56 and not root
In case of a raid5/6 filesystem 'btrfs fi us' returns wrong values
without the root capabilities:

  $ sudo btrfs fi us /tmp/raid5fs  # as root
  Overall:
      Device size:                   3.00GiB
      Device allocated:              1.51GiB		<--- OK
      Device unallocated:            1.49GiB		<--- OK
      Device missing:                  0.00B
      Device slack:                    0.00B
      Used:                        769.03MiB		<--- OK
      Free (estimated):              1.32GiB      (min: 1.32GiB) <-OK
      Free (statfs, df):             1.32GiB
      Data ratio:                       1.50		<--- OK
      Metadata ratio:                   1.50		<--- OK
      Global reserve:                5.50MiB      (used: 0.00B)
      Multiple profiles:                  no
  [...]

  $ btrfs fi us /tmp/raid5fs      # as user
  WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
  Overall:
      Device size:                   3.00GiB
      Device allocated:                0.00B		<--- WRONG
      Device unallocated:            3.00GiB		<--- WRONG
      Device missing:                  0.00B
      Device slack:                    0.00B
      Used:                            0.00B		<--- WRONG
      Free (estimated):                0.00B      (min: 8.00EiB) <- WRONG
      Free (statfs, df):             1.32GiB
      Data ratio:                       0.00		<--- WRONG
      Metadata ratio:                   0.00		<--- WRONG
      Global reserve:                5.50MiB      (used: 0.00B)
      Multiple profiles:                  no
  [...]

The reason is that the BTRFS_IOC_SPACE_INFO ioctl doesn't return enough
information. To bypass it a scan of the chunks is required when a
raid5/6 profile is present.

To avoid providing wrong information, in case of a raid5/6 filesystem
without the root capabilities the "btrfs fi us" is not executed at all
and a warning with a suggestion to run it as root is printed.

  $ ./btrfs fi us /tmp/t/
  WARNING: cannot read detailed chunk info, per-device usage will not be shown, run as root
  WARNING: due to the presence of a raid5/raid6 profile, we cannots compute some values;
  WARNING: run as root instead.

Signed-off-by: Goffredo Baroncelli <kreijack@libero.it>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-18 02:14:23 +01:00
..
balance.c btrfs-progs: remove old syntax of 'balance /path' 2023-11-03 18:04:37 +01:00
commands.h btrfs-progs: use unsigned type for bit shift values 2023-11-03 18:04:37 +01:00
device.c btrfs-progs: device delete: add timeout when removing multiple devices 2023-12-01 02:54:09 +01:00
filesystem-du.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
filesystem-usage.c btrfs-progs: fi usage: wrong values in case of raid56 and not root 2024-01-18 02:14:23 +01:00
filesystem-usage.h btrfs-progs: convert device info to struct array 2023-10-17 19:34:00 +02:00
filesystem.c btrfs-progs: implement arg_strtou64_with_suffix() with a new helper 2024-01-18 02:14:23 +01:00
inspect-dump-super.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
inspect-dump-tree.c btrfs-progs: dump-tree: allow using '-' for tree ids 2023-10-06 17:33:08 +02:00
inspect-tree-stats.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
inspect.c btrfs-progs: cmds: drop unsigned long long casts for printf 2023-11-03 18:04:37 +01:00
property.c btrfs-progs: property set: skip opening char devices completely 2023-11-14 15:48:00 +01:00
props.h btrfs-progs: use unsigned type for bit shift values 2023-11-03 18:04:37 +01:00
qgroup.c btrfs-progs: implement arg_strtou64_with_suffix() with a new helper 2024-01-18 02:14:23 +01:00
qgroup.h btrfs-progs: sync uapi/btrfs.h into btrfs-progs 2023-05-26 18:02:28 +02:00
quota.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
receive-dump.c btrfs-progs: receive: add support for fs-verity 2022-10-11 09:08:08 +02:00
receive-dump.h btrfs-progs: cmds: update include lists 2022-10-11 09:07:59 +02:00
receive.c btrfs-progs: receive: properly report lack of zstd support 2023-12-07 14:29:54 +01:00
reflink.c btrfs-progs: implement arg_strtou64_with_suffix() with a new helper 2024-01-18 02:14:23 +01:00
replace.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
rescue-chunk-recover.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
rescue-super-recover.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
rescue.c btrfs-progs: rescue: replace kfree by free in clear_uuid_tree 2023-11-03 18:04:37 +01:00
rescue.h btrfs-progs: unify GPL header comments 2021-09-07 13:58:44 +02:00
restore.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
scrub.c btrfs-progs: implement arg_strtou64_with_suffix() with a new helper 2024-01-18 02:14:23 +01:00
send.c btrfs-progs: use get_sysfs_proto_supported() in get_sysfs_proto_supported() 2023-12-01 01:58:56 +01:00
subvolume-list.c btrfs-progs: fix all variable shadowing 2023-10-10 19:16:29 +02:00
subvolume.c btrfs-progs: subvolume: fix return value when the target exists 2024-01-10 04:16:13 +01:00
subvolume.h btrfs-progs: subvol: introduce rowspec definition for json output 2023-08-28 17:24:23 +02:00