diff options
author | Dan Williams <dan.j.williams@intel.com> | 2008-05-15 16:48:54 +1000 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2008-05-15 16:48:54 +1000 |
commit | 3e70c845e25295d80680d884d5671107bf8bded3 (patch) | |
tree | 3a8b69bb18e66ee64db5c6a0705d90a9f0843e02 /managemon.c | |
parent | b109d92863bfa319d140b305132ca41bfb8d1194 (diff) |
add infrastructure to receive higher order commands, like remove_device
From: Dan Williams <dan.j.williams@intel.com>
Each md_message encapsulates a single command. A command includes an 'action'
member which describes what if any data comes after the action. Communication
with the monitor involves updating the active_cmd pointer and then writing to
mgr_pipe. Pass/fail status is returned via mon_pipe.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'managemon.c')
-rw-r--r-- | managemon.c | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/managemon.c b/managemon.c index f8123d0e..23019468 100644 --- a/managemon.c +++ b/managemon.c @@ -74,10 +74,8 @@ #endif #include "mdadm.h" #include "mdmon.h" -#include "msg.h" #include <sys/socket.h> - static void close_aa(struct active_array *aa) { struct mdinfo *d; @@ -108,7 +106,14 @@ static void free_aa(struct active_array *aa) static void write_wakeup(struct supertype *c) { - write(c->pipe[1], "PING", 4); + 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); + read(c->mon_pipe[0], &err, 1); } static void replace_array(struct supertype *container, @@ -300,7 +305,29 @@ void manage(struct mdstat_ent *mdstat, struct active_array *aa, } } -void read_sock(int pfd) +static int handle_message(struct supertype *container, struct md_message *msg) +{ + int err; + struct md_generic_cmd *cmd = msg->buf; + + if (!cmd) + return 0; + + switch (cmd->action) { + case md_action_remove_device: + + /* forward to the monitor */ + active_cmd = cmd; + write(container->mgr_pipe[1], &err, 1); + read(container->mon_pipe[0], &err, 1); + return err; + + default: + return -1; + } +} + +void read_sock(struct supertype *container) { int fd; struct md_message msg; @@ -308,7 +335,7 @@ void read_sock(int pfd) long fl; int tmo = 3; /* 3 second timeout before hanging up the socket */ - fd = accept(pfd, NULL, NULL); + fd = accept(container->sock, NULL, NULL); if (fd < 0) return; @@ -317,12 +344,17 @@ void read_sock(int pfd) fcntl(fd, F_SETFL, fl); do { + int err; + msg.buf = NULL; /* read and validate the message */ if (receive_message(fd, &msg, tmo) == 0) { - // FIXME: handle message contents - ack(fd, msg.seq, tmo); + err = handle_message(container, &msg); + if (!err) + ack(fd, msg.seq, tmo); + else + nack(fd, err, tmo); } else { terminate = 1; nack(fd, -1, tmo); @@ -343,7 +375,7 @@ void do_manager(struct supertype *container) manage(mdstat, array_list, container); - read_sock(container->sock); + read_sock(container); mdstat_wait_fd(container->sock); } while(1); |