]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdmon.c
Revise message passing code.
[thirdparty/mdadm.git] / mdmon.c
diff --git a/mdmon.c b/mdmon.c
index d013dc8ffc9749a643beb4430d2da2a042b9e57c..407f637add3b400c5b72c401a3da00063df38dbf 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
 
 #include       <unistd.h>
 #include       <stdlib.h>
+#include       <sys/types.h>
 #include       <sys/stat.h>
 #include       <sys/socket.h>
 #include       <sys/un.h>
 #include       <sys/mman.h>
+#include       <sys/syscall.h>
 #include       <stdio.h>
 #include       <errno.h>
 #include       <string.h>
 #include       "mdadm.h"
 #include       "mdmon.h"
 
-struct active_array *array_list;
 struct active_array *discard_this;
 struct active_array *pending_discard;
-struct md_generic_cmd *active_cmd;
+
+int mon_tid, mgr_tid;
 
 int run_child(void *v)
 {
        struct supertype *c = v;
+
+       mon_tid = syscall(SYS_gettid);
        do_monitor(c);
        return 0;
 }
@@ -58,28 +62,13 @@ int clone_monitor(struct supertype *container)
        static char stack[4096];
        int rv;
 
-       rv = pipe(container->mgr_pipe);
-       if (rv < 0)
-               return rv;
-       rv = pipe(container->mon_pipe);
-       if (rv < 0)
-               goto err_mon_pipe;
 
        rv = clone(run_child, stack+4096-64,
                   CLONE_FS|CLONE_FILES|CLONE_VM|CLONE_SIGHAND|CLONE_THREAD,
                   container);
-       if (rv < 0)
-               goto err_clone;
-       else
-               return rv;
-
- err_clone:
-       close(container->mon_pipe[0]);
-       close(container->mon_pipe[1]);
- err_mon_pipe:
-       close(container->mgr_pipe[0]);
-       close(container->mgr_pipe[1]);
 
+       mgr_tid = syscall(SYS_gettid);
+       
        return rv;
 }
 
@@ -87,6 +76,8 @@ static struct superswitch *find_metadata_methods(char *vers)
 {
        if (strcmp(vers, "ddf") == 0)
                return &super_ddf;
+       if (strcmp(vers, "imsm") == 0)
+               return &super_imsm;
        return NULL;
 }
 
@@ -141,6 +132,14 @@ static void try_kill_monitor(char *devname)
                kill(pid, SIGTERM);
 }
 
+void remove_pidfile(char *devname)
+{
+       char buf[100];
+
+       sprintf(buf, "/var/run/mdadm/%s.pid", devname);
+       unlink(buf);
+}
+
 static int make_control_sock(char *devname)
 {
        char path[100];
@@ -167,11 +166,19 @@ static int make_control_sock(char *devname)
        return sfd;
 }
 
+static void wake_me(int sig)
+{
+
+}
+
 int main(int argc, char *argv[])
 {
        int mdfd;
        struct mdinfo *mdi, *di;
        struct supertype *container;
+       sigset_t set;
+       struct sigaction act;
+
        if (argc != 2) {
                fprintf(stderr, "Usage: md-manage /device/name/for/container\n");
                exit(2);
@@ -191,9 +198,9 @@ int main(int argc, char *argv[])
        /* hopefully it is a container - we'll check later */
 
        container = malloc(sizeof(*container));
-       container->devfd = mdfd;
        container->devnum = fd2devnum(mdfd);
        container->devname = devnum2devname(container->devnum);
+       container->device_name = argv[1];
 
        /* If this fails, we hope it already exists */
        mkdir("/var/run/mdadm", 0600);
@@ -263,10 +270,23 @@ int main(int argc, char *argv[])
                        argv[1]);
                exit(3);
        }
-
+       close(mdfd);
+       close(mdfd);
 
        mlockall(MCL_FUTURE);
 
+       /* SIGUSR is sent between parent and child.  So both block it
+        * and enable it only with pselect.
+        */
+       sigemptyset(&set);
+       sigaddset(&set, SIGUSR1);
+       sigprocmask(SIG_BLOCK, &set, NULL);
+       act.sa_handler = wake_me;
+       act.sa_flags = 0;
+       sigaction(SIGUSR1, &act, NULL);
+       act.sa_handler = SIG_IGN;
+       sigaction(SIGPIPE, &act, NULL);
+
        if (clone_monitor(container) < 0) {
                fprintf(stderr, "md-manage: failed to start monitor process: %s\n",
                        strerror(errno));