dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/Monitor-check_array-Centralize-exit-path.patch

2c1b57
From 1830e74b4cbde28279f341bc80b68e9d82df32c6 Mon Sep 17 00:00:00 2001
2c1b57
From: Jes Sorensen <jsorensen@fb.com>
2c1b57
Date: Tue, 9 May 2017 16:25:23 -0400
2c1b57
Subject: [RHEL7.5 PATCH 125/169] Monitor/check_array: Centralize exit path
2c1b57
2c1b57
Improve exit handling to make it easier to share error handling and free
2c1b57
sysfs entries later.
2c1b57
2c1b57
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2c1b57
---
2c1b57
 Monitor.c | 24 ++++++++++++++----------
2c1b57
 1 file changed, 14 insertions(+), 10 deletions(-)
2c1b57
2c1b57
diff --git a/Monitor.c b/Monitor.c
2c1b57
index c96f8e8..f404009 100644
2c1b57
--- a/Monitor.c
2c1b57
+++ b/Monitor.c
2c1b57
@@ -459,16 +459,19 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
2c1b57
 	int remaining_disks;
2c1b57
 	int last_disk;
2c1b57
 	int new_array = 0;
2c1b57
+	int retval;
2c1b57
 
2c1b57
 	if (test)
2c1b57
 		alert("TestMessage", dev, NULL, ainfo);
2c1b57
 
2c1b57
+	retval = 0;
2c1b57
+
2c1b57
 	fd = open(dev, O_RDONLY);
2c1b57
 	if (fd < 0) {
2c1b57
 		if (!st->err)
2c1b57
 			alert("DeviceDisappeared", dev, NULL, ainfo);
2c1b57
 		st->err++;
2c1b57
-		return 0;
2c1b57
+		goto out;
2c1b57
 	}
2c1b57
 
2c1b57
 	if (!md_array_active(fd)) {
2c1b57
@@ -476,7 +479,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
2c1b57
 		if (!st->err)
2c1b57
 			alert("DeviceDisappeared", dev, NULL, ainfo);
2c1b57
 		st->err++;
2c1b57
-		return 0;
2c1b57
+		goto out;
2c1b57
 	}
2c1b57
 
2c1b57
 	fcntl(fd, F_SETFD, FD_CLOEXEC);
2c1b57
@@ -485,7 +488,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
2c1b57
 			alert("DeviceDisappeared", dev, NULL, ainfo);
2c1b57
 		st->err++;
2c1b57
 		close(fd);
2c1b57
-		return 0;
2c1b57
+		goto out;
2c1b57
 	}
2c1b57
 	/* It's much easier to list what array levels can't
2c1b57
 	 * have a device disappear than all of them that can
2c1b57
@@ -495,7 +498,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
2c1b57
 			alert("DeviceDisappeared", dev, " Wrong-Level", ainfo);
2c1b57
 		st->err++;
2c1b57
 		close(fd);
2c1b57
-		return 0;
2c1b57
+		goto out;
2c1b57
 	}
2c1b57
 	if (st->devnm[0] == 0)
2c1b57
 		strcpy(st->devnm, fd2devnm(fd));
2c1b57
@@ -511,7 +514,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
2c1b57
 		 * or re-created after reading mdstat*/
2c1b57
 		st->err++;
2c1b57
 		close(fd);
2c1b57
-		return 0;
2c1b57
+		goto out;
2c1b57
 	}
2c1b57
 	/* this array is in /proc/mdstat */
2c1b57
 	if (array.utime == 0)
2c1b57
@@ -533,9 +536,8 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
2c1b57
 	    (mse == NULL  || (mse->percent == st->percent))) {
2c1b57
 		close(fd);
2c1b57
 		if ((st->active < st->raid) && st->spare == 0)
2c1b57
-			return 1;
2c1b57
-		else
2c1b57
-			return 0;
2c1b57
+			retval = 1;
2c1b57
+		goto out;
2c1b57
 	}
2c1b57
 	if (st->utime == 0 && /* new array */
2c1b57
 	    mse->pattern && strchr(mse->pattern, '_') /* degraded */)
2c1b57
@@ -656,8 +658,10 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
2c1b57
 	st->raid = array.raid_disks;
2c1b57
 	st->err = 0;
2c1b57
 	if ((st->active < st->raid) && st->spare == 0)
2c1b57
-		return 1;
2c1b57
-	return 0;
2c1b57
+		retval = 1;
2c1b57
+
2c1b57
+ out:
2c1b57
+	return retval;
2c1b57
 }
2c1b57
 
2c1b57
 static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
2c1b57
-- 
2c1b57
2.7.4
2c1b57