Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
b8770356
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,发现更多精彩内容 >>
提交
b8770356
编写于
5月 09, 2020
作者:
H
haozi007
提交者:
lifeng68
7月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor digest store
Signed-off-by:
N
haozi007
<
liuhao27@huawei.com
>
上级
1de52502
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
119 addition
and
73 deletion
+119
-73
src/image/oci/storage/layer_store/layer_store.c
src/image/oci/storage/layer_store/layer_store.c
+119
-73
未找到文件。
src/image/oci/storage/layer_store/layer_store.c
浏览文件 @
b8770356
...
@@ -42,6 +42,11 @@ typedef struct __layer_store_metadata_t {
...
@@ -42,6 +42,11 @@ typedef struct __layer_store_metadata_t {
size_t
layers_list_len
;
size_t
layers_list_len
;
}
layer_store_metadata
;
}
layer_store_metadata
;
typedef
struct
digest_layer
{
struct
linked_list
layer_list
;
size_t
layer_list_len
;
}
digest_layer_t
;
static
layer_store_metadata
g_metadata
;
static
layer_store_metadata
g_metadata
;
static
char
*
g_root_dir
;
static
char
*
g_root_dir
;
static
char
*
g_run_dir
;
static
char
*
g_run_dir
;
...
@@ -50,9 +55,11 @@ static inline char *tar_split_path(const char *id);
...
@@ -50,9 +55,11 @@ static inline char *tar_split_path(const char *id);
static
inline
char
*
mountpoint_json_path
(
const
char
*
id
);
static
inline
char
*
mountpoint_json_path
(
const
char
*
id
);
static
inline
char
*
layer_json_path
(
const
char
*
id
);
static
inline
char
*
layer_json_path
(
const
char
*
id
);
static
int
insert_digest_into_map
(
map_t
*
by_digest
,
const
char
*
digest
,
const
char
*
id
);
static
int
delete_digest_from_map
(
map_t
*
by_digest
,
const
char
*
digest
,
const
char
*
id
);
static
bool
remove_name
(
const
char
*
name
);
static
bool
remove_name
(
const
char
*
name
);
static
void
recover_name
(
const
char
*
name
);
static
void
recover_name
(
const
char
*
name
);
static
int
update_digest_map
(
map_t
*
by_digest
,
const
char
*
old_val
,
const
char
*
new_val
,
const
char
*
id
);
static
inline
bool
layer_store_lock
(
bool
writable
)
static
inline
bool
layer_store_lock
(
bool
writable
)
{
{
...
@@ -87,18 +94,28 @@ void layer_store_cleanup()
...
@@ -87,18 +94,28 @@ void layer_store_cleanup()
struct
linked_list
*
next
=
NULL
;
struct
linked_list
*
next
=
NULL
;
map_free
(
g_metadata
.
by_id
);
map_free
(
g_metadata
.
by_id
);
g_metadata
.
by_id
=
NULL
;
map_free
(
g_metadata
.
by_name
);
map_free
(
g_metadata
.
by_name
);
g_metadata
.
by_name
=
NULL
;
map_free
(
g_metadata
.
by_compress_digest
);
map_free
(
g_metadata
.
by_compress_digest
);
g_metadata
.
by_compress_digest
=
NULL
;
map_free
(
g_metadata
.
by_uncompress_digest
);
map_free
(
g_metadata
.
by_uncompress_digest
);
g_metadata
.
by_uncompress_digest
=
NULL
;
linked_list_for_each_safe
(
item
,
&
(
g_metadata
.
layers_list
),
next
)
{
linked_list_for_each_safe
(
item
,
&
(
g_metadata
.
layers_list
),
next
)
{
linked_list_del
(
item
);
linked_list_del
(
item
);
layer_ref_dec
((
layer_t
*
)
item
->
elem
);
layer_ref_dec
((
layer_t
*
)
item
->
elem
);
free
(
item
);
free
(
item
);
item
=
NULL
;
}
}
g_metadata
.
layers_list_len
=
0
;
g_metadata
.
layers_list_len
=
0
;
pthread_rwlock_destroy
(
&
(
g_metadata
.
rwlock
));
pthread_rwlock_destroy
(
&
(
g_metadata
.
rwlock
));
free
(
g_run_dir
);
g_run_dir
=
NULL
;
free
(
g_root_dir
);
g_root_dir
=
NULL
;
}
}
/* layers map kvfree */
/* layers map kvfree */
...
@@ -107,11 +124,33 @@ static void layer_map_kvfree(void *key, void *value)
...
@@ -107,11 +124,33 @@ static void layer_map_kvfree(void *key, void *value)
free
(
key
);
free
(
key
);
}
}
static
void
free_digest_layer_t
(
digest_layer_t
*
ptr
)
{
struct
linked_list
*
item
=
NULL
;
struct
linked_list
*
next
=
NULL
;
if
(
ptr
==
NULL
)
{
return
;
}
linked_list_for_each_safe
(
item
,
&
(
ptr
->
layer_list
),
next
)
{
linked_list_del
(
item
);
free
(
item
->
elem
);
item
->
elem
=
NULL
;
free
(
item
);
item
=
NULL
;
}
ptr
->
layer_list_len
=
0
;
free
(
ptr
);
}
static
void
digest_map_kvfree
(
void
*
key
,
void
*
value
)
static
void
digest_map_kvfree
(
void
*
key
,
void
*
value
)
{
{
free
(
key
)
;
digest_layer_t
*
val
=
(
digest_layer_t
*
)
value
;
util_free_array
((
char
**
)
value
);
free
(
key
);
free_digest_layer_t
(
val
);
}
}
static
inline
void
insert_g_layer_list_item
(
struct
linked_list
*
item
)
static
inline
void
insert_g_layer_list_item
(
struct
linked_list
*
item
)
...
@@ -302,43 +341,39 @@ static int load_layers_from_json_files()
...
@@ -302,43 +341,39 @@ static int load_layers_from_json_files()
}
}
if
(
!
map_insert
(
g_metadata
.
by_name
,
(
void
*
)
tl
->
slayer
->
names
[
i
],
(
void
*
)
tl
))
{
if
(
!
map_insert
(
g_metadata
.
by_name
,
(
void
*
)
tl
->
slayer
->
names
[
i
],
(
void
*
)
tl
))
{
ERROR
(
"Insert name: %s for layer failed"
,
tl
->
slayer
->
names
[
i
]);
ERROR
(
"Insert name: %s for layer failed"
,
tl
->
slayer
->
names
[
i
]);
goto
err
_out
;
goto
unlock
_out
;
}
}
}
}
ret
=
update_digest_map
(
g_metadata
.
by_compress_digest
,
NULL
,
tl
->
slayer
->
compressed_diff_digest
,
tl
->
slayer
->
id
);
ret
=
insert_digest_into_map
(
g_metadata
.
by_compress_digest
,
tl
->
slayer
->
compressed_diff_digest
,
tl
->
slayer
->
id
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
ERROR
(
"update layer: %s compress failed"
,
tl
->
slayer
->
id
);
ERROR
(
"update layer: %s compress failed"
,
tl
->
slayer
->
id
);
goto
err
_out
;
goto
unlock
_out
;
}
}
ret
=
update_digest_map
(
g_metadata
.
by_uncompress_digest
,
NULL
,
tl
->
slayer
->
diff_digest
,
tl
->
slayer
->
id
);
ret
=
insert_digest_into_map
(
g_metadata
.
by_uncompress_digest
,
tl
->
slayer
->
diff_digest
,
tl
->
slayer
->
id
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
ERROR
(
"update layer: %s uncompress failed"
,
tl
->
slayer
->
id
);
ERROR
(
"update layer: %s uncompress failed"
,
tl
->
slayer
->
id
);
goto
err
_out
;
goto
unlock
_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
);
ERROR
(
"delete layer: %s failed"
,
tl
->
slayer
->
id
);
goto
err
_out
;
goto
unlock
_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
);
ERROR
(
"save layer: %s failed"
,
tl
->
slayer
->
id
);
goto
err
_out
;
goto
unlock
_out
;
}
}
}
}
ret
=
0
;
ret
=
0
;
goto
unlock_out
;
goto
unlock_out
;
err_out:
// clear memory store
layer_store_cleanup
();
ret
=
-
1
;
unlock_out:
unlock_out:
layer_store_unlock
();
layer_store_unlock
();
return
ret
;
return
ret
;
...
@@ -643,70 +678,78 @@ free_out:
...
@@ -643,70 +678,78 @@ free_out:
return
ret
;
return
ret
;
}
}
static
int
update_digest_map
(
map_t
*
by_digest
,
const
char
*
old_val
,
const
char
*
new_val
,
const
char
*
id
)
static
int
delete_digest_from_map
(
map_t
*
by_digest
,
const
char
*
digest
,
const
char
*
id
)
{
{
char
**
old_list
=
NULL
;
digest_layer_t
*
old_list
=
NULL
;
size_t
old_len
=
0
;
struct
linked_list
*
item
=
NULL
;
int
ret
=
0
;
struct
linked_list
*
next
=
NULL
;
size_t
i
=
0
;
if
(
new_val
!=
NULL
)
{
char
**
tmp_new_list
=
NULL
;
char
**
new_list
=
(
char
**
)
map_search
(
by_digest
,
(
void
*
)
new_val
);
size_t
new_len
=
util_array_len
((
const
char
**
)
new_list
);
tmp_new_list
=
util_smart_calloc_s
(
sizeof
(
char
*
),
new_len
+
2
);
if
(
digest
==
NULL
)
{
if
(
tmp_new_list
==
NULL
)
{
return
0
;
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
}
for
(
i
=
0
;
i
<
new_len
;
i
++
)
{
tmp_new_list
[
new_len
]
=
new_list
[
i
];
old_list
=
(
digest_layer_t
*
)
map_search
(
by_digest
,
(
void
*
)
digest
);
new_list
[
i
]
=
NULL
;
if
(
old_list
==
NULL
)
{
return
0
;
}
}
tmp_new_list
[
new_len
]
=
util_strdup_s
(
id
);
if
(
!
map_replace
(
by_digest
,
(
void
*
)
new_val
,
(
void
*
)
tmp_new_list
))
{
linked_list_for_each_safe
(
item
,
&
(
old_list
->
layer_list
),
next
)
{
ERROR
(
"Insert new digest failed"
);
char
*
t_id
=
(
char
*
)
item
->
elem
;
// recover new list
if
(
strcmp
(
t_id
,
id
)
==
0
)
{
for
(
i
=
0
;
i
<
new_len
;
i
++
)
{
linked_list_del
(
item
);
new_list
[
i
]
=
tmp_new_list
[
i
];
free
(
item
->
elem
);
free
(
item
);
item
=
NULL
;
old_list
->
layer_list_len
-=
1
;
break
;
}
}
free
(
tmp_new_list
[
new_len
]);
free
(
tmp_new_list
);
ret
=
-
1
;
goto
out
;
}
}
if
(
old_list
->
layer_list_len
==
0
&&
!
map_remove
(
by_digest
,
(
void
*
)
digest
))
{
WARN
(
"Remove old failed"
);
}
}
if
(
old_val
!=
NULL
)
{
return
0
;
size_t
idx
=
0
;
}
size_t
new_len
;
old_list
=
(
char
**
)
map_search
(
by_digest
,
(
void
*
)
old_val
);
old_len
=
util_array_len
((
const
char
**
)
old_list
);
new_len
=
old_len
;
for
(;
idx
<
old_len
;
idx
++
)
{
static
int
insert_digest_into_map
(
map_t
*
by_digest
,
const
char
*
digest
,
const
char
*
id
)
if
(
strcmp
(
old_list
[
idx
],
id
)
==
0
)
{
{
new_len
--
;
digest_layer_t
*
old_list
=
NULL
;
free
(
old_list
[
idx
]);
struct
linked_list
*
item
=
NULL
;
old_list
[
idx
]
=
NULL
;
digest_layer_t
*
new_list
=
NULL
;
break
;
if
(
digest
==
NULL
)
{
INFO
(
"Layer: %s with empty digest"
,
id
);
return
0
;
}
}
old_list
=
(
digest_layer_t
*
)
map_search
(
by_digest
,
(
void
*
)
digest
);
if
(
old_list
==
NULL
)
{
new_list
=
(
digest_layer_t
*
)
util_common_calloc_s
(
sizeof
(
digest_layer_t
));
if
(
new_list
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
}
for
(
idx
=
idx
+
1
;
idx
<
old_len
;
idx
++
)
{
old_list
=
new_list
;
old_list
[
idx
-
1
]
=
old_list
[
idx
];
old_list
[
idx
]
=
NULL
;
}
}
if
(
new_len
==
0
&&
!
map_remove
(
by_digest
,
(
void
*
)
old_val
))
{
item
=
(
struct
linked_list
*
)
util_common_calloc_s
(
sizeof
(
struct
linked_list
));
WARN
(
"Remove old failed"
);
if
(
item
==
NULL
)
{
ERROR
(
"Out of memory"
);
goto
free_out
;
}
}
linked_list_add_elem
(
item
,
(
void
*
)
util_strdup_s
(
id
));
linked_list_add_tail
(
&
(
old_list
->
layer_list
),
item
);
old_list
->
layer_list_len
+=
1
;
if
(
!
map_replace
(
by_digest
,
(
void
*
)
digest
,
(
void
*
)
old_list
))
{
goto
free_out
;
}
}
out:
return
0
;
return
ret
;
free_out:
free_digest_layer_t
(
new_list
);
return
-
1
;
}
}
static
int
remove_memory_stores
(
const
char
*
id
)
static
int
remove_memory_stores
(
const
char
*
id
)
...
@@ -723,12 +766,12 @@ static int remove_memory_stores(const char *id)
...
@@ -723,12 +766,12 @@ static int remove_memory_stores(const char *id)
return
-
1
;
return
-
1
;
}
}
if
(
update_digest_map
(
g_metadata
.
by_compress_digest
,
l
->
slayer
->
compressed_diff_digest
,
NULL
,
l
->
slayer
->
id
)
!=
0
)
{
if
(
delete_digest_from_map
(
g_metadata
.
by_compress_digest
,
l
->
slayer
->
compressed_diff_digest
,
l
->
slayer
->
id
)
!=
0
)
{
ERROR
(
"Remove %s from compress digest failed"
,
id
);
ERROR
(
"Remove %s from compress digest failed"
,
id
);
ret
=
-
1
;
ret
=
-
1
;
goto
out
;
goto
out
;
}
}
if
(
update_digest_map
(
g_metadata
.
by_uncompress_digest
,
l
->
slayer
->
diff_digest
,
NULL
,
l
->
slayer
->
id
)
!=
0
)
{
if
(
delete_digest_from_map
(
g_metadata
.
by_uncompress_digest
,
l
->
slayer
->
diff_digest
,
l
->
slayer
->
id
)
!=
0
)
{
// ignore this error, because only happen at out of memory;
// ignore this error, because only happen at out of memory;
// we cannot to recover before operator, so just go on.
// we cannot to recover before operator, so just go on.
WARN
(
"Remove %s from uncompress failed"
,
id
);
WARN
(
"Remove %s from uncompress failed"
,
id
);
...
@@ -811,6 +854,8 @@ static int apply_diff(const char *id, const struct io_read_wrapper *diff)
...
@@ -811,6 +854,8 @@ static int apply_diff(const char *id, const struct io_read_wrapper *diff)
INFO
(
"Apply layer get size: %lld"
,
size
);
INFO
(
"Apply layer get size: %lld"
,
size
);
// TODO: save split tar
return
ret
;
return
ret
;
}
}
...
@@ -901,19 +946,20 @@ static int layer_store_remove_layer(const char *id)
...
@@ -901,19 +946,20 @@ static int layer_store_remove_layer(const char *id)
{
{
char
*
rpath
=
NULL
;
char
*
rpath
=
NULL
;
int
ret
=
0
;
int
ret
=
0
;
int
nret
=
0
;
if
(
id
==
NULL
)
{
if
(
id
==
NULL
)
{
return
0
;
return
0
;
}
}
rpath
=
layer_json_path
(
id
);
nret
=
asprintf
(
&
rpath
,
"%s/%s"
,
g_root_dir
,
id
);
if
(
rpath
==
NULL
)
{
if
(
nret
<
0
||
nret
>
PATH_MAX
)
{
WARN
(
"Generate rpath for layer %s failed, jsut ignore"
,
id
);
SYSERROR
(
"Create layer json path failed"
);
return
0
;
return
-
1
;
}
}
ret
=
util_path_remove
(
rpath
);
ret
=
util_path_remove
(
rpath
);
free
(
rpath
);
free
(
rpath
);
return
ret
;
return
ret
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录