remove pipe between pod and hyper init

Get rid of pipe by stopping pod in hyper init.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2015-10-10 18:01:40 +08:00
parent b14f68378d
commit 555bc46d14
3 changed files with 16 additions and 116 deletions
+6 -4
View File
@@ -515,16 +515,18 @@ int hyper_release_exec(struct hyper_exec *exec,
fprintf(stdout, "%s container init exited, type %d, remains %d, policy %d\n",
__func__, pod->type, pod->remains, pod->policy);
/* stop pod, should not restart container */
if (pod->type == STOPPOD)
return 0;
if (exec->code)
pod->code = exec->code;
if (--pod->remains > 0)
return 0;
/* stop pod, should not restart container */
if (pod->type == STOPPOD) {
hyper_send_type(ctl.chan.fd, ACK);
return 0;
}
/* should shutdown? */
if (pod->policy == POLICY_NEVER ||
((pod->policy == POLICY_ONFAILURE) && pod->code == 0)) {
-2
View File
@@ -56,7 +56,6 @@ struct hyper_pod {
uint8_t policy;
int efd;
struct hyper_event sig;
struct hyper_event ctl;
};
struct hyper_win_size {
@@ -83,7 +82,6 @@ struct hyper_ctl {
struct hyper_event sig;
struct hyper_event tty;
struct hyper_event chan;
struct hyper_event ctl;
};
int hyper_mkdir(char *hyper_path);
+10 -110
View File
@@ -179,25 +179,6 @@ static void hyper_term_all(struct hyper_pod *pod)
}
}
static int pod_ctl_pipe_handle(struct hyper_event *de, uint32_t len)
{
struct hyper_buf *buf = &de->rbuf;
fprintf(stdout, "%s\n", __func__);
if (hyper_get_be32(buf->data) == STOPPOD) {
struct hyper_pod *pod = de->ptr;
fprintf(stdout, "pod init get type STOPPOD, exit\n");
hyper_term_all(pod);
hyper_reset_event(&pod->ctl);
hyper_unmount_all();
_exit(0);
}
return 0;
}
static int hyper_handle_exit(struct hyper_pod *pod)
{
int pid, status;
@@ -258,14 +239,6 @@ static int hyper_signal_loop(struct hyper_event *de)
return 0;
}
static struct hyper_event_ops pod_ctl_pipe_ops = {
.read = hyper_event_read,
.handle = pod_ctl_pipe_handle,
.hup = hyper_event_hup,
.rbuf_size = 8,
.len_offset = 4,
};
static int pod_init_loop(struct hyper_pod *pod)
{
int i, n;
@@ -277,14 +250,6 @@ static int pod_init_loop(struct hyper_pod *pod)
return -1;
}
fprintf(stdout, "hyper_init_event pod ctl pipe event %p, ops %p, fd %d\n",
&pod->ctl, &pod_ctl_pipe_ops, pod->ctl.fd);
if (hyper_init_event(&pod->ctl, &pod_ctl_pipe_ops, pod) < 0 ||
hyper_add_event(pod->efd, &pod->ctl, EPOLLIN) < 0) {
fprintf(stderr, "hyper add pod ctl pipe event failed\n");
return -1;
}
fprintf(stdout, "hyper_init_event pod signal event %p, ops %p, fd %d\n",
&pod->sig, &hyper_signal_ops, pod->sig.fd);
if (hyper_init_event(&pod->sig, &hyper_signal_ops, NULL) < 0 ||
@@ -333,11 +298,6 @@ static int hyper_pod_init(void *data)
close(ctl.tty.fd);
pod->sig.fd = -1;
pod->ctl.fd = arg->ctl_pipe[1];
if (hyper_setfd_cloexec(pod->ctl.fd) < 0) {
perror("set pod init ctl pipe fd FD_CLOEXEC failed");
goto fail;
}
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
@@ -369,47 +329,26 @@ static int hyper_pod_init(void *data)
goto fail;
}
fprintf(stdout, "pod ctl_pipe %d\n", arg->ctl_pipe[1]);
if (hyper_send_type(arg->ctl_pipe[1], READY) < 0) {
fprintf(stderr, "container init send ready message failed\n");
goto fail;
}
close(arg->ctl_pipe[1]);
pod_init_loop(pod);
fprintf(stdout, "pod init exit\n");
out:
_exit(-1);
fail:
close(pod->sig.fd);
hyper_send_type(arg->ctl_pipe[1], ERROR);
close(arg->ctl_pipe[1]);
close(pod->sig.fd);
goto out;
}
static int hyper_ctl_pipe_handle(struct hyper_event *de, uint32_t len)
{
struct hyper_buf *buf = &de->rbuf;
uint32_t type;
/* container exec finish message */
fprintf(stdout, "%s\n", __func__);
type = hyper_get_be32(buf->data);
switch (type) {
case ACK:
/* ACK only being sent on stoppod, in this case, ctl pipe
* fd is block, and ACK is the last message, exit loop. */
fprintf(stdout, "hyper_ctl_pipe_loop get ack\n");
return 1;
default:
fprintf(stdout, "get unknown type %" PRIu32"\n", type);
break;
}
return 0;
}
static int hyper_do_start_containers(void *data)
{
int i, pidns, ipcns, utsns, ret;
@@ -525,14 +464,6 @@ out:
return ret;
}
static struct hyper_event_ops hyper_ctl_pipe_ops = {
.read = hyper_event_read,
.handle = hyper_ctl_pipe_handle,
.hup = hyper_event_hup,
.rbuf_size = 256,
.len_offset = 4,
};
static int hyper_setup_container(struct hyper_pod *pod)
{
int stacksize = getpagesize() * 4;
@@ -559,7 +490,6 @@ static int hyper_setup_container(struct hyper_pod *pod)
goto out;
}
ctl.ctl.fd = arg.ctl_pipe[0];
arg.pod = pod;
pod->init_pid = clone(hyper_pod_init, stack + stacksize, flags, &arg);
@@ -586,22 +516,11 @@ static int hyper_setup_container(struct hyper_pod *pod)
goto out;
}
if (hyper_setfd_cloexec(arg.ctl_pipe[0]) < 0) {
perror("set ctl pipe fd FD_CLOEXEC failed");
goto out;
}
fprintf(stdout, "hyper_init_event hyper ctl pipe fd %d\n", ctl.ctl.fd);
if (hyper_init_event(&ctl.ctl, &hyper_ctl_pipe_ops, pod) < 0 ||
hyper_add_event(ctl.efd, &ctl.ctl, EPOLLIN) < 0) {
goto out;
}
ret = 0;
out:
close(arg.ctl_pipe[1]);
close(arg.ctl_pipe[0]);
if (ret < 0) {
close(arg.ctl_pipe[0]);
hyper_stop_pod(pod);
}
return ret;
@@ -1008,23 +927,8 @@ static void hyper_cleanup_shared(struct hyper_pod *pod)
if (rmdir("/tmp/hyper/shared") < 0)
perror("fail to delete /tmp/hyper/shared");
}
static int hyper_send_stoppod(int fd)
{
if (hyper_setfd_block(fd) < 0) {
perror("set fd BLOCK failed");
return -1;
}
if (hyper_send_type(fd, STOPPOD) < 0) {
fprintf(stderr, "send STOPPOD message failed\n");
return -1;
}
hyper_event_read(&ctl.ctl);
return 0;
sync();
}
static int hyper_stop_pod(struct hyper_pod *pod)
@@ -1036,9 +940,8 @@ static int hyper_stop_pod(struct hyper_pod *pod)
}
pod->init_pid = 0;
/* Make hyper ctl_pipe blocked */
hyper_send_stoppod(ctl.ctl.fd);
hyper_term_all(pod);
hyper_cleanup_exec(pod);
hyper_cleanup_container(pod);
hyper_cleanup_network(pod);
@@ -1047,10 +950,6 @@ static int hyper_stop_pod(struct hyper_pod *pod)
free(pod->hostname);
sync();
/* Wait for pod init ack */
close(ctl.ctl.fd);
hyper_reset_event(&ctl.ctl);
return 0;
}
@@ -1165,7 +1064,8 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
break;
case STOPPOD:
ret = hyper_stop_pod(pod);
break;
return 0;
//break;
case DESTROYPOD:
fprintf(stdout, "get DESTROYPOD message\n");
hyper_shutdown(pod);