summaryrefslogtreecommitdiff
path: root/btrfstune.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2015-05-11 16:08:47 +0800
committerDavid Sterba <dsterba@suse.cz>2015-05-14 15:41:07 +0200
commit0c8b978881f8f5d2b15b7bf2ec5621500ec3858a (patch)
tree4a89621fec0972a11f79ef6d1fa738899e308e80 /btrfstune.c
parent92b020ee0487b34282169a55a91261cee3daa1fe (diff)
btrfs-progs: Introduce change_header_uuid function
This function is used to change fsid and chunk_tree_uuid of a node/leaf. The function does it without transaction protection. This is the basis of offline uuid change. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'btrfstune.c')
-rw-r--r--btrfstune.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/btrfstune.c b/btrfstune.c
index 808466f9..92837e6f 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -98,6 +98,38 @@ static int enable_skinny_metadata(struct btrfs_root *root)
return 0;
}
+static int change_header_uuid(struct btrfs_root *root, struct extent_buffer *eb)
+{
+ struct btrfs_fs_info *fs_info = root->fs_info;
+ int same_fsid = 1;
+ int same_chunk_tree_uuid = 1;
+ int ret;
+
+ /* Check for whether we need to change fs/chunk id */
+ if (!fs_info->new_fsid && !fs_info->new_chunk_tree_uuid)
+ return 0;
+ if (fs_info->new_fsid)
+ same_fsid = !memcmp_extent_buffer(eb, fs_info->new_fsid,
+ btrfs_header_fsid(), BTRFS_FSID_SIZE);
+ if (fs_info->new_chunk_tree_uuid)
+ same_chunk_tree_uuid =
+ !memcmp_extent_buffer(eb, fs_info->new_chunk_tree_uuid,
+ btrfs_header_chunk_tree_uuid(eb),
+ BTRFS_UUID_SIZE);
+ if (same_fsid && same_chunk_tree_uuid)
+ return 0;
+ if (!same_fsid)
+ write_extent_buffer(eb, fs_info->new_fsid, btrfs_header_fsid(),
+ BTRFS_FSID_SIZE);
+ if (!same_chunk_tree_uuid)
+ write_extent_buffer(eb, fs_info->new_chunk_tree_uuid,
+ btrfs_header_chunk_tree_uuid(eb),
+ BTRFS_UUID_SIZE);
+ ret = write_tree_block(NULL, root, eb);
+
+ return ret;
+}
+
static void print_usage(void)
{
fprintf(stderr, "usage: btrfstune [options] device\n");