summaryrefslogtreecommitdiffstats
path: root/mdstat.c
diff options
context:
space:
mode:
authorTomasz Majchrzak <tomasz.majchrzak@intel.com>2016-07-05 09:12:51 +0200
committerJes Sorensen <Jes.Sorensen@redhat.com>2016-07-21 17:37:17 +0200
commit52209d6ee1183581e148791cf6ee4d60a0193b1d (patch)
tree518c81be1c4f86cf89c59caa72291bfc5d245412 /mdstat.c
parentRemove: container should wait for an array to release a drive (diff)
downloadmdadm-52209d6ee1183581e148791cf6ee4d60a0193b1d.tar.xz
mdadm-52209d6ee1183581e148791cf6ee4d60a0193b1d.zip
Monitor: release /proc/mdstat fd when no arrays present
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>
Diffstat (limited to 'mdstat.c')
-rw-r--r--mdstat.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/mdstat.c b/mdstat.c
index 2972cdf6..39628967 100644
--- 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");