From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 8/8] btrfs-progs: btrfstune: Introduce new "-u" and "-U" options.
Date: Tue, 5 May 2015 14:16:46 +0800 [thread overview]
Message-ID: <1430806606-3226-9-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1430806606-3226-1-git-send-email-quwenruo@cn.fujitsu.com>
These new options will change fsid and chunk tree uuid respectively.
This feature is useful for things like virt-clone, which needs to change
UUID of a filesystem to avoid conflicts.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
Documentation/btrfstune.asciidoc | 12 +++++--
btrfstune.c | 67 +++++++++++++++++++++++++++++++++++++---
2 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/Documentation/btrfstune.asciidoc b/Documentation/btrfstune.asciidoc
index 9620221..efd5fc8 100644
--- a/Documentation/btrfstune.asciidoc
+++ b/Documentation/btrfstune.asciidoc
@@ -25,8 +25,16 @@ Enable extended inode refs.
-x::
Enable skinny metadata extent refs.
-f::
-Allow dangerous changes, e.g. clear the seeding flag. Make sure that you are
-aware of the dangers.
+Allow dangerous changes, e.g. clear the seeding flag or changing UUID.
+Make sure that you are aware of the dangers.
+-u <uuid>::
+Change fsid to <uuid>.
+-U <uuid>::
+Change chunk tree uuid to <uuid>.
+
+WARNING: If canceling a running fsid changing process, the fs will not be
+mountable due to mismatch fsid. When that happens, use *btrfstune* to change
+fsid again, and it should fix the inconsistence.
When mounting the new device, btrfs will check whether the seeding flag is set
when try to open seeding device. If the user clears the seeding flag of the
diff --git a/btrfstune.c b/btrfstune.c
index 3e308b7..ef69a31 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -325,7 +325,9 @@ static void print_usage(void)
fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed\n");
fprintf(stderr, "\t-r \t\tenable extended inode refs\n");
fprintf(stderr, "\t-x \t\tenable skinny metadata extent refs\n");
- fprintf(stderr, "\t-f \t\tforce to set or clear flags, make sure that you are aware of the dangers\n");
+ fprintf(stderr, "\t-f \t\tforce to do dangerous operation, make sure that you are aware of the dangers\n");
+ fprintf(stderr, "\t-u uuid\tchange fsid\n");
+ fprintf(stderr, "\t-U uuid\tchange chunk tree uuid\n");
}
int main(int argc, char *argv[])
@@ -336,12 +338,15 @@ int main(int argc, char *argv[])
int extrefs_flag = 0;
int seeding_flag = 0;
u64 seeding_value = 0;
+ char *new_fsid = NULL;
+ char *new_chunk_uuid = NULL;
int skinny_flag = 0;
+ enum btrfs_open_ctree_flags open_flags = OPEN_CTREE_WRITES;
int ret;
optind = 1;
while(1) {
- int c = getopt(argc, argv, "S:rxf");
+ int c = getopt(argc, argv, "S:rxfu:U:");
if (c < 0)
break;
switch(c) {
@@ -358,6 +363,13 @@ int main(int argc, char *argv[])
case 'f':
force = 1;
break;
+ case 'u':
+ new_fsid = optarg;
+ open_flags |= OPEN_CTREE_IGNORE_FSID;
+ break;
+ case 'U':
+ new_chunk_uuid = optarg;
+ break;
default:
print_usage();
return 1;
@@ -372,13 +384,42 @@ int main(int argc, char *argv[])
return 1;
}
- if (!(seeding_flag + extrefs_flag + skinny_flag)) {
+ if (!(seeding_flag + extrefs_flag + skinny_flag) &&
+ !(new_fsid || new_chunk_uuid)) {
fprintf(stderr,
"ERROR: At least one option should be assigned.\n");
print_usage();
return 1;
}
+ if (new_fsid) {
+ uuid_t dummy_uuid;
+
+ if (uuid_parse(new_fsid, dummy_uuid) != 0) {
+ fprintf(stderr, "could not parse UUID: %s\n", new_fsid);
+ return 1;
+ }
+ if (!test_uuid_unique(new_fsid)) {
+ fprintf(stderr, "non-unique UUID: %s\n", new_fsid);
+ return 1;
+ }
+ }
+
+ if (new_chunk_uuid) {
+ uuid_t dummy_uuid;
+
+ if (uuid_parse(new_chunk_uuid, dummy_uuid) != 0) {
+ fprintf(stderr, "could not parse UUID: %s\n",
+ new_chunk_uuid);
+ return 1;
+ }
+ if (!test_uuid_unique(new_chunk_uuid)) {
+ fprintf(stderr, "non-unique UUID: %s\n",
+ new_chunk_uuid);
+ return 1;
+ }
+ }
+
ret = check_mounted(device);
if (ret < 0) {
fprintf(stderr, "Could not check mount status: %s\n",
@@ -389,7 +430,7 @@ int main(int argc, char *argv[])
return 1;
}
- root = open_ctree(device, 0, OPEN_CTREE_WRITES);
+ root = open_ctree(device, 0, open_flags);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
@@ -424,6 +465,24 @@ int main(int argc, char *argv[])
total++;
}
+ if (new_fsid || new_chunk_uuid) {
+ if (!force) {
+ fprintf(stderr,
+ "Warning: It's highly recommended to run 'btrfs check' before changing UUID. \n");
+ fprintf(stderr,
+ "Also canceling running UUID change progress will cause corruption\n");
+ ret = ask_user("Are you sure to process?");
+ if (!ret) {
+ fprintf(stderr, "UUID change canceled\n");
+ return 1;
+ }
+ }
+ ret = change_uuid(root->fs_info, new_fsid, new_chunk_uuid);
+ if (!ret)
+ success++;
+ total++;
+ }
+
if (success == total) {
ret = 0;
} else {
--
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 ` [PATCH 4/8] btrfs-progs: Introduce change_extents_uuid() function Qu Wenruo
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 ` Qu Wenruo [this message]
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-9-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).