Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
65fd0ccb
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
65fd0ccb
编写于
8月 07, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
restore: do not remove container when restart state failed
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
dcad2ec8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
85 deletion
+28
-85
src/daemon/modules/container/restore/restore.c
src/daemon/modules/container/restore/restore.c
+28
-85
未找到文件。
src/daemon/modules/container/restore/restore.c
浏览文件 @
65fd0ccb
...
...
@@ -116,39 +116,6 @@ out:
return
ret
;
}
static
void
post_nonexist_image_containers
(
const
container_t
*
cont
,
Container_Status
status
,
const
struct
runtime_container_status_info
*
info
)
{
int
nret
;
const
char
*
id
=
cont
->
common_config
->
id
;
if
(
info
->
status
==
RUNTIME_CONTAINER_STATUS_STOPPED
)
{
if
(
status
!=
CONTAINER_STATUS_STOPPED
&&
status
!=
CONTAINER_STATUS_CREATED
)
{
nret
=
post_stopped_container_to_gc
(
id
,
cont
->
runtime
,
cont
->
state_path
,
0
);
if
(
nret
!=
0
)
{
ERROR
(
"Failed to post container %s to garbage"
"collector, that may lost some resources"
"used with container!"
,
id
);
}
container_state_set_stopped
(
cont
->
state
,
255
);
}
}
else
if
(
info
->
status
==
RUNTIME_CONTAINER_STATUS_RUNNING
)
{
nret
=
post_stopped_container_to_gc
(
id
,
cont
->
runtime
,
cont
->
state_path
,
info
->
pid
);
if
(
nret
!=
0
)
{
ERROR
(
"Failed to post container %s to garbage"
"collector, that may lost some resources"
"used with container!"
,
id
);
}
container_state_set_stopped
(
cont
->
state
,
255
);
}
else
{
ERROR
(
"Container %s get invalid status %d"
,
id
,
info
->
status
);
}
return
;
}
static
int
check_container_image_exist
(
const
container_t
*
cont
)
{
int
ret
=
0
;
...
...
@@ -208,7 +175,7 @@ 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
)
static
void
restore_stopped_container
(
Container_Status
status
,
const
container_t
*
cont
,
bool
*
need_save
)
{
const
char
*
id
=
cont
->
common_config
->
id
;
pid_t
pid
=
0
;
...
...
@@ -227,14 +194,11 @@ static int restore_stopped_container(Container_Status status, const container_t
container_state_set_stopped
(
cont
->
state
,
255
);
*
need_save
=
true
;
}
return
0
;
}
static
int
restore_running_container
(
Container_Status
status
,
container_t
*
cont
,
const
struct
runtime_container_status_info
*
info
)
static
void
restore_running_container
(
Container_Status
status
,
container_t
*
cont
,
const
struct
runtime_container_status_info
*
info
)
{
int
ret
=
0
;
int
nret
=
0
;
const
char
*
id
=
cont
->
common_config
->
id
;
pid_ppid_info_t
pid_info
=
{
0
};
...
...
@@ -242,6 +206,7 @@ static int restore_running_container(Container_Status status, container_t *cont,
nret
=
util_read_pid_ppid_info
(
info
->
pid
,
&
pid_info
);
if
(
nret
==
0
)
{
try_to_set_container_running
(
status
,
cont
,
&
pid_info
);
container_reset_manually_stopped
(
cont
);
}
else
{
ERROR
(
"Failed to restore container:%s due to unable to read container pid information"
,
id
);
nret
=
post_stopped_container_to_gc
(
id
,
cont
->
runtime
,
cont
->
state_path
,
0
);
...
...
@@ -251,20 +216,13 @@ static int restore_running_container(Container_Status status, container_t *cont,
"used with container!"
,
id
);
}
ret
=
-
1
;
goto
out
;
container_state_set_stopped
(
cont
->
state
,
255
);
}
container_reset_manually_stopped
(
cont
);
out:
return
ret
;
}
static
int
restore_paused_container
(
Container_Status
status
,
container_t
*
cont
,
const
struct
runtime_container_status_info
*
info
)
static
void
restore_paused_container
(
Container_Status
status
,
container_t
*
cont
,
const
struct
runtime_container_status_info
*
info
)
{
int
ret
=
0
;
int
nret
=
0
;
const
char
*
id
=
cont
->
common_config
->
id
;
pid_ppid_info_t
pid_info
=
{
0
};
...
...
@@ -274,6 +232,7 @@ static int restore_paused_container(Container_Status status, container_t *cont,
nret
=
util_read_pid_ppid_info
(
info
->
pid
,
&
pid_info
);
if
(
nret
==
0
)
{
try_to_set_paused_container_pid
(
status
,
cont
,
&
pid_info
);
container_reset_manually_stopped
(
cont
);
}
else
{
ERROR
(
"Failed to restore container:%s due to unable to read container pid information"
,
id
);
nret
=
post_stopped_container_to_gc
(
id
,
cont
->
runtime
,
cont
->
state_path
,
0
);
...
...
@@ -283,20 +242,13 @@ static int restore_paused_container(Container_Status status, container_t *cont,
"used with container!"
,
id
);
}
ret
=
-
1
;
goto
out
;
container_state_set_stopped
(
cont
->
state
,
255
);
}
container_reset_manually_stopped
(
cont
);
out:
return
ret
;
}
/* restore state */
static
int
restore_state
(
container_t
*
cont
)
static
void
restore_state
(
container_t
*
cont
)
{
int
ret
=
0
;
int
nret
=
0
;
bool
need_save
=
false
;
const
char
*
id
=
cont
->
common_config
->
id
;
...
...
@@ -307,13 +259,6 @@ static int restore_state(container_t *cont)
(
void
)
container_exit_on_next
(
cont
);
/* cancel restart policy */
if
(
check_container_image_exist
(
cont
)
!=
0
)
{
ERROR
(
"Failed to restore container:%s due to image not exist"
,
id
);
post_nonexist_image_containers
(
cont
,
status
,
&
real_status
);
ret
=
-
1
;
goto
out
;
}
params
.
rootpath
=
cont
->
root_path
;
params
.
state
=
cont
->
state_path
;
nret
=
runtime_status
(
id
,
runtime
,
&
params
,
&
real_status
);
...
...
@@ -324,36 +269,22 @@ static int restore_state(container_t *cont)
}
if
(
real_status
.
status
==
RUNTIME_CONTAINER_STATUS_STOPPED
)
{
ret
=
restore_stopped_container
(
status
,
cont
,
&
need_save
);
if
(
ret
!=
0
)
{
goto
out
;
}
restore_stopped_container
(
status
,
cont
,
&
need_save
);
}
else
if
(
real_status
.
status
==
RUNTIME_CONTAINER_STATUS_RUNNING
)
{
ret
=
restore_running_container
(
status
,
cont
,
&
real_status
);
if
(
ret
!=
0
)
{
goto
out
;
}
restore_running_container
(
status
,
cont
,
&
real_status
);
}
else
if
(
real_status
.
status
==
RUNTIME_CONTAINER_STATUS_PAUSED
)
{
ret
=
restore_paused_container
(
status
,
cont
,
&
real_status
);
if
(
ret
!=
0
)
{
goto
out
;
}
restore_paused_container
(
status
,
cont
,
&
real_status
);
}
else
{
ERROR
(
"Container %s get invalid status %d"
,
id
,
real_status
.
status
);
ret
=
-
1
;
goto
out
;
}
out:
if
(
container_is_removal_in_progress
(
cont
->
state
))
{
container_state_reset_removal_in_progress
(
cont
->
state
);
need_save
=
true
;
}
if
(
need_save
&&
container_to_disk
(
cont
)
!=
0
)
{
ERROR
(
"Failed to re-save container
\"
%s
\"
to disk"
,
id
);
ret
=
-
1
;
}
return
ret
;
}
/* remove invalid container */
...
...
@@ -450,14 +381,24 @@ static void handle_restored_container()
id
=
cont
->
common_config
->
id
;
if
(
container_is_in_gc_progress
(
id
))
{
ERROR
(
"Container %s is in gc process, skip it in restore process"
,
id
);
goto
unlock_continue
;
}
if
(
container_is_running
(
cont
->
state
))
{
if
(
restore_supervisor
(
cont
)
!=
0
)
{
ERROR
(
"Failed to restore %s supervisor, set state to stopped"
,
id
);
container_state_set_stopped
(
cont
->
state
,
255
);
if
(
post_stopped_container_to_gc
(
id
,
cont
->
runtime
,
cont
->
state_path
,
0
)
!=
0
)
{
ERROR
(
"Failed to post container %s to garbage"
"collector, that may lost some resources"
"used with container!"
,
id
);
}
goto
unlock_continue
;
}
container_init_health_monitor
(
id
);
}
else
{
if
(
cont
->
hostconfig
!=
NULL
&&
cont
->
hostconfig
->
auto_remove_bak
)
{
(
void
)
set_container_to_removal
(
cont
);
...
...
@@ -495,11 +436,13 @@ static void scan_dir_to_add_store(const char *runtime, const char *rootpath, con
goto
error_load
;
}
if
(
restore_state
(
cont
)
)
{
WARN
(
"Failed to restore container %s state
"
,
subdir
[
i
]);
if
(
check_container_image_exist
(
cont
)
!=
0
)
{
ERROR
(
"Failed to restore container:%s due to image not exist
"
,
subdir
[
i
]);
goto
error_load
;
}
restore_state
(
cont
);
index_flag
=
container_name_index_add
(
cont
->
common_config
->
name
,
cont
->
common_config
->
id
);
if
(
!
index_flag
)
{
ERROR
(
"Failed add %s into name indexs"
,
subdir
[
i
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录