Commit 4c332970 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

images: Implement collect_images() to minimaze code lines

Pack repeated actions in one. Also, fixed the "return -1"
from the middle of restore_task_with_children(),
while cleanup is need.

v2: goto err in case of error instead of return -1.
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 149890a8
......@@ -320,7 +320,7 @@ static int run_post_prepare(void)
static int root_prepare_shared(void)
{
int ret = 0, i;
int ret = 0;
struct pstree_item *pi;
pr_info("Preparing info about shared resources\n");
......@@ -331,11 +331,8 @@ static int root_prepare_shared(void)
if (prepare_seccomp_filters())
return -1;
for (i = 0; i < ARRAY_SIZE(cinfos); i++) {
ret = collect_image(cinfos[i]);
if (ret)
return -1;
}
if (collect_images(cinfos, ARRAY_SIZE(cinfos)))
return -1;
for_each_pstree_item(pi) {
if (pi->pid->state == TASK_HELPER)
......@@ -1505,8 +1502,6 @@ static int restore_task_with_children(void *_arg)
/* Restore root task */
if (current->parent == NULL) {
int i;
if (fdstore_init())
goto err;
......@@ -1526,12 +1521,8 @@ static int restore_task_with_children(void *_arg)
if (mount_proc())
goto err;
for (i = 0; i < ARRAY_SIZE(before_ns_cinfos); i++) {
ret = collect_image(before_ns_cinfos[i]);
if (ret)
return -1;
}
if (collect_images(before_ns_cinfos, ARRAY_SIZE(before_ns_cinfos)))
goto err;
if (prepare_namespace(current, ca->clone_flags))
goto err;
......
......@@ -41,4 +41,14 @@ struct collect_image_info {
extern int collect_image(struct collect_image_info *);
static inline int collect_images(struct collect_image_info **array, unsigned size)
{
int i;
for (i = 0; i < size; i++) {
if (collect_image(array[i]))
return -1;
}
return 0;
}
#endif /* __CR_PROTOBUF_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment