btrfs: Remove fs_info argument from update_inline_extent_backref
[sfrench/cifs-2.6.git] / fs / btrfs / extent-tree.c
index 3d9fe58c0080db89f4933f162f8bf7f8d6df1c85..102911286497e8c87231b79b0a37be976cde72bf 100644 (file)
@@ -1304,13 +1304,12 @@ fail:
 }
 
 static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans,
-                                          struct btrfs_fs_info *fs_info,
                                           struct btrfs_path *path,
                                           u64 bytenr, u64 parent,
                                           u64 root_objectid, u64 owner,
                                           u64 offset, int refs_to_add)
 {
-       struct btrfs_root *root = fs_info->extent_root;
+       struct btrfs_root *root = trans->fs_info->extent_root;
        struct btrfs_key key;
        struct extent_buffer *leaf;
        u32 size;
@@ -1384,7 +1383,6 @@ fail:
 }
 
 static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans,
-                                          struct btrfs_fs_info *fs_info,
                                           struct btrfs_path *path,
                                           int refs_to_drop, int *last_ref)
 {
@@ -1421,7 +1419,7 @@ static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans,
        num_refs -= refs_to_drop;
 
        if (num_refs == 0) {
-               ret = btrfs_del_item(trans, fs_info->extent_root, path);
+               ret = btrfs_del_item(trans, trans->fs_info->extent_root, path);
                *last_ref = 1;
        } else {
                if (key.type == BTRFS_EXTENT_DATA_REF_KEY)
@@ -1523,7 +1521,6 @@ static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans,
 }
 
 static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans,
-                                         struct btrfs_fs_info *fs_info,
                                          struct btrfs_path *path,
                                          u64 bytenr, u64 parent,
                                          u64 root_objectid)
@@ -1540,7 +1537,7 @@ static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans,
                key.offset = root_objectid;
        }
 
