iSulad: do resume when do gc process
Signed-off-by: LiFeng <lifeng68@huawei.com>
This commit is contained in:
parent
43555b4437
commit
368f9f2ca0
@ -498,7 +498,7 @@ pack_response:
|
||||
return (cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||
}
|
||||
|
||||
static int resume_container(container_t *cont)
|
||||
static int do_resume_container(container_t *cont)
|
||||
{
|
||||
int ret = 0;
|
||||
const char *id = cont->common_config->id;
|
||||
@ -662,7 +662,7 @@ static int container_resume_cb(const container_resume_request *request, containe
|
||||
goto pack_response;
|
||||
}
|
||||
|
||||
ret = resume_container(cont);
|
||||
ret = do_resume_container(cont);
|
||||
if (ret != 0) {
|
||||
cc = ISULAD_ERR_EXEC;
|
||||
container_state_set_error(cont->state, (const char *)g_isulad_errmsg);
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "utils.h"
|
||||
#include "execution.h"
|
||||
#include "containers_store.h"
|
||||
#include "runtime.h"
|
||||
|
||||
static containers_gc_t g_gc_containers;
|
||||
|
||||
@ -385,6 +386,57 @@ static void add_to_list_tail_to_retry_gc(struct linked_list *it)
|
||||
gc_containers_unlock();
|
||||
}
|
||||
|
||||
static int do_runtime_resume_container(const container_t *cont)
|
||||
{
|
||||
int ret = 0;
|
||||
rt_resume_params_t params = { 0 };
|
||||
const char *id = cont->common_config->id;
|
||||
|
||||
params.rootpath = cont->root_path;
|
||||
|
||||
if (runtime_resume(id, cont->runtime, ¶ms)) {
|
||||
ERROR("Failed to resume container:%s", id);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
state_reset_paused(cont->state);
|
||||
|
||||
if (container_to_disk(cont)) {
|
||||
ERROR("Failed to save container \"%s\" to disk", id);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void try_to_resume_container(const char *id, const char *runtime)
|
||||
{
|
||||
int ret = 0;
|
||||
container_t *cont = NULL;
|
||||
|
||||
if (id == NULL || runtime == NULL) {
|
||||
ERROR("Invalid input arguments");
|
||||
goto out;
|
||||
}
|
||||
|
||||
cont = containers_store_get(id);
|
||||
if (cont == NULL) {
|
||||
WARN("No such container:%s", id);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = do_runtime_resume_container(cont);
|
||||
if (ret != 0) {
|
||||
ERROR("try to runtime resume failed");
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
container_unref(cont);
|
||||
}
|
||||
|
||||
static void gc_container_process(struct linked_list *it)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -424,6 +476,7 @@ static void gc_container_process(struct linked_list *it)
|
||||
free_container_garbage_config_gc_containers_element(gc_cont);
|
||||
free(it);
|
||||
} else {
|
||||
try_to_resume_container(id, runtime);
|
||||
ret = kill(pid, SIGKILL);
|
||||
if (ret < 0 && errno != ESRCH) {
|
||||
ERROR("Can not kill process (pid=%d) with SIGKILL for container %s", pid, id);
|
||||
|
||||
@ -205,10 +205,14 @@ static void try_to_set_container_running(Container_Status status, container_t *c
|
||||
static int restore_stopped_container(Container_Status status, const container_t *cont, bool *need_save)
|
||||
{
|
||||
const char *id = cont->common_config->id;
|
||||
pid_t pid = 0;
|
||||
|
||||
if (status != CONTAINER_STATUS_STOPPED && \
|
||||
status != CONTAINER_STATUS_CREATED) {
|
||||
int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, 0);
|
||||
if (util_process_alive(cont->state->state->pid, cont->state->state->start_time)) {
|
||||
pid = cont->state->state->pid;
|
||||
}
|
||||
int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, pid);
|
||||
if (nret != 0) {
|
||||
ERROR("Failed to post container %s to garbage"
|
||||
"collector, that may lost some resources"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user