Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
49d2c4c1
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,发现更多精彩内容 >>
提交
49d2c4c1
编写于
6月 20, 2020
作者:
W
WangFengTu
提交者:
lifeng68
7月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reuse image and check diffid
Signed-off-by:
N
WangFengTu
<
wangfengtu@huawei.com
>
上级
5f8472dd
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
73 addition
and
23 deletion
+73
-23
src/daemon/image/oci/registry/registry.c
src/daemon/image/oci/registry/registry.c
+73
-23
未找到文件。
src/daemon/image/oci/registry/registry.c
浏览文件 @
49d2c4c1
...
...
@@ -488,6 +488,12 @@ static int set_cached_info_to_desc(thread_fetch_info *infos, size_t infos_len, p
if
(
desc
->
layers
[
i
].
diff_id
==
NULL
)
{
desc
->
layers
[
i
].
diff_id
=
util_strdup_s
(
cache
->
diffid
);
}
else
if
(
cache
->
diffid
==
NULL
)
{
ERROR
(
"unexpected NULL diff id"
);
return
-
1
;
}
else
if
(
strcmp
(
desc
->
layers
[
i
].
diff_id
,
cache
->
diffid
))
{
ERROR
(
"invalid diff id, expect %s, got %s"
,
desc
->
layers
[
i
].
diff_id
,
cache
->
diffid
);
return
-
1
;
}
if
(
desc
->
layers
[
i
].
file
==
NULL
)
{
...
...
@@ -635,7 +641,7 @@ static int get_top_layer_index(pull_descriptor *desc, size_t *top_layer_index)
return
-
1
;
}
static
int
create_image
(
pull_descriptor
*
desc
,
char
*
image_id
)
static
int
create_image
(
pull_descriptor
*
desc
,
char
*
image_id
,
bool
*
reuse
)
{
int
ret
=
0
;
size_t
top_layer_index
=
0
;
...
...
@@ -643,7 +649,7 @@ static int create_image(pull_descriptor *desc, char *image_id)
char
*
top_layer_id
=
NULL
;
char
*
pre_top_layer
=
NULL
;
if
(
desc
==
NULL
||
image_id
==
NULL
)
{
if
(
desc
==
NULL
||
image_id
==
NULL
||
reuse
==
NULL
)
{
ERROR
(
"Invalid NULL pointer"
);
return
-
1
;
}
...
...
@@ -680,17 +686,25 @@ static int create_image(pull_descriptor *desc, char *image_id)
}
ret
=
0
;
*
reuse
=
true
;
}
else
{
*
reuse
=
false
;
}
ret
=
storage_img_add_name
(
image_id
,
desc
->
dest_image_name
);
if
(
ret
!=
0
)
{
ERROR
(
"add image name failed"
);
if
(
!
(
*
reuse
))
{
if
(
storage_img_delete
(
image_id
,
true
))
{
ERROR
(
"delete image %s failed"
,
image_id
);
}
}
goto
out
;
}
out:
free
(
pre_top_layer
);
return
ret
;
}
...
...
@@ -783,6 +797,7 @@ static int register_image(pull_descriptor *desc)
int
ret
=
0
;
char
*
image_id
=
NULL
;
bool
image_created
=
false
;
bool
reuse
=
false
;
if
(
desc
==
NULL
)
{
ERROR
(
"Invalid NULL pointer"
);
...
...
@@ -797,12 +812,18 @@ static int register_image(pull_descriptor *desc)
}
image_id
=
without_sha256_prefix
(
desc
->
config
.
digest
);
ret
=
create_image
(
desc
,
image_id
);
ret
=
create_image
(
desc
,
image_id
,
&
reuse
);
if
(
ret
!=
0
)
{
ERROR
(
"create image %s failed"
,
desc
->
dest_image_name
);
isulad_try_set_error_message
(
"create image failed"
);
goto
out
;
}
// If image is reused, no need to set file and infos.
if
(
reuse
)
{
goto
out
;
}
image_created
=
true
;
ret
=
set_config
(
desc
,
image_id
);
...
...
@@ -1251,6 +1272,7 @@ static int fetch_layers(pull_descriptor *desc)
sret
=
snprintf
(
file
,
sizeof
(
file
),
"%s/%d"
,
desc
->
blobpath
,
(
int
)
i
);
if
(
sret
<
0
||
(
size_t
)
sret
>=
sizeof
(
file
))
{
ERROR
(
"Failed to sprintf file for layer %d"
,
(
int
)
i
);
ret
=
-
1
;
goto
out
;
}
...
...
@@ -1280,10 +1302,11 @@ static int fetch_layers(pull_descriptor *desc)
ret
=
result
;
}
ret
=
set_cached_info_to_desc
(
infos
,
desc
->
layers_len
,
desc
);
if
(
ret
!=
0
)
{
if
(
ret
==
0
)
{
if
(
set_cached_info_to_desc
(
infos
,
desc
->
layers_len
,
desc
)
!=
0
)
{
ERROR
(
"set cached infos to desc failed"
);
}
}
mutex_unlock
(
&
g_shared
->
mutex
);
...
...
@@ -1394,12 +1417,40 @@ out:
return
ret
;
}
static
int
registry_fetch
(
pull_descriptor
*
desc
)
static
bool
reuse_image
(
pull_descriptor
*
desc
)
{
int
ret
=
0
;
imagetool_image
*
image
=
NULL
;
bool
reuse
=
false
;
char
*
id
=
NULL
;
if
(
desc
==
NULL
)
{
// If the image already exist, do not pull it again.
image
=
storage_img_get
(
desc
->
dest_image_name
);
if
(
image
==
NULL
||
desc
->
config
.
digest
==
NULL
||
image
->
id
==
NULL
)
{
goto
out
;
}
id
=
without_sha256_prefix
(
desc
->
config
.
digest
);
if
(
id
==
NULL
)
{
goto
out
;
}
if
(
!
strcmp
(
id
,
image
->
id
))
{
DEBUG
(
"image %s with id %s already exist, ignore pulling"
,
desc
->
dest_image_name
,
image
->
id
);
reuse
=
true
;
}
out:
free_imagetool_image
(
image
);
image
=
NULL
;
return
reuse
;
}
static
int
registry_fetch
(
pull_descriptor
*
desc
,
bool
*
reuse
)
{
int
ret
=
0
;
if
(
desc
==
NULL
||
reuse
==
NULL
)
{
ERROR
(
"Invalid NULL param"
);
return
-
1
;
}
...
...
@@ -1411,10 +1462,8 @@ static int registry_fetch(pull_descriptor *desc)
goto
out
;
}
// If the image already exist, do not pull it again.
image
=
storage_img_get
(
desc
->
dest_image_name
);
if
(
image
!=
NULL
&&
desc
->
config
.
digest
!=
NULL
&&
!
strcmp
(
image
->
id
,
desc
->
config
.
digest
))
{
DEBUG
(
"image %s with id %s already exist, ignore pulling"
,
desc
->
dest_image_name
,
image
->
id
);
*
reuse
=
reuse_image
(
desc
);
if
(
*
reuse
)
{
goto
out
;
}
...
...
@@ -1449,8 +1498,6 @@ static int registry_fetch(pull_descriptor *desc)
}
out:
free_imagetool_image
(
image
);
image
=
NULL
;
return
ret
;
}
...
...
@@ -1556,6 +1603,7 @@ int registry_pull(registry_pull_options *options)
{
int
ret
=
0
;
pull_descriptor
*
desc
=
NULL
;
bool
reuse
=
false
;
if
(
options
==
NULL
||
options
->
image_name
==
NULL
)
{
ERROR
(
"Invalid NULL param"
);
...
...
@@ -1576,7 +1624,7 @@ int registry_pull(registry_pull_options *options)
goto
out
;
}
ret
=
registry_fetch
(
desc
);
ret
=
registry_fetch
(
desc
,
&
reuse
);
if
(
ret
!=
0
)
{
ERROR
(
"error fetching %s"
,
options
->
image_name
);
isulad_try_set_error_message
(
"error fetching %s"
,
options
->
image_name
);
...
...
@@ -1584,6 +1632,7 @@ int registry_pull(registry_pull_options *options)
goto
out
;
}
if
(
!
reuse
)
{
ret
=
register_image
(
desc
);
if
(
ret
!=
0
)
{
ERROR
(
"error register image %s to store"
,
options
->
image_name
);
...
...
@@ -1591,6 +1640,7 @@ int registry_pull(registry_pull_options *options)
ret
=
-
1
;
goto
out
;
}
}
INFO
(
"Pull images %s success"
,
options
->
image_name
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录