]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Btrfs: reserve some space for an orphan item when unlinking
authorJosef Bacik <josef@redhat.com>
Fri, 14 Oct 2011 18:46:51 +0000 (14:46 -0400)
committerChris Mason <chris.mason@oracle.com>
Wed, 16 Nov 2011 02:20:35 +0000 (21:20 -0500)
In __unlink_start_trans() if we don't have enough room for a reservation we will
check to see if the unlink will free up space.  If it does that's great, but we
will still could add an orphan item, so we need to reserve enough space to add
the orphan item.  Do this and migrate the space the global reserve so it all
works out right.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
(cherry picked from commit 3880a1b46d87a6b030c31889875befc745d95dff)

fs/btrfs/inode.c

index 53378b4b7c0d4b46533f19f6363db46625d8a591..8a803caae2ef2cb2b35d2f9e0e146b411a21b62d 100644 (file)
@@ -2642,7 +2642,8 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir,
                return ERR_PTR(-ENOMEM);
        }
 
-       trans = btrfs_start_transaction(root, 0);
+       /* 1 for the orphan item */
+       trans = btrfs_start_transaction(root, 1);
        if (IS_ERR(trans)) {
                btrfs_free_path(path);
                root->fs_info->enospc_unlink = 0;
@@ -2747,6 +2748,12 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir,
        err = 0;
 out:
        btrfs_free_path(path);
+       /* Migrate the orphan reservation over */
+       if (!err)
+               err = btrfs_block_rsv_migrate(trans->block_rsv,
+                               &root->fs_info->global_block_rsv,
+                               btrfs_calc_trans_metadata_size(root, 1));
+
        if (err) {
                btrfs_end_transaction(trans, root);
                root->fs_info->enospc_unlink = 0;