From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 7/8] btrfs-progs: Remove btrfs_fs_info::new_fsid
Date: Thu, 11 Oct 2018 18:04:03 +0300 [thread overview]
Message-ID: <1539270244-27076-8-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1539270244-27076-1-git-send-email-nborisov@suse.com>
This member was used only by btrfstune when using the old method to
change fsid. It's only an in-memory value with a very specific
purpose so it makes no sense to pollute a generic structure such as
btrfs_fs_info with it. Just remove it and pass it as a function
argument where pertinent. No functional changes.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
btrfstune.c | 46 +++++++++++++++++++++-------------------------
ctree.h | 1 -
2 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/btrfstune.c b/btrfstune.c
index c1e4fa8067e8..d093d26f288c 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -202,15 +202,15 @@ static int set_super_incompat_flags(struct btrfs_root *root, u64 flags)
return ret;
}
-static int change_buffer_header_uuid(struct extent_buffer *eb)
+static int change_buffer_header_uuid(struct extent_buffer *eb, uuid_t new_fsid)
{
struct btrfs_fs_info *fs_info = eb->fs_info;
int same_fsid = 1;
int same_chunk_tree_uuid = 1;
int ret;
- same_fsid = !memcmp_extent_buffer(eb, fs_info->new_fsid,
- btrfs_header_fsid(), BTRFS_FSID_SIZE);
+ same_fsid = !memcmp_extent_buffer(eb, new_fsid, btrfs_header_fsid(),
+ BTRFS_FSID_SIZE);
same_chunk_tree_uuid =
!memcmp_extent_buffer(eb, fs_info->new_chunk_tree_uuid,
btrfs_header_chunk_tree_uuid(eb),
@@ -218,7 +218,7 @@ static int change_buffer_header_uuid(struct extent_buffer *eb)
if (same_fsid && same_chunk_tree_uuid)
return 0;
if (!same_fsid)
- write_extent_buffer(eb, fs_info->new_fsid, btrfs_header_fsid(),
+ write_extent_buffer(eb, new_fsid, btrfs_header_fsid(),
BTRFS_FSID_SIZE);
if (!same_chunk_tree_uuid)
write_extent_buffer(eb, fs_info->new_chunk_tree_uuid,
@@ -229,7 +229,7 @@ static int change_buffer_header_uuid(struct extent_buffer *eb)
return ret;
}
-static int change_extents_uuid(struct btrfs_fs_info *fs_info)
+static int change_extents_uuid(struct btrfs_fs_info *fs_info, uuid_t new_fsid)
{
struct btrfs_root *root = fs_info->extent_root;
struct btrfs_path path;
@@ -268,7 +268,7 @@ static int change_extents_uuid(struct btrfs_fs_info *fs_info)
ret = PTR_ERR(eb);
goto out;
}
- ret = change_buffer_header_uuid(eb);
+ ret = change_buffer_header_uuid(eb, new_fsid);
free_extent_buffer(eb);
if (ret < 0) {
error("failed to change uuid of tree block: %llu",
@@ -290,27 +290,27 @@ static int change_extents_uuid(struct btrfs_fs_info *fs_info)
return ret;
}
-static int change_device_uuid(struct extent_buffer *eb, int slot)
+static int change_device_uuid(struct extent_buffer *eb, int slot,
+ uuid_t new_fsid)
{
struct btrfs_dev_item *di;
struct btrfs_fs_info *fs_info = eb->fs_info;
int ret = 0;
di = btrfs_item_ptr(eb, slot, struct btrfs_dev_item);
- if (!memcmp_extent_buffer(eb, fs_info->new_fsid,
+ if (!memcmp_extent_buffer(eb, new_fsid,
(unsigned long)btrfs_device_fsid(di),
BTRFS_FSID_SIZE))
return ret;
- write_extent_buffer(eb, fs_info->new_fsid,
- (unsigned long)btrfs_device_fsid(di),
+ write_extent_buffer(eb, new_fsid, (unsigned long)btrfs_device_fsid(di),
BTRFS_FSID_SIZE);
ret = write_tree_block(NULL, fs_info, eb);
return ret;
}
-static int change_devices_uuid(struct btrfs_fs_info *fs_info)
+static int change_devices_uuid(struct btrfs_fs_info *fs_info, uuid_t new_fsid)
{
struct btrfs_root *root = fs_info->chunk_root;
struct btrfs_path path;
@@ -328,7 +328,8 @@ static int change_devices_uuid(struct btrfs_fs_info *fs_info)
if (key.type != BTRFS_DEV_ITEM_KEY ||
key.objectid != BTRFS_DEV_ITEMS_OBJECTID)
goto next;
- ret = change_device_uuid(path.nodes[0], path.slots[0]);
+ ret = change_device_uuid(path.nodes[0], path.slots[0],
+ new_fsid);
if (ret < 0)
goto out;
next:
@@ -345,7 +346,7 @@ static int change_devices_uuid(struct btrfs_fs_info *fs_info)
return ret;
}
-static int change_fsid_prepare(struct btrfs_fs_info *fs_info)
+static int change_fsid_prepare(struct btrfs_fs_info *fs_info, uuid_t new_fsid)
{
struct btrfs_root *tree_root = fs_info->tree_root;
u64 flags = btrfs_super_flags(fs_info->super_copy);
@@ -354,14 +355,13 @@ static int change_fsid_prepare(struct btrfs_fs_info *fs_info)
flags |= BTRFS_SUPER_FLAG_CHANGING_FSID;
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, new_fsid, BTRFS_FSID_SIZE);
ret = write_all_supers(fs_info);
if (ret < 0)
return ret;
/* Also need to change the metadatauuid of the fs info */
- memcpy(fs_info->fs_devices->metadata_uuid, fs_info->new_fsid,
- BTRFS_FSID_SIZE);
+ memcpy(fs_info->fs_devices->metadata_uuid, new_fsid, BTRFS_FSID_SIZE);
/* also restore new chunk_tree_id into tree_root for restore */
write_extent_buffer(tree_root->node, fs_info->new_chunk_tree_uuid,
@@ -415,7 +415,6 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
uuid_generate(new_chunk_id);
}
- fs_info->new_fsid = new_fsid;
fs_info->new_chunk_tree_uuid = new_chunk_id;
memcpy(old_fsid, (const char*)fs_info->fs_devices->fsid, BTRFS_UUID_SIZE);
@@ -426,13 +425,13 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
printf("New fsid: %s\n", uuid_buf);
/* Now we can begin fsid change */
printf("Set superblock flag CHANGING_FSID\n");
- ret = change_fsid_prepare(fs_info);
+ ret = change_fsid_prepare(fs_info, new_fsid);
if (ret < 0)
goto out;
/* Change extents first */
printf("Change fsid in extents\n");
- ret = change_extents_uuid(fs_info);
+ ret = change_extents_uuid(fs_info, new_fsid);
if (ret < 0) {
error("failed to change UUID of metadata: %d", ret);
goto out;
@@ -440,17 +439,15 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
/* Then devices */
printf("Change fsid on devices\n");
- ret = change_devices_uuid(fs_info);
+ ret = change_devices_uuid(fs_info, new_fsid);
if (ret < 0) {
error("failed to change UUID of devices: %d", ret);
goto out;
}
/* Last, change fsid in super */
- memcpy(fs_info->fs_devices->fsid, fs_info->new_fsid,
- BTRFS_FSID_SIZE);
- memcpy(fs_info->super_copy->fsid, fs_info->new_fsid,
- BTRFS_FSID_SIZE);
+ memcpy(fs_info->fs_devices->fsid, new_fsid, BTRFS_FSID_SIZE);
+ memcpy(fs_info->super_copy->fsid, new_fsid, BTRFS_FSID_SIZE);
ret = write_all_supers(fs_info);
if (ret < 0)
goto out;
@@ -458,7 +455,6 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
/* Now fsid change is done */
printf("Clear superblock flag CHANGING_FSID\n");
ret = change_fsid_done(fs_info);
- fs_info->new_fsid = NULL;
fs_info->new_chunk_tree_uuid = NULL;
printf("Fsid change finished\n");
out:
diff --git a/ctree.h b/ctree.h
index bf0c0ca86219..3938e8e8b0e5 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1080,7 +1080,6 @@ struct btrfs_block_group_cache {
struct btrfs_device;
struct btrfs_fs_devices;
struct btrfs_fs_info {
- u8 *new_fsid;
u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
u8 *new_chunk_tree_uuid;
struct btrfs_root *fs_root;
--
2.7.4
next prev parent reply other threads:[~2018-10-11 15:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-11 15:03 [PATCH 0/8] FSID change userspace v2 Nikolay Borisov
2018-10-11 15:03 ` [PATCH 1/8] btrfstune: Remove fs_info arg from change_device_uuid Nikolay Borisov
2018-10-11 15:03 ` [PATCH 2/8] btrfstune: Rename change_header_uuid to change_buffer_header_uuid Nikolay Borisov
2018-10-11 15:03 ` [PATCH 3/8] btrfs-progs: Add support for metadata_uuid field Nikolay Borisov
2018-10-11 15:04 ` [PATCH 4/8] btrfstune: Add support for changing the user uuid Nikolay Borisov
2018-10-11 15:04 ` [PATCH 5/8] btrfs-progs: tests: Add tests for changing fsid feature Nikolay Borisov
2018-10-11 15:04 ` [PATCH 6/8] btrfs-progs: Remove fsid/metdata_uuid fields from fs_info Nikolay Borisov
2018-10-11 15:04 ` Nikolay Borisov [this message]
2018-10-11 15:04 ` [PATCH 8/8] btrfs-progs: Directly pass root to change_devices_uuid Nikolay Borisov
2018-12-13 19:14 ` [PATCH 0/8] FSID change userspace v2 David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1539270244-27076-8-git-send-email-nborisov@suse.com \
--to=nborisov@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).