Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
91c2f82a
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,发现更多精彩内容 >>
提交
91c2f82a
编写于
6月 24, 2020
作者:
W
wujing
提交者:
lifeng68
7月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code structure decoupling
Signed-off-by:
N
wujing
<
wujing50@huawei.com
>
上级
4d008e06
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
170 addition
and
228 deletion
+170
-228
src/daemon/image/oci/registry/registry.c
src/daemon/image/oci/registry/registry.c
+0
-1
src/daemon/image/oci/registry/registry_common.c
src/daemon/image/oci/registry/registry_common.c
+0
-181
src/daemon/image/oci/registry/registry_common.h
src/daemon/image/oci/registry/registry_common.h
+0
-41
src/daemon/image/oci/registry_type.c
src/daemon/image/oci/registry_type.c
+0
-0
src/daemon/image/oci/registry_type.h
src/daemon/image/oci/registry_type.h
+1
-2
src/daemon/image/oci/storage/image_store/image_store.c
src/daemon/image/oci/storage/image_store/image_store.c
+0
-1
src/daemon/image/oci/utils_images.c
src/daemon/image/oci/utils_images.c
+159
-0
src/daemon/image/oci/utils_images.h
src/daemon/image/oci/utils_images.h
+9
-0
test/image/oci/storage/images/CMakeLists.txt
test/image/oci/storage/images/CMakeLists.txt
+1
-2
未找到文件。
src/daemon/image/oci/registry/registry.c
浏览文件 @
91c2f82a
...
...
@@ -41,7 +41,6 @@
#include "storage.h"
#include "constants.h"
#include "utils_images.h"
#include "registry_common.h"
#define MANIFEST_BIG_DATA_KEY "manifest"
...
...
src/daemon/image/oci/registry/registry_common.c
已删除
100644 → 0
浏览文件 @
4d008e06
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: WuJing
* Create: 2020-06-13
* Description: provide registry common functions
*******************************************************************************/
#define _GNU_SOURCE
#include "registry_common.h"
#include <stdlib.h>
#include <string.h>
#include "isula_libutils/log.h"
#include "utils.h"
void
free_items_not_inherit
(
docker_image_config_v2
*
config
)
{
size_t
i
=
0
;
if
(
config
==
NULL
)
{
return
;
}
free
(
config
->
id
);
config
->
id
=
NULL
;
free
(
config
->
parent
);
config
->
parent
=
NULL
;
config
->
size
=
0
;
free_docker_image_rootfs
(
config
->
rootfs
);
config
->
rootfs
=
NULL
;
for
(
i
=
0
;
i
<
config
->
history_len
;
i
++
)
{
free_docker_image_history
(
config
->
history
[
i
]);
config
->
history
[
i
]
=
NULL
;
}
config
->
history
=
NULL
;
config
->
history_len
=
0
;
return
;
}
static
char
*
convert_created_by
(
image_manifest_v1_compatibility
*
config
)
{
size_t
i
=
0
;
char
*
created_by
=
NULL
;
size_t
size
=
0
;
if
(
config
==
NULL
||
config
->
container_config
==
NULL
||
config
->
container_config
->
cmd
==
NULL
||
config
->
container_config
->
cmd_len
==
0
)
{
return
NULL
;
}
for
(
i
=
0
;
i
<
config
->
container_config
->
cmd_len
;
i
++
)
{
size
+=
strlen
(
config
->
container_config
->
cmd
[
i
])
+
1
;
// +1 for ' ' or '\0'
}
created_by
=
util_common_calloc_s
(
size
);
if
(
created_by
==
NULL
)
{
ERROR
(
"out of memory"
);
return
NULL
;
}
for
(
i
=
0
;
i
<
config
->
container_config
->
cmd_len
;
i
++
)
{
if
(
i
!=
0
)
{
(
void
)
strcat
(
created_by
,
" "
);
}
(
void
)
strcat
(
created_by
,
config
->
container_config
->
cmd
[
i
]);
}
return
created_by
;
}
int
add_rootfs_and_history
(
const
layer_blob
*
layers
,
size_t
layers_len
,
const
registry_manifest_schema1
*
manifest
,
docker_image_config_v2
*
config
)
{
int
i
=
0
;
int
ret
=
0
;
size_t
history_index
=
0
;
parser_error
err
=
NULL
;
image_manifest_v1_compatibility
*
v1config
=
NULL
;
docker_image_history
*
history
=
NULL
;
if
(
layers
==
NULL
||
layers_len
==
0
||
config
==
NULL
||
manifest
==
NULL
)
{
ERROR
(
"Invalid NULL param"
);
return
-
1
;
}
config
->
rootfs
=
util_common_calloc_s
(
sizeof
(
docker_image_rootfs
));
config
->
history
=
util_common_calloc_s
(
sizeof
(
docker_image_history
*
)
*
layers_len
);
if
(
config
->
rootfs
==
NULL
||
config
->
history
==
NULL
)
{
ERROR
(
"out of memory"
);
return
-
1
;
}
config
->
rootfs
->
type
=
util_strdup_s
(
ROOTFS_TYPE
);
history_index
=
manifest
->
history_len
-
1
;
for
(
i
=
0
;
i
<
layers_len
;
i
++
)
{
v1config
=
image_manifest_v1_compatibility_parse_data
(
manifest
->
history
[
history_index
]
->
v1compatibility
,
NULL
,
&
err
);
if
(
v1config
==
NULL
)
{
ERROR
(
"parse v1 compatibility config failed, err: %s"
,
err
);
ret
=
-
1
;
goto
out
;
}
free
(
err
);
err
=
NULL
;
history
=
util_common_calloc_s
(
sizeof
(
docker_image_history
));
if
(
history
==
NULL
)
{
ERROR
(
"out of memory"
);
ret
=
-
1
;
goto
out
;
}
history
->
created
=
v1config
->
created
;
v1config
->
created
=
NULL
;
history
->
author
=
v1config
->
author
;
v1config
->
author
=
NULL
;
history
->
created_by
=
convert_created_by
(
v1config
);
history
->
comment
=
v1config
->
comment
;
v1config
->
comment
=
NULL
;
history
->
empty_layer
=
layers
[
i
].
empty_layer
;
config
->
history
[
i
]
=
history
;
history
=
NULL
;
config
->
history_len
++
;
free_image_manifest_v1_compatibility
(
v1config
);
v1config
=
NULL
;
history_index
--
;
if
(
layers
[
i
].
empty_layer
)
{
continue
;
}
ret
=
util_array_append
(
&
config
->
rootfs
->
diff_ids
,
layers
[
i
].
diff_id
);
if
(
ret
!=
0
)
{
ERROR
(
"append diff id of layer %u to rootfs failed, diff id is %s"
,
i
,
layers
[
i
].
diff_id
);
ret
=
-
1
;
goto
out
;
}
config
->
rootfs
->
diff_ids_len
++
;
}
out:
free
(
err
);
err
=
NULL
;
free_docker_image_history
(
history
);
history
=
NULL
;
free_image_manifest_v1_compatibility
(
v1config
);
v1config
=
NULL
;
return
ret
;
}
types_timestamp_t
created_to_timestamp
(
char
*
created
)
{
int64_t
nanos
=
0
;
types_timestamp_t
timestamp
=
{
0
};
if
(
to_unix_nanos_from_str
(
created
,
&
nanos
)
!=
0
)
{
ERROR
(
"Failed to get created time from image config"
);
goto
out
;
}
timestamp
.
has_seconds
=
true
;
timestamp
.
seconds
=
nanos
/
Time_Second
;
timestamp
.
has_nanos
=
true
;
timestamp
.
nanos
=
nanos
%
Time_Second
;
out:
return
timestamp
;
}
src/daemon/image/oci/registry/registry_common.h
已删除
100644 → 0
浏览文件 @
4d008e06
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: WuJing
* Create: 2020-06-13
* Description: provide registry common functions
********************************************************************************/
#ifndef __OCI_REGISTRY_COMMON_H
#define __OCI_REGISTRY_COMMON_H
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include "isula_libutils/docker_image_config_v2.h"
#include "isula_libutils/registry_manifest_schema1.h"
#include "isula_libutils/image_manifest_v1_compatibility.h"
#include "registry_type.h"
#include "utils_timestamp.h"
#ifdef __cplusplus
extern
"C"
{
#endif
void
free_items_not_inherit
(
docker_image_config_v2
*
config
);
int
add_rootfs_and_history
(
const
layer_blob
*
layers
,
size_t
layers_len
,
const
registry_manifest_schema1
*
manifest
,
docker_image_config_v2
*
config
);
types_timestamp_t
created_to_timestamp
(
char
*
created
);
#ifdef __cplusplus
}
#endif
#endif
/* __OCI_REGISTRY_COMMON_H */
src/daemon/image/oci/registry
/registry
_type.c
→
src/daemon/image/oci/registry_type.c
浏览文件 @
91c2f82a
文件已移动
src/daemon/image/oci/registry
/registry
_type.h
→
src/daemon/image/oci/registry_type.h
浏览文件 @
91c2f82a
...
...
@@ -20,7 +20,6 @@
#include <time.h>
#include "utils_timestamp.h"
#include "utils_images.h"
// 8 is enough for challenge, usually only one challenge is provided.
#define CHALLENGE_MAX 8
...
...
@@ -107,4 +106,4 @@ void free_challenge(challenge *c);
void
free_layer_blob
(
layer_blob
*
layer
);
void
free_pull_desc
(
pull_descriptor
*
desc
);
#endif
#endif
/* _IMAGE_REGISTRY_TYPE_H */
src/daemon/image/oci/storage/image_store/image_store.c
浏览文件 @
91c2f82a
...
...
@@ -48,7 +48,6 @@
#include "isula_libutils/image_manifest_v1_compatibility.h"
#include "registry_type.h"
#include "mediatype.h"
#include "registry_common.h"
#include "storage.h"
// the name of the big data item whose contents we consider useful for computing a "digest" of the
...
...
src/daemon/image/oci/utils_images.c
浏览文件 @
91c2f82a
...
...
@@ -392,3 +392,162 @@ out:
}
return
diff_id
;
}
void
free_items_not_inherit
(
docker_image_config_v2
*
config
)
{
size_t
i
=
0
;
if
(
config
==
NULL
)
{
return
;
}
free
(
config
->
id
);
config
->
id
=
NULL
;
free
(
config
->
parent
);
config
->
parent
=
NULL
;
config
->
size
=
0
;
free_docker_image_rootfs
(
config
->
rootfs
);
config
->
rootfs
=
NULL
;
for
(
i
=
0
;
i
<
config
->
history_len
;
i
++
)
{
free_docker_image_history
(
config
->
history
[
i
]);
config
->
history
[
i
]
=
NULL
;
}
config
->
history
=
NULL
;
config
->
history_len
=
0
;
return
;
}
static
char
*
convert_created_by
(
image_manifest_v1_compatibility
*
config
)
{
size_t
i
=
0
;
char
*
created_by
=
NULL
;
size_t
size
=
0
;
if
(
config
==
NULL
||
config
->
container_config
==
NULL
||
config
->
container_config
->
cmd
==
NULL
||
config
->
container_config
->
cmd_len
==
0
)
{
return
NULL
;
}
for
(
i
=
0
;
i
<
config
->
container_config
->
cmd_len
;
i
++
)
{
size
+=
strlen
(
config
->
container_config
->
cmd
[
i
])
+
1
;
// +1 for ' ' or '\0'
}
created_by
=
util_common_calloc_s
(
size
);
if
(
created_by
==
NULL
)
{
ERROR
(
"out of memory"
);
return
NULL
;
}
for
(
i
=
0
;
i
<
config
->
container_config
->
cmd_len
;
i
++
)
{
if
(
i
!=
0
)
{
(
void
)
strcat
(
created_by
,
" "
);
}
(
void
)
strcat
(
created_by
,
config
->
container_config
->
cmd
[
i
]);
}
return
created_by
;
}
int
add_rootfs_and_history
(
const
layer_blob
*
layers
,
size_t
layers_len
,
const
registry_manifest_schema1
*
manifest
,
docker_image_config_v2
*
config
)
{
int
i
=
0
;
int
ret
=
0
;
size_t
history_index
=
0
;
parser_error
err
=
NULL
;
image_manifest_v1_compatibility
*
v1config
=
NULL
;
docker_image_history
*
history
=
NULL
;
if
(
layers
==
NULL
||
layers_len
==
0
||
config
==
NULL
||
manifest
==
NULL
)
{
ERROR
(
"Invalid NULL param"
);
return
-
1
;
}
config
->
rootfs
=
util_common_calloc_s
(
sizeof
(
docker_image_rootfs
));
config
->
history
=
util_common_calloc_s
(
sizeof
(
docker_image_history
*
)
*
layers_len
);
if
(
config
->
rootfs
==
NULL
||
config
->
history
==
NULL
)
{
ERROR
(
"out of memory"
);
return
-
1
;
}
config
->
rootfs
->
type
=
util_strdup_s
(
ROOTFS_TYPE
);
history_index
=
manifest
->
history_len
-
1
;
for
(
i
=
0
;
i
<
layers_len
;
i
++
)
{
v1config
=
image_manifest_v1_compatibility_parse_data
(
manifest
->
history
[
history_index
]
->
v1compatibility
,
NULL
,
&
err
);
if
(
v1config
==
NULL
)
{
ERROR
(
"parse v1 compatibility config failed, err: %s"
,
err
);
ret
=
-
1
;
goto
out
;
}
free
(
err
);
err
=
NULL
;
history
=
util_common_calloc_s
(
sizeof
(
docker_image_history
));
if
(
history
==
NULL
)
{
ERROR
(
"out of memory"
);
ret
=
-
1
;
goto
out
;
}
history
->
created
=
v1config
->
created
;
v1config
->
created
=
NULL
;
history
->
author
=
v1config
->
author
;
v1config
->
author
=
NULL
;
history
->
created_by
=
convert_created_by
(
v1config
);
history
->
comment
=
v1config
->
comment
;
v1config
->
comment
=
NULL
;
history
->
empty_layer
=
layers
[
i
].
empty_layer
;
config
->
history
[
i
]
=
history
;
history
=
NULL
;
config
->
history_len
++
;
free_image_manifest_v1_compatibility
(
v1config
);
v1config
=
NULL
;
history_index
--
;
if
(
layers
[
i
].
empty_layer
)
{
continue
;
}
ret
=
util_array_append
(
&
config
->
rootfs
->
diff_ids
,
layers
[
i
].
diff_id
);
if
(
ret
!=
0
)
{
ERROR
(
"append diff id of layer %u to rootfs failed, diff id is %s"
,
i
,
layers
[
i
].
diff_id
);
ret
=
-
1
;
goto
out
;
}
config
->
rootfs
->
diff_ids_len
++
;
}
out:
free
(
err
);
err
=
NULL
;
free_docker_image_history
(
history
);
history
=
NULL
;
free_image_manifest_v1_compatibility
(
v1config
);
v1config
=
NULL
;
return
ret
;
}
types_timestamp_t
created_to_timestamp
(
char
*
created
)
{
int64_t
nanos
=
0
;
types_timestamp_t
timestamp
=
{
0
};
if
(
to_unix_nanos_from_str
(
created
,
&
nanos
)
!=
0
)
{
ERROR
(
"Failed to get created time from image config"
);
goto
out
;
}
timestamp
.
has_seconds
=
true
;
timestamp
.
seconds
=
nanos
/
Time_Second
;
timestamp
.
has_nanos
=
true
;
timestamp
.
nanos
=
nanos
%
Time_Second
;
out:
return
timestamp
;
}
src/daemon/image/oci/utils_images.h
浏览文件 @
91c2f82a
...
...
@@ -19,6 +19,11 @@
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include "isula_libutils/docker_image_config_v2.h"
#include "isula_libutils/registry_manifest_schema1.h"
#include "isula_libutils/image_manifest_v1_compatibility.h"
#include "registry_type.h"
#include "utils_timestamp.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -44,6 +49,10 @@ char *oci_full_image_name(const char *host, const char *name, const char *tag);
char
*
oci_strip_dockerio_prefix
(
const
char
*
name
);
char
*
make_big_data_base_name
(
const
char
*
key
);
char
*
oci_calc_diffid
(
const
char
*
file
);
void
free_items_not_inherit
(
docker_image_config_v2
*
config
);
int
add_rootfs_and_history
(
const
layer_blob
*
layers
,
size_t
layers_len
,
const
registry_manifest_schema1
*
manifest
,
docker_image_config_v2
*
config
);
types_timestamp_t
created_to_timestamp
(
char
*
created
);
#ifdef __cplusplus
}
...
...
test/image/oci/storage/images/CMakeLists.txt
浏览文件 @
91c2f82a
...
...
@@ -19,8 +19,7 @@ add_executable(${EXE}
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_timestamp.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/daemon/image/oci/utils_images.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/daemon/image/oci/storage/image_store/image_type.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/daemon/image/oci/registry/registry_common.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/daemon/image/oci/registry/registry_type.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/daemon/image/oci/registry_type.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/daemon/image/oci/storage/image_store/image_store.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../mocks/storage_mock.cc
storage_images_ut.cpp
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录