]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Monitor: release /proc/mdstat fd when no arrays present
authorTomasz Majchrzak <tomasz.majchrzak@intel.com>
Tue, 5 Jul 2016 07:12:51 +0000 (09:12 +0200)
committerJes Sorensen <Jes.Sorensen@redhat.com>
Thu, 21 Jul 2016 15:37:17 +0000 (11:37 -0400)
If md kernel module is reloaded, /proc/mdstat cannot be accessed ("cat:
/proc/mdstat: No such file or directory"). The reason is mdadm monitor
still holds a file descriptor to previous /proc/mdstat instance. It
leads to really confusing outcome of the following operations - mdadm
seems to run without errors, however some udev rules don't get executed
and new array doesn't work.

Add a check if lseek was successful as it fails if md kernel module has
been unloaded - close a file descriptor then. The problem is mdadm
monitor doesn't always do it before next operation takes place. To
prevent it monitor always releases /proc/mdstat descriptor when there
are no arrays to be monitored, just in case driver unload happens in a
moment.

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Reviewed-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Monitor.c
mdstat.c

index 4adc23750845486cb1eef215fa3bf869e3d6227e..802a9d9864b9cbec68ec8d2214642970070160a7 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -213,6 +213,8 @@ 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,
index 2972cdf63288495606db90908c3a5baa04950cca..39628967047e7b8275269871fdd79507fa5112e3 100644 (file)
--- a/mdstat.c
+++ b/mdstat.c
@@ -133,7 +133,11 @@ struct mdstat_ent *mdstat_read(int hold, int start)
        int fd;
 
        if (hold && mdstat_fd != -1) {
-               lseek(mdstat_fd, 0L, 0);
+               off_t offset = lseek(mdstat_fd, 0L, 0);
+               if (offset == (off_t)-1) {
+                       mdstat_close();
+                       return NULL;
+               }
                fd = dup(mdstat_fd);
                if (fd >= 0)
                        f = fdopen(fd, "r");