All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Rajnoha <prajnoha@fedoraproject.org>
To: lvm-devel@redhat.com
Subject: master - dmsetup: also apply 'mangle' command for UUIDs
Date: Wed, 10 Oct 2012 15:18:34 +0000 (UTC)	[thread overview]
Message-ID: <20121010151834.30E56335B@hosted02.fedoraproject.org> (raw)

Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=470d1a2f5459bbbf82effb70b83a86329a170f85
Commit:        470d1a2f5459bbbf82effb70b83a86329a170f85
Parent:        788b7a6a2b6c20f7dddda3b90cd4dd5c60b1e1f5
Author:        Peter Rajnoha <prajnoha@redhat.com>
AuthorDate:    Wed Oct 10 17:03:47 2012 +0200
Committer:     Peter Rajnoha <prajnoha@redhat.com>
CommitterDate: Wed Oct 10 17:16:15 2012 +0200

dmsetup: also apply 'mangle' command for UUIDs

Compared to names, UUIDs can't be renamed once they are created
for a device. The 'mangle' command will just issue an error message
about a need for manual intervention in this case - reactivating the
device (remove + create) does the job as the defualt mangling mode
used is "auto" and that will assign a correct mangled form the UUID.
---
 tools/dmsetup.c |   41 +++++++++++++++++++++++++++++++++--------
 1 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 8d24293..196c170 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -2943,8 +2943,8 @@ static int _ls(CMD_ARGS)
 
 static int _mangle(CMD_ARGS)
 {
-	char *name;
-	char *new_name = NULL;
+	const char *name, *uuid;
+	char *new_name = NULL, *new_uuid = NULL;
 	struct dm_task *dmt;
 	struct dm_info info;
 	int r = 0;
@@ -2973,25 +2973,49 @@ static int _mangle(CMD_ARGS)
 	if (!dm_task_get_info(dmt, &info) || !info.exists)
 		goto out;
 
+	uuid = dm_task_get_uuid(dmt);
+
 	target_format = _switches[MANGLENAME_ARG] ? _int_args[MANGLENAME_ARG]
 						  : DEFAULT_DM_NAME_MANGLING;
 
-	if (target_format == DM_STRING_MANGLING_AUTO && strstr(name, "\\x5cx")) {
-		log_error("The name \"%s\" seems to be mangled more than once. "
-			  "Manual intervention required to rename the device.", name);
-		goto out;
+	if (target_format == DM_STRING_MANGLING_AUTO) {
+		if (strstr(name, "\\x5cx")) {
+			log_error("The name \"%s\" seems to be mangled more than once. "
+				  "Manual intervention required to rename the device.", name);
+			goto out;
+		}
+		if (strstr(uuid, "\\x5cx")) {
+			log_error("The UUID \"%s\" seems to be mangled more than once. "
+				  "Manual intervention required to correct the device UUID.", uuid);
+			goto out;
+		}
 	}
 
 	if (target_format == DM_STRING_MANGLING_NONE) {
 		if (!(new_name = dm_task_get_name_unmangled(dmt)))
 			goto out;
+		if (!(new_uuid = dm_task_get_uuid_unmangled(dmt)))
+			goto out;
 	}
-	else if (!(new_name = dm_task_get_name_mangled(dmt)))
+	else {
+		if (!(new_name = dm_task_get_name_mangled(dmt)))
+			goto out;
+		if (!(new_uuid = dm_task_get_uuid_mangled(dmt)))
+			goto out;
+	}
+
+	/* We can't rename the UUID, the device must be reactivated manually. */
+	if (strcmp(uuid, new_uuid)) {
+		log_error("%s: %s: UUID in incorrect form. ", name, uuid);
+		log_error("Unable to change device UUID. The device must be deactivated first.");
+		r = 0;
 		goto out;
+	}
 
 	/* Nothing to do if the name is in correct form already. */
 	if (!strcmp(name, new_name)) {
-		log_print("%s: name already in correct form", name);
+		log_print("%s: %s: name %salready in correct form", name,
+			  *uuid ? uuid : "[no UUID]", *uuid ? "and UUID " : "");
 		r = 1;
 		goto out;
 	}
@@ -3003,6 +3027,7 @@ static int _mangle(CMD_ARGS)
 
 out:
 	dm_free(new_name);
+	dm_free(new_uuid);
 	dm_task_destroy(dmt);
 	return r;
 }



                 reply	other threads:[~2012-10-10 15:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20121010151834.30E56335B@hosted02.fedoraproject.org \
    --to=prajnoha@fedoraproject.org \
    --cc=lvm-devel@redhat.com \
    /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.