From bcbb3112d2801594358153956191e4cff6021de3 Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Thu, 22 Mar 2012 16:07:02 +1100
Subject: [PATCH] Manage: replace 'return 1' with 'goto abort'.

This will allow exit processing in next patch

Signed-off-by: NeilBrown <neilb@suse.de>
---
 Manage.c |   75 ++++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 39 insertions(+), 36 deletions(-)

--- mdadm-3.2.2.orig/Manage.c
+++ mdadm-3.2.2/Manage.c
@@ -406,7 +406,7 @@ int Manage_subdevs(char *devname, int fd
 	if (ioctl(fd, GET_ARRAY_INFO, &array)) {
 		fprintf(stderr, Name ": cannot get array info for %s\n",
 			devname);
-		return 1;
+		goto abort;
 	}
 
 	/* array.size is only 32 bit and may be truncated.
@@ -421,7 +421,7 @@ int Manage_subdevs(char *devname, int fd
 	if (!tst) {
 		fprintf(stderr, Name ": unsupport array - version %d.%d\n",
 			array.major_version, array.minor_version);
-		return 1;
+		goto abort;
 	}
 
 	stb.st_rdev = 0;
@@ -443,7 +443,7 @@ int Manage_subdevs(char *devname, int fd
 				fprintf(stderr, Name ": %s only meaningful "
 					"with -r, not -%c\n",
 					dv->devname, dv->disposition);
-				return 1;
+				goto abort;
 			}
 			for (; j < 1024 && remaining_disks > 0; j++) {
 				unsigned dev;
@@ -476,7 +476,7 @@ int Manage_subdevs(char *devname, int fd
 				fprintf(stderr, Name ": %s only meaningful "
 					"with -r of -f, not -%c\n",
 					dv->devname, dv->disposition);
-				return 1;
+				goto abort;
 			}
 			for (; j < 1024 && remaining_disks > 0; j++) {
 				int sfd;
@@ -516,7 +516,7 @@ int Manage_subdevs(char *devname, int fd
 			if (dv->disposition != 'a' || dv->re_add == 0) {
 				fprintf(stderr, Name ": 'missing' only meaningful "
 					"with --re-add\n");
-				return 1;
+				goto abort;
 			}
 			if (add_devlist == NULL)
 				add_devlist = conf_get_devs();
@@ -540,7 +540,7 @@ int Manage_subdevs(char *devname, int fd
 				fprintf(stderr, Name ": %s only meaningful "
 					"with -r or -f, not -%c\n",
 					dv->devname, dv->disposition);
-				return 1;
+				goto abort;
 			}
 
 			sprintf(dname, "dev-%s", dv->devname);
@@ -562,7 +562,7 @@ int Manage_subdevs(char *devname, int fd
 					fprintf(stderr, Name ": %s does not appear "
 						"to be a component of %s\n",
 						dv->devname, devname);
-					return 1;
+					goto abort;
 				}
 			}
 		} else {
@@ -581,7 +581,7 @@ int Manage_subdevs(char *devname, int fd
 						dv->devname, strerror(errno));
 					if (tfd >= 0)
 						close(tfd);
-					return 1;
+					goto abort;
 				}
 				close(tfd);
 				tfd = -1;
@@ -590,21 +590,21 @@ int Manage_subdevs(char *devname, int fd
 				fprintf(stderr, Name ": %s is not a "
 					"block device.\n",
 					dv->devname);
-				return 1;
+				goto abort;
 			}
 		}
 		switch(dv->disposition){
 		default:
 			fprintf(stderr, Name ": internal error - devmode[%s]=%d\n",
 				dv->devname, dv->disposition);
-			return 1;
+			goto abort;
 		case 'a':
 			/* add the device */
 			if (subarray) {
 				fprintf(stderr, Name ": Cannot add disks to a"
 					" \'member\' array, perform this"
 					" operation on the parent container\n");
-				return 1;
+				goto abort;
 			}
 			/* Make sure it isn't in use (in 2.6 or later) */
 			tfd = dev_open(add_dev, O_RDONLY|O_EXCL|O_DIRECT);
@@ -613,7 +613,7 @@ int Manage_subdevs(char *devname, int fd
 			if (tfd < 0) {
 				fprintf(stderr, Name ": Cannot open %s: %s\n",
 					dv->devname, strerror(errno));
-				return 1;
+				goto abort;
 			}
 
 			st = dup_super(tst);
@@ -624,7 +624,7 @@ int Manage_subdevs(char *devname, int fd
 			if (add_dev == dv->devname) {
 				if (!get_dev_size(tfd, dv->devname, &ldsize)) {
 					close(tfd);
-					return 1;
+					goto abort;
 				}
 			} else if (!get_dev_size(tfd, NULL, &ldsize)) {
 				close(tfd);
@@ -644,7 +644,7 @@ int Manage_subdevs(char *devname, int fd
 						"really wan to add this device.\n",
 						add_dev, devname);
 					close(tfd);
-					return 1;
+					goto abort;
 				}
 				fprintf(stderr, Name
 					": %s is larger than %s can "
@@ -668,7 +668,7 @@ int Manage_subdevs(char *devname, int fd
 
 				fprintf(stderr, Name ": hot add failed for %s: %s\n",
 					add_dev, strerror(errno));
-				return 1;
+				goto abort;
 			}
 
 			if (array.not_persistent == 0 || tst->ss->external) {
@@ -714,7 +714,7 @@ int Manage_subdevs(char *devname, int fd
 				} else if (!tst->sb) {
 					close(tfd);
 					fprintf(stderr, Name ": cannot load array metadata from %s\n", devname);
-					return 1;
+					goto abort;
 				}
 
 				/* Make sure device is large enough */
@@ -726,7 +726,7 @@ int Manage_subdevs(char *devname, int fd
 						continue;
 					fprintf(stderr, Name ": %s not large enough to join array\n",
 						dv->devname);
-					return 1;
+					goto abort;
 				}
 
 				/* Possibly this device was recently part of the array
@@ -783,7 +783,7 @@ int Manage_subdevs(char *devname, int fd
 							if (tfd < 0) {
 								fprintf(stderr, Name ": failed to open %s for"
 									" superblock update during re-add\n", dv->devname);
-								return 1;
+								goto abort;
 							}
 
 							if (dv->writemostly == 1)
@@ -813,7 +813,7 @@ int Manage_subdevs(char *devname, int fd
 							if (rv != 0) {
 								fprintf(stderr, Name ": failed to update"
 									" superblock during re-add\n");
-								return 1;
+								goto abort;
 							}
 						}
 						/* don't even try if disk is marked as faulty */
@@ -829,7 +829,7 @@ int Manage_subdevs(char *devname, int fd
 								add_dev, strerror(errno));
 							if (add_dev != dv->devname)
 								continue;
-							return 1;
+							goto abort;
 						}
 					skip_re_add:
 						re_add_failed = 1;
@@ -853,7 +853,7 @@ int Manage_subdevs(char *devname, int fd
 					fprintf(stderr, Name
 						": --re-add for %s to %s is not possible\n",
 						dv->devname, devname);
-					return 1;
+					goto abort;
 				}
 				if (re_add_failed) {
 					fprintf(stderr, Name ": %s reports being an active member for %s, but a --re-add fails.\n",
@@ -864,7 +864,7 @@ int Manage_subdevs(char *devname, int fd
 						dv->devname);
 					if (tfd >= 0)
 						close(tfd);
-					return 1;
+					goto abort;
 				}
 			} else {
 				/* non-persistent. Must ensure that new drive
@@ -875,7 +875,7 @@ int Manage_subdevs(char *devname, int fd
 						dv->devname);
 					if (tfd >= 0)
 						close(tfd);
-					return 1;
+					goto abort;
 				}
 			}
 			/* committed to really trying this device now*/
@@ -912,11 +912,11 @@ int Manage_subdevs(char *devname, int fd
 				if (tst->ss->add_to_super(tst, &disc, dfd,
 							  dv->devname)) {
 					close(dfd);
-					return 1;
+					goto abort;
 				}
 				if (tst->ss->write_init_super(tst)) {
 					close(dfd);
-					return 1;
+					goto abort;
 				}
 			} else if (dv->re_add) {
 				/*  this had better be raid1.
@@ -967,7 +967,7 @@ int Manage_subdevs(char *devname, int fd
 						" could not get exclusive access to container\n",
 						dv->devname);
 					tst->ss->free_super(tst);
-					return 1;
+					goto abort;
 				}
 
 				dfd = dev_open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
@@ -977,7 +977,7 @@ int Manage_subdevs(char *devname, int fd
 							  dv->devname)) {
 					close(dfd);
 					close(container_fd);
-					return 1;
+					goto abort;
 				}
 				if (tst->update_tail)
 					flush_metadata_updates(tst);
@@ -990,7 +990,7 @@ int Manage_subdevs(char *devname, int fd
 						dv->devname);
 					close(container_fd);
 					tst->ss->free_super(tst);
-					return 1;
+					goto abort;
 				}
 				sra->array.level = LEVEL_CONTAINER;
 				/* Need to set data_offset and component_size */
@@ -1006,7 +1006,7 @@ int Manage_subdevs(char *devname, int fd
 						" failed for %s\n", dv->devname);
 					close(container_fd);
 					sysfs_free(sra);
-					return 1;
+					goto abort;
 				}
 				ping_monitor_by_id(devnum);
 				sysfs_free(sra);
@@ -1016,7 +1016,7 @@ int Manage_subdevs(char *devname, int fd
 				if (ioctl(fd, ADD_NEW_DISK, &disc)) {
 					fprintf(stderr, Name ": add new device failed for %s as %d: %s\n",
 						dv->devname, j, strerror(errno));
-					return 1;
+					goto abort;
 				}
 			}
 			if (verbose >= 0)
@@ -1031,7 +1031,7 @@ int Manage_subdevs(char *devname, int fd
 					" operation on the parent container\n");
 				if (sysfd >= 0)
 					close(sysfd);
-				return 1;
+				goto abort;
 			}
 			if (tst->ss->external) {
 				/* To remove a device from a container, we must
@@ -1051,7 +1051,7 @@ int Manage_subdevs(char *devname, int fd
 						" to container - odd\n");
 					if (sysfd >= 0)
 						close(sysfd);
-					return 1;
+					goto abort;
 				}
 				/* in the detached case it is not possible to
 				 * check if we are the unique holder, so just
@@ -1068,7 +1068,7 @@ int Manage_subdevs(char *devname, int fd
 						errno == EEXIST ? "still in use":
 						"not a member");
 					close(lfd);
-					return 1;
+					goto abort;
 				}
 			}
 			/* FIXME check that it is a current member */
@@ -1111,7 +1111,7 @@ int Manage_subdevs(char *devname, int fd
 					strerror(errno));
 				if (lfd >= 0)
 					close(lfd);
-				return 1;
+				goto abort;
 			}
 			if (tst->ss->external) {
 				/*
@@ -1124,7 +1124,7 @@ int Manage_subdevs(char *devname, int fd
 
 				if (!name) {
 					fprintf(stderr, Name ": unable to get container name\n");
-					return 1;
+					goto abort;
 				}
 
 				ping_manager(name);
@@ -1147,7 +1147,7 @@ int Manage_subdevs(char *devname, int fd
 					dnprintable, strerror(errno));
 				if (sysfd >= 0)
 					close(sysfd);
-				return 1;
+				goto abort;
 			}
 			if (sysfd >= 0)
 				close(sysfd);
@@ -1162,6 +1162,9 @@ int Manage_subdevs(char *devname, int fd
 	if (test && count == 0)
 		return 2;
 	return 0;
+
+abort:
+	return 1;
 }
 
 int autodetect(void)
