From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 4/8] btrfs-progs: Introduce change_extents_uuid() function.
Date: Tue, 5 May 2015 14:16:42 +0800 [thread overview]
Message-ID: <1430806606-3226-5-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1430806606-3226-1-git-send-email-quwenruo@cn.fujitsu.com>
This is the function which iterates all metadata extent and change their
fsid.
This function also does it without transaction.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
btrfstune.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/btrfstune.c b/btrfstune.c
index f039d84..9c1b7aa 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <uuid/uuid.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
@@ -129,6 +130,74 @@ static int change_header_uuid(struct btrfs_root *root, struct extent_buffer *eb)
return ret;
}
+static int change_extents_uuid(struct btrfs_fs_info *fs_info)
+{
+ struct btrfs_root *root = fs_info->extent_root;
+ struct btrfs_path *path;
+ struct btrfs_key key = {0, 0, 0};
+ int ret = 0;
+
+ if (!fs_info->new_fsid && !fs_info->new_chunk_tree_uuid)
+ return 0;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ /*
+ * Here we don't use transaction as it will takes a lot of reserve
+ * space, and that will make a near-full btrfs unable to change uuid
+ */
+ ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
+ if (ret < 0)
+ goto out;
+
+ while (1) {
+ struct btrfs_extent_item *ei;
+ struct extent_buffer *eb;
+ u64 flags;
+ u64 bytenr;
+
+ btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+ if (key.type != BTRFS_EXTENT_ITEM_KEY &&
+ key.type != BTRFS_METADATA_ITEM_KEY)
+ goto next;
+ ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
+ struct btrfs_extent_item);
+ flags = btrfs_extent_flags(path->nodes[0], ei);
+ if (!(flags & BTRFS_EXTENT_FLAG_TREE_BLOCK))
+ goto next;
+
+ bytenr = key.objectid;
+ eb = read_tree_block(root, bytenr, root->nodesize, 0);
+ if (IS_ERR(eb)) {
+ fprintf(stderr, "Failed to read tree block: %llu\n",
+ bytenr);
+ ret = PTR_ERR(eb);
+ goto out;
+ }
+ ret = change_header_uuid(root, eb);
+ free_extent_buffer(eb);
+ if (ret < 0) {
+ fprintf(stderr, "Failed to change uuid of tree block: %llu\n",
+ bytenr);
+ goto out;
+ }
+next:
+ ret = btrfs_next_item(root, path);
+ if (ret < 0)
+ goto out;
+ if (ret > 0) {
+ ret = 0;
+ goto out;
+ }
+ }
+
+out:
+ btrfs_free_path(path);
+ return ret;
+}
+
static void print_usage(void)
{
fprintf(stderr, "usage: btrfstune [options] device\n");
--
2.3.7
next prev parent reply other threads:[~2015-05-05 6:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-05 6:16 [PATCH 0/8] Introduce offline fsid/chunk tree uuid change for btrfstune Qu Wenruo
2015-05-05 6:16 ` [PATCH 1/8] btrfs-progs: Allow open_ctree to ignore fsid mismatch Qu Wenruo
2015-05-05 6:16 ` [PATCH 2/8] btrfs-progs: Export write_tree_block() Qu Wenruo
2015-05-05 6:16 ` [PATCH 3/8] btrfs-progs: Introduce change_header_uuid() function Qu Wenruo
2015-05-05 6:16 ` Qu Wenruo [this message]
2015-05-05 6:16 ` [PATCH 5/8] btrfs-progs: Introduce function change_device_uuid() Qu Wenruo
2015-05-05 6:16 ` [PATCH 6/8] btrfs-progs: Introduce change_devices_uuid() function Qu Wenruo
2015-05-05 6:16 ` [PATCH 7/8] btrfs-progs: Introduce change_uuid() function Qu Wenruo
2015-05-05 6:16 ` [PATCH 8/8] btrfs-progs: btrfstune: Introduce new "-u" and "-U" options Qu Wenruo
2015-05-05 15:20 ` [PATCH 0/8] Introduce offline fsid/chunk tree uuid change for btrfstune David Sterba
2015-05-06 0:49 ` Qu Wenruo
2015-05-06 15:43 ` David Sterba
2015-05-08 8:57 ` Qu Wenruo
2015-05-11 16:24 ` David Sterba
2015-05-12 2:09 ` Qu Wenruo
2015-05-12 4:00 ` Anand Jain
2015-05-13 0:54 ` Qu Wenruo
2015-05-13 13:43 ` David Sterba
2015-05-15 15:42 ` Anand Jain
2015-05-21 16:30 ` David Sterba
2015-05-22 15:20 ` Anand Jain
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=1430806606-3226-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).