Bug 60808

Summary: ENOSPC on btrfs balance on almost empty filesystem
Product: File System Reporter: kernel-bugzilla
Component: btrfsAssignee: Josef Bacik (josef)
Status: RESOLVED CODE_FIX    
Severity: normal    
Priority: P1    
Hardware: x86-64   
OS: Linux   
Kernel Version: kernel-3.10.9-200.fc19.x86_64 Subsystem:
Regression: No Bisected commit-id:

Description kernel-bugzilla 2013-08-28 15:25:12 UTC
(please note this bug also exists in fedora as https://bugzilla.redhat.com/show_bug.cgi?id=1001214 . Please advise if I should only file future bug in both or only one bugzillas)

Description of problem:
Converting a btrfs RAID10 filesystem to RAID1 using balance ends with ENOSPC errors although there should be ample space

Version-Release number of selected component (if applicable):
kernel-3.10.9-200.fc19.x86_64

How reproducible:
Always

Steps to Reproduce:
# mkfs.btrfs -f -m raid10 -d raid10 /dev/sd{b,c,d,e,f,g}
[...]

# mount /dev/sdb /tank
# btrfs filesystem show /dev/sdb
Label: none  uuid: 64fc9652-004c-4cf1-8be9-90e7a6ea546e
        Total devices 6 FS bytes used 28.00KB
        devid    6 size 2.73TB used 2.00GB path /dev/sdg
        devid    5 size 2.73TB used 2.00GB path /dev/sdf
        devid    4 size 2.73TB used 2.00GB path /dev/sde
        devid    3 size 2.73TB used 2.00GB path /dev/sdd
        devid    2 size 2.73TB used 2.00GB path /dev/sdc
        devid    1 size 2.73TB used 2.02GB path /dev/sdb

# dd if=/dev/zero of=/tank/outfile bs=1M count=10k
10240+0 records in
10240+0 records out
10737418240 bytes (11 GB) copied, 19.3461 s, 555 MB/s

# umount /tank
# mount /dev/sdb /tank
# md5sum /tank/outfile
2dd26c4d4799ebd29fa31e48d49e8e53  /tank/outfile

# btrfs balance start -dconvert=raid1 -mconvert=raid1 /tank
ERROR: error during balancing '/tank' - No space left on device
There may be more info in syslog - try dmesg | tail

---
[  320.348412] device fsid 64fc9652-004c-4cf1-8be9-90e7a6ea546e devid 1 transid 8 /dev/sdb
[  320.350086] btrfs: disk space caching is enabled
[  320.351432] SELinux: initialized (dev sdg, type btrfs), uses xattr
[  453.781449] btrfs: relocating block group 12914130944 flags 65
[  453.978438] btrfs: relocating block group 9692905472 flags 65
[  463.650472] btrfs: found 3 extents
[  475.883302] btrfs: found 3 extents
[  476.117307] btrfs: relocating block group 6471680000 flags 65
[  476.295196] btrfs: relocating block group 3250454528 flags 65
[  476.450862] btrfs: relocating block group 29229056 flags 68
[  477.161875] btrfs: found 3265 extents
[  477.351047] btrfs: relocating block group 20971520 flags 66
[  477.550992] btrfs: found 2 extents
[  477.744960] btrfs: relocating block group 12582912 flags 1
[  477.940231] btrfs: relocating block group 4194304 flags 4
[  478.153028] btrfs: 3 enospc errors during balance

---

# btrfs filesystem df /tank
Data, RAID10: total=9.00GB, used=8.59GB
Data, RAID1: total=11.00GB, used=1.41GB
System, RAID1: total=32.00MB, used=12.00KB
System: total=4.00MB, used=0.00
Metadata, RAID1: total=1.00GB, used=12.98MB

# umount /tank
# mount /dev/sdb /tank
# md5sum /tank/outfile
2dd26c4d4799ebd29fa31e48d49e8e53  /tank/outfile





The fs is still mountable, and the file seems to be intact. It seems the file is in some kind of limbo, part RAID10, part RAID1.
Comment 1 Josef Bacik 2013-08-30 18:39:43 UTC
Fixed with patch

[PATCH] Btrfs: actually limit the size of delalloc range

Sorry about that.  Let me know if you have any other issues.