]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Monitor.c
Fix RAID metadata check
[thirdparty/mdadm.git] / Monitor.c
index a5300329b464b8108e2deec305cf1418a82ca5db..802a9d9864b9cbec68ec8d2214642970070160a7 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -33,7 +33,7 @@
 struct state {
        char *devname;
        char devnm[32]; /* to sync with mdstat info */
-       long utime;
+       unsigned int utime;
        int err;
        char *spare_group;
        int active, working, failed, spare, raid;
@@ -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,
@@ -597,7 +599,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
                } else
                        alert("RebuildFinished", dev, NULL, ainfo);
                if (sra)
-                       free(sra);
+                       sysfs_free(sra);
        }
        st->percent = mse->percent;
 
@@ -993,6 +995,7 @@ int Wait(char *dev)
        struct stat stb;
        char devnm[32];
        int rv = 1;
+       int frozen_remaining = 3;
 
        if (stat(dev, &stb) != 0) {
                pr_err("Cannot find %s: %s\n", dev,
@@ -1009,7 +1012,7 @@ int Wait(char *dev)
                        if (strcmp(e->devnm, devnm) == 0)
                                break;
 
-               if (e->percent == RESYNC_NONE) {
+               if (e && e->percent == RESYNC_NONE) {
                        /* We could be in the brief pause before something
                         * starts. /proc/mdstat doesn't show that, but
                         * sync_action does.
@@ -1019,8 +1022,15 @@ int Wait(char *dev)
                        sysfs_init(&mdi, -1, devnm);
                        if (sysfs_get_str(&mdi, NULL, "sync_action",
                                          buf, 20) > 0 &&
-                           strcmp(buf,"idle\n") != 0)
+                           strcmp(buf,"idle\n") != 0) {
                                e->percent = RESYNC_UNKNOWN;
+                               if (strcmp(buf, "frozen\n") == 0) {
+                                       if (frozen_remaining == 0)
+                                               e->percent = RESYNC_NONE;
+                                       else
+                                               frozen_remaining -= 1;
+                               }
+                       }
                }
                if (!e || e->percent == RESYNC_NONE) {
                        if (e && e->metadata_version &&