Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
50d64742
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,发现更多精彩内容 >>
提交
50d64742
编写于
4月 02, 2020
作者:
W
wujing
提交者:
lifeng68
7月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Carding the image module interface
Signed-off-by:
N
wujing
<
wujing50@huawei.com
>
上级
ff03f0bc
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
488 addition
and
353 deletion
+488
-353
src/image/oci/storage/image_store/image_store.c
src/image/oci/storage/image_store/image_store.c
+338
-198
src/image/oci/storage/image_store/image_store.h
src/image/oci/storage/image_store/image_store.h
+63
-83
test/image/oci/storage/images/storage_images_llt.cc
test/image/oci/storage/images/storage_images_llt.cc
+82
-72
tools/static_check
tools/static_check
+5
-0
未找到文件。
src/image/oci/storage/image_store/image_store.c
浏览文件 @
50d64742
此差异已折叠。
点击以展开。
src/image/oci/storage/image_store/image_store.h
浏览文件 @
50d64742
...
...
@@ -19,7 +19,7 @@
#include <string.h>
#include <pthread.h>
#include "storage_image.h"
#include "t
imestamp
.h"
#include "t
ypes_def
.h"
#include "map.h"
#ifdef __cplusplus
...
...
@@ -31,89 +31,69 @@ extern "C" {
#define IMAGE_DIGEST_BIG_DATA_KEY "manifest"
#define IMAGE_NAME_LEN 64
// Load the image in the dir folder
int
new_image_store
(
const
char
*
dir
);
// Create an image that has a specified ID (or a random one) and optional names, using the specified layer as
// its topmost (hopefully read-only) layer. That layer can be referenced by multiple images.
storage_image
*
image_store_create
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
,
const
char
*
layer
,
const
char
*
metadata
,
const
types_timestamp_t
*
time
,
const
char
*
searchable_digest
);
// Attempt to translate a name to an ID. Most methods do this implicitly.
storage_image
*
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
);
// Add the name for an image. Duplicate names are removed from the list automatically.
int
image_store_add_name
(
const
char
*
id
,
const
char
*
name
);
// Replace the list of names associated with an image with the supplied values.
int
image_store_set_names
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
);
// Updates the metadata associated with the item with the specified ID.
int
image_store_set_metadata
(
const
char
*
id
,
const
char
*
metadata
);
// Set the image pulled time
int
image_store_set_load_time
(
const
char
*
id
,
const
types_timestamp_t
*
time
);
// Saves the contents of the store to disk.
int
image_store_save
(
storage_image
*
image
);
// Check if there is an image with the given ID or name.
bool
image_store_exists
(
const
char
*
id
);
// Retrieve information about an image given an ID or name.
const
storage_image
*
image_store_get_image
(
const
char
*
id
);
// Retrieves a (potentially large) piece of data associated with this ID, if it has previously been set.
char
*
image_store_big_data
(
const
char
*
id
,
const
char
*
key
);
// Retrieves the size of a (potentially large) piece of data associated with this ID, if it has previously been set.
int64_t
image_store_big_data_size
(
const
char
*
id
,
const
char
*
key
);
// Retrieves the digest of a (potentially large) piece of data associated with this ID, if it has previously been set.
const
char
*
image_store_big_data_digest
(
const
char
*
id
,
const
char
*
key
);
// Returns a list of the names of previously-stored pieces of data.
int
image_store_big_data_names
(
const
char
*
id
,
char
***
names
,
size_t
*
names_len
);
// Reads metadata associated with an item with the specified ID.
const
char
*
image_store_metadata
(
const
char
*
id
);
// Return a slice enumerating the known images.
int
image_store_get_all_images
(
storage_image
***
images
,
size_t
*
len
);
// Return a slice enumerating the images which have a big data
// item with the name ImageDigestBigDataKey and the specified digest.
int
image_store_get_images_by_digest
(
const
char
*
digest
,
storage_image
***
images
,
size_t
*
len
);
typedef
struct
file_locker
{
// key: string value: struct flock
map_t
*
lock_files
;
pthread_mutex_t
lock_files_lock
;
}
file_locker_t
;
typedef
struct
digest_image
{
storage_image
**
images
;
size_t
images_len
;
}
digest_image_t
;
typedef
struct
image_store
{
file_locker_t
lockfile
;
file_locker_t
rolockfile
;
char
*
dir
;
storage_image
**
images
;
size_t
images_len
;
map_t
*
idindex
;
map_t
*
byid
;
map_t
*
byname
;
map_t
*
bydigest
;
// flag for daemon
bool
daemon
;
bool
loaded
;
}
image_store_t
,
*
image_store_ptr
;
// // ROImageStore interface: Provides bookkeeping for information about Images.
// typedef struct ro_image_store_ops {
// // TODO: ROFileBasedStore
// // TODO: ROMetadataStore
// // TODO: ROBigDataStore
//
// // Check if there is an image with the given ID or name.
// bool (*exists)(const char *id);
//
// // Retrieve information about an image given an ID or name.
// int (*get)(const char *id, storage_image *image);
//
// // Attempt to translate a name to an ID. Most methods do this implicitly.
// int (*lookup)(const char *name, char **id);
//
// // Return a slice enumerating the known images.
// int (*images)(storage_image **images, size_t *len);
//
// // Return a slice enumerating the images which have a big data
// // item with the name ImageDigestBigDataKey and the specified digest.
// int (*by_digest)(storage_image **images, size_t *len);
// } ro_image_store_ops_t;
//
// // ImageStore interface: Provides bookkeeping for information about Images.
// typedef struct image_store_opt {
// // ROImageStore
// // RWFileBasedStore
// // RWMetadataStore
// // RWBigDataStore
// // FlaggableStore
//
// // Create an image that has a specified ID (or a random one) and
// // optional names, using the specified layer as its topmost (hopefully
// // read-only) layer. That layer can be referenced by multiple images.
// int (*create)(const char *id, const char **names, size_t names_len, const char *layer, const char *metadata,
// timestamp time, const char *searchable_digest, storage_image *image);
//
// // Replace the list of names associated with an image with the supplied values.
// int (*set_names)(const char *id, const char **names, size_t names_len);
//
// // Remove the record of the image.
// int (*delete)(const char *id);
//
// // Remove records of all images
// int (*wipe)();
//
// // Set the image pulled time
// int (*set_loaded_time)(const char *id, timestamp loaded);
//
// // Add the name for an image. Duplicate names are removed from the list automatically.
// int (*add_name)(const char *id, const char *name);
// } image_store_ops_t;
//
int
new_image_store
(
bool
daemon
,
bool
readonly
,
const
char
*
dir
,
image_store_t
**
image_store
);
void
free_image_store
(
image_store_t
*
image_store
);
#ifdef __cplusplus
}
#endif
...
...
test/image/oci/storage/images/storage_images_llt.cc
浏览文件 @
50d64742
...
...
@@ -26,13 +26,13 @@ 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
))
{
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'
;
for
(
int
i
{
ret
};
i
>=
0
;
--
i
)
{
if
(
abs_path
[
i
]
==
'/'
)
{
abs_path
[
i
+
1
]
=
'\0'
;
break
;
}
}
...
...
@@ -93,78 +93,88 @@ std::string GetDirectory()
******************************************************************************************/
class
StorageImagesUnitTest
:
public
testing
::
Test
{
protected:
void
SetUp
()
override
{
std
::
string
dir
=
GetDirectory
()
+
"/data"
;
protected:
void
SetUp
()
override
{
std
::
string
dir
=
GetDirectory
()
+
"/data"
;
ASSERT_STRNE
(
cleanpath
(
dir
.
c_str
(),
real_path
,
sizeof
(
real_path
)),
nullptr
);
ASSERT_EQ
(
new_image_store
(
true
,
false
,
real_path
,
&
image_store
),
0
);
}
void
TearDown
()
override
{
free_image_store
(
image_store
);
}
image_store_t
*
image_store
{
nullptr
};
std
::
vector
<
std
::
string
>
ids
{
"39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
,
"e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
};
char
real_path
[
PATH_MAX
]
=
{
0x00
};
ASSERT_STRNE
(
cleanpath
(
dir
.
c_str
(),
real_path
,
sizeof
(
real_path
)),
nullptr
);
ASSERT_EQ
(
new_image_store
(
real_path
),
0
);
}
void
TearDown
()
override
{
}
std
::
vector
<
std
::
string
>
ids
{
"39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
,
"e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
};
char
real_path
[
PATH_MAX
]
=
{
0x00
};
};
TEST_F
(
StorageImagesUnitTest
,
test_images_load
)
{
auto
image
=
image_store_get_image
(
ids
.
at
(
0
).
c_str
());
ASSERT_NE
(
image
,
nullptr
);
ASSERT_STREQ
(
image
->
digest
,
"sha256:94192fe835d92cba5513297aad1cbcb32c9af455fb575e926ee5ec683a95e586"
);
ASSERT_EQ
(
image
->
names_len
,
1
);
ASSERT_STREQ
(
image
->
names
[
0
],
"rnd-dockerhub.huawei.com/official/centos:latest"
);
ASSERT_STREQ
(
image
->
layer
,
"edd34c086208711c693a7b7a3ade23e24e6170ae24d8d2dab7c4f3efca61d509"
);
ASSERT_STREQ
(
image
->
metadata
,
"{}"
);
ASSERT_EQ
(
image
->
big_data_names_len
,
2
);
ASSERT_STREQ
(
image
->
big_data_names
[
0
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_STREQ
(
image
->
big_data_names
[
1
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
0
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
0
],
741
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
1
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
1
],
2235
);
ASSERT_EQ
(
image
->
big_data_digests
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
0
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
0
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
1
],
"manifest"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
1
],
"sha256:94192fe835d92cba5513297aad1cbcb32c9af455fb575e926ee5ec683a95e586"
);
ASSERT_STREQ
(
image
->
created
,
"2017-07-10T12:46:57.770791248Z"
);
ASSERT_STREQ
(
image
->
loaded
,
"2020-03-16T03:46:12.172621513Z"
);
ASSERT_NE
(
image_store
,
nullptr
);
ASSERT_STREQ
(
image_store
->
dir
,
real_path
);
ASSERT_EQ
(
image_store
->
images_len
,
2
);
for
(
size_t
i
{};
i
<
image_store
->
images_len
;
i
++
)
{
auto
image
=
image_store
->
images
[
i
];
ASSERT_NE
(
find
(
ids
.
begin
(),
ids
.
end
(),
std
::
string
(
image
->
id
)),
ids
.
end
());
if
(
std
::
string
(
image
->
id
)
==
ids
.
at
(
0
))
{
ASSERT_STREQ
(
image
->
digest
,
"sha256:94192fe835d92cba5513297aad1cbcb32c9af455fb575e926ee5ec683a95e586"
);
ASSERT_EQ
(
image
->
names_len
,
1
);
ASSERT_STREQ
(
image
->
names
[
0
],
"rnd-dockerhub.huawei.com/official/centos:latest"
);
ASSERT_STREQ
(
image
->
layer
,
"edd34c086208711c693a7b7a3ade23e24e6170ae24d8d2dab7c4f3efca61d509"
);
ASSERT_STREQ
(
image
->
metadata
,
"{}"
);
ASSERT_EQ
(
image
->
big_data_names_len
,
2
);
ASSERT_STREQ
(
image
->
big_data_names
[
0
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_STREQ
(
image
->
big_data_names
[
1
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
0
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
0
],
741
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
1
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
1
],
2235
);
ASSERT_EQ
(
image
->
big_data_digests
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
0
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
0
],
"sha256:39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
1
],
"manifest"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
1
],
"sha256:94192fe835d92cba5513297aad1cbcb32c9af455fb575e926ee5ec683a95e586"
);
ASSERT_STREQ
(
image
->
created
,
"2017-07-10T12:46:57.770791248Z"
);
ASSERT_STREQ
(
image
->
loaded
,
"2020-03-16T03:46:12.172621513Z"
);
}
else
{
ASSERT_STREQ
(
image
->
digest
,
"sha256:64da743694ece2ca88df34bf4c5378fdfc44a1a5b50478722e2ff98b82e4a5c9"
);
ASSERT_EQ
(
image
->
names_len
,
1
);
ASSERT_STREQ
(
image
->
names
[
0
],
"rnd-dockerhub.huawei.com/official/busybox:latest"
);
ASSERT_STREQ
(
image
->
layer
,
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
);
ASSERT_STREQ
(
image
->
metadata
,
"{}"
);
ASSERT_EQ
(
image
->
big_data_names_len
,
2
);
ASSERT_STREQ
(
image
->
big_data_names
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_STREQ
(
image
->
big_data_names
[
1
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
0
],
1497
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
1
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
1
],
527
);
ASSERT_EQ
(
image
->
big_data_digests
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
1
],
"manifest"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
1
],
"sha256:64da743694ece2ca88df34bf4c5378fdfc44a1a5b50478722e2ff98b82e4a5c9"
);
ASSERT_STREQ
(
image
->
created
,
"2019-06-15T00:19:54.402459069Z"
);
ASSERT_STREQ
(
image
->
loaded
,
"2020-03-16T03:46:17.439778957Z"
);
}
}
image
=
image_store_get_image
(
ids
.
at
(
1
).
c_str
());
ASSERT_NE
(
image
,
nullptr
);
ASSERT_STREQ
(
image
->
digest
,
"sha256:64da743694ece2ca88df34bf4c5378fdfc44a1a5b50478722e2ff98b82e4a5c9"
);
ASSERT_EQ
(
image
->
names_len
,
1
);
ASSERT_STREQ
(
image
->
names
[
0
],
"rnd-dockerhub.huawei.com/official/busybox:latest"
);
ASSERT_STREQ
(
image
->
layer
,
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"
);
ASSERT_STREQ
(
image
->
metadata
,
"{}"
);
ASSERT_EQ
(
image
->
big_data_names_len
,
2
);
ASSERT_STREQ
(
image
->
big_data_names
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_STREQ
(
image
->
big_data_names
[
1
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
0
],
1497
);
ASSERT_STREQ
(
image
->
big_data_sizes
->
keys
[
1
],
"manifest"
);
ASSERT_EQ
(
image
->
big_data_sizes
->
values
[
1
],
527
);
ASSERT_EQ
(
image
->
big_data_digests
->
len
,
2
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
0
],
"sha256:e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
keys
[
1
],
"manifest"
);
ASSERT_STREQ
(
image
->
big_data_digests
->
values
[
1
],
"sha256:64da743694ece2ca88df34bf4c5378fdfc44a1a5b50478722e2ff98b82e4a5c9"
);
ASSERT_STREQ
(
image
->
created
,
"2019-06-15T00:19:54.402459069Z"
);
ASSERT_STREQ
(
image
->
loaded
,
"2020-03-16T03:46:17.439778957Z"
);
}
/*TEST_F(StorageImagesUnitTest, test_images_create)
{
std::string id {"50551ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10"};
const char *names[2] = {"hello_world:latest", "euleros:3.1"};
std::string layer {"9994458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a"};
std::string metadata {"{}"};
types_timestamp_t time {0x00};
std::string searchableDigest {"manifest"};
auto image = create(image_store, id.c_str(), names, sizeof(names)/sizeof(names[0]),
layer.c_str(), metadata.c_str(), &time, searchableDigest.c_str());
ASSERT_NE(image, nullptr);
}*/
tools/static_check
浏览文件 @
50d64742
...
...
@@ -254,6 +254,11 @@ function astyle_fix() {
}
function
astyle_format
()
{
which astyle
if
[[
$?
-ne
0
]]
;
then
echo
"please install astyle tool first"
exit
1
fi
echo
-e
"
\
=================================================================================================
\0
33[1;36m
___ _____ ________ __ __ ______ ______ ____ ____ __ ___ ___ ______
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录