File 0125-Monitor-check_array-Centralize-exit-path.patch of Package mdadm.7989

From 1830e74b4cbde28279f341bc80b68e9d82df32c6 Mon Sep 17 00:00:00 2001
From: Jes Sorensen <jsorensen@fb.com>
Date: Tue, 9 May 2017 16:25:23 -0400
Subject: [PATCH] Monitor/check_array: Centralize exit path
Git-commit: 1830e74b4cbde28279f341bc80b68e9d82df32c6
Patch-mainline: mdadm-4.0+
References: bsc#1069165, bsc#1069167, bsc#1068030

Improve exit handling to make it easier to share error handling and free
sysfs entries later.

Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Signed-off-by: Coly Li <colyli@suse.de>

---
 Monitor.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/Monitor.c b/Monitor.c
index c96f8e8..f404009 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -459,16 +459,19 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 	int remaining_disks;
 	int last_disk;
 	int new_array = 0;
+	int retval;
 
 	if (test)
 		alert("TestMessage", dev, NULL, ainfo);
 
+	retval = 0;
+
 	fd = open(dev, O_RDONLY);
 	if (fd < 0) {
 		if (!st->err)
 			alert("DeviceDisappeared", dev, NULL, ainfo);
 		st->err++;
-		return 0;
+		goto out;
 	}
 
 	if (!md_array_active(fd)) {
@@ -476,7 +479,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 		if (!st->err)
 			alert("DeviceDisappeared", dev, NULL, ainfo);
 		st->err++;
-		return 0;
+		goto out;
 	}
 
 	fcntl(fd, F_SETFD, FD_CLOEXEC);
@@ -485,7 +488,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 			alert("DeviceDisappeared", dev, NULL, ainfo);
 		st->err++;
 		close(fd);
-		return 0;
+		goto out;
 	}
 	/* It's much easier to list what array levels can't
 	 * have a device disappear than all of them that can
@@ -495,7 +498,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 			alert("DeviceDisappeared", dev, " Wrong-Level", ainfo);
 		st->err++;
 		close(fd);
-		return 0;
+		goto out;
 	}
 	if (st->devnm[0] == 0)
 		strcpy(st->devnm, fd2devnm(fd));
@@ -511,7 +514,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 		 * or re-created after reading mdstat*/
 		st->err++;
 		close(fd);
-		return 0;
+		goto out;
 	}
 	/* this array is in /proc/mdstat */
 	if (array.utime == 0)
@@ -533,9 +536,8 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 	    (mse == NULL  || (mse->percent == st->percent))) {
 		close(fd);
 		if ((st->active < st->raid) && st->spare == 0)
-			return 1;
-		else
-			return 0;
+			retval = 1;
+		goto out;
 	}
 	if (st->utime == 0 && /* new array */
 	    mse->pattern && strchr(mse->pattern, '_') /* degraded */)
@@ -656,8 +658,10 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
 	st->raid = array.raid_disks;
 	st->err = 0;
 	if ((st->active < st->raid) && st->spare == 0)
-		return 1;
-	return 0;
+		retval = 1;
+
+ out:
+	return retval;
 }
 
 static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
-- 
2.13.6
openSUSE Build Service is sponsored by