btrfs-progs: Refactor write_all_supers and its callers to use btrfs_fs_info

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
master
Qu Wenruo 2017-06-13 17:19:27 +08:00 committed by David Sterba
parent bb3ecd59f2
commit a0d9de4e40
5 changed files with 31 additions and 31 deletions

View File

@ -93,7 +93,7 @@ int main(int argc, char **argv)
/* make the super writing code think we've read the first super */ /* make the super writing code think we've read the first super */
root->fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET; root->fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET;
ret = write_all_supers(root); ret = write_all_supers(root->fs_info);
/* we don't close the ctree or anything, because we don't want a real /* we don't close the ctree or anything, because we don't want a real
* transaction commit. We just want the super copy we pulled off the * transaction commit. We just want the super copy we pulled off the

View File

@ -242,7 +242,7 @@ static int change_fsid_prepare(struct btrfs_fs_info *fs_info)
btrfs_set_super_flags(fs_info->super_copy, flags); btrfs_set_super_flags(fs_info->super_copy, flags);
memcpy(fs_info->super_copy->fsid, fs_info->new_fsid, BTRFS_FSID_SIZE); memcpy(fs_info->super_copy->fsid, fs_info->new_fsid, BTRFS_FSID_SIZE);
ret = write_all_supers(tree_root); ret = write_all_supers(fs_info);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -260,7 +260,7 @@ static int change_fsid_done(struct btrfs_fs_info *fs_info)
flags &= ~BTRFS_SUPER_FLAG_CHANGING_FSID; flags &= ~BTRFS_SUPER_FLAG_CHANGING_FSID;
btrfs_set_super_flags(fs_info->super_copy, flags); btrfs_set_super_flags(fs_info->super_copy, flags);
return write_all_supers(fs_info->tree_root); return write_all_supers(fs_info);
} }
/* /*
@ -354,7 +354,7 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
BTRFS_FSID_SIZE); BTRFS_FSID_SIZE);
memcpy(fs_info->super_copy->fsid, fs_info->new_fsid, memcpy(fs_info->super_copy->fsid, fs_info->new_fsid,
BTRFS_FSID_SIZE); BTRFS_FSID_SIZE);
ret = write_all_supers(fs_info->tree_root); ret = write_all_supers(fs_info);
if (ret < 0) if (ret < 0)
goto out; goto out;

View File

@ -599,7 +599,7 @@ commit_tree:
BUG_ON(ret); BUG_ON(ret);
ret = __commit_transaction(trans, root); ret = __commit_transaction(trans, root);
BUG_ON(ret); BUG_ON(ret);
write_ctree_super(trans, root); write_ctree_super(trans, fs_info);
btrfs_finish_extent_commit(trans, fs_info->extent_root, btrfs_finish_extent_commit(trans, fs_info->extent_root,
&fs_info->pinned_extents); &fs_info->pinned_extents);
kfree(trans); kfree(trans);
@ -1631,7 +1631,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
return transid > 0 ? 0 : -1; return transid > 0 ? 0 : -1;
} }
static int write_dev_supers(struct btrfs_root *root, static int write_dev_supers(struct btrfs_fs_info *fs_info,
struct btrfs_super_block *sb, struct btrfs_super_block *sb,
struct btrfs_device *device) struct btrfs_device *device)
{ {
@ -1639,8 +1639,8 @@ static int write_dev_supers(struct btrfs_root *root,
u32 crc; u32 crc;
int i, ret; int i, ret;
if (root->fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) { if (fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) {
btrfs_set_super_bytenr(sb, root->fs_info->super_bytenr); btrfs_set_super_bytenr(sb, fs_info->super_bytenr);
crc = ~(u32)0; crc = ~(u32)0;
crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc, crc = btrfs_csum_data((char *)sb + BTRFS_CSUM_SIZE, crc,
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE); BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
@ -1650,9 +1650,9 @@ static int write_dev_supers(struct btrfs_root *root,
* super_copy is BTRFS_SUPER_INFO_SIZE bytes and is * super_copy is BTRFS_SUPER_INFO_SIZE bytes and is
* zero filled, we can use it directly * zero filled, we can use it directly
*/ */
ret = pwrite64(device->fd, root->fs_info->super_copy, ret = pwrite64(device->fd, fs_info->super_copy,
BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_SIZE,
root->fs_info->super_bytenr); fs_info->super_bytenr);
if (ret != BTRFS_SUPER_INFO_SIZE) if (ret != BTRFS_SUPER_INFO_SIZE)
goto write_err; goto write_err;
return 0; return 0;
@ -1674,7 +1674,7 @@ static int write_dev_supers(struct btrfs_root *root,
* super_copy is BTRFS_SUPER_INFO_SIZE bytes and is * super_copy is BTRFS_SUPER_INFO_SIZE bytes and is
* zero filled, we can use it directly * zero filled, we can use it directly
*/ */
ret = pwrite64(device->fd, root->fs_info->super_copy, ret = pwrite64(device->fd, fs_info->super_copy,
BTRFS_SUPER_INFO_SIZE, bytenr); BTRFS_SUPER_INFO_SIZE, bytenr);
if (ret != BTRFS_SUPER_INFO_SIZE) if (ret != BTRFS_SUPER_INFO_SIZE)
goto write_err; goto write_err;
@ -1691,17 +1691,17 @@ write_err:
return ret; return ret;
} }
int write_all_supers(struct btrfs_root *root) int write_all_supers(struct btrfs_fs_info *fs_info)
{ {
struct list_head *cur; struct list_head *cur;
struct list_head *head = &root->fs_info->fs_devices->devices; struct list_head *head = &fs_info->fs_devices->devices;
struct btrfs_device *dev; struct btrfs_device *dev;
struct btrfs_super_block *sb; struct btrfs_super_block *sb;
struct btrfs_dev_item *dev_item; struct btrfs_dev_item *dev_item;
int ret; int ret;
u64 flags; u64 flags;
sb = root->fs_info->super_copy; sb = fs_info->super_copy;
dev_item = &sb->dev_item; dev_item = &sb->dev_item;
list_for_each(cur, head) { list_for_each(cur, head) {
dev = list_entry(cur, struct btrfs_device, dev_list); dev = list_entry(cur, struct btrfs_device, dev_list);
@ -1722,36 +1722,36 @@ int write_all_supers(struct btrfs_root *root)
flags = btrfs_super_flags(sb); flags = btrfs_super_flags(sb);
btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN); btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN);
ret = write_dev_supers(root, sb, dev); ret = write_dev_supers(fs_info, sb, dev);
BUG_ON(ret); BUG_ON(ret);
} }
return 0; return 0;
} }
int write_ctree_super(struct btrfs_trans_handle *trans, int write_ctree_super(struct btrfs_trans_handle *trans,
struct btrfs_root *root) struct btrfs_fs_info *fs_info)
{ {
int ret; int ret;
struct btrfs_root *tree_root = root->fs_info->tree_root; struct btrfs_root *tree_root = fs_info->tree_root;
struct btrfs_root *chunk_root = root->fs_info->chunk_root; struct btrfs_root *chunk_root = fs_info->chunk_root;
if (root->fs_info->readonly) if (fs_info->readonly)
return 0; return 0;
btrfs_set_super_generation(root->fs_info->super_copy, btrfs_set_super_generation(fs_info->super_copy,
trans->transid); trans->transid);
btrfs_set_super_root(root->fs_info->super_copy, btrfs_set_super_root(fs_info->super_copy,
tree_root->node->start); tree_root->node->start);
btrfs_set_super_root_level(root->fs_info->super_copy, btrfs_set_super_root_level(fs_info->super_copy,
btrfs_header_level(tree_root->node)); btrfs_header_level(tree_root->node));
btrfs_set_super_chunk_root(root->fs_info->super_copy, btrfs_set_super_chunk_root(fs_info->super_copy,
chunk_root->node->start); chunk_root->node->start);
btrfs_set_super_chunk_root_level(root->fs_info->super_copy, btrfs_set_super_chunk_root_level(fs_info->super_copy,
btrfs_header_level(chunk_root->node)); btrfs_header_level(chunk_root->node));
btrfs_set_super_chunk_root_generation(root->fs_info->super_copy, btrfs_set_super_chunk_root_generation(fs_info->super_copy,
btrfs_header_generation(chunk_root->node)); btrfs_header_generation(chunk_root->node));
ret = write_all_supers(root); ret = write_all_supers(fs_info);
if (ret) if (ret)
fprintf(stderr, "failed to write new super block err %d\n", ret); fprintf(stderr, "failed to write new super block err %d\n", ret);
return ret; return ret;
@ -1773,14 +1773,14 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
BUG_ON(ret); BUG_ON(ret);
ret = __commit_transaction(trans, root); ret = __commit_transaction(trans, root);
BUG_ON(ret); BUG_ON(ret);
write_ctree_super(trans, root); write_ctree_super(trans, fs_info);
kfree(trans); kfree(trans);
} }
if (fs_info->finalize_on_close) { if (fs_info->finalize_on_close) {
btrfs_set_super_magic(fs_info->super_copy, BTRFS_MAGIC); btrfs_set_super_magic(fs_info->super_copy, BTRFS_MAGIC);
root->fs_info->finalize_on_close = 0; root->fs_info->finalize_on_close = 0;
ret = write_all_supers(root); ret = write_all_supers(fs_info);
if (ret) if (ret)
fprintf(stderr, fprintf(stderr,
"failed to write new super block err %d\n", ret); "failed to write new super block err %d\n", ret);

View File

@ -161,9 +161,9 @@ static inline int close_ctree(struct btrfs_root *root)
return close_ctree_fs_info(root->fs_info); return close_ctree_fs_info(root->fs_info);
} }
int write_all_supers(struct btrfs_root *root); int write_all_supers(struct btrfs_fs_info *fs_info);
int write_ctree_super(struct btrfs_trans_handle *trans, int write_ctree_super(struct btrfs_trans_handle *trans,
struct btrfs_root *root); struct btrfs_fs_info *fs_info);
int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
unsigned sbflags); unsigned sbflags);
int btrfs_map_bh_to_logical(struct btrfs_root *root, struct extent_buffer *bh, int btrfs_map_bh_to_logical(struct btrfs_root *root, struct extent_buffer *bh,

View File

@ -302,7 +302,7 @@ int btrfs_recover_superblocks(const char *dname,
} }
/* reset super_bytenr in order that we will rewrite all supers */ /* reset super_bytenr in order that we will rewrite all supers */
root->fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET; root->fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET;
ret = write_all_supers(root); ret = write_all_supers(root->fs_info);
if (!ret) if (!ret)
ret = 2; ret = 2;
else else