btrfs-progs: Add open_ctree check for uuid changing
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 11 May 2015 08:08:45 +0000 (16:08 +0800)
committerDavid Sterba <dsterba@suse.cz>
Thu, 14 May 2015 13:41:07 +0000 (15:41 +0200)
Now open_ctree will exit if it found the superblock is marked
CHANGING_FSID, except given IGNORE_FSID open ctree flags.

Kernel will do the same thing later.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[removed the chunk tree flag, reworded the error message]
Signed-off-by: David Sterba <dsterba@suse.cz>
ctree.h
disk-io.c
disk-io.h

diff --git a/ctree.h b/ctree.h
index 7c1bef5..98cb1fb 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -1011,6 +1011,7 @@ struct btrfs_fs_info {
        unsigned int is_chunk_recover:1;
        unsigned int quota_enabled:1;
        unsigned int suppress_check_block_errors:1;
+       unsigned int ignore_fsid_mismatch:1;
 
        int (*free_extent_hook)(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
index c1cf146..3daed3b 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -49,7 +49,8 @@ static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
 
        fs_devices = root->fs_info->fs_devices;
        while (fs_devices) {
-               if (!memcmp_extent_buffer(buf, fs_devices->fsid,
+               if (root->fs_info->ignore_fsid_mismatch ||
+                   !memcmp_extent_buffer(buf, fs_devices->fsid,
                                          btrfs_header_fsid(),
                                          BTRFS_FSID_SIZE)) {
                        ret = 0;
@@ -1149,6 +1150,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
                fs_info->on_restoring = 1;
        if (flags & OPEN_CTREE_SUPPRESS_CHECK_BLOCK_ERRORS)
                fs_info->suppress_check_block_errors = 1;
+       if (flags & OPEN_CTREE_IGNORE_FSID_MISMATCH)
+               fs_info->ignore_fsid_mismatch = 1;
 
        ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr,
                                    (flags & OPEN_CTREE_RECOVER_SUPER),
@@ -1180,6 +1183,12 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
                goto out_devices;
        }
 
+       if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_CHANGING_FSID &&
+           !fs_info->ignore_fsid_mismatch) {
+               fprintf(stderr, "ERROR: Filesystem UUID change in progress\n");
+               goto out_devices;
+       }
+
        memcpy(fs_info->fsid, &disk_super->fsid, BTRFS_FSID_SIZE);
 
        ret = btrfs_check_fs_compatibility(fs_info->super_copy,
index 4caebeb..19f333e 100644 (file)
--- a/disk-io.h
+++ b/disk-io.h
@@ -49,6 +49,8 @@ enum btrfs_open_ctree_flags {
         * tree bits.
         * Like split PARTIAL into SKIP_CSUM/SKIP_EXTENT
         */
+
+       OPEN_CTREE_IGNORE_FSID_MISMATCH = (1 << 10)
 };
 
 static inline u64 btrfs_sb_offset(int mirror)