提交 7d0a82f5 编写于 作者: L lifeng68

blkio: add support blk read/write iops

Signed-off-by: Nlifeng68 <lifeng68@huawei.com>
上级 d1c33623
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......
此差异已折叠。
......@@ -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 */
......
......@@ -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 {
......
......@@ -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 */
......
......@@ -765,37 +765,12 @@ 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)
{
int ret = 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.");
ret = -1;
goto out;
}
if (is_hostconfig_blkio_weight_invalid(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)
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_device_len > 0 && !(sysinfo->blkioinfo.blkio_weight_device)) {
ERROR("Your kernel does not support Block I/O weight_device.");
......@@ -803,6 +778,16 @@ static int verify_blkio_device(const sysinfo_t *sysinfo, size_t weight_device_le
ret = -1;
}
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;
}
......@@ -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;
}
......
......@@ -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;
}
......@@ -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
......@@ -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
......@@ -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.
先完成此消息的编辑!
想要评论请 注册