btrfs: kill tree_mod_log_set_node_key helper
[sfrench/cifs-2.6.git] / fs / btrfs / ctree.c
index b3c4305b5ecd5fb5506ce1b4a01dc6cb140a4e76..260ca86a5cf8d03ed20266994c9ffa7714a8d6c9 100644 (file)
@@ -299,11 +299,6 @@ enum mod_log_op {
        MOD_LOG_ROOT_REPLACE,
 };
 
-struct tree_mod_move {
-       int dst_slot;
-       int nr_items;
-};
-
 struct tree_mod_root {
        u64 logical;
        u8 level;
@@ -326,32 +321,15 @@ struct tree_mod_elem {
        u64 blockptr;
 
        /* this is used for op == MOD_LOG_MOVE_KEYS */
-       struct tree_mod_move move;
+       struct {
+               int dst_slot;
+               int nr_items;
+       } move;
 
        /* this is used for op == MOD_LOG_ROOT_REPLACE */
        struct tree_mod_root old_root;
 };
 
-static inline void tree_mod_log_read_lock(struct btrfs_fs_info *fs_info)
-{
-       read_lock(&fs_info->tree_mod_log_lock);
-}
-
-static inline void tree_mod_log_read_unlock(struct btrfs_fs_info *fs_info)
-{
-       read_unlock(&fs_info->tree_mod_log_lock);
-}
-
-static inline void tree_mod_log_write_lock(struct btrfs_fs_info *fs_info)
-{
-       write_lock(&fs_info->tree_mod_log_lock);
-}
-
-static inline void tree_mod_log_write_unlock(struct btrfs_fs_info *fs_info)
-{
-       write_unlock(&fs_info->tree_mod_log_lock);
-}
-
 /*
  * Pull a new tree mod seq number for our operation.
  */
@@ -371,14 +349,14 @@ static inline u64 btrfs_inc_tree_mod_seq(struct btrfs_fs_info *fs_info)
 u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
                           struct seq_list *elem)
 {
-       tree_mod_log_write_lock(fs_info);
+       write_lock(&fs_info->tree_mod_log_lock);
        spin_lock(&fs_info->tree_mod_seq_lock);
        if (!elem->seq) {
                elem->seq = btrfs_inc_tree_mod_seq(fs_info);
                list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
        }
        spin_unlock(&fs_info->tree_mod_seq_lock);
-       tree_mod_log_write_unlock(fs_info);
+       write_unlock(&fs_info->tree_mod_log_lock);
 
        return elem->seq;
 }
@@ -420,7 +398,7 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
         * anything that's lower than the lowest existing (read: blocked)
         * sequence number can be removed from the tree.
         */
-       tree_mod_log_write_lock(fs_info);
+       write_lock(&fs_info->tree_mod_log_lock);
        tm_root = &fs_info->tree_mod_log;
        for (node = rb_first(tm_root); node; node = next) {
                next = rb_next(node);
@@ -430,7 +408,7 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
                rb_erase(node, tm_root);
                kfree(tm);
        }
-       tree_mod_log_write_unlock(fs_info);
+       write_unlock(&fs_info->tree_mod_log_lock);
 }
 
 /*
@@ -441,7 +419,7 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
  * for root replace operations, or the logical address of the affected
  * block for all other operations.
  *
- * Note: must be called with write lock (tree_mod_log_write_lock).
+ * Note: must be called with write lock for fs_info::tree_mod_log_lock.
  */
 static noinline int
 __tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)
@@ -479,7 +457,7 @@ __tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)
  * Determines if logging can be omitted. Returns 1 if it can. Otherwise, it
  * returns zero with the tree_mod_log_lock acquired. The caller must hold
  * this until all tree mod log insertions are recorded in the rb tree and then
