|
|
b7f731 |
From b9a0309c7fc3e6c1607d51ab3c3f8486478a65ef Mon Sep 17 00:00:00 2001
|
|
|
b7f731 |
From: Jes Sorensen <jsorensen@fb.com>
|
|
|
b7f731 |
Date: Mon, 8 May 2017 17:34:08 -0400
|
|
|
b7f731 |
Subject: [RHEL7.5 PATCH 117/169] Monitor: Use md_array_active() instead of
|
|
|
b7f731 |
manually fiddling in sysfs
|
|
|
b7f731 |
|
|
|
b7f731 |
This removes a pile of clutter that can easily behandled with a simple
|
|
|
b7f731 |
check of array_state.
|
|
|
b7f731 |
|
|
|
b7f731 |
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
|
|
|
b7f731 |
---
|
|
|
b7f731 |
Monitor.c | 39 +++++++++++----------------------------
|
|
|
b7f731 |
1 file changed, 11 insertions(+), 28 deletions(-)
|
|
|
b7f731 |
|
|
|
b7f731 |
diff --git a/Monitor.c b/Monitor.c
|
|
|
b7f731 |
index e2b36ff..b5231d2 100644
|
|
|
b7f731 |
--- a/Monitor.c
|
|
|
b7f731 |
+++ b/Monitor.c
|
|
|
b7f731 |
@@ -454,7 +454,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
|
|
|
b7f731 |
mdu_array_info_t array;
|
|
|
b7f731 |
struct mdstat_ent *mse = NULL, *mse2;
|
|
|
b7f731 |
char *dev = st->devname;
|
|
|
b7f731 |
- int fd = -1;
|
|
|
b7f731 |
+ int fd;
|
|
|
b7f731 |
int i;
|
|
|
b7f731 |
int remaining_disks;
|
|
|
b7f731 |
int last_disk;
|
|
|
b7f731 |
@@ -462,33 +462,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
|
|
|
b7f731 |
|
|
|
b7f731 |
if (test)
|
|
|
b7f731 |
alert("TestMessage", dev, NULL, ainfo);
|
|
|
b7f731 |
- if (st->devnm[0])
|
|
|
b7f731 |
- fd = open("/sys/block", O_RDONLY|O_DIRECTORY);
|
|
|
b7f731 |
- if (fd >= 0) {
|
|
|
b7f731 |
- /* Don't open the device unless it is present and
|
|
|
b7f731 |
- * active in sysfs.
|
|
|
b7f731 |
- */
|
|
|
b7f731 |
- char buf[10];
|
|
|
b7f731 |
- close(fd);
|
|
|
b7f731 |
- fd = sysfs_open(st->devnm, NULL, "array_state");
|
|
|
b7f731 |
- if (fd < 0 ||
|
|
|
b7f731 |
- read(fd, buf, 10) < 5 ||
|
|
|
b7f731 |
- strncmp(buf,"clear",5) == 0 ||
|
|
|
b7f731 |
- strncmp(buf,"inact",5) == 0) {
|
|
|
b7f731 |
- if (fd >= 0)
|
|
|
b7f731 |
- close(fd);
|
|
|
b7f731 |
- fd = sysfs_open(st->devnm, NULL, "level");
|
|
|
b7f731 |
- if (fd < 0 || read(fd, buf, 10) != 0) {
|
|
|
b7f731 |
- if (fd >= 0)
|
|
|
b7f731 |
- close(fd);
|
|
|
b7f731 |
- if (!st->err)
|
|
|
b7f731 |
- alert("DeviceDisappeared", dev, NULL, ainfo);
|
|
|
b7f731 |
- st->err++;
|
|
|
b7f731 |
- return 0;
|
|
|
b7f731 |
- }
|
|
|
b7f731 |
- }
|
|
|
b7f731 |
- close(fd);
|
|
|
b7f731 |
- }
|
|
|
b7f731 |
+
|
|
|
b7f731 |
fd = open(dev, O_RDONLY);
|
|
|
b7f731 |
if (fd < 0) {
|
|
|
b7f731 |
if (!st->err)
|
|
|
b7f731 |
@@ -496,6 +470,15 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
|
|
|
b7f731 |
st->err++;
|
|
|
b7f731 |
return 0;
|
|
|
b7f731 |
}
|
|
|
b7f731 |
+
|
|
|
b7f731 |
+ if (!md_array_active(fd)) {
|
|
|
b7f731 |
+ close(fd);
|
|
|
b7f731 |
+ if (!st->err)
|
|
|
b7f731 |
+ alert("DeviceDisappeared", dev, NULL, ainfo);
|
|
|
b7f731 |
+ st->err++;
|
|
|
b7f731 |
+ return 0;
|
|
|
b7f731 |
+ }
|
|
|
b7f731 |
+
|
|
|
b7f731 |
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
|
|
b7f731 |
if (md_get_array_info(fd, &array) < 0) {
|
|
|
b7f731 |
if (!st->err)
|
|
|
b7f731 |
--
|
|
|
b7f731 |
2.7.4
|
|
|
b7f731 |
|