Blame SOURCES/Assemble-Clean1-up-start_array.patch

b7f731
From 94b53b777e095e1bc253654acc2e459d368c5dd5 Mon Sep 17 00:00:00 2001
b7f731
From: Jes Sorensen <jsorensen@fb.com>
b7f731
Date: Wed, 12 Apr 2017 14:23:45 -0400
b7f731
Subject: [RHEL7.5 PATCH 075/169] Assemble: Clean up start_array()
b7f731
b7f731
This is purely cosmetic, no codeflow changes.
b7f731
b7f731
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
b7f731
---
b7f731
 Assemble.c | 97 +++++++++++++++++++++++++++++++++++++-------------------------
b7f731
 1 file changed, 58 insertions(+), 39 deletions(-)
b7f731
b7f731
diff --git a/Assemble.c b/Assemble.c
b7f731
index b828523..22596b5 100644
b7f731
--- a/Assemble.c
b7f731
+++ b/Assemble.c
b7f731
@@ -992,7 +992,7 @@ static int start_array(int mdfd,
b7f731
 	}
b7f731
 
b7f731
 	/* First, add the raid disks, but add the chosen one last */
b7f731
-	for (i=0; i<= bestcnt; i++) {
b7f731
+	for (i = 0; i <= bestcnt; i++) {
b7f731
 		int j;
b7f731
 		if (i < bestcnt) {
b7f731
 			j = best[i];
b7f731
@@ -1002,8 +1002,9 @@ static int start_array(int mdfd,
b7f731
 			j = chosen_drive;
b7f731
 
b7f731
 		if (j >= 0 && !devices[j].included) {
b7f731
-			int dfd = dev_open(devices[j].devname,
b7f731
-					   O_RDWR|O_EXCL);
b7f731
+			int dfd;
b7f731
+
b7f731
+			dfd = dev_open(devices[j].devname, O_RDWR|O_EXCL);
b7f731
 			if (dfd >= 0) {
b7f731
 				remove_partitions(dfd);
b7f731
 				close(dfd);
b7f731
@@ -1012,28 +1013,30 @@ static int start_array(int mdfd,
b7f731
 
b7f731
 			if (rv) {
b7f731
 				pr_err("failed to add %s to %s: %s\n",
b7f731
-				       devices[j].devname,
b7f731
-				       mddev,
b7f731
+				       devices[j].devname, mddev,
b7f731
 				       strerror(errno));
b7f731
-				if (i < content->array.raid_disks * 2
b7f731
-				    || i == bestcnt)
b7f731
+				if (i < content->array.raid_disks * 2 ||
b7f731
+				    i == bestcnt)
b7f731
 					okcnt--;
b7f731
 				else
b7f731
 					sparecnt--;
b7f731
-			} else if (c->verbose > 0)
b7f731
+			} else if (c->verbose > 0) {
b7f731
 				pr_err("added %s to %s as %d%s%s\n",
b7f731
 				       devices[j].devname, mddev,
b7f731
 				       devices[j].i.disk.raid_disk,
b7f731
 				       devices[j].uptodate?"":
b7f731
 				       " (possibly out of date)",
b7f731
-				       (devices[j].i.disk.state & (1<
b7f731
+				       (devices[j].i.disk.state &
b7f731
+					(1<
b7f731
+				       " replacement":"");
b7f731
+			}
b7f731
 		} else if (j >= 0) {
b7f731
 			if (c->verbose > 0)
b7f731
 				pr_err("%s is already in %s as %d\n",
b7f731
 				       devices[j].devname, mddev,
b7f731
 				       devices[j].i.disk.raid_disk);
b7f731
-		} else if (c->verbose > 0 && i < content->array.raid_disks*2
b7f731
-			   && (i&1) == 0)
b7f731
+		} else if (c->verbose > 0 &&
b7f731
+			   i < content->array.raid_disks * 2 && (i & 1) == 0)
b7f731
 			pr_err("no uptodate device for slot %d of %s\n",
b7f731
 			       i/2, mddev);
b7f731
 	}
b7f731
@@ -1041,8 +1044,8 @@ static int start_array(int mdfd,
b7f731
 	if (content->array.level == LEVEL_CONTAINER) {
b7f731
 		if (c->verbose >= 0) {
b7f731
 			pr_err("Container %s has been assembled with %d drive%s",
b7f731
-			       mddev, okcnt+sparecnt+journalcnt,
b7f731
-			       okcnt+sparecnt+journalcnt==1?"":"s");
b7f731
+			       mddev, okcnt + sparecnt + journalcnt,
b7f731
+			       okcnt + sparecnt + journalcnt == 1 ? "" : "s");
b7f731
 			if (okcnt < (unsigned)content->array.raid_disks)
b7f731
 				fprintf(stderr, " (out of %d)",
b7f731
 					content->array.raid_disks);
b7f731
@@ -1051,10 +1054,13 @@ static int start_array(int mdfd,
b7f731
 
b7f731
 		if (st->ss->validate_container) {
b7f731
 			struct mdinfo *devices_list;
b7f731
-			struct mdinfo *info_devices = xmalloc(sizeof(struct mdinfo)*(okcnt+sparecnt));
b7f731
+			struct mdinfo *info_devices;
b7f731
 			unsigned int count;
b7f731
+
b7f731
 			devices_list = NULL;
b7f731
-			for (count = 0; count < okcnt+sparecnt; count++) {
b7f731
+			info_devices = xmalloc(sizeof(struct mdinfo) *
b7f731
+					       (okcnt + sparecnt));
b7f731
+			for (count = 0; count < okcnt + sparecnt; count++) {
b7f731
 				info_devices[count] = devices[count].i;
b7f731
 				info_devices[count].next = devices_list;
b7f731
 				devices_list = &info_devices[count];
b7f731
@@ -1080,16 +1086,16 @@ static int start_array(int mdfd,
b7f731
 
b7f731
 	if (c->runstop == 1 ||
b7f731
 	    (c->runstop <= 0 &&
b7f731
-	     ( enough(content->array.level, content->array.raid_disks,
b7f731
-		      content->array.layout, clean, avail) &&
b7f731
-	       (okcnt + rebuilding_cnt >= req_cnt || start_partial_ok)
b7f731
-		     ))) {
b7f731
+	     (enough(content->array.level, content->array.raid_disks,
b7f731
+		     content->array.layout, clean, avail) &&
b7f731
+	       (okcnt + rebuilding_cnt >= req_cnt || start_partial_ok)))) {
b7f731
 		/* This array is good-to-go.
b7f731
 		 * If a reshape is in progress then we might need to
b7f731
 		 * continue monitoring it.  In that case we start
b7f731
 		 * it read-only and let the grow code make it writable.
b7f731
 		 */
b7f731
 		int rv;
b7f731
+
b7f731
 		if (content->reshape_active &&
b7f731
 		    !(content->reshape_active & RESHAPE_NO_BACKUP) &&
b7f731
 		    content->delta_disks <= 0) {
b7f731
@@ -1109,8 +1115,8 @@ static int start_array(int mdfd,
b7f731
 						   c->backup_file, 0,
b7f731
 						   c->freeze_reshape);
b7f731
 		} else if (c->readonly &&
b7f731
-			   sysfs_attribute_available(
b7f731
-				   content, NULL, "array_state")) {
b7f731
+			   sysfs_attribute_available(content, NULL,
b7f731
+						     "array_state")) {
b7f731
 			rv = sysfs_set_str(content, NULL,
b7f731
 					   "array_state", "readonly");
b7f731
 		} else
b7f731
@@ -1121,13 +1127,19 @@ static int start_array(int mdfd,
b7f731
 				pr_err("%s has been started with %d drive%s",
b7f731
 				       mddev, okcnt, okcnt==1?"":"s");
b7f731
 				if (okcnt < (unsigned)content->array.raid_disks)
b7f731
-					fprintf(stderr, " (out of %d)", content->array.raid_disks);
b7f731
+					fprintf(stderr, " (out of %d)",
b7f731
+						content->array.raid_disks);
b7f731
 				if (rebuilding_cnt)
b7f731
-					fprintf(stderr, "%s %d rebuilding", sparecnt?",":" and", rebuilding_cnt);
b7f731
+					fprintf(stderr, "%s %d rebuilding",
b7f731
+						sparecnt?",":" and",
b7f731
+						rebuilding_cnt);
b7f731
 				if (sparecnt)
b7f731
-					fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
b7f731
+					fprintf(stderr, " and %d spare%s",
b7f731
+						sparecnt,
b7f731
+						sparecnt == 1 ? "" : "s");
b7f731
 				if (content->journal_clean)
b7f731
-					fprintf(stderr, " and %d journal", journalcnt);
b7f731
+					fprintf(stderr, " and %d journal",
b7f731
+						journalcnt);
b7f731
 				fprintf(stderr, ".\n");
b7f731
 			}
b7f731
 			if (content->reshape_active &&
b7f731
@@ -1137,11 +1149,14 @@ static int start_array(int mdfd,
b7f731
 				 * of the stripe cache - default is 256
b7f731
 				 */
b7f731
 				int chunk_size = content->array.chunk_size;
b7f731
+
b7f731
 				if (content->reshape_active &&
b7f731
 				    content->new_chunk > chunk_size)
b7f731
 					chunk_size = content->new_chunk;
b7f731
 				if (256 < 4 * ((chunk_size+4065)/4096)) {
b7f731
-					struct mdinfo *sra = sysfs_read(mdfd, NULL, 0);
b7f731
+					struct mdinfo *sra;
b7f731
+
b7f731
+					sra = sysfs_read(mdfd, NULL, 0);
b7f731
 					if (sra)
b7f731
 						sysfs_set_num(sra, NULL,
b7f731
 							      "stripe_cache_size",
b7f731
@@ -1174,7 +1189,9 @@ static int start_array(int mdfd,
b7f731
 			if (content->array.level == 6 &&
b7f731
 			    okcnt + 1 == (unsigned)content->array.raid_disks &&
b7f731
 			    was_forced) {
b7f731
-				struct mdinfo *sra = sysfs_read(mdfd, NULL, 0);
b7f731
+				struct mdinfo *sra;
b7f731
+
b7f731
+				sra = sysfs_read(mdfd, NULL, 0);
b7f731
 				if (sra)
b7f731
 					sysfs_set_str(sra, NULL,
b7f731
 						      "sync_action", "repair");
b7f731
@@ -1182,45 +1199,47 @@ static int start_array(int mdfd,
b7f731
 			}
b7f731
 			return 0;
b7f731
 		}
b7f731
-		pr_err("failed to RUN_ARRAY %s: %s\n",
b7f731
-		       mddev, strerror(errno));
b7f731
+		pr_err("failed to RUN_ARRAY %s: %s\n", mddev, strerror(errno));
b7f731
 
b7f731
 		if (!enough(content->array.level, content->array.raid_disks,
b7f731
 			    content->array.layout, 1, avail))
b7f731
 			pr_err("Not enough devices to start the array.\n");
b7f731
 		else if (!enough(content->array.level,
b7f731
 				 content->array.raid_disks,
b7f731
-				 content->array.layout, clean,
b7f731
-				 avail))
b7f731
+				 content->array.layout, clean, avail))
b7f731
 			pr_err("Not enough devices to start the array while not clean - consider --force.\n");
b7f731
 
b7f731
 		return 1;
b7f731
 	}
b7f731
 	if (c->runstop == -1) {
b7f731
 		pr_err("%s assembled from %d drive%s",
b7f731
-		       mddev, okcnt, okcnt==1?"":"s");
b7f731
+		       mddev, okcnt, okcnt == 1 ? "" : "s");
b7f731
 		if (okcnt != (unsigned)content->array.raid_disks)
b7f731
-			fprintf(stderr, " (out of %d)", content->array.raid_disks);
b7f731
+			fprintf(stderr, " (out of %d)",
b7f731
+				content->array.raid_disks);
b7f731
 		fprintf(stderr, ", but not started.\n");
b7f731
 		return 2;
b7f731
 	}
b7f731
 	if (c->verbose >= -1) {
b7f731
-		pr_err("%s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s");
b7f731
+		pr_err("%s assembled from %d drive%s",
b7f731
+		       mddev, okcnt, okcnt == 1 ? "" : "s");
b7f731
 		if (rebuilding_cnt)
b7f731
-			fprintf(stderr, "%s %d rebuilding", sparecnt?",":" and", rebuilding_cnt);
b7f731
+			fprintf(stderr, "%s %d rebuilding",
b7f731
+				sparecnt ? "," : " and", rebuilding_cnt);
b7f731
 		if (sparecnt)
b7f731
-			fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
b7f731
+			fprintf(stderr, " and %d spare%s", sparecnt,
b7f731
+				sparecnt == 1 ? "" : "s");
b7f731
 		if (!enough(content->array.level, content->array.raid_disks,
b7f731
 			    content->array.layout, 1, avail))
b7f731
 			fprintf(stderr, " - not enough to start the array.\n");
b7f731
 		else if (!enough(content->array.level,
b7f731
 				 content->array.raid_disks,
b7f731
-				 content->array.layout, clean,
b7f731
-				 avail))
b7f731
+				 content->array.layout, clean, avail))
b7f731
 			fprintf(stderr, " - not enough to start the array while not clean - consider --force.\n");
b7f731
 		else {
b7f731
 			if (req_cnt == (unsigned)content->array.raid_disks)
b7f731
-				fprintf(stderr, " - need all %d to start it", req_cnt);
b7f731
+				fprintf(stderr, " - need all %d to start it",
b7f731
+					req_cnt);
b7f731
 			else
b7f731
 				fprintf(stderr, " - need %d to start", req_cnt);
b7f731
 			fprintf(stderr, " (use --run to insist).\n");
b7f731
-- 
b7f731
2.7.4
b7f731