- if (new_chunk_uuid) {
- /* allocated mem will be freed at close_ctree() */
- fs_info->new_chunk_tree_uuid = malloc(BTRFS_UUID_SIZE);
- if (!fs_info->new_chunk_tree_uuid) {
- ret = -ENOMEM;
- goto out;
+/*
+ * Change fsid of a given fs.
+ *
+ * If new_fsid_str is not given, use a random generated UUID.
+ * Caller should check new_fsid_str is valid
+ */
+static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
+{
+ uuid_t new_fsid;
+ uuid_t new_chunk_id;
+ uuid_t old_fsid;
+ char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
+ int ret = 0;
+
+ if (check_unfinished_fsid_change(fs_info, new_fsid, new_chunk_id)) {
+ if (new_fsid_str) {
+ uuid_t tmp;
+
+ uuid_parse(new_fsid_str, tmp);
+ if (memcmp(tmp, new_fsid, BTRFS_FSID_SIZE)) {
+ error(
+ "new fsid %s is not the same with unfinished fsid change",
+ new_fsid_str);
+ return -EINVAL;
+ }