Btrfs: reserve sufficient space for ioctl clone
authorSage Weil <sage@newdream.net>
Tue, 20 Sep 2011 18:48:51 +0000 (14:48 -0400)
committerChris Mason <chris.mason@oracle.com>
Tue, 20 Sep 2011 18:48:51 +0000 (14:48 -0400)
Fix a crash/BUG_ON in the clone ioctl due to insufficient reservation. We
need to reserve space for:

 - adjusting the old extent (possibly splitting it)
 - adding the new extent
 - updating the inode

Signed-off-by: Sage Weil <sage@newdream.net>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ioctl.c

index 9947a0ac7bd5958a3445908ca495d389acd0ae58..6f89bcc4e5554cbf497e149043ab0e02202e8164 100644 (file)
@@ -2336,7 +2336,12 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
                        else
                                new_key.offset = destoff;
 
-                       trans = btrfs_start_transaction(root, 1);
+                       /*
+                        * 1 - adjusting old extent (we may have to split it)
+                        * 1 - add new extent
+                        * 1 - inode update
+                        */
+                       trans = btrfs_start_transaction(root, 3);
                        if (IS_ERR(trans)) {
                                ret = PTR_ERR(trans);
                                goto out;