mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-09-04 20:51:27 +00:00
cleanup pod after nobody use pod data
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user