Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
7d0a82f5
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,发现更多精彩内容 >>
提交
7d0a82f5
编写于
9月 04, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
blkio: add support blk read/write iops
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
d1c33623
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
857 addition
and
533 deletion
+857
-533
src/client/connect/pack_config.c
src/client/connect/pack_config.c
+164
-22
src/client/libisula.c
src/client/libisula.c
+19
-0
src/client/libisula.h
src/client/libisula.h
+6
-0
src/cmd/isula/base/create.c
src/cmd/isula/base/create.c
+20
-0
src/cmd/isula/base/create.h
src/cmd/isula/base/create.h
+417
-403
src/cmd/isula/client_arguments.c
src/cmd/isula/client_arguments.c
+12
-0
src/cmd/isula/client_arguments.h
src/cmd/isula/client_arguments.h
+6
-0
src/daemon/modules/spec/specs_mount.c
src/daemon/modules/spec/specs_mount.c
+146
-75
src/daemon/modules/spec/verify.c
src/daemon/modules/spec/verify.c
+30
-31
src/utils/cutils/utils_convert.c
src/utils/cutils/utils_convert.c
+23
-1
src/utils/cutils/utils_convert.h
src/utils/cutils/utils_convert.h
+1
-1
src/utils/cutils/utils_verify.c
src/utils/cutils/utils_verify.c
+11
-0
src/utils/cutils/utils_verify.h
src/utils/cutils/utils_verify.h
+2
-0
未找到文件。
src/client/connect/pack_config.c
浏览文件 @
7d0a82f5
...
...
@@ -797,7 +797,7 @@ erro_out:
return
NULL
;
}
static
int
parse_blkio_throttle_bps_device
(
const
char
*
device
,
char
**
path
,
const
uint64_t
*
rate
)
static
int
parse_blkio_throttle_bps_device
(
const
char
*
device
,
char
**
path
,
uint64_t
*
rate
)
{
int
ret
=
0
;
char
**
split
=
NULL
;
...
...
@@ -862,6 +862,80 @@ error_out:
return
NULL
;
}
static
int
parse_blkio_throttle_iops_device
(
const
char
*
device
,
char
**
path
,
uint64_t
*
rate
)
{
int
ret
=
0
;
char
**
split
=
NULL
;
split
=
util_string_split_multi
(
device
,
':'
);
if
(
split
==
NULL
||
util_array_len
((
const
char
**
)
split
)
!=
2
)
{
COMMAND_ERROR
(
"bad format: %s"
,
device
);
ret
=
-
1
;
goto
out
;
}
if
(
strncmp
(
split
[
0
],
"/dev/"
,
strlen
(
"/dev/"
))
!=
0
)
{
COMMAND_ERROR
(
"bad format for device path: %s"
,
device
);
ret
=
-
1
;
goto
out
;
}
if
(
!
util_valid_positive_interger
(
split
[
1
]))
{
COMMAND_ERROR
(
"invalid rate for device: %s. The correct format is <device-path>:<number>."
" Number must be unsigned 64 bytes integer."
,
device
);
ret
=
-
1
;
goto
out
;
}
if
(
util_safe_uint64
(
split
[
1
],
rate
)
!=
0
)
{
COMMAND_ERROR
(
"invalid rate for device: %s. The correct format is <device-path>:<number>."
" Number must be unsigned 64 bytes integer."
,
device
);
ret
=
-
1
;
goto
out
;
}
*
path
=
util_strdup_s
(
split
[
0
]);
out:
util_free_array
(
split
);
return
ret
;
}
// validate that the specified string has a valid device-rate format.
static
defs_blkio_device
*
pack_throttle_iops_device
(
const
char
*
device
)
{
char
*
path
=
NULL
;
uint64_t
rate
=
0
;
defs_blkio_device
*
iops_dev
=
NULL
;
if
(
device
==
NULL
||
!
strcmp
(
device
,
""
))
{
COMMAND_ERROR
(
"blkio throttle read bps device can't be empty"
);
return
NULL
;
}
iops_dev
=
util_common_calloc_s
(
sizeof
(
defs_blkio_device
));
if
(
iops_dev
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
}
if
(
parse_blkio_throttle_iops_device
(
device
,
&
path
,
&
rate
)
!=
0
)
{
goto
error_out
;
}
iops_dev
->
path
=
path
;
iops_dev
->
rate
=
rate
;
return
iops_dev
;
error_out:
free
(
path
);
free_defs_blkio_device
(
iops_dev
);
return
NULL
;
}
static
int
split_hugetlb_limit
(
char
*
temp
,
char
**
pagesize
,
char
**
limit_value
)
{
int
ret
=
0
;
...
...
@@ -1387,18 +1461,13 @@ static int generate_blkio_weight_device(host_config **dstconfig, const isula_hos
goto
out
;
}
if
(
srcconfig
->
blkio_weight_device_len
>
SIZE_MAX
/
sizeof
(
defs_blkio_weight_device
*
))
{
ERROR
(
"Too many blkio weight devies to get!"
);
ret
=
-
1
;
goto
out
;
}
(
*
dstconfig
)
->
blkio_weight_device
=
util_
common_calloc_s
(
srcconfig
->
blkio_weight_device_len
*
sizeof
(
defs_blkio_weight_device
*
)
);
util_
smart_calloc_s
(
sizeof
(
defs_blkio_weight_device
*
),
srcconfig
->
blkio_weight_device_len
);
if
((
*
dstconfig
)
->
blkio_weight_device
==
NULL
)
{
ret
=
-
1
;
goto
out
;
}
for
(
i
=
0
;
i
<
srcconfig
->
blkio_weight_device_len
;
i
++
)
{
(
*
dstconfig
)
->
blkio_weight_device
[(
*
dstconfig
)
->
blkio_weight_device_len
]
=
pack_blkio_weight_devices
(
srcconfig
->
blkio_weight_device
[
i
]);
...
...
@@ -1427,18 +1496,13 @@ static int generate_blkio_throttle_read_bps_device(host_config **dstconfig, cons
goto
out
;
}
if
(
srcconfig
->
blkio_throttle_read_bps_device_len
>
SIZE_MAX
/
sizeof
(
defs_blkio_device
*
))
{
ERROR
(
"Too many blkio throttle read bps devies to get!"
);
ret
=
-
1
;
goto
out
;
}
(
*
dstconfig
)
->
blkio_device_read_bps
=
util_
common_calloc_s
(
srcconfig
->
blkio_throttle_read_bps_device_len
*
sizeof
(
defs_blkio_device
*
)
);
util_
smart_calloc_s
(
sizeof
(
defs_blkio_device
*
),
srcconfig
->
blkio_throttle_read_bps_device_len
);
if
((
*
dstconfig
)
->
blkio_device_read_bps
==
NULL
)
{
ret
=
-
1
;
goto
out
;
}
for
(
i
=
0
;
i
<
srcconfig
->
blkio_throttle_read_bps_device_len
;
i
++
)
{
(
*
dstconfig
)
->
blkio_device_read_bps
[(
*
dstconfig
)
->
blkio_device_read_bps_len
]
=
pack_throttle_bps_device
(
srcconfig
->
blkio_throttle_read_bps_device
[
i
]);
...
...
@@ -1467,18 +1531,13 @@ static int generate_blkio_throttle_write_bps_device(host_config **dstconfig, con
goto
out
;
}
if
(
srcconfig
->
blkio_throttle_write_bps_device_len
>
SIZE_MAX
/
sizeof
(
defs_blkio_device
*
))
{
ERROR
(
"Too many blkio throttle write bps devies to get!"
);
ret
=
-
1
;
goto
out
;
}
(
*
dstconfig
)
->
blkio_device_write_bps
=
util_
common_calloc_s
(
srcconfig
->
blkio_throttle_write_bps_device_len
*
sizeof
(
defs_blkio_device
*
)
);
util_
smart_calloc_s
(
sizeof
(
defs_blkio_device
*
),
srcconfig
->
blkio_throttle_write_bps_device_len
);
if
((
*
dstconfig
)
->
blkio_device_write_bps
==
NULL
)
{
ret
=
-
1
;
goto
out
;
}
for
(
i
=
0
;
i
<
srcconfig
->
blkio_throttle_write_bps_device_len
;
i
++
)
{
(
*
dstconfig
)
->
blkio_device_write_bps
[(
*
dstconfig
)
->
blkio_device_write_bps_len
]
=
pack_throttle_bps_device
(
srcconfig
->
blkio_throttle_write_bps_device
[
i
]);
...
...
@@ -1494,6 +1553,76 @@ out:
return
ret
;
}
static
int
generate_blkio_throttle_read_iops_device
(
host_config
**
dstconfig
,
const
isula_host_config_t
*
srcconfig
)
{
int
ret
=
0
;
size_t
i
=
0
;
if
(
dstconfig
==
NULL
||
*
dstconfig
==
NULL
)
{
goto
out
;
}
if
(
srcconfig
->
blkio_throttle_read_iops_device
==
NULL
||
srcconfig
->
blkio_throttle_read_iops_device_len
==
0
)
{
goto
out
;
}
(
*
dstconfig
)
->
blkio_device_read_iops
=
util_smart_calloc_s
(
sizeof
(
defs_blkio_device
*
),
srcconfig
->
blkio_throttle_read_iops_device_len
);
if
((
*
dstconfig
)
->
blkio_device_read_iops
==
NULL
)
{
ret
=
-
1
;
goto
out
;
}
for
(
i
=
0
;
i
<
srcconfig
->
blkio_throttle_read_iops_device_len
;
i
++
)
{
(
*
dstconfig
)
->
blkio_device_read_iops
[(
*
dstconfig
)
->
blkio_device_read_iops_len
]
=
pack_throttle_iops_device
(
srcconfig
->
blkio_throttle_read_iops_device
[
i
]);
if
((
*
dstconfig
)
->
blkio_device_read_iops
[(
*
dstconfig
)
->
blkio_device_read_iops_len
]
==
NULL
)
{
ERROR
(
"Failed to get blkio throttle read iops devices"
);
ret
=
-
1
;
goto
out
;
}
(
*
dstconfig
)
->
blkio_device_read_iops_len
++
;
}
out:
return
ret
;
}
static
int
generate_blkio_throttle_write_iops_device
(
host_config
**
dstconfig
,
const
isula_host_config_t
*
srcconfig
)
{
int
ret
=
0
;
size_t
i
=
0
;
if
(
dstconfig
==
NULL
||
*
dstconfig
==
NULL
)
{
goto
out
;
}
if
(
srcconfig
->
blkio_throttle_write_iops_device
==
NULL
||
srcconfig
->
blkio_throttle_write_iops_device_len
==
0
)
{
goto
out
;
}
(
*
dstconfig
)
->
blkio_device_write_iops
=
util_smart_calloc_s
(
sizeof
(
defs_blkio_device
*
),
srcconfig
->
blkio_throttle_write_iops_device_len
);
if
((
*
dstconfig
)
->
blkio_device_write_iops
==
NULL
)
{
ret
=
-
1
;
goto
out
;
}
for
(
i
=
0
;
i
<
srcconfig
->
blkio_throttle_write_iops_device_len
;
i
++
)
{
(
*
dstconfig
)
->
blkio_device_write_iops
[(
*
dstconfig
)
->
blkio_device_write_iops_len
]
=
pack_throttle_iops_device
(
srcconfig
->
blkio_throttle_write_iops_device
[
i
]);
if
((
*
dstconfig
)
->
blkio_device_write_iops
[(
*
dstconfig
)
->
blkio_device_write_iops_len
]
==
NULL
)
{
ERROR
(
"Failed to get blkio throttle write iops devices"
);
ret
=
-
1
;
goto
out
;
}
(
*
dstconfig
)
->
blkio_device_write_iops_len
++
;
}
out:
return
ret
;
}
static
int
generate_blkio
(
host_config
**
dstconfig
,
const
isula_host_config_t
*
srcconfig
)
{
int
ret
;
...
...
@@ -1503,6 +1632,7 @@ static int generate_blkio(host_config **dstconfig, const isula_host_config_t *sr
if
(
ret
<
0
)
{
goto
out
;
}
/* blkio throttle read bps devies */
ret
=
generate_blkio_throttle_read_bps_device
(
dstconfig
,
srcconfig
);
if
(
ret
<
0
)
{
...
...
@@ -1515,6 +1645,18 @@ static int generate_blkio(host_config **dstconfig, const isula_host_config_t *sr
goto
out
;
}
/* blkio throttle read iops devies */
ret
=
generate_blkio_throttle_read_iops_device
(
dstconfig
,
srcconfig
);
if
(
ret
<
0
)
{
goto
out
;
}
/* blkio throttle write iops devies */
ret
=
generate_blkio_throttle_write_iops_device
(
dstconfig
,
srcconfig
);
if
(
ret
<
0
)
{
goto
out
;
}
out:
return
ret
;
}
...
...
src/client/libisula.c
浏览文件 @
7d0a82f5
...
...
@@ -332,6 +332,25 @@ void isula_host_config_free(isula_host_config_t *hostconfig)
hostconfig
->
blkio_weight_device
=
NULL
;
hostconfig
->
blkio_weight_device_len
=
0
;
util_free_array_by_len
(
hostconfig
->
blkio_throttle_read_bps_device
,
hostconfig
->
blkio_throttle_read_bps_device_len
);
hostconfig
->
blkio_throttle_read_bps_device
=
NULL
;
hostconfig
->
blkio_throttle_read_bps_device_len
=
0
;
util_free_array_by_len
(
hostconfig
->
blkio_throttle_write_bps_device
,
hostconfig
->
blkio_throttle_write_bps_device_len
);
hostconfig
->
blkio_throttle_write_bps_device
=
NULL
;
hostconfig
->
blkio_throttle_write_bps_device_len
=
0
;
util_free_array_by_len
(
hostconfig
->
blkio_throttle_read_iops_device
,
hostconfig
->
blkio_throttle_read_iops_device_len
);
hostconfig
->
blkio_throttle_read_iops_device
=
NULL
;
hostconfig
->
blkio_throttle_read_iops_device_len
=
0
;
util_free_array_by_len
(
hostconfig
->
blkio_throttle_write_iops_device
,
hostconfig
->
blkio_throttle_write_iops_device_len
);
hostconfig
->
blkio_throttle_write_iops_device
=
NULL
;
hostconfig
->
blkio_throttle_write_iops_device_len
=
0
;
container_cgroup_resources_free
(
hostconfig
->
cr
);
hostconfig
->
cr
=
NULL
;
...
...
src/client/libisula.h
浏览文件 @
7d0a82f5
...
...
@@ -179,6 +179,12 @@ typedef struct isula_host_config {
char
**
blkio_throttle_write_bps_device
;
size_t
blkio_throttle_write_bps_device_len
;
char
**
blkio_throttle_read_iops_device
;
size_t
blkio_throttle_read_iops_device_len
;
char
**
blkio_throttle_write_iops_device
;
size_t
blkio_throttle_write_iops_device_len
;
bool
privileged
;
bool
system_container
;
char
**
ns_change_files
;
...
...
src/cmd/isula/base/create.c
浏览文件 @
7d0a82f5
...
...
@@ -875,11 +875,31 @@ static void request_pack_host_device_write_bps(const struct client_arguments *ar
}
}
static
void
request_pack_host_device_read_iops
(
const
struct
client_arguments
*
args
,
isula_host_config_t
*
hostconfig
)
{
if
(
args
->
custom_conf
.
blkio_throttle_read_iops_device
!=
NULL
)
{
hostconfig
->
blkio_throttle_read_iops_device_len
=
util_array_len
((
const
char
**
)(
args
->
custom_conf
.
blkio_throttle_read_iops_device
));
hostconfig
->
blkio_throttle_read_iops_device
=
args
->
custom_conf
.
blkio_throttle_read_iops_device
;
}
}
static
void
request_pack_host_device_write_iops
(
const
struct
client_arguments
*
args
,
isula_host_config_t
*
hostconfig
)
{
if
(
args
->
custom_conf
.
blkio_throttle_write_iops_device
!=
NULL
)
{
hostconfig
->
blkio_throttle_write_iops_device_len
=
util_array_len
((
const
char
**
)(
args
->
custom_conf
.
blkio_throttle_write_iops_device
));
hostconfig
->
blkio_throttle_write_iops_device
=
args
->
custom_conf
.
blkio_throttle_write_iops_device
;
}
}
static
void
request_pack_host_blockio
(
const
struct
client_arguments
*
args
,
isula_host_config_t
*
hostconfig
)
{
request_pack_host_weight_devices
(
args
,
hostconfig
);
request_pack_host_device_read_bps
(
args
,
hostconfig
);
request_pack_host_device_write_bps
(
args
,
hostconfig
);
request_pack_host_device_read_iops
(
args
,
hostconfig
);
request_pack_host_device_write_iops
(
args
,
hostconfig
);
}
static
void
request_pack_host_devices
(
const
struct
client_arguments
*
args
,
isula_host_config_t
*
hostconfig
)
...
...
src/cmd/isula/base/create.h
浏览文件 @
7d0a82f5
...
...
@@ -90,14 +90,14 @@ extern "C" {
"device-read-bps", \
0, \
&(cmdargs).custom_conf.blkio_throttle_read_bps_device, \
"Limit read rate (bytes per second) from a device (default [])
",
\
"Limit read rate (bytes per second) from a device (default [])
,format: <device-path>:<number>[<unit>], Number is a positive integer",
\
command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, \
false, \
"device-write-bps", \
0, \
&(cmdargs).custom_conf.blkio_throttle_write_bps_device, \
"Limit write rate (bytes per second) to a device (default [])
",
\
"Limit write rate (bytes per second) to a device (default [])
,format: <device-path>:<number>[<unit>], Number is a positive integer",
\
command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, \
false, \
...
...
@@ -428,7 +428,21 @@ extern "C" {
"blkio-weight-device", \
0, \
&(cmdargs).custom_conf.weight_devices, \
"Block IO weight (relative device weight) (default []), format: DEVICE_NAME:WEIGHT", \
"Block IO weight (relative device weight) (default []), format: DEVICE_NAME:WEIGHT, weight value between 10 and 1000, or 0 to disable (default 0)", \
command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, \
false, \
"device-read-iops", \
0, \
&(cmdargs).custom_conf.blkio_throttle_read_iops_device, \
"Limit read rate (IO per second) from a device (format: <device-path>:<number>),number is unsigned 64 bytes integer", \
command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, \
false, \
"device-write-iops", \
0, \
&(cmdargs).custom_conf.blkio_throttle_write_iops_device, \
"Limit write rate (IO per second) to a device (format: <device-path>:<number>),number is unsigned 64 bytes integer.", \
command_append_array },
#define CREATE_EXTEND_OPTIONS(cmdargs) \
...
...
src/cmd/isula/client_arguments.c
浏览文件 @
7d0a82f5
...
...
@@ -238,6 +238,18 @@ void client_arguments_free(struct client_arguments *args)
free
(
args
->
key_file
);
args
->
key_file
=
NULL
;
util_free_array
(
custom_conf
->
blkio_throttle_read_bps_device
);
custom_conf
->
blkio_throttle_read_bps_device
=
NULL
;
util_free_array
(
custom_conf
->
blkio_throttle_write_bps_device
);
custom_conf
->
blkio_throttle_write_bps_device
=
NULL
;
util_free_array
(
custom_conf
->
blkio_throttle_read_iops_device
);
custom_conf
->
blkio_throttle_read_iops_device
=
NULL
;
util_free_array
(
custom_conf
->
blkio_throttle_write_iops_device
);
custom_conf
->
blkio_throttle_write_iops_device
=
NULL
;
}
/* print common help */
...
...
src/cmd/isula/client_arguments.h
浏览文件 @
7d0a82f5
...
...
@@ -197,6 +197,12 @@ struct custom_configs {
/* device write bps */
char
**
blkio_throttle_write_bps_device
;
/* device read iops */
char
**
blkio_throttle_read_iops_device
;
/* device write iops */
char
**
blkio_throttle_write_iops_device
;
};
struct
args_cgroup_resources
{
...
...
src/daemon/modules/spec/specs_mount.c
浏览文件 @
7d0a82f5
...
...
@@ -958,111 +958,56 @@ out:
return
ret
;
}
static
int
get_
read_bps_devices_from_path
(
const
defs_blkio_device
*
read_bps_dev
,
defs_block_io_device_throttle
*
spec_read_bps_dev
)
static
int
get_
blkio_device_throttle_info
(
const
defs_blkio_device
*
blkio_dev_info
,
defs_block_io_device_throttle
*
blkio_dev_throttle
)
{
int
ret
=
0
;
struct
stat
st
;
if
(
read_bps_dev
==
NULL
||
spec_read_bps_dev
==
NULL
)
{
if
(
blkio_dev_info
==
NULL
||
blkio_dev_throttle
==
NULL
)
{
return
-
1
;
}
ret
=
stat
(
read_bps_dev
->
path
,
&
st
);
ret
=
stat
(
blkio_dev_info
->
path
,
&
st
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to get state of device:%s"
,
read_bps_dev
->
path
);
isulad_set_error_message
(
"no such file or directory: %s"
,
read_bps_dev
->
path
);
return
-
1
;
}
/* fill spec throttle read bps dev */
spec_read_bps_dev
->
rate
=
read_bps_dev
->
rate
;
spec_read_bps_dev
->
major
=
(
int64_t
)
major
(
st
.
st_rdev
);
spec_read_bps_dev
->
minor
=
(
int64_t
)
minor
(
st
.
st_rdev
);
return
0
;
}
static
int
merge_host_config_blk_read_bps_device
(
defs_block_io_device_throttle
**
out_spec_read_bps_dev
,
const
defs_blkio_device
*
blkio_device_read_bps
)
{
int
ret
=
0
;
defs_block_io_device_throttle
*
spec_read_bps_dev
=
NULL
;
spec_read_bps_dev
=
util_common_calloc_s
(
sizeof
(
defs_block_io_device_throttle
));
if
(
spec_read_bps_dev
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
erro_out
;
}
ret
=
get_read_bps_devices_from_path
(
blkio_device_read_bps
,
spec_read_bps_dev
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to get throttle read bps devices info"
);
ret
=
-
1
;
goto
erro_out
;
}
*
out_spec_read_bps_dev
=
spec_read_bps_dev
;
goto
out
;
erro_out:
free_defs_block_io_device_throttle
(
spec_read_bps_dev
);
out:
return
ret
;
}
static
int
get_write_bps_devices_from_path
(
const
defs_blkio_device
*
write_bps_dev
,
defs_block_io_device_throttle
*
spec_write_bps_dev
)
{
int
ret
=
0
;
struct
stat
st
;
if
(
write_bps_dev
==
NULL
||
spec_write_bps_dev
==
NULL
)
{
return
-
1
;
}
ret
=
stat
(
write_bps_dev
->
path
,
&
st
);
if
(
ret
<
0
)
{
ERROR
(
"no such file or directory :%s"
,
write_bps_dev
->
path
);
isulad_set_error_message
(
"no such file or directory: %s"
,
write_bps_dev
->
path
);
ERROR
(
"no such file or directory :%s"
,
blkio_dev_info
->
path
);
isulad_set_error_message
(
"no such file or directory: %s"
,
blkio_dev_info
->
path
);
return
-
1
;
}
/* fill spec throttle write bps dev */
spec_write_bps_dev
->
rate
=
write_bps_dev
->
rate
;
spec_write_bps_dev
->
major
=
(
int64_t
)
major
(
st
.
st_rdev
);
spec_write_bps_dev
->
minor
=
(
int64_t
)
minor
(
st
.
st_rdev
);
blkio_dev_throttle
->
rate
=
blkio_dev_info
->
rate
;
blkio_dev_throttle
->
major
=
(
int64_t
)
major
(
st
.
st_rdev
);
blkio_dev_throttle
->
minor
=
(
int64_t
)
minor
(
st
.
st_rdev
);
return
0
;
}
static
int
merge_host_config_blk_
write_bps_device
(
defs_block_io_device_throttle
**
out_spec_write_bps_dev
,
const
defs_blkio_device
*
blkio_device_write_bps
)
static
int
merge_host_config_blk_
device
(
defs_block_io_device_throttle
**
blkio_dev_throttle
,
const
defs_blkio_device
*
blkio_dev
)
{
int
ret
=
0
;
defs_block_io_device_throttle
*
spec_write_bps_dev
=
NULL
;
defs_block_io_device_throttle
*
tmp_throttle
=
NULL
;
spec_write_bps_dev
=
util_common_calloc_s
(
sizeof
(
defs_block_io_device_throttle
));
if
(
spec_write_bps_dev
==
NULL
)
{
tmp_throttle
=
util_common_calloc_s
(
sizeof
(
defs_block_io_device_throttle
));
if
(
tmp_throttle
==
NULL
)
{
ERROR
(
"Memory out"
);
ret
=
-
1
;
goto
erro_out
;
}
ret
=
get_
write_bps_devices_from_path
(
blkio_device_write_bps
,
spec_write_bps_dev
);
ret
=
get_
blkio_device_throttle_info
(
blkio_dev
,
tmp_throttle
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to get throttle
write
bps devices info"
);
ERROR
(
"Failed to get throttle
read
bps devices info"
);
ret
=
-
1
;
goto
erro_out
;
}
*
out_spec_write_bps_dev
=
spec_write_bps_dev
;
*
blkio_dev_throttle
=
tmp_throttle
;
goto
out
;
erro_out:
free_defs_block_io_device_throttle
(
spec_write_bps_dev
);
free_defs_block_io_device_throttle
(
tmp_throttle
);
out:
return
ret
;
...
...
@@ -1668,7 +1613,7 @@ static int merge_blkio_read_bps_device(oci_runtime_spec *oci_spec, defs_blkio_de
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_bps_device
=
throttle_read_bps_device
;
for
(
i
=
0
;
i
<
throttle_read_bps_device_len
;
i
++
)
{
ret
=
merge_host_config_blk_
read_bps_
device
(
ret
=
merge_host_config_blk_device
(
&
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_bps_device
[
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_bps_device_len
],
blkio_read_bps_device
[
i
]);
...
...
@@ -1721,7 +1666,7 @@ static int merge_blkio_write_bps_device(oci_runtime_spec *oci_spec, defs_blkio_d
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_bps_device
=
throttle_write_bps_device
;
for
(
i
=
0
;
i
<
throttle_write_bps_device_len
;
i
++
)
{
ret
=
merge_host_config_blk_
write_bps_
device
(
ret
=
merge_host_config_blk_device
(
&
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_bps_device
[
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_bps_device_len
],
blkio_write_bps_device
[
i
]);
...
...
@@ -1737,6 +1682,112 @@ out:
return
ret
;
}
static
int
merge_blkio_read_iops_device
(
oci_runtime_spec
*
oci_spec
,
defs_blkio_device
**
blkio_read_iops_device
,
size_t
throttle_read_iops_device_len
)
{
int
ret
=
0
;
size_t
new_size
=
0
;
size_t
old_size
=
0
;
size_t
i
=
0
;
defs_block_io_device_throttle
**
throttle_read_iops_device
=
NULL
;
ret
=
make_sure_oci_spec_linux_resources_blkio
(
oci_spec
);
if
(
ret
<
0
)
{
goto
out
;
}
if
(
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device_len
>
LIST_DEVICE_SIZE_MAX
-
throttle_read_iops_device_len
)
{
ERROR
(
"Too many throttle read iops devices to merge, the limit is %lld"
,
LIST_DEVICE_SIZE_MAX
);
isulad_set_error_message
(
"Too many throttle read iops devices devices to merge, the limit is %d"
,
LIST_DEVICE_SIZE_MAX
);
ret
=
-
1
;
goto
out
;
}
new_size
=
(
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device_len
+
throttle_read_iops_device_len
)
*
sizeof
(
defs_block_io_device_throttle
*
);
old_size
=
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device_len
*
sizeof
(
defs_block_io_device_throttle
*
);
ret
=
mem_realloc
((
void
**
)
&
throttle_read_iops_device
,
new_size
,
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device
,
old_size
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to realloc memory for blkio throttle read iops devices"
);
ret
=
-
1
;
goto
out
;
}
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device
=
throttle_read_iops_device
;
for
(
i
=
0
;
i
<
throttle_read_iops_device_len
;
i
++
)
{
ret
=
merge_host_config_blk_device
(
&
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device
[
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device_len
],
blkio_read_iops_device
[
i
]);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to merge blkio throttle read iops device"
);
ret
=
-
1
;
goto
out
;
}
oci_spec
->
linux
->
resources
->
block_io
->
throttle_read_iops_device_len
++
;
}
out:
return
ret
;
}
static
int
merge_blkio_write_iops_device
(
oci_runtime_spec
*
oci_spec
,
defs_blkio_device
**
blkio_write_iops_device
,
size_t
throttle_write_iops_device_len
)
{
int
ret
=
0
;
size_t
new_size
=
0
;
size_t
old_size
=
0
;
size_t
i
=
0
;
defs_block_io_device_throttle
**
throttle_write_iops_device
=
NULL
;
ret
=
make_sure_oci_spec_linux_resources_blkio
(
oci_spec
);
if
(
ret
<
0
)
{
goto
out
;
}
if
(
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device_len
>
LIST_DEVICE_SIZE_MAX
-
throttle_write_iops_device_len
)
{
ERROR
(
"Too many throttle write iops devices to merge, the limit is %lld"
,
LIST_DEVICE_SIZE_MAX
);
isulad_set_error_message
(
"Too many throttle write iops devices devices to merge, the limit is %d"
,
LIST_DEVICE_SIZE_MAX
);
ret
=
-
1
;
goto
out
;
}
new_size
=
(
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device_len
+
throttle_write_iops_device_len
)
*
sizeof
(
defs_block_io_device_throttle
*
);
old_size
=
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device_len
*
sizeof
(
defs_block_io_device_throttle
*
);
ret
=
mem_realloc
((
void
**
)
&
throttle_write_iops_device
,
new_size
,
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device
,
old_size
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to realloc memory for throttle write iops devices"
);
ret
=
-
1
;
goto
out
;
}
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device
=
throttle_write_iops_device
;
for
(
i
=
0
;
i
<
throttle_write_iops_device_len
;
i
++
)
{
ret
=
merge_host_config_blk_device
(
&
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device
[
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device_len
],
blkio_write_iops_device
[
i
]);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to merge blkio throttle write iops device"
);
ret
=
-
1
;
goto
out
;
}
oci_spec
->
linux
->
resources
->
block_io
->
throttle_write_iops_device_len
++
;
}
out:
return
ret
;
}
int
merge_conf_device
(
oci_runtime_spec
*
oci_spec
,
host_config
*
host_spec
)
{
int
ret
=
0
;
...
...
@@ -1770,6 +1821,26 @@ int merge_conf_device(oci_runtime_spec *oci_spec, host_config *host_spec)
}
}
/* blkio throttle read iops devices */
if
(
host_spec
->
blkio_device_read_iops
!=
NULL
&&
host_spec
->
blkio_device_read_iops_len
!=
0
)
{
ret
=
merge_blkio_read_iops_device
(
oci_spec
,
host_spec
->
blkio_device_read_iops
,
host_spec
->
blkio_device_read_iops_len
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to merge blkio read iops devices"
);
goto
out
;
}
}
/* blkio throttle write iops devices */
if
(
host_spec
->
blkio_device_write_iops
!=
NULL
&&
host_spec
->
blkio_device_write_iops_len
!=
0
)
{
ret
=
merge_blkio_write_iops_device
(
oci_spec
,
host_spec
->
blkio_device_write_iops
,
host_spec
->
blkio_device_write_iops_len
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to merge blkio write iops devices"
);
goto
out
;
}
}
/* devices which will be populated into container */
if
(
host_spec
->
devices
!=
NULL
&&
host_spec
->
devices_len
!=
0
)
{
/* privileged containers will populate all devices in host */
...
...
src/daemon/modules/spec/verify.c
浏览文件 @
7d0a82f5
...
...
@@ -765,44 +765,29 @@ out:
return
ret
;
}
static
inline
bool
is_hostconfig_blkio_weight_invalid
(
uint16_t
weight
)
{
return
weight
>
0
&&
(
weight
<
10
||
weight
>
1000
);
}
/* verify hostconfig blkio weight */
static
int
verify_hostconfig_blkio_weight
(
const
sysinfo_t
*
sysinfo
,
uint16_t
weight
)
/* verify blkio device */
static
int
verify_blkio_device
(
const
sysinfo_t
*
sysinfo
,
const
defs_block_io_device_weight
**
weight_device
,
size_t
weight_device_len
)
{
int
ret
=
0
;
size_t
i
=
0
;
if
(
weight
>
0
&&
!
(
sysinfo
->
blkioinfo
.
blkio_weight
))
{
ERROR
(
"Your kernel does not support Block I/O weight
. Weight in host config discarded
."
);
isulad_set_error_message
(
"Your kernel does not support Block I/O weight
. Weight in host config discarded
."
);
if
(
weight
_device_len
>
0
&&
!
(
sysinfo
->
blkioinfo
.
blkio_weight_device
))
{
ERROR
(
"Your kernel does not support Block I/O weight
_device
."
);
isulad_set_error_message
(
"Your kernel does not support Block I/O weight
_device
."
);
ret
=
-
1
;
goto
out
;
}
if
(
is_hostconfig_blkio_weight_invalid
(
weight
))
{
for
(
i
=
0
;
i
<
weight_device_len
;
i
++
)
{
if
(
is_blkio_weight_invalid
(
weight_device
[
i
]
->
weight
))
{
ERROR
(
"Range of blkio weight is from 10 to 1000."
);
isulad_set_error_message
(
"Range of blkio weight is from 10 to 1000."
);
ret
=
-
1
;
goto
out
;
}
out:
return
ret
;
}
/* verify blkio device */
static
int
verify_blkio_device
(
const
sysinfo_t
*
sysinfo
,
size_t
weight_device_len
)
{
int
ret
=
0
;
if
(
weight_device_len
>
0
&&
!
(
sysinfo
->
blkioinfo
.
blkio_weight_device
))
{
ERROR
(
"Your kernel does not support Block I/O weight_device."
);
isulad_set_error_message
(
"Your kernel does not support Block I/O weight_device."
);
ret
=
-
1
;
}
out:
return
ret
;
}
...
...
@@ -929,7 +914,8 @@ static int verify_resources_blkio(const sysinfo_t *sysinfo, const defs_resources
goto
out
;
}
ret
=
verify_blkio_device
(
sysinfo
,
blkio
->
weight_device_len
);
ret
=
verify_blkio_device
(
sysinfo
,
(
const
defs_block_io_device_weight
**
)
blkio
->
weight_device
,
blkio
->
weight_device_len
);
if
(
ret
!=
0
)
{
goto
out
;
}
...
...
@@ -1771,12 +1757,25 @@ static int host_config_settings_blkio(const sysinfo_t *sysinfo, const host_confi
{
int
ret
=
0
;
ret
=
verify_hostconfig_blkio_weight
(
sysinfo
,
hostconfig
->
blkio_weight
);
ret
=
verify_blkio_weight
(
sysinfo
,
hostconfig
->
blkio_weight
);
if
(
ret
!=
0
)
{
goto
out
;
}
ret
=
verify_blkio_device
(
sysinfo
,
(
const
defs_block_io_device_weight
**
)
hostconfig
->
blkio_weight_device
,
hostconfig
->
blkio_weight_device_len
);
if
(
ret
!=
0
)
{
goto
out
;
}
ret
=
verify_blkio_rw_bps_device
(
sysinfo
,
hostconfig
->
blkio_device_read_bps_len
,
hostconfig
->
blkio_device_write_bps_len
);
if
(
ret
!=
0
)
{
goto
out
;
}
ret
=
verify_blkio_device
(
sysinfo
,
hostconfig
->
blkio_weight_device_len
);
ret
=
verify_blkio_rw_iops_device
(
sysinfo
,
hostconfig
->
blkio_device_read_iops_len
,
hostconfig
->
blkio_device_write_iops_len
);
if
(
ret
!=
0
)
{
goto
out
;
}
...
...
src/utils/cutils/utils_convert.c
浏览文件 @
7d0a82f5
...
...
@@ -107,6 +107,29 @@ int util_safe_uint(const char *numstr, unsigned int *converted)
return
0
;
}
int
util_safe_uint64
(
const
char
*
numstr
,
uint64_t
*
converted
)
{
char
*
err_str
=
NULL
;
uint64_t
ull
;
if
(
numstr
==
NULL
||
converted
==
NULL
)
{
return
-
EINVAL
;
}
errno
=
0
;
ull
=
strtoull
(
numstr
,
&
err_str
,
0
);
if
(
errno
>
0
)
{
return
-
errno
;
}
if
(
is_invalid_error_str
(
err_str
,
numstr
))
{
return
-
EINVAL
;
}
*
converted
=
(
uint64_t
)
ull
;
return
0
;
}
int
util_safe_llong
(
const
char
*
numstr
,
long
long
*
converted
)
{
char
*
err_str
=
NULL
;
...
...
@@ -179,4 +202,3 @@ int util_str_to_bool(const char *boolstr, bool *converted)
}
return
0
;
}
src/utils/cutils/utils_convert.h
浏览文件 @
7d0a82f5
...
...
@@ -28,10 +28,10 @@ int util_safe_uint(const char *numstr, unsigned int *converted);
int
util_safe_llong
(
const
char
*
numstr
,
long
long
*
converted
);
int
util_safe_strtod
(
const
char
*
numstr
,
double
*
converted
);
int
util_str_to_bool
(
const
char
*
boolstr
,
bool
*
converted
);
int
util_safe_uint64
(
const
char
*
numstr
,
uint64_t
*
converted
);
#ifdef __cplusplus
}
#endif
#endif // UTILS_CUTILS_UTILS_CONVERT_H
src/utils/cutils/utils_verify.c
浏览文件 @
7d0a82f5
...
...
@@ -640,3 +640,14 @@ bool util_valid_exec_suffix(const char *suffix)
return
util_reg_match
(
patten
,
suffix
)
==
0
;
}
bool
util_valid_positive_interger
(
const
char
*
value
)
{
const
char
*
patten
=
"^[0-9]*$"
;
if
(
value
==
NULL
)
{
return
false
;
}
return
util_reg_match
(
patten
,
value
)
==
0
;
}
\ No newline at end of file
src/utils/cutils/utils_verify.h
浏览文件 @
7d0a82f5
...
...
@@ -99,6 +99,8 @@ bool util_valid_short_sha256_id(const char *id);
bool
util_valid_exec_suffix
(
const
char
*
suffix
);
bool
util_valid_positive_interger
(
const
char
*
value
);
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录