diff options
author | Jeff Mahoney <jeffm@suse.com> | 2016-06-22 18:54:23 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-12-06 10:06:59 -0500 |
commit | 0b246afa62b0cf5b09d078121f543135f28492ad (patch) | |
tree | 200ad296d09f1b2f5329658c8de81bc625007ace /fs/btrfs/tree-log.c | |
parent | 6202df6921494f29308307e0ae6f567c2ab2ba19 (diff) |
btrfs: root->fs_info cleanup, add fs_info convenience variables
In routines where someptr->fs_info is referenced multiple times, we
introduce a convenience variable. This makes the code considerably
more readable.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/tree-log.c')
-rw-r--r-- | fs/btrfs/tree-log.c | 117 |
1 files changed, 64 insertions, 53 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index ad3ae2ef0cd4..dcb225e6a1c7 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -142,12 +142,13 @@ static int start_log_trans(struct btrfs_trans_handle *trans, | |||
142 | struct btrfs_root *root, | 142 | struct btrfs_root *root, |
143 | struct btrfs_log_ctx *ctx) | 143 | struct btrfs_log_ctx *ctx) |
144 | { | 144 | { |
145 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
145 | int ret = 0; | 146 | int ret = 0; |
146 | 147 | ||
147 | mutex_lock(&root->log_mutex); | 148 | mutex_lock(&root->log_mutex); |
148 | 149 | ||
149 | if (root->log_root) { | 150 | if (root->log_root) { |
150 | if (btrfs_need_log_full_commit(root->fs_info, trans)) { | 151 | if (btrfs_need_log_full_commit(fs_info, trans)) { |
151 | ret = -EAGAIN; | 152 | ret = -EAGAIN; |
152 | goto out; | 153 | goto out; |
153 | } | 154 | } |
@@ -159,10 +160,10 @@ static int start_log_trans(struct btrfs_trans_handle *trans, | |||
159 | set_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); | 160 | set_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); |
160 | } | 161 | } |
161 | } else { | 162 | } else { |
162 | mutex_lock(&root->fs_info->tree_log_mutex); | 163 | mutex_lock(&fs_info->tree_log_mutex); |
163 | if (!root->fs_info->log_root_tree) | 164 | if (!fs_info->log_root_tree) |
164 | ret = btrfs_init_log_root_tree(trans, root->fs_info); | 165 | ret = btrfs_init_log_root_tree(trans, fs_info); |
165 | mutex_unlock(&root->fs_info->tree_log_mutex); | 166 | mutex_unlock(&fs_info->tree_log_mutex); |
166 | if (ret) | 167 | if (ret) |
167 | goto out; | 168 | goto out; |
168 | 169 | ||
@@ -292,20 +293,21 @@ static int process_one_buffer(struct btrfs_root *log, | |||
292 | struct extent_buffer *eb, | 293 | struct extent_buffer *eb, |
293 | struct walk_control *wc, u64 gen) | 294 | struct walk_control *wc, u64 gen) |
294 | { | 295 | { |
296 | struct btrfs_fs_info *fs_info = log->fs_info; | ||
295 | int ret = 0; | 297 | int ret = 0; |
296 | 298 | ||
297 | /* | 299 | /* |
298 | * If this fs is mixed then we need to be able to process the leaves to | 300 | * If this fs is mixed then we need to be able to process the leaves to |
299 | * pin down any logged extents, so we have to read the block. | 301 | * pin down any logged extents, so we have to read the block. |
300 | */ | 302 | */ |
301 | if (btrfs_fs_incompat(log->fs_info, MIXED_GROUPS)) { | 303 | if (btrfs_fs_incompat(fs_info, MIXED_GROUPS)) { |
302 | ret = btrfs_read_buffer(eb, gen); | 304 | ret = btrfs_read_buffer(eb, gen); |
303 | if (ret) | 305 | if (ret) |
304 | return ret; | 306 | return ret; |
305 | } | 307 | } |
306 | 308 | ||
307 | if (wc->pin) | 309 | if (wc->pin) |
308 | ret = btrfs_pin_extent_for_log_replay(log->fs_info->extent_root, | 310 | ret = btrfs_pin_extent_for_log_replay(fs_info->extent_root, |
309 | eb->start, eb->len); | 311 | eb->start, eb->len); |
310 | 312 | ||
311 | if (!ret && btrfs_buffer_uptodate(eb, gen, 0)) { | 313 | if (!ret && btrfs_buffer_uptodate(eb, gen, 0)) { |
@@ -582,6 +584,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
582 | struct extent_buffer *eb, int slot, | 584 | struct extent_buffer *eb, int slot, |
583 | struct btrfs_key *key) | 585 | struct btrfs_key *key) |
584 | { | 586 | { |
587 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
585 | int found_type; | 588 | int found_type; |
586 | u64 extent_end; | 589 | u64 extent_end; |
587 | u64 start = key->offset; | 590 | u64 start = key->offset; |
@@ -609,7 +612,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
609 | size = btrfs_file_extent_inline_len(eb, slot, item); | 612 | size = btrfs_file_extent_inline_len(eb, slot, item); |
610 | nbytes = btrfs_file_extent_ram_bytes(eb, item); | 613 | nbytes = btrfs_file_extent_ram_bytes(eb, item); |
611 | extent_end = ALIGN(start + size, | 614 | extent_end = ALIGN(start + size, |
612 | root->fs_info->sectorsize); | 615 | fs_info->sectorsize); |
613 | } else { | 616 | } else { |
614 | ret = 0; | 617 | ret = 0; |
615 | goto out; | 618 | goto out; |
@@ -690,7 +693,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
690 | * as the owner of the file extent changed from log tree | 693 | * as the owner of the file extent changed from log tree |
691 | * (doesn't affect qgroup) to fs/file tree(affects qgroup) | 694 | * (doesn't affect qgroup) to fs/file tree(affects qgroup) |
692 | */ | 695 | */ |
693 | ret = btrfs_qgroup_trace_extent(trans, root->fs_info, | 696 | ret = btrfs_qgroup_trace_extent(trans, fs_info, |
694 | btrfs_file_extent_disk_bytenr(eb, item), | 697 | btrfs_file_extent_disk_bytenr(eb, item), |
695 | btrfs_file_extent_disk_num_bytes(eb, item), | 698 | btrfs_file_extent_disk_num_bytes(eb, item), |
696 | GFP_NOFS); | 699 | GFP_NOFS); |
@@ -797,14 +800,12 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
797 | struct btrfs_ordered_sum, | 800 | struct btrfs_ordered_sum, |
798 | list); | 801 | list); |
799 | if (!ret) | 802 | if (!ret) |
800 | ret = btrfs_del_csums(trans, | 803 | ret = btrfs_del_csums(trans, fs_info, |
801 | root->fs_info, | ||
802 | sums->bytenr, | 804 | sums->bytenr, |
803 | sums->len); | 805 | sums->len); |
804 | if (!ret) | 806 | if (!ret) |
805 | ret = btrfs_csum_file_blocks(trans, | 807 | ret = btrfs_csum_file_blocks(trans, |
806 | root->fs_info->csum_root, | 808 | fs_info->csum_root, sums); |
807 | sums); | ||
808 | list_del(&sums->list); | 809 | list_del(&sums->list); |
809 | kfree(sums); | 810 | kfree(sums); |
810 | } | 811 | } |
@@ -2408,6 +2409,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, | |||
2408 | struct btrfs_path *path, int *level, | 2409 | struct btrfs_path *path, int *level, |
2409 | struct walk_control *wc) | 2410 | struct walk_control *wc) |
2410 | { | 2411 | { |
2412 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
2411 | u64 root_owner; | 2413 | u64 root_owner; |
2412 | u64 bytenr; | 2414 | u64 bytenr; |
2413 | u64 ptr_gen; | 2415 | u64 ptr_gen; |
@@ -2433,7 +2435,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, | |||
2433 | 2435 | ||
2434 | bytenr = btrfs_node_blockptr(cur, path->slots[*level]); | 2436 | bytenr = btrfs_node_blockptr(cur, path->slots[*level]); |
2435 | ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]); | 2437 | ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]); |
2436 | blocksize = root->fs_info->nodesize; | 2438 | blocksize = fs_info->nodesize; |
2437 | 2439 | ||
2438 | parent = path->nodes[*level]; | 2440 | parent = path->nodes[*level]; |
2439 | root_owner = btrfs_header_owner(parent); | 2441 | root_owner = btrfs_header_owner(parent); |
@@ -2460,8 +2462,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, | |||
2460 | if (trans) { | 2462 | if (trans) { |
2461 | btrfs_tree_lock(next); | 2463 | btrfs_tree_lock(next); |
2462 | btrfs_set_lock_blocking(next); | 2464 | btrfs_set_lock_blocking(next); |
2463 | clean_tree_block(trans, root->fs_info, | 2465 | clean_tree_block(trans, fs_info, next); |
2464 | next); | ||
2465 | btrfs_wait_tree_block_writeback(next); | 2466 | btrfs_wait_tree_block_writeback(next); |
2466 | btrfs_tree_unlock(next); | 2467 | btrfs_tree_unlock(next); |
2467 | } | 2468 | } |
@@ -2506,6 +2507,7 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans, | |||
2506 | struct btrfs_path *path, int *level, | 2507 | struct btrfs_path *path, int *level, |
2507 | struct walk_control *wc) | 2508 | struct walk_control *wc) |
2508 | { | 2509 | { |
2510 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
2509 | u64 root_owner; | 2511 | u64 root_owner; |
2510 | int i; | 2512 | int i; |
2511 | int slot; | 2513 | int slot; |
@@ -2539,8 +2541,7 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans, | |||
2539 | if (trans) { | 2541 | if (trans) { |
2540 | btrfs_tree_lock(next); | 2542 | btrfs_tree_lock(next); |
2541 | btrfs_set_lock_blocking(next); | 2543 | btrfs_set_lock_blocking(next); |
2542 | clean_tree_block(trans, root->fs_info, | 2544 | clean_tree_block(trans, fs_info, next); |
2543 | next); | ||
2544 | btrfs_wait_tree_block_writeback(next); | 2545 | btrfs_wait_tree_block_writeback(next); |
2545 | btrfs_tree_unlock(next); | 2546 | btrfs_tree_unlock(next); |
2546 | } | 2547 | } |
@@ -2642,14 +2643,15 @@ out: | |||
2642 | static int update_log_root(struct btrfs_trans_handle *trans, | 2643 | static int update_log_root(struct btrfs_trans_handle *trans, |
2643 | struct btrfs_root *log) | 2644 | struct btrfs_root *log) |
2644 | { | 2645 | { |
2646 | struct btrfs_fs_info *fs_info = log->fs_info; | ||
2645 | int ret; | 2647 | int ret; |
2646 | 2648 | ||
2647 | if (log->log_transid == 1) { | 2649 | if (log->log_transid == 1) { |
2648 | /* insert root item on the first sync */ | 2650 | /* insert root item on the first sync */ |
2649 | ret = btrfs_insert_root(trans, log->fs_info->log_root_tree, | 2651 | ret = btrfs_insert_root(trans, fs_info->log_root_tree, |
2650 | &log->root_key, &log->root_item); | 2652 | &log->root_key, &log->root_item); |
2651 | } else { | 2653 | } else { |
2652 | ret = btrfs_update_root(trans, log->fs_info->log_root_tree, | 2654 | ret = btrfs_update_root(trans, fs_info->log_root_tree, |
2653 | &log->root_key, &log->root_item); | 2655 | &log->root_key, &log->root_item); |
2654 | } | 2656 | } |
2655 | return ret; | 2657 | return ret; |
@@ -2743,8 +2745,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2743 | int index2; | 2745 | int index2; |
2744 | int mark; | 2746 | int mark; |
2745 | int ret; | 2747 | int ret; |
2748 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
2746 | struct btrfs_root *log = root->log_root; | 2749 | struct btrfs_root *log = root->log_root; |
2747 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; | 2750 | struct btrfs_root *log_root_tree = fs_info->log_root_tree; |
2748 | int log_transid = 0; | 2751 | int log_transid = 0; |
2749 | struct btrfs_log_ctx root_log_ctx; | 2752 | struct btrfs_log_ctx root_log_ctx; |
2750 | struct blk_plug plug; | 2753 | struct blk_plug plug; |
@@ -2772,7 +2775,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2772 | while (1) { | 2775 | while (1) { |
2773 | int batch = atomic_read(&root->log_batch); | 2776 | int batch = atomic_read(&root->log_batch); |
2774 | /* when we're on an ssd, just kick the log commit out */ | 2777 | /* when we're on an ssd, just kick the log commit out */ |
2775 | if (!btrfs_test_opt(root->fs_info, SSD) && | 2778 | if (!btrfs_test_opt(fs_info, SSD) && |
2776 | test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) { | 2779 | test_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state)) { |
2777 | mutex_unlock(&root->log_mutex); | 2780 | mutex_unlock(&root->log_mutex); |
2778 | schedule_timeout_uninterruptible(1); | 2781 | schedule_timeout_uninterruptible(1); |
@@ -2784,7 +2787,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2784 | } | 2787 | } |
2785 | 2788 | ||
2786 | /* bail out if we need to do a full commit */ | 2789 | /* bail out if we need to do a full commit */ |
2787 | if (btrfs_need_log_full_commit(root->fs_info, trans)) { | 2790 | if (btrfs_need_log_full_commit(fs_info, trans)) { |
2788 | ret = -EAGAIN; | 2791 | ret = -EAGAIN; |
2789 | btrfs_free_logged_extents(log, log_transid); | 2792 | btrfs_free_logged_extents(log, log_transid); |
2790 | mutex_unlock(&root->log_mutex); | 2793 | mutex_unlock(&root->log_mutex); |
@@ -2805,7 +2808,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2805 | blk_finish_plug(&plug); | 2808 | blk_finish_plug(&plug); |
2806 | btrfs_abort_transaction(trans, ret); | 2809 | btrfs_abort_transaction(trans, ret); |
2807 | btrfs_free_logged_extents(log, log_transid); | 2810 | btrfs_free_logged_extents(log, log_transid); |
2808 | btrfs_set_log_full_commit(root->fs_info, trans); | 2811 | btrfs_set_log_full_commit(fs_info, trans); |
2809 | mutex_unlock(&root->log_mutex); | 2812 | mutex_unlock(&root->log_mutex); |
2810 | goto out; | 2813 | goto out; |
2811 | } | 2814 | } |
@@ -2850,7 +2853,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2850 | list_del_init(&root_log_ctx.list); | 2853 | list_del_init(&root_log_ctx.list); |
2851 | 2854 | ||
2852 | blk_finish_plug(&plug); | 2855 | blk_finish_plug(&plug); |
2853 | btrfs_set_log_full_commit(root->fs_info, trans); | 2856 | btrfs_set_log_full_commit(fs_info, trans); |
2854 | 2857 | ||
2855 | if (ret != -ENOSPC) { | 2858 | if (ret != -ENOSPC) { |
2856 | btrfs_abort_transaction(trans, ret); | 2859 | btrfs_abort_transaction(trans, ret); |
@@ -2899,7 +2902,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2899 | * now that we've moved on to the tree of log tree roots, | 2902 | * now that we've moved on to the tree of log tree roots, |
2900 | * check the full commit flag again | 2903 | * check the full commit flag again |
2901 | */ | 2904 | */ |
2902 | if (btrfs_need_log_full_commit(root->fs_info, trans)) { | 2905 | if (btrfs_need_log_full_commit(fs_info, trans)) { |
2903 | blk_finish_plug(&plug); | 2906 | blk_finish_plug(&plug); |
2904 | btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); | 2907 | btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); |
2905 | btrfs_free_logged_extents(log, log_transid); | 2908 | btrfs_free_logged_extents(log, log_transid); |
@@ -2913,7 +2916,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2913 | EXTENT_DIRTY | EXTENT_NEW); | 2916 | EXTENT_DIRTY | EXTENT_NEW); |
2914 | blk_finish_plug(&plug); | 2917 | blk_finish_plug(&plug); |
2915 | if (ret) { | 2918 | if (ret) { |
2916 | btrfs_set_log_full_commit(root->fs_info, trans); | 2919 | btrfs_set_log_full_commit(fs_info, trans); |
2917 | btrfs_abort_transaction(trans, ret); | 2920 | btrfs_abort_transaction(trans, ret); |
2918 | btrfs_free_logged_extents(log, log_transid); | 2921 | btrfs_free_logged_extents(log, log_transid); |
2919 | mutex_unlock(&log_root_tree->log_mutex); | 2922 | mutex_unlock(&log_root_tree->log_mutex); |
@@ -2925,17 +2928,17 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2925 | &log_root_tree->dirty_log_pages, | 2928 | &log_root_tree->dirty_log_pages, |
2926 | EXTENT_NEW | EXTENT_DIRTY); | 2929 | EXTENT_NEW | EXTENT_DIRTY); |
2927 | if (ret) { | 2930 | if (ret) { |
2928 | btrfs_set_log_full_commit(root->fs_info, trans); | 2931 | btrfs_set_log_full_commit(fs_info, trans); |
2929 | btrfs_free_logged_extents(log, log_transid); | 2932 | btrfs_free_logged_extents(log, log_transid); |
2930 | mutex_unlock(&log_root_tree->log_mutex); | 2933 | mutex_unlock(&log_root_tree->log_mutex); |
2931 | goto out_wake_log_root; | 2934 | goto out_wake_log_root; |
2932 | } | 2935 | } |
2933 | btrfs_wait_logged_extents(trans, log, log_transid); | 2936 | btrfs_wait_logged_extents(trans, log, log_transid); |
2934 | 2937 | ||
2935 | btrfs_set_super_log_root(root->fs_info->super_for_commit, | 2938 | btrfs_set_super_log_root(fs_info->super_for_commit, |
2936 | log_root_tree->node->start); | 2939 | log_root_tree->node->start); |
2937 | btrfs_set_super_log_root_level(root->fs_info->super_for_commit, | 2940 | btrfs_set_super_log_root_level(fs_info->super_for_commit, |
2938 | btrfs_header_level(log_root_tree->node)); | 2941 | btrfs_header_level(log_root_tree->node)); |
2939 | 2942 | ||
2940 | log_root_tree->log_transid++; | 2943 | log_root_tree->log_transid++; |
2941 | mutex_unlock(&log_root_tree->log_mutex); | 2944 | mutex_unlock(&log_root_tree->log_mutex); |
@@ -2947,9 +2950,9 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2947 | * the running transaction open, so a full commit can't hop | 2950 | * the running transaction open, so a full commit can't hop |
2948 | * in and cause problems either. | 2951 | * in and cause problems either. |
2949 | */ | 2952 | */ |
2950 | ret = write_ctree_super(trans, root->fs_info->tree_root, 1); | 2953 | ret = write_ctree_super(trans, fs_info->tree_root, 1); |
2951 | if (ret) { | 2954 | if (ret) { |
2952 | btrfs_set_log_full_commit(root->fs_info, trans); | 2955 | btrfs_set_log_full_commit(fs_info, trans); |
2953 | btrfs_abort_transaction(trans, ret); | 2956 | btrfs_abort_transaction(trans, ret); |
2954 | goto out_wake_log_root; | 2957 | goto out_wake_log_root; |
2955 | } | 2958 | } |
@@ -3183,6 +3186,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, | |||
3183 | const char *name, int name_len, | 3186 | const char *name, int name_len, |
3184 | struct inode *inode, u64 dirid) | 3187 | struct inode *inode, u64 dirid) |
3185 | { | 3188 | { |
3189 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
3186 | struct btrfs_root *log; | 3190 | struct btrfs_root *log; |
3187 | u64 index; | 3191 | u64 index; |
3188 | int ret; | 3192 | int ret; |
@@ -3200,7 +3204,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, | |||
3200 | dirid, &index); | 3204 | dirid, &index); |
3201 | mutex_unlock(&BTRFS_I(inode)->log_mutex); | 3205 | mutex_unlock(&BTRFS_I(inode)->log_mutex); |
3202 | if (ret == -ENOSPC) { | 3206 | if (ret == -ENOSPC) { |
3203 | btrfs_set_log_full_commit(root->fs_info, trans); | 3207 | btrfs_set_log_full_commit(fs_info, trans); |
3204 | ret = 0; | 3208 | ret = 0; |
3205 | } else if (ret < 0 && ret != -ENOENT) | 3209 | } else if (ret < 0 && ret != -ENOENT) |
3206 | btrfs_abort_transaction(trans, ret); | 3210 | btrfs_abort_transaction(trans, ret); |
@@ -3607,6 +3611,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, | |||
3607 | int start_slot, int nr, int inode_only, | 3611 | int start_slot, int nr, int inode_only, |
3608 | u64 logged_isize) | 3612 | u64 logged_isize) |
3609 | { | 3613 | { |
3614 | struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); | ||
3610 | unsigned long src_offset; | 3615 | unsigned long src_offset; |
3611 | unsigned long dst_offset; | 3616 | unsigned long dst_offset; |
3612 | struct btrfs_root *log = BTRFS_I(inode)->root->log_root; | 3617 | struct btrfs_root *log = BTRFS_I(inode)->root->log_root; |
@@ -3717,7 +3722,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, | |||
3717 | } | 3722 | } |
3718 | 3723 | ||
3719 | ret = btrfs_lookup_csums_range( | 3724 | ret = btrfs_lookup_csums_range( |
3720 | log->fs_info->csum_root, | 3725 | fs_info->csum_root, |
3721 | ds + cs, ds + cs + cl - 1, | 3726 | ds + cs, ds + cs + cl - 1, |
3722 | &ordered_sums, 0); | 3727 | &ordered_sums, 0); |
3723 | if (ret) { | 3728 | if (ret) { |
@@ -3790,7 +3795,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, | |||
3790 | src_path->slots[0], | 3795 | src_path->slots[0], |
3791 | extent); | 3796 | extent); |
3792 | *last_extent = ALIGN(key.offset + len, | 3797 | *last_extent = ALIGN(key.offset + len, |
3793 | log->fs_info->sectorsize); | 3798 | fs_info->sectorsize); |
3794 | } else { | 3799 | } else { |
3795 | len = btrfs_file_extent_num_bytes(src, extent); | 3800 | len = btrfs_file_extent_num_bytes(src, extent); |
3796 | *last_extent = key.offset + len; | 3801 | *last_extent = key.offset + len; |
@@ -3854,7 +3859,7 @@ fill_holes: | |||
3854 | BTRFS_FILE_EXTENT_INLINE) { | 3859 | BTRFS_FILE_EXTENT_INLINE) { |
3855 | len = btrfs_file_extent_inline_len(src, i, extent); | 3860 | len = btrfs_file_extent_inline_len(src, i, extent); |
3856 | extent_end = ALIGN(key.offset + len, | 3861 | extent_end = ALIGN(key.offset + len, |
3857 | log->fs_info->sectorsize); | 3862 | fs_info->sectorsize); |
3858 | } else { | 3863 | } else { |
3859 | len = btrfs_file_extent_num_bytes(src, extent); | 3864 | len = btrfs_file_extent_num_bytes(src, extent); |
3860 | extent_end = key.offset + len; | 3865 | extent_end = key.offset + len; |
@@ -3904,6 +3909,7 @@ static int wait_ordered_extents(struct btrfs_trans_handle *trans, | |||
3904 | const struct list_head *logged_list, | 3909 | const struct list_head *logged_list, |
3905 | bool *ordered_io_error) | 3910 | bool *ordered_io_error) |
3906 | { | 3911 | { |
3912 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
3907 | struct btrfs_ordered_extent *ordered; | 3913 | struct btrfs_ordered_extent *ordered; |
3908 | struct btrfs_root *log = root->log_root; | 3914 | struct btrfs_root *log = root->log_root; |
3909 | u64 mod_start = em->mod_start; | 3915 | u64 mod_start = em->mod_start; |
@@ -4020,7 +4026,7 @@ static int wait_ordered_extents(struct btrfs_trans_handle *trans, | |||
4020 | } | 4026 | } |
4021 | 4027 | ||
4022 | /* block start is already adjusted for the file extent offset. */ | 4028 | /* block start is already adjusted for the file extent offset. */ |
4023 | ret = btrfs_lookup_csums_range(log->fs_info->csum_root, | 4029 | ret = btrfs_lookup_csums_range(fs_info->csum_root, |
4024 | em->block_start + csum_offset, | 4030 | em->block_start + csum_offset, |
4025 | em->block_start + csum_offset + | 4031 | em->block_start + csum_offset + |
4026 | csum_len - 1, &ordered_sums, 0); | 4032 | csum_len - 1, &ordered_sums, 0); |
@@ -4363,6 +4369,7 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans, | |||
4363 | struct inode *inode, | 4369 | struct inode *inode, |
4364 | struct btrfs_path *path) | 4370 | struct btrfs_path *path) |
4365 | { | 4371 | { |
4372 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
4366 | int ret; | 4373 | int ret; |
4367 | struct btrfs_key key; | 4374 | struct btrfs_key key; |
4368 | u64 hole_start; | 4375 | u64 hole_start; |
@@ -4372,7 +4379,7 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans, | |||
4372 | const u64 ino = btrfs_ino(inode); | 4379 | const u64 ino = btrfs_ino(inode); |
4373 | const u64 i_size = i_size_read(inode); | 4380 | const u64 i_size = i_size_read(inode); |
4374 | 4381 | ||
4375 | if (!btrfs_fs_incompat(root->fs_info, NO_HOLES)) | 4382 | if (!btrfs_fs_incompat(fs_info, NO_HOLES)) |
4376 | return 0; | 4383 | return 0; |
4377 | 4384 | ||
4378 | key.objectid = ino; | 4385 | key.objectid = ino; |
@@ -4429,7 +4436,7 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans, | |||
4429 | if (hole_size == 0) | 4436 | if (hole_size == 0) |
4430 | return 0; | 4437 | return 0; |
4431 | 4438 | ||
4432 | hole_size = ALIGN(hole_size, root->fs_info->sectorsize); | 4439 | hole_size = ALIGN(hole_size, fs_info->sectorsize); |
4433 | ret = btrfs_insert_file_extent(trans, log, ino, hole_start, 0, 0, | 4440 | ret = btrfs_insert_file_extent(trans, log, ino, hole_start, 0, 0, |
4434 | hole_size, 0, hole_size, 0, 0, 0); | 4441 | hole_size, 0, hole_size, 0, 0, 0); |
4435 | return ret; | 4442 | return ret; |
@@ -4587,6 +4594,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, | |||
4587 | const loff_t end, | 4594 | const loff_t end, |
4588 | struct btrfs_log_ctx *ctx) | 4595 | struct btrfs_log_ctx *ctx) |
4589 | { | 4596 | { |
4597 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
4590 | struct btrfs_path *path; | 4598 | struct btrfs_path *path; |
4591 | struct btrfs_path *dst_path; | 4599 | struct btrfs_path *dst_path; |
4592 | struct btrfs_key min_key; | 4600 | struct btrfs_key min_key; |
@@ -4639,7 +4647,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, | |||
4639 | * fixup (create temporary BTRFS_TREE_LOG_FIXUP_OBJECTID items). | 4647 | * fixup (create temporary BTRFS_TREE_LOG_FIXUP_OBJECTID items). |
4640 | */ | 4648 | */ |
4641 | if (S_ISDIR(inode->i_mode) || | 4649 | if (S_ISDIR(inode->i_mode) || |
4642 | BTRFS_I(inode)->generation > root->fs_info->last_trans_committed) | 4650 | BTRFS_I(inode)->generation > fs_info->last_trans_committed) |
4643 | ret = btrfs_commit_inode_delayed_items(trans, inode); | 4651 | ret = btrfs_commit_inode_delayed_items(trans, inode); |
4644 | else | 4652 | else |
4645 | ret = btrfs_commit_inode_delayed_inode(inode); | 4653 | ret = btrfs_commit_inode_delayed_inode(inode); |
@@ -4776,7 +4784,7 @@ again: | |||
4776 | inode_key.objectid = other_ino; | 4784 | inode_key.objectid = other_ino; |
4777 | inode_key.type = BTRFS_INODE_ITEM_KEY; | 4785 | inode_key.type = BTRFS_INODE_ITEM_KEY; |
4778 | inode_key.offset = 0; | 4786 | inode_key.offset = 0; |
4779 | other_inode = btrfs_iget(root->fs_info->sb, | 4787 | other_inode = btrfs_iget(fs_info->sb, |
4780 | &inode_key, root, | 4788 | &inode_key, root, |
4781 | NULL); | 4789 | NULL); |
4782 | /* | 4790 | /* |
@@ -5140,6 +5148,7 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans, | |||
5140 | struct inode *start_inode, | 5148 | struct inode *start_inode, |
5141 | struct btrfs_log_ctx *ctx) | 5149 | struct btrfs_log_ctx *ctx) |
5142 | { | 5150 | { |
5151 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
5143 | struct btrfs_root *log = root->log_root; | 5152 | struct btrfs_root *log = root->log_root; |
5144 | struct btrfs_path *path; | 5153 | struct btrfs_path *path; |
5145 | LIST_HEAD(dir_list); | 5154 | LIST_HEAD(dir_list); |
@@ -5207,8 +5216,7 @@ process_leaf: | |||
5207 | if (di_key.type == BTRFS_ROOT_ITEM_KEY) | 5216 | if (di_key.type == BTRFS_ROOT_ITEM_KEY) |
5208 | continue; | 5217 | continue; |
5209 | 5218 | ||
5210 | di_inode = btrfs_iget(root->fs_info->sb, &di_key, | 5219 | di_inode = btrfs_iget(fs_info->sb, &di_key, root, NULL); |
5211 | root, NULL); | ||
5212 | if (IS_ERR(di_inode)) { | 5220 | if (IS_ERR(di_inode)) { |
5213 | ret = PTR_ERR(di_inode); | 5221 | ret = PTR_ERR(di_inode); |
5214 | goto next_dir_inode; | 5222 | goto next_dir_inode; |
@@ -5270,6 +5278,7 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans, | |||
5270 | struct inode *inode, | 5278 | struct inode *inode, |
5271 | struct btrfs_log_ctx *ctx) | 5279 | struct btrfs_log_ctx *ctx) |
5272 | { | 5280 | { |
5281 | struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); | ||
5273 | int ret; | 5282 | int ret; |
5274 | struct btrfs_path *path; | 5283 | struct btrfs_path *path; |
5275 | struct btrfs_key key; | 5284 | struct btrfs_key key; |
@@ -5334,7 +5343,7 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans, | |||
5334 | cur_offset = item_size; | 5343 | cur_offset = item_size; |
5335 | } | 5344 | } |
5336 | 5345 | ||
5337 | dir_inode = btrfs_iget(root->fs_info->sb, &inode_key, | 5346 | dir_inode = btrfs_iget(fs_info->sb, &inode_key, |
5338 | root, NULL); | 5347 | root, NULL); |
5339 | /* If parent inode was deleted, skip it. */ | 5348 | /* If parent inode was deleted, skip it. */ |
5340 | if (IS_ERR(dir_inode)) | 5349 | if (IS_ERR(dir_inode)) |
@@ -5376,17 +5385,18 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
5376 | int exists_only, | 5385 | int exists_only, |
5377 | struct btrfs_log_ctx *ctx) | 5386 | struct btrfs_log_ctx *ctx) |
5378 | { | 5387 | { |
5388 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
5379 | int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL; | 5389 | int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL; |
5380 | struct super_block *sb; | 5390 | struct super_block *sb; |
5381 | struct dentry *old_parent = NULL; | 5391 | struct dentry *old_parent = NULL; |
5382 | int ret = 0; | 5392 | int ret = 0; |
5383 | u64 last_committed = root->fs_info->last_trans_committed; | 5393 | u64 last_committed = fs_info->last_trans_committed; |
5384 | bool log_dentries = false; | 5394 | bool log_dentries = false; |
5385 | struct inode *orig_inode = inode; | 5395 | struct inode *orig_inode = inode; |
5386 | 5396 | ||
5387 | sb = inode->i_sb; | 5397 | sb = inode->i_sb; |
5388 | 5398 | ||
5389 | if (btrfs_test_opt(root->fs_info, NOTREELOG)) { | 5399 | if (btrfs_test_opt(fs_info, NOTREELOG)) { |
5390 | ret = 1; | 5400 | ret = 1; |
5391 | goto end_no_trans; | 5401 | goto end_no_trans; |
5392 | } | 5402 | } |
@@ -5395,8 +5405,8 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
5395 | * The prev transaction commit doesn't complete, we need do | 5405 | * The prev transaction commit doesn't complete, we need do |
5396 | * full commit by ourselves. | 5406 | * full commit by ourselves. |
5397 | */ | 5407 | */ |
5398 | if (root->fs_info->last_trans_log_full_commit > | 5408 | if (fs_info->last_trans_log_full_commit > |
5399 | root->fs_info->last_trans_committed) { | 5409 | fs_info->last_trans_committed) { |
5400 | ret = 1; | 5410 | ret = 1; |
5401 | goto end_no_trans; | 5411 | goto end_no_trans; |
5402 | } | 5412 | } |
@@ -5517,7 +5527,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
5517 | end_trans: | 5527 | end_trans: |
5518 | dput(old_parent); | 5528 | dput(old_parent); |
5519 | if (ret < 0) { | 5529 | if (ret < 0) { |
5520 | btrfs_set_log_full_commit(root->fs_info, trans); | 5530 | btrfs_set_log_full_commit(fs_info, trans); |
5521 | ret = 1; | 5531 | ret = 1; |
5522 | } | 5532 | } |
5523 | 5533 | ||
@@ -5788,6 +5798,7 @@ int btrfs_log_new_name(struct btrfs_trans_handle *trans, | |||
5788 | struct inode *inode, struct inode *old_dir, | 5798 | struct inode *inode, struct inode *old_dir, |
5789 | struct dentry *parent) | 5799 | struct dentry *parent) |
5790 | { | 5800 | { |
5801 | struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); | ||
5791 | struct btrfs_root * root = BTRFS_I(inode)->root; | 5802 | struct btrfs_root * root = BTRFS_I(inode)->root; |
5792 | 5803 | ||
5793 | /* | 5804 | /* |
@@ -5802,9 +5813,9 @@ int btrfs_log_new_name(struct btrfs_trans_handle *trans, | |||
5802 | * from hasn't been logged, we don't need to log it | 5813 | * from hasn't been logged, we don't need to log it |
5803 | */ | 5814 | */ |
5804 | if (BTRFS_I(inode)->logged_trans <= | 5815 | if (BTRFS_I(inode)->logged_trans <= |
5805 | root->fs_info->last_trans_committed && | 5816 | fs_info->last_trans_committed && |
5806 | (!old_dir || BTRFS_I(old_dir)->logged_trans <= | 5817 | (!old_dir || BTRFS_I(old_dir)->logged_trans <= |
5807 | root->fs_info->last_trans_committed)) | 5818 | fs_info->last_trans_committed)) |
5808 | return 0; | 5819 | return 0; |
5809 | 5820 | ||
5810 | return btrfs_log_inode_parent(trans, root, inode, parent, 0, | 5821 | return btrfs_log_inode_parent(trans, root, inode, parent, 0, |