My system is Fedora 19 x86_64 w/3.10.7 kernel.
I am trying to use a btrfs snapshot for backing up my /, like this:
#!/bin/bash
btrfs subvolume snapshot / /snap/
tar -cvf - /snap 2>/dev/null | /opt/bup/bin/bup split -n nb -vv
btrfs subvolume delete /snap
Unfortunately the system runs out of free space somewhere at the middle of this process. btrfs filesystem df / reports there is some free space actually:
[root@cellar ~]# btrfs filesystem df /
Data: total=107.21GB, used=75.06GB
System, DUP: total=8.00MB, used=20.00KB
System: total=4.00MB, used=0.00
Metadata, DUP: total=3.50GB, used=3.00GB
Metadata: total=8.00MB, used=0.00
but I can't neither create nor delete a single file. This is 100% reproducible on every script run. I am usually able to recover from this situation after about 30 mins of random tries to delete anything unimportant. It looks like the root of problem is metadata space shortage. When there is no snapshot my system uses about 2.39-2.40GB of metadata space.
This looks like a bug to me. Why does a snapshot need 0.6GB of the metadata space when there are no heavy writes at this time at all? Why is btrfs unable to use remaining 0.5GB of the metadata space? I tried to use btrfs balance but it did not relocate anything so I guessed the FS was perfectly balanced already. Is it possible to reserve more metadata space somehow? (probably I need to reformat the whole partition but I was unable to find anything related to metadata space size in mkfs.btrfs manual). I guess I can set a larger nodesize using -n option but I'm not sure if it can help.
btrfs subvolume snapshot -rright now, everything is OK with metadata space so far!