Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
c92ab5d6
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,发现更多精彩内容 >>
提交
c92ab5d6
编写于
5月 14, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename storage container to rootfs
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
8408ba1c
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
217 addition
and
206 deletion
+217
-206
src/constants.h
src/constants.h
+1
-1
src/image/oci/storage/CMakeLists.txt
src/image/oci/storage/CMakeLists.txt
+3
-3
src/image/oci/storage/rootfs_store/CMakeLists.txt
src/image/oci/storage/rootfs_store/CMakeLists.txt
+11
-0
src/image/oci/storage/rootfs_store/rootfs.c
src/image/oci/storage/rootfs_store/rootfs.c
+13
-13
src/image/oci/storage/rootfs_store/rootfs.h
src/image/oci/storage/rootfs_store/rootfs.h
+11
-11
src/image/oci/storage/rootfs_store/rootfs_store.c
src/image/oci/storage/rootfs_store/rootfs_store.c
+154
-154
src/image/oci/storage/rootfs_store/rootfs_store.h
src/image/oci/storage/rootfs_store/rootfs_store.h
+23
-23
src/image/oci/storage/storage.h
src/image/oci/storage/storage.h
+1
-1
src/json/schema/schema/storage/rootfs.json
src/json/schema/schema/storage/rootfs.json
+0
-0
未找到文件。
src/constants.h
浏览文件 @
c92ab5d6
...
...
@@ -54,7 +54,7 @@
#define IMAGE_STORE_PATH_MODE 0700
#define
CONTAINER
_STORE_PATH_MODE 0700
#define
ROOTFS
_STORE_PATH_MODE 0700
#define ISULAD_CONFIG "/etc/isulad"
...
...
src/image/oci/storage/CMakeLists.txt
浏览文件 @
c92ab5d6
...
...
@@ -2,13 +2,13 @@
aux_source_directory
(
${
CMAKE_CURRENT_SOURCE_DIR
}
local_storage_srcs
)
add_subdirectory
(
image_store
)
add_subdirectory
(
layer_store
)
add_subdirectory
(
container
_store
)
add_subdirectory
(
rootfs
_store
)
set
(
STORAGE_SRCS
${
local_storage_srcs
}
${
IMAGE_STORE_SRCS
}
${
LAYER_STORE_SRCS
}
${
CONTAINER
_STORE_SRCS
}
${
ROOTFS
_STORE_SRCS
}
PARENT_SCOPE
)
...
...
@@ -16,6 +16,6 @@ set(STORAGE_INCS
${
CMAKE_CURRENT_SOURCE_DIR
}
${
IMAGE_STORE_INCS
}
${
LAYER_STORE_INCS
}
${
CONTAINER
_STORE_INCS
}
${
ROOTFS
_STORE_INCS
}
PARENT_SCOPE
)
src/image/oci/storage/
container
_store/CMakeLists.txt
→
src/image/oci/storage/
rootfs
_store/CMakeLists.txt
浏览文件 @
c92ab5d6
# get current directory sources files
aux_source_directory
(
${
CMAKE_CURRENT_SOURCE_DIR
}
local_
container
_store_srcs
)
aux_source_directory
(
${
CMAKE_CURRENT_SOURCE_DIR
}
local_
rootfs
_store_srcs
)
set
(
CONTAINER
_STORE_SRCS
${
local_
container
_store_srcs
}
set
(
ROOTFS
_STORE_SRCS
${
local_
rootfs
_store_srcs
}
PARENT_SCOPE
)
set
(
CONTAINER
_STORE_INCS
set
(
ROOTFS
_STORE_INCS
${
CMAKE_CURRENT_SOURCE_DIR
}
PARENT_SCOPE
)
src/image/oci/storage/
container_store/container
.c
→
src/image/oci/storage/
rootfs_store/rootfs
.c
浏览文件 @
c92ab5d6
...
...
@@ -12,18 +12,18 @@
* Create: 2020-05-12
* Description: provide container function definition
******************************************************************************/
#include "
container
.h"
#include "storage_
container
.h"
#include "
rootfs
.h"
#include "storage_
rootfs
.h"
#include "constants.h"
#include "util_atomic.h"
#include "utils.h"
#include "log.h"
static
cntr_t
*
create_empty_cntr
()
static
cntr
ootfs
_t
*
create_empty_cntr
()
{
cntr_t
*
result
=
NULL
;
cntr
ootfs
_t
*
result
=
NULL
;
result
=
(
cntr
_t
*
)
util_smart_calloc_s
(
sizeof
(
cntr
_t
),
1
);
result
=
(
cntr
ootfs_t
*
)
util_smart_calloc_s
(
sizeof
(
cntrootfs
_t
),
1
);
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
goto
err_out
;
...
...
@@ -33,13 +33,13 @@ static cntr_t *create_empty_cntr()
return
result
;
err_out:
free_
container
_t
(
result
);
free_
rootfs
_t
(
result
);
return
NULL
;
}
cntr
_t
*
new_container
(
storage_container
*
scntr
)
cntr
ootfs_t
*
new_rootfs
(
storage_rootfs
*
scntr
)
{
cntr_t
*
c
=
NULL
;
cntr
ootfs
_t
*
c
=
NULL
;
if
(
scntr
==
NULL
)
{
ERROR
(
"Empty storage cntr"
);
...
...
@@ -57,7 +57,7 @@ cntr_t *new_container(storage_container *scntr)
}
void
container_ref_inc
(
cntr
_t
*
c
)
void
rootfs_ref_inc
(
cntrootfs
_t
*
c
)
{
if
(
c
==
NULL
)
{
return
;
...
...
@@ -65,7 +65,7 @@ void container_ref_inc(cntr_t *c)
atomic_int_inc
(
&
c
->
refcnt
);
}
void
container_ref_dec
(
cntr
_t
*
c
)
void
rootfs_ref_dec
(
cntrootfs
_t
*
c
)
{
bool
is_zero
=
false
;
...
...
@@ -78,15 +78,15 @@ void container_ref_dec(cntr_t *c)
return
;
}
free_
container
_t
(
c
);
free_
rootfs
_t
(
c
);
}
void
free_
container_t
(
cntr
_t
*
ptr
)
void
free_
rootfs_t
(
cntrootfs
_t
*
ptr
)
{
if
(
ptr
==
NULL
)
{
return
;
}
free_storage_
container
(
ptr
->
scontainer
);
free_storage_
rootfs
(
ptr
->
scontainer
);
ptr
->
scontainer
=
NULL
;
free
(
ptr
);
...
...
src/image/oci/storage/
container_store/container
.h
→
src/image/oci/storage/
rootfs_store/rootfs
.h
浏览文件 @
c92ab5d6
...
...
@@ -12,31 +12,31 @@
* Create: 2020-05-12
* Description: provide containers function definition
******************************************************************************/
#ifndef __OCI_STORAGE_
CONTAINER
_H
#define __OCI_STORAGE_
CONTAINER
_H
#ifndef __OCI_STORAGE_
ROOTFS
_H
#define __OCI_STORAGE_
ROOTFS
_H
#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include "storage_
container
.h"
#include "storage_
rootfs
.h"
#include "log.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
_cntr
_t_
{
storage_
container
*
scontainer
;
typedef
struct
_cntr
ootfs_t
{
storage_
rootfs
*
scontainer
;
uint64_t
refcnt
;
}
cntr_t
;
}
cntr
ootfs
_t
;
cntr
_t
*
new_container
(
storage_container
*
scntr
);
void
container_ref_inc
(
cntr
_t
*
cntr
);
void
container_ref_dec
(
cntr
_t
*
cntr
);
void
free_
container_t
(
cntr
_t
*
ptr
);
cntr
ootfs_t
*
new_rootfs
(
storage_rootfs
*
scntr
);
void
rootfs_ref_inc
(
cntrootfs
_t
*
cntr
);
void
rootfs_ref_dec
(
cntrootfs
_t
*
cntr
);
void
free_
rootfs_t
(
cntrootfs
_t
*
ptr
);
#ifdef __cplusplus
}
#endif
#endif // __OCI_STORAGE_
CONTAINER
_H
#endif // __OCI_STORAGE_
ROOTFS
_H
src/image/oci/storage/
container_store/container
_store.c
→
src/image/oci/storage/
rootfs_store/rootfs
_store.c
浏览文件 @
c92ab5d6
...
...
@@ -13,7 +13,7 @@
* Description: provide image store functions
******************************************************************************/
#define _GNU_SOURCE
#include "
container
_store.h"
#include "
rootfs
_store.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/limits.h>
...
...
@@ -31,32 +31,32 @@
#include "defs.h"
#include "map.h"
#include "linked_list.h"
#include "
container
.h"
#include "
rootfs
.h"
#define CONTAINER_JSON "container.json"
typedef
struct
container
_store
{
typedef
struct
rootfs
_store
{
pthread_rwlock_t
rwlock
;
char
*
dir
;
struct
linked_list
container
s_list
;
size_t
container
s_list_len
;
struct
linked_list
rootf
s_list
;
size_t
rootf
s_list_len
;
map_t
*
byid
;
map_t
*
bylayer
;
map_t
*
byname
;
bool
loaded
;
}
container
_store_t
;
}
rootfs
_store_t
;
container_store_t
*
g_container
_store
=
NULL
;
rootfs_store_t
*
g_rootfs
_store
=
NULL
;
static
inline
bool
container
_store_lock
(
bool
writable
)
static
inline
bool
rootfs
_store_lock
(
bool
writable
)
{
int
nret
=
0
;
if
(
writable
)
{
nret
=
pthread_rwlock_wrlock
(
&
g_
container
_store
->
rwlock
);
nret
=
pthread_rwlock_wrlock
(
&
g_
rootfs
_store
->
rwlock
);
}
else
{
nret
=
pthread_rwlock_rdlock
(
&
g_
container
_store
->
rwlock
);
nret
=
pthread_rwlock_rdlock
(
&
g_
rootfs
_store
->
rwlock
);
}
if
(
nret
!=
0
)
{
ERROR
(
"Lock memory store failed: %s"
,
strerror
(
nret
));
...
...
@@ -66,17 +66,17 @@ static inline bool container_store_lock(bool writable)
return
true
;
}
static
inline
void
container
_store_unlock
()
static
inline
void
rootfs
_store_unlock
()
{
int
nret
=
0
;
nret
=
pthread_rwlock_unlock
(
&
g_
container
_store
->
rwlock
);
nret
=
pthread_rwlock_unlock
(
&
g_
rootfs
_store
->
rwlock
);
if
(
nret
!=
0
)
{
FATAL
(
"Unlock memory store failed: %s"
,
strerror
(
nret
));
}
}
static
void
free_
container_store
(
container
_store_t
*
store
)
static
void
free_
rootfs_store
(
rootfs
_store_t
*
store
)
{
struct
linked_list
*
item
=
NULL
;
struct
linked_list
*
next
=
NULL
;
...
...
@@ -97,36 +97,36 @@ static void free_container_store(container_store_t *store)
(
void
)
map_free
(
store
->
byname
);
store
->
byname
=
NULL
;
linked_list_for_each_safe
(
item
,
&
(
store
->
container
s_list
),
next
)
{
linked_list_for_each_safe
(
item
,
&
(
store
->
rootf
s_list
),
next
)
{
linked_list_del
(
item
);
container_ref_dec
((
cntr
_t
*
)
item
->
elem
);
rootfs_ref_dec
((
cntrootfs
_t
*
)
item
->
elem
);
free
(
item
);
item
=
NULL
;
}
store
->
container
s_list_len
=
0
;
store
->
rootf
s_list_len
=
0
;
free
(
store
);
}
void
container
_store_free
()
void
rootfs
_store_free
()
{
free_
container_store
(
g_container
_store
);
g_
container
_store
=
NULL
;
free_
rootfs_store
(
g_rootfs
_store
);
g_
rootfs
_store
=
NULL
;
}
static
void
container
_store_field_kvfree
(
void
*
key
,
void
*
value
)
static
void
rootfs
_store_field_kvfree
(
void
*
key
,
void
*
value
)
{
(
void
)
value
;
free
(
key
);
}
static
int
do_append_container
(
storage_
container
*
c
)
static
int
do_append_container
(
storage_
rootfs
*
c
)
{
cntr_t
*
cntr
=
NULL
;
cntr
ootfs
_t
*
cntr
=
NULL
;
struct
linked_list
*
item
=
NULL
;
cntr
=
new_
container
(
c
);
cntr
=
new_
rootfs
(
c
);
if
(
cntr
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
...
...
@@ -135,13 +135,13 @@ static int do_append_container(storage_container *c)
item
=
util_smart_calloc_s
(
sizeof
(
struct
linked_list
),
1
);
if
(
item
==
NULL
)
{
ERROR
(
"Out of memory"
);
free_
container
_t
(
cntr
);
free_
rootfs
_t
(
cntr
);
return
-
1
;
}
linked_list_add_elem
(
item
,
cntr
);
linked_list_add_tail
(
&
g_
container_store
->
container
s_list
,
item
);
g_
container_store
->
container
s_list_len
++
;
linked_list_add_tail
(
&
g_
rootfs_store
->
rootf
s_list
,
item
);
g_
rootfs_store
->
rootf
s_list_len
++
;
return
0
;
}
...
...
@@ -151,7 +151,7 @@ static int append_container_by_directory(const char *container_dir)
int
ret
=
0
;
int
nret
;
char
container_path
[
PATH_MAX
]
=
{
0x00
};
storage_
container
*
c
=
NULL
;
storage_
rootfs
*
c
=
NULL
;
parser_error
err
=
NULL
;
nret
=
snprintf
(
container_path
,
sizeof
(
container_path
),
"%s/%s"
,
container_dir
,
CONTAINER_JSON
);
...
...
@@ -160,7 +160,7 @@ static int append_container_by_directory(const char *container_dir)
return
-
1
;
}
c
=
storage_
container
_parse_file
(
container_path
,
NULL
,
&
err
);
c
=
storage_
rootfs
_parse_file
(
container_path
,
NULL
,
&
err
);
if
(
c
==
NULL
)
{
ERROR
(
"Failed to parse container path: %s"
,
err
);
return
-
1
;
...
...
@@ -175,7 +175,7 @@ static int append_container_by_directory(const char *container_dir)
c
=
NULL
;
out:
free_storage_
container
(
c
);
free_storage_
rootfs
(
c
);
free
(
err
);
return
ret
;
}
...
...
@@ -190,12 +190,12 @@ static int get_containers_from_json()
char
*
id_patten
=
"^[a-f0-9]{64}$"
;
char
container_path
[
PATH_MAX
]
=
{
0x00
};
if
(
!
container
_store_lock
(
true
))
{
if
(
!
rootfs
_store_lock
(
true
))
{
ERROR
(
"Failed to lock container store"
);
return
-
1
;
}
ret
=
util_list_all_subdir
(
g_
container
_store
->
dir
,
&
container_dirs
);
ret
=
util_list_all_subdir
(
g_
rootfs
_store
->
dir
,
&
container_dirs
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to get container directorys"
);
goto
out
;
...
...
@@ -210,7 +210,7 @@ static int get_containers_from_json()
}
DEBUG
(
"Restore the containers:%s"
,
container_dirs
[
i
]);
nret
=
snprintf
(
container_path
,
sizeof
(
container_path
),
"%s/%s"
,
g_
container
_store
->
dir
,
container_dirs
[
i
]);
nret
=
snprintf
(
container_path
,
sizeof
(
container_path
),
"%s/%s"
,
g_
rootfs
_store
->
dir
,
container_dirs
[
i
]);
if
(
nret
<
0
||
(
size_t
)
nret
>=
sizeof
(
container_path
))
{
ERROR
(
"Failed to get container path"
);
ret
=
-
1
;
...
...
@@ -226,11 +226,11 @@ static int get_containers_from_json()
out:
util_free_array
(
container_dirs
);
container
_store_unlock
();
rootfs
_store_unlock
();
return
ret
;
}
static
int
remove_name
(
cntr_t
*
cntr
,
const
char
*
name
)
static
int
remove_name
(
cntr
ootfs
_t
*
cntr
,
const
char
*
name
)
{
size_t
i
;
size_t
new_size
;
...
...
@@ -273,12 +273,12 @@ static int remove_name(cntr_t *cntr, const char *name)
static
int
get_container_path
(
const
char
*
id
,
char
*
path
,
size_t
len
)
{
int
nret
=
snprintf
(
path
,
len
,
"%s/%s/%s"
,
g_
container
_store
->
dir
,
id
,
CONTAINER_JSON
);
int
nret
=
snprintf
(
path
,
len
,
"%s/%s/%s"
,
g_
rootfs
_store
->
dir
,
id
,
CONTAINER_JSON
);
return
(
nret
<
0
||
(
size_t
)
nret
>=
len
)
?
-
1
:
0
;
}
static
int
save_
container
(
cntr
_t
*
cntr
)
static
int
save_
rootfs
(
cntrootfs
_t
*
cntr
)
{
int
ret
=
0
;
char
container_path
[
PATH_MAX
]
=
{
0x00
};
...
...
@@ -292,13 +292,13 @@ static int save_container(cntr_t *cntr)
}
strcpy
(
container_dir
,
container_path
);
ret
=
util_mkdir_p
(
dirname
(
container_dir
),
CONTAINER
_STORE_PATH_MODE
);
ret
=
util_mkdir_p
(
dirname
(
container_dir
),
ROOTFS
_STORE_PATH_MODE
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to create container directory %s."
,
container_path
);
return
-
1
;
}
json_data
=
storage_
container
_generate_json
(
cntr
->
scontainer
,
NULL
,
&
err
);
json_data
=
storage_
rootfs
_generate_json
(
cntr
->
scontainer
,
NULL
,
&
err
);
if
(
json_data
==
NULL
)
{
ERROR
(
"Failed to generate container json path string:%s"
,
err
?
err
:
" "
);
ret
=
-
1
;
...
...
@@ -318,24 +318,24 @@ out:
return
ret
;
}
static
int
load_container_to_store_field
(
cntr_t
*
cntr
)
static
int
load_container_to_store_field
(
cntr
ootfs
_t
*
cntr
)
{
int
ret
=
0
;
bool
should_save
=
false
;
size_t
i
;
if
(
!
map_replace
(
g_
container
_store
->
byid
,
(
void
*
)
cntr
->
scontainer
->
id
,
(
void
*
)
cntr
))
{
if
(
!
map_replace
(
g_
rootfs
_store
->
byid
,
(
void
*
)
cntr
->
scontainer
->
id
,
(
void
*
)
cntr
))
{
ERROR
(
"Failed to insert container to id index"
);
return
-
1
;
}
if
(
!
map_replace
(
g_
container
_store
->
bylayer
,
(
void
*
)
cntr
->
scontainer
->
layer
,
(
void
*
)
cntr
))
{
if
(
!
map_replace
(
g_
rootfs
_store
->
bylayer
,
(
void
*
)
cntr
->
scontainer
->
layer
,
(
void
*
)
cntr
))
{
ERROR
(
"Failed to insert container to layer index"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
cntr
->
scontainer
->
names_len
;
i
++
)
{
cntr
_t
*
conflict_container
=
(
cntr_t
*
)
map_search
(
g_container
_store
->
byname
,
(
void
*
)
cntr
->
scontainer
->
names
[
i
]);
cntr
ootfs_t
*
conflict_container
=
(
cntrootfs_t
*
)
map_search
(
g_rootfs
_store
->
byname
,
(
void
*
)
cntr
->
scontainer
->
names
[
i
]);
if
(
conflict_container
!=
NULL
)
{
if
(
remove_name
(
conflict_container
,
cntr
->
scontainer
->
names
[
i
])
!=
0
)
{
ERROR
(
"Failed to remove name from conflict container"
);
...
...
@@ -344,14 +344,14 @@ static int load_container_to_store_field(cntr_t *cntr)
}
should_save
=
true
;
}
if
(
!
map_replace
(
g_
container
_store
->
byname
,
(
void
*
)
cntr
->
scontainer
->
names
[
i
],
(
void
*
)
cntr
))
{
if
(
!
map_replace
(
g_
rootfs
_store
->
byname
,
(
void
*
)
cntr
->
scontainer
->
names
[
i
],
(
void
*
)
cntr
))
{
ERROR
(
"Failed to insert containes to name index"
);
ret
=
-
1
;
goto
out
;
}
}
if
(
should_save
&&
save_
container
(
cntr
)
!=
0
)
{
if
(
should_save
&&
save_
rootfs
(
cntr
)
!=
0
)
{
ERROR
(
"Failed to save container"
);
ret
=
-
1
;
goto
out
;
...
...
@@ -361,12 +361,12 @@ out:
return
ret
;
}
static
int
container
_store_load
()
static
int
rootfs
_store_load
()
{
struct
linked_list
*
item
=
NULL
;
struct
linked_list
*
next
=
NULL
;
if
(
g_
container
_store
->
loaded
)
{
if
(
g_
rootfs
_store
->
loaded
)
{
DEBUG
(
"Do not need reload if daemon"
);
return
0
;
}
...
...
@@ -376,19 +376,19 @@ static int container_store_load()
return
-
1
;
}
linked_list_for_each_safe
(
item
,
&
(
g_
container_store
->
container
s_list
),
next
)
{
if
(
load_container_to_store_field
((
cntr_t
*
)
item
->
elem
)
!=
0
)
{
linked_list_for_each_safe
(
item
,
&
(
g_
rootfs_store
->
rootf
s_list
),
next
)
{
if
(
load_container_to_store_field
((
cntr
ootfs
_t
*
)
item
->
elem
)
!=
0
)
{
ERROR
(
"Failed to load container to container store"
);
return
-
1
;
}
}
g_
container
_store
->
loaded
=
true
;
g_
rootfs
_store
->
loaded
=
true
;
return
0
;
}
static
char
*
get_
container
_store_root_path
(
const
struct
storage_module_init_options
*
opts
)
static
char
*
get_
rootfs
_store_root_path
(
const
struct
storage_module_init_options
*
opts
)
{
int
nret
=
0
;
char
*
root_dir
=
NULL
;
...
...
@@ -412,70 +412,70 @@ static char *get_container_store_root_path(const struct storage_module_init_opti
return
root_dir
;
}
int
container
_store_init
(
struct
storage_module_init_options
*
opts
)
int
rootfs
_store_init
(
struct
storage_module_init_options
*
opts
)
{
int
ret
=
0
;
char
*
root_dir
=
NULL
;
if
(
g_
container
_store
!=
NULL
)
{
if
(
g_
rootfs
_store
!=
NULL
)
{
ERROR
(
"Container store has already been initialized"
);
return
-
1
;
}
root_dir
=
get_
container
_store_root_path
(
opts
);
root_dir
=
get_
rootfs
_store_root_path
(
opts
);
if
(
root_dir
==
NULL
)
{
return
ret
;
}
ret
=
util_mkdir_p
(
root_dir
,
CONTAINER
_STORE_PATH_MODE
);
ret
=
util_mkdir_p
(
root_dir
,
ROOTFS
_STORE_PATH_MODE
);
if
(
ret
<
0
)
{
ERROR
(
"Unable to create container store directory %s."
,
root_dir
);
ret
=
-
1
;
goto
out
;
}
g_
container_store
=
(
container_store_t
*
)
util_common_calloc_s
(
sizeof
(
container
_store_t
));
if
(
g_
container
_store
==
NULL
)
{
g_
rootfs_store
=
(
rootfs_store_t
*
)
util_common_calloc_s
(
sizeof
(
rootfs
_store_t
));
if
(
g_
rootfs
_store
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
ret
=
pthread_rwlock_init
(
&
(
g_
container
_store
->
rwlock
),
NULL
);
ret
=
pthread_rwlock_init
(
&
(
g_
rootfs
_store
->
rwlock
),
NULL
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to init container store rwlock"
);
ret
=
-
1
;
goto
out
;
}
g_
container
_store
->
dir
=
root_dir
;
g_
rootfs
_store
->
dir
=
root_dir
;
root_dir
=
NULL
;
g_
container_store
->
container
s_list_len
=
0
;
linked_list_init
(
&
g_
container_store
->
container
s_list
);
g_
rootfs_store
->
rootf
s_list_len
=
0
;
linked_list_init
(
&
g_
rootfs_store
->
rootf
s_list
);
g_
container_store
->
byid
=
map_new
(
MAP_STR_PTR
,
MAP_DEFAULT_CMP_FUNC
,
container
_store_field_kvfree
);
if
(
g_
container
_store
->
byid
==
NULL
)
{
g_
rootfs_store
->
byid
=
map_new
(
MAP_STR_PTR
,
MAP_DEFAULT_CMP_FUNC
,
rootfs
_store_field_kvfree
);
if
(
g_
rootfs
_store
->
byid
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
g_
container_store
->
bylayer
=
map_new
(
MAP_STR_PTR
,
MAP_DEFAULT_CMP_FUNC
,
container
_store_field_kvfree
);
if
(
g_
container
_store
->
bylayer
==
NULL
)
{
g_
rootfs_store
->
bylayer
=
map_new
(
MAP_STR_PTR
,
MAP_DEFAULT_CMP_FUNC
,
rootfs
_store_field_kvfree
);
if
(
g_
rootfs
_store
->
bylayer
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
g_
container_store
->
byname
=
map_new
(
MAP_STR_PTR
,
MAP_DEFAULT_CMP_FUNC
,
container
_store_field_kvfree
);
if
(
g_
container
_store
->
byname
==
NULL
)
{
g_
rootfs_store
->
byname
=
map_new
(
MAP_STR_PTR
,
MAP_DEFAULT_CMP_FUNC
,
rootfs
_store_field_kvfree
);
if
(
g_
rootfs
_store
->
byname
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
ret
=
container
_store_load
();
ret
=
rootfs
_store_load
();
if
(
ret
!=
0
)
{
ERROR
(
"Failed to load container store"
);
ret
=
-
1
;
...
...
@@ -484,8 +484,8 @@ int container_store_init(struct storage_module_init_options *opts)
out:
if
(
ret
!=
0
)
{
free_
container_store
(
g_container
_store
);
g_
container
_store
=
NULL
;
free_
rootfs_store
(
g_rootfs
_store
);
g_
rootfs
_store
=
NULL
;
}
free
(
root_dir
);
return
ret
;
...
...
@@ -509,7 +509,7 @@ static char *generate_random_container_id()
ERROR
(
"Generate random str failed"
);
goto
err_out
;
}
cntr
_t
*
cntr
=
map_search
(
g_container
_store
->
byid
,
(
void
*
)
id
);
cntr
ootfs_t
*
cntr
=
map_search
(
g_rootfs
_store
->
byid
,
(
void
*
)
id
);
if
(
cntr
==
NULL
)
{
break
;
}
...
...
@@ -526,69 +526,69 @@ err_out:
return
NULL
;
}
static
int
copy_id_map
(
storage_
container
*
c
,
const
struct
storage_container_options
*
container
_opts
)
static
int
copy_id_map
(
storage_
rootfs
*
c
,
const
struct
storage_rootfs_options
*
rootfs
_opts
)
{
int
ret
=
0
;
size_t
i
;
storage_
container
_uidmap_element
**
uid_map
=
NULL
;
storage_
rootfs
_uidmap_element
**
uid_map
=
NULL
;
size_t
uid_map_len
=
0
;
storage_
container
_gidmap_element
**
gid_map
=
NULL
;
storage_
rootfs
_gidmap_element
**
gid_map
=
NULL
;
size_t
gid_map_len
=
0
;
if
(
container
_opts
==
NULL
)
{
if
(
rootfs
_opts
==
NULL
)
{
return
0
;
}
if
(
container
_opts
->
id_mapping_opts
.
uid_map_len
!=
0
)
{
if
(
container_opts
->
id_mapping_opts
.
uid_map_len
>=
SIZE_MAX
/
sizeof
(
storage_container
_uidmap_element
*
))
{
if
(
rootfs
_opts
->
id_mapping_opts
.
uid_map_len
!=
0
)
{
if
(
rootfs_opts
->
id_mapping_opts
.
uid_map_len
>=
SIZE_MAX
/
sizeof
(
storage_rootfs
_uidmap_element
*
))
{
ERROR
(
"Too many id map"
);
return
-
1
;
}
uid_map
=
(
storage_
container
_uidmap_element
**
)
util_common_calloc_s
(
sizeof
(
storage_
container_uidmap_element
*
)
*
container
_opts
->
id_mapping_opts
.
uid_map_len
);
uid_map
=
(
storage_
rootfs
_uidmap_element
**
)
util_common_calloc_s
(
sizeof
(
storage_
rootfs_uidmap_element
*
)
*
rootfs
_opts
->
id_mapping_opts
.
uid_map_len
);
if
(
uid_map
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
container
_opts
->
id_mapping_opts
.
uid_map_len
;
i
++
)
{
uid_map
[
i
]
=
(
storage_
container
_uidmap_element
*
)
util_common_calloc_s
(
sizeof
(
storage_
container
_uidmap_element
));
for
(
i
=
0
;
i
<
rootfs
_opts
->
id_mapping_opts
.
uid_map_len
;
i
++
)
{
uid_map
[
i
]
=
(
storage_
rootfs
_uidmap_element
*
)
util_common_calloc_s
(
sizeof
(
storage_
rootfs
_uidmap_element
));
if
(
uid_map
[
i
]
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
uid_map
[
i
]
->
container_id
=
container
_opts
->
id_mapping_opts
.
uid_map
->
container_id
;
uid_map
[
i
]
->
host_id
=
container
_opts
->
id_mapping_opts
.
uid_map
->
host_id
;
uid_map
[
i
]
->
size
=
container
_opts
->
id_mapping_opts
.
uid_map
->
size
;
uid_map
[
i
]
->
container_id
=
rootfs
_opts
->
id_mapping_opts
.
uid_map
->
container_id
;
uid_map
[
i
]
->
host_id
=
rootfs
_opts
->
id_mapping_opts
.
uid_map
->
host_id
;
uid_map
[
i
]
->
size
=
rootfs
_opts
->
id_mapping_opts
.
uid_map
->
size
;
uid_map_len
++
;
}
}
if
(
container
_opts
->
id_mapping_opts
.
gid_map_len
!=
0
)
{
if
(
container_opts
->
id_mapping_opts
.
gid_map_len
>=
SIZE_MAX
/
sizeof
(
storage_container
_gidmap_element
*
))
{
if
(
rootfs
_opts
->
id_mapping_opts
.
gid_map_len
!=
0
)
{
if
(
rootfs_opts
->
id_mapping_opts
.
gid_map_len
>=
SIZE_MAX
/
sizeof
(
storage_rootfs
_gidmap_element
*
))
{
ERROR
(
"Too many id map"
);
return
-
1
;
}
gid_map
=
(
storage_
container
_gidmap_element
**
)
util_common_calloc_s
(
sizeof
(
storage_
container_gidmap_element
*
)
*
container
_opts
->
id_mapping_opts
.
gid_map_len
);
gid_map
=
(
storage_
rootfs
_gidmap_element
**
)
util_common_calloc_s
(
sizeof
(
storage_
rootfs_gidmap_element
*
)
*
rootfs
_opts
->
id_mapping_opts
.
gid_map_len
);
if
(
gid_map
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
container
_opts
->
id_mapping_opts
.
gid_map_len
;
i
++
)
{
gid_map
[
i
]
=
(
storage_
container
_gidmap_element
*
)
util_common_calloc_s
(
sizeof
(
storage_
container
_gidmap_element
));
for
(
i
=
0
;
i
<
rootfs
_opts
->
id_mapping_opts
.
gid_map_len
;
i
++
)
{
gid_map
[
i
]
=
(
storage_
rootfs
_gidmap_element
*
)
util_common_calloc_s
(
sizeof
(
storage_
rootfs
_gidmap_element
));
if
(
gid_map
[
i
]
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
gid_map
[
i
]
->
container_id
=
container
_opts
->
id_mapping_opts
.
gid_map
->
container_id
;
gid_map
[
i
]
->
host_id
=
container
_opts
->
id_mapping_opts
.
gid_map
->
host_id
;
gid_map
[
i
]
->
size
=
container
_opts
->
id_mapping_opts
.
gid_map
->
size
;
gid_map
[
i
]
->
container_id
=
rootfs
_opts
->
id_mapping_opts
.
gid_map
->
container_id
;
gid_map
[
i
]
->
host_id
=
rootfs
_opts
->
id_mapping_opts
.
gid_map
->
host_id
;
gid_map
[
i
]
->
size
=
rootfs
_opts
->
id_mapping_opts
.
gid_map
->
size
;
gid_map_len
++
;
}
}
...
...
@@ -619,15 +619,15 @@ out:
return
ret
;
}
static
storage_
container
*
new_storage_container
(
const
char
*
id
,
const
char
*
image
,
char
**
unique_names
,
size_t
unique_names_len
,
const
char
*
layer
,
const
char
*
metadata
,
struct
storage_container_options
*
container
_opts
)
static
storage_
rootfs
*
new_storage_rootfs
(
const
char
*
id
,
const
char
*
image
,
char
**
unique_names
,
size_t
unique_names_len
,
const
char
*
layer
,
const
char
*
metadata
,
struct
storage_rootfs_options
*
rootfs
_opts
)
{
int
ret
=
0
;
char
timebuffer
[
TIME_STR_SIZE
]
=
{
0x00
};
storage_
container
*
c
=
NULL
;
storage_
rootfs
*
c
=
NULL
;
c
=
(
storage_
container
*
)
util_common_calloc_s
(
sizeof
(
storage_container
));
c
=
(
storage_
rootfs
*
)
util_common_calloc_s
(
sizeof
(
storage_rootfs
));
if
(
c
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
...
...
@@ -649,7 +649,7 @@ static storage_container *new_storage_container(const char *id, const char *imag
}
c
->
created
=
util_strdup_s
(
timebuffer
);
if
(
copy_id_map
(
c
,
container
_opts
)
!=
0
)
{
if
(
copy_id_map
(
c
,
rootfs
_opts
)
!=
0
)
{
ERROR
(
"Failed to copy UID&GID map"
);
ret
=
-
1
;
goto
out
;
...
...
@@ -657,14 +657,14 @@ static storage_container *new_storage_container(const char *id, const char *imag
out:
if
(
ret
!=
0
)
{
free_storage_
container
(
c
);
free_storage_
rootfs
(
c
);
c
=
NULL
;
}
return
c
;
}
static
int
container_store_append_container
(
const
char
*
id
,
const
char
*
layer
,
const
char
**
unique_names
,
size_t
unique_names_len
,
cntr
_t
*
cntr
)
static
int
rootfs_store_append_container_rootfs
(
const
char
*
id
,
const
char
*
layer
,
const
char
**
unique_names
,
size_t
unique_names_len
,
cntrootfs
_t
*
cntr
)
{
int
ret
=
0
;
size_t
i
=
0
;
...
...
@@ -676,29 +676,29 @@ static int container_store_append_container(const char *id, const char *layer, c
return
-
1
;
}
linked_list_add_elem
(
item
,
cntr
);
linked_list_add_tail
(
&
g_
container_store
->
container
s_list
,
item
);
g_
container_store
->
container
s_list_len
++
;
linked_list_add_tail
(
&
g_
rootfs_store
->
rootf
s_list
,
item
);
g_
rootfs_store
->
rootf
s_list_len
++
;
if
(
!
map_insert
(
g_
container
_store
->
byid
,
(
void
*
)
id
,
(
void
*
)
cntr
))
{
if
(
!
map_insert
(
g_
rootfs
_store
->
byid
,
(
void
*
)
id
,
(
void
*
)
cntr
))
{
ERROR
(
"Failed to insert container to container store"
);
ret
=
-
1
;
goto
out
;
}
if
(
!
map_insert
(
g_
container
_store
->
bylayer
,
(
void
*
)
layer
,
(
void
*
)
cntr
))
{
if
(
!
map_insert
(
g_
rootfs
_store
->
bylayer
,
(
void
*
)
layer
,
(
void
*
)
cntr
))
{
ERROR
(
"Failed to insert container to container store"
);
ret
=
-
1
;
goto
out
;
}
for
(
i
=
0
;
i
<
unique_names_len
;
i
++
)
{
if
(
!
map_insert
(
g_
container
_store
->
byname
,
(
void
*
)
unique_names
[
i
],
(
void
*
)
cntr
))
{
if
(
!
map_insert
(
g_
rootfs
_store
->
byname
,
(
void
*
)
unique_names
[
i
],
(
void
*
)
cntr
))
{
ERROR
(
"Failed to insert container to container store's name index"
);
ret
=
-
1
;
goto
out
;
}
}
container
_ref_inc
(
cntr
);
rootfs
_ref_inc
(
cntr
);
out:
if
(
ret
!=
0
)
{
...
...
@@ -708,22 +708,22 @@ out:
return
ret
;
}
char
*
container
_store_create
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
,
const
char
*
image
,
const
char
*
layer
,
const
char
*
metadata
,
struct
storage_container_options
*
container
_opts
)
char
*
rootfs
_store_create
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
,
const
char
*
image
,
const
char
*
layer
,
const
char
*
metadata
,
struct
storage_rootfs_options
*
rootfs
_opts
)
{
int
ret
=
0
;
char
*
dst_id
=
NULL
;
char
**
unique_names
=
NULL
;
size_t
unique_names_len
=
0
;
cntr_t
*
cntr
=
NULL
;
storage_
container
*
c
=
NULL
;
cntr
ootfs
_t
*
cntr
=
NULL
;
storage_
rootfs
*
c
=
NULL
;
if
(
g_
container
_store
==
NULL
)
{
if
(
g_
rootfs
_store
==
NULL
)
{
ERROR
(
"Container store is not ready"
);
return
NULL
;
}
if
(
!
container
_store_lock
(
true
))
{
if
(
!
rootfs
_store_lock
(
true
))
{
ERROR
(
"Failed to lock container store, not allowed to create new containers"
);
return
NULL
;
}
...
...
@@ -734,7 +734,7 @@ char *container_store_create(const char *id, const char **names, size_t names_le
dst_id
=
util_strdup_s
(
id
);
}
if
(
map_search
(
g_
container
_store
->
byid
,
(
void
*
)
dst_id
)
!=
NULL
)
{
if
(
map_search
(
g_
rootfs
_store
->
byid
,
(
void
*
)
dst_id
)
!=
NULL
)
{
ERROR
(
"ID is already in use: %s"
,
id
);
ret
=
-
1
;
goto
out
;
...
...
@@ -746,27 +746,27 @@ char *container_store_create(const char *id, const char **names, size_t names_le
goto
out
;
}
c
=
new_storage_
container
(
id
,
image
,
unique_names
,
unique_names_len
,
layer
,
metadata
,
container
_opts
);
c
=
new_storage_
rootfs
(
id
,
image
,
unique_names
,
unique_names_len
,
layer
,
metadata
,
rootfs
_opts
);
if
(
c
==
NULL
)
{
ERROR
(
"Failed to generate new storage container"
);
ret
=
-
1
;
goto
out
;
}
cntr
=
new_
container
(
c
);
cntr
=
new_
rootfs
(
c
);
if
(
cntr
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
if
(
container_store_append_container
(
id
,
layer
,
(
const
char
**
)
unique_names
,
unique_names_len
,
cntr
)
!=
0
)
{
if
(
rootfs_store_append_container_rootfs
(
id
,
layer
,
(
const
char
**
)
unique_names
,
unique_names_len
,
cntr
)
!=
0
)
{
ERROR
(
"Failed to append container to container store"
);
ret
=
-
1
;
goto
out
;
}
if
(
save_
container
(
cntr
)
!=
0
)
{
if
(
save_
rootfs
(
cntr
)
!=
0
)
{
ERROR
(
"Failed to save container"
);
ret
=
-
1
;
goto
out
;
...
...
@@ -776,23 +776,23 @@ out:
if
(
ret
!=
0
)
{
free
(
dst_id
);
dst_id
=
NULL
;
free_storage_
container
(
c
);
free_storage_
rootfs
(
c
);
c
=
NULL
;
free_
container
_t
(
cntr
);
free_
rootfs
_t
(
cntr
);
cntr
=
NULL
;
}
container
_store_unlock
();
rootfs
_store_unlock
();
return
dst_id
;
}
static
cntr
_t
*
get_container
_for_store_by_prefix
(
const
char
*
id
)
static
cntr
ootfs_t
*
get_rootfs
_for_store_by_prefix
(
const
char
*
id
)
{
bool
ret
=
true
;
cntr_t
*
value
=
NULL
;
cntr
ootfs
_t
*
value
=
NULL
;
map_itor
*
itor
=
NULL
;
const
char
*
key
=
NULL
;
itor
=
map_itor_new
(
g_
container
_store
->
byid
);
itor
=
map_itor_new
(
g_
rootfs
_store
->
byid
);
if
(
itor
==
NULL
)
{
ERROR
(
"Failed to get byid's iterator from container store"
);
return
NULL
;
...
...
@@ -825,26 +825,26 @@ out:
return
value
;
}
static
cntr_t
*
lookup
(
const
char
*
id
)
static
cntr
ootfs
_t
*
lookup
(
const
char
*
id
)
{
cntr_t
*
value
=
NULL
;
cntr
ootfs
_t
*
value
=
NULL
;
if
(
id
==
NULL
)
{
ERROR
(
"Invalid input parameter, id is NULL"
);
return
NULL
;
}
value
=
map_search
(
g_
container
_store
->
byid
,
(
void
*
)
id
);
value
=
map_search
(
g_
rootfs
_store
->
byid
,
(
void
*
)
id
);
if
(
value
!=
NULL
)
{
goto
found
;
}
value
=
map_search
(
g_
container
_store
->
bylayer
,
(
void
*
)
id
);
value
=
map_search
(
g_
rootfs
_store
->
bylayer
,
(
void
*
)
id
);
if
(
value
!=
NULL
)
{
goto
found
;
}
value
=
get_
container
_for_store_by_prefix
(
id
);
value
=
get_
rootfs
_for_store_by_prefix
(
id
);
if
(
value
!=
NULL
)
{
goto
found
;
}
...
...
@@ -852,34 +852,34 @@ static cntr_t *lookup(const char *id)
return
NULL
;
found:
container
_ref_inc
(
value
);
rootfs
_ref_inc
(
value
);
return
value
;
}
static
inline
cntr_t
*
lookup_with_lock
(
const
char
*
id
)
static
inline
cntr
ootfs
_t
*
lookup_with_lock
(
const
char
*
id
)
{
cntr_t
*
cntr
=
NULL
;
cntr
ootfs
_t
*
cntr
=
NULL
;
if
(
!
container
_store_lock
(
false
))
{
if
(
!
rootfs
_store_lock
(
false
))
{
return
NULL
;
}
cntr
=
lookup
(
id
);
container
_store_unlock
();
rootfs
_store_unlock
();
return
cntr
;
}
char
*
container
_store_lookup
(
const
char
*
id
)
char
*
rootfs
_store_lookup
(
const
char
*
id
)
{
char
*
container_id
=
NULL
;
cntr_t
*
cntr
=
NULL
;
cntr
ootfs
_t
*
cntr
=
NULL
;
if
(
id
==
NULL
)
{
ERROR
(
"Invalid input parameter, id is NULL"
);
return
NULL
;
}
if
(
g_
container
_store
==
NULL
)
{
if
(
g_
rootfs
_store
==
NULL
)
{
ERROR
(
"Container store is not ready"
);
return
NULL
;
}
...
...
@@ -891,77 +891,77 @@ char *container_store_lookup(const char *id)
}
container_id
=
util_strdup_s
(
cntr
->
scontainer
->
id
);
container
_ref_dec
(
cntr
);
rootfs
_ref_dec
(
cntr
);
return
container_id
;
}
int
container
_store_delete
(
const
char
*
id
)
int
rootfs
_store_delete
(
const
char
*
id
)
{
return
0
;
}
int
container
_store_wipe
()
int
rootfs
_store_wipe
()
{
return
0
;
}
int
container
_store_set_big_data
(
const
char
*
id
,
const
char
*
key
,
const
char
*
data
)
int
rootfs
_store_set_big_data
(
const
char
*
id
,
const
char
*
key
,
const
char
*
data
)
{
return
0
;
}
int
container
_store_set_names
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
)
int
rootfs
_store_set_names
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
)
{
return
0
;
}
int
container
_store_set_metadata
(
const
char
*
id
,
const
char
*
metadata
)
int
rootfs
_store_set_metadata
(
const
char
*
id
,
const
char
*
metadata
)
{
return
0
;
}
int
container_store_save
(
cntr
_t
*
c
)
int
rootfs_store_save
(
cntrootfs
_t
*
c
)
{
return
0
;
}
bool
container
_store_exists
(
const
char
*
id
)
bool
rootfs
_store_exists
(
const
char
*
id
)
{
return
false
;
}
cntr
_t
*
container_store_get_container
(
const
char
*
id
)
cntr
ootfs_t
*
rootfs_store_get_rootfs
(
const
char
*
id
)
{
return
NULL
;
}
char
*
container
_store_big_data
(
const
char
*
id
,
const
char
*
key
)
char
*
rootfs
_store_big_data
(
const
char
*
id
,
const
char
*
key
)
{
return
NULL
;
}
int64_t
container
_store_big_data_size
(
const
char
*
id
,
const
char
*
key
)
int64_t
rootfs
_store_big_data_size
(
const
char
*
id
,
const
char
*
key
)
{
return
-
1
;
}
char
*
container
_store_big_data_digest
(
const
char
*
id
,
const
char
*
key
)
char
*
rootfs
_store_big_data_digest
(
const
char
*
id
,
const
char
*
key
)
{
return
NULL
;
}
int
container
_store_big_data_names
(
const
char
*
id
,
char
***
names
,
size_t
*
names_len
)
int
rootfs
_store_big_data_names
(
const
char
*
id
,
char
***
names
,
size_t
*
names_len
)
{
return
0
;
}
char
*
container
_store_metadata
(
const
char
*
id
)
char
*
rootfs
_store_metadata
(
const
char
*
id
)
{
return
NULL
;
}
int
container_store_get_all_containers
(
cntr
_t
*
containers
,
size_t
*
len
)
int
rootfs_store_get_all_rootfs
(
cntrootfs
_t
*
containers
,
size_t
*
len
)
{
return
0
;
}
...
...
src/image/oci/storage/
container_store/container
_store.h
→
src/image/oci/storage/
rootfs_store/rootfs
_store.h
浏览文件 @
c92ab5d6
...
...
@@ -12,78 +12,78 @@
* Create: 2020-05-12
* Description: provide containers module interface definition
******************************************************************************/
#ifndef __OCI_STORAGE_
CONTAINER
_STORE_H
#define __OCI_STORAGE_
CONTAINER
_STORE_H
#ifndef __OCI_STORAGE_
ROOTFS
_STORE_H
#define __OCI_STORAGE_
ROOTFS
_STORE_H
#include <stdbool.h>
#include <string.h>
#include <pthread.h>
#include "storage.h"
#include "
container
.h"
#include "
rootfs
.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// Load the containers in the folder(${driver}-containers)
int
container
_store_init
(
struct
storage_module_init_options
*
opts
);
int
rootfs
_store_init
(
struct
storage_module_init_options
*
opts
);
// Creates a container that has a specified ID (or generates a random one if an empty value is supplied)
// and optional names, based on the specified image, using the specified layer as its read-write layer.
// return a new id, or NULL if failed.
char
*
container
_store_create
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
,
const
char
*
image
,
const
char
*
layer
,
const
char
*
metadata
,
struct
storage_container_options
*
container
_opts
);
char
*
rootfs
_store_create
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
,
const
char
*
image
,
const
char
*
layer
,
const
char
*
metadata
,
struct
storage_rootfs_options
*
rootfs
_opts
);
// Attempt to translate a name to an ID. Most methods do this implicitly.
char
*
container
_store_lookup
(
const
char
*
id
);
char
*
rootfs
_store_lookup
(
const
char
*
id
);
// Remove the record of the container.
int
container
_store_delete
(
const
char
*
id
);
int
rootfs
_store_delete
(
const
char
*
id
);
// Remove records of all containers
int
container
_store_wipe
();
int
rootfs
_store_wipe
();
// Stores a (potentially large) piece of data associated with this ID.
int
container
_store_set_big_data
(
const
char
*
id
,
const
char
*
key
,
const
char
*
data
);
int
rootfs
_store_set_big_data
(
const
char
*
id
,
const
char
*
key
,
const
char
*
data
);
// Replace the list of names associated with a container with the supplied values.
int
container
_store_set_names
(
const
char
*
id
,
const
char
**
names
,
size_t
names_len
);
int
rootfs
_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
container
_store_set_metadata
(
const
char
*
id
,
const
char
*
metadata
);
int
rootfs
_store_set_metadata
(
const
char
*
id
,
const
char
*
metadata
);
// Saves the contents of the store to disk.
int
container_store_save
(
cntr
_t
*
c
);
int
rootfs_store_save
(
cntrootfs
_t
*
c
);
// Check if there is a container with the given ID or name.
bool
container
_store_exists
(
const
char
*
id
);
bool
rootfs
_store_exists
(
const
char
*
id
);
// Retrieve information about a container given an ID or name.
cntr
_t
*
container_store_get_container
(
const
char
*
id
);
cntr
ootfs_t
*
rootfs_store_get_rootfs
(
const
char
*
id
);
// Retrieves a (potentially large) piece of data associated with this ID, if it has previously been set.
char
*
container
_store_big_data
(
const
char
*
id
,
const
char
*
key
);
char
*
rootfs
_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
container
_store_big_data_size
(
const
char
*
id
,
const
char
*
key
);
int64_t
rootfs
_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.
char
*
container
_store_big_data_digest
(
const
char
*
id
,
const
char
*
key
);
char
*
rootfs
_store_big_data_digest
(
const
char
*
id
,
const
char
*
key
);
// Returns a list of the names of previously-stored pieces of data.
int
container
_store_big_data_names
(
const
char
*
id
,
char
***
names
,
size_t
*
names_len
);
int
rootfs
_store_big_data_names
(
const
char
*
id
,
char
***
names
,
size_t
*
names_len
);
// Reads metadata associated with an item with the specified ID.
char
*
container
_store_metadata
(
const
char
*
id
);
char
*
rootfs
_store_metadata
(
const
char
*
id
);
// Return a slice enumerating the known containers.
int
container_store_get_all_containers
(
cntr
_t
*
containers
,
size_t
*
len
);
int
rootfs_store_get_all_rootfs
(
cntrootfs
_t
*
containers
,
size_t
*
len
);
// Free memory of container store, but will not delete the persisted files
void
container
_store_free
();
void
rootfs
_store_free
();
#ifdef __cplusplus
}
#endif
#endif
/* __OCI_STORAGE_
CONTAINER
_STORE_H */
#endif
/* __OCI_STORAGE_
ROOTFS
_STORE_H */
src/image/oci/storage/storage.h
浏览文件 @
c92ab5d6
...
...
@@ -82,7 +82,7 @@ struct id_mapping_options {
size_t
gid_map_len
;
};
struct
storage_
container
_options
{
struct
storage_
rootfs
_options
{
struct
id_mapping_options
id_mapping_opts
;
char
**
label_opts
;
size_t
label_opts_len
;
...
...
src/json/schema/schema/storage/
container
.json
→
src/json/schema/schema/storage/
rootfs
.json
浏览文件 @
c92ab5d6
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录