All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH v2 06/13] btrfs-progs: Introduce change_header_uuid() function.
Date: Mon, 11 May 2015 16:08:47 +0800	[thread overview]
Message-ID: <1431331734-11714-7-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1431331734-11714-1-git-send-email-quwenruo@cn.fujitsu.com>

This function is used to change fsid/chunk_tree_uuid of a node/leaf.
The function does it without transaction protect.

This is the basis of offline uuid change.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
v2:
  Move to props.c
---
 ctree.h |  2 ++
 props.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/ctree.h b/ctree.h
index 1608645..0fc876a 100644
--- a/ctree.h
+++ b/ctree.h
@@ -956,7 +956,9 @@ struct btrfs_device;
 struct btrfs_fs_devices;
 struct btrfs_fs_info {
 	u8 fsid[BTRFS_FSID_SIZE];
+	u8 *new_fsid;
 	u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
+	u8 *new_chunk_tree_uuid;
 	struct btrfs_root *fs_root;
 	struct btrfs_root *extent_root;
 	struct btrfs_root *tree_root;
diff --git a/props.c b/props.c
index c7c6752..abc3ae0 100644
--- a/props.c
+++ b/props.c
@@ -25,6 +25,7 @@
 #include "commands.h"
 #include "utils.h"
 #include "props.h"
+#include "disk-io.h"
 
 #define XATTR_BTRFS_PREFIX     "btrfs."
 #define XATTR_BTRFS_PREFIX_LEN (sizeof(XATTR_BTRFS_PREFIX) - 1)
@@ -187,6 +188,36 @@ out:
 	return ret;
 }
 
+static int change_header_uuid(struct btrfs_root *root, struct extent_buffer *eb)
+{
+	struct btrfs_fs_info *fs_info = root->fs_info;
+	int same_fsid = 1;
+	int same_chunk_tree_uuid = 1;
+	int ret = 0;
+
+	/* Check for whether we need to change fs/chunk id */
+	if (!fs_info->new_fsid && !fs_info->new_chunk_tree_uuid)
+		return 0;
+	if (fs_info->new_fsid)
+		same_fsid = !memcmp_extent_buffer(eb, fs_info->new_fsid,
+					  btrfs_header_fsid(), BTRFS_FSID_SIZE);
+	if (fs_info->new_chunk_tree_uuid)
+		same_chunk_tree_uuid =
+			!memcmp_extent_buffer(eb, fs_info->new_chunk_tree_uuid,
+					      btrfs_header_chunk_tree_uuid(eb),
+					      BTRFS_UUID_SIZE);
+	if (same_fsid && same_chunk_tree_uuid)
+		return 0;
+	if (!same_fsid)
+		write_extent_buffer(eb, fs_info->new_fsid, btrfs_header_fsid(),
+				    BTRFS_FSID_SIZE);
+	if (!same_chunk_tree_uuid)
+		write_extent_buffer(eb, fs_info->new_chunk_tree_uuid,
+				    btrfs_header_chunk_tree_uuid(eb),
+				    BTRFS_UUID_SIZE);
+	ret = write_tree_block(NULL, root, eb);
+	return ret;
+}
 
 const struct prop_handler prop_handlers[] = {
 	{"ro", "Set/get read-only flag of subvolume.", 0, prop_object_subvol,
-- 
2.4.0


  parent reply	other threads:[~2015-05-11  8:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-11  8:08 [PATCH v2 00/13] Introduce offline fsid/chunk tree uuid change for btrfstune Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 01/13] btrfs-progs: Add CHANGIND_FSID and CHANGING_CHUNK_TREE_ID super flags Qu Wenruo
2015-05-13 13:57   ` David Sterba
2015-05-11  8:08 ` [PATCH v2 02/13] btrfs-progs: Use unified function to implement print_readable_*_flag() function Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 03/13] btrfs-progs: Make btrfs-show-super print human readable flag for super flags Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 04/13] btrfs-progs: Add open_ctree check for uuid changing Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 05/13] btrfs-progs: Export write_tree_block() Qu Wenruo
2015-05-11  8:08 ` Qu Wenruo [this message]
2015-05-11  8:08 ` [PATCH v2 07/13] btrfs-progs: Introduce change_extents_uuid() function Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 08/13] btrfs-progs: Introduce change_device_uuid() function Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 09/13] btrfs-progs: Introduce change_devices_uuid() function Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 10/13] btrfs-progs: Introduce change_id_prepare() and change_id_done() functions Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 11/13] btrfs-progs: Introduce change_uuid() function Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 12/13] btrfs-progs: Add offline type for btrfs property Qu Wenruo
2015-05-11  8:08 ` [PATCH v2 13/13] btrfs-progs: Update Doc for btrfs-property Qu Wenruo
2015-05-13 13:56 ` [PATCH v2 00/13] Introduce offline fsid/chunk tree uuid change for btrfstune David Sterba
2015-05-13 16:03 ` David Sterba
2015-05-14  0:33   ` Qu Wenruo
2015-05-14 13:32     ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431331734-11714-7-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.