From: Jes Sorensen Date: Tue, 9 May 2017 20:38:06 +0000 (-0400) Subject: Monitor/check_array: Reduce duplicated error handling X-Git-Tag: mdadm-4.1-rc1~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13e5d8455c22d4db420ead9fde3ee0c1536b73a3;p=thirdparty%2Fmdadm.git Monitor/check_array: Reduce duplicated error handling Avoid closing fd in multiple places, and duplicating the error message for when a device disappeared. Signed-off-by: Jes Sorensen --- diff --git a/Monitor.c b/Monitor.c index f4040099..c5198775 100644 --- a/Monitor.c +++ b/Monitor.c @@ -467,29 +467,16 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat, retval = 0; fd = open(dev, O_RDONLY); - if (fd < 0) { - if (!st->err) - alert("DeviceDisappeared", dev, NULL, ainfo); - st->err++; - goto out; - } + if (fd < 0) + goto disappeared; - if (!md_array_active(fd)) { - close(fd); - if (!st->err) - alert("DeviceDisappeared", dev, NULL, ainfo); - st->err++; - goto out; - } + if (!md_array_active(fd)) + goto disappeared; fcntl(fd, F_SETFD, FD_CLOEXEC); - if (md_get_array_info(fd, &array) < 0) { - if (!st->err) - alert("DeviceDisappeared", dev, NULL, ainfo); - st->err++; - close(fd); - goto out; - } + if (md_get_array_info(fd, &array) < 0) + goto disappeared; + /* It's much easier to list what array levels can't * have a device disappear than all of them that can */ @@ -497,7 +484,6 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat, if (!st->err && !st->from_config) alert("DeviceDisappeared", dev, " Wrong-Level", ainfo); st->err++; - close(fd); goto out; } if (st->devnm[0] == 0) @@ -534,7 +520,6 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat, st->working == array.working_disks && st->spare == array.spare_disks && (mse == NULL || (mse->percent == st->percent))) { - close(fd); if ((st->active < st->raid) && st->spare == 0) retval = 1; goto out; @@ -614,8 +599,6 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat, if (st->metadata == NULL && st->parent_devnm[0] == 0) st->metadata = super_by_fd(fd, NULL); - close(fd); - for (i=0; i 0) + close(fd); return retval; + + disappeared: + if (!st->err) + alert("DeviceDisappeared", dev, NULL, ainfo); + st->err++; + goto out; } static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,