Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
23f31b10
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,发现更多精彩内容 >>
提交
23f31b10
编写于
4月 26, 2020
作者:
W
wujing
提交者:
lifeng68
7月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create image store root directory based on the driver name
Signed-off-by:
N
wujing
<
wujing50@huawei.com
>
上级
f5ff0844
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
16 deletion
+45
-16
src/image/oci/storage/image_store/image_store.c
src/image/oci/storage/image_store/image_store.c
+43
-16
test/image/oci/storage/images/data/overlay-images/39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10/images.json
...d71320915f33d2eb80ab42908e398472cab3c1ce7ac10/images.json
+0
-0
test/image/oci/storage/images/data/overlay-images/e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b/images.json
...a0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b/images.json
+0
-0
test/image/oci/storage/images/storage_images_llt.cc
test/image/oci/storage/images/storage_images_llt.cc
+2
-0
未找到文件。
src/image/oci/storage/image_store/image_store.c
浏览文件 @
23f31b10
...
...
@@ -12,6 +12,7 @@
* Create: 2020-03-13
* Description: provide image store functions
******************************************************************************/
#define _GNU_SOURCE
#include "image_store.h"
#include <sys/types.h>
#include <stdio.h>
...
...
@@ -32,6 +33,7 @@
// image, by which we can locate the image later.
#define IMAGE_DIGEST_BIG_DATA_KEY "manifest"
#define IMAGE_NAME_LEN 64
#define IMAGE_JSON "images.json"
typedef
struct
file_locker
{
// key: string value: struct flock
...
...
@@ -113,7 +115,7 @@ static void image_store_digest_field_kvfree(void *key, void *value)
static
int
get_image_path
(
image_store_t
*
image_store
,
const
char
*
id
,
char
*
path
,
size_t
len
)
{
int
nret
=
snprintf
(
path
,
len
,
"%s/%s/
image.json"
,
image_store
->
dir
,
id
);
int
nret
=
snprintf
(
path
,
len
,
"%s/%s/
%s"
,
image_store
->
dir
,
id
,
IMAGE_JSON
);
return
(
nret
<
0
||
(
size_t
)
nret
>=
len
)
?
-
1
:
0
;
}
...
...
@@ -151,7 +153,7 @@ static int append_image_by_image_directory(const char *image_dir, storage_image
storage_image
*
tmp_image
=
NULL
;
parser_error
err
=
NULL
;
nret
=
snprintf
(
image_path
,
sizeof
(
image_path
),
"%s/%s"
,
image_dir
,
"image.json"
);
nret
=
snprintf
(
image_path
,
sizeof
(
image_path
),
"%s/%s"
,
image_dir
,
IMAGE_JSON
);
if
(
nret
<
0
||
(
size_t
)
nret
>=
sizeof
(
image_path
))
{
ERROR
(
"Failed to get image path"
);
return
-
1
;
...
...
@@ -331,13 +333,13 @@ int save_image(image_store_t *image_store, storage_image *image)
json_data
=
storage_image_generate_json
(
image
,
NULL
,
&
err
);
if
(
json_data
==
NULL
)
{
ERROR
(
"Failed to generate image
s.json
string:%s"
,
err
?
err
:
" "
);
ERROR
(
"Failed to generate image
json path
string:%s"
,
err
?
err
:
" "
);
ret
=
-
1
;
goto
out
;
}
if
(
save_file
(
image_path
,
json_data
,
CONFIG_FILE_MODE
)
!=
0
)
{
ERROR
(
"Failed to save image
s.
json file"
);
ERROR
(
"Failed to save image
json file"
);
ret
=
-
1
;
goto
out
;
}
...
...
@@ -602,23 +604,47 @@ static int image_store_load(image_store_t *image_store)
return
load_helper
(
image_store
);
}
static
char
*
get_image_store_root_path
(
const
struct
storage_module_init_options
*
opts
)
{
int
nret
=
0
;
char
*
root_dir
=
NULL
;
if
(
opts
==
NULL
)
{
return
NULL
;
}
if
(
opts
->
storage_root
==
NULL
||
opts
->
driver_name
==
NULL
)
{
ERROR
(
"Invalid argument"
);
return
NULL
;
}
nret
=
asprintf
(
&
root_dir
,
"%s/%s-images"
,
opts
->
storage_root
,
opts
->
driver_name
);
if
(
nret
<
0
||
nret
>
PATH_MAX
)
{
SYSERROR
(
"Create root path failed"
);
free
(
root_dir
);
root_dir
=
NULL
;
}
return
root_dir
;
}
int
image_store_init
(
struct
storage_module_init_options
*
opts
)
{
#define IMAGE_STORAGE_PATH "overlay-images"
int
ret
=
0
;
image_store_t
*
store
=
NULL
;
char
dir
[
PATH_MAX
]
=
{
0x00
}
;
char
*
root_dir
=
NULL
;
ret
=
snprintf
(
dir
,
sizeof
(
dir
),
"%s/%s"
,
opts
->
storage_root
,
IMAGE_STORAGE_PATH
);
if
(
ret
<
0
||
ret
>=
sizeof
(
dir
))
{
ERROR
(
"Failed to compose image store directory"
);
root_dir
=
get_image_store_root_path
(
opts
);
if
(
root_dir
==
NULL
)
{
return
ret
;
}
ret
=
util_mkdir_p
(
dir
,
IMAGE_STORE_PATH_MODE
);
ret
=
util_mkdir_p
(
root_
dir
,
IMAGE_STORE_PATH_MODE
);
if
(
ret
<
0
)
{
ERROR
(
"Unable to create image store directory %s."
,
dir
);
return
ret
;
ERROR
(
"Unable to create image store directory %s."
,
root_dir
);
ret
=
-
1
;
goto
out
;
}
store
=
(
image_store_t
*
)
util_common_calloc_s
(
sizeof
(
image_store_t
));
...
...
@@ -628,7 +654,8 @@ int image_store_init(struct storage_module_init_options *opts)
goto
out
;
}
store
->
dir
=
util_strdup_s
(
dir
);
store
->
dir
=
root_dir
;
root_dir
=
NULL
;
store
->
images
=
NULL
;
store
->
images_len
=
0
;
store
->
idindex
=
map_new
(
MAP_STR_PTR
,
MAP_DEFAULT_CMP_FUNC
,
image_store_field_kvfree
);
...
...
@@ -673,6 +700,7 @@ int image_store_init(struct storage_module_init_options *opts)
out:
free_image_store
(
store
);
free
(
root_dir
);
return
ret
;
}
...
...
@@ -840,7 +868,7 @@ storage_image *image_store_create(const char *id, const char **names, size_t nam
}
if
(
!
is_read_write
())
{
ERROR
(
"not allowed to create new images at %s/
images.json"
,
g_image_store
->
dir
);
ERROR
(
"not allowed to create new images at %s/
%s"
,
g_image_store
->
dir
,
IMAGE_JSON
);
return
NULL
;
}
...
...
@@ -1139,7 +1167,7 @@ int image_store_delete(const char *id)
char
image_path
[
PATH_MAX
]
=
{
0x00
};
if
(
!
is_read_write
())
{
ERROR
(
"not allowed to create new images at %s/
images.json"
,
g_image_store
->
dir
);
ERROR
(
"not allowed to create new images at %s/
%s"
,
g_image_store
->
dir
,
IMAGE_JSON
);
return
-
1
;
}
...
...
@@ -1189,7 +1217,6 @@ int image_store_delete(const char *id)
}
}
ERROR
(
"Uriel C delete image: %s"
,
to_delete_image
->
id
);
if
(
g_image_store
->
images_len
>
1
)
{
free_storage_image
(
to_delete_image
);
old_size
=
g_image_store
->
images_len
*
sizeof
(
storage_image
*
);
...
...
test/image/oci/storage/images/data/overlay-images/39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10/image.json
→
test/image/oci/storage/images/data/overlay-images/39891ff67da98ab8540d71320915f33d2eb80ab42908e398472cab3c1ce7ac10/image
s
.json
浏览文件 @
23f31b10
文件已移动
test/image/oci/storage/images/data/overlay-images/e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b/image.json
→
test/image/oci/storage/images/data/overlay-images/e4db68de4ff27c2adfea0c54bbb73a61a42f5b667c326de4d7d5b19ab71c6a3b/image
s
.json
浏览文件 @
23f31b10
文件已移动
test/image/oci/storage/images/storage_images_llt.cc
浏览文件 @
23f31b10
...
...
@@ -116,8 +116,10 @@ protected:
ASSERT_STRNE
(
cleanpath
(
dir
.
c_str
(),
real_path
,
sizeof
(
real_path
)),
nullptr
);
opts
.
storage_root
=
strdup
(
real_path
);
opts
.
driver_name
=
strdup
(
"overlay"
);
ASSERT_EQ
(
image_store_init
(
&
opts
),
0
);
free
(
opts
.
storage_root
);
free
(
opts
.
driver_name
);
}
void
TearDown
()
override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录