btrfs-progs: Introduce change_fsid_prepare and change_fsid_done functions
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Wed, 13 May 2015 14:41:51 +0000 (16:41 +0200)
committerDavid Sterba <dsterba@suse.cz>
Thu, 14 May 2015 13:41:08 +0000 (15:41 +0200)
These two functions will write flags to all supers before and after
fsid/chunk tree id change, informing kernel not to mount a inconsistent
fs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[removed chunk tree super flag]
Signed-off-by: David Sterba <dsterba@suse.cz>
btrfstune.c

index 77a8b7a..9a63f41 100644 (file)
@@ -262,6 +262,34 @@ out:
        return ret;
 }
 
+static int change_fsid_prepare(struct btrfs_fs_info *fs_info)
+{
+       u64 flags = btrfs_super_flags(fs_info->super_copy);
+
+       if (!fs_info->new_fsid && !fs_info->new_chunk_tree_uuid)
+               return 0;
+
+       if (fs_info->new_fsid)
+               flags |= BTRFS_SUPER_FLAG_CHANGING_FSID;
+       btrfs_set_super_flags(fs_info->super_copy, flags);
+
+       return write_all_supers(fs_info->tree_root);
+}
+
+static int change_fsid_done(struct btrfs_fs_info *fs_info)
+{
+       u64 flags = btrfs_super_flags(fs_info->super_copy);
+
+       if (!fs_info->new_fsid && !fs_info->new_chunk_tree_uuid)
+               return 0;
+
+       if (fs_info->new_fsid)
+               flags &= ~BTRFS_SUPER_FLAG_CHANGING_FSID;
+       btrfs_set_super_flags(fs_info->super_copy, flags);
+
+       return write_all_supers(fs_info->tree_root);
+}
+
 static void print_usage(void)
 {
        fprintf(stderr, "usage: btrfstune [options] device\n");