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

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