]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - msg.c
Discard devnum in favour of devnm
[thirdparty/mdadm.git] / msg.c
diff --git a/msg.c b/msg.c
index 98d6d13b1e216d27189a47427e8db17f10b22026..776b29be4d0d67b2dc53563385e46a6640b43d3a 100644 (file)
--- a/msg.c
+++ b/msg.c
@@ -106,9 +106,7 @@ int receive_message(int fd, struct metadata_update *msg, int tmo)
        if (rv < 0 || len > MSG_MAX_LEN)
                return -1;
        if (len > 0) {
-               msg->buf = malloc(len);
-               if (msg->buf == NULL)
-                       return -1;
+               msg->buf = xmalloc(len);
                rv = recv_buf(fd, msg->buf, len, tmo);
                if (rv < 0) {
                        free(msg->buf);
@@ -207,22 +205,13 @@ int fping_monitor(int sfd)
 int ping_monitor(char *devname)
 {
        int sfd = connect_monitor(devname);
-       int err = fping_monitor(sfd);
-
-       close(sfd);
-       return err;
-}
+       int err;
 
-/* ping monitor using device number */
-int ping_monitor_by_id(int devnum)
-{
-       int err = -1;
-       char *container = devnum2devname(devnum);
-
-       if (container) {
-               err = ping_monitor(container);
-               free(container);
-       }
+       if (sfd >= 0) {
+               err = fping_monitor(sfd);
+               close(sfd);
+       } else
+               err = -1;
 
        return err;
 }
@@ -288,9 +277,8 @@ int block_subarray(struct mdinfo *sra)
 int check_mdmon_version(char *container)
 {
        char *version = NULL;
-       int devnum = devname2devnum(container);
 
-       if (!mdmon_running(devnum)) {
+       if (!mdmon_running(container)) {
                /* if mdmon is not active we assume that any instance that is
                 * later started will match the current mdadm version, if this
                 * assumption is violated we may inadvertantly rebuild an array
@@ -305,9 +293,8 @@ int check_mdmon_version(char *container)
                ver = version ? mdadm_version(version) : -1;
                free(version);
                if (ver < 3002000) {
-                       fprintf(stderr, Name
-                               ": mdmon instance for %s cannot be disabled\n",
-                               container);
+                       pr_err("mdmon instance for %s cannot be disabled\n",
+                              container);
                        return -1;
                }
        }
@@ -346,8 +333,7 @@ int block_monitor(char *container, const int freeze)
 
        ent = mdstat_read(0, 0);
        if (!ent) {
-               fprintf(stderr, Name
-                       ": failed to read /proc/mdstat while disabling mdmon\n");
+               pr_err("failed to read /proc/mdstat while disabling mdmon\n");
                return -1;
        }
 
@@ -356,11 +342,10 @@ int block_monitor(char *container, const int freeze)
                if (!is_container_member(e, container))
                        continue;
                sysfs_free(sra);
-               sra = sysfs_read(-1, e->devnum, GET_VERSION);
+               sra = sysfs_read(-1, e->devnm, GET_VERSION);
                if (!sra) {
-                       fprintf(stderr, Name
-                               ": failed to read sysfs for subarray%s\n",
-                               to_subarray(e, container));
+                       pr_err("failed to read sysfs for subarray%s\n",
+                              to_subarray(e, container));
                        break;
                }
                /* can't reshape an array that we can't monitor */
@@ -393,7 +378,7 @@ int block_monitor(char *container, const int freeze)
                 * or part-spares
                 */
                sysfs_free(sra);
-               sra = sysfs_read(-1, e->devnum, GET_DEVS | GET_STATE);
+               sra = sysfs_read(-1, e->devnm, GET_DEVS | GET_STATE);
                if (sra && sra->array.spare_disks > 0) {
                        unblock_subarray(sra, freeze);
                        break;
@@ -401,7 +386,7 @@ int block_monitor(char *container, const int freeze)
        }
 
        if (e) {
-               fprintf(stderr, Name ": failed to freeze subarray%s\n",
+               pr_err("failed to freeze subarray%s\n",
                        to_subarray(e, container));
 
                /* thaw the partially frozen container */
@@ -409,9 +394,9 @@ int block_monitor(char *container, const int freeze)
                        if (!is_container_member(e2, container))
                                continue;
                        sysfs_free(sra);
-                       sra = sysfs_read(-1, e2->devnum, GET_VERSION);
+                       sra = sysfs_read(-1, e2->devnm, GET_VERSION);
                        if (unblock_subarray(sra, freeze))
-                               fprintf(stderr, Name ": Failed to unfreeze %s\n", e2->dev);
+                               pr_err("Failed to unfreeze %s\n", e2->dev);
                }
 
                ping_monitor(container); /* cleared frozen */
@@ -432,8 +417,7 @@ void unblock_monitor(char *container, const int unfreeze)
 
        ent = mdstat_read(0, 0);
        if (!ent) {
-               fprintf(stderr, Name
-                       ": failed to read /proc/mdstat while unblocking container\n");
+               pr_err("failed to read /proc/mdstat while unblocking container\n");
                return;
        }
 
@@ -442,11 +426,13 @@ void unblock_monitor(char *container, const int unfreeze)
                if (!is_container_member(e, container))
                        continue;
                sysfs_free(sra);
-               sra = sysfs_read(-1, e->devnum, GET_VERSION|GET_LEVEL);
+               sra = sysfs_read(-1, e->devnm, GET_VERSION|GET_LEVEL);
+               if (!sra)
+                       continue;
                if (sra->array.level > 0)
                        to_ping++;
                if (unblock_subarray(sra, unfreeze))
-                       fprintf(stderr, Name ": Failed to unfreeze %s\n", e->dev);
+                       pr_err("Failed to unfreeze %s\n", e->dev);
        }
        if (to_ping)
                ping_monitor(container);
@@ -455,8 +441,6 @@ void unblock_monitor(char *container, const int unfreeze)
        free_mdstat(ent);
 }
 
-
-
 /* give the manager a chance to view the updated container state.  This
  * would naturally happen due to the manager noticing a change in
  * /proc/mdstat; however, pinging encourages this detection to happen
@@ -480,3 +464,13 @@ int ping_manager(char *devname)
        close(sfd);
        return err;
 }
+
+/* using takeover operation for grow purposes, mdadm has to be sure
+ * that mdmon processes all updates, and if necessary it will be closed
+ * at takeover to raid0 operation
+  */
+void flush_mdmon(char *container)
+{
+       ping_manager(container);
+       ping_monitor(container);
+}