summaryrefslogtreecommitdiff
path: root/btrfstune.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2015-05-11 16:08:50 +0800
committerDavid Sterba <dsterba@suse.cz>2015-05-14 15:41:07 +0200
commit01cdf01ecfb66dac2a66c88f54f3b91039604a90 (patch)
tree5bee10fec6970372bc00ddb1c3a7a2348a4e456a /btrfstune.c
parentcff8aa2313c48788b55d6559e107b5726dcb1217 (diff)
btrfs-progs: Introduce change_devices_uuid function.
This function will change all device items' fsid. 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.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/btrfstune.c b/btrfstune.c
index 4ccd6d4c..77a8b7ac 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -219,6 +219,49 @@ static int change_device_uuid(struct btrfs_root *root, struct extent_buffer *eb,
return ret;
}
+static int change_devices_uuid(struct btrfs_fs_info *fs_info)
+{
+ struct btrfs_root *root = fs_info->chunk_root;
+ struct btrfs_path *path;
+ struct btrfs_key key = {0, 0, 0};
+ int ret = 0;
+
+ /*
+ * Unlike change_extents_uuid, we only need to change fsid in dev_item
+ */
+ if (!fs_info->new_fsid)
+ return 0;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+ /* No transaction again */
+ ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
+ if (ret < 0)
+ goto out;
+
+ while (1) {
+ btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+ if (key.type != BTRFS_DEV_ITEM_KEY ||
+ key.objectid != BTRFS_DEV_ITEMS_OBJECTID)
+ goto next;
+ ret = change_device_uuid(root, path->nodes[0], path->slots[0]);
+ if (ret < 0)
+ goto out;
+next:
+ ret = btrfs_next_item(root, path);
+ if (ret < 0)
+ goto out;
+ if (ret > 0) {
+ ret = 0;
+ goto out;
+ }
+ }
+out:
+ btrfs_free_path(path);
+ return ret;
+}
+
static void print_usage(void)
{
fprintf(stderr, "usage: btrfstune [options] device\n");