cleanup pod after nobody use pod data

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2015-10-10 20:49:20 +08:00
parent 555bc46d14
commit f3f78303b1
4 changed files with 30 additions and 11 deletions
+2 -1
View File
@@ -524,6 +524,7 @@ int hyper_release_exec(struct hyper_exec *exec,
/* stop pod, should not restart container */
if (pod->type == STOPPOD) {
hyper_send_type(ctl.chan.fd, ACK);
hyper_cleanup_pod(pod);
return 0;
}
@@ -531,7 +532,7 @@ int hyper_release_exec(struct hyper_exec *exec,
if (pod->policy == POLICY_NEVER ||
((pod->policy == POLICY_ONFAILURE) && pod->code == 0)) {
hyper_send_finish(pod);
//hyper_shutdown(pod);
hyper_cleanup_pod(pod);
return 0;
}
+1
View File
@@ -88,6 +88,7 @@ int hyper_mkdir(char *hyper_path);
int hyper_open_serial(char *tty);
struct hyper_container *hyper_find_container(struct hyper_pod *pod, char *id);
int hyper_start_containers(struct hyper_pod *pod);
void hyper_cleanup_pod(struct hyper_pod *pod);
extern struct hyper_pod global_pod;
extern struct hyper_ctl ctl;
+17 -9
View File
@@ -911,6 +911,12 @@ out:
return ret;
}
static void hyper_cleanup_hostname(struct hyper_pod *pod)
{
free(pod->hostname);
pod->hostname = NULL;
}
static void hyper_cleanup_shared(struct hyper_pod *pod)
{
if (pod->tag == NULL) {
@@ -919,6 +925,7 @@ static void hyper_cleanup_shared(struct hyper_pod *pod)
}
free(pod->tag);
pod->tag = NULL;
if (umount("/tmp/hyper/shared") < 0 &&
umount2("/tmp/hyper/shared", MNT_DETACH)) {
perror("fail to umount 9p dir");
@@ -931,6 +938,16 @@ static void hyper_cleanup_shared(struct hyper_pod *pod)
sync();
}
void hyper_cleanup_pod(struct hyper_pod *pod)
{
hyper_cleanup_exec(pod);
hyper_cleanup_container(pod);
hyper_cleanup_network(pod);
hyper_cleanup_shared(pod);
hyper_cleanup_dns(pod);
hyper_cleanup_hostname(pod);
}
static int hyper_stop_pod(struct hyper_pod *pod)
{
fprintf(stdout, "hyper_stop_pod init_pid %d\n", pod->init_pid);
@@ -940,16 +957,7 @@ static int hyper_stop_pod(struct hyper_pod *pod)
}
pod->init_pid = 0;
hyper_term_all(pod);
hyper_cleanup_exec(pod);
hyper_cleanup_container(pod);
hyper_cleanup_network(pod);
hyper_cleanup_dns(pod);
hyper_cleanup_shared(pod);
free(pod->hostname);
return 0;
}
+10 -1
View File
@@ -869,8 +869,17 @@ out:
void hyper_cleanup_dns(struct hyper_pod *pod)
{
int fd = open("/tmp/hyper/resolv.conf", O_WRONLY| O_TRUNC);
int fd, i;
for (i = 0; i < pod->d_num; i++) {
free(pod->dns[i]);
}
free(pod->dns);
pod->dns = NULL;
pod->d_num = 0;
fd = open("/tmp/hyper/resolv.conf", O_WRONLY| O_TRUNC);
if (fd < 0) {
perror("open /tmp/hyper/resolv.conf failed");
return;