]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Monitor: refresh mdstat fd after select
authorMariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Wed, 9 Sep 2020 08:31:17 +0000 (10:31 +0200)
committerJes Sorensen <jsorensen@fb.com>
Wed, 14 Oct 2020 15:31:39 +0000 (11:31 -0400)
After 52209d6ee118 ("Monitor: release /proc/mdstat fd when no arrays
present") mdstat fd is closed if mdstat is empty or cannot be opened.
It causes that monitor is not able to select on mdstat. Select
doesn't fail because it gets valid descriptor to a different resource.
As a result any new event will be unnoticed until timeout (delay).

Refresh mdstat after wake up, don't poll on wrong resource.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Monitor.c
mdstat.c

index 2d6b3b9016e4e4f608e230bfe16e1642c5875016..80a3200fec6b752d38cb205373fc65e8f8ea5754 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -216,8 +216,6 @@ int Monitor(struct mddev_dev *devlist,
                if (mdstat)
                        free_mdstat(mdstat);
                mdstat = mdstat_read(oneshot ? 0 : 1, 0);
-               if (!mdstat)
-                       mdstat_close();
 
                for (st = statelist; st; st = st->next)
                        if (check_array(st, mdstat, c->test, &info,
@@ -238,8 +236,10 @@ int Monitor(struct mddev_dev *devlist,
                if (!new_found) {
                        if (oneshot)
                                break;
-                       else
+                       else {
                                mdstat_wait(c->delay);
+                               mdstat_close();
+                       }
                }
                c->test = 0;
 
index 20577a35e78b4199ceff85c9c0e8a5f2369104d5..48559e6443890066bdd570b6c2a32ec860f970dd 100644 (file)
--- a/mdstat.c
+++ b/mdstat.c
@@ -135,7 +135,6 @@ struct mdstat_ent *mdstat_read(int hold, int start)
        if (hold && mdstat_fd != -1) {
                off_t offset = lseek(mdstat_fd, 0L, 0);
                if (offset == (off_t)-1) {
-                       mdstat_close();
                        return NULL;
                }
                fd = dup(mdstat_fd);
@@ -312,7 +311,8 @@ void mdstat_wait(int seconds)
        if (mdstat_fd >= 0) {
                FD_SET(mdstat_fd, &fds);
                maxfd = mdstat_fd;
-       }
+       } else
+               return;
        tm.tv_sec = seconds;
        tm.tv_usec = 0;
        select(maxfd + 1, NULL, NULL, &fds, &tm);