kdave / btrfs-progs

Development of userspace BTRFS tools
GNU General Public License v2.0
527 stars 239 forks source link

Enhancement: evaluate allocation requirements before balance convert #718

Open Forza-tng opened 7 months ago

Forza-tng commented 7 months ago

It would be good if btrfs-progs would evaluate if a balance operation is likely to work, and warn the user otherwise (like when doing a full balance).

For example, a user wanted to convert the following filesystem to DUP metadata, but it failed with ENOSPC.

btrfs fi us /
Overall:
    Device size:         899.51GiB
    Device allocated:        899.51GiB
    Device unallocated:        1.02MiB
    Device missing:          0.00B
    Device slack:            0.00B
    Used:            657.34GiB
    Free (estimated):        233.77GiB  (min: 233.77GiB)
    Free (statfs, df):       233.77GiB
    Data ratio:               1.00
    Metadata ratio:           1.00
    Global reserve:      512.00MiB  (used: 0.00B)
    Multiple profiles:              no

Data,single: Size:881.47GiB, Used:647.70GiB (73.48%)
   /dev/mapper/data  881.47GiB

Metadata,single: Size:18.01GiB, Used:9.64GiB (53.55%)
   /dev/mapper/data   18.01GiB

System,single: Size:32.00MiB, Used:128.00KiB (0.39%)
   /dev/mapper/data   32.00MiB

Unallocated:
   /dev/mapper/data    1.02MiB

An ENOSPC error isn't particularly helpful to users. It would be better if btrfs-progs would print a warning describing that there isn't enough unallocated space available to perform the conversion.

Bonus points if btrfs (kernel or progs) would understand that it needs to compact some data chunks and do this automatically (with a warning?).