]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Remove mgr_pipe for communicating from manage to monitor.
authorNeil Brown <neilb@suse.de>
Sat, 12 Jul 2008 10:27:40 +0000 (20:27 +1000)
committerNeil Brown <neilb@suse.de>
Sat, 12 Jul 2008 10:27:40 +0000 (20:27 +1000)
Data is being passed in shared memory, so the pipe is only being
use as a wakeup.  This can more easily be done with a thread-signal.

managemon.c
mdadm.h
mdmon.c
mdmon.h
monitor.c
msg.c
msg.h

index e7c60aa9b28fe6deea6aa7f16c9891f1a8712595..9de0c0cb41973e4c602806db4806f2d349b4264f 100644 (file)
@@ -85,6 +85,7 @@
 #endif
 #include       "mdadm.h"
 #include       "mdmon.h"
+#include       <sys/syscall.h>
 #include       <sys/socket.h>
 #include       <signal.h>
 
@@ -143,15 +144,11 @@ static struct active_array *duplicate_aa(struct active_array *aa)
        return newa;
 }
 
-static void write_wakeup(struct supertype *c)
+static void wakeup_monitor(void)
 {
-       static struct md_generic_cmd cmd = { .action = md_action_ping_monitor };
-       int err;
-
-       active_cmd = &cmd;
-
-       /* send the monitor thread a pointer to the ping action */
-       write(c->mgr_pipe[1], &err, 1);
+       /* tgkill(getpid(), mon_tid, SIGUSR1); */
+       int pid = getpid();
+       syscall(SYS_tgkill, pid, mon_tid, SIGUSR1);
 }
 
 static void remove_old(void)
@@ -177,7 +174,7 @@ static void replace_array(struct supertype *container,
         */
        remove_old();
        while (pending_discard) {
-               write_wakeup(container);
+               wakeup_monitor();
                while (discard_this == NULL)
                        sleep(1);
                remove_old();
@@ -186,7 +183,7 @@ static void replace_array(struct supertype *container,
        new->replaces = old;
        new->next = container->arrays;
        container->arrays = new;
-       write_wakeup(container);
+       wakeup_monitor();
 }
 
 struct metadata_update *update_queue = NULL;
@@ -207,7 +204,7 @@ void check_update_queue(struct supertype *container)
            update_queue_pending) {
                update_queue = update_queue_pending;
                update_queue_pending = NULL;
-               write_wakeup(container);
+               wakeup_monitor();
        }
 }
 
@@ -433,16 +430,7 @@ void manage(struct mdstat_ent *mdstat, struct supertype *container)
 
 static int handle_message(struct supertype *container, struct md_message *msg)
 {
-       struct md_generic_cmd *cmd = msg->buf;
-
-       if (!cmd)
-               return 0;
-
-       switch (cmd->action) {
-
-       default:
-               return -1;
-       }
+       return -1;
 }
 
 void read_sock(struct supertype *container)
@@ -485,26 +473,17 @@ void read_sock(struct supertype *container)
        close(fd);
 }
 
-static int woke = 0;
-void wake_me(int sig)
-{
-       woke = 1;
-}
-
 int exit_now = 0;
 int manager_ready = 0;
 void do_manager(struct supertype *container)
 {
        struct mdstat_ent *mdstat;
-       sigset_t block, orig;
+       sigset_t set;
 
-       sigemptyset(&block);
-       sigaddset(&block, SIGUSR1);
-
-       signal(SIGUSR1, wake_me);
+       sigprocmask(SIG_UNBLOCK, NULL, &set);
+       sigdelset(&set, SIGUSR1);
 
        do {
-               woke = 0;
 
                if (exit_now)
                        exit(0);
@@ -522,9 +501,7 @@ void do_manager(struct supertype *container)
                check_update_queue(container);
 
                manager_ready = 1;
-               sigprocmask(SIG_SETMASK, &block, &orig);
-               if (woke == 0)
-                       mdstat_wait_fd(container->sock, &orig);
-               sigprocmask(SIG_SETMASK, &orig, NULL);
+
+               mdstat_wait_fd(container->sock, &set);
        } while(1);
 }
diff --git a/mdadm.h b/mdadm.h
index c0cad4331f42e39c18fa913bac66c2d513317cf2..08b78689b1c410120e3bde3427f09b2669b20cd6 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -582,7 +582,6 @@ struct supertype {
        /* extra stuff used by mdmon */
        struct active_array *arrays;
        int sock; /* listen to external programs */
-       int mgr_pipe[2]; /* communicate between threads */
        int devnum;
        char *devname; /* e.g. md0.  This appears in metadata_verison:
                        *  external:/md0/12
diff --git a/mdmon.c b/mdmon.c
index bb0c4f75a1498390e516af4a0114558c4d4e1fae..08f4445519af9cb8720b5b15ca43178554654516 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>
 
 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;
-       sigset_t set;
-       /* SIGUSR is sent from child to parent,  So child must block it */
-       sigemptyset(&set);
-       sigaddset(&set, SIGUSR1);
-       sigprocmask(SIG_BLOCK, &set, NULL);
 
+       mon_tid = syscall(SYS_gettid);
        do_monitor(c);
        return 0;
 }
@@ -63,22 +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 = 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->mgr_pipe[0]);
-       close(container->mgr_pipe[1]);
 
+       mgr_tid = syscall(SYS_gettid);
+       
        return rv;
 }
 
