btrfs: add and use helpers for reading and writing last_log_commit
[linux-2.6-microblaze.git] / fs / btrfs / tree-log.c
index cbb17b5..28a61a7 100644 (file)
@@ -347,8 +347,7 @@ static int process_one_buffer(struct btrfs_root *log,
        }
 
        if (wc->pin) {
-               ret = btrfs_pin_extent_for_log_replay(wc->trans, eb->start,
-                                                     eb->len);
+               ret = btrfs_pin_extent_for_log_replay(wc->trans, eb);
                if (ret)
                        return ret;
 
@@ -504,9 +503,9 @@ insert:
                found_size = btrfs_item_size(path->nodes[0],
                                                path->slots[0]);
                if (found_size > item_size)
-                       btrfs_truncate_item(path, item_size, 1);
+                       btrfs_truncate_item(trans, path, item_size, 1);
                else if (found_size < item_size)
-                       btrfs_extend_item(path, item_size - found_size);
+                       btrfs_extend_item(trans, path, item_size - found_size);
        } else if (ret) {
                return ret;
        }
@@ -574,7 +573,7 @@ insert:
                }
        }
 no_copy:
-       btrfs_mark_buffer_dirty(path->nodes[0]);
+       btrfs_mark_buffer_dirty(trans, path->nodes[0]);
        btrfs_release_path(path);
        return 0;
 }
@@ -767,7 +766,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
                        } else if (ret == 0) {
                                btrfs_init_generic_ref(&ref,
                                                BTRFS_ADD_DELAYED_REF,
-                                               ins.objectid, ins.offset, 0);
+                                               ins.objectid, ins.offset, 0,
+                                               root->root_key.objectid);
                                btrfs_init_data_ref(&ref,
                                                root->root_key.objectid,
                                                key->objectid, offset, 0, false);
@@ -890,7 +890,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
 
 update_inode:
        btrfs_update_inode_bytes(BTRFS_I(inode), nbytes, drop_args.bytes_found);
-       ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
+       ret = btrfs_update_inode(trans, BTRFS_I(inode));
 out:
        iput(inode);
        return ret;
@@ -1445,7 +1445,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
                        if (ret)
                                goto out;
 
-                       ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
+                       ret = btrfs_update_inode(trans, BTRFS_I(inode));
                        if (ret)
                                goto out;
                }
@@ -1483,8 +1483,7 @@ out:
        return ret;
 }
 
