aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2011-01-05 05:07:18 -0500
committerChris Mason <chris.mason@oracle.com>2011-01-16 11:30:19 -0500
commitd52a5b5f1fa40804f681cf9868d4a8f90661bdf3 (patch)
tree93ae0faf84163748353d1edb6c5247483762f2df /fs
parent299a08b1c34f9397797946a0fa215c5fd145c5cf (diff)
btrfs: try to reclaim some space when chunk allocation fails
We cannot write data into files when when there is tiny space in the filesystem. Reproduce steps: # mkfs.btrfs /dev/sda1 # mount /dev/sda1 /mnt # dd if=/dev/zero of=/mnt/tmpfile0 bs=4K count=1 # dd if=/dev/zero of=/mnt/tmpfile1 bs=4K count=99999999999999 (fill the filesystem) # umount /mnt # mount /dev/sda1 /mnt # rm -f /mnt/tmpfile0 # dd if=/dev/zero of=/mnt/tmpfile0 bs=4K count=1 (failed with nospec) But if we do the last step again, we can write data successfully. The reason of the problem is that btrfs didn't try to commit the current transaction and reclaim some space when chunk allocation failed. This patch fixes it by committing the current transaction to reclaim some space when chunk allocation fails. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Reviewed-by: Josef Bacik <josef@redhat.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/extent-tree.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index b180efdc8b68..3c71d95111fe 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3162,8 +3162,12 @@ alloc:
3162 bytes + 2 * 1024 * 1024, 3162 bytes + 2 * 1024 * 1024,
3163 alloc_target, 0); 3163 alloc_target, 0);
3164 btrfs_end_transaction(trans, root); 3164 btrfs_end_transaction(trans, root);
3165 if (ret < 0) 3165 if (ret < 0) {
3166 return ret; 3166 if (ret != -ENOSPC)
3167 return ret;
3168 else
3169 goto commit_trans;
3170 }
3167 3171
3168 if (!data_sinfo) { 3172 if (!data_sinfo) {
3169 btrfs_set_inode_space_info(root, inode); 3173 btrfs_set_inode_space_info(root, inode);
@@ -3174,6 +3178,7 @@ alloc:
3174 spin_unlock(&data_sinfo->lock); 3178 spin_unlock(&data_sinfo->lock);
3175 3179
3176 /* commit the current transaction and try again */ 3180 /* commit the current transaction and try again */
3181commit_trans:
3177 if (!committed && !root->fs_info->open_ioctl_trans) { 3182 if (!committed && !root->fs_info->open_ioctl_trans) {
3178 committed = 1; 3183 committed = 1;
3179 trans = btrfs_join_transaction(root, 1); 3184 trans = btrfs_join_transaction(root, 1);