-       ret = btrfs_insert_empty_item(trans, fs_info->extent_root,
+       ret = btrfs_insert_empty_item(trans, trans->fs_info->extent_root,
                                      path, &key, 0);
        btrfs_release_path(path);
        return ret;
@@ -1599,13 +1596,13 @@ static int find_next_key(struct btrfs_path *path, int level,
  */
 static noinline_for_stack
 int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
-                                struct btrfs_fs_info *fs_info,
                                 struct btrfs_path *path,
                                 struct btrfs_extent_inline_ref **ref_ret,
                                 u64 bytenr, u64 num_bytes,
                                 u64 parent, u64 root_objectid,
                                 u64 owner, u64 offset, int insert)
 {
+       struct btrfs_fs_info *fs_info = trans->fs_info;
        struct btrfs_root *root = fs_info->extent_root;
        struct btrfs_key key;
        struct extent_buffer *leaf;
@@ -1635,8 +1632,8 @@ int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
                extra_size = -1;
 
        /*
-        * Owner is our parent level, so we can just add one to get the level
-        * for the block we are interested in.
+        * Owner is our level, so we can just add one to get the level for the
+        * block we are interested in.
         */
        if (skinny_metadata && owner < BTRFS_FIRST_FREE_OBJECTID) {
                key.type = BTRFS_METADATA_ITEM_KEY;
@@ -1871,9 +1868,9 @@ static int lookup_extent_backref(struct btrfs_trans_handle *trans,
 {
        int ret;
 
-       ret = lookup_inline_extent_backref(trans, fs_info, path, ref_ret,
-                                          bytenr, num_bytes, parent,
-                                          root_objectid, owner, offset, 0);
+       ret = lookup_inline_extent_backref(trans, path, ref_ret, bytenr,
+                                          num_bytes, parent, root_objectid,
+                                          owner, offset, 0);
        if (ret != -ENOENT)
                return ret;
 
@@ -1895,14 +1892,14 @@ static int lookup_extent_backref(struct btrfs_trans_handle *trans,
  * helper to update/remove inline back ref
  */
 static noinline_for_stack
-void update_inline_extent_backref(struct btrfs_fs_info *fs_info,
-                                 struct btrfs_path *path,
+void update_inline_extent_backref(struct btrfs_path *path,
                                  struct btrfs_extent_inline_ref *iref,
                                  int refs_to_mod,
                                  struct btrfs_delayed_extent_op *extent_op,
                                  int *last_ref)
 {
-       struct extent_buffer *leaf;
+       struct extent_buffer *leaf = path->nodes[0];
+       struct btrfs_fs_info *fs_info = leaf->fs_info;
        struct btrfs_extent_item *ei;
        struct btrfs_extent_data_ref *dref = NULL;
        struct btrfs_shared_data_ref *sref = NULL;
@@ -1913,7 +1910,6 @@ void update_inline_extent_backref(struct btrfs_fs_info *fs_info,
        int type;
        u64 refs;
 
-       leaf = path->nodes[0];
        ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
        refs = btrfs_extent_refs(leaf, ei);
        WARN_ON(refs_to_mod < 0 && refs + refs_to_mod <= 0);
@@ -1975,13 +1971,13 @@ int insert_inline_extent_backref(struct btrfs_trans_handle *trans,
        struct btrfs_extent_inline_ref *iref;
        int ret;
 
-       ret = lookup_inline_extent_backref(trans, fs_info, path, &iref,
-                                          bytenr, num_bytes, parent,
-                                          root_objectid, owner, offset, 1);
+       ret = lookup_inline_extent_backref(trans, path, &iref, bytenr,
+                                          num_bytes, parent, root_objectid,
+                                          owner, offset, 1);
        if (ret == 0) {
                BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID);
-               update_inline_extent_backref(fs_info, path, iref,
-                                            refs_to_add, extent_op, NULL);
+               update_inline_extent_backref(path, iref, refs_to_add,
+                                            extent_op, NULL);
        } else if (ret == -ENOENT) {
                setup_inline_extent_backref(fs_info, path, iref, parent,
                                            root_objectid, owner, offset,
@@ -1992,7 +1988,6 @@ int insert_inline_extent_backref(struct btrfs_trans_handle *trans,
 }
 
 static int insert_extent_backref(struct btrfs_trans_handle *trans,
-                                struct btrfs_fs_info *fs_info,
                                 struct btrfs_path *path,
                                 u64 bytenr, u64 parent, u64 root_objectid,
                                 u64 owner, u64 offset, int refs_to_add)
@@ -2000,12 +1995,12 @@ static int insert_extent_backref(struct btrfs_trans_handle *trans,
        int ret;
        if (owner < BTRFS_FIRST_FREE_OBJECTID) {
                BUG_ON(refs_to_add != 1);
-               ret = insert_tree_block_ref(trans, fs_info, path, bytenr,
-                                           parent, root_objectid);
+               ret = insert_tree_block_ref(trans, path, bytenr, parent,
+                                           root_objectid);
        } else {
-               ret = insert_extent_data_ref(trans, fs_info, path, bytenr,
-                                            parent, root_objectid,
-                                            owner, offset, refs_to_add);
+               ret = insert_extent_data_ref(trans, path, bytenr, parent,
+                                            root_objectid, owner, offset,
+                                            refs_to_add);
        }
        return ret;
 }
@@ -2020,10 +2015,10 @@ static int remove_extent_backref(struct btrfs_trans_handle *trans,
 
        BUG_ON(!is_data && refs_to_drop != 1);
        if (iref) {
-               update_inline_extent_backref(fs_info, path, iref,
-                                            -refs_to_drop, NULL, last_ref);
+               update_inline_extent_backref(path, iref, -refs_to_drop, NULL,
+                                            last_ref);
        } else if (is_data) {
-               ret = remove_extent_data_ref(trans, fs_info, path, refs_to_drop,
+               ret = remove_extent_data_ref(trans, path, refs_to_drop,
                                             last_ref);
        } else {
                *last_ref = 1;
@@ -2207,6 +2202,40 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
        return ret;
 }
 
+/*
+ * __btrfs_inc_extent_ref - insert backreference for a given extent
+ *
+ * @trans:         Handle of transaction
+ *
+ * @node:          The delayed ref node used to get the bytenr/length for
+ *                 extent whose references are incremented.
+ *
+ * @parent:        If this is a shared extent (BTRFS_SHARED_DATA_REF_KEY/
+ *                 BTRFS_SHARED_BLOCK_REF_KEY) then it holds the logical
+ *                 bytenr of the parent block. Since new extents are always
+ *                 created with indirect references, this will only be the case
+ *                 when relocating a shared extent. In that case, root_objectid
+ *                 will be BTRFS_TREE_RELOC_OBJECTID. Otheriwse, parent must
+ *                 be 0
+ *
+ * @root_objectid:  The id of the root where this modification has originated,
+ *                 this can be either one of the well-known metadata trees or
+ *                 the subvolume id which references this extent.
+ *
+ * @owner:         For data extents it is the inode number of the owning file.
+ *                 For metadata extents this parameter holds the level in the
+ *                 tree of the extent.
+ *
+ * @offset:        For metadata extents the offset is ignored and is currently
+ *                 always passed as 0. For data extents it is the fileoffset
+ *                 this extent belongs to.
+ *
+ * @refs_to_add     Number of references to add
+ *
+ * @extent_op       Pointer to a structure, holding information necessary when
+ *                  updating a tree block's flags
+ *
+ */
 static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
                                  struct btrfs_fs_info *fs_info,
                                  struct btrfs_delayed_ref_node *node,
@@ -2256,8 +2285,8 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
        path->reada = READA_FORWARD;
        path->leave_spinning = 1;
        /* now insert the actual backref */
-       ret = insert_extent_backref(trans, fs_info, path, bytenr, parent,
-                                   root_objectid, owner, offset, refs_to_add);
+       ret = insert_extent_backref(trans, path, bytenr, parent, root_objectid,
+                                   owner, offset, refs_to_add);
        if (ret)
                btrfs_abort_transaction(trans, ret);
 out:
@@ -6279,7 +6308,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
                if (list_empty(&cache->dirty_list)) {
                        list_add_tail(&cache->dirty_list,
                                      &trans->transaction->dirty_bgs);
-                               trans->transaction->num_dirty_bgs++;
+                       trans->transaction->num_dirty_bgs++;
                        btrfs_get_block_group(cache);
                }
                spin_unlock(&trans->transaction->dirty_bgs_lock);
@@ -7534,7 +7563,7 @@ search:
                 * for the proper type.
                 */
                if (!block_group_bits(block_group, flags)) {
-                   u64 extra = BTRFS_BLOCK_GROUP_DUP |
+                       u64 extra = BTRFS_BLOCK_GROUP_DUP |
                                BTRFS_BLOCK_GROUP_RAID1 |
                                BTRFS_BLOCK_GROUP_RAID5 |
                                BTRFS_BLOCK_GROUP_RAID6 |