kdave / btrfs-progs

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

Enhancement: mkfs with slack #281

Open Forza-tng opened 4 years ago

Forza-tng commented 4 years ago

I am thinking that it might be a good idea to leave a percentage of a disk as slack. This can help rescue a full filesystem when extra USB sticks or loop devices are not available.

Example: mkfs.btrfs /dev/sdb1 /dev/sdc --slack 5% This would reserve 5% slack on each disk. It should be possible to use a fixed size too, like 4G.

# btrfs device usage /
/dev/sda3, ID: 1
   Device size:           233.47GiB
   Device slack:            4.00GiB
   Data,single:            71.00GiB
   Metadata,single:         2.00GiB
   System,single:          32.00MiB
   Unallocated:           156.44GiB

It might be a good idea to add slack in the output of btrfs filesystem usage/show too to make amount of slack more visible.

Overall:
    Device size:         229.47GiB
    Device slack:                  4.00GiB
    Device allocated:         73.03GiB
    Device unallocated:      156.44GiB
    Device missing:        0.00B
    Used:             29.07GiB
    Free (estimated):        199.66GiB  (min: 199.66GiB)
    Data ratio:               1.00
    Metadata ratio:           1.00
    Global reserve:      133.92MiB  (used: 0.00B)
    Multiple profiles:              no

Data,single: Size:71.00GiB, Used:27.78GiB (39.13%)
   /dev/sda3      71.00GiB

Metadata,single: Size:2.00GiB, Used:1.29GiB (64.56%)
   /dev/sda3       2.00GiB

System,single: Size:32.00MiB, Used:16.00KiB (0.05%)
   /dev/sda3      32.00MiB

Unallocated:
   /dev/sda3     156.44GiB

Slack:
   /dev/sda3       4.00GiB
kdave commented 4 years ago

I'm confused, there already is report on the slack space, 2nd row in the summary:

Device slack:                  4.00GiB

The meaning of the value is delta of device size and filesystem space occupying the device, eg. a 10G device and filesystem resized to 6G on that device will give 4G of slack space. But that's maybe just terminology.

The idea of slack space for later use can be achieved already, though there's no nice command line UI for that. Manually, iterate over all device ids of a filesystem and do btrfs fi resize id:-4G /mnt (replacing id with device ids).

Forza-tng commented 4 years ago

Hi, sorry to be unclear. I did what you suggested btrfs fi resize id:-4G /mnt before posting to be able to show it.

There were two things I wanted to change: 1) Have this "--slack" option available in mkfs.btrfs, so we can avoid doing "btrfs fi resize id:-4G /mnt" after creating the filesystem. 2) btrfs filesystem usage does not show slack, so add slack in its output.

Forza-tng commented 4 years ago

Just realized mkfs.btrfs -b|--byte-count SIZE exists. This is very similar. Perhaps adjust so we can use percentages and negative numbers (for reverse size, i.e. like resize 1:-4G)?