#endif
#include "mdadm.h"
#include "mdmon.h"
+#include <sys/syscall.h>
#include <sys/socket.h>
#include <signal.h>
/* Note that this doesn't close fds if they are being used
* by a clone. ->container will be set for a clone
*/
+ dprintf("%s: devnum: %d\n", __func__, aa->devnum);
if (!aa->container)
close_aa(aa);
while (aa->info.devs) {
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);
- read(c->mon_pipe[0], &err, 1);
+ /* tgkill(getpid(), mon_tid, SIGUSR1); */
+ int pid = getpid();
+ syscall(SYS_tgkill, pid, mon_tid, SIGUSR1);
}
static void remove_old(void)
*/
remove_old();
while (pending_discard) {
- write_wakeup(container);
+ wakeup_monitor();
while (discard_this == NULL)
sleep(1);
remove_old();
new->replaces = old;
new->next = container->arrays;
container->arrays = new;
- write_wakeup(container);
+ wakeup_monitor();
}
struct metadata_update *update_queue = NULL;
while (update_queue_handled) {
struct metadata_update *this = update_queue_handled;
update_queue_handled = this->next;
-// free(this->buf);
+ free(this->buf);
+ if (this->space)
+ free(this->space);
free(this);
}
if (update_queue == NULL &&
update_queue_pending) {
update_queue = update_queue_pending;
update_queue_pending = NULL;
- write_wakeup(container);
+ wakeup_monitor();
}
}
new->info.state_fd = sysfs_open(new->devnum, NULL, "array_state");
new->resync_start_fd = sysfs_open(new->devnum, NULL, "resync_start");
new->resync_start = 0;
+ dprintf("%s: inst: %d action: %d state: %d\n", __func__, atoi(inst),
+ new->action_fd, new->info.state_fd);
sysfs_free(mdi);
// finds and compares.
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;
- }
+ return -1;
}
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;
-
- sigemptyset(&block);
- sigaddset(&block, SIGUSR1);
+ sigset_t set;
- signal(SIGUSR1, wake_me);
+ sigprocmask(SIG_UNBLOCK, NULL, &set);
+ sigdelset(&set, SIGUSR1);
do {
- woke = 0;
if (exit_now)
exit(0);
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);
}