@@ -176,11 +166,18 @@ 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;
+
        if (argc != 2) {
                fprintf(stderr, "Usage: md-manage /device/name/for/container\n");
                exit(2);
@@ -277,6 +274,14 @@ int main(int argc, char *argv[])
 
        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);
+       signal(SIGUSR1, wake_me);
+
        if (clone_monitor(container) < 0) {
                fprintf(stderr, "md-manage: failed to start monitor process: %s\n",
                        strerror(errno));
diff --git a/mdmon.h b/mdmon.h
index a679ec367d04f3aea8d01dcb1f185a76878ffaa0..403853374e8c6d409808ed47544f1057f0d9321f 100644 (file)
--- a/mdmon.h
+++ b/mdmon.h
@@ -66,3 +66,4 @@ int read_dev_state(int fd);
 struct mdstat_ent *mdstat_read(int hold, int start);
 
 extern int exit_now, manager_ready;
+extern int mon_tid, mgr_tid;
index 0d85d32f2bb3a12151d8ccd7ff520cc498e87715..524411e3a290140e7021be47dec4b8b11b7761cf 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -1,7 +1,7 @@
 
 #include "mdadm.h"
 #include "mdmon.h"
-
+#include <sys/syscall.h>
 #include <sys/select.h>
 #include <signal.h>
 
@@ -138,7 +138,9 @@ int read_dev_state(int fd)
 
 static void signal_manager(void)
 {
-       kill(getpid(), SIGUSR1);
+       /* tgkill(getpid(), mon_tid, SIGUSR1); */
+       int pid = getpid();
+       syscall(SYS_tgkill, pid, mgr_tid, SIGUSR1);
 }
 
 /* Monitor a set of active md arrays - all of which share the
@@ -367,16 +369,6 @@ static void reconcile_failed(struct active_array *aa, struct mdinfo *failed)
        }
 }
 
-static int handle_pipe(struct md_generic_cmd *cmd, struct active_array *aa)
-{
-       switch (cmd->action) {
-       case md_action_ping_monitor:
-               return 0;
-       }
-
-       return -1;
-}
-
 #ifdef DEBUG
 static void dprint_wake_reasons(fd_set *fds)
 {
@@ -407,8 +399,7 @@ static void dprint_wake_reasons(fd_set *fds)
 }
 #endif
 
-static int wait_and_act(struct supertype *container, int pfd,
-                       int nowait)
+static int wait_and_act(struct supertype *container, int nowait)
 {
        fd_set rfds;
        int maxfd = 0;
@@ -419,7 +410,6 @@ static int wait_and_act(struct supertype *container, int pfd,
 
        FD_ZERO(&rfds);
 
-       add_fd(&rfds, &maxfd, pfd);
        for (ap = aap ; *ap ;) {
                a = *ap;
                /* once an array has been deactivated we want to
@@ -463,21 +453,15 @@ static int wait_and_act(struct supertype *container, int pfd,
        }
 
        if (!nowait) {
-               rv = select(maxfd+1, &rfds, NULL, NULL, NULL);
+               sigset_t set;
+               sigprocmask(SIG_UNBLOCK, NULL, &set);
+               sigdelset(&set, SIGUSR1);
+               rv = pselect(maxfd+1, &rfds, NULL, NULL, NULL, &set);
 
                #ifdef DEBUG
                dprint_wake_reasons(&rfds);
                #endif
 
-               if (rv <= 0)
-                       return rv;
-
-               if (FD_ISSET(pfd, &rfds)) {
-                       int err = -1;
-
-                       if (read(pfd, &err, 1) > 0)
-                               err = handle_pipe(active_cmd, *aap);
-               }
        }
 
        if (update_queue) {
@@ -526,8 +510,7 @@ void do_monitor(struct supertype *container)
        int rv;
        int first = 1;
        do {
-               rv = wait_and_act(container, container->mgr_pipe[0],
-                                 first);
+               rv = wait_and_act(container, first);
                first = 0;
        } while (rv >= 0);
 }
diff --git a/msg.c b/msg.c
index d0e505dce29d29cb8453546949a132a6e4bb1b6d..ac40ee5aaf48de2b19a7e840aebaaf4dfdc043c9 100644 (file)
--- a/msg.c
+++ b/msg.c
@@ -88,7 +88,7 @@ tx_rx_message(int fd, struct md_message *msg, int recv_send, int tmo)
                                break;
                        case TX_RX_NUM_BYTES:
                                if (msg->num_bytes >
-                                   sizeof(union md_message_commands))
+                                   1024*1024)
                                        state = TX_RX_ERR;
                                else if (recv_send && msg->num_bytes) {
                                        msg->buf = malloc(msg->num_bytes);
diff --git a/msg.h b/msg.h
index ccaa571beb2dba5f8df8428d9a90c06a356cc51b..433239da8cc45ca818c55a2ea33fab0d503ed029 100644 (file)
--- a/msg.h
+++ b/msg.h
@@ -27,21 +27,6 @@ struct md_message {
        void *buf;
 };
 
-enum md_message_action {
-       md_action_ping_monitor,
-};
-
-struct md_generic_cmd {
-       enum md_message_action action;
-};
-
-/* union of all known command types, used to sanity check ->num_bytes
- * on the receive path
- */
-union md_message_commands {
-       struct md_generic_cmd generic;
-};
-
 extern const int start_magic;
 extern const int end_magic;