Move some code out of ctree.c and ctree.h
Subsystems (2)
David Sterba
maintainercover Move some code out of ctree.c and ctree.h
The ctree.[ch] files gathered a lot of unrelated code over the years, it should be moved to appropriate files. This series does the easiest part, nes I'll split the incompate/feature handling and messages.
David Sterba (7):
btrfs: move cond_wake_up functions out of ctree
btrfs: move math functions to misc.h
btrfs: move private raid56 definitions from ctree.h
btrfs: rename and export read_node_slot
btrfs: move functions for tree compare to send.c
btrfs: move struct io_ctl to free-space-cache.h
btrfs: move dev_stats helpers to volumes.c
fs/btrfs/block-group.c | 2 +- fs/btrfs/block-group.h | 2 + fs/btrfs/block-rsv.c | 2 +- fs/btrfs/compression.c | 1 + fs/btrfs/ctree.c | 382 +----------------------------------- fs/btrfs/ctree.h | 93 +-------- fs/btrfs/delayed-inode.c | 1 + fs/btrfs/dev-replace.c | 1 + fs/btrfs/extent-tree.c | 2 +- fs/btrfs/free-space-cache.h | 14 +- fs/btrfs/inode.c | 1 + fs/btrfs/locking.c | 1 + fs/btrfs/math.h | 28 --- fs/btrfs/misc.h | 50 +++++ fs/btrfs/ordered-data.c | 1 + fs/btrfs/raid56.c | 16 ++ fs/btrfs/send.c | 374 +++++++++++++++++++++++++++++++++++ fs/btrfs/space-info.c | 2 +- fs/btrfs/transaction.c | 1 + fs/btrfs/tree-log.c | 1 + fs/btrfs/volumes.c | 25 ++- fs/btrfs/zstd.c | 1 + 22 files changed, 505 insertions(+), 496 deletions(-) delete mode 100644 fs/btrfs/math.h create mode 100644 fs/btrfs/misc.h
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH 1/7 btrfs: move cond_wake_up functions out of ctree
The file ctree.h serves as a header for everything and has become quite bloated. Split some helpers that are generic and create a new file that should be the catch-all for code that's not btrfs-specific.
--- fs/btrfs/compression.c | 1 + fs/btrfs/ctree.h | 22 ---------------------- fs/btrfs/delayed-inode.c | 1 + fs/btrfs/dev-replace.c | 1 + fs/btrfs/extent-tree.c | 1 + fs/btrfs/inode.c | 1 + fs/btrfs/locking.c | 1 + fs/btrfs/misc.h | 33 +++++++++++++++++++++++++++++++++ fs/btrfs/ordered-data.c | 1 + fs/btrfs/transaction.c | 1 + fs/btrfs/tree-log.c | 1 + fs/btrfs/zstd.c | 1 + 12 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 fs/btrfs/misc.h
fs/btrfs/compression.c +1 -0
@@ -18,6 +18,7 @@#include <linux/sched/mm.h> #include <linux/log2.h> #include <crypto/hash.h> +#include "misc.h" #include "ctree.h" #include "disk-io.h" #include "transaction.h"
fs/btrfs/ctree.h +0 -22
@@ -3516,26 +3516,4 @@ static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) }#endif -static inline void cond_wake_up (struct wait_queue_head *wq) -{ -/* -* This implies a full smp_mb barrier, see comments for -* waitqueue_active why. -*/ -if (wq_has_sleeper (wq)) -wake_up (wq); -} - -static inline void cond_wake_up_nomb (struct wait_queue_head *wq) -{ -/* -* Special case for conditional wakeup where the barrier required for -* waitqueue_active is implied by some of the preceding code. Eg. one -* of such atomic operations (atomic_dec_and_return, ...), or a -* unlock/lock sequence, etc. -*/ -if (waitqueue_active (wq)) -wake_up (wq); -} -#endif
fs/btrfs/delayed-inode.c +1 -0
@@ -6,6 +6,7 @@#include <linux/slab.h> #include <linux/iversion.h> +#include "misc.h" #include "delayed-inode.h" #include "disk-io.h" #include "transaction.h"
fs/btrfs/dev-replace.c +1 -0
@@ -9,6 +9,7 @@#include <linux/blkdev.h> #include <linux/kthread.h> #include <linux/math64.h> +#include "misc.h" #include "ctree.h" #include "extent_map.h" #include "disk-io.h"
fs/btrfs/extent-tree.c +1 -0
@@ -16,6 +16,7 @@#include <linux/percpu_counter.h> #include <linux/lockdep.h> #include <linux/crc32c.h> +#include "misc.h" #include "tree-log.h" #include "disk-io.h" #include "print-tree.h"
fs/btrfs/inode.c +1 -0
@@ -30,6 +30,7 @@#include <linux/swap.h> #include <linux/sched/mm.h> #include <asm/unaligned.h> +#include "misc.h" #include "ctree.h" #include "disk-io.h" #include "transaction.h"
fs/btrfs/locking.c +1 -0
@@ -8,6 +8,7 @@#include <linux/spinlock.h> #include <linux/page-flags.h> #include <asm/bug.h> +#include "misc.h" #include "ctree.h" #include "extent_io.h" #include "locking.h"
fs/btrfs/misc.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BTRFS_MISC_H +#define BTRFS_MISC_H + +#include <linux/sched.h> +#include <linux/wait.h> + +#define in_range (b, first, len) ((b) >= (first) && (b) < (first) + (len)) + +static inline void cond_wake_up (struct wait_queue_head *wq) +{ +/* +* This implies a full smp_mb barrier, see comments for +* waitqueue_active why. +*/ +if (wq_has_sleeper (wq)) +wake_up (wq); +} + +static inline void cond_wake_up_nomb (struct wait_queue_head *wq) +{ +/* +* Special case for conditional wakeup where the barrier required for +* waitqueue_active is implied by some of the preceding code. Eg. one +* of such atomic operations (atomic_dec_and_return, ...), or a +* unlock/lock sequence, etc. +*/ +if (waitqueue_active (wq)) +wake_up (wq); +} + +#endif
fs/btrfs/ordered-data.c +1 -0
@@ -7,6 +7,7 @@#include <linux/blkdev.h> #include <linux/writeback.h> #include <linux/sched/mm.h> +#include "misc.h" #include "ctree.h" #include "transaction.h" #include "btrfs_inode.h"
fs/btrfs/transaction.c +1 -0
@@ -10,6 +10,7 @@#include <linux/pagemap.h> #include <linux/blkdev.h> #include <linux/uuid.h> +#include "misc.h" #include "ctree.h" #include "disk-io.h" #include "transaction.h"
fs/btrfs/tree-log.c +1 -0
@@ -8,6 +8,7 @@#include <linux/blkdev.h> #include <linux/list_sort.h> #include <linux/iversion.h> +#include "misc.h" #include "ctree.h" #include "tree-log.h" #include "disk-io.h"
fs/btrfs/zstd.c +1 -0
@@ -17,6 +17,7 @@#include <linux/sched.h> #include <linux/slab.h> #include <linux/zstd.h> +#include "misc.h" #include "compression.h" #include "ctree.h"
Signature · 1 line
2.22.0
Re: [PATCH 1/7] btrfs: move cond_wake_up functions out of ctree
Looks good,
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
David Sterba
maintainerPATCH 2/7 btrfs: move math functions to misc.h
In reply to David Sterba--- fs/btrfs/block-group.c | 2 +- fs/btrfs/block-rsv.c | 2 +- fs/btrfs/extent-tree.c | 1 - fs/btrfs/math.h | 28 ---------------------------- fs/btrfs/misc.h | 17 +++++++++++++++++ fs/btrfs/space-info.c | 2 +- fs/btrfs/volumes.c | 2 +- 7 files changed, 21 insertions(+), 33 deletions(-) delete mode 100644 fs/btrfs/math.h
fs/btrfs/block-group.c +1 -1
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#include "misc.h" #include "ctree.h" #include "block-group.h" #include "space-info.h"
@@ -13,7 +14,6 @@#include "sysfs.h" #include "tree-log.h" #include "delalloc-space.h" -#include "math.h" /* * Return target flags in extended format or 0 if restripe for this chunk_type
fs/btrfs/block-rsv.c +1 -1
@@ -1,9 +1,9 @@// SPDX-License-Identifier: GPL-2.0 +#include "misc.h" #include "ctree.h" #include "block-rsv.h" #include "space-info.h" -#include "math.h" #include "transaction.h" static u64 block_rsv_release_bytes(struct btrfs_fs_info *fs_info,
fs/btrfs/extent-tree.c +0 -1
@@ -25,7 +25,6 @@#include "locking.h" #include "free-space-cache.h" #include "free-space-tree.h" -#include "math.h" #include "sysfs.h" #include "qgroup.h" #include "ref-verify.h"
fs/btrfs/math.h deleted +0 -28
@@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Copyright (C) 2012 Fujitsu. All rights reserved. -* Written by Miao Xie <[email protected]> -*/ - -#ifndef BTRFS_MATH_H -#define BTRFS_MATH_H - -#include <asm/div64.h> - -static inline u64 div_factor (u64 num,int factor) -{ -if (factor ==10 ) -return num; - num *= factor; -return div_u64 (num,10 ); -} - -static inline u64 div_factor_fine (u64 num,int factor) -{ -if (factor ==100 ) -return num; - num *= factor; -return div_u64 (num,100 ); -} - -#endif
fs/btrfs/misc.h +17 -0
@@ -5,6 +5,7 @@#include <linux/sched.h> #include <linux/wait.h> +#include <asm/div64.h> #define in_range (b, first, len) ((b) >= (first) && (b) < (first) + (len))
@@ -30,4 +31,20 @@ static inline void cond_wake_up_nomb(struct wait_queue_head *wq) wake_up(wq); } +static inline u64 div_factor (u64 num,int factor) +{ +if (factor ==10 ) +return num; + num *= factor; +return div_u64 (num,10 ); +} + +static inline u64 div_factor_fine (u64 num,int factor) +{ +if (factor ==100 ) +return num; + num *= factor; +return div_u64 (num,100 ); +} +#endif
fs/btrfs/space-info.c +1 -1
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#include "misc.h" #include "ctree.h" #include "space-info.h" #include "sysfs.h"
@@ -7,7 +8,6 @@#include "free-space-cache.h" #include "ordered-data.h" #include "transaction.h" -#include "math.h" #include "block-group.h" u64 btrfs_space_info_used(struct btrfs_space_info *s_info,
fs/btrfs/volumes.c +1 -1
@@ -14,6 +14,7 @@#include <linux/semaphore.h> #include <linux/uuid.h> #include <linux/list_sort.h> +#include "misc.h" #include "ctree.h" #include "extent_map.h" #include "disk-io.h"
@@ -24,7 +25,6 @@#include "async-thread.h" #include "check-integrity.h" #include "rcu-string.h" -#include "math.h" #include "dev-replace.h" #include "sysfs.h" #include "tree-checker.h"
Signature · 1 line
2.22.0
Re: [PATCH 2/7] btrfs: move math functions to misc.h
fs/btrfs/math.h line 5
Quoted 7 lines
fs/btrfs/math.h deleted +0
-5@@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Copyright (C) 2012 Fujitsu. All rights reserved. -* Written by Miao Xie <[email protected]> -*/
This copyright note will get lost with this patch.
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
David Sterba
maintainerPATCH 3/7 btrfs: move private raid56 definitions from ctree.h
In reply to David Sterba--- fs/btrfs/ctree.h | 16 ---------------- fs/btrfs/raid56.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-)
fs/btrfs/ctree.h +0 -16
@@ -470,22 +470,6 @@ enum btrfs_orphan_cleanup_state { ORPHAN_CLEANUP_DONE = 2, }; -/* used by the raid56 code to lock stripes for read/modify/write */ -struct btrfs_stripe_hash { -struct list_head hash_list; -spinlock_t lock; -}; - -/* used by the raid56 code to lock stripes for read/modify/write */ -struct btrfs_stripe_hash_table { -struct list_head stripe_cache; -spinlock_t cache_lock; -int cache_size; -struct btrfs_stripe_hash table[]; -}; - -#define BTRFS_STRIPE_HASH_TABLE_BITS 11 -void btrfs_init_async_reclaim_work (struct work_struct *work);/* fs_info */
fs/btrfs/raid56.c +16 -0
@@ -35,6 +35,22 @@#define RBIO_CACHE_SIZE 1024 +#define BTRFS_STRIPE_HASH_TABLE_BITS 11 + +/* Used by the raid56 code to lock stripes for read/modify/write */ +struct btrfs_stripe_hash { +struct list_head hash_list; +spinlock_t lock; +}; + +/* Used by the raid56 code to lock stripes for read/modify/write */ +struct btrfs_stripe_hash_table { +struct list_head stripe_cache; +spinlock_t cache_lock; +int cache_size; +struct btrfs_stripe_hash table[]; +}; +enum btrfs_rbio_ops {BTRFS_RBIO_WRITE ,BTRFS_RBIO_READ_REBUILD ,
Signature · 1 line
2.22.0
Re: [PATCH 3/7] btrfs: move private raid56 definitions from ctree.h
Looks good,
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
David Sterba
maintainerPATCH 4/7 btrfs: rename and export read_node_slot
In reply to David SterbaPreparatory work for code that will be moved out of ctree and uses this function.
--- fs/btrfs/ctree.c | 22 +++++++++++----------- fs/btrfs/ctree.h | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-)
fs/btrfs/ctree.c +11 -11
@@ -1792,8 +1792,8 @@ static void root_sub_used(struct btrfs_root *root, u32 size)/* given a node and slot number, this reads the blocks it points to. The * extent buffer is returned with a reference taken (but unlocked). */ -static noinline struct extent_buffer *read_node_slot( -struct extent_buffer *parent,int slot) +struct extent_buffer *btrfs_read_node_slot (struct extent_buffer *parent, +int slot) {int level =btrfs_header_level (parent);struct extent_buffer *eb;
@@ -1862,7 +1862,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,return 0 ;/* promote the child to a root */ - child =read_node_slot (mid,0 ); + child =btrfs_read_node_slot (mid,0 );if (IS_ERR (child)) { ret =PTR_ERR (child);btrfs_handle_fs_error (fs_info, ret,NULL );
@@ -1902,7 +1902,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, BTRFS_NODEPTRS_PER_BLOCK(fs_info) / 4)return 0 ; - left =read_node_slot (parent, pslot -1 ); + left =btrfs_read_node_slot (parent, pslot -1 );if (IS_ERR (left)) left =NULL ;
@@ -1917,7 +1917,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, } } - right =read_node_slot (parent, pslot +1 ); + right =btrfs_read_node_slot (parent, pslot +1 );if (IS_ERR (right)) right =NULL ;
@@ -2077,7 +2077,7 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,if (!parent)return 1 ; - left =read_node_slot (parent, pslot -1 ); + left =btrfs_read_node_slot (parent, pslot -1 );if (IS_ERR (left)) left =NULL ;
@@ -2129,7 +2129,7 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,btrfs_tree_unlock (left);free_extent_buffer (left); } - right =read_node_slot (parent, pslot +1 ); + right =btrfs_read_node_slot (parent, pslot +1 );if (IS_ERR (right)) right =NULL ;
@@ -3783,7 +3783,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_rootbtrfs_assert_tree_locked (path->nodes[1 ]); - right =read_node_slot (upper, slot +1 ); + right =btrfs_read_node_slot (upper, slot +1 );/* * slot + 1 is not valid or we fail to read the right node, * no big deal, just return.
@@ -4017,7 +4017,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_rootbtrfs_assert_tree_locked (path->nodes[1 ]); - left =read_node_slot (path->nodes[1 ], slot -1 ); + left =btrfs_read_node_slot (path->nodes[1 ], slot -1 );/* * slot - 1 is not valid or we fail to read the left node, * no big deal, just return.
@@ -5224,7 +5224,7 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, goto out; }btrfs_set_path_blocking (path); - cur =read_node_slot (cur, slot); + cur =btrfs_read_node_slot (cur, slot);if (IS_ERR (cur)) { ret =PTR_ERR (cur); goto out;
@@ -5251,7 +5251,7 @@ static int tree_move_down(struct btrfs_path *path, int *level)struct extent_buffer *eb;BUG_ON (*level ==0 ); - eb =read_node_slot (path->nodes[*level], path->slots[*level]); + eb =btrfs_read_node_slot (path->nodes[*level], path->slots[*level]);if (IS_ERR (eb))return PTR_ERR (eb);
fs/btrfs/ctree.h +3 -0
@@ -2586,6 +2586,9 @@ int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,int btrfs_search_forward (struct btrfs_root *root,struct btrfs_key *min_key,struct btrfs_path *path,u64 min_trans); +struct extent_buffer *btrfs_read_node_slot (struct extent_buffer *parent, +int slot); +enum btrfs_compare_tree_result {BTRFS_COMPARE_TREE_NEW ,BTRFS_COMPARE_TREE_DELETED ,
Signature · 1 line
2.22.0
Re: [PATCH 4/7] btrfs: rename and export read_node_slot
Looks good,
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
David Sterba
maintainerPATCH 5/7 btrfs: move functions for tree compare to send.c
In reply to David SterbaSend is the only user of tree_compare, we can move it there along with the other helpers and definitions.
--- fs/btrfs/ctree.c | 362 --------------------------------------------- fs/btrfs/ctree.h | 14 -- fs/btrfs/send.c | 374 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 374 insertions(+), 376 deletions(-)
fs/btrfs/ctree.c +0 -362
@@ -5246,368 +5246,6 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,return ret; } -static int tree_move_down (struct btrfs_path *path,int *level) -{ -struct extent_buffer *eb; - -BUG_ON (*level ==0 ); - eb =btrfs_read_node_slot (path->nodes[*level], path->slots[*level]); -if (IS_ERR (eb)) -return PTR_ERR (eb); - - path->nodes[*level -1 ] = eb; - path->slots[*level -1 ] =0 ; - (*level)--; -return 0 ; -} - -static int tree_move_next_or_upnext (struct btrfs_path *path, -int *level,int root_level) -{ -int ret =0 ; -int nritems; - nritems =btrfs_header_nritems (path->nodes[*level]); - - path->slots[*level]++; - -while (path->slots[*level] >= nritems) { -if (*level == root_level) -return -1 ; - -/* move upnext */ - path->slots[*level] =0 ; -free_extent_buffer (path->nodes[*level]); - path->nodes[*level] =NULL ; - (*level)++; - path->slots[*level]++; - - nritems =btrfs_header_nritems (path->nodes[*level]); - ret =1 ; - } -return ret; -} - -/* -* Returns 1 if it had to move up and next. 0 is returned if it moved only next -* or down. -*/ -static int tree_advance (struct btrfs_path *path, -int *level,int root_level, -int allow_down, -struct btrfs_key *key) -{ -int ret; - -if (*level ==0 || !allow_down) { - ret =tree_move_next_or_upnext (path, level, root_level); - }else { - ret =tree_move_down (path, level); - } -if (ret >=0 ) { -if (*level ==0 ) -btrfs_item_key_to_cpu (path->nodes[*level], key, - path->slots[*level]); -else -btrfs_node_key_to_cpu (path->nodes[*level], key, - path->slots[*level]); - } -return ret; -} - -static int tree_compare_item (struct btrfs_path *left_path, -struct btrfs_path *right_path, -char *tmp_buf) -{ -int cmp; -int len1, len2; -unsigned long off1, off2; - - len1 =btrfs_item_size_nr (left_path->nodes[0 ], left_path->slots[0 ]); - len2 =btrfs_item_size_nr (right_path->nodes[0 ], right_path->slots[0 ]); -if (len1 != len2) -return 1 ; - - off1 =btrfs_item_ptr_offset (left_path->nodes[0 ], left_path->slots[0 ]); - off2 =btrfs_item_ptr_offset (right_path->nodes[0 ], - right_path->slots[0 ]); - -read_extent_buffer (left_path->nodes[0 ], tmp_buf, off1, len1); - - cmp =memcmp_extent_buffer (right_path->nodes[0 ], tmp_buf, off2, len1); -if (cmp) -return 1 ; -return 0 ; -} - -#define ADVANCE 1 -#define ADVANCE_ONLY_NEXT -1 - -/* -* This function compares two trees and calls the provided callback for -* every changed/new/deleted item it finds. -* If shared tree blocks are encountered, whole subtrees are skipped, making -* the compare pretty fast on snapshotted subvolumes. -* -* This currently works on commit roots only. As commit roots are read only, -* we don't do any locking. The commit roots are protected with transactions. -* Transactions are ended and rejoined when a commit is tried in between. -* -* This function checks for modifications done to the trees while comparing. -* If it detects a change, it aborts immediately. -*/ -int btrfs_compare_trees (struct btrfs_root *left_root, -struct btrfs_root *right_root, -btrfs_changed_cb_t changed_cb,void *ctx) -{ -struct btrfs_fs_info *fs_info = left_root->fs_info; -int ret; -int cmp; -struct btrfs_path *left_path =NULL ; -struct btrfs_path *right_path =NULL ; -struct btrfs_key left_key; -struct btrfs_key right_key; -char *tmp_buf =NULL ; -int left_root_level; -int right_root_level; -int left_level; -int right_level; -int left_end_reached; -int right_end_reached; -int advance_left; -int advance_right; -u64 left_blockptr; -u64 right_blockptr; -u64 left_gen; -u64 right_gen; - - left_path =btrfs_alloc_path (); -if (!left_path) { - ret = -ENOMEM ; - goto out; - } - right_path =btrfs_alloc_path (); -if (!right_path) { - ret = -ENOMEM ; - goto out; - } - - tmp_buf =kvmalloc (fs_info->nodesize,GFP_KERNEL ); -if (!tmp_buf) { - ret = -ENOMEM ; - goto out; - } - - left_path->search_commit_root =1 ; - left_path->skip_locking =1 ; - right_path->search_commit_root =1 ; - right_path->skip_locking =1 ; - -/* -* Strategy: Go to the first items of both trees. Then do -* -* If both trees are at level 0 -* Compare keys of current items -* If left < right treat left item as new, advance left tree -* and repeat -* If left > right treat right item as deleted, advance right tree -* and repeat -* If left == right do deep compare of items, treat as changed if -* needed, advance both trees and repeat -* If both trees are at the same level but not at level 0 -* Compare keys of current nodes/leafs -* If left < right advance left tree and repeat -* If left > right advance right tree and repeat -* If left == right compare blockptrs of the next nodes/leafs -* If they match advance both trees but stay at the same level -* and repeat -* If they don't match advance both trees while allowing to go -* deeper and repeat -* If tree levels are different -* Advance the tree that needs it and repeat -* -* Advancing a tree means: -* If we are at level 0, try to go to the next slot. If that's not -* possible, go one level up and repeat. Stop when we found a level -* where we could go to the next slot. We may at this point be on a -* node or a leaf. -* -* If we are not at level 0 and not on shared tree blocks, go one -* level deeper. -* -* If we are not at level 0 and on shared tree blocks, go one slot to -* the right if possible or go up and right. -*/ - -down_read (&fs_info->commit_root_sem); - left_level =btrfs_header_level (left_root->commit_root); - left_root_level = left_level; - left_path->nodes[left_level] = -btrfs_clone_extent_buffer (left_root->commit_root); -if (!left_path->nodes[left_level]) { -up_read (&fs_info->commit_root_sem); - ret = -ENOMEM ; - goto out; - } - - right_level =btrfs_header_level (right_root->commit_root); - right_root_level = right_level; - right_path->nodes[right_level] = -btrfs_clone_extent_buffer (right_root->commit_root); -if (!right_path->nodes[right_level]) { -up_read (&fs_info->commit_root_sem); - ret = -ENOMEM ; - goto out; - } -up_read (&fs_info->commit_root_sem); - -if (left_level ==0 ) -btrfs_item_key_to_cpu (left_path->nodes[left_level], - &left_key, left_path->slots[left_level]); -else -btrfs_node_key_to_cpu (left_path->nodes[left_level], - &left_key, left_path->slots[left_level]); -if (right_level ==0 ) -btrfs_item_key_to_cpu (right_path->nodes[right_level], - &right_key, right_path->slots[right_level]); -else -btrfs_node_key_to_cpu (right_path->nodes[right_level], - &right_key, right_path->slots[right_level]); - - left_end_reached = right_end_reached =0 ; - advance_left = advance_right =0 ; - -while (1 ) { -if (advance_left && !left_end_reached) { - ret =tree_advance (left_path, &left_level, - left_root_level, - advance_left !=ADVANCE_ONLY_NEXT , - &left_key); -if (ret ==-1 ) - left_end_reached =ADVANCE ; -else if (ret <0 ) - goto out; - advance_left =0 ; - } -if (advance_right && !right_end_reached) { - ret =tree_advance (right_path, &right_level, - right_root_level, - advance_right !=ADVANCE_ONLY_NEXT , - &right_key); -if (ret ==-1 ) - right_end_reached =ADVANCE ; -else if (ret <0 ) - goto out; - advance_right =0 ; - } - -if (left_end_reached && right_end_reached) { - ret =0 ; - goto out; - }else if (left_end_reached) { -if (right_level ==0 ) { - ret =changed_cb (left_path, right_path, - &right_key, -BTRFS_COMPARE_TREE_DELETED , - ctx); -if (ret <0 ) - goto out; - } - advance_right =ADVANCE ; -continue ; - }else if (right_end_reached) { -if (left_level ==0 ) { - ret =changed_cb (left_path, right_path, - &left_key, -BTRFS_COMPARE_TREE_NEW , - ctx); -if (ret <0 ) - goto out; - } - advance_left =ADVANCE ; -continue ; - } - -if (left_level ==0 && right_level ==0 ) { - cmp =btrfs_comp_cpu_keys (&left_key, &right_key); -if (cmp <0 ) { - ret =changed_cb (left_path, right_path, - &left_key, -BTRFS_COMPARE_TREE_NEW , - ctx); -if (ret <0 ) - goto out; - advance_left =ADVANCE ; - }else if (cmp >0 ) { - ret =changed_cb (left_path, right_path, - &right_key, -BTRFS_COMPARE_TREE_DELETED , - ctx); -if (ret <0 ) - goto out; - advance_right =ADVANCE ; - }else { -enum btrfs_compare_tree_result result; - -WARN_ON (!extent_buffer_uptodate (left_path->nodes[0 ])); - ret =tree_compare_item (left_path, right_path, - tmp_buf); -if (ret) - result =BTRFS_COMPARE_TREE_CHANGED ; -else - result =BTRFS_COMPARE_TREE_SAME ; - ret =changed_cb (left_path, right_path, - &left_key, result, ctx); -if (ret <0 ) - goto out; - advance_left =ADVANCE ; - advance_right =ADVANCE ; - } - }else if (left_level == right_level) { - cmp =btrfs_comp_cpu_keys (&left_key, &right_key); -if (cmp <0 ) { - advance_left =ADVANCE ; - }else if (cmp >0 ) { - advance_right =ADVANCE ; - }else { - left_blockptr =btrfs_node_blockptr ( - left_path->nodes[left_level], - left_path->slots[left_level]); - right_blockptr =btrfs_node_blockptr ( - right_path->nodes[right_level], - right_path->slots[right_level]); - left_gen =btrfs_node_ptr_generation ( - left_path->nodes[left_level], - left_path->slots[left_level]); - right_gen =btrfs_node_ptr_generation ( - right_path->nodes[right_level], - right_path->slots[right_level]); -if (left_blockptr == right_blockptr && - left_gen == right_gen) { -/* -* As we're on a shared block, don't -* allow to go deeper. -*/ - advance_left =ADVANCE_ONLY_NEXT ; - advance_right =ADVANCE_ONLY_NEXT ; - }else { - advance_left =ADVANCE ; - advance_right =ADVANCE ; - } - } - }else if (left_level < right_level) { - advance_right =ADVANCE ; - }else { - advance_left =ADVANCE ; - } - } - -out: -btrfs_free_path (left_path); -btrfs_free_path (right_path); -kvfree (tmp_buf); -return ret; -} -/* * this is similar to btrfs_next_leaf, but does not try to preserve * and fixup the path. It looks for and returns the next key in the
fs/btrfs/ctree.h +0 -14
@@ -2589,20 +2589,6 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,struct extent_buffer *btrfs_read_node_slot (struct extent_buffer *parent,int slot); -enum btrfs_compare_tree_result { -BTRFS_COMPARE_TREE_NEW , -BTRFS_COMPARE_TREE_DELETED , -BTRFS_COMPARE_TREE_CHANGED , -BTRFS_COMPARE_TREE_SAME , -}; -typedef int (*btrfs_changed_cb_t )(struct btrfs_path *left_path, -struct btrfs_path *right_path, -struct btrfs_key *key, -enum btrfs_compare_tree_result result, -void *ctx); -int btrfs_compare_trees (struct btrfs_root *left_root, -struct btrfs_root *right_root, -btrfs_changed_cb_t cb,void *ctx); int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, struct extent_buffer *parent, int parent_slot,
fs/btrfs/send.c +374 -0
386 lines not on this page · raw message
Signature · 1 line
2.22.0
Re: [PATCH 5/7] btrfs: move functions for tree compare to send.c
Looks good,
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
David Sterba
maintainerPATCH 6/7 btrfs: move struct io_ctl to free-space-cache.h
In reply to David SterbaThe io_ctl structure is used for free space management, and used only by the v1 space cache code, but unfortunatlly the full definition is required by block-group.h so it can't be moved to free-space-cache.c without additional changes.
--- fs/btrfs/block-group.h | 2 ++ fs/btrfs/ctree.h | 14 -------------- fs/btrfs/free-space-cache.h | 14 +++++++++++++- 3 files changed, 15 insertions(+), 15 deletions(-)
fs/btrfs/block-group.h +2 -0
@@ -3,6 +3,8 @@#ifndef BTRFS_BLOCK_GROUP_H #define BTRFS_BLOCK_GROUP_H +#include "free-space-cache.h" +enum btrfs_disk_cache_state {BTRFS_DC_WRITTEN , BTRFS_DC_ERROR,
fs/btrfs/ctree.h +0 -14
@@ -433,20 +433,6 @@ enum btrfs_caching_type { BTRFS_CACHE_ERROR, }; -struct btrfs_io_ctl { -void *cur, *orig; -struct page *page; -struct page **pages; -struct btrfs_fs_info *fs_info; -struct inode *inode; -unsigned long size; -int index; -int num_pages; -int entries; -int bitmaps; -unsigned check_crcs:1 ; -}; -/* * Tree to record all locked full stripes of a RAID5/6 block group */
fs/btrfs/free-space-cache.h +13 -1
@@ -36,7 +36,19 @@ struct btrfs_free_space_op { struct btrfs_free_space *info); }; -struct btrfs_io_ctl ; +struct btrfs_io_ctl { +void *cur, *orig; +struct page *page; +struct page **pages; +struct btrfs_fs_info *fs_info; +struct inode *inode; +unsigned long size; +int index; +int num_pages; +int entries; +int bitmaps; +unsigned check_crcs:1 ; +}; struct inode *lookup_free_space_inode( struct btrfs_block_group_cache *block_group,
Signature · 1 line
2.22.0
Re: [PATCH 6/7] btrfs: move struct io_ctl to free-space-cache.h
Looks good,
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
David Sterba
maintainerPATCH 7/7 btrfs: move dev_stats helpers to volumes.c
In reply to David SterbaThe other dev stats functions are already there and the helpers are not used by anything else.
--- fs/btrfs/ctree.h | 24 ------------------------ fs/btrfs/volumes.c | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 24 deletions(-)
fs/btrfs/ctree.h +0 -24
@@ -2257,30 +2257,6 @@ static inline u32 btrfs_file_extent_inline_item_len(return btrfs_item_size (eb, e) -BTRFS_FILE_EXTENT_INLINE_DATA_START ; } -/* btrfs_dev_stats_item */ -static inline u64 btrfs_dev_stats_value (const struct extent_buffer *eb, -const struct btrfs_dev_stats_item *ptr, -int index) -{ -u64 val; - -read_extent_buffer (eb, &val, - offsetof(struct btrfs_dev_stats_item , values) + - ((unsigned long )ptr) + (index *sizeof (u64)), -sizeof (val)); -return val; -} - -static inline void btrfs_set_dev_stats_value (struct extent_buffer *eb, -struct btrfs_dev_stats_item *ptr, -int index,u64 val) -{ -write_extent_buffer (eb, &val, - offsetof(struct btrfs_dev_stats_item , values) + - ((unsigned long )ptr) + (index *sizeof (u64)), -sizeof (val)); -} -/* btrfs_qgroup_status_item */ BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, generation,64 );
fs/btrfs/volumes.c +23 -0
@@ -7276,6 +7276,29 @@ void btrfs_init_devices_late(struct btrfs_fs_info *fs_info) } } +static u64 btrfs_dev_stats_value (const struct extent_buffer *eb, +const struct btrfs_dev_stats_item *ptr, +int index) +{ +u64 val; + +read_extent_buffer (eb, &val, + offsetof(struct btrfs_dev_stats_item , values) + + ((unsigned long )ptr) + (index *sizeof (u64)), +sizeof (val)); +return val; +} + +static void btrfs_set_dev_stats_value (struct extent_buffer *eb, +struct btrfs_dev_stats_item *ptr, +int index,u64 val) +{ +write_extent_buffer (eb, &val, + offsetof(struct btrfs_dev_stats_item , values) + + ((unsigned long )ptr) + (index *sizeof (u64)), +sizeof (val)); +} +int btrfs_init_dev_stats (struct btrfs_fs_info *fs_info) {struct btrfs_key key;
Signature · 1 line
2.22.0
Re: [PATCH 7/7] btrfs: move dev_stats helpers to volumes.c
Looks good,
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850