* [PATCH 01/32] btrfs-progs: Remove deprecated leafsize usage
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 02/32] btrfs-progs: Introduce sectorsize nodesize and stripesize members for btrfs_fs_info Qu Wenruo
` (31 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Leafsize is deprecated for a long time, and kernel has already updated
ctree.h to rename sb->leafsize to sb->__unused_leafsize.
This patch will remove normal users of leafsize:
1) Remove leafsize member from btrfs_root structure
Now only root->nodesize and root->sectorisze.
No longer root->leafsize.
2) Remove @leafsize parameter from btrfs_setup_root() function
Since no root->leafsize, no need for @leafsize parameter.
The remaining user of leafsize will be:
1) btrfs inspect-internal dump-super
Reformat the "leafsize" output to "leafsize (deprecated)" and
use le32_to_cpu() to do the cast manually.
2) mkfs
We still need to set sb->__unused_leafsize to nodesize.
Do the manual cast too.
3) convert
Same as mkfs, these two superblock setup should be merged later
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
chunk-recover.c | 4 +---
cmds-inspect-dump-super.c | 4 ++--
convert/common.c | 2 +-
ctree.h | 18 +-----------------
disk-io.c | 28 +++++++++++-----------------
disk-io.h | 2 +-
mkfs/common.c | 2 +-
7 files changed, 18 insertions(+), 42 deletions(-)
diff --git a/chunk-recover.c b/chunk-recover.c
index 0dc8a430..cf8b3184 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1450,7 +1450,6 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
struct extent_buffer *eb;
u32 sectorsize;
u32 nodesize;
- u32 leafsize;
u32 stripesize;
int ret;
@@ -1482,11 +1481,10 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
goto out_devices;
nodesize = btrfs_super_nodesize(disk_super);
- leafsize = btrfs_super_leafsize(disk_super);
sectorsize = btrfs_super_sectorsize(disk_super);
stripesize = btrfs_super_stripesize(disk_super);
- btrfs_setup_root(nodesize, leafsize, sectorsize, stripesize,
+ btrfs_setup_root(nodesize, sectorsize, stripesize,
fs_info->chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID);
ret = build_device_maps_by_chunk_records(rc, fs_info->chunk_root);
diff --git a/cmds-inspect-dump-super.c b/cmds-inspect-dump-super.c
index 85307e33..98e0270a 100644
--- a/cmds-inspect-dump-super.c
+++ b/cmds-inspect-dump-super.c
@@ -397,8 +397,8 @@ static void dump_superblock(struct btrfs_super_block *sb, int full)
(unsigned long long)btrfs_super_sectorsize(sb));
printf("nodesize\t\t%llu\n",
(unsigned long long)btrfs_super_nodesize(sb));
- printf("leafsize\t\t%llu\n",
- (unsigned long long)btrfs_super_leafsize(sb));
+ printf("leafsize (deprecated)\t\t%u\n",
+ le32_to_cpu(sb->__unused_leafsize));
printf("stripesize\t\t%llu\n",
(unsigned long long)btrfs_super_stripesize(sb));
printf("root_dir\t\t%llu\n",
diff --git a/convert/common.c b/convert/common.c
index 40bf32cf..5411864d 100644
--- a/convert/common.c
+++ b/convert/common.c
@@ -128,7 +128,7 @@ static int setup_temp_super(int fd, struct btrfs_mkfs_config *cfg,
*/
btrfs_set_super_bytes_used(super, 6 * cfg->nodesize);
btrfs_set_super_sectorsize(super, cfg->sectorsize);
- btrfs_set_super_leafsize(super, cfg->nodesize);
+ super->__unused_leafsize = cpu_to_le32(cfg->nodesize);
btrfs_set_super_nodesize(super, cfg->nodesize);
btrfs_set_super_stripesize(super, cfg->stripesize);
btrfs_set_super_csum_type(super, BTRFS_CSUM_TYPE_CRC32);
diff --git a/ctree.h b/ctree.h
index 13cf3b00..c457a8dc 100644
--- a/ctree.h
+++ b/ctree.h
@@ -440,7 +440,7 @@ struct btrfs_super_block {
__le32 sectorsize;
__le32 nodesize;
/* Unused and must be equal to nodesize */
- __le32 leafsize;
+ __le32 __unused_leafsize;
__le32 stripesize;
__le32 sys_chunk_array_size;
__le64 chunk_root_generation;
@@ -1168,9 +1168,6 @@ struct btrfs_root {
/* node allocations are done in nodesize units */
u32 nodesize;
- /* Unused, equal to nodesize */
- u32 leafsize;
-
/* leaf allocations are done in nodesize units */
u32 stripesize;
@@ -2159,8 +2156,6 @@ BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
sectorsize, 32);
BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
nodesize, 32);
-BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
- leafsize, 32);
BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
stripesize, 32);
BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
@@ -2410,17 +2405,6 @@ static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
return btrfs_file_extent_ram_bytes(eb, fi);
}
-/*
- * NOTE: Backward compatibility, do not use.
- * Replacement: read nodesize directly
- */
-__attribute__((deprecated))
-static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
- if (level == 0)
- return root->leafsize;
- return root->nodesize;
-}
-
#define btrfs_fs_incompat(fs_info, opt) \
__btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
diff --git a/disk-io.c b/disk-io.c
index 6aa6d98a..838d5cd4 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -476,7 +476,7 @@ int write_tree_block(struct btrfs_trans_handle *trans,
return write_and_map_eb(root, eb);
}
-void btrfs_setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
+void btrfs_setup_root(u32 nodesize, u32 sectorsize,
u32 stripesize, struct btrfs_root *root,
struct btrfs_fs_info *fs_info, u64 objectid)
{
@@ -484,7 +484,6 @@ void btrfs_setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
root->commit_root = NULL;
root->sectorsize = sectorsize;
root->nodesize = nodesize;
- root->leafsize = leafsize;
root->stripesize = stripesize;
root->ref_cows = 0;
root->track_dirty = 0;
@@ -631,9 +630,8 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
u32 blocksize;
u64 generation;
- btrfs_setup_root(tree_root->nodesize, tree_root->leafsize,
- tree_root->sectorsize, tree_root->stripesize,
- root, fs_info, objectid);
+ btrfs_setup_root(tree_root->nodesize, tree_root->sectorsize,
+ tree_root->stripesize, root, fs_info, objectid);
ret = btrfs_find_last_root(tree_root, objectid,
&root->root_item, &root->root_key);
if (ret)
@@ -667,9 +665,9 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
blocksize = tree_root->nodesize;
- btrfs_setup_root(tree_root->nodesize, tree_root->leafsize,
- tree_root->sectorsize, tree_root->stripesize,
- log_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
+ btrfs_setup_root(tree_root->nodesize, tree_root->sectorsize,
+ tree_root->stripesize, log_root, fs_info,
+ BTRFS_TREE_LOG_OBJECTID);
log_root->node = read_tree_block(tree_root, blocknr,
blocksize,
@@ -731,9 +729,9 @@ struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info,
goto insert;
}
- btrfs_setup_root(tree_root->nodesize, tree_root->leafsize,
- tree_root->sectorsize, tree_root->stripesize,
- root, fs_info, location->objectid);
+ btrfs_setup_root(tree_root->nodesize, tree_root->sectorsize,
+ tree_root->stripesize, root, fs_info,
+ location->objectid);
path = btrfs_alloc_path();
if (!path) {
@@ -1000,19 +998,17 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
struct btrfs_key key;
u32 sectorsize;
u32 nodesize;
- u32 leafsize;
u32 stripesize;
u64 generation;
u32 blocksize;
int ret;
nodesize = btrfs_super_nodesize(sb);
- leafsize = btrfs_super_leafsize(sb);
sectorsize = btrfs_super_sectorsize(sb);
stripesize = btrfs_super_stripesize(sb);
root = fs_info->tree_root;
- btrfs_setup_root(nodesize, leafsize, sectorsize, stripesize,
+ btrfs_setup_root(nodesize, sectorsize, stripesize,
root, fs_info, BTRFS_ROOT_TREE_OBJECTID);
blocksize = root->nodesize;
generation = btrfs_super_generation(sb);
@@ -1194,18 +1190,16 @@ int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info,
struct btrfs_super_block *sb = fs_info->super_copy;
u32 sectorsize;
u32 nodesize;
- u32 leafsize;
u32 blocksize;
u32 stripesize;
u64 generation;
int ret;
nodesize = btrfs_super_nodesize(sb);
- leafsize = btrfs_super_leafsize(sb);
sectorsize = btrfs_super_sectorsize(sb);
stripesize = btrfs_super_stripesize(sb);
- btrfs_setup_root(nodesize, leafsize, sectorsize, stripesize,
+ btrfs_setup_root(nodesize, sectorsize, stripesize,
fs_info->chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID);
ret = btrfs_read_sys_array(fs_info->chunk_root);
diff --git a/disk-io.h b/disk-io.h
index cd4fe929..27dea40a 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -133,7 +133,7 @@ void readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize,
struct extent_buffer* btrfs_find_create_tree_block(
struct btrfs_fs_info *fs_info, u64 bytenr, u32 blocksize);
-void btrfs_setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
+void btrfs_setup_root(u32 nodesize, u32 sectorsize,
u32 stripesize, struct btrfs_root *root,
struct btrfs_fs_info *fs_info, u64 objectid);
int clean_tree_block(struct btrfs_trans_handle *trans,
diff --git a/mkfs/common.c b/mkfs/common.c
index 1e8f26ea..e4785c58 100644
--- a/mkfs/common.c
+++ b/mkfs/common.c
@@ -108,7 +108,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
btrfs_set_super_total_bytes(&super, num_bytes);
btrfs_set_super_bytes_used(&super, 6 * cfg->nodesize);
btrfs_set_super_sectorsize(&super, cfg->sectorsize);
- btrfs_set_super_leafsize(&super, cfg->nodesize);
+ super.__unused_leafsize = cpu_to_le32(cfg->nodesize);
btrfs_set_super_nodesize(&super, cfg->nodesize);
btrfs_set_super_stripesize(&super, cfg->stripesize);
btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 02/32] btrfs-progs: Introduce sectorsize nodesize and stripesize members for btrfs_fs_info
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
2017-05-18 3:38 ` [PATCH 01/32] btrfs-progs: Remove deprecated leafsize usage Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 03/32] btrfs-progs: Refactor block sizes users in disk-io.c Qu Wenruo
` (30 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Just like what we do in kernel, since we will not support different
leaf/node/stripe size per tree, there is no need to store these block
sizes in btrfs_root.
This patch will introduce these block size members into btrfs_fs_info
structure, allowing us to convert such usage in later patches.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
chunk-recover.c | 3 +++
ctree.h | 4 ++++
disk-io.c | 3 +++
3 files changed, 10 insertions(+)
diff --git a/chunk-recover.c b/chunk-recover.c
index cf8b3184..1a880038 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1475,6 +1475,9 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
}
memcpy(fs_info->fsid, &disk_super->fsid, BTRFS_FSID_SIZE);
+ fs_info->sectorsize = btrfs_super_sectorsize(disk_super);
+ fs_info->nodesize = btrfs_super_nodesize(disk_super);
+ fs_info->stripesize = btrfs_super_stripesize(disk_super);
ret = btrfs_check_fs_compatibility(disk_super, OPEN_CTREE_WRITES);
if (ret)
diff --git a/ctree.h b/ctree.h
index c457a8dc..78956a4f 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1147,6 +1147,10 @@ struct btrfs_fs_info {
struct cache_tree *fsck_extent_cache;
struct cache_tree *corrupt_blocks;
+ /* Cached block sizes */
+ u32 nodesize;
+ u32 sectorsize;
+ u32 stripesize;
};
/*
diff --git a/disk-io.c b/disk-io.c
index 838d5cd4..bfdac5ab 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1327,6 +1327,9 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
}
memcpy(fs_info->fsid, &disk_super->fsid, BTRFS_FSID_SIZE);
+ fs_info->sectorsize = btrfs_super_sectorsize(disk_super);
+ fs_info->nodesize = btrfs_super_nodesize(disk_super);
+ fs_info->stripesize = btrfs_super_stripesize(disk_super);
ret = btrfs_check_fs_compatibility(fs_info->super_copy, flags);
if (ret)
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 03/32] btrfs-progs: Refactor block sizes users in disk-io.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
2017-05-18 3:38 ` [PATCH 01/32] btrfs-progs: Remove deprecated leafsize usage Qu Wenruo
2017-05-18 3:38 ` [PATCH 02/32] btrfs-progs: Introduce sectorsize nodesize and stripesize members for btrfs_fs_info Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 04/32] btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.c Qu Wenruo
` (29 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Since we have cached block sizes in fs_info, there is no need to specify
these sizes in btrfs_setup_root() function.
And refactor all root->sector/node/stripesize users in disk-io.c.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
chunk-recover.c | 11 ++--------
disk-io.c | 64 ++++++++++++++++++++-------------------------------------
disk-io.h | 5 ++---
3 files changed, 26 insertions(+), 54 deletions(-)
diff --git a/chunk-recover.c b/chunk-recover.c
index 1a880038..96b939a3 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1448,9 +1448,6 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
struct btrfs_fs_info *fs_info;
struct btrfs_super_block *disk_super;
struct extent_buffer *eb;
- u32 sectorsize;
- u32 nodesize;
- u32 stripesize;
int ret;
fs_info = btrfs_new_fs_info(1, BTRFS_SUPER_INFO_OFFSET);
@@ -1483,12 +1480,8 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
if (ret)
goto out_devices;
- nodesize = btrfs_super_nodesize(disk_super);
- sectorsize = btrfs_super_sectorsize(disk_super);
- stripesize = btrfs_super_stripesize(disk_super);
-
- btrfs_setup_root(nodesize, sectorsize, stripesize,
- fs_info->chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID);
+ btrfs_setup_root(fs_info->chunk_root, fs_info,
+ BTRFS_CHUNK_TREE_OBJECTID);
ret = build_device_maps_by_chunk_records(rc, fs_info->chunk_root);
if (ret)
diff --git a/disk-io.c b/disk-io.c
index bfdac5ab..89e35c92 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -56,7 +56,7 @@ static int check_tree_block(struct btrfs_fs_info *fs_info,
{
struct btrfs_fs_devices *fs_devices;
- u32 nodesize = btrfs_super_nodesize(fs_info->super_copy);
+ u32 nodesize = fs_info->nodesize;
int ret = BTRFS_BAD_FSID;
if (buf->start != btrfs_header_bytenr(buf))
@@ -313,8 +313,8 @@ struct extent_buffer* read_tree_block_fs_info(
int ret;
struct extent_buffer *eb;
u64 best_transid = 0;
- u32 sectorsize = btrfs_super_sectorsize(fs_info->super_copy);
- u32 nodesize = btrfs_super_nodesize(fs_info->super_copy);
+ u32 sectorsize = fs_info->sectorsize;
+ u32 nodesize = fs_info->nodesize;
int mirror_num = 0;
int good_mirror = 0;
int num_copies;
@@ -476,15 +476,14 @@ int write_tree_block(struct btrfs_trans_handle *trans,
return write_and_map_eb(root, eb);
}
-void btrfs_setup_root(u32 nodesize, u32 sectorsize,
- u32 stripesize, struct btrfs_root *root,
- struct btrfs_fs_info *fs_info, u64 objectid)
+void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
+ u64 objectid)
{
root->node = NULL;
root->commit_root = NULL;
- root->sectorsize = sectorsize;
- root->nodesize = nodesize;
- root->stripesize = stripesize;
+ root->sectorsize = fs_info->sectorsize;
+ root->nodesize = fs_info->nodesize;
+ root->stripesize = fs_info->stripesize;
root->ref_cows = 0;
root->track_dirty = 0;
@@ -630,14 +629,13 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
u32 blocksize;
u64 generation;
- btrfs_setup_root(tree_root->nodesize, tree_root->sectorsize,
- tree_root->stripesize, root, fs_info, objectid);
+ btrfs_setup_root(root, fs_info, objectid);
ret = btrfs_find_last_root(tree_root, objectid,
&root->root_item, &root->root_key);
if (ret)
return ret;
- blocksize = root->nodesize;
+ blocksize = fs_info->nodesize;
generation = btrfs_root_generation(&root->root_item);
root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
blocksize, generation);
@@ -663,10 +661,9 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
return 0;
}
- blocksize = tree_root->nodesize;
+ blocksize = fs_info->nodesize;
- btrfs_setup_root(tree_root->nodesize, tree_root->sectorsize,
- tree_root->stripesize, log_root, fs_info,
+ btrfs_setup_root(log_root, fs_info,
BTRFS_TREE_LOG_OBJECTID);
log_root->node = read_tree_block(tree_root, blocknr,
@@ -729,8 +726,7 @@ struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info,
goto insert;
}
- btrfs_setup_root(tree_root->nodesize, tree_root->sectorsize,
- tree_root->stripesize, root, fs_info,
+ btrfs_setup_root(root, fs_info,
location->objectid);
path = btrfs_alloc_path();
@@ -758,7 +754,7 @@ out:
return ERR_PTR(ret);
}
generation = btrfs_root_generation(&root->root_item);
- blocksize = root->nodesize;
+ blocksize = fs_info->nodesize;
root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
blocksize, generation);
if (!extent_buffer_uptodate(root->node)) {
@@ -996,21 +992,13 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
struct btrfs_super_block *sb = fs_info->super_copy;
struct btrfs_root *root;
struct btrfs_key key;
- u32 sectorsize;
- u32 nodesize;
- u32 stripesize;
u64 generation;
u32 blocksize;
int ret;
- nodesize = btrfs_super_nodesize(sb);
- sectorsize = btrfs_super_sectorsize(sb);
- stripesize = btrfs_super_stripesize(sb);
-
root = fs_info->tree_root;
- btrfs_setup_root(nodesize, sectorsize, stripesize,
- root, fs_info, BTRFS_ROOT_TREE_OBJECTID);
- blocksize = root->nodesize;
+ btrfs_setup_root(root, fs_info, BTRFS_ROOT_TREE_OBJECTID);
+ blocksize = fs_info->nodesize;
generation = btrfs_super_generation(sb);
if (!root_tree_bytenr && !(flags & OPEN_CTREE_BACKUP_ROOT)) {
@@ -1188,31 +1176,22 @@ int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info,
u64 chunk_root_bytenr)
{
struct btrfs_super_block *sb = fs_info->super_copy;
- u32 sectorsize;
- u32 nodesize;
- u32 blocksize;
- u32 stripesize;
u64 generation;
int ret;
- nodesize = btrfs_super_nodesize(sb);
- sectorsize = btrfs_super_sectorsize(sb);
- stripesize = btrfs_super_stripesize(sb);
-
- btrfs_setup_root(nodesize, sectorsize, stripesize,
- fs_info->chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID);
+ btrfs_setup_root(fs_info->chunk_root, fs_info,
+ BTRFS_CHUNK_TREE_OBJECTID);
ret = btrfs_read_sys_array(fs_info->chunk_root);
if (ret)
return ret;
- blocksize = fs_info->chunk_root->nodesize;
generation = btrfs_super_chunk_root_generation(sb);
if (chunk_root_bytenr && !IS_ALIGNED(chunk_root_bytenr,
- btrfs_super_sectorsize(sb))) {
+ fs_info->sectorsize)) {
warning("chunk_root_bytenr %llu is unaligned to %u, ignore it",
- chunk_root_bytenr, btrfs_super_sectorsize(sb));
+ chunk_root_bytenr, fs_info->sectorsize);
chunk_root_bytenr = 0;
}
@@ -1223,7 +1202,8 @@ int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info,
fs_info->chunk_root->node = read_tree_block(fs_info->chunk_root,
chunk_root_bytenr,
- blocksize, generation);
+ fs_info->nodesize,
+ generation);
if (!extent_buffer_uptodate(fs_info->chunk_root->node)) {
if (fs_info->ignore_chunk_tree_error) {
warning("cannot read chunk root, continue anyway");
diff --git a/disk-io.h b/disk-io.h
index 27dea40a..b4d02275 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -133,9 +133,8 @@ void readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize,
struct extent_buffer* btrfs_find_create_tree_block(
struct btrfs_fs_info *fs_info, u64 bytenr, u32 blocksize);
-void btrfs_setup_root(u32 nodesize, u32 sectorsize,
- u32 stripesize, struct btrfs_root *root,
- struct btrfs_fs_info *fs_info, u64 objectid);
+void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
+ u64 objectid);
int clean_tree_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct extent_buffer *buf);
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 04/32] btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (2 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 03/32] btrfs-progs: Refactor block sizes users in disk-io.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 05/32] btrfs-progs: Refactor block sizes users in ctree.c and ctree.h Qu Wenruo
` (28 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Convert root->sectorsize/nodesize users in btrfs-corrupt-block.
This provides the basis to further refactor incorrect btrfs_root
parameter to btrfs_fs_info parameter.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
btrfs-corrupt-block.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 71b4d771..20a4c1df 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -169,7 +169,7 @@ static int corrupt_keys_in_block(struct btrfs_root *root, u64 bytenr)
{
struct extent_buffer *eb;
- eb = read_tree_block(root, bytenr, root->nodesize, 0);
+ eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb))
return -EIO;;
@@ -297,7 +297,7 @@ static void btrfs_corrupt_extent_tree(struct btrfs_trans_handle *trans,
struct extent_buffer *next;
next = read_tree_block(root, btrfs_node_blockptr(eb, i),
- root->nodesize,
+ root->fs_info->nodesize,
btrfs_node_ptr_generation(eb, i));
if (!extent_buffer_uptodate(next))
continue;
@@ -764,7 +764,7 @@ static int corrupt_metadata_block(struct btrfs_root *root, u64 block,
return -EINVAL;
}
- eb = read_tree_block(root, block, root->nodesize, 0);
+ eb = read_tree_block(root, block, root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb)) {
fprintf(stderr, "Couldn't read in tree block %s\n", field);
return -EINVAL;
@@ -1352,10 +1352,9 @@ int main(int argc, char **argv)
print_usage(1);
if (bytes == 0)
- bytes = root->sectorsize;
+ bytes = root->fs_info->sectorsize;
- bytes = (bytes + root->sectorsize - 1) / root->sectorsize;
- bytes *= root->sectorsize;
+ bytes = round_up(bytes, root->fs_info->sectorsize);
while (bytes > 0) {
if (corrupt_block_keys) {
@@ -1364,7 +1363,7 @@ int main(int argc, char **argv)
struct extent_buffer *eb;
eb = btrfs_find_create_tree_block(root->fs_info,
- logical, root->sectorsize);
+ logical, root->fs_info->sectorsize);
if (!eb) {
error(
"not enough memory to allocate extent buffer for bytenr %llu",
@@ -1373,12 +1372,12 @@ int main(int argc, char **argv)
goto out_close;
}
- debug_corrupt_block(eb, root, logical, root->sectorsize,
- copy);
+ debug_corrupt_block(eb, root, logical,
+ root->fs_info->sectorsize, copy);
free_extent_buffer(eb);
}
- logical += root->sectorsize;
- bytes -= root->sectorsize;
+ logical += root->fs_info->sectorsize;
+ bytes -= root->fs_info->sectorsize;
}
return ret;
out_close:
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 05/32] btrfs-progs: Refactor block sizes users in ctree.c and ctree.h
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (3 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 04/32] btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 06/32] btrfs-progs: Refactor block sizes users in btrfs-map-logical.c Qu Wenruo
` (27 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
ctree.c | 10 +++++-----
ctree.h | 4 ++--
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/ctree.c b/ctree.c
index 02c71807..266a3cf2 100644
--- a/ctree.c
+++ b/ctree.c
@@ -650,7 +650,7 @@ struct extent_buffer *read_node_slot(struct btrfs_root *root,
return NULL;
return read_tree_block(root, btrfs_node_blockptr(parent, slot),
- root->nodesize,
+ root->fs_info->nodesize,
btrfs_node_ptr_generation(parent, slot));
}
@@ -987,7 +987,7 @@ void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
node = path->nodes[level];
search = btrfs_node_blockptr(node, slot);
- blocksize = root->nodesize;
+ blocksize = root->fs_info->nodesize;
eb = btrfs_find_tree_block(root, search, blocksize);
if (eb) {
free_extent_buffer(eb);
@@ -1420,7 +1420,7 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
else
btrfs_node_key(lower, &lower_key, 0);
- c = btrfs_alloc_free_block(trans, root, root->nodesize,
+ c = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
root->root_key.objectid, &lower_key,
level, root->node->start, 0);
@@ -1543,7 +1543,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
mid = (c_nritems + 1) / 2;
btrfs_node_key(c, &disk_key, mid);
- split = btrfs_alloc_free_block(trans, root, root->nodesize,
+ split = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
root->root_key.objectid,
&disk_key, level, c->start, 0);
if (IS_ERR(split))
@@ -2110,7 +2110,7 @@ again:
else
btrfs_item_key(l, &disk_key, mid);
- right = btrfs_alloc_free_block(trans, root, root->nodesize,
+ right = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
root->root_key.objectid,
&disk_key, 0, l->start, 0);
if (IS_ERR(right)) {
diff --git a/ctree.h b/ctree.h
index 78956a4f..84298c7b 100644
--- a/ctree.h
+++ b/ctree.h
@@ -352,11 +352,11 @@ struct btrfs_header {
u8 level;
} __attribute__ ((__packed__));
-#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
+#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->fs_info->nodesize - \
sizeof(struct btrfs_header)) / \
sizeof(struct btrfs_key_ptr))
#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
-#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize))
+#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->fs_info->nodesize))
#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
sizeof(struct btrfs_item) - \
sizeof(struct btrfs_file_extent_item))
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 06/32] btrfs-progs: Refactor block sizes users in btrfs-map-logical.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (4 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 05/32] btrfs-progs: Refactor block sizes users in ctree.c and ctree.h Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 07/32] btrfs-progs: Refactor block sizes users in chunk-recover.c Qu Wenruo
` (26 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
btrfs-map-logical.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c
index e856b698..e88357fc 100644
--- a/btrfs-map-logical.c
+++ b/btrfs-map-logical.c
@@ -82,7 +82,7 @@ again:
}
logical = key.objectid;
if (key.type == BTRFS_METADATA_ITEM_KEY)
- len = fs_info->tree_root->nodesize;
+ len = fs_info->nodesize;
else
len = key.offset;
@@ -286,7 +286,7 @@ int main(int argc, char **argv)
}
if (bytes == 0)
- bytes = root->nodesize;
+ bytes = root->fs_info->nodesize;
cur_logical = logical;
cur_len = bytes;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 07/32] btrfs-progs: Refactor block sizes users in chunk-recover.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (5 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 06/32] btrfs-progs: Refactor block sizes users in btrfs-map-logical.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 08/32] btrfs-progs: Refactor block sizes users in backref.c Qu Wenruo
` (25 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
chunk-recover.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/chunk-recover.c b/chunk-recover.c
index 96b939a3..08d2f07e 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1070,7 +1070,7 @@ again:
key.type == BTRFS_METADATA_ITEM_KEY) {
old_val = btrfs_super_bytes_used(fs_info->super_copy);
if (key.type == BTRFS_METADATA_ITEM_KEY)
- old_val += root->nodesize;
+ old_val += fs_info->nodesize;
else
old_val += key.offset;
btrfs_set_super_bytes_used(fs_info->super_copy,
@@ -1086,7 +1086,7 @@ again:
if (key.objectid < end) {
if (key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) {
- key.objectid += root->sectorsize;
+ key.objectid += fs_info->sectorsize;
key.type = BTRFS_EXTENT_ITEM_KEY;
key.offset = 0;
}
@@ -1163,7 +1163,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans,
btrfs_set_disk_key_type(&disk_key, BTRFS_DEV_ITEM_KEY);
btrfs_set_disk_key_offset(&disk_key, min_devid);
- cow = btrfs_alloc_free_block(trans, root, root->nodesize,
+ cow = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
BTRFS_CHUNK_TREE_OBJECTID,
&disk_key, 0, 0, 0);
btrfs_set_header_bytenr(cow, cow->start);
@@ -1340,7 +1340,7 @@ static int calculate_bg_used(struct btrfs_root *extent_root,
found_key.type != BTRFS_EXTENT_DATA_KEY)
goto next;
if (found_key.type == BTRFS_METADATA_ITEM_KEY)
- used_ret += extent_root->nodesize;
+ used_ret += extent_root->fs_info->nodesize;
else
used_ret += found_key.offset;
next:
@@ -1833,7 +1833,7 @@ static int next_csum(struct btrfs_root *root,
int ret = 0;
struct btrfs_root *csum_root = root->fs_info->csum_root;
struct btrfs_csum_item *csum_item;
- u32 blocksize = root->sectorsize;
+ u32 blocksize = root->fs_info->sectorsize;
u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
int csums_in_item = btrfs_item_size_nr(*leaf, *slot) / csum_size;
@@ -1916,7 +1916,7 @@ out:
static u64 item_end_offset(struct btrfs_root *root, struct btrfs_key *key,
struct extent_buffer *leaf, int slot) {
- u32 blocksize = root->sectorsize;
+ u32 blocksize = root->fs_info->sectorsize;
u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
u64 offset = btrfs_item_size_nr(leaf, slot);
@@ -2006,7 +2006,7 @@ static int rebuild_raid_data_chunk_stripes(struct recover_control *rc,
u64 chunk_end = chunk->offset + chunk->length;
u64 csum_offset = 0;
u64 data_offset;
- u32 blocksize = root->sectorsize;
+ u32 blocksize = root->fs_info->sectorsize;
u32 tree_csum;
int index = 0;
int num_unordered = 0;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 08/32] btrfs-progs: Refactor block sizes users in backref.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (6 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 07/32] btrfs-progs: Refactor block sizes users in chunk-recover.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 09/32] btrfs-progs: Refactor block sizes users in cmds-restore.c Qu Wenruo
` (24 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
backref.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/backref.c b/backref.c
index e1f41e1a..31681a85 100644
--- a/backref.c
+++ b/backref.c
@@ -451,7 +451,7 @@ static int __add_missing_keys(struct btrfs_fs_info *fs_info,
continue;
BUG_ON(!ref->wanted_disk_byte);
eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte,
- fs_info->tree_root->nodesize, 0);
+ fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb)) {
free_extent_buffer(eb);
return -EIO;
@@ -804,7 +804,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
ref->level == 0) {
u32 bsz;
struct extent_buffer *eb;
- bsz = fs_info->extent_root->nodesize;
+ bsz = fs_info->nodesize;
eb = read_tree_block(fs_info->extent_root,
ref->parent, bsz, 0);
if (!extent_buffer_uptodate(eb)) {
@@ -1154,7 +1154,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
}
btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]);
if (found_key->type == BTRFS_METADATA_ITEM_KEY)
- size = fs_info->extent_root->nodesize;
+ size = fs_info->nodesize;
else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)
size = found_key->offset;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 09/32] btrfs-progs: Refactor block sizes users in cmds-restore.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (7 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 08/32] btrfs-progs: Refactor block sizes users in backref.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 10/32] btrfs-progs: Refactor nodesize user in extent_io.c Qu Wenruo
` (23 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-restore.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/cmds-restore.c b/cmds-restore.c
index c327cef0..09388b29 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -126,7 +126,7 @@ static int decompress_lzo(struct btrfs_root *root, unsigned char *inbuf,
inbuf += LZO_LEN;
tot_in += LZO_LEN;
- new_len = lzo1x_worst_compress(root->sectorsize);
+ new_len = lzo1x_worst_compress(root->fs_info->sectorsize);
ret = lzo1x_decompress_safe((const unsigned char *)inbuf, in_len,
(unsigned char *)outbuf,
(void *)&new_len, NULL);
@@ -143,8 +143,8 @@ static int decompress_lzo(struct btrfs_root *root, unsigned char *inbuf,
* If the 4 byte header does not fit to the rest of the page we
* have to move to the next one, unless we read some garbage
*/
- mod_page = tot_in % root->sectorsize;
- rem_page = root->sectorsize - mod_page;
+ mod_page = tot_in % root->fs_info->sectorsize;
+ rem_page = root->fs_info->sectorsize - mod_page;
if (rem_page < LZO_LEN) {
inbuf += rem_page;
tot_in += rem_page;
@@ -1256,7 +1256,7 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location,
root_location = btrfs_super_root(fs_info->super_copy);
generation = btrfs_super_generation(fs_info->super_copy);
root->node = read_tree_block(root, root_location,
- root->nodesize, generation);
+ fs_info->nodesize, generation);
if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Error opening tree root\n");
close_ctree(root);
@@ -1502,7 +1502,8 @@ int cmd_restore(int argc, char **argv)
if (fs_location != 0) {
free_extent_buffer(root->node);
- root->node = read_tree_block(root, fs_location, root->nodesize, 0);
+ root->node = read_tree_block(root, fs_location,
+ root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Failed to read fs location\n");
ret = 1;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 10/32] btrfs-progs: Refactor nodesize user in extent_io.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (8 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 09/32] btrfs-progs: Refactor block sizes users in cmds-restore.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 11/32] btrfs-progs: Refactor nodesize users in image/main.c Qu Wenruo
` (22 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
extent_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/extent_io.c b/extent_io.c
index 915c6ed8..26a67865 100644
--- a/extent_io.c
+++ b/extent_io.c
@@ -765,7 +765,7 @@ int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
u64 stripe_len = this_len;
this_len = min(this_len, bytes_left);
- this_len = min(this_len, (u64)info->tree_root->nodesize);
+ this_len = min(this_len, (u64)info->nodesize);
eb = malloc(sizeof(struct extent_buffer) + this_len);
if (!eb) {
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 11/32] btrfs-progs: Refactor nodesize users in image/main.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (9 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 10/32] btrfs-progs: Refactor nodesize user in extent_io.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 12/32] btrfs-progs: Refactor block sizes users in cmds-check.c Qu Wenruo
` (21 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
image/main.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/image/main.c b/image/main.c
index f1c28de1..6a4ccfaf 100644
--- a/image/main.c
+++ b/image/main.c
@@ -919,7 +919,7 @@ static int flush_pending(struct metadump_struct *md, int done)
{
struct async_work *async = NULL;
struct extent_buffer *eb;
- u64 blocksize = md->root->nodesize;
+ u64 blocksize = md->root->fs_info->nodesize;
u64 start = 0;
u64 size;
size_t offset;
@@ -1083,7 +1083,8 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
int i = 0;
int ret;
- ret = add_extent(btrfs_header_bytenr(eb), root->nodesize, metadump, 0);
+ ret = add_extent(btrfs_header_bytenr(eb), root->fs_info->nodesize,
+ metadump, 0);
if (ret) {
error("unable to add metadata block %llu: %d",
btrfs_header_bytenr(eb), ret);
@@ -1102,7 +1103,8 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
continue;
ri = btrfs_item_ptr(eb, i, struct btrfs_root_item);
bytenr = btrfs_disk_root_bytenr(eb, ri);
- tmp = read_tree_block(root, bytenr, root->nodesize, 0);
+ tmp = read_tree_block(root, bytenr,
+ root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
error("unable to read log root block");
return -EIO;
@@ -1113,7 +1115,8 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
return ret;
} else {
bytenr = btrfs_node_blockptr(eb, i);
- tmp = read_tree_block(root, bytenr, root->nodesize, 0);
+ tmp = read_tree_block(root, bytenr,
+ root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
error("unable to read log root block");
return -EIO;
@@ -1260,7 +1263,7 @@ static int copy_from_extent_tree(struct metadump_struct *metadump,
bytenr = key.objectid;
if (key.type == BTRFS_METADATA_ITEM_KEY) {
- num_bytes = extent_root->nodesize;
+ num_bytes = extent_root->fs_info->nodesize;
} else {
num_bytes = key.offset;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 12/32] btrfs-progs: Refactor block sizes users in cmds-check.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (10 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 11/32] btrfs-progs: Refactor nodesize users in image/main.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 13/32] btrfs-progs: Refactor nodesize user in btrfstune.c Qu Wenruo
` (20 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-check.c | 110 +++++++++++++++++++++++++++++++----------------------------
1 file changed, 58 insertions(+), 52 deletions(-)
diff --git a/cmds-check.c b/cmds-check.c
index ad7c81b2..ce479855 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -829,7 +829,8 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
}
if (!found)
fprintf(stderr, "\tstart: 0, len: %llu\n",
- round_up(rec->isize, root->sectorsize));
+ round_up(rec->isize,
+ root->fs_info->sectorsize));
}
}
@@ -1699,7 +1700,8 @@ static int count_csum_range(struct btrfs_root *root, u64 start,
start = key.offset;
size = btrfs_item_size_nr(leaf, path.slots[0]);
- csum_end = key.offset + (size / csum_size) * root->sectorsize;
+ csum_end = key.offset + (size / csum_size) *
+ root->fs_info->sectorsize;
if (csum_end > start) {
size = min(csum_end - start, len);
len -= size;
@@ -1726,7 +1728,7 @@ static int process_file_extent(struct btrfs_root *root,
u64 num_bytes = 0;
u64 disk_bytenr = 0;
u64 extent_offset = 0;
- u64 mask = root->sectorsize - 1;
+ u64 mask = root->fs_info->sectorsize - 1;
int extent_type;
int ret;
@@ -1977,7 +1979,7 @@ static void reada_walk_down(struct btrfs_root *root,
return;
nritems = btrfs_header_nritems(node);
- blocksize = root->nodesize;
+ blocksize = root->fs_info->nodesize;
for (i = slot; i < nritems; i++) {
bytenr = btrfs_node_blockptr(node, i);
ptr_gen = btrfs_node_ptr_generation(node, i);
@@ -2153,7 +2155,7 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
}
bytenr = btrfs_node_blockptr(cur, path->slots[*level]);
ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]);
- blocksize = root->nodesize;
+ blocksize = root->fs_info->nodesize;
if (bytenr == nrefs->bytenr[*level - 1]) {
refs = nrefs->refs[*level - 1];
@@ -2192,7 +2194,8 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
btrfs_add_corrupt_extent_record(root->fs_info,
&node_key,
path->nodes[*level]->start,
- root->nodesize, *level);
+ root->fs_info->nodesize,
+ *level);
err = -EIO;
goto out;
}
@@ -2281,7 +2284,7 @@ static int walk_down_tree_v2(struct btrfs_root *root, struct btrfs_path *path,
}
bytenr = btrfs_node_blockptr(cur, path->slots[*level]);
ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]);
- blocksize = root->nodesize;
+ blocksize = root->fs_info->nodesize;
ret = update_nodes_refs(root, bytenr, nrefs, *level - 1);
if (ret)
@@ -2306,7 +2309,8 @@ static int walk_down_tree_v2(struct btrfs_root *root, struct btrfs_path *path,
btrfs_add_corrupt_extent_record(root->fs_info,
&node_key,
path->nodes[*level]->start,
- root->nodesize, *level);
+ root->fs_info->nodesize,
+ *level);
ret = -EIO;
break;
}
@@ -3232,7 +3236,8 @@ static int repair_inode_discount_extent(struct btrfs_trans_handle *trans,
/* special case for a file losing all its file extent */
if (!found) {
ret = btrfs_punch_hole(trans, root, rec->ino, 0,
- round_up(rec->isize, root->sectorsize));
+ round_up(rec->isize,
+ root->fs_info->sectorsize));
if (ret < 0)
goto out;
}
@@ -3852,9 +3857,9 @@ static int repair_btree(struct btrfs_root *root,
* return value is not concerned.
*/
btrfs_release_path(&path);
- ret = btrfs_free_extent(trans, root, offset, root->nodesize,
- 0, root->root_key.objectid,
- level - 1, 0);
+ ret = btrfs_free_extent(trans, root, offset,
+ root->fs_info->nodesize, 0,
+ root->root_key.objectid, level - 1, 0);
cache = next_cache_extent(cache);
}
@@ -4981,9 +4986,10 @@ out:
* Just a warning, as dir inode nbytes is just an
* instructive value.
*/
- if (!IS_ALIGNED(nbytes, root->nodesize)) {
+ if (!IS_ALIGNED(nbytes, root->fs_info->nodesize)) {
warning("root %llu DIR INODE[%llu] nbytes should be aligned to %u",
- root->objectid, inode_id, root->nodesize);
+ root->objectid, inode_id,
+ root->fs_info->nodesize);
}
if (isize != size) {
@@ -6103,7 +6109,7 @@ static int add_extent_rec_nolookup(struct cache_tree *extent_cache,
if (tmpl->metadata)
rec->crossing_stripes = check_crossing_stripes(global_info,
- rec->start, global_info->tree_root->nodesize);
+ rec->start, global_info->nodesize);
check_extent_type(rec);
return ret;
}
@@ -6205,7 +6211,7 @@ static int add_extent_rec(struct cache_tree *extent_cache,
if (tmpl->metadata)
rec->crossing_stripes = check_crossing_stripes(
global_info, rec->start,
- global_info->tree_root->nodesize);
+ global_info->nodesize);
check_extent_type(rec);
maybe_free_extent_rec(extent_cache, rec);
return ret;
@@ -6802,14 +6808,14 @@ static int process_extent_item(struct btrfs_root *root,
if (key.type == BTRFS_METADATA_ITEM_KEY) {
metadata = 1;
- num_bytes = root->nodesize;
+ num_bytes = root->fs_info->nodesize;
} else {
num_bytes = key.offset;
}
- if (!IS_ALIGNED(key.objectid, root->sectorsize)) {
+ if (!IS_ALIGNED(key.objectid, root->fs_info->sectorsize)) {
error("ignoring invalid extent, bytenr %llu is not aligned to %u",
- key.objectid, root->sectorsize);
+ key.objectid, root->fs_info->sectorsize);
return -EIO;
}
if (item_size < sizeof(*ei)) {
@@ -6838,14 +6844,14 @@ static int process_extent_item(struct btrfs_root *root,
metadata = 1;
else
metadata = 0;
- if (metadata && num_bytes != root->nodesize) {
+ if (metadata && num_bytes != root->fs_info->nodesize) {
error("ignore invalid metadata extent, length %llu does not equal to %u",
- num_bytes, root->nodesize);
+ num_bytes, root->fs_info->nodesize);
return -EIO;
}
- if (!metadata && !IS_ALIGNED(num_bytes, root->sectorsize)) {
+ if (!metadata && !IS_ALIGNED(num_bytes, root->fs_info->sectorsize)) {
error("ignore invalid data extent, length %llu is not aligned to %u",
- num_bytes, root->sectorsize);
+ num_bytes, root->fs_info->sectorsize);
return -EIO;
}
@@ -7053,7 +7059,7 @@ static int verify_space_cache(struct btrfs_root *root,
if (key.type == BTRFS_EXTENT_ITEM_KEY)
last = key.objectid + key.offset;
else
- last = key.objectid + root->nodesize;
+ last = key.objectid + root->fs_info->nodesize;
path.slots[0]++;
continue;
}
@@ -7065,7 +7071,7 @@ static int verify_space_cache(struct btrfs_root *root,
if (key.type == BTRFS_EXTENT_ITEM_KEY)
last = key.objectid + key.offset;
else
- last = key.objectid + root->nodesize;
+ last = key.objectid + root->fs_info->nodesize;
path.slots[0]++;
}
@@ -7115,7 +7121,7 @@ static int check_space_cache(struct btrfs_root *root)
start = cache->key.objectid + cache->key.offset;
if (!cache->free_space_ctl) {
if (btrfs_init_free_space_ctl(cache,
- root->sectorsize)) {
+ root->fs_info->sectorsize)) {
ret = -ENOMEM;
break;
}
@@ -7176,7 +7182,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
int mirror;
int num_copies;
- if (num_bytes % root->sectorsize)
+ if (num_bytes % root->fs_info->sectorsize)
return -EINVAL;
data = malloc(num_bytes);
@@ -7199,11 +7205,11 @@ again:
tmp = offset + data_checked;
csum = btrfs_csum_data((char *)data + tmp,
- csum, root->sectorsize);
+ csum, root->fs_info->sectorsize);
btrfs_csum_final(csum, (u8 *)&csum);
csum_offset = leaf_offset +
- tmp / root->sectorsize * csum_size;
+ tmp / root->fs_info->sectorsize * csum_size;
read_extent_buffer(eb, (char *)&csum_expected,
csum_offset, csum_size);
/* try another mirror */
@@ -7219,7 +7225,7 @@ again:
goto again;
}
}
- data_checked += root->sectorsize;
+ data_checked += root->fs_info->sectorsize;
}
offset += read_len;
}
@@ -7420,7 +7426,7 @@ static int check_csums(struct btrfs_root *root)
}
data_len = (btrfs_item_size_nr(leaf, path.slots[0]) /
- csum_size) * root->sectorsize;
+ csum_size) * root->fs_info->sectorsize;
if (!check_data_csum)
goto skip_csum_check;
leaf_offset = btrfs_item_ptr_offset(leaf, path.slots[0]);
@@ -7821,7 +7827,7 @@ static int run_next_block(struct btrfs_root *root,
ref),
btrfs_extent_data_ref_offset(buf, ref),
btrfs_extent_data_ref_count(buf, ref),
- 0, root->sectorsize);
+ 0, root->fs_info->sectorsize);
continue;
}
if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
@@ -7831,7 +7837,7 @@ static int run_next_block(struct btrfs_root *root,
add_data_backref(extent_cache,
key.objectid, key.offset, 0, 0, 0,
btrfs_shared_data_ref_count(buf, ref),
- 0, root->sectorsize);
+ 0, root->fs_info->sectorsize);
continue;
}
if (key.type == BTRFS_ORPHAN_ITEM_KEY) {
@@ -7863,7 +7869,7 @@ static int run_next_block(struct btrfs_root *root,
data_bytes_allocated +=
btrfs_file_extent_disk_num_bytes(buf, fi);
- if (data_bytes_allocated < root->sectorsize) {
+ if (data_bytes_allocated < root->fs_info->sectorsize) {
abort();
}
data_bytes_referenced +=
@@ -7887,7 +7893,7 @@ static int run_next_block(struct btrfs_root *root,
struct extent_record tmpl;
ptr = btrfs_node_blockptr(buf, i);
- size = root->nodesize;
+ size = root->fs_info->nodesize;
btrfs_node_key_to_cpu(buf, &key, i);
if (ri != NULL) {
if ((level == ri->drop_level)
@@ -8113,7 +8119,7 @@ static int delete_extent_records(struct btrfs_trans_handle *trans,
if (found_key.type == BTRFS_EXTENT_ITEM_KEY ||
found_key.type == BTRFS_METADATA_ITEM_KEY) {
u64 bytes = (found_key.type == BTRFS_EXTENT_ITEM_KEY) ?
- found_key.offset : root->nodesize;
+ found_key.offset : root->fs_info->nodesize;
ret = btrfs_update_block_group(trans, root, bytenr,
bytes, 0, 0);
@@ -8147,7 +8153,7 @@ static int record_extent(struct btrfs_trans_handle *trans,
if (!back->is_data)
rec->max_size = max_t(u64, rec->max_size,
- info->extent_root->nodesize);
+ info->nodesize);
if (!allocated) {
u32 item_size = sizeof(*ei);
@@ -9890,14 +9896,14 @@ again:
level = btrfs_header_level(root1->node);
ret = add_root_item_to_list(&normal_trees, root1->root_key.objectid,
root1->node->start, 0, level, 0,
- root1->nodesize, NULL);
+ root1->fs_info->nodesize, NULL);
if (ret < 0)
goto out;
root1 = root->fs_info->chunk_root;
level = btrfs_header_level(root1->node);
ret = add_root_item_to_list(&normal_trees, root1->root_key.objectid,
root1->node->start, 0, level, 0,
- root1->nodesize, NULL);
+ root1->fs_info->nodesize, NULL);
if (ret < 0)
goto out;
btrfs_init_path(&path);
@@ -9928,7 +9934,7 @@ again:
last_snapshot = btrfs_root_last_snapshot(&ri);
if (btrfs_disk_key_objectid(&ri.drop_progress) == 0) {
level = btrfs_root_level(&ri);
- level_size = root->nodesize;
+ level_size = root->fs_info->nodesize;
ret = add_root_item_to_list(&normal_trees,
found_key.objectid,
btrfs_root_bytenr(&ri),
@@ -9938,7 +9944,7 @@ again:
goto out;
} else {
level = btrfs_root_level(&ri);
- level_size = root->nodesize;
+ level_size = root->fs_info->nodesize;
objectid = found_key.objectid;
btrfs_disk_key_to_cpu(&found_key,
&ri.drop_progress);
@@ -10065,7 +10071,7 @@ static int check_tree_block_ref(struct btrfs_root *root,
int slot;
int skinny_level;
int type;
- u32 nodesize = root->nodesize;
+ u32 nodesize = root->fs_info->nodesize;
u32 item_size;
u64 offset;
int tree_reloc_root = 0;
@@ -10250,20 +10256,20 @@ static int check_extent_data_item(struct btrfs_root *root,
extent_num_bytes = btrfs_file_extent_num_bytes(eb, fi);
/* Check unaligned disk_num_bytes and num_bytes */
- if (!IS_ALIGNED(disk_num_bytes, root->sectorsize)) {
+ if (!IS_ALIGNED(disk_num_bytes, root->fs_info->sectorsize)) {
error(
"file extent [%llu, %llu] has unaligned disk num bytes: %llu, should be aligned to %u",
fi_key.objectid, fi_key.offset, disk_num_bytes,
- root->sectorsize);
+ root->fs_info->sectorsize);
err |= BYTES_UNALIGNED;
} else {
data_bytes_allocated += disk_num_bytes;
}
- if (!IS_ALIGNED(extent_num_bytes, root->sectorsize)) {
+ if (!IS_ALIGNED(extent_num_bytes, root->fs_info->sectorsize)) {
error(
"file extent [%llu, %llu] has unaligned num bytes: %llu, should be aligned to %u",
fi_key.objectid, fi_key.offset, extent_num_bytes,
- root->sectorsize);
+ root->fs_info->sectorsize);
err |= BYTES_UNALIGNED;
} else {
data_bytes_referenced += extent_num_bytes;
@@ -10476,7 +10482,7 @@ static int check_tree_block_backref(struct btrfs_fs_info *fs_info, u64 root_id,
}
/* Read out the tree block to get item/node key */
- eb = read_tree_block(root, bytenr, root->nodesize, 0);
+ eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb)) {
err |= REFERENCER_MISSING;
free_extent_buffer(eb);
@@ -11499,7 +11505,7 @@ static int traverse_tree_block(struct btrfs_root *root,
* As a btrfs tree has most 8 levels (0..7), so it's quite safe
* to call the function itself.
*/
- eb = read_tree_block(root, blocknr, root->nodesize, 0);
+ eb = read_tree_block(root, blocknr, root->fs_info->nodesize, 0);
if (extent_buffer_uptodate(eb)) {
ret = traverse_tree_block(root, eb);
err |= ret;
@@ -11590,7 +11596,7 @@ static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
goto init;
}
c = btrfs_alloc_free_block(trans, root,
- root->nodesize,
+ root->fs_info->nodesize,
root->root_key.objectid,
&disk_key, level, 0, 0);
if (IS_ERR(c)) {
@@ -12088,7 +12094,7 @@ static int populate_csum(struct btrfs_trans_handle *trans,
int ret = 0;
while (offset < len) {
- sectorsize = csum_root->sectorsize;
+ sectorsize = csum_root->fs_info->sectorsize;
ret = read_extent_data(csum_root, buf, start + offset,
§orsize, 0);
if (ret)
@@ -12116,7 +12122,7 @@ static int fill_csum_tree_from_one_fs_root(struct btrfs_trans_handle *trans,
int slot = 0;
int ret = 0;
- buf = malloc(cur_root->fs_info->csum_root->sectorsize);
+ buf = malloc(cur_root->fs_info->sectorsize);
if (!buf)
return -ENOMEM;
@@ -12248,7 +12254,7 @@ static int fill_csum_tree_from_extent(struct btrfs_trans_handle *trans,
return ret;
}
- buf = malloc(csum_root->sectorsize);
+ buf = malloc(csum_root->fs_info->sectorsize);
if (!buf) {
btrfs_release_path(&path);
return -ENOMEM;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 13/32] btrfs-progs: Refactor nodesize user in btrfstune.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (11 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 12/32] btrfs-progs: Refactor block sizes users in cmds-check.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 14/32] btrfs-progs: Refactor nodesize users in utils.c Qu Wenruo
` (19 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
btrfstune.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/btrfstune.c b/btrfstune.c
index 257bac44..0a6ad9ca 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -149,7 +149,7 @@ static int change_extents_uuid(struct btrfs_fs_info *fs_info)
goto next;
bytenr = key.objectid;
- eb = read_tree_block(root, bytenr, root->nodesize, 0);
+ eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0);
if (IS_ERR(eb)) {
error("failed to read tree block: %llu", bytenr);
ret = PTR_ERR(eb);
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 14/32] btrfs-progs: Refactor nodesize users in utils.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (12 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 13/32] btrfs-progs: Refactor nodesize user in btrfstune.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 15/32] btrfs-progs: Refactor block sizes users in extent-tree.c Qu Wenruo
` (18 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/utils.c b/utils.c
index d2489e70..823b7f3d 100644
--- a/utils.c
+++ b/utils.c
@@ -378,7 +378,7 @@ int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
btrfs_set_stack_inode_generation(&inode_item, trans->transid);
btrfs_set_stack_inode_size(&inode_item, 0);
btrfs_set_stack_inode_nlink(&inode_item, 1);
- btrfs_set_stack_inode_nbytes(&inode_item, root->nodesize);
+ btrfs_set_stack_inode_nbytes(&inode_item, root->fs_info->nodesize);
btrfs_set_stack_inode_mode(&inode_item, S_IFDIR | 0755);
btrfs_set_stack_timespec_sec(&inode_item.atime, now);
btrfs_set_stack_timespec_nsec(&inode_item.atime, 0);
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 15/32] btrfs-progs: Refactor block sizes users in extent-tree.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (13 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 14/32] btrfs-progs: Refactor nodesize users in utils.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 16/32] btrfs-progs: Refactor nodesize user in print-tree.c Qu Wenruo
` (17 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
And in the refactoring, also refactors a open-coded round_up().
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
extent-tree.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/extent-tree.c b/extent-tree.c
index b12ee290..43fa3b5f 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -152,7 +152,7 @@ static int cache_block_group(struct btrfs_root *root,
last + hole_size - 1);
}
if (key.type == BTRFS_METADATA_ITEM_KEY)
- last = key.objectid + root->nodesize;
+ last = key.objectid + root->fs_info->nodesize;
else
last = key.objectid + key.offset;
}
@@ -1452,7 +1452,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
if (metadata &&
!btrfs_fs_incompat(root->fs_info, SKINNY_METADATA)) {
- offset = root->nodesize;
+ offset = root->fs_info->nodesize;
metadata = 0;
}
@@ -1487,14 +1487,14 @@ again:
path->slots[0]);
if (key.objectid == bytenr &&
key.type == BTRFS_EXTENT_ITEM_KEY &&
- key.offset == root->nodesize)
+ key.offset == root->fs_info->nodesize)
ret = 0;
}
if (ret) {
btrfs_release_path(path);
key.type = BTRFS_EXTENT_ITEM_KEY;
- key.offset = root->nodesize;
+ key.offset = root->fs_info->nodesize;
metadata = 0;
goto again;
}
@@ -1558,7 +1558,7 @@ int btrfs_set_block_flags(struct btrfs_trans_handle *trans,
key.offset = level;
key.type = BTRFS_METADATA_ITEM_KEY;
} else {
- key.offset = root->nodesize;
+ key.offset = root->fs_info->nodesize;
key.type = BTRFS_EXTENT_ITEM_KEY;
}
@@ -1575,13 +1575,13 @@ again:
btrfs_item_key_to_cpu(path->nodes[0], &key,
path->slots[0]);
if (key.objectid == bytenr &&
- key.offset == root->nodesize &&
+ key.offset == root->fs_info->nodesize &&
key.type == BTRFS_EXTENT_ITEM_KEY)
ret = 0;
}
if (ret) {
btrfs_release_path(path);
- key.offset = root->nodesize;
+ key.offset = root->fs_info->nodesize;
key.type = BTRFS_EXTENT_ITEM_KEY;
goto again;
}
@@ -1679,7 +1679,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
}
} else {
bytenr = btrfs_node_blockptr(buf, i);
- num_bytes = root->nodesize;
+ num_bytes = root->fs_info->nodesize;
ret = process_func(trans, root, bytenr, num_bytes,
parent, ref_root, level - 1, 0);
if (ret) {
@@ -2001,7 +2001,7 @@ static int update_pinned_extents(struct btrfs_root *root,
while (num > 0) {
cache = btrfs_lookup_block_group(fs_info, bytenr);
if (!cache) {
- len = min((u64)root->sectorsize, num);
+ len = min((u64)fs_info->sectorsize, num);
goto next;
}
WARN_ON(!cache);
@@ -2479,7 +2479,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
int pending_ret;
int ret;
- WARN_ON(num_bytes < root->sectorsize);
+ WARN_ON(num_bytes < root->fs_info->sectorsize);
if (root == extent_root) {
struct pending_extent_op *extent_op;
@@ -2506,9 +2506,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
static u64 stripe_align(struct btrfs_root *root, u64 val)
{
- u64 mask = ((u64)root->stripesize - 1);
- u64 ret = (val + mask) & ~mask;
- return ret;
+ return round_up(val, (u64)root->fs_info->stripesize);
}
/*
@@ -2536,7 +2534,7 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans,
int full_scan = 0;
int wrapped = 0;
- WARN_ON(num_bytes < root->sectorsize);
+ WARN_ON(num_bytes < info->sectorsize);
ins->type = BTRFS_EXTENT_ITEM_KEY;
search_start = stripe_align(root, search_start);
@@ -2688,7 +2686,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
BUG_ON(ret);
}
- WARN_ON(num_bytes < root->sectorsize);
+ WARN_ON(num_bytes < info->sectorsize);
ret = find_free_extent(trans, root, num_bytes, empty_size,
search_start, search_end, hint_byte, ins,
trans->alloc_exclude_start,
@@ -2749,7 +2747,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
btrfs_mark_buffer_dirty(leaf);
btrfs_free_path(path);
- ret = update_block_group(trans, root, ins->objectid, root->nodesize,
+ ret = update_block_group(trans, root, ins->objectid, fs_info->nodesize,
1, 0);
return ret;
}
@@ -3405,7 +3403,7 @@ int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
block_group_cache = &root->fs_info->block_group_cache;
chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
- group_align = 64 * root->sectorsize;
+ group_align = 64 * root->fs_info->sectorsize;
cur_start = 0;
while (cur_start < total_bytes) {
@@ -3907,9 +3905,9 @@ int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans,
key.objectid, key.offset, 1, 0);
BUG_ON(ret);
} else if (key.type == BTRFS_METADATA_ITEM_KEY) {
- bytes_used += root->nodesize;
+ bytes_used += fs_info->nodesize;
ret = btrfs_update_block_group(trans, root,
- key.objectid, root->nodesize, 1, 0);
+ key.objectid, fs_info->nodesize, 1, 0);
BUG_ON(ret);
}
path.slots[0]++;
@@ -3931,7 +3929,7 @@ static void __get_extent_size(struct btrfs_root *root, struct btrfs_path *path,
if (key.type == BTRFS_EXTENT_ITEM_KEY)
*len = key.offset;
else
- *len = root->nodesize;
+ *len = root->fs_info->nodesize;
}
/*
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 16/32] btrfs-progs: Refactor nodesize user in print-tree.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (14 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 15/32] btrfs-progs: Refactor block sizes users in extent-tree.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 17/32] btrfs-progs: Refactor nodesize users in qgroup-verify.c Qu Wenruo
` (16 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
print-tree.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/print-tree.c b/print-tree.c
index a0d33956..1b15640b 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -1297,7 +1297,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
(unsigned long long)btrfs_header_owner(eb));
print_uuids(eb);
fflush(stdout);
- size = root->nodesize;
+ size = root->fs_info->nodesize;
for (i = 0; i < nr; i++) {
u64 blocknr = btrfs_node_blockptr(eb, i);
btrfs_node_key(eb, &disk_key, i);
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 17/32] btrfs-progs: Refactor nodesize users in qgroup-verify.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (15 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 16/32] btrfs-progs: Refactor nodesize user in print-tree.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 18/32] btrfs-progs: Refactor nodesize users in cmds-inspect-tree-stats.c Qu Wenruo
` (15 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
qgroup-verify.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/qgroup-verify.c b/qgroup-verify.c
index 23d34699..2f4b1c66 100644
--- a/qgroup-verify.c
+++ b/qgroup-verify.c
@@ -736,7 +736,7 @@ static int travel_tree(struct btrfs_fs_info *info, struct btrfs_root *root,
nr = btrfs_header_nritems(eb);
for (i = 0; i < nr; i++) {
new_bytenr = btrfs_node_blockptr(eb, i);
- new_num_bytes = root->nodesize;
+ new_num_bytes = info->nodesize;
ret = travel_tree(info, root, new_bytenr, new_num_bytes,
ref_parent);
@@ -1185,7 +1185,7 @@ static int scan_extents(struct btrfs_fs_info *info,
bytenr = key.objectid;
num_bytes = key.offset;
if (key.type == BTRFS_METADATA_ITEM_KEY) {
- num_bytes = info->extent_root->nodesize;
+ num_bytes = info->nodesize;
meta = 1;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 18/32] btrfs-progs: Refactor nodesize users in cmds-inspect-tree-stats.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (16 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 17/32] btrfs-progs: Refactor nodesize users in qgroup-verify.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 19/32] btrfs-progs: Refactor sectorsize users in mkfs/main.c Qu Wenruo
` (14 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-inspect-tree-stats.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/cmds-inspect-tree-stats.c b/cmds-inspect-tree-stats.c
index 58dd29e1..ecb33ce2 100644
--- a/cmds-inspect-tree-stats.c
+++ b/cmds-inspect-tree-stats.c
@@ -105,7 +105,7 @@ static int walk_leaf(struct btrfs_root *root, struct btrfs_path *path,
struct btrfs_key found_key;
int i;
- stat->total_bytes += root->nodesize;
+ stat->total_bytes += root->fs_info->nodesize;
stat->total_leaves++;
if (!find_inline)
@@ -137,12 +137,13 @@ static int walk_nodes(struct btrfs_root *root, struct btrfs_path *path,
struct root_stats *stat, int level, int find_inline)
{
struct extent_buffer *b = path->nodes[level];
+ u32 nodesize = root->fs_info->nodesize;
u64 last_block;
- u64 cluster_size = root->nodesize;
+ u64 cluster_size = nodesize;
int i;
int ret = 0;
- stat->total_bytes += root->nodesize;
+ stat->total_bytes += nodesize;
stat->total_nodes++;
last_block = btrfs_header_bytenr(b);
@@ -153,7 +154,7 @@ static int walk_nodes(struct btrfs_root *root, struct btrfs_path *path,
path->slots[level] = i;
if ((level - 1) > 0 || find_inline) {
tmp = read_tree_block(root, cur_blocknr,
- root->nodesize,
+ nodesize,
btrfs_node_ptr_generation(b, i));
if (!extent_buffer_uptodate(tmp)) {
error("failed to read blocknr %llu",
@@ -167,9 +168,9 @@ static int walk_nodes(struct btrfs_root *root, struct btrfs_path *path,
find_inline);
else
ret = walk_leaf(root, path, stat, find_inline);
- if (last_block + root->nodesize != cur_blocknr) {
+ if (last_block + nodesize != cur_blocknr) {
u64 distance = calc_distance(last_block +
- root->nodesize,
+ nodesize,
cur_blocknr);
stat->total_seeks++;
stat->total_seek_len += distance;
@@ -186,7 +187,7 @@ static int walk_nodes(struct btrfs_root *root, struct btrfs_path *path,
stat->forward_seeks++;
else
stat->backward_seeks++;
- if (cluster_size != root->nodesize) {
+ if (cluster_size != nodesize) {
stat->total_cluster_size += cluster_size;
stat->total_clusters++;
if (cluster_size < stat->min_cluster_size)
@@ -194,9 +195,9 @@ static int walk_nodes(struct btrfs_root *root, struct btrfs_path *path,
if (cluster_size > stat->max_cluster_size)
stat->max_cluster_size = cluster_size;
}
- cluster_size = root->nodesize;
+ cluster_size = nodesize;
} else {
- cluster_size += root->nodesize;
+ cluster_size += nodesize;
}
last_block = cur_blocknr;
if (cur_blocknr < stat->lowest_bytenr)
@@ -334,7 +335,7 @@ static int calc_root_size(struct btrfs_root *tree_root, struct btrfs_key *key,
stat.lowest_bytenr = btrfs_header_bytenr(root->node);
stat.highest_bytenr = stat.lowest_bytenr;
stat.min_cluster_size = (u64)-1;
- stat.max_cluster_size = root->nodesize;
+ stat.max_cluster_size = root->fs_info->nodesize;
path.nodes[level] = root->node;
if (gettimeofday(&start, NULL)) {
error("cannot get time: %s", strerror(errno));
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 19/32] btrfs-progs: Refactor sectorsize users in mkfs/main.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (17 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 18/32] btrfs-progs: Refactor nodesize users in cmds-inspect-tree-stats.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 20/32] btrfs-progs: Refactor sectorsizes users in file-item.c Qu Wenruo
` (13 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
mkfs/main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mkfs/main.c b/mkfs/main.c
index 61f746b3..24a51cb4 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -451,7 +451,7 @@ static int fill_inode_item(struct btrfs_trans_handle *trans,
struct btrfs_inode_item *dst, struct stat *src)
{
u64 blocks = 0;
- u64 sectorsize = root->sectorsize;
+ u64 sectorsize = root->fs_info->sectorsize;
/*
* btrfs_inode_item has some reserved fields
@@ -652,7 +652,7 @@ static int add_file_items(struct btrfs_trans_handle *trans,
u64 bytes_read = 0;
struct btrfs_key key;
int blocks;
- u32 sectorsize = root->sectorsize;
+ u32 sectorsize = root->fs_info->sectorsize;
u64 first_block = 0;
u64 file_pos = 0;
u64 cur_bytes;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 20/32] btrfs-progs: Refactor sectorsizes users in file-item.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (18 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 19/32] btrfs-progs: Refactor sectorsize users in mkfs/main.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 21/32] btrfs-progs: Refactor sectorsize users in free-space-cache.c Qu Wenruo
` (12 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
file-item.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/file-item.c b/file-item.c
index 333fa339..6877a1a9 100644
--- a/file-item.c
+++ b/file-item.c
@@ -162,7 +162,8 @@ btrfs_lookup_csum(struct btrfs_trans_handle *trans,
if (found_key.type != BTRFS_EXTENT_CSUM_KEY)
goto fail;
- csum_offset = (bytenr - found_key.offset) / root->sectorsize;
+ csum_offset = (bytenr - found_key.offset) /
+ root->fs_info->sectorsize;
csums_in_item = btrfs_item_size_nr(leaf, path->slots[0]);
csums_in_item /= csum_size;
@@ -195,6 +196,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
struct extent_buffer *leaf = NULL;
u64 csum_offset;
u32 csum_result = ~(u32)0;
+ u32 sectorsize = root->fs_info->sectorsize;
u32 nritems;
u32 ins_size;
u16 csum_size =
@@ -265,7 +267,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
path->slots[0]--;
leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
- csum_offset = (file_key.offset - found_key.offset) / root->sectorsize;
+ csum_offset = (file_key.offset - found_key.offset) / sectorsize;
if (found_key.objectid != BTRFS_EXTENT_CSUM_OBJECTID ||
found_key.type != BTRFS_EXTENT_CSUM_KEY ||
csum_offset >= MAX_CSUM_ITEMS(root, csum_size)) {
@@ -288,7 +290,7 @@ insert:
if (found_next) {
u64 tmp = min(alloc_end, next_offset);
tmp -= file_key.offset;
- tmp /= root->sectorsize;
+ tmp /= sectorsize;
tmp = max((u64)1, tmp);
tmp = min(tmp, (u64)MAX_CSUM_ITEMS(root, csum_size));
ins_size = csum_size * tmp;
@@ -346,12 +348,12 @@ static noinline int truncate_one_csum(struct btrfs_root *root,
btrfs_super_csum_size(root->fs_info->super_copy);
u64 csum_end;
u64 end_byte = bytenr + len;
- u32 blocksize = root->sectorsize;
+ u32 blocksize = root->fs_info->sectorsize;
int ret;
leaf = path->nodes[0];
csum_end = btrfs_item_size_nr(leaf, path->slots[0]) / csum_size;
- csum_end *= root->sectorsize;
+ csum_end *= root->fs_info->sectorsize;
csum_end += key->offset;
if (key->offset < bytenr && csum_end <= end_byte) {
@@ -403,7 +405,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
int ret;
u16 csum_size =
btrfs_super_csum_size(root->fs_info->super_copy);
- int blocksize = root->sectorsize;
+ int blocksize = root->fs_info->sectorsize;
root = root->fs_info->csum_root;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 21/32] btrfs-progs: Refactor sectorsize users in free-space-cache.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (19 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 20/32] btrfs-progs: Refactor sectorsizes users in file-item.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 22/32] btrfs-progs: Refactor sectorsize users in file.c Qu Wenruo
` (11 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
free-space-cache.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/free-space-cache.c b/free-space-cache.c
index a4196eb1..4bf4a6cb 100644
--- a/free-space-cache.c
+++ b/free-space-cache.c
@@ -54,7 +54,8 @@ static int io_ctl_init(struct io_ctl *io_ctl, u64 size, u64 ino,
struct btrfs_root *root)
{
memset(io_ctl, 0, sizeof(struct io_ctl));
- io_ctl->num_pages = (size + root->sectorsize - 1) / root->sectorsize;
+ io_ctl->num_pages = (size + root->fs_info->sectorsize - 1) /
+ root->fs_info->sectorsize;
io_ctl->buffer = kzalloc(size, GFP_NOFS);
if (!io_ctl->buffer)
return -ENOMEM;
@@ -81,11 +82,12 @@ static void io_ctl_unmap_page(struct io_ctl *io_ctl)
static void io_ctl_map_page(struct io_ctl *io_ctl, int clear)
{
BUG_ON(io_ctl->index >= io_ctl->num_pages);
- io_ctl->cur = io_ctl->buffer + (io_ctl->index++ * io_ctl->root->sectorsize);
+ io_ctl->cur = io_ctl->buffer + (io_ctl->index++ *
+ io_ctl->root->fs_info->sectorsize);
io_ctl->orig = io_ctl->cur;
- io_ctl->size = io_ctl->root->sectorsize;
+ io_ctl->size = io_ctl->root->fs_info->sectorsize;
if (clear)
- memset(io_ctl->cur, 0, io_ctl->root->sectorsize);
+ memset(io_ctl->cur, 0, io_ctl->root->fs_info->sectorsize);
}
static void io_ctl_drop_pages(struct io_ctl *io_ctl)
@@ -210,7 +212,8 @@ static int io_ctl_check_crc(struct io_ctl *io_ctl, int index)
val = *tmp;
io_ctl_map_page(io_ctl, 0);
- crc = crc32c(crc, io_ctl->orig + offset, io_ctl->root->sectorsize - offset);
+ crc = crc32c(crc, io_ctl->orig + offset,
+ io_ctl->root->fs_info->sectorsize - offset);
btrfs_csum_final(crc, (u8 *)&crc);
if (val != crc) {
printk("btrfs: csum mismatch on free space cache\n");
@@ -257,7 +260,7 @@ static int io_ctl_read_bitmap(struct io_ctl *io_ctl,
if (ret)
return ret;
- memcpy(entry->bitmap, io_ctl->cur, io_ctl->root->sectorsize);
+ memcpy(entry->bitmap, io_ctl->cur, io_ctl->root->fs_info->sectorsize);
io_ctl_unmap_page(io_ctl);
return 0;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 22/32] btrfs-progs: Refactor sectorsize users in file.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (20 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 21/32] btrfs-progs: Refactor sectorsize users in free-space-cache.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 23/32] btrfs-progs: Refactor sectorsize users in volumes.c Qu Wenruo
` (10 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
file.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/file.c b/file.c
index bf31ccef..028bfba8 100644
--- a/file.c
+++ b/file.c
@@ -193,10 +193,10 @@ int btrfs_read_file(struct btrfs_root *root, u64 ino, u64 start, int len,
int read = 0;
int ret;
- if (!IS_ALIGNED(start, root->sectorsize) ||
- !IS_ALIGNED(len, root->sectorsize)) {
+ if (!IS_ALIGNED(start, root->fs_info->sectorsize) ||
+ !IS_ALIGNED(len, root->fs_info->sectorsize)) {
warning("@start and @len must be aligned to %u for function %s",
- root->sectorsize, __func__);
+ root->fs_info->sectorsize, __func__);
return -EINVAL;
}
@@ -260,7 +260,7 @@ int btrfs_read_file(struct btrfs_root *root, u64 ino, u64 start, int len,
goto next;
read_extent_buffer(leaf, dest,
btrfs_file_extent_inline_start(fi), extent_len);
- read += round_up(extent_len, root->sectorsize);
+ read += round_up(extent_len, root->fs_info->sectorsize);
break;
}
@@ -319,7 +319,7 @@ next:
ii = btrfs_item_ptr(path.nodes[0], path.slots[0],
struct btrfs_inode_item);
isize = round_up(btrfs_inode_size(path.nodes[0], ii),
- root->sectorsize);
+ root->fs_info->sectorsize);
read = min_t(u64, isize - start, len);
}
out:
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 23/32] btrfs-progs: Refactor sectorsize users in volumes.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (21 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 22/32] btrfs-progs: Refactor sectorsize users in file.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 24/32] btrfs-progs: Refactor sectorsize users in free-space-tree.c Qu Wenruo
` (9 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
volumes.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/volumes.c b/volumes.c
index b350e259..3fc5a624 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1060,9 +1060,9 @@ again:
btrfs_set_stack_chunk_num_stripes(chunk, num_stripes);
btrfs_set_stack_chunk_io_align(chunk, stripe_len);
btrfs_set_stack_chunk_io_width(chunk, stripe_len);
- btrfs_set_stack_chunk_sector_size(chunk, extent_root->sectorsize);
+ btrfs_set_stack_chunk_sector_size(chunk, info->sectorsize);
btrfs_set_stack_chunk_sub_stripes(chunk, sub_stripes);
- map->sector_size = extent_root->sectorsize;
+ map->sector_size = info->sectorsize;
map->stripe_len = stripe_len;
map->io_align = stripe_len;
map->io_width = stripe_len;
@@ -1123,7 +1123,7 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
key.type = BTRFS_CHUNK_ITEM_KEY;
if (convert) {
- if (*start != round_down(*start, extent_root->sectorsize)) {
+ if (*start != round_down(*start, info->sectorsize)) {
error("DATA chunk start not sectorsize aligned: %llu",
(unsigned long long)*start);
return -EINVAL;
@@ -1188,9 +1188,9 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
btrfs_set_stack_chunk_num_stripes(chunk, num_stripes);
btrfs_set_stack_chunk_io_align(chunk, stripe_len);
btrfs_set_stack_chunk_io_width(chunk, stripe_len);
- btrfs_set_stack_chunk_sector_size(chunk, extent_root->sectorsize);
+ btrfs_set_stack_chunk_sector_size(chunk, info->sectorsize);
btrfs_set_stack_chunk_sub_stripes(chunk, sub_stripes);
- map->sector_size = extent_root->sectorsize;
+ map->sector_size = info->sectorsize;
map->stripe_len = stripe_len;
map->io_align = stripe_len;
map->io_width = stripe_len;
@@ -1685,6 +1685,7 @@ int btrfs_check_chunk_valid(struct btrfs_root *root,
u16 num_stripes;
u16 sub_stripes;
u64 type;
+ u32 sectorsize = root->fs_info->sectorsize;
length = btrfs_chunk_length(leaf, chunk);
stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
@@ -1695,16 +1696,16 @@ int btrfs_check_chunk_valid(struct btrfs_root *root,
/*
* These valid checks may be insufficient to cover every corner cases.
*/
- if (!IS_ALIGNED(logical, root->sectorsize)) {
+ if (!IS_ALIGNED(logical, sectorsize)) {
error("invalid chunk logical %llu", logical);
return -EIO;
}
- if (btrfs_chunk_sector_size(leaf, chunk) != root->sectorsize) {
+ if (btrfs_chunk_sector_size(leaf, chunk) != sectorsize) {
error("invalid chunk sectorsize %llu",
(unsigned long long)btrfs_chunk_sector_size(leaf, chunk));
return -EIO;
}
- if (!length || !IS_ALIGNED(length, root->sectorsize)) {
+ if (!length || !IS_ALIGNED(length, sectorsize)) {
error("invalid chunk length %llu", length);
return -EIO;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 24/32] btrfs-progs: Refactor sectorsize users in free-space-tree.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (22 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 23/32] btrfs-progs: Refactor sectorsize users in volumes.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 25/32] btrfs-progs: Refactor sectorsize in convert/source-fs.c Qu Wenruo
` (8 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
free-space-tree.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/free-space-tree.c b/free-space-tree.c
index f3a51263..69a4eca8 100644
--- a/free-space-tree.c
+++ b/free-space-tree.c
@@ -205,7 +205,7 @@ static int load_free_space_bitmaps(struct btrfs_fs_info *fs_info,
offset = key.objectid;
while (offset < key.objectid + key.offset) {
bit = free_space_test_bit(block_group, path, offset,
- root->sectorsize);
+ fs_info->sectorsize);
if (prev_bit == 0 && bit == 1) {
extent_start = offset;
} else if (prev_bit == 1 && bit == 0) {
@@ -213,7 +213,7 @@ static int load_free_space_bitmaps(struct btrfs_fs_info *fs_info,
extent_count++;
}
prev_bit = bit;
- offset += root->sectorsize;
+ offset += fs_info->sectorsize;
}
}
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 25/32] btrfs-progs: Refactor sectorsize in convert/source-fs.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (23 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 24/32] btrfs-progs: Refactor sectorsize users in free-space-tree.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 26/32] btrfs-progs: Refactor sectorsize users in convert/main.c Qu Wenruo
` (7 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
convert/source-fs.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/convert/source-fs.c b/convert/source-fs.c
index 80e4e418..59e36095 100644
--- a/convert/source-fs.c
+++ b/convert/source-fs.c
@@ -68,9 +68,10 @@ int block_iterate_proc(u64 disk_block, u64 file_block,
int do_barrier;
struct btrfs_root *root = idata->root;
struct btrfs_block_group_cache *cache;
- u64 bytenr = disk_block * root->sectorsize;
+ u32 sectorsize = root->fs_info->sectorsize;
+ u64 bytenr = disk_block * sectorsize;
- sb_region = intersect_with_sb(bytenr, root->sectorsize);
+ sb_region = intersect_with_sb(bytenr, sectorsize);
do_barrier = sb_region || disk_block >= idata->boundary;
if ((idata->num_blocks > 0 && do_barrier) ||
(file_block > idata->first_block + idata->num_blocks) ||
@@ -102,7 +103,7 @@ int block_iterate_proc(u64 disk_block, u64 file_block,
idata->first_block = file_block;
idata->disk_block = disk_block;
- idata->boundary = bytenr / root->sectorsize;
+ idata->boundary = bytenr / sectorsize;
}
idata->num_blocks++;
fail:
@@ -195,9 +196,10 @@ int record_file_blocks(struct blk_iterate_data *data,
struct btrfs_root *root = data->root;
struct btrfs_root *convert_root = data->convert_root;
struct btrfs_path path;
- u64 file_pos = file_block * root->sectorsize;
- u64 old_disk_bytenr = disk_block * root->sectorsize;
- u64 num_bytes = num_blocks * root->sectorsize;
+ u32 sectorsize = root->fs_info->sectorsize;
+ u64 file_pos = file_block * sectorsize;
+ u64 old_disk_bytenr = disk_block * sectorsize;
+ u64 num_bytes = num_blocks * sectorsize;
u64 cur_off = old_disk_bytenr;
/* Hole, pass it to record_file_extent directly */
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 26/32] btrfs-progs: Refactor sectorsize users in convert/main.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (24 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 25/32] btrfs-progs: Refactor sectorsize in convert/source-fs.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 27/32] btrfs-progs: Refactor sectorsize users in convert/source-ext2.c Qu Wenruo
` (6 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
convert/main.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/convert/main.c b/convert/main.c
index c56382e9..bf050132 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -159,7 +159,7 @@ static int csum_disk_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 disk_bytenr, u64 num_bytes)
{
- u32 blocksize = root->sectorsize;
+ u32 blocksize = root->fs_info->sectorsize;
u64 offset;
char *buffer;
int ret = 0;
@@ -199,12 +199,12 @@ static int create_image_file_range(struct btrfs_trans_handle *trans,
int ret;
u32 datacsum = convert_flags & CONVERT_FLAG_DATACSUM;
- if (bytenr != round_down(bytenr, root->sectorsize)) {
+ if (bytenr != round_down(bytenr, root->fs_info->sectorsize)) {
error("bytenr not sectorsize aligned: %llu",
(unsigned long long)bytenr);
return -EINVAL;
}
- if (len != round_down(len, root->sectorsize)) {
+ if (len != round_down(len, root->fs_info->sectorsize)) {
error("length not sectorsize aligned: %llu",
(unsigned long long)len);
return -EINVAL;
@@ -293,7 +293,7 @@ static int create_image_file_range(struct btrfs_trans_handle *trans,
bg_cache->key.offset - bytenr);
}
- if (len != round_down(len, root->sectorsize)) {
+ if (len != round_down(len, root->fs_info->sectorsize)) {
error("remaining length not sectorsize aligned: %llu",
(unsigned long long)len);
return -EINVAL;
@@ -346,7 +346,7 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans,
cur_off = max(cache->start, cur_off);
cur_len = min(cache->start + cache->size, range_end(range)) -
cur_off;
- BUG_ON(cur_len < root->sectorsize);
+ BUG_ON(cur_len < root->fs_info->sectorsize);
/* reserve extent for the data */
ret = btrfs_reserve_extent(trans, root, cur_len, 0, 0, (u64)-1,
@@ -1011,7 +1011,8 @@ static int make_convert_data_block_groups(struct btrfs_trans_handle *trans,
*/
max_chunk_size = cfg->num_bytes / 10;
max_chunk_size = min((u64)(1024 * 1024 * 1024), max_chunk_size);
- max_chunk_size = round_down(max_chunk_size, extent_root->sectorsize);
+ max_chunk_size = round_down(max_chunk_size,
+ extent_root->fs_info->sectorsize);
for (cache = first_cache_extent(data_chunks); cache;
cache = next_cache_extent(cache)) {
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 27/32] btrfs-progs: Refactor sectorsize users in convert/source-ext2.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (25 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 26/32] btrfs-progs: Refactor sectorsize users in convert/main.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 28/32] btrfs-progs: Refactor sectorsize users in cmds-inspect-dump-tree.c Qu Wenruo
` (5 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
convert/source-ext2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/convert/source-ext2.c b/convert/source-ext2.c
index 1b0576b1..d12681b5 100644
--- a/convert/source-ext2.c
+++ b/convert/source-ext2.c
@@ -289,7 +289,7 @@ static int ext2_create_file_extents(struct btrfs_trans_handle *trans,
char *buffer = NULL;
errcode_t err;
u32 last_block;
- u32 sectorsize = root->sectorsize;
+ u32 sectorsize = root->fs_info->sectorsize;
u64 inode_size = btrfs_stack_inode_size(btrfs_inode);
struct blk_iterate_data data;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 28/32] btrfs-progs: Refactor sectorsize users in cmds-inspect-dump-tree.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (26 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 27/32] btrfs-progs: Refactor sectorsize users in convert/source-ext2.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 29/32] btrfs-progs: Remove block size members in btrfs_root Qu Wenruo
` (4 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-inspect-dump-tree.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c
index 5a5ca536..869ad6ba 100644
--- a/cmds-inspect-dump-tree.c
+++ b/cmds-inspect-dump-tree.c
@@ -49,7 +49,7 @@ static void print_extents(struct btrfs_root *root, struct extent_buffer *eb)
return;
}
- size = root->nodesize;
+ size = root->fs_info->nodesize;
nr = btrfs_header_nritems(eb);
for (i = 0; i < nr; i++) {
next = read_tree_block(root, btrfs_node_blockptr(eb, i),
@@ -313,7 +313,7 @@ int cmd_inspect_dump_tree(int argc, char **argv)
if (block_only) {
leaf = read_tree_block(root,
block_only,
- root->nodesize, 0);
+ info->nodesize, 0);
if (extent_buffer_uptodate(leaf) &&
btrfs_header_level(leaf) != 0) {
@@ -324,7 +324,7 @@ int cmd_inspect_dump_tree(int argc, char **argv)
if (!leaf) {
leaf = read_tree_block(root,
block_only,
- root->nodesize, 0);
+ info->nodesize, 0);
}
if (!extent_buffer_uptodate(leaf)) {
error("failed to read %llu",
@@ -441,8 +441,7 @@ again:
read_extent_buffer(leaf, &ri, offset, sizeof(ri));
buf = read_tree_block(tree_root_scan,
btrfs_root_bytenr(&ri),
- tree_root_scan->nodesize,
- 0);
+ info->nodesize, 0);
if (!extent_buffer_uptodate(buf))
goto next;
if (tree_id && found_key.objectid != tree_id) {
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 29/32] btrfs-progs: Remove block size members in btrfs_root
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (27 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 28/32] btrfs-progs: Refactor sectorsize users in cmds-inspect-dump-tree.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 30/32] btrfs-progs: Refactor btrfs_root paramters in btrfs-corrupt-block.c Qu Wenruo
` (3 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Finally, we can get rid of per tree block size members now.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
ctree.h | 9 ---------
disk-io.c | 3 ---
2 files changed, 12 deletions(-)
diff --git a/ctree.h b/ctree.h
index 84298c7b..602c9562 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1166,15 +1166,6 @@ struct btrfs_root {
u64 objectid;
u64 last_trans;
- /* data allocations are done in sectorsize units */
- u32 sectorsize;
-
- /* node allocations are done in nodesize units */
- u32 nodesize;
-
- /* leaf allocations are done in nodesize units */
- u32 stripesize;
-
int ref_cows;
int track_dirty;
diff --git a/disk-io.c b/disk-io.c
index 89e35c92..553073a4 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -481,9 +481,6 @@ void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
{
root->node = NULL;
root->commit_root = NULL;
- root->sectorsize = fs_info->sectorsize;
- root->nodesize = fs_info->nodesize;
- root->stripesize = fs_info->stripesize;
root->ref_cows = 0;
root->track_dirty = 0;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 30/32] btrfs-progs: Refactor btrfs_root paramters in btrfs-corrupt-block.c
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (28 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 29/32] btrfs-progs: Remove block size members in btrfs_root Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 31/32] btrfs-progs: Refactor read_tree_block to get rid of btrfs_root Qu Wenruo
` (2 subsequent siblings)
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Refactor the following functions and its callers to get rid of
incorrectly passed btrfs_root parameters:
1) corrupt_keys()
2) corrupt_metadata_block()
The only reason passing btrfs_root for them is to get block sizes.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
btrfs-corrupt-block.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 20a4c1df..5649a00e 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -126,7 +126,7 @@ static void print_usage(int ret)
}
static void corrupt_keys(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
+ struct btrfs_fs_info *fs_info,
struct extent_buffer *eb)
{
int slot;
@@ -158,22 +158,22 @@ static void corrupt_keys(struct btrfs_trans_handle *trans,
btrfs_mark_buffer_dirty(eb);
if (!trans) {
u16 csum_size =
- btrfs_super_csum_size(root->fs_info->super_copy);
+ btrfs_super_csum_size(fs_info->super_copy);
csum_tree_block_size(eb, csum_size, 0);
write_extent_to_disk(eb);
}
}
-static int corrupt_keys_in_block(struct btrfs_root *root, u64 bytenr)
+static int corrupt_keys_in_block(struct btrfs_fs_info *fs_info, u64 bytenr)
{
struct extent_buffer *eb;
- eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0);
+ eb = read_tree_block_fs_info(fs_info, bytenr, fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb))
return -EIO;;
- corrupt_keys(NULL, root, eb);
+ corrupt_keys(NULL, fs_info, eb);
free_extent_buffer(eb);
return 0;
}
@@ -745,10 +745,11 @@ static void shift_items(struct btrfs_root *root, struct extent_buffer *eb)
}
}
-static int corrupt_metadata_block(struct btrfs_root *root, u64 block,
+static int corrupt_metadata_block(struct btrfs_fs_info *fs_info, u64 block,
char *field)
{
struct btrfs_trans_handle *trans;
+ struct btrfs_root *root;
struct btrfs_path *path;
struct extent_buffer *eb;
struct btrfs_key key, root_key;
@@ -764,7 +765,7 @@ static int corrupt_metadata_block(struct btrfs_root *root, u64 block,
return -EINVAL;
}
- eb = read_tree_block(root, block, root->fs_info->nodesize, 0);
+ eb = read_tree_block_fs_info(fs_info, block, fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb)) {
fprintf(stderr, "Couldn't read in tree block %s\n", field);
return -EINVAL;
@@ -781,7 +782,7 @@ static int corrupt_metadata_block(struct btrfs_root *root, u64 block,
root_key.type = BTRFS_ROOT_ITEM_KEY;
root_key.offset = (u64)-1;
- root = btrfs_read_fs_root(root->fs_info, &root_key);
+ root = btrfs_read_fs_root(fs_info, &root_key);
if (IS_ERR(root)) {
fprintf(stderr, "Couldn't find owner root %llu\n",
key.objectid);
@@ -1295,7 +1296,8 @@ int main(int argc, char **argv)
if (metadata_block) {
if (*field == 0)
print_usage(1);
- ret = corrupt_metadata_block(root, metadata_block, field);
+ ret = corrupt_metadata_block(root->fs_info, metadata_block,
+ field);
goto out_close;
}
if (corrupt_di) {
@@ -1358,7 +1360,7 @@ int main(int argc, char **argv)
while (bytes > 0) {
if (corrupt_block_keys) {
- corrupt_keys_in_block(root, logical);
+ corrupt_keys_in_block(root->fs_info, logical);
} else {
struct extent_buffer *eb;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 31/32] btrfs-progs: Refactor read_tree_block to get rid of btrfs_root
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (29 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 30/32] btrfs-progs: Refactor btrfs_root paramters in btrfs-corrupt-block.c Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-18 3:38 ` [PATCH 32/32] btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root parameter Qu Wenruo
2017-05-29 18:07 ` [PATCH 00/32] btrfs_fs_info refactoring David Sterba
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
The only reasom read_tree_block() needs a btrfs_root parameter is to get
its node/sector size.
And long ago, I have already introduced a compactible interface,
read_tree_block_fs_info() to pass btrfs_fs_info instead of btrfs_root.
Since we have cleaned up all root->sector/node/stripesize users, we
should be OK to refactor read_tree_block() function.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
backref.c | 6 +++---
btrfs-corrupt-block.c | 9 +++++----
btrfstune.c | 2 +-
cmds-check.c | 24 ++++++++++++------------
cmds-inspect-dump-tree.c | 10 +++++-----
cmds-inspect-tree-stats.c | 2 +-
cmds-restore.c | 4 ++--
ctree.c | 2 +-
disk-io.c | 18 ++++++++++--------
disk-io.h | 9 +--------
find-root.c | 3 +--
image/main.c | 14 ++++++++------
print-tree.c | 3 ++-
qgroup-verify.c | 2 +-
14 files changed, 53 insertions(+), 55 deletions(-)
diff --git a/backref.c b/backref.c
index 31681a85..ce12bbdf 100644
--- a/backref.c
+++ b/backref.c
@@ -450,7 +450,7 @@ static int __add_missing_keys(struct btrfs_fs_info *fs_info,
if (ref->key_for_search.type)
continue;
BUG_ON(!ref->wanted_disk_byte);
- eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte,
+ eb = read_tree_block(fs_info, ref->wanted_disk_byte,
fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb)) {
free_extent_buffer(eb);
@@ -805,8 +805,8 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
u32 bsz;
struct extent_buffer *eb;
bsz = fs_info->nodesize;
- eb = read_tree_block(fs_info->extent_root,
- ref->parent, bsz, 0);
+ eb = read_tree_block(fs_info,
+ ref->parent, bsz, 0);
if (!extent_buffer_uptodate(eb)) {
free_extent_buffer(eb);
ret = -EIO;
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 5649a00e..f29f22d2 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -169,7 +169,7 @@ static int corrupt_keys_in_block(struct btrfs_fs_info *fs_info, u64 bytenr)
{
struct extent_buffer *eb;
- eb = read_tree_block_fs_info(fs_info, bytenr, fs_info->nodesize, 0);
+ eb = read_tree_block(fs_info, bytenr, fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb))
return -EIO;;
@@ -278,6 +278,7 @@ static void btrfs_corrupt_extent_tree(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct extent_buffer *eb)
{
+ struct btrfs_fs_info *fs_info = root->fs_info;
int i;
if (!eb)
@@ -296,8 +297,8 @@ static void btrfs_corrupt_extent_tree(struct btrfs_trans_handle *trans,
for (i = 0; i < btrfs_header_nritems(eb); i++) {
struct extent_buffer *next;
- next = read_tree_block(root, btrfs_node_blockptr(eb, i),
- root->fs_info->nodesize,
+ next = read_tree_block(fs_info, btrfs_node_blockptr(eb, i),
+ fs_info->nodesize,
btrfs_node_ptr_generation(eb, i));
if (!extent_buffer_uptodate(next))
continue;
@@ -765,7 +766,7 @@ static int corrupt_metadata_block(struct btrfs_fs_info *fs_info, u64 block,
return -EINVAL;
}
- eb = read_tree_block_fs_info(fs_info, block, fs_info->nodesize, 0);
+ eb = read_tree_block(fs_info, block, fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb)) {
fprintf(stderr, "Couldn't read in tree block %s\n", field);
return -EINVAL;
diff --git a/btrfstune.c b/btrfstune.c
index 0a6ad9ca..b5a1c2fe 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -149,7 +149,7 @@ static int change_extents_uuid(struct btrfs_fs_info *fs_info)
goto next;
bytenr = key.objectid;
- eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0);
+ eb = read_tree_block(fs_info, bytenr, fs_info->nodesize, 0);
if (IS_ERR(eb)) {
error("failed to read tree block: %llu", bytenr);
ret = PTR_ERR(eb);
diff --git a/cmds-check.c b/cmds-check.c
index ce479855..84148b67 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -2183,7 +2183,7 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
if (!next || !btrfs_buffer_uptodate(next, ptr_gen)) {
free_extent_buffer(next);
reada_walk_down(root, cur, path->slots[*level]);
- next = read_tree_block(root, bytenr, blocksize,
+ next = read_tree_block(root->fs_info, bytenr, blocksize,
ptr_gen);
if (!extent_buffer_uptodate(next)) {
struct btrfs_key node_key;
@@ -2298,7 +2298,7 @@ static int walk_down_tree_v2(struct btrfs_root *root, struct btrfs_path *path,
if (!next || !btrfs_buffer_uptodate(next, ptr_gen)) {
free_extent_buffer(next);
reada_walk_down(root, cur, path->slots[*level]);
- next = read_tree_block(root, bytenr, blocksize,
+ next = read_tree_block(root->fs_info, bytenr, blocksize,
ptr_gen);
if (!extent_buffer_uptodate(next)) {
struct btrfs_key node_key;
@@ -7670,7 +7670,7 @@ static int run_next_block(struct btrfs_root *root,
}
/* fixme, get the real parent transid */
- buf = read_tree_block(root, bytenr, size, gen);
+ buf = read_tree_block(root->fs_info, bytenr, size, gen);
if (!extent_buffer_uptodate(buf)) {
record_bad_block_io(root->fs_info,
extent_cache, bytenr, size);
@@ -9783,7 +9783,7 @@ static int deal_root_from_list(struct list_head *list,
rec = list_entry(list->next,
struct root_item_record, list);
last = 0;
- buf = read_tree_block(root->fs_info->tree_root,
+ buf = read_tree_block(root->fs_info,
rec->bytenr, rec->level_size, 0);
if (!extent_buffer_uptodate(buf)) {
free_extent_buffer(buf);
@@ -10429,7 +10429,7 @@ static int query_tree_block_level(struct btrfs_fs_info *fs_info, u64 bytenr)
btrfs_release_path(&path);
/* Get level from tree block as an alternative source */
- eb = read_tree_block_fs_info(fs_info, bytenr, nodesize, transid);
+ eb = read_tree_block(fs_info, bytenr, nodesize, transid);
if (!extent_buffer_uptodate(eb)) {
free_extent_buffer(eb);
return -EIO;
@@ -10482,7 +10482,7 @@ static int check_tree_block_backref(struct btrfs_fs_info *fs_info, u64 root_id,
}
/* Read out the tree block to get item/node key */
- eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0);
+ eb = read_tree_block(fs_info, bytenr, root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(eb)) {
err |= REFERENCER_MISSING;
free_extent_buffer(eb);
@@ -10584,7 +10584,7 @@ static int check_shared_block_backref(struct btrfs_fs_info *fs_info,
int found_parent = 0;
int i;
- eb = read_tree_block_fs_info(fs_info, parent, nodesize, 0);
+ eb = read_tree_block(fs_info, parent, nodesize, 0);
if (!extent_buffer_uptodate(eb))
goto out;
@@ -10738,7 +10738,7 @@ static int check_shared_data_backref(struct btrfs_fs_info *fs_info,
int found_parent = 0;
int i;
- eb = read_tree_block_fs_info(fs_info, parent, nodesize, 0);
+ eb = read_tree_block(fs_info, parent, nodesize, 0);
if (!extent_buffer_uptodate(eb))
goto out;
@@ -11505,7 +11505,8 @@ static int traverse_tree_block(struct btrfs_root *root,
* As a btrfs tree has most 8 levels (0..7), so it's quite safe
* to call the function itself.
*/
- eb = read_tree_block(root, blocknr, root->fs_info->nodesize, 0);
+ eb = read_tree_block(root->fs_info, blocknr,
+ root->fs_info->nodesize, 0);
if (extent_buffer_uptodate(eb)) {
ret = traverse_tree_block(root, eb);
err |= ret;
@@ -11691,8 +11692,7 @@ static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
* in, but for now this doesn't actually use the root so
* just pass in extent_root.
*/
- tmp = read_tree_block(fs_info->extent_root, bytenr,
- nodesize, 0);
+ tmp = read_tree_block(fs_info, bytenr, nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
fprintf(stderr, "Error reading root block\n");
return -EIO;
@@ -11710,7 +11710,7 @@ static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
continue;
}
- tmp = read_tree_block(fs_info->extent_root, bytenr,
+ tmp = read_tree_block(fs_info, bytenr,
nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
fprintf(stderr, "Error reading tree block\n");
diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c
index 869ad6ba..93dff086 100644
--- a/cmds-inspect-dump-tree.c
+++ b/cmds-inspect-dump-tree.c
@@ -52,7 +52,8 @@ static void print_extents(struct btrfs_root *root, struct extent_buffer *eb)
size = root->fs_info->nodesize;
nr = btrfs_header_nritems(eb);
for (i = 0; i < nr; i++) {
- next = read_tree_block(root, btrfs_node_blockptr(eb, i),
+ next = read_tree_block(root->fs_info,
+ btrfs_node_blockptr(eb, i),
size, btrfs_node_ptr_generation(eb, i));
if (!extent_buffer_uptodate(next))
continue;
@@ -311,7 +312,7 @@ int cmd_inspect_dump_tree(int argc, char **argv)
}
if (block_only) {
- leaf = read_tree_block(root,
+ leaf = read_tree_block(info,
block_only,
info->nodesize, 0);
@@ -322,7 +323,7 @@ int cmd_inspect_dump_tree(int argc, char **argv)
}
if (!leaf) {
- leaf = read_tree_block(root,
+ leaf = read_tree_block(info,
block_only,
info->nodesize, 0);
}
@@ -439,8 +440,7 @@ again:
offset = btrfs_item_ptr_offset(leaf, slot);
read_extent_buffer(leaf, &ri, offset, sizeof(ri));
- buf = read_tree_block(tree_root_scan,
- btrfs_root_bytenr(&ri),
+ buf = read_tree_block(info, btrfs_root_bytenr(&ri),
info->nodesize, 0);
if (!extent_buffer_uptodate(buf))
goto next;
diff --git a/cmds-inspect-tree-stats.c b/cmds-inspect-tree-stats.c
index ecb33ce2..05f4f616 100644
--- a/cmds-inspect-tree-stats.c
+++ b/cmds-inspect-tree-stats.c
@@ -153,7 +153,7 @@ static int walk_nodes(struct btrfs_root *root, struct btrfs_path *path,
path->slots[level] = i;
if ((level - 1) > 0 || find_inline) {
- tmp = read_tree_block(root, cur_blocknr,
+ tmp = read_tree_block(root->fs_info, cur_blocknr,
nodesize,
btrfs_node_ptr_generation(b, i));
if (!extent_buffer_uptodate(tmp)) {
diff --git a/cmds-restore.c b/cmds-restore.c
index 09388b29..ae01430c 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -1255,7 +1255,7 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location,
if (!root_location)
root_location = btrfs_super_root(fs_info->super_copy);
generation = btrfs_super_generation(fs_info->super_copy);
- root->node = read_tree_block(root, root_location,
+ root->node = read_tree_block(fs_info, root_location,
fs_info->nodesize, generation);
if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Error opening tree root\n");
@@ -1502,7 +1502,7 @@ int cmd_restore(int argc, char **argv)
if (fs_location != 0) {
free_extent_buffer(root->node);
- root->node = read_tree_block(root, fs_location,
+ root->node = read_tree_block(root->fs_info, fs_location,
root->fs_info->nodesize, 0);
if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Failed to read fs location\n");
diff --git a/ctree.c b/ctree.c
index 266a3cf2..09273818 100644
--- a/ctree.c
+++ b/ctree.c
@@ -649,7 +649,7 @@ struct extent_buffer *read_node_slot(struct btrfs_root *root,
if (level == 0)
return NULL;
- return read_tree_block(root, btrfs_node_blockptr(parent, slot),
+ return read_tree_block(root->fs_info, btrfs_node_blockptr(parent, slot),
root->fs_info->nodesize,
btrfs_node_ptr_generation(parent, slot));
}
diff --git a/disk-io.c b/disk-io.c
index 553073a4..ec2f52af 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -306,7 +306,7 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirr
return 0;
}
-struct extent_buffer* read_tree_block_fs_info(
+struct extent_buffer* read_tree_block(
struct btrfs_fs_info *fs_info, u64 bytenr, u32 blocksize,
u64 parent_transid)
{
@@ -634,8 +634,9 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
blocksize = fs_info->nodesize;
generation = btrfs_root_generation(&root->root_item);
- root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
- blocksize, generation);
+ root->node = read_tree_block(fs_info,
+ btrfs_root_bytenr(&root->root_item),
+ blocksize, generation);
if (!extent_buffer_uptodate(root->node))
return -EIO;
@@ -663,7 +664,7 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
btrfs_setup_root(log_root, fs_info,
BTRFS_TREE_LOG_OBJECTID);
- log_root->node = read_tree_block(tree_root, blocknr,
+ log_root->node = read_tree_block(fs_info, blocknr,
blocksize,
btrfs_super_generation(disk_super) + 1);
@@ -752,8 +753,9 @@ out:
}
generation = btrfs_root_generation(&root->root_item);
blocksize = fs_info->nodesize;
- root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
- blocksize, generation);
+ root->node = read_tree_block(fs_info,
+ btrfs_root_bytenr(&root->root_item),
+ blocksize, generation);
if (!extent_buffer_uptodate(root->node)) {
free(root);
return ERR_PTR(-EIO);
@@ -1012,7 +1014,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
generation = btrfs_backup_tree_root_gen(backup);
}
- root->node = read_tree_block(root, root_tree_bytenr, blocksize,
+ root->node = read_tree_block(fs_info, root_tree_bytenr, blocksize,
generation);
if (!extent_buffer_uptodate(root->node)) {
fprintf(stderr, "Couldn't read tree root\n");
@@ -1197,7 +1199,7 @@ int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info,
else
generation = 0;
- fs_info->chunk_root->node = read_tree_block(fs_info->chunk_root,
+ fs_info->chunk_root->node = read_tree_block(fs_info,
chunk_root_bytenr,
fs_info->nodesize,
generation);
diff --git a/disk-io.h b/disk-io.h
index b4d02275..b097785a 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -115,16 +115,9 @@ static inline u64 btrfs_sb_offset(int mirror)
struct btrfs_device;
int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirror);
-struct extent_buffer* read_tree_block_fs_info(
+struct extent_buffer* read_tree_block(
struct btrfs_fs_info *fs_info, u64 bytenr, u32 blocksize,
u64 parent_transid);
-static inline struct extent_buffer* read_tree_block(
- struct btrfs_root *root, u64 bytenr, u32 blocksize,
- u64 parent_transid)
-{
- return read_tree_block_fs_info(root->fs_info, bytenr, blocksize,
- parent_transid);
-}
int read_extent_data(struct btrfs_root *root, char *data, u64 logical,
u64 *len, int mirror);
diff --git a/find-root.c b/find-root.c
index 89d36119..1b41b217 100644
--- a/find-root.c
+++ b/find-root.c
@@ -133,8 +133,7 @@ int btrfs_find_root_search(struct btrfs_fs_info *fs_info,
for (offset = chunk_offset;
offset < chunk_offset + chunk_size;
offset += nodesize) {
- eb = read_tree_block_fs_info(fs_info, offset, nodesize,
- 0);
+ eb = read_tree_block(fs_info, offset, nodesize, 0);
if (!eb || IS_ERR(eb))
continue;
ret = add_eb_to_result(eb, result, nodesize, filter,
diff --git a/image/main.c b/image/main.c
index 6a4ccfaf..b41739cf 100644
--- a/image/main.c
+++ b/image/main.c
@@ -973,7 +973,8 @@ static int flush_pending(struct metadump_struct *md, int done)
while (!md->data && size > 0) {
u64 this_read = min(blocksize, size);
- eb = read_tree_block(md->root, start, this_read, 0);
+ eb = read_tree_block(md->root->fs_info, start,
+ this_read, 0);
if (!extent_buffer_uptodate(eb)) {
free(async->buffer);
free(async);
@@ -1077,13 +1078,14 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
struct extent_buffer *tmp;
struct btrfs_root_item *ri;
struct btrfs_key key;
+ struct btrfs_fs_info *fs_info = root->fs_info;
u64 bytenr;
int level;
int nritems = 0;
int i = 0;
int ret;
- ret = add_extent(btrfs_header_bytenr(eb), root->fs_info->nodesize,
+ ret = add_extent(btrfs_header_bytenr(eb), fs_info->nodesize,
metadump, 0);
if (ret) {
error("unable to add metadata block %llu: %d",
@@ -1103,8 +1105,8 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
continue;
ri = btrfs_item_ptr(eb, i, struct btrfs_root_item);
bytenr = btrfs_disk_root_bytenr(eb, ri);
- tmp = read_tree_block(root, bytenr,
- root->fs_info->nodesize, 0);
+ tmp = read_tree_block(fs_info, bytenr,
+ fs_info->nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
error("unable to read log root block");
return -EIO;
@@ -1115,8 +1117,8 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
return ret;
} else {
bytenr = btrfs_node_blockptr(eb, i);
- tmp = read_tree_block(root, bytenr,
- root->fs_info->nodesize, 0);
+ tmp = read_tree_block(fs_info, bytenr,
+ fs_info->nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
error("unable to read log root block");
return -EIO;
diff --git a/print-tree.c b/print-tree.c
index 1b15640b..07366e98 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -1314,7 +1314,8 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
return;
for (i = 0; i < nr; i++) {
- next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
+ next = read_tree_block(root->fs_info,
+ btrfs_node_blockptr(eb, i), size,
btrfs_node_ptr_generation(eb, i));
if (!extent_buffer_uptodate(next)) {
fprintf(stderr, "failed to read %llu in tree %llu\n",
diff --git a/qgroup-verify.c b/qgroup-verify.c
index 2f4b1c66..5162adbb 100644
--- a/qgroup-verify.c
+++ b/qgroup-verify.c
@@ -711,7 +711,7 @@ static int travel_tree(struct btrfs_fs_info *info, struct btrfs_root *root,
// printf("travel_tree: bytenr: %llu\tnum_bytes: %llu\tref_parent: %llu\n",
// bytenr, num_bytes, ref_parent);
- eb = read_tree_block(root, bytenr, num_bytes, 0);
+ eb = read_tree_block(info, bytenr, num_bytes, 0);
if (!extent_buffer_uptodate(eb))
return -EIO;
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH 32/32] btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root parameter
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (30 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 31/32] btrfs-progs: Refactor read_tree_block to get rid of btrfs_root Qu Wenruo
@ 2017-05-18 3:38 ` Qu Wenruo
2017-05-29 18:07 ` [PATCH 00/32] btrfs_fs_info refactoring David Sterba
32 siblings, 0 replies; 34+ messages in thread
From: Qu Wenruo @ 2017-05-18 3:38 UTC (permalink / raw)
To: linux-btrfs, dsterba
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-restore.c | 5 +++--
ctree.c | 37 ++++++++++++++++++++++---------------
ctree.h | 2 +-
3 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/cmds-restore.c b/cmds-restore.c
index ae01430c..06c88b26 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -181,6 +181,7 @@ static int next_leaf(struct btrfs_root *root, struct btrfs_path *path)
int offset = 1;
struct extent_buffer *c;
struct extent_buffer *next = NULL;
+ struct btrfs_fs_info *fs_info = root->fs_info;
again:
for (; level < BTRFS_MAX_LEVEL; level++) {
@@ -210,7 +211,7 @@ again:
if (path->reada)
reada_for_search(root, path, level, slot, 0);
- next = read_node_slot(root, c, slot);
+ next = read_node_slot(fs_info, c, slot);
if (extent_buffer_uptodate(next))
break;
offset++;
@@ -226,7 +227,7 @@ again:
break;
if (path->reada)
reada_for_search(root, path, level, 0, 0);
- next = read_node_slot(root, next, 0);
+ next = read_node_slot(fs_info, next, 0);
if (!extent_buffer_uptodate(next))
goto again;
}
diff --git a/ctree.c b/ctree.c
index 09273818..43f283c1 100644
--- a/ctree.c
+++ b/ctree.c
@@ -637,7 +637,7 @@ static int bin_search(struct extent_buffer *eb, struct btrfs_key *key,
slot);
}
-struct extent_buffer *read_node_slot(struct btrfs_root *root,
+struct extent_buffer *read_node_slot(struct btrfs_fs_info *fs_info,
struct extent_buffer *parent, int slot)
{
int level = btrfs_header_level(parent);
@@ -649,8 +649,8 @@ struct extent_buffer *read_node_slot(struct btrfs_root *root,
if (level == 0)
return NULL;
- return read_tree_block(root->fs_info, btrfs_node_blockptr(parent, slot),
- root->fs_info->nodesize,
+ return read_tree_block(fs_info, btrfs_node_blockptr(parent, slot),
+ fs_info->nodesize,
btrfs_node_ptr_generation(parent, slot));
}
@@ -662,6 +662,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
struct extent_buffer *mid;
struct extent_buffer *left = NULL;
struct extent_buffer *parent = NULL;
+ struct btrfs_fs_info *fs_info = root->fs_info;
int ret = 0;
int wret;
int pslot;
@@ -692,7 +693,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
return 0;
/* promote the child to a root */
- child = read_node_slot(root, mid, 0);
+ child = read_node_slot(fs_info, mid, 0);
BUG_ON(!extent_buffer_uptodate(child));
ret = btrfs_cow_block(trans, root, child, mid, 0, &child);
BUG_ON(ret);
@@ -715,7 +716,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
BTRFS_NODEPTRS_PER_BLOCK(root) / 4)
return 0;
- left = read_node_slot(root, parent, pslot - 1);
+ left = read_node_slot(fs_info, parent, pslot - 1);
if (extent_buffer_uptodate(left)) {
wret = btrfs_cow_block(trans, root, left,
parent, pslot - 1, &left);
@@ -724,7 +725,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
goto enospc;
}
}
- right = read_node_slot(root, parent, pslot + 1);
+ right = read_node_slot(fs_info, parent, pslot + 1);
if (extent_buffer_uptodate(right)) {
wret = btrfs_cow_block(trans, root, right,
parent, pslot + 1, &right);
@@ -854,6 +855,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
struct extent_buffer *mid;
struct extent_buffer *left = NULL;
struct extent_buffer *parent = NULL;
+ struct btrfs_fs_info *fs_info = root->fs_info;
int ret = 0;
int wret;
int pslot;
@@ -873,7 +875,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
if (!parent)
return 1;
- left = read_node_slot(root, parent, pslot - 1);
+ left = read_node_slot(fs_info, parent, pslot - 1);
/* first, try to make some room in the middle buffer */
if (extent_buffer_uptodate(left)) {
@@ -914,7 +916,7 @@ static int noinline push_nodes_for_insert(struct btrfs_trans_handle *trans,
}
free_extent_buffer(left);
}
- right= read_node_slot(root, parent, pslot + 1);
+ right= read_node_slot(fs_info, parent, pslot + 1);
/*
* then try to empty the right most buffer into the middle
@@ -1102,6 +1104,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
int ret;
int level;
int should_reada = p->reada;
+ struct btrfs_fs_info *fs_info = root->fs_info;
u8 lowest_level = 0;
lowest_level = p->lowest_level;
@@ -1169,7 +1172,7 @@ again:
reada_for_search(root, p, level, slot,
key->objectid);
- b = read_node_slot(root, b, slot);
+ b = read_node_slot(fs_info, b, slot);
if (!extent_buffer_uptodate(b))
return -EIO;
} else {
@@ -1644,6 +1647,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
struct extent_buffer *right;
struct extent_buffer *upper;
struct btrfs_disk_key disk_key;
+ struct btrfs_fs_info *fs_info = root->fs_info;
int slot;
u32 i;
int free_space;
@@ -1665,7 +1669,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
if (slot >= btrfs_header_nritems(upper) - 1)
return 1;
- right = read_node_slot(root, upper, slot + 1);
+ right = read_node_slot(fs_info, upper, slot + 1);
if (!extent_buffer_uptodate(right)) {
if (IS_ERR(right))
return PTR_ERR(right);
@@ -1797,6 +1801,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
struct btrfs_disk_key disk_key;
struct extent_buffer *right = path->nodes[0];
struct extent_buffer *left;
+ struct btrfs_fs_info *fs_info = root->fs_info;
int slot;
int i;
int free_space;
@@ -1821,7 +1826,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
return 1;
}
- left = read_node_slot(root, path->nodes[1], slot - 1);
+ left = read_node_slot(fs_info, path->nodes[1], slot - 1);
free_space = btrfs_leaf_free_space(root, left);
if (free_space < data_size) {
free_extent_buffer(left);
@@ -2770,6 +2775,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
int level = 1;
struct extent_buffer *c;
struct extent_buffer *next = NULL;
+ struct btrfs_fs_info *fs_info = root->fs_info;
while(level < BTRFS_MAX_LEVEL) {
if (!path->nodes[level])
@@ -2785,7 +2791,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
}
slot--;
- next = read_node_slot(root, c, slot);
+ next = read_node_slot(fs_info, c, slot);
if (!extent_buffer_uptodate(next)) {
if (IS_ERR(next))
return PTR_ERR(next);
@@ -2805,7 +2811,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
path->slots[level] = slot;
if (!level)
break;
- next = read_node_slot(root, next, slot);
+ next = read_node_slot(fs_info, next, slot);
if (!extent_buffer_uptodate(next)) {
if (IS_ERR(next))
return PTR_ERR(next);
@@ -2826,6 +2832,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
int level = 1;
struct extent_buffer *c;
struct extent_buffer *next = NULL;
+ struct btrfs_fs_info *fs_info = root->fs_info;
while(level < BTRFS_MAX_LEVEL) {
if (!path->nodes[level])
@@ -2843,7 +2850,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
if (path->reada)
reada_for_search(root, path, level, slot, 0);
- next = read_node_slot(root, c, slot);
+ next = read_node_slot(fs_info, c, slot);
if (!extent_buffer_uptodate(next))
return -EIO;
break;
@@ -2859,7 +2866,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
break;
if (path->reada)
reada_for_search(root, path, level, 0, 0);
- next = read_node_slot(root, next, 0);
+ next = read_node_slot(fs_info, next, 0);
if (!extent_buffer_uptodate(next))
return -EIO;
}
diff --git a/ctree.h b/ctree.h
index 602c9562..cf337ae5 100644
--- a/ctree.h
+++ b/ctree.h
@@ -2533,7 +2533,7 @@ btrfs_check_leaf(struct btrfs_root *root, struct btrfs_disk_key *parent_key,
struct extent_buffer *buf);
void reada_for_search(struct btrfs_root *root, struct btrfs_path *path,
int level, int slot, u64 objectid);
-struct extent_buffer *read_node_slot(struct btrfs_root *root,
+struct extent_buffer *read_node_slot(struct btrfs_fs_info *fs_info,
struct extent_buffer *parent, int slot);
int btrfs_previous_item(struct btrfs_root *root,
struct btrfs_path *path, u64 min_objectid,
--
2.13.0
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [PATCH 00/32] btrfs_fs_info refactoring
2017-05-18 3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
` (31 preceding siblings ...)
2017-05-18 3:38 ` [PATCH 32/32] btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root parameter Qu Wenruo
@ 2017-05-29 18:07 ` David Sterba
32 siblings, 0 replies; 34+ messages in thread
From: David Sterba @ 2017-05-29 18:07 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs, dsterba
On Thu, May 18, 2017 at 11:38:25AM +0800, Qu Wenruo wrote:
> The patchset can be fetched from my github:
> https://github.com/adam900710/btrfs-progs/tree/fs_info_refactor
>
> Which is based on v4.11-rc1.
>
> This quite scary patchset does a large refactoring (while still less than
> 500 LoC) to move sector/node/stripe size members from btrfs_root to
> btrfs_fs_info.
> (Patch 2~29)
>
> Also, refactor some functions which only uses btrfs_root parameter for
> block sizes. (Path 30~32)
> Refactored functions are:
> 1) read_tree_block() in disk-io.c
> 2) corrupt_keys() in btrfs-corrupt-block.c
> 3) corrupt_metadata_block() in btrfs-corrupt-block.c
> 4) read_node_slot() in ctree.c
>
> Such refactoring has already been done in kernel for some time.
>
> I'm pretty sure there are still quite some remaining, but I'd like to
> put them after this large patchset get merged.
>
> I have run test-fsck, test-convert (despite the quotation error) and
> test-misc. They all finished without problem.
>
> Despite the refactoring, I also synchronized the definition of
> btrfs_super_block, to make leafsize deprecated.
> (Patch 1)
>
> And less than 3 open-coded round_up are also refactored to round_up()
> macro.
>
> Qu Wenruo (32):
> btrfs-progs: Remove deprecated leafsize usage
> btrfs-progs: Introduce sectorsize nodesize and stripesize members for
> btrfs_fs_info
> btrfs-progs: Refactor block sizes users in disk-io.c
> btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.c
> btrfs-progs: Refactor block sizes users in ctree.c and ctree.h
> btrfs-progs: Refactor block sizes users in btrfs-map-logical.c
> btrfs-progs: Refactor block sizes users in chunk-recover.c
> btrfs-progs: Refactor block sizes users in backref.c
> btrfs-progs: Refactor block sizes users in cmds-restore.c
> btrfs-progs: Refactor nodesize user in extent_io.c
> btrfs-progs: Refactor nodesize users in image/main.c
> btrfs-progs: Refactor block sizes users in cmds-check.c
> btrfs-progs: Refactor nodesize user in btrfstune.c
> btrfs-progs: Refactor nodesize users in utils.c
> btrfs-progs: Refactor block sizes users in extent-tree.c
> btrfs-progs: Refactor nodesize user in print-tree.c
> btrfs-progs: Refactor nodesize users in qgroup-verify.c
> btrfs-progs: Refactor nodesize users in cmds-inspect-tree-stats.c
> btrfs-progs: Refactor sectorsize users in mkfs/main.c
> btrfs-progs: Refactor sectorsizes users in file-item.c
> btrfs-progs: Refactor sectorsize users in free-space-cache.c
> btrfs-progs: Refactor sectorsize users in file.c
> btrfs-progs: Refactor sectorsize users in volumes.c
> btrfs-progs: Refactor sectorsize users in free-space-tree.c
> btrfs-progs: Refactor sectorsize in convert/source-fs.c
> btrfs-progs: Refactor sectorsize users in convert/main.c
> btrfs-progs: Refactor sectorsize users in convert/source-ext2.c
> btrfs-progs: Refactor sectorsize users in cmds-inspect-dump-tree.c
> btrfs-progs: Remove block size members in btrfs_root
> btrfs-progs: Refactor btrfs_root paramters in btrfs-corrupt-block.c
> btrfs-progs: Refactor read_tree_block to get rid of btrfs_root
> btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root
> parameter
Applied, thanks.
^ permalink raw reply [flat|nested] 34+ messages in thread