]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
Btrfs: make sure btrfs_update_delayed_ref doesn't increase ref_mod
authorChris Mason <chris.mason@oracle.com>
Wed, 25 Mar 2009 13:55:11 +0000 (09:55 -0400)
committerChris Mason <chris.mason@oracle.com>
Wed, 25 Mar 2009 13:55:11 +0000 (09:55 -0400)
btrfs_update_delayed_ref is optimized to add and remove different
references in one pass through the delayed ref tree.  It is a zero
sum on the total number of refs on a given extent.

But, the code was recording an extra ref in the head node.  This
never made it down to the disk but was used when deciding if it was
safe to free the extent while dropping snapshots.

The fix used here is to make sure the ref_mod count is unchanged
on the head ref when btrfs_update_delayed_ref is called.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/delayed-ref.c
fs/btrfs/delayed-ref.h

index 759fa247ced85341ebd301b773388ed60d41284d..cbf7dc8ae3ec2e2b84eb70f65da7cce75de6afbd 100644 (file)
@@ -450,8 +450,12 @@ static noinline int __btrfs_add_delayed_ref(struct btrfs_trans_handle *trans,
         * the head node stores the sum of all the mods, so dropping a ref
         * should drop the sum in the head node by one.
         */
-       if (parent == (u64)-1 && action == BTRFS_DROP_DELAYED_REF)
-               count_mod = -1;
+       if (parent == (u64)-1) {
+               if (action == BTRFS_DROP_DELAYED_REF)
+                       count_mod = -1;
+               else if (action == BTRFS_UPDATE_DELAYED_HEAD)
+                       count_mod = 0;
+       }
 
        /*
         * BTRFS_ADD_DELAYED_EXTENT means that we need to update
@@ -647,7 +651,7 @@ int btrfs_update_delayed_ref(struct btrfs_trans_handle *trans,
         */
        ret = __btrfs_add_delayed_ref(trans, &head_ref->node, bytenr, num_bytes,
                                      (u64)-1, 0, 0, 0,
-                                     BTRFS_ADD_DELAYED_REF, 0);
+                                     BTRFS_UPDATE_DELAYED_HEAD, 0);
        BUG_ON(ret);
 
        ret = __btrfs_add_delayed_ref(trans, &ref->node, bytenr, num_bytes,
index 57153fcc347bbcc285c56ad6d96d84b61e180ef1..3bec2ff0b15c907cee10209b46b1c07fdb8f6a03 100644 (file)
@@ -22,6 +22,7 @@
 #define BTRFS_ADD_DELAYED_REF    1 /* add one backref to the tree */
 #define BTRFS_DROP_DELAYED_REF   2 /* delete one backref from the tree */
 #define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */
+#define BTRFS_UPDATE_DELAYED_HEAD 4 /* not changing ref count on head ref */
 
 struct btrfs_delayed_ref_node {
        struct rb_node rb_node;