- * call tree_mod_log_write_unlock() to release.
+ * write unlock fs_info::tree_mod_log_lock.
  */
 static inline int tree_mod_dont_log(struct btrfs_fs_info *fs_info,
                                    struct extent_buffer *eb) {
@@ -489,9 +467,9 @@ static inline int tree_mod_dont_log(struct btrfs_fs_info *fs_info,
        if (eb && btrfs_header_level(eb) == 0)
                return 1;
 
-       tree_mod_log_write_lock(fs_info);
+       write_lock(&fs_info->tree_mod_log_lock);
        if (list_empty(&(fs_info)->tree_mod_seq_list)) {
-               tree_mod_log_write_unlock(fs_info);
+               write_unlock(&fs_info->tree_mod_log_lock);
                return 1;
        }
 
@@ -553,7 +531,7 @@ static noinline int tree_mod_log_insert_key(struct extent_buffer *eb, int slot,
        }
 
        ret = __tree_mod_log_insert(eb->fs_info, tm);
-       tree_mod_log_write_unlock(eb->fs_info);
+       write_unlock(&eb->fs_info->tree_mod_log_lock);
        if (ret)
                kfree(tm);
 
@@ -615,7 +593,7 @@ static noinline int tree_mod_log_insert_move(struct extent_buffer *eb,
        ret = __tree_mod_log_insert(eb->fs_info, tm);
        if (ret)
                goto free_tms;
-       tree_mod_log_write_unlock(eb->fs_info);
+       write_unlock(&eb->fs_info->tree_mod_log_lock);
        kfree(tm_list);
 
        return 0;
@@ -626,7 +604,7 @@ free_tms:
                kfree(tm_list[i]);
        }
        if (locked)
-               tree_mod_log_write_unlock(eb->fs_info);
+               write_unlock(&eb->fs_info->tree_mod_log_lock);
        kfree(tm_list);
        kfree(tm);
 
@@ -654,12 +632,10 @@ __tree_mod_log_free_eb(struct btrfs_fs_info *fs_info,
        return 0;
 }
 
-static noinline int
-tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
-                        struct extent_buffer *old_root,
-                        struct extent_buffer *new_root,
-                        int log_removal)
+static noinline int tree_mod_log_insert_root(struct extent_buffer *old_root,
+                        struct extent_buffer *new_root, int log_removal)
 {
+       struct btrfs_fs_info *fs_info = old_root->fs_info;
        struct tree_mod_elem *tm = NULL;
        struct tree_mod_elem **tm_list = NULL;
        int nritems = 0;
@@ -707,7 +683,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
        if (!ret)
                ret = __tree_mod_log_insert(fs_info, tm);
 
-       tree_mod_log_write_unlock(fs_info);
+       write_unlock(&fs_info->tree_mod_log_lock);
        if (ret)
                goto free_tms;
        kfree(tm_list);
@@ -734,7 +710,7 @@ __tree_mod_log_search(struct btrfs_fs_info *fs_info, u64 start, u64 min_seq,
        struct tree_mod_elem *cur = NULL;
        struct tree_mod_elem *found = NULL;
 
-       tree_mod_log_read_lock(fs_info);
+       read_lock(&fs_info->tree_mod_log_lock);
        tm_root = &fs_info->tree_mod_log;
        node = tm_root->rb_node;
        while (node) {
@@ -762,7 +738,7 @@ __tree_mod_log_search(struct btrfs_fs_info *fs_info, u64 start, u64 min_seq,
                        break;
                }
        }
-       tree_mod_log_read_unlock(fs_info);
+       read_unlock(&fs_info->tree_mod_log_lock);
 
        return found;
 }
@@ -843,7 +819,7 @@ tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
                        goto free_tms;
        }
 
-       tree_mod_log_write_unlock(fs_info);
+       write_unlock(&fs_info->tree_mod_log_lock);
        kfree(tm_list);
 
        return 0;
@@ -855,31 +831,12 @@ free_tms:
                kfree(tm_list[i]);
        }
        if (locked)
-               tree_mod_log_write_unlock(fs_info);
+               write_unlock(&fs_info->tree_mod_log_lock);
        kfree(tm_list);
 
        return ret;
 }
 
-static inline void
-tree_mod_log_eb_move(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
-                    int dst_offset, int src_offset, int nr_items)
-{
-       int ret;
-       ret = tree_mod_log_insert_move(dst, dst_offset, src_offset, nr_items);
-       BUG_ON(ret < 0);
-}
-
-static noinline void tree_mod_log_set_node_key(struct extent_buffer *eb,
-               int slot, int atomic)
-{
-       int ret;
-
-       ret = tree_mod_log_insert_key(eb, slot, MOD_LOG_KEY_REPLACE,
-                                       atomic ? GFP_ATOMIC : GFP_NOFS);
-       BUG_ON(ret < 0);
-}
-
 static noinline int tree_mod_log_free_eb(struct extent_buffer *eb)
 {
        struct tree_mod_elem **tm_list = NULL;
@@ -911,7 +868,7 @@ static noinline int tree_mod_log_free_eb(struct extent_buffer *eb)
                goto free_tms;
 
        ret = __tree_mod_log_free_eb(eb->fs_info, tm_list, nritems);
-       tree_mod_log_write_unlock(eb->fs_info);
+       write_unlock(&eb->fs_info->tree_mod_log_lock);
        if (ret)
                goto free_tms;
        kfree(tm_list);
@@ -932,8 +889,7 @@ tree_mod_log_set_root_pointer(struct btrfs_root *root,
                              int log_removal)
 {
        int ret;
-       ret = tree_mod_log_insert_root(root->fs_info, root->node,
-                                      new_root_node, log_removal);
+       ret = tree_mod_log_insert_root(root->node, new_root_node, log_removal);
        BUG_ON(ret < 0);
 }
 
@@ -1201,9 +1157,8 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
  * returns the logical address of the oldest predecessor of the given root.
  * entries older than time_seq are ignored.
  */
-static struct tree_mod_elem *
-__tree_mod_log_oldest_root(struct btrfs_fs_info *fs_info,
-                          struct extent_buffer *eb_root, u64 time_seq)
+static struct tree_mod_elem *__tree_mod_log_oldest_root(
+               struct extent_buffer *eb_root, u64 time_seq)
 {
        struct tree_mod_elem *tm;
        struct tree_mod_elem *found = NULL;
@@ -1220,7 +1175,7 @@ __tree_mod_log_oldest_root(struct btrfs_fs_info *fs_info,
         * first operation that's logged for this root.
         */
        while (1) {
-               tm = tree_mod_log_search_oldest(fs_info, root_logical,
+               tm = tree_mod_log_search_oldest(eb_root->fs_info, root_logical,
                                                time_seq);
                if (!looped && !tm)
                        return NULL;
@@ -1269,7 +1224,7 @@ __tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct extent_buffer *eb,
        unsigned long p_size = sizeof(struct btrfs_key_ptr);
 
        n = btrfs_header_nritems(eb);
-       tree_mod_log_read_lock(fs_info);
+       read_lock(&fs_info->tree_mod_log_lock);
        while (tm && tm->seq >= time_seq) {
                /*
                 * all the operations are recorded with the operator used for
@@ -1324,7 +1279,7 @@ __tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct extent_buffer *eb,
                if (tm->logical != first_tm->logical)
                        break;
        }
-       tree_mod_log_read_unlock(fs_info);
+       read_unlock(&fs_info->tree_mod_log_lock);
        btrfs_set_header_nritems(eb, n);
 }
 
@@ -1410,7 +1365,7 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
        u64 logical;
 
        eb_root = btrfs_read_lock_root_node(root);
-       tm = __tree_mod_log_oldest_root(fs_info, eb_root, time_seq);
+       tm = __tree_mod_log_oldest_root(eb_root, time_seq);
        if (!tm)
                return eb_root;
 
@@ -1474,7 +1429,7 @@ int btrfs_old_root_level(struct btrfs_root *root, u64 time_seq)
        int level;
        struct extent_buffer *eb_root = btrfs_root_node(root);
 
-       tm = __tree_mod_log_oldest_root(root->fs_info, eb_root, time_seq);
+       tm = __tree_mod_log_oldest_root(eb_root, time_seq);
        if (tm && tm->op == MOD_LOG_ROOT_REPLACE) {
                level = tm->old_root.level;
        } else {
@@ -1997,7 +1952,9 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
                } else {
                        struct btrfs_disk_key right_key;
                        btrfs_node_key(right, &right_key, 0);
-                       tree_mod_log_set_node_key(parent, pslot + 1, 0);
+                       ret = tree_mod_log_insert_key(parent, pslot + 1,
+                                       MOD_LOG_KEY_REPLACE, GFP_NOFS);
+                       BUG_ON(ret < 0);
                        btrfs_set_node_key(parent, &right_key, pslot + 1);
                        btrfs_mark_buffer_dirty(parent);
                }
@@ -2041,7 +1998,9 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
                /* update the parent key to reflect our changes */
                struct btrfs_disk_key mid_key;
                btrfs_node_key(mid, &mid_key, 0);
-               tree_mod_log_set_node_key(parent, pslot, 0);
+               ret = tree_mod_log_insert_key(parent, pslot,
+                               MOD_LOG_KEY_REPLACE, GFP_NOFS);
+               BUG_ON(ret < 0);
                btrfs_set_node_key(parent, &mid_key, pslot);
                btrfs_mark_buffer_dirty(parent);
        }
@@ -2142,7 +2101,9 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,
                        struct btrfs_disk_key disk_key;
                        orig_slot += left_nr;
                        btrfs_node_key(mid, &disk_key, 0);
-                       tree_mod_log_set_node_key(parent, pslot, 0);
+                       ret = tree_mod_log_insert_key(parent, pslot,
+                                       MOD_LOG_KEY_REPLACE, GFP_NOFS);
+                       BUG_ON(ret < 0);
                        btrfs_set_node_key(parent, &disk_key, pslot);
                        btrfs_mark_buffer_dirty(parent);
                        if (btrfs_header_nritems(left) > orig_slot) {
@@ -2196,7 +2157,9 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,
                        struct btrfs_disk_key disk_key;
 
                        btrfs_node_key(right, &disk_key, 0);
-                       tree_mod_log_set_node_key(parent, pslot + 1, 0);
+                       ret = tree_mod_log_insert_key(parent, pslot + 1,
+                                       MOD_LOG_KEY_REPLACE, GFP_NOFS);
+                       BUG_ON(ret < 0);
                        btrfs_set_node_key(parent, &disk_key, pslot + 1);
                        btrfs_mark_buffer_dirty(parent);
 
@@ -3149,13 +3112,17 @@ static void fixup_low_keys(struct btrfs_fs_info *fs_info,
 {
        int i;
        struct extent_buffer *t;
+       int ret;
 
        for (i = level; i < BTRFS_MAX_LEVEL; i++) {
                int tslot = path->slots[i];
+
                if (!path->nodes[i])
                        break;
                t = path->nodes[i];
-               tree_mod_log_set_node_key(t, tslot, 1);
+               ret = tree_mod_log_insert_key(t, tslot, MOD_LOG_KEY_REPLACE,
+                               GFP_ATOMIC);
+               BUG_ON(ret < 0);
                btrfs_set_node_key(t, key, tslot);
                btrfs_mark_buffer_dirty(path->nodes[i]);
                if (tslot != 0)
@@ -3252,8 +3219,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,
 
        if (push_items < src_nritems) {
                /*
-                * don't call tree_mod_log_eb_move here, key removal was already
-                * fully logged by tree_mod_log_eb_copy above.
+                * Don't call tree_mod_log_insert_move here, key removal was
+                * already fully logged by tree_mod_log_eb_copy above.
                 */
                memmove_extent_buffer(src, btrfs_node_key_ptr_offset(0),
                                      btrfs_node_key_ptr_offset(push_items),
@@ -3308,7 +3275,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
        if (max_push < push_items)
                push_items = max_push;
 
-       tree_mod_log_eb_move(fs_info, dst, push_items, 0, dst_nritems);
+       ret = tree_mod_log_insert_move(dst, push_items, 0, dst_nritems);
+       BUG_ON(ret < 0);
        memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(push_items),
                                      btrfs_node_key_ptr_offset(0),
                                      (dst_nritems) *
@@ -3426,9 +3394,11 @@ static void insert_ptr(struct btrfs_trans_handle *trans,
        BUG_ON(slot > nritems);
        BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(fs_info));
        if (slot != nritems) {
-               if (level)
-                       tree_mod_log_eb_move(fs_info, lower, slot + 1,
-                                            slot, nritems - slot);
+               if (level) {
+                       ret = tree_mod_log_insert_move(lower, slot + 1, slot,
+                                       nritems - slot);
+                       BUG_ON(ret < 0);
+               }
                memmove_extent_buffer(lower,
                              btrfs_node_key_ptr_offset(slot + 1),
                              btrfs_node_key_ptr_offset(slot),
@@ -4899,9 +4869,11 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
 
        nritems = btrfs_header_nritems(parent);
        if (slot != nritems - 1) {
-               if (level)
-                       tree_mod_log_eb_move(fs_info, parent, slot,
-                                            slot + 1, nritems - slot - 1);
+               if (level) {
+                       ret = tree_mod_log_insert_move(parent, slot, slot + 1,
+                                       nritems - slot - 1);
+                       BUG_ON(ret < 0);
+               }
                memmove_extent_buffer(parent,
                              btrfs_node_key_ptr_offset(slot),
                              btrfs_node_key_ptr_offset(slot + 1),