diff mbox

[v2,10/13] btrfs-progs: Introduce change_id_prepare() and change_id_done() functions.

Message ID 1431331734-11714-11-git-send-email-quwenruo@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Qu Wenruo May 11, 2015, 8:08 a.m. UTC
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>
---
v2:
  Newly introduced to inform kernel and progs not to open fs with
  unfinished uuid change.
---
 props.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
diff mbox

Patch

diff --git a/props.c b/props.c
index 59e09b3..0a1bc1e 100644
--- a/props.c
+++ b/props.c
@@ -351,6 +351,38 @@  out:
 	return ret;
 }
 
+static int change_id_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;
+	if (fs_info->new_chunk_tree_uuid)
+		flags |= BTRFS_SUPER_FLAG_CHANGING_CHUNK_TREE_ID;
+	btrfs_set_super_flags(fs_info->super_copy, flags);
+
+	return write_all_supers(fs_info->tree_root);
+}
+
+static int change_id_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;
+	if (fs_info->new_chunk_tree_uuid)
+		flags &= ~BTRFS_SUPER_FLAG_CHANGING_CHUNK_TREE_ID;
+	btrfs_set_super_flags(fs_info->super_copy, flags);
+
+	return write_all_supers(fs_info->tree_root);
+}
+
 const struct prop_handler prop_handlers[] = {
 	{"ro", "Set/get read-only flag of subvolume.", 0, prop_object_subvol,
 	 prop_read_only},