kill process in destroy pod

hyper send destroy pod to shutdown vm, we should
give process a chance to handle TERM signal.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2015-12-10 11:19:06 +08:00
parent 2b1edeceb4
commit d34656475e
4 changed files with 45 additions and 39 deletions
+27 -2
View File
@@ -524,6 +524,29 @@ free_exec:
goto out;
}
static int hyper_send_pod_finished(struct hyper_pod *pod)
{
int ret = -1;
struct hyper_container *c;
uint8_t *data = NULL, *new;
int c_num = 0;
list_for_each_entry(c, &pod->containers, list) {
c_num++;
new = realloc(data, c_num * 4);
if (new == NULL)
goto out;
hyper_set_be32(new + ((c_num - 1) * 4), c->exec.code);
data = new;
}
ret = hyper_send_msg_block(ctl.chan.fd, PODFINISHED, c_num * 4, data);
out:
free(data);
return ret;
}
int hyper_release_exec(struct hyper_exec *exec,
struct hyper_pod *pod)
{
@@ -550,8 +573,11 @@ int hyper_release_exec(struct hyper_exec *exec,
return 0;
if (pod->type == STOPPOD) {
/* stop pod manually */
/* stop pod manually, hyper doesn't care the pod finished codes */
hyper_send_msg_block(ctl.chan.fd, ACK, 0, NULL);
} else if (pod->type == DESTROYPOD) {
/* shutdown vm manually, hyper doesn't care the pod finished codes */
hyper_shutdown();
} else {
/* send out pod finish message, hyper will decide if restart pod or not */
hyper_send_pod_finished(pod);
@@ -562,7 +588,6 @@ int hyper_release_exec(struct hyper_exec *exec,
}
hyper_free_exec(exec);
return 0;
}
+14 -2
View File
@@ -669,6 +669,18 @@ static void hyper_print_uptime(void)
close(fd);
}
static int hyper_destroy_pod(struct hyper_pod *pod)
{
if (pod->init_pid == 0) {
/* Pod stopped, just shutdown */
hyper_shutdown();
} else {
/* Kill pod */
hyper_term_all(pod);
}
return 0;
}
static int hyper_start_pod(char *json, int length)
{
struct hyper_pod *pod = &global_pod;
@@ -684,7 +696,7 @@ static int hyper_start_pod(char *json, int length)
}
if (hyper_setup_pod(pod) < 0) {
hyper_shutdown(pod);
hyper_destroy_pod(pod);
return -1;
}
@@ -1151,7 +1163,7 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
//break;
case DESTROYPOD:
fprintf(stdout, "get DESTROYPOD message\n");
hyper_shutdown(pod);
hyper_destroy_pod(pod);
return 0;
case EXECCMD:
ret = hyper_exec_cmd((char *)buf->data + 8, len - 8);
+3 -32
View File
@@ -339,7 +339,7 @@ int hyper_socketpair(int domain, int type, int protocol, int sv[2])
return 0;
}
void hyper_unmount_all(void)
static void hyper_unmount_all(void)
{
FILE *mtab;
struct mntent *mnt;
@@ -384,38 +384,9 @@ void hyper_unmount_all(void)
sync();
}
int hyper_send_pod_finished(struct hyper_pod *pod)
void hyper_shutdown()
{
int ret = -1;
struct hyper_container *c;
uint8_t *data = NULL, *new;
int c_num = 0;
list_for_each_entry(c, &pod->containers, list) {
c_num++;
new = realloc(data, c_num * 4);
if (new == NULL)
goto out;
hyper_set_be32(new + ((c_num - 1) * 4), c->exec.code);
data = new;
}
ret = hyper_send_msg_block(ctl.chan.fd, PODFINISHED, c_num * 4, data);
out:
free(data);
return ret;
}
void hyper_shutdown(struct hyper_pod *pod)
{
hyper_send_pod_finished(pod);
/* vm will shutdown immediately after we call reboot,
* no chance to send out eof message in release exec.
* send it out by ourself */
hyper_cleanup_exec(pod);
hyper_send_msg_block(ctl.chan.fd, ACK, 0, NULL);
hyper_unmount_all();
reboot(LINUX_REBOOT_CMD_POWER_OFF);
}
+1 -3
View File
@@ -24,8 +24,6 @@ int hyper_setfd_cloexec(int fd);
int hyper_setfd_block(int fd);
int hyper_setfd_nonblock(int fd);
int hyper_socketpair(int domain, int type, int protocol, int sv[2]);
void hyper_shutdown(struct hyper_pod *pod);
int hyper_send_pod_finished(struct hyper_pod *pod);
void hyper_unmount_all(void);
void hyper_shutdown(void);
int hyper_insmod(char *module);
#endif