Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
6bbc7324
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,发现更多精彩内容 >>
提交
6bbc7324
编写于
4月 29, 2020
作者:
H
haozi007
提交者:
lifeng68
7月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add llt for layer store
1. add llt 2. add debug info Signed-off-by:
N
haozi007
<
liuhao27@huawei.com
>
上级
a2dcc99a
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
392 addition
and
28 deletion
+392
-28
src/image/oci/storage/layer_store/graphdriver/driver.c
src/image/oci/storage/layer_store/graphdriver/driver.c
+0
-2
src/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
...torage/layer_store/graphdriver/overlay2/driver_overlay2.c
+1
-1
src/image/oci/storage/layer_store/layer.c
src/image/oci/storage/layer_store/layer.c
+4
-0
src/image/oci/storage/layer_store/layer_store.c
src/image/oci/storage/layer_store/layer_store.c
+39
-21
src/image/oci/storage/layer_store/layer_store.h
src/image/oci/storage/layer_store/layer_store.h
+3
-3
src/services/cri/cni_network_plugin.cc
src/services/cri/cni_network_plugin.cc
+1
-1
test/image/oci/storage/CMakeLists.txt
test/image/oci/storage/CMakeLists.txt
+1
-0
test/image/oci/storage/images/CMakeLists.txt
test/image/oci/storage/images/CMakeLists.txt
+1
-0
test/image/oci/storage/layers/CMakeLists.txt
test/image/oci/storage/layers/CMakeLists.txt
+81
-0
test/image/oci/storage/layers/data/overlay-layers/6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a/layer.json
...83d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a/layer.json
+1
-0
test/image/oci/storage/layers/data/run/overlay-layers/ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1.json
...84e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1.json
+1
-0
test/image/oci/storage/layers/storage_layers_llt.cc
test/image/oci/storage/layers/storage_layers_llt.cc
+259
-0
未找到文件。
src/image/oci/storage/layer_store/graphdriver/driver.c
浏览文件 @
6bbc7324
...
@@ -26,8 +26,6 @@
...
@@ -26,8 +26,6 @@
#include "utils.h"
#include "utils.h"
#include "libisulad.h"
#include "libisulad.h"
#include "isula_libutils/log.h"
#include "isula_libutils/log.h"
#include "isulad_config.h"
#include "image.h"
#include "util_archive.h"
#include "util_archive.h"
static
struct
graphdriver
*
g_graphdriver
=
NULL
;
static
struct
graphdriver
*
g_graphdriver
=
NULL
;
...
...
src/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
浏览文件 @
6bbc7324
...
@@ -259,7 +259,7 @@ int overlay2_init(struct graphdriver *driver, const char *drvier_home, const cha
...
@@ -259,7 +259,7 @@ int overlay2_init(struct graphdriver *driver, const char *drvier_home, const cha
int
ret
=
0
;
int
ret
=
0
;
char
*
link_dir
=
NULL
;
char
*
link_dir
=
NULL
;
if
(
driver
==
NULL
||
drvier_home
==
NULL
||
options
==
NULL
)
{
if
(
driver
==
NULL
||
drvier_home
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
...
...
src/image/oci/storage/layer_store/layer.c
浏览文件 @
6bbc7324
...
@@ -138,6 +138,7 @@ int save_layer(layer_t *layer)
...
@@ -138,6 +138,7 @@ int save_layer(layer_t *layer)
int
ret
=
-
1
;
int
ret
=
-
1
;
if
(
layer
==
NULL
||
layer
->
layer_json_path
==
NULL
||
layer
->
slayer
==
NULL
)
{
if
(
layer
==
NULL
||
layer
->
layer_json_path
==
NULL
||
layer
->
slayer
==
NULL
)
{
ERROR
(
"Invalid arguments"
);
return
ret
;
return
ret
;
}
}
...
@@ -148,6 +149,9 @@ int save_layer(layer_t *layer)
...
@@ -148,6 +149,9 @@ int save_layer(layer_t *layer)
}
}
ret
=
util_atomic_write_file
(
layer
->
layer_json_path
,
jstr
,
strlen
(
jstr
),
SECURE_CONFIG_FILE_MODE
);
ret
=
util_atomic_write_file
(
layer
->
layer_json_path
,
jstr
,
strlen
(
jstr
),
SECURE_CONFIG_FILE_MODE
);
if
(
ret
!=
0
)
{
ERROR
(
"Atomic write layer: %s failed"
,
layer
->
slayer
->
id
);
}
out:
out:
free
(
jstr
);
free
(
jstr
);
free
(
jerr
);
free
(
jerr
);
...
...
src/image/oci/storage/layer_store/layer_store.c
浏览文件 @
6bbc7324
...
@@ -114,7 +114,7 @@ static void remove_layer_list_tail()
...
@@ -114,7 +114,7 @@ static void remove_layer_list_tail()
return
;
return
;
}
}
item
=
g_metadata
.
layers_list
.
next
;
item
=
g_metadata
.
layers_list
.
prev
;
linked_list_del
(
item
);
linked_list_del
(
item
);
layer_ref_dec
((
layer_t
*
)
item
->
elem
);
layer_ref_dec
((
layer_t
*
)
item
->
elem
);
...
@@ -255,23 +255,27 @@ static int load_layers_from_json_files()
...
@@ -255,23 +255,27 @@ static int load_layers_from_json_files()
ret
=
update_digest_map
(
g_metadata
.
by_compress_digest
,
NULL
,
tl
->
slayer
->
compressed_diff_digest
,
tl
->
slayer
->
id
);
ret
=
update_digest_map
(
g_metadata
.
by_compress_digest
,
NULL
,
tl
->
slayer
->
compressed_diff_digest
,
tl
->
slayer
->
id
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
ERROR
(
"update layer: %s compress failed"
,
tl
->
slayer
->
id
);
goto
err_out
;
goto
err_out
;
}
}
ret
=
update_digest_map
(
g_metadata
.
by_uncompress_digest
,
NULL
,
tl
->
slayer
->
diff_digest
,
tl
->
slayer
->
id
);
ret
=
update_digest_map
(
g_metadata
.
by_uncompress_digest
,
NULL
,
tl
->
slayer
->
diff_digest
,
tl
->
slayer
->
id
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
ERROR
(
"update layer: %s uncompress failed"
,
tl
->
slayer
->
id
);
goto
err_out
;
goto
err_out
;
}
}
// check complete
// check complete
if
(
tl
->
incompelte
)
{
if
(
tl
->
incompelte
)
{
if
(
layer_store_delete
(
tl
->
slayer
->
id
)
!=
0
)
{
if
(
layer_store_delete
(
tl
->
slayer
->
id
)
!=
0
)
{
ERROR
(
"delete layer: %s failed"
,
tl
->
slayer
->
id
);
goto
err_out
;
goto
err_out
;
}
}
should_save
=
true
;
should_save
=
true
;
}
}
if
(
should_save
&&
save_layer
(
tl
)
!=
0
)
{
if
(
should_save
&&
save_layer
(
tl
)
!=
0
)
{
ERROR
(
"save layer: %s failed"
,
tl
->
slayer
->
id
);
goto
err_out
;
goto
err_out
;
}
}
}
}
...
@@ -288,23 +292,13 @@ int layer_store_init(const struct storage_module_init_options *conf)
...
@@ -288,23 +292,13 @@ int layer_store_init(const struct storage_module_init_options *conf)
int
nret
=
0
;
int
nret
=
0
;
if
(
!
init_from_conf
(
conf
))
{
if
(
!
init_from_conf
(
conf
))
{
goto
free_out
;
return
-
1
;
}
// build root dir and run dir
nret
=
util_mkdir_p
(
g_root_dir
,
IMAGE_STORE_PATH_MODE
);
if
(
nret
!=
0
)
{
ERROR
(
"build root dir of layer store failed"
);
goto
free_out
;
}
nret
=
util_mkdir_p
(
g_run_dir
,
IMAGE_STORE_PATH_MODE
);
if
(
nret
!=
0
)
{
ERROR
(
"build run dir of layer store failed"
);
goto
free_out
;
}
}
// init manager structs
// init manager structs
g_metadata
.
layers_list_len
=
0
;
g_metadata
.
layers_list_len
=
0
;
linked_list_init
(
&
g_metadata
.
layers_list
);
linked_list_init
(
&
g_metadata
.
layers_list
);
nret
=
pthread_rwlock_init
(
&
(
g_metadata
.
rwlock
),
NULL
);
nret
=
pthread_rwlock_init
(
&
(
g_metadata
.
rwlock
),
NULL
);
if
(
nret
!=
0
)
{
if
(
nret
!=
0
)
{
ERROR
(
"Failed to init metadata rwlock"
);
ERROR
(
"Failed to init metadata rwlock"
);
...
@@ -331,11 +325,24 @@ int layer_store_init(const struct storage_module_init_options *conf)
...
@@ -331,11 +325,24 @@ int layer_store_init(const struct storage_module_init_options *conf)
goto
free_out
;
goto
free_out
;
}
}
// build root dir and run dir
nret
=
util_mkdir_p
(
g_root_dir
,
IMAGE_STORE_PATH_MODE
);
if
(
nret
!=
0
)
{
ERROR
(
"build root dir of layer store failed"
);
goto
free_out
;
}
nret
=
util_mkdir_p
(
g_run_dir
,
IMAGE_STORE_PATH_MODE
);
if
(
nret
!=
0
)
{
ERROR
(
"build run dir of layer store failed"
);
goto
free_out
;
}
// TODO: load layer json files
// TODO: load layer json files
if
(
load_layers_from_json_files
()
!=
0
)
{
if
(
load_layers_from_json_files
()
!=
0
)
{
goto
free_out
;
goto
free_out
;
}
}
DEBUG
(
"Init layer store success"
);
return
0
;
return
0
;
free_out:
free_out:
layer_store_cleanup
();
layer_store_cleanup
();
...
@@ -721,6 +728,9 @@ static int apply_diff(const char *id, const struct io_read_wrapper *diff)
...
@@ -721,6 +728,9 @@ static int apply_diff(const char *id, const struct io_read_wrapper *diff)
int64_t
size
=
0
;
int64_t
size
=
0
;
int
ret
=
0
;
int
ret
=
0
;
if
(
diff
==
NULL
)
{
return
0
;
}
ret
=
graphdriver_apply_diff
(
id
,
diff
,
&
size
);
ret
=
graphdriver_apply_diff
(
id
,
diff
,
&
size
);
...
@@ -952,7 +962,7 @@ static void copy_json_to_layer(const layer_t *jl, struct layer *l)
...
@@ -952,7 +962,7 @@ static void copy_json_to_layer(const layer_t *jl, struct layer *l)
}
}
}
}
struct
layer
**
layer_store_list
()
struct
layer
**
layer_store_list
(
size_t
*
layers_len
)
{
{
// TODO: add lock
// TODO: add lock
struct
linked_list
*
item
=
NULL
;
struct
linked_list
*
item
=
NULL
;
...
@@ -960,7 +970,7 @@ struct layer** layer_store_list()
...
@@ -960,7 +970,7 @@ struct layer** layer_store_list()
struct
layer
**
result
=
NULL
;
struct
layer
**
result
=
NULL
;
size_t
i
=
0
;
size_t
i
=
0
;
result
=
(
struct
layer
**
)
util_smart_calloc_s
(
sizeof
(
struct
layer
*
),
g_metadata
.
layers_list_len
);
result
=
(
struct
layer
**
)
util_smart_calloc_s
(
sizeof
(
struct
layer
*
),
g_metadata
.
layers_list_len
+
1
);
if
(
result
==
NULL
)
{
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
NULL
;
return
NULL
;
...
@@ -977,6 +987,7 @@ struct layer** layer_store_list()
...
@@ -977,6 +987,7 @@ struct layer** layer_store_list()
i
++
;
i
++
;
}
}
*
layers_len
=
g_metadata
.
layers_list_len
;
return
result
;
return
result
;
err_out:
err_out:
while
(
i
>=
0
)
{
while
(
i
>=
0
)
{
...
@@ -1000,7 +1011,7 @@ bool layer_store_is_used(const char *id)
...
@@ -1000,7 +1011,7 @@ bool layer_store_is_used(const char *id)
return
true
;
return
true
;
}
}
static
struct
layer
**
layers_by_digest_map
(
map_t
*
m
,
const
char
*
digest
)
static
struct
layer
**
layers_by_digest_map
(
map_t
*
m
,
const
char
*
digest
,
size_t
*
layers_len
)
{
{
char
**
ids
=
NULL
;
char
**
ids
=
NULL
;
struct
layer
**
result
=
NULL
;
struct
layer
**
result
=
NULL
;
...
@@ -1015,7 +1026,7 @@ static struct layer **layers_by_digest_map(map_t *m, const char *digest)
...
@@ -1015,7 +1026,7 @@ static struct layer **layers_by_digest_map(map_t *m, const char *digest)
if
(
len
>
0
)
{
if
(
len
>
0
)
{
layer_t
*
l
=
NULL
;
layer_t
*
l
=
NULL
;
result
=
util_smart_calloc_s
(
sizeof
(
struct
layer
*
),
len
);
result
=
util_smart_calloc_s
(
sizeof
(
struct
layer
*
),
len
+
1
);
for
(;
i
<
len
;
i
++
)
{
for
(;
i
<
len
;
i
++
)
{
struct
layer
*
t_layer
=
util_common_calloc_s
(
sizeof
(
struct
layer
));
struct
layer
*
t_layer
=
util_common_calloc_s
(
sizeof
(
struct
layer
));
if
(
t_layer
==
NULL
)
{
if
(
t_layer
==
NULL
)
{
...
@@ -1034,6 +1045,7 @@ static struct layer **layers_by_digest_map(map_t *m, const char *digest)
...
@@ -1034,6 +1045,7 @@ static struct layer **layers_by_digest_map(map_t *m, const char *digest)
}
}
}
}
*
layers_len
=
len
;
return
result
;
return
result
;
free_out:
free_out:
while
(
result
!=
NULL
&&
i
>=
0
)
{
while
(
result
!=
NULL
&&
i
>=
0
)
{
...
@@ -1043,16 +1055,22 @@ free_out:
...
@@ -1043,16 +1055,22 @@ free_out:
return
NULL
;
return
NULL
;
}
}
struct
layer
**
layer_store_by_compress_digest
(
const
char
*
digest
)
struct
layer
**
layer_store_by_compress_digest
(
const
char
*
digest
,
size_t
*
layers_len
)
{
{
if
(
layers_len
==
NULL
)
{
return
NULL
;
}
// TODO: add lock
// TODO: add lock
return
layers_by_digest_map
(
g_metadata
.
by_compress_digest
,
digest
);
return
layers_by_digest_map
(
g_metadata
.
by_compress_digest
,
digest
,
layers_len
);
}
}
struct
layer
**
layer_store_by_uncompress_digest
(
const
char
*
digest
)
struct
layer
**
layer_store_by_uncompress_digest
(
const
char
*
digest
,
size_t
*
layers_len
)
{
{
if
(
layers_len
==
NULL
)
{
return
NULL
;
}
// TODO: add lock
// TODO: add lock
return
layers_by_digest_map
(
g_metadata
.
by_uncompress_digest
,
digest
);
return
layers_by_digest_map
(
g_metadata
.
by_uncompress_digest
,
digest
,
layers_len
);
}
}
char
*
layer_store_lookup
(
const
char
*
name
)
char
*
layer_store_lookup
(
const
char
*
name
)
...
...
src/image/oci/storage/layer_store/layer_store.h
浏览文件 @
6bbc7324
...
@@ -53,10 +53,10 @@ int layer_store_create(const char *id, const struct layer_opts *opts, const stru
...
@@ -53,10 +53,10 @@ int layer_store_create(const char *id, const struct layer_opts *opts, const stru
int
layer_store_remove_layer
(
const
char
*
id
);
int
layer_store_remove_layer
(
const
char
*
id
);
int
layer_store_delete
(
const
char
*
id
);
int
layer_store_delete
(
const
char
*
id
);
bool
layer_store_exists
(
const
char
*
id
);
bool
layer_store_exists
(
const
char
*
id
);
struct
layer
**
layer_store_list
();
struct
layer
**
layer_store_list
(
size_t
*
layers_len
);
bool
layer_store_is_used
(
const
char
*
id
);
bool
layer_store_is_used
(
const
char
*
id
);
struct
layer
**
layer_store_by_compress_digest
(
const
char
*
digest
);
struct
layer
**
layer_store_by_compress_digest
(
const
char
*
digest
,
size_t
*
layers_len
);
struct
layer
**
layer_store_by_uncompress_digest
(
const
char
*
digest
);
struct
layer
**
layer_store_by_uncompress_digest
(
const
char
*
digest
,
size_t
*
layers_len
);
char
*
layer_store_lookup
(
const
char
*
name
);
char
*
layer_store_lookup
(
const
char
*
name
);
char
*
layer_store_mount
(
const
char
*
id
,
const
struct
layer_store_mount_opts
*
opts
);
char
*
layer_store_mount
(
const
char
*
id
,
const
struct
layer_store_mount_opts
*
opts
);
int
layer_store_umount
(
const
char
*
id
,
bool
force
);
int
layer_store_umount
(
const
char
*
id
,
bool
force
);
...
...
src/services/cri/cni_network_plugin.cc
浏览文件 @
6bbc7324
...
@@ -30,7 +30,7 @@ namespace Network {
...
@@ -30,7 +30,7 @@ namespace Network {
static
std
::
unique_ptr
<
CNINetwork
>
GetLoNetwork
(
std
::
vector
<
std
::
string
>
binDirs
,
const
std
::
string
&
vendorDirPrefix
)
static
std
::
unique_ptr
<
CNINetwork
>
GetLoNetwork
(
std
::
vector
<
std
::
string
>
binDirs
,
const
std
::
string
&
vendorDirPrefix
)
{
{
const
std
::
string
loNetConfListJson
{
"{
\"
cniVersion
\"
:
\"
0.3.0
\"
,
\"
name
\"
:
\"
cni-loopback
\"
,"
const
std
::
string
loNetConfListJson
{
"{
\"
cniVersion
\"
:
\"
0.3.0
\"
,
\"
name
\"
:
\"
cni-loopback
\"
,"
"
\"
plugins
\"
:[{
\"
type
\"
:
\"
loopback
\"
}]}"
};
"
\"
plugins
\"
:[{
\"
type
\"
:
\"
loopback
\"
}]}"
};
char
*
cerr
{
nullptr
};
char
*
cerr
{
nullptr
};
struct
cni_network_list_conf
*
loConf
{
struct
cni_network_list_conf
*
loConf
{
...
...
test/image/oci/storage/CMakeLists.txt
浏览文件 @
6bbc7324
project
(
iSulad_LLT
)
project
(
iSulad_LLT
)
add_subdirectory
(
images
)
add_subdirectory
(
images
)
add_subdirectory
(
layers
)
test/image/oci/storage/images/CMakeLists.txt
浏览文件 @
6bbc7324
...
@@ -22,6 +22,7 @@ add_executable(${EXE}
...
@@ -22,6 +22,7 @@ add_executable(${EXE}
${
CMAKE_BINARY_DIR
}
/json/defs.c
${
CMAKE_BINARY_DIR
}
/json/defs.c
${
CMAKE_BINARY_DIR
}
/json/storage_image.c
${
CMAKE_BINARY_DIR
}
/json/storage_image.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/image_store/image.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/image_store/image.c
${
CMAKE_BINARY_DIR
}
/json/imagetool_fs_info.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/image_store/image_store.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/image_store/image_store.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../mocks/storage_mock.cc
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../mocks/storage_mock.cc
storage_images_llt.cc
)
storage_images_llt.cc
)
...
...
test/image/oci/storage/layers/CMakeLists.txt
0 → 100644
浏览文件 @
6bbc7324
project
(
iSulad_LLT
)
SET
(
EXE storage_layers_llt
)
add_executable
(
${
EXE
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_regex.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_verify.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_array.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_string.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_convert.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_file.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/utils_fs.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils/util_atomic.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/log.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/tar/libtar.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/tar/util_archive.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/sha256/sha256.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/path.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/mainloop.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/map/map.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/map/rb_tree.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/json/schema/src/read_file.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/types_def.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/console/console.c
${
CMAKE_BINARY_DIR
}
/json/json_common.c
${
CMAKE_BINARY_DIR
}
/json/defs.c
${
CMAKE_BINARY_DIR
}
/json/image_devmapper_device_info.c
${
CMAKE_BINARY_DIR
}
/json/image_devmapper_deviceset_metadata.c
${
CMAKE_BINARY_DIR
}
/json/image_devmapper_direct_lvm_config.c
${
CMAKE_BINARY_DIR
}
/json/image_devmapper_transaction.c
${
CMAKE_BINARY_DIR
}
/json/oci_image_spec.c
${
CMAKE_BINARY_DIR
}
/json/imagetool_image.c
${
CMAKE_BINARY_DIR
}
/json/storage_image.c
${
CMAKE_BINARY_DIR
}
/json/imagetool_fs_info.c
${
CMAKE_BINARY_DIR
}
/json/imagetool_images_list.c
${
CMAKE_BINARY_DIR
}
/json/storage_layer.c
${
CMAKE_BINARY_DIR
}
/json/storage_mount_point.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/storage.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/image_store/image_store.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/layer_store.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/layer.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/driver.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/quota/project_quota.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/devmapper/metadata_store.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/devmapper/device_setup.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../mocks/storage_mock.cc
storage_layers_llt.cc
)
target_include_directories
(
${
EXE
}
PUBLIC
${
GTEST_INCLUDE_DIR
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../include
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/tar
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/cutils
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/map
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/sha256
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/console
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/json/schema/src
${
CMAKE_BINARY_DIR
}
/conf
${
CMAKE_BINARY_DIR
}
/json
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../test/mocks
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/image_store
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/devmapper
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/quota
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../../src/image/oci/storage/layer_store/graphdriver/overlay2
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lwebsockets -lcrypto -lyajl -larchive -ldevmapper -lz
)
test/image/oci/storage/layers/data/overlay-layers/6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a/layer.json
0 → 100755
浏览文件 @
6bbc7324
{
"id"
:
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
,
"created"
:
"2020-04-16T12:08:52.304153815Z"
,
"compressed-diff-digest"
:
"sha256:8f52abd3da461b2c0c11fda7a1b53413f1a92320eb96525ddf92c0b5cde781ad"
,
"compressed-size"
:
740169
,
"diff-digest"
:
"sha256:6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
,
"diff-size"
:
1441280
,
"compression"
:
2
}
\ No newline at end of file
test/image/oci/storage/layers/data/run/overlay-layers/ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1.json
0 → 100755
浏览文件 @
6bbc7324
{
"id"
:
"ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1"
,
"path"
:
"/var/lib/isulad/storage/overlay/ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1/merged"
,
"count"
:
1
}
\ No newline at end of file
test/image/oci/storage/layers/storage_layers_llt.cc
0 → 100644
浏览文件 @
6bbc7324
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* 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 v1 for more details.
* Author: wujing
* Create: 2020-03-30
* Description: provide oci storage images unit test
******************************************************************************/
#include "layer_store.h"
#include <cstddef>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tuple>
#include <fstream>
#include <climits>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <gtest/gtest.h>
#include "path.h"
#include "storage.h"
#include "layer.h"
std
::
string
GetDirectory
()
{
char
abs_path
[
PATH_MAX
];
int
ret
=
readlink
(
"/proc/self/exe"
,
abs_path
,
sizeof
(
abs_path
));
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
abs_path
))
{
return
""
;
}
for
(
int
i
{
ret
};
i
>=
0
;
--
i
)
{
if
(
abs_path
[
i
]
==
'/'
)
{
abs_path
[
i
+
1
]
=
'\0'
;
break
;
}
}
return
static_cast
<
std
::
string
>
(
abs_path
);
}
bool
dirExists
(
const
char
*
path
)
{
DIR
*
dp
=
NULL
;
if
((
dp
=
opendir
(
path
))
==
NULL
)
{
return
false
;
}
closedir
(
dp
);
return
true
;
}
/********************************test data 1: container layer json**************************************
{
"id": "ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1",
"names": [
"689feccc14f14112b43b1fbf7dc14c3426e4fdd6e2bff462ec70b9f6ee4b3fae-layer"
],
"parent": "6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a",
"created": "2020-04-29T07:34:27.076073345Z"
}
mount info
{
"id": "ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1",
"path": "/var/lib/isulad/storage/overlay/ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1/merged",
"count": 1
}
******************************************************************************************/
/********************************test data 2: busybox image layer json**************************************
{
"id": "6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a",
"created": "2020-04-16T12:08:52.304153815Z",
"compressed-diff-digest": "sha256:8f52abd3da461b2c0c11fda7a1b53413f1a92320eb96525ddf92c0b5cde781ad",
"compressed-size": 740169,
"diff-digest": "sha256:6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a",
"diff-size": 1441280,
"compression": 2
}
******************************************************************************************/
class
StorageImagesUnitTest
:
public
testing
::
Test
{
protected:
void
SetUp
()
override
{
struct
storage_module_init_options
opts
=
{
0
};
std
::
string
dir
=
GetDirectory
()
+
"/data"
;
std
::
string
rundir
=
GetDirectory
()
+
"/data/run"
;
ASSERT_STRNE
(
cleanpath
(
dir
.
c_str
(),
real_path
,
sizeof
(
real_path
)),
nullptr
);
opts
.
storage_root
=
strdup
(
real_path
);
ASSERT_STRNE
(
cleanpath
(
rundir
.
c_str
(),
real_run_path
,
sizeof
(
real_run_path
)),
nullptr
);
opts
.
storage_run_root
=
strdup
(
real_run_path
);
opts
.
driver_name
=
strdup
(
"overlay"
);
ASSERT_EQ
(
layer_store_init
(
&
opts
),
0
);
free
(
opts
.
storage_root
);
free
(
opts
.
driver_name
);
}
void
TearDown
()
override
{
}
std
::
vector
<
std
::
string
>
ids
{
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
,
"ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1"
};
char
real_path
[
PATH_MAX
]
=
{
0x00
};
char
real_run_path
[
PATH_MAX
]
=
{
0x00
};
};
TEST_F
(
StorageImagesUnitTest
,
test_layers_load
)
{
size_t
layers_len
=
0
;
struct
layer
**
layers
=
layer_store_list
(
&
layers_len
);
ASSERT_EQ
(
layers_len
,
2
);
// check layer 6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a
ASSERT_NE
(
layers
[
0
],
nullptr
);
ASSERT_STREQ
(
layers
[
0
]
->
id
,
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
);
ASSERT_EQ
(
layers
[
0
]
->
parent
,
nullptr
);
ASSERT_STREQ
(
layers
[
0
]
->
compressed_digest
,
"sha256:8f52abd3da461b2c0c11fda7a1b53413f1a92320eb96525ddf92c0b5cde781ad"
);
ASSERT_EQ
(
layers
[
0
]
->
compress_size
,
740169
);
ASSERT_STREQ
(
layers
[
0
]
->
uncompressed_digest
,
"sha256:6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
);
ASSERT_EQ
(
layers
[
0
]
->
uncompress_size
,
1441280
);
// check layer ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1
ASSERT_NE
(
layers
[
1
],
nullptr
);
ASSERT_STREQ
(
layers
[
1
]
->
id
,
"ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1"
);
ASSERT_STREQ
(
layers
[
1
]
->
parent
,
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
);
ASSERT_EQ
(
layers
[
1
]
->
mount_count
,
1
);
ASSERT_STREQ
(
layers
[
1
]
->
mount_point
,
"/var/lib/isulad/storage/overlay/ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1/merged"
);
}
/********************************test data *************************************************
{
"id": "50551ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10",
"digest": "manifest",
"names": [
"euleros:3.1",
"hello_world:latest"
],
"layer": "9994458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a",
"metadata": "{}",
"created": "2020-04-02T05:44:23.408951489-04:00",
"loaded": "2020-04-02T05:44:23.408987703-04:00"
}
******************************************************************************************/
TEST_F
(
StorageImagesUnitTest
,
test_layer_store_create
)
{
std
::
string
id
{
"d3b9337701b412d8235da15ae7653560ccc6cf042c18298214aa5543c38588f8"
};
std
::
string
parent
{
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
};
struct
layer_opts
opts
=
{
.
parent
=
strdup
(
parent
.
c_str
()),
.
writable
=
true
,
};
char
*
new_id
=
nullptr
;
auto
created_layer
=
layer_store_create
(
id
.
c_str
(),
&
opts
,
nullptr
,
&
new_id
);
ASSERT_EQ
(
created_layer
,
0
);
ASSERT_TRUE
(
layer_store_exists
(
id
.
c_str
()));
ASSERT_EQ
(
layer_store_delete
(
id
.
c_str
()),
0
);
ASSERT_FALSE
(
layer_store_exists
(
id
.
c_str
()));
ASSERT_FALSE
(
dirExists
((
std
::
string
(
real_path
)
+
"/"
+
id
).
c_str
()));
}
TEST_F
(
StorageImagesUnitTest
,
test_layer_store_lookup
)
{
std
::
string
id
{
"ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1"
};
std
::
string
name
{
"689feccc14f14112b43b1fbf7dc14c3426e4fdd6e2bff462ec70b9f6ee4b3fae-layer"
};
std
::
string
incorrectId
{
"4db68de4ff27"
};
ASSERT_STREQ
(
layer_store_lookup
(
name
.
c_str
()),
id
.
c_str
());
ASSERT_STREQ
(
layer_store_lookup
(
id
.
c_str
()),
id
.
c_str
());
ASSERT_EQ
(
layer_store_lookup
(
incorrectId
.
c_str
()),
nullptr
);
}
TEST_F
(
StorageImagesUnitTest
,
test_layer_store_exists
)
{
std
::
string
id
{
"ac86325a0e6384e251f2f4418d7b36321ad6811f9ba8a3dc87e13d634b0ec1d1"
};
std
::
string
name
{
"689feccc14f14112b43b1fbf7dc14c3426e4fdd6e2bff462ec70b9f6ee4b3fae-layer"
};
std
::
string
incorrectId
{
"4db68de4ff27"
};
ASSERT_TRUE
(
layer_store_exists
(
name
.
c_str
()));
ASSERT_TRUE
(
layer_store_exists
(
id
.
c_str
()));
ASSERT_FALSE
(
layer_store_exists
(
incorrectId
.
c_str
()));
}
TEST_F
(
StorageImagesUnitTest
,
test_layer_store_list
)
{
struct
layer
**
layers
=
NULL
;
size_t
len
=
0
;
layers
=
layer_store_list
(
&
len
);
ASSERT_EQ
(
len
,
2
);
for
(
size_t
i
{};
i
<
len
;
i
++
)
{
ASSERT_NE
(
find
(
ids
.
begin
(),
ids
.
end
(),
std
::
string
(
layers
[
i
]
->
id
)),
ids
.
end
());
}
for
(
size_t
i
{};
i
<
len
;
i
++
)
{
free_layer
(
layers
[
i
]);
layers
[
i
]
=
NULL
;
}
free
(
layers
);
}
TEST_F
(
StorageImagesUnitTest
,
test_layer_store_by_compress_digest
)
{
struct
layer
**
layers
=
NULL
;
size_t
len
=
0
;
std
::
string
compress
{
"sha256:8f52abd3da461b2c0c11fda7a1b53413f1a92320eb96525ddf92c0b5cde781ad"
};
std
::
string
id
{
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
};
layers
=
layer_store_by_compress_digest
(
compress
.
c_str
(),
&
len
);
ASSERT_EQ
(
len
,
1
);
ASSERT_STREQ
(
layers
[
0
]
->
id
,
id
.
c_str
());
ASSERT_STREQ
(
layers
[
0
]
->
compressed_digest
,
compress
.
c_str
());
ASSERT_EQ
(
layers
[
0
]
->
compress_size
,
740169
);
for
(
size_t
i
{};
i
<
len
;
i
++
)
{
free_layer
(
layers
[
i
]);
layers
[
i
]
=
NULL
;
}
free
(
layers
);
}
TEST_F
(
StorageImagesUnitTest
,
test_layer_store_by_uncompress_digest
)
{
struct
layer
**
layers
=
NULL
;
size_t
len
=
0
;
std
::
string
uncompress
{
"sha256:6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
};
std
::
string
id
{
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
};
layers
=
layer_store_by_uncompress_digest
(
uncompress
.
c_str
(),
&
len
);
ASSERT_EQ
(
len
,
1
);
ASSERT_STREQ
(
layers
[
0
]
->
id
,
id
.
c_str
());
ASSERT_STREQ
(
layers
[
0
]
->
uncompressed_digest
,
uncompress
.
c_str
());
ASSERT_EQ
(
layers
[
0
]
->
uncompress_size
,
1441280
);
for
(
size_t
i
{};
i
<
len
;
i
++
)
{
free_layer
(
layers
[
i
]);
layers
[
i
]
=
NULL
;
}
free
(
layers
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录