Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
6fc0f024
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,发现更多精彩内容 >>
提交
6fc0f024
编写于
8月 22, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
image: fix lock error when list all images
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
512b8468
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
13 addition
and
144 deletion
+13
-144
src/daemon/modules/image/oci/storage/image_store/image_store.c
...aemon/modules/image/oci/storage/image_store/image_store.c
+11
-116
src/daemon/modules/image/oci/storage/image_store/image_store.h
...aemon/modules/image/oci/storage/image_store/image_store.h
+0
-3
src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
...mon/modules/image/oci/storage/rootfs_store/rootfs_store.c
+2
-7
test/image/oci/storage/images/storage_images_ut.cpp
test/image/oci/storage/images/storage_images_ut.cpp
+0
-18
未找到文件。
src/daemon/modules/image/oci/storage/image_store/image_store.c
浏览文件 @
6fc0f024
...
...
@@ -1674,35 +1674,15 @@ static int remove_image_dir(const char *id)
return
0
;
}
int
image_store_delete
(
const
char
*
id
)
static
int
do_delete_image_info
(
const
char
*
id
)
{
int
ret
=
0
;
image_t
*
img
=
NULL
;
if
(
id
==
NULL
)
{
ERROR
(
"Invalid input parameter: empty id"
);
return
-
1
;
}
if
(
g_image_store
==
NULL
)
{
ERROR
(
"Image store is not ready"
);
return
-
1
;
}
if
(
!
image_store_exists
(
id
))
{
WARN
(
"image %s not exists already, return success"
,
id
);
return
0
;
}
if
(
!
image_store_lock
(
EXCLUSIVE
))
{
ERROR
(
"Failed to lock image store with exclusive lock, not allowed to delete image from store"
);
return
-
1
;
}
img
=
lookup
(
id
);
if
(
img
==
NULL
)
{
ERROR
(
"Image not known"
);
ret
=
-
1
;
WARN
(
"image %s not exists already, return success"
,
id
);
ret
=
0
;
goto
out
;
}
...
...
@@ -1720,14 +1700,12 @@ int image_store_delete(const char *id)
out:
image_ref_dec
(
img
);
image_store_unlock
();
return
ret
;
}
static
int
delete_image_from_store_without_lock
(
const
char
*
id
)
int
image_store_delete
(
const
char
*
id
)
{
int
ret
=
0
;
image_t
*
img
=
NULL
;
if
(
id
==
NULL
)
{
ERROR
(
"Invalid input parameter: empty id"
);
...
...
@@ -1739,59 +1717,18 @@ static int delete_image_from_store_without_lock(const char *id)
return
-
1
;
}
img
=
lookup
(
id
);
if
(
img
==
NULL
)
{
ERROR
(
"Image not known"
);
if
(
!
image_store_lock
(
EXCLUSIVE
))
{
ERROR
(
"Failed to lock image store with exclusive lock, not allowed to delete image from store"
);
return
-
1
;
}
if
(
remove_image_from_memory
(
img
->
simage
->
id
)
!=
0
)
{
ERROR
(
"Failed to remove image from memory"
);
ret
=
-
1
;
goto
out
;
}
if
(
remove_image_dir
(
img
->
simage
->
id
)
!=
0
)
{
ERROR
(
"Failed to delete image directory"
);
if
(
do_delete_image_info
(
id
)
!=
0
)
{
ERROR
(
"Failed to delete image info %s"
,
id
);
ret
=
-
1
;
goto
out
;
}
out:
image_ref_dec
(
img
);
return
ret
;
}
int
image_store_wipe
()
{
int
ret
=
0
;
char
*
id
=
NULL
;
struct
linked_list
*
item
=
NULL
;
struct
linked_list
*
next
=
NULL
;
if
(
g_image_store
==
NULL
)
{
ERROR
(
"Image store is not ready"
);
return
-
1
;
}
if
(
!
image_store_lock
(
EXCLUSIVE
))
{
ERROR
(
"Failed to lock image store with exclusive lock, not allowed to delete images"
);
return
-
1
;
}
linked_list_for_each_safe
(
item
,
&
(
g_image_store
->
images_list
),
next
)
{
id
=
util_strdup_s
(((
image_t
*
)
item
->
elem
)
->
simage
->
id
);
if
(
delete_image_from_store_without_lock
(
id
)
!=
0
)
{
ERROR
(
"Failed to delete image: %s"
,
id
);
ret
=
-
1
;
goto
out
;
}
free
(
id
);
id
=
NULL
;
}
out:
free
(
id
);
image_store_unlock
();
return
ret
;
}
...
...
@@ -3335,35 +3272,6 @@ out:
return
imginfo
;
}
static
int
image_list_shrink_to_fit
(
imagetool_images_list
*
images_list
)
{
int
ret
=
0
;
imagetool_image
**
tmp
=
NULL
;
// all images loaded
if
(
images_list
->
images_len
==
g_image_store
->
images_list_len
)
{
return
0
;
}
// all images damaged
if
(
images_list
->
images_len
==
0
)
{
free
(
images_list
->
images
);
images_list
->
images
=
NULL
;
return
0
;
}
// memory shrink to fit
ret
=
mem_realloc
((
void
**
)(
&
tmp
),
images_list
->
images_len
*
sizeof
(
imagetool_image
*
),
images_list
->
images
,
g_image_store
->
images_list_len
*
sizeof
(
imagetool_image
*
));
if
(
ret
!=
0
)
{
ERROR
(
"Failed to realloc memory for memory shrink to fit"
);
return
-
1
;
}
images_list
->
images
=
tmp
;
return
0
;
}
int
image_store_get_all_images
(
imagetool_images_list
*
images_list
)
{
int
ret
=
0
;
...
...
@@ -3380,8 +3288,8 @@ int image_store_get_all_images(imagetool_images_list *images_list)
return
-
1
;
}
if
(
!
image_store_lock
(
SHARED
))
{
ERROR
(
"Failed to lock image store with
shared
lock, not allowed to get all the known images"
);
if
(
!
image_store_lock
(
EXCLUSIVE
))
{
ERROR
(
"Failed to lock image store with
exclusive
lock, not allowed to get all the known images"
);
return
-
1
;
}
...
...
@@ -3399,33 +3307,20 @@ int image_store_get_all_images(imagetool_images_list *images_list)
linked_list_for_each_safe
(
item
,
&
(
g_image_store
->
images_list
),
next
)
{
imagetool_image
*
imginfo
=
NULL
;
image_t
*
img
=
(
image_t
*
)
item
->
elem
;
imginfo
=
get_image_info
(
img
);
if
(
imginfo
==
NULL
)
{
ERROR
(
"Delete image %s due to: Get image information failed, image may be damaged"
,
img
->
simage
->
id
);
image_store_unlock
();
if
(
image_store_delete
(
img
->
simage
->
id
)
!=
0
)
{
if
(
do_delete_image_info
(
img
->
simage
->
id
)
!=
0
)
{
ERROR
(
"Failed to delete image, please delete residual file manually"
);
}
if
(
!
image_store_lock
(
SHARED
))
{
ERROR
(
"Failed to relock image store with shared lock, not allowed to get the known images"
);
ret
=
-
1
;
goto
out
;
}
continue
;
}
images_list
->
images
[
images_list
->
images_len
++
]
=
imginfo
;
imginfo
=
NULL
;
}
if
(
image_list_shrink_to_fit
(
images_list
)
!=
0
)
{
WARN
(
"Failed to shrink to fit memory"
);
goto
unlock
;
}
unlock:
image_store_unlock
();
out:
return
ret
;
}
...
...
src/daemon/modules/image/oci/storage/image_store/image_store.h
浏览文件 @
6fc0f024
...
...
@@ -49,9 +49,6 @@ char *image_store_lookup(const char *id);
// Remove the record of the image.
int
image_store_delete
(
const
char
*
id
);
// Remove records of all images
int
image_store_wipe
();
// Stores a (potentially large) piece of data associated with this ID.
int
image_store_set_big_data
(
const
char
*
id
,
const
char
*
key
,
const
char
*
data
);
...
...
src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
浏览文件 @
6fc0f024
...
...
@@ -999,11 +999,6 @@ int rootfs_store_delete(const char *id)
return
-
1
;
}
if
(
!
rootfs_store_exists
(
id
))
{
WARN
(
"rootfs %s not exists already, return success"
,
id
);
return
0
;
}
if
(
!
rootfs_store_lock
(
EXCLUSIVE
))
{
ERROR
(
"Failed to lock rootfs store"
);
return
-
1
;
...
...
@@ -1011,8 +1006,8 @@ int rootfs_store_delete(const char *id)
cntr
=
lookup
(
id
);
if
(
cntr
==
NULL
)
{
ERROR
(
"Rootfs %s not known
"
,
id
);
ret
=
-
1
;
WARN
(
"rootfs %s not exists already, return success
"
,
id
);
ret
=
0
;
goto
out
;
}
...
...
test/image/oci/storage/images/storage_images_ut.cpp
浏览文件 @
6fc0f024
...
...
@@ -641,24 +641,6 @@ TEST_F(StorageImagesUnitTest, test_image_store_delete)
Restore
();
}
TEST_F
(
StorageImagesUnitTest
,
test_image_store_wipe
)
{
BackUp
();
for
(
auto
elem
:
ids
)
{
ASSERT_TRUE
(
image_store_exists
(
elem
.
c_str
()));
ASSERT_TRUE
(
dirExists
((
std
::
string
(
store_real_path
)
+
"/overlay-images/"
+
elem
).
c_str
()));
}
ASSERT_EQ
(
image_store_wipe
(),
0
);
for
(
auto
elem
:
ids
)
{
ASSERT_FALSE
(
image_store_exists
(
elem
.
c_str
()));
ASSERT_FALSE
(
dirExists
((
std
::
string
(
store_real_path
)
+
"/overlay-images/"
+
elem
).
c_str
()));
}
Restore
();
}
TEST_F
(
StorageImagesUnitTest
,
test_image_store_remove_single_name
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录