Btrfs: fix a bug on overcommit stuff
authorLiu Bo <liubo2009@cn.fujitsu.com>
Thu, 16 Feb 2012 10:34:39 +0000 (18:34 +0800)
committerDavid Sterba <dsterba@suse.cz>
Thu, 16 Feb 2012 16:23:18 +0000 (17:23 +0100)
When overcommitting, we should check the sum of pinned space and
bytes for delayed item.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
fs/btrfs/extent-tree.c

index 60bfe2d68547b8f7a7fed66c6d41d75c6dd7daef..dc083f55bcfd6d59b1dfdabe7d854d53093ee037 100644 (file)
@@ -3611,12 +3611,15 @@ static int may_commit_transaction(struct btrfs_root *root,
        if (space_info != delayed_rsv->space_info)
                return -ENOSPC;
 
+       spin_lock(&space_info->lock);
        spin_lock(&delayed_rsv->lock);
-       if (delayed_rsv->size < bytes) {
+       if (space_info->bytes_pinned + delayed_rsv->size < bytes) {
                spin_unlock(&delayed_rsv->lock);
+               spin_unlock(&space_info->lock);
                return -ENOSPC;
        }
        spin_unlock(&delayed_rsv->lock);
+       spin_unlock(&space_info->lock);
 
 commit:
        trans = btrfs_join_transaction(root);