-static int count_inode_extrefs(struct btrfs_root *root,
-               struct btrfs_inode *inode, struct btrfs_path *path)
+static int count_inode_extrefs(struct btrfs_inode *inode, struct btrfs_path *path)
 {
        int ret = 0;
        int name_len;
@@ -1498,8 +1497,8 @@ static int count_inode_extrefs(struct btrfs_root *root,
        struct extent_buffer *leaf;
 
        while (1) {
-               ret = btrfs_find_one_extref(root, inode_objectid, offset, path,
-                                           &extref, &offset);
+               ret = btrfs_find_one_extref(inode->root, inode_objectid, offset,
+                                           path, &extref, &offset);
                if (ret)
                        break;
 
@@ -1527,8 +1526,7 @@ static int count_inode_extrefs(struct btrfs_root *root,
        return nlink;
 }
 
-static int count_inode_refs(struct btrfs_root *root,
-                       struct btrfs_inode *inode, struct btrfs_path *path)
+static int count_inode_refs(struct btrfs_inode *inode, struct btrfs_path *path)
 {
        int ret;
        struct btrfs_key key;
@@ -1543,7 +1541,7 @@ static int count_inode_refs(struct btrfs_root *root,
        key.offset = (u64)-1;
 
        while (1) {
-               ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
+               ret = btrfs_search_slot(NULL, inode->root, &key, path, 0, 0);
                if (ret < 0)
                        break;
                if (ret > 0) {
@@ -1595,9 +1593,9 @@ process_slot:
  * will free the inode.
  */
 static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans,
-                                          struct btrfs_root *root,
                                           struct inode *inode)
 {
+       struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_path *path;
        int ret;
        u64 nlink = 0;
@@ -1607,13 +1605,13 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans,
        if (!path)
                return -ENOMEM;
 
-       ret = count_inode_refs(root, BTRFS_I(inode), path);
+       ret = count_inode_refs(BTRFS_I(inode), path);
        if (ret < 0)
                goto out;
 
        nlink = ret;
 
-       ret = count_inode_extrefs(root, BTRFS_I(inode), path);
+       ret = count_inode_extrefs(BTRFS_I(inode), path);
        if (ret < 0)
                goto out;
 
@@ -1623,7 +1621,7 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans,
 
        if (nlink != inode->i_nlink) {
                set_nlink(inode, nlink);
-               ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
+               ret = btrfs_update_inode(trans, BTRFS_I(inode));
                if (ret)
                        goto out;
        }
@@ -1685,7 +1683,7 @@ static noinline int fixup_inode_link_counts(struct btrfs_trans_handle *trans,
                        break;
                }
 
-               ret = fixup_inode_link_count(trans, root, inode);
+               ret = fixup_inode_link_count(trans, inode);
                iput(inode);
                if (ret)
                        break;
@@ -1732,7 +1730,7 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans,
                        set_nlink(inode, 1);
                else
                        inc_nlink(inode);
-               ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
+               ret = btrfs_update_inode(trans, BTRFS_I(inode));
        } else if (ret == -EEXIST) {
                ret = 0;
        }
@@ -1939,7 +1937,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
 out:
        if (!ret && update_size) {
                btrfs_i_size_write(BTRFS_I(dir), dir->i_size + name.len * 2);
-               ret = btrfs_update_inode(trans, root, BTRFS_I(dir));
+               ret = btrfs_update_inode(trans, BTRFS_I(dir));
        }
        kfree(name.name);
        iput(dir);
@@ -2483,7 +2481,7 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
                                                        drop_args.bytes_found);
                                        /* Update the inode's nbytes. */
                                        ret = btrfs_update_inode(wc->trans,
-                                                       root, BTRFS_I(inode));
+                                                                BTRFS_I(inode));
                                }
                                iput(inode);
                                if (ret)
@@ -2574,7 +2572,7 @@ static int clean_log_buffer(struct btrfs_trans_handle *trans,
        btrfs_tree_unlock(eb);
 
        if (trans) {
-               ret = btrfs_pin_reserved_extent(trans, eb->start, eb->len);
+               ret = btrfs_pin_reserved_extent(trans, eb);
                if (ret)
                        return ret;
                btrfs_redirty_list_add(trans->transaction, eb);
@@ -2848,10 +2846,9 @@ static inline void btrfs_remove_all_log_ctxs(struct btrfs_root *root,
 }
 
 /*
- * btrfs_sync_log does sends a given tree log down to the disk and
- * updates the super blocks to record it.  When this call is done,
- * you know that any inodes previously logged are safely on disk only
- * if it returns 0.
+ * Sends a given tree log down to the disk and updates the super blocks to
+ * record it.  When this call is done, you know that any inodes previously
+ * logged are safely on disk only if it returns 0.
  *
  * Any other return value means you need to call btrfs_commit_transaction.
  * Some of the edge cases for fsyncing directories that have had unlinks
@@ -3136,8 +3133,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
         * someone else already started it. We use <= and not < because the
         * first log transaction has an ID of 0.
         */
-       ASSERT(root->last_log_commit <= log_transid);
-       root->last_log_commit = log_transid;
+       ASSERT(btrfs_get_root_last_log_commit(root) <= log_transid);
+       btrfs_set_root_last_log_commit(root, log_transid);
 
 out_wake_log_root:
        mutex_lock(&log_root_tree->log_mutex);
@@ -3211,8 +3208,7 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
                }
        }
 
-       clear_extent_bits(&log->dirty_log_pages, 0, (u64)-1,
-                         EXTENT_DIRTY | EXTENT_NEW | EXTENT_NEED_WAIT);
+       extent_io_tree_release(&log->dirty_log_pages);
        extent_io_tree_release(&log->log_csum_range);
 
        btrfs_put_root(log);
@@ -3530,7 +3526,7 @@ static noinline int insert_dir_log_key(struct btrfs_trans_handle *trans,
                last_offset = max(last_offset, curr_end);
        }
        btrfs_set_dir_log_end(path->nodes[0], item, last_offset);
-       btrfs_mark_buffer_dirty(path->nodes[0]);
+       btrfs_mark_buffer_dirty(trans, path->nodes[0]);
        btrfs_release_path(path);
        return 0;
 }
@@ -4488,7 +4484,7 @@ copy_item:
                dst_index++;
        }
 
-       btrfs_mark_buffer_dirty(dst_path->nodes[0]);
+       btrfs_mark_buffer_dirty(trans, dst_path->nodes[0]);
        btrfs_release_path(dst_path);
 out:
        kfree(ins_data);
@@ -4693,7 +4689,7 @@ static int log_one_extent(struct btrfs_trans_handle *trans,
        write_extent_buffer(leaf, &fi,
                            btrfs_item_ptr_offset(leaf, path->slots[0]),
                            sizeof(fi));
-       btrfs_mark_buffer_dirty(leaf);
+       btrfs_mark_buffer_dirty(trans, leaf);
 
        btrfs_release_path(path);
 
@@ -4921,12 +4917,12 @@ process:
                set_bit(BTRFS_ORDERED_LOGGED, &ordered->flags);
 
                if (!test_bit(BTRFS_ORDERED_COMPLETE, &ordered->flags)) {
-                       spin_lock_irq(&inode->ordered_tree.lock);
+                       spin_lock_irq(&inode->ordered_tree_lock);
                        if (!test_bit(BTRFS_ORDERED_COMPLETE, &ordered->flags)) {
                                set_bit(BTRFS_ORDERED_PENDING, &ordered->flags);
                                atomic_inc(&trans->transaction->pending_ordered);
                        }
-                       spin_unlock_irq(&inode->ordered_tree.lock);
+                       spin_unlock_irq(&inode->ordered_tree_lock);
                }
                btrfs_put_ordered_extent(ordered);
        }
@@ -7204,9 +7200,7 @@ again:
                         * each subsequent pass.
                         */
                        if (ret == -ENOENT)
-                               ret = btrfs_pin_extent_for_log_replay(trans,
-                                                       log->node->start,
-                                                       log->node->len);
+                               ret = btrfs_pin_extent_for_log_replay(trans, log->node);
                        btrfs_put_root(log);
 
                        if (!ret)