send eof message to hyper before shutdown vm

When hyperstart received destory-vm message, some execs are still
running, send eof message immediately.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2015-10-24 20:51:39 +08:00
parent c86afd1a5c
commit 99ee15c731
3 changed files with 21 additions and 62 deletions
+10 -4
View File
@@ -636,14 +636,20 @@ int hyper_handle_exec_exit(struct hyper_pod *pod, int pid, uint8_t code)
return 0;
}
/*
void hyper_cleanup_exec(struct hyper_pod *pod)
{
struct hyper_exec *exec, *next;
uint8_t buf[12];
if (hyper_setfd_block(ctl.tty.fd) < 0)
return;
hyper_set_be32(buf + 8, 12);
list_for_each_entry_safe(exec, next, &pod->exec_head, list) {
fprintf(stdout, "cleanup exec seq %" PRIu64 "\n", exec->seq);
hyper_release_exec(exec, pod);
fprintf(stdout, "send eof for exec seq %" PRIu64 "\n", exec->seq);
hyper_set_be64(buf, exec->seq);
if (hyper_send_data(ctl.tty.fd, buf, 12) < 0)
fprintf(stderr, "send eof failed\n");
}
}
*/
+5 -14
View File
@@ -10,6 +10,7 @@
#include <termios.h>
#include "hyper.h"
#include "util.h"
#include "../config.h"
void hyper_set_be32(uint8_t *buf, uint32_t val)
@@ -115,14 +116,9 @@ int hyper_get_type_block(int fd, uint32_t *type)
{
int ret = 0, flags;
flags = fcntl(fd, F_GETFL, 0);
flags = hyper_setfd_block(fd);
if (flags < 0) {
fprintf(stderr, "%s get fd flag failed\n", __func__);
return -1;
}
if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) < 0) {
perror("set fd BLOCK failed");
fprintf(stderr, "%s fail to set fd block\n", __func__);
return -1;
}
@@ -144,14 +140,9 @@ int hyper_send_type_block(int fd, uint32_t type, int need_ack)
int ret = 0, flags;
uint32_t t;
flags = fcntl(fd, F_GETFL, 0);
flags = hyper_setfd_block(fd);
if (flags < 0) {
fprintf(stderr, "get fd flag failed\n");
return -1;
}
if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) < 0) {
perror("set fd BLOCK failed");
fprintf(stderr, "%s fail to set fd block\n", __func__);
return -1;
}
+6 -44
View File
@@ -304,7 +304,7 @@ int hyper_setfd_block(int fd)
return -1;
}
return 0;
return flags;
}
int hyper_setfd_nonblock(int fd)
@@ -321,7 +321,7 @@ int hyper_setfd_nonblock(int fd)
return -1;
}
return 0;
return flags;
}
int hyper_socketpair(int domain, int type, int protocol, int sv[2])
@@ -384,46 +384,6 @@ void hyper_unmount_all(void)
sync();
}
void hyper_kill_all(void)
{
int npids = 0;
int index = 0;
int pid;
DIR *dp;
struct dirent *de;
pid_t *pids = NULL;
dp = opendir("/proc");
if (dp == NULL)
return;
while ((de = readdir(dp)) && de != NULL) {
if (!isdigit(de->d_name[0]))
continue;
pid = atoi(de->d_name);
if (pid == 1)
continue;
if (index <= npids) {
pids = realloc(pids, npids + 16384);
if (pids == NULL)
return;
npids += 16384;
}
pids[index++] = pid;
}
fprintf(stdout, "Sending SIGTERM\n");
for (--index; index >= 0; --index) {
fprintf(stdout, "kill process %d\n", pids[index]);
kill(pids[index], SIGTERM);
}
free(pids);
closedir(dp);
}
int hyper_send_finish(struct hyper_pod *pod)
{
int i, ret;
@@ -440,8 +400,10 @@ int hyper_send_finish(struct hyper_pod *pod)
void hyper_shutdown(struct hyper_pod *pod)
{
hyper_send_finish(pod);
//hyper_kill_all();
/* 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_unmount_all();