Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
07190f90
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,发现更多精彩内容 >>
提交
07190f90
编写于
5月 15, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rootfs: add get container rootfs usage info interface
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
0f31d041
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
172 addition
and
11 deletion
+172
-11
src/image/image.c
src/image/image.c
+2
-0
src/image/oci/oci_image.c
src/image/oci/oci_image.c
+13
-11
src/image/oci/storage/layer_store/graphdriver/driver.c
src/image/oci/storage/layer_store/graphdriver/driver.c
+16
-0
src/image/oci/storage/layer_store/graphdriver/driver.h
src/image/oci/storage/layer_store/graphdriver/driver.h
+4
-0
src/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
...torage/layer_store/graphdriver/overlay2/driver_overlay2.c
+97
-0
src/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
...torage/layer_store/graphdriver/overlay2/driver_overlay2.h
+2
-0
src/image/oci/storage/layer_store/layer_store.c
src/image/oci/storage/layer_store/layer_store.c
+5
-0
src/image/oci/storage/layer_store/layer_store.h
src/image/oci/storage/layer_store/layer_store.h
+2
-0
src/image/oci/storage/storage.c
src/image/oci/storage/storage.c
+29
-0
src/image/oci/storage/storage.h
src/image/oci/storage/storage.h
+2
-0
未找到文件。
src/image/image.c
浏览文件 @
07190f90
...
...
@@ -367,10 +367,12 @@ int im_get_container_filesystem_usage(const char *image_type, const char *id, im
}
*
fs_usage
=
filesystemusage
;
filesystemusage
=
NULL
;
EVENT
(
"Event: {Object: container
\'
%s
\'
filesystem info, Type: inspected}"
,
id
!=
NULL
?
id
:
""
);
out:
free_im_container_fs_usage_request
(
request
);
free_imagetool_fs_info
(
filesystemusage
);
return
ret
;
}
...
...
src/image/oci/oci_image.c
浏览文件 @
07190f90
...
...
@@ -296,30 +296,32 @@ out:
int
oci_container_filesystem_usage
(
const
im_container_fs_usage_request
*
request
,
imagetool_fs_info
**
fs_usage
)
{
int
ret
=
0
;
char
*
output
=
NULL
;
parser_error
err
=
NULL
;
imagetool_fs_info
*
layer_fs_tmp
=
NULL
;
if
(
request
==
NULL
||
fs_usage
==
NULL
)
{
ERROR
(
"Invalid input arguments"
);
return
-
1
;
}
// TODO call storage container fs interface
// ret = isula_container_fs_usage(request->name_id, &output);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to inspect container filesystem info"
)
;
layer_fs_tmp
=
util_common_calloc_s
(
sizeof
(
imagetool_fs_info
));
if
(
layer_fs_tmp
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
out
;
}
*
fs_usage
=
imagetool_fs_info_parse_data
(
output
,
NULL
,
&
err
);
if
(
*
fs_usage
==
NULL
)
{
ERROR
(
"Failed to parse output json: %s"
,
err
);
isulad_set_error_message
(
"Failed to parse output json:%s"
,
err
);
ret
=
storage_rootfs_fs_usgae
(
request
->
name_id
,
layer_fs_tmp
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to inspect container filesystem info"
);
ret
=
-
1
;
goto
out
;
}
*
fs_usage
=
layer_fs_tmp
;
layer_fs_tmp
=
NULL
;
out:
free
(
output
);
free
_imagetool_fs_info
(
layer_fs_tmp
);
return
ret
;
}
...
...
src/image/oci/storage/layer_store/graphdriver/driver.c
浏览文件 @
07190f90
...
...
@@ -47,6 +47,7 @@ static const struct graphdriver_ops g_overlay2_ops = {
.
get_driver_status
=
overlay2_get_driver_status
,
.
clean_up
=
overlay2_clean_up
,
.
try_repair_lowers
=
overlay2_repair_lowers
,
.
get_layer_fs_info
=
overlay2_get_layer_fs_info
,
};
/* devicemapper */
...
...
@@ -369,3 +370,18 @@ int graphdriver_try_repair_lowers(const char *id, const char *parent)
return
g_graphdriver
->
ops
->
try_repair_lowers
(
id
,
parent
,
g_graphdriver
);
}
int
graphdriver_get_layer_fs_info
(
const
char
*
id
,
imagetool_fs_info
*
fs_info
)
{
if
(
g_graphdriver
==
NULL
)
{
ERROR
(
"Driver not inited yet"
);
return
-
1
;
}
if
(
id
==
NULL
||
fs_info
==
NULL
)
{
ERROR
(
"Invalid input arguments for driver get layer info"
);
return
-
1
;
}
return
g_graphdriver
->
ops
->
get_layer_fs_info
(
id
,
g_graphdriver
,
fs_info
);
}
\ No newline at end of file
src/image/oci/storage/layer_store/graphdriver/driver.h
浏览文件 @
07190f90
...
...
@@ -71,6 +71,8 @@ struct graphdriver_ops {
int
(
*
clean_up
)(
const
struct
graphdriver
*
driver
);
int
(
*
try_repair_lowers
)(
const
char
*
id
,
const
char
*
parent
,
const
struct
graphdriver
*
driver
);
int
(
*
get_layer_fs_info
)(
const
char
*
id
,
const
struct
graphdriver
*
driver
,
imagetool_fs_info
*
fs_info
);
};
struct
graphdriver
{
...
...
@@ -116,6 +118,8 @@ int graphdriver_try_repair_lowers(const char *id, const char *parent);
container_inspect_graph_driver
*
graphdriver_get_metadata
(
const
char
*
id
);
int
graphdriver_get_layer_fs_info
(
const
char
*
id
,
imagetool_fs_info
*
fs_info
);
#ifdef __cplusplus
}
#endif
...
...
src/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
浏览文件 @
07190f90
...
...
@@ -1845,3 +1845,100 @@ out:
free
(
lowers_repaired
);
return
ret
;
}
static
int
do_cal_layer_fs_info
(
const
char
*
layer_diff
,
imagetool_fs_info
*
fs_info
)
{
int
ret
=
0
;
imagetool_fs_info_image_filesystems_element
*
fs_usage_tmp
=
NULL
;
int64_t
total_size
=
0
;
int64_t
total_inodes
=
0
;
fs_usage_tmp
=
util_common_calloc_s
(
sizeof
(
imagetool_fs_info_image_filesystems_element
));
if
(
fs_usage_tmp
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
out
;
}
fs_usage_tmp
->
timestamp
=
get_now_time_nanos
();
fs_usage_tmp
->
fs_id
=
util_common_calloc_s
(
sizeof
(
imagetool_fs_info_image_filesystems_fs_id
));
if
(
fs_usage_tmp
->
fs_id
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
out
;
}
fs_usage_tmp
->
fs_id
->
mountpoint
=
util_strdup_s
(
layer_diff
);
util_calculate_dir_size
(
layer_diff
,
0
,
&
total_size
,
&
total_inodes
);
fs_usage_tmp
->
inodes_used
=
util_common_calloc_s
(
sizeof
(
imagetool_fs_info_image_filesystems_inodes_used
));
if
(
fs_usage_tmp
->
inodes_used
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
out
;
}
fs_usage_tmp
->
inodes_used
->
value
=
total_inodes
;
fs_usage_tmp
->
used_bytes
=
util_common_calloc_s
(
sizeof
(
imagetool_fs_info_image_filesystems_used_bytes
));
if
(
fs_usage_tmp
->
used_bytes
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
out
;
}
fs_usage_tmp
->
used_bytes
->
value
=
total_size
;
fs_info
->
image_filesystems
=
util_common_calloc_s
(
sizeof
(
imagetool_fs_info_image_filesystems_element
*
));
if
(
fs_info
->
image_filesystems
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
out
;
}
fs_info
->
image_filesystems
[
0
]
=
fs_usage_tmp
;
fs_usage_tmp
=
NULL
;
fs_info
->
image_filesystems_len
=
1
;
out:
free_imagetool_fs_info_image_filesystems_element
(
fs_usage_tmp
);
return
ret
;
}
int
overlay2_get_layer_fs_info
(
const
char
*
id
,
const
struct
graphdriver
*
driver
,
imagetool_fs_info
*
fs_info
)
{
int
ret
=
0
;
char
*
layer_dir
=
NULL
;
char
*
layer_diff
=
NULL
;
if
(
id
==
NULL
||
fs_info
==
NULL
)
{
return
-
1
;
}
layer_dir
=
util_path_join
(
driver
->
home
,
id
);
if
(
layer_dir
==
NULL
)
{
ERROR
(
"Failed to join layer dir:%s"
,
id
);
goto
out
;
}
if
(
!
util_dir_exists
(
layer_dir
))
{
SYSERROR
(
"layer dir %s not exist"
,
layer_dir
);
goto
out
;
}
layer_diff
=
util_path_join
(
layer_dir
,
OVERLAY_LAYER_DIFF
);
if
(
layer_diff
==
NULL
)
{
ERROR
(
"Failed to join layer diff dir:%s"
,
id
);
ret
=
-
1
;
goto
out
;
}
if
(
do_cal_layer_fs_info
(
layer_diff
,
fs_info
)
!=
0
)
{
ERROR
(
"Failed to cal layer diff :%s fs info"
,
layer_diff
);
ret
=
-
1
;
goto
out
;
}
out:
free
(
layer_dir
);
free
(
layer_diff
);
return
ret
;
}
\ No newline at end of file
src/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
浏览文件 @
07190f90
...
...
@@ -55,6 +55,8 @@ void free_driver_mount_opts(struct driver_mount_opts *opts);
int
overlay2_repair_lowers
(
const
char
*
id
,
const
char
*
parent
,
const
struct
graphdriver
*
driver
);
int
overlay2_get_layer_fs_info
(
const
char
*
id
,
const
struct
graphdriver
*
driver
,
imagetool_fs_info
*
fs_info
);
#ifdef __cplusplus
}
#endif
...
...
src/image/oci/storage/layer_store/layer_store.c
浏览文件 @
07190f90
...
...
@@ -1634,3 +1634,8 @@ void free_layer_store_mount_opts(struct layer_store_mount_opts *ptr)
ptr
->
mount_opts
=
NULL
;
free
(
ptr
);
}
int
layer_store_get_layer_fs_info
(
const
char
*
layer_id
,
imagetool_fs_info
*
fs_info
)
{
return
graphdriver_get_layer_fs_info
(
layer_id
,
fs_info
);
}
src/image/oci/storage/layer_store/layer_store.h
浏览文件 @
07190f90
...
...
@@ -64,6 +64,8 @@ int layer_store_try_repair_lowers(const char *id);
void
free_layer_store_mount_opts
(
struct
layer_store_mount_opts
*
ptr
);
void
free_layer_opts
(
struct
layer_opts
*
opts
);
int
layer_store_get_layer_fs_info
(
const
char
*
layer_id
,
imagetool_fs_info
*
fs_info
);
#ifdef __cplusplus
}
#endif
...
...
src/image/oci/storage/storage.c
浏览文件 @
07190f90
...
...
@@ -1025,3 +1025,32 @@ out:
free_storage_rootfs
(
rootfs_info
);
return
ret
;
}
int
storage_rootfs_fs_usgae
(
const
char
*
container_id
,
imagetool_fs_info
*
fs_info
)
{
int
ret
=
0
;
storage_rootfs
*
rootfs_info
=
NULL
;
if
(
container_id
==
NULL
||
fs_info
==
NULL
)
{
ERROR
(
"Invalid input arguments"
);
ret
=
-
1
;
goto
out
;
}
rootfs_info
=
rootfs_store_get_rootfs
(
container_id
);
if
(
rootfs_info
==
NULL
)
{
ERROR
(
"Failed to get rootfs %s info"
,
container_id
);
ret
=
-
1
;
goto
out
;
}
if
(
layer_store_get_layer_fs_info
(
rootfs_info
->
layer
,
fs_info
)
!=
0
)
{
ERROR
(
"Failed to get layer %s fs usgae info"
,
rootfs_info
->
layer
);
ret
=
-
1
;
goto
out
;
}
out:
free_storage_rootfs
(
rootfs_info
);
return
ret
;
}
src/image/oci/storage/storage.h
浏览文件 @
07190f90
...
...
@@ -154,6 +154,8 @@ int storage_rootfs_create(const char *container_id, const char *image, json_map_
int
storage_rootfs_delete
(
const
char
*
container_id
);
int
storage_rootfs_fs_usgae
(
const
char
*
container_id
,
imagetool_fs_info
*
fs_info
);
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录