Re: [PATCH v2] mdadm: make --update=homehost work again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed,  6 Feb 2013 12:07:17 -0800 Justin Maggard <jmaggard10@xxxxxxxxx>
wrote:

> Commit 1e2b276535cea41c348292a019bdda8a58cb1679 (Report error in --update
> string is not recognised) broke homehost updating functionality because it
> depended on each string comparison being done even after we already found
> a match.  Make it work again by using a goto instead.
> 

Hi Justin,
thanks for the patch.  Unfortunately I really don't like gotos when they can
be easily avoided (though they do have their place sometimes).
So I restructured the code a bit instead - as below.

Thanks,
NeilBrown

From 1fc34af916a7afd0b6a6b386973a6045579ee31a Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@xxxxxxx>
Date: Thu, 7 Feb 2013 11:51:21 +1100
Subject: [PATCH] make --update=homehost work again

Commit 1e2b276535cea41c348292a019bdda8a58cb1679 (Report error in --update
string is not recognised) broke homehost updating functionality because it
depended on each string comparison being done even after we already found
a match.  Make it work again by restructuring code.

Reported-by: (and original version by) Justin Maggard <jmaggard10@xxxxxxxxx>
Signed-off-by: NeilBrown <neilb@xxxxxxx>

diff --git a/super0.c b/super0.c
index 32a9f7b..1f4dc75 100644
--- a/super0.c
+++ b/super0.c
@@ -435,6 +435,18 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
 	int rv = 0;
 	int uuid[4];
 	mdp_super_t *sb = st->sb;
+
+	if (strcmp(update, "homehost") == 0 &&
+	    homehost) {
+		/* note that 'homehost' is special as it is really
+		 * a "uuid" update.
+		 */
+		uuid_set = 0;
+		update = "uuid";
+		info->uuid[0] = sb->set_uuid0;
+		info->uuid[1] = sb->set_uuid1;
+	}
+
 	if (strcmp(update, "sparc2.2")==0 ) {
 		/* 2.2 sparc put the events in the wrong place
 		 * So we copy the tail of the superblock
@@ -551,12 +563,6 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
 		/* make sure resync happens */
 		sb->state &= ~(1<<MD_SB_CLEAN);
 		sb->recovery_cp = 0;
-	} else if (strcmp(update, "homehost") == 0 &&
-		   homehost) {
-		uuid_set = 0;
-		update = "uuid";
-		info->uuid[0] = sb->set_uuid0;
-		info->uuid[1] = sb->set_uuid1;
 	} else if (strcmp(update, "uuid") == 0) {
 		if (!uuid_set && homehost) {
 			char buf[20];
diff --git a/super1.c b/super1.c
index c240b91..d0f1d5f 100644
--- a/super1.c
+++ b/super1.c
@@ -885,6 +885,21 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
 	int rv = 0;
 	struct mdp_superblock_1 *sb = st->sb;
 
+	if (strcmp(update, "homehost") == 0 &&
+	    homehost) {
+		/* Note that 'homehost' is special as it is really
+		 * a "name" update.
+		 */
+		char *c;
+		update = "name";
+		c = strchr(sb->set_name, ':');
+		if (c)
+			strncpy(info->name, c+1, 31 - (c-sb->set_name));
+		else
+			strncpy(info->name, sb->set_name, 32);
+		info->name[32] = 0;
+	}
+
 	if (strcmp(update, "force-one")==0) {
 		/* Not enough devices for a working array,
 		 * so bring this one up-to-date
@@ -1037,16 +1052,6 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
 			sb->bblog_shift = 0;
 			sb->bblog_offset = 0;
 		}
-	} else if (strcmp(update, "homehost") == 0 &&
-		   homehost) {
-		char *c;
-		update = "name";
-		c = strchr(sb->set_name, ':');
-		if (c)
-			strncpy(info->name, c+1, 31 - (c-sb->set_name));
-		else
-			strncpy(info->name, sb->set_name, 32);
-		info->name[32] = 0;
 	} else if (strcmp(update, "name") == 0) {
 		if (info->name[0] == 0)
 			sprintf(info->name, "%d", info->array.md_minor);

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux