From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNZ7p-0001lX-Vq for qemu-devel@nongnu.org; Fri, 16 Nov 2018 03:05:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNZ7l-0005nt-QL for qemu-devel@nongnu.org; Fri, 16 Nov 2018 03:05:13 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3106 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNZ7j-0005gN-Qm for qemu-devel@nongnu.org; Fri, 16 Nov 2018 03:05:09 -0500 From: xiezhide Date: Fri, 16 Nov 2018 15:59:16 +0800 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v5 1/6] fsdev-throttle-qmp: factor out throttle code to reuse code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: groug@kaod.org, aneesh.kumar@linux.vnet.ibm.com, eblake@redhat.com, armbru@redhat.com, berto@igalia.com, zengcanfu@huawei.com, jinxuefeng@huawei.com, chenhui.rtos@huawei.com Factor out throttle parameter parsing code to a new common function which will be used by block and fsdev. Rename function throttle_parse_options to throttle_parse_group to resolve function name conflict Reviewed-by: Eric Blake Signed-off-by: xiezhide --- block/throttle.c | 6 ++-- blockdev.c | 43 +------------------------- fsdev/qemu-fsdev-throttle.c | 44 ++------------------------ include/qemu/throttle-options.h | 2 ++ include/qemu/throttle.h | 4 +-- include/qemu/typedefs.h | 1 + util/throttle.c | 68 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 79 insertions(+), 89 deletions(-) diff --git a/block/throttle.c b/block/throttle.c index 636c976..bd23c58 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -41,7 +41,7 @@ static QemuOptsList throttle_opts = { * @group and must be freed by the caller. * If there's an error then @group remains unmodified. */ -static int throttle_parse_options(QDict *options, char **group, Error **errp) +static int throttle_parse_group(QDict *options, char **group, Error **errp) { int ret; const char *group_name; @@ -90,7 +90,7 @@ static int throttle_open(BlockDriverState *bs, QDict *options, bs->supported_zero_flags = bs->file->bs->supported_zero_flags | BDRV_REQ_WRITE_UNCHANGED; - ret = throttle_parse_options(options, &group, errp); + ret = throttle_parse_group(options, &group, errp); if (ret == 0) { /* Register membership to group with name group_name */ throttle_group_register_tgm(tgm, group, bdrv_get_aio_context(bs)); @@ -179,7 +179,7 @@ static int throttle_reopen_prepare(BDRVReopenState *reopen_state, assert(reopen_state != NULL); assert(reopen_state->bs != NULL); - ret = throttle_parse_options(reopen_state->options, &group, errp); + ret = throttle_parse_group(reopen_state->options, &group, errp); reopen_state->opaque = group; return ret; } diff --git a/blockdev.c b/blockdev.c index 81f95d9..fce5d8f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -400,48 +400,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } if (throttle_cfg) { - throttle_config_init(throttle_cfg); - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.bps-total", 0); - throttle_cfg->buckets[THROTTLE_BPS_READ].avg = - qemu_opt_get_number(opts, "throttling.bps-read", 0); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.bps-write", 0); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.iops-total", 0); - throttle_cfg->buckets[THROTTLE_OPS_READ].avg = - qemu_opt_get_number(opts, "throttling.iops-read", 0); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.iops-write", 0); - - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.bps-total-max", 0); - throttle_cfg->buckets[THROTTLE_BPS_READ].max = - qemu_opt_get_number(opts, "throttling.bps-read-max", 0); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.bps-write-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.iops-total-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_READ].max = - qemu_opt_get_number(opts, "throttling.iops-read-max", 0); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - - throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); - throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); - throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); - throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - - throttle_cfg->op_size = - qemu_opt_get_number(opts, "throttling.iops-size", 0); + throttle_parse_options(throttle_cfg, opts); if (!throttle_is_valid(throttle_cfg, errp)) { return; diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index cfd8641..6a4108a 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -17,6 +17,7 @@ #include "qemu-fsdev-throttle.h" #include "qemu/iov.h" #include "qemu/option.h" +#include "qemu/throttle-options.h" static void fsdev_throttle_read_timer_cb(void *opaque) { @@ -32,48 +33,7 @@ static void fsdev_throttle_write_timer_cb(void *opaque) void fsdev_throttle_parse_opts(QemuOpts *opts, FsThrottle *fst, Error **errp) { - throttle_config_init(&fst->cfg); - fst->cfg.buckets[THROTTLE_BPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.bps-total", 0); - fst->cfg.buckets[THROTTLE_BPS_READ].avg = - qemu_opt_get_number(opts, "throttling.bps-read", 0); - fst->cfg.buckets[THROTTLE_BPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.bps-write", 0); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.iops-total", 0); - fst->cfg.buckets[THROTTLE_OPS_READ].avg = - qemu_opt_get_number(opts, "throttling.iops-read", 0); - fst->cfg.buckets[THROTTLE_OPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.iops-write", 0); - - fst->cfg.buckets[THROTTLE_BPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.bps-total-max", 0); - fst->cfg.buckets[THROTTLE_BPS_READ].max = - qemu_opt_get_number(opts, "throttling.bps-read-max", 0); - fst->cfg.buckets[THROTTLE_BPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.bps-write-max", 0); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.iops-total-max", 0); - fst->cfg.buckets[THROTTLE_OPS_READ].max = - qemu_opt_get_number(opts, "throttling.iops-read-max", 0); - fst->cfg.buckets[THROTTLE_OPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.iops-write-max", 0); - - fst->cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.bps-total-max-length", 1); - fst->cfg.buckets[THROTTLE_BPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.bps-read-max-length", 1); - fst->cfg.buckets[THROTTLE_BPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.bps-write-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = - qemu_opt_get_number(opts, "throttling.iops-total-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_READ].burst_length = - qemu_opt_get_number(opts, "throttling.iops-read-max-length", 1); - fst->cfg.buckets[THROTTLE_OPS_WRITE].burst_length = - qemu_opt_get_number(opts, "throttling.iops-write-max-length", 1); - fst->cfg.op_size = - qemu_opt_get_number(opts, "throttling.iops-size", 0); - + throttle_parse_options(&fst->cfg, opts); throttle_is_valid(&fst->cfg, errp); } diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h index 3528a8f..944a08c 100644 --- a/include/qemu/throttle-options.h +++ b/include/qemu/throttle-options.h @@ -111,4 +111,6 @@ .help = "when limiting by iops max size of an I/O in bytes",\ } +void throttle_parse_options(ThrottleConfig *, QemuOpts *); + #endif diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index abeb886..f379d91 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -90,10 +90,10 @@ typedef struct LeakyBucket { * However it allows to keep the code clean and the bucket field is reset to * zero at the right time. */ -typedef struct ThrottleConfig { +struct ThrottleConfig { LeakyBucket buckets[BUCKETS_COUNT]; /* leaky buckets */ uint64_t op_size; /* size of an operation in bytes */ -} ThrottleConfig; +}; typedef struct ThrottleState { ThrottleConfig cfg; /* configuration */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 3ec0e13..0d75edc 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -109,6 +109,7 @@ typedef struct SerialState SerialState; typedef struct SHPCDevice SHPCDevice; typedef struct SMBusDevice SMBusDevice; typedef struct SSIBus SSIBus; +typedef struct ThrottleConfig ThrottleConfig; typedef struct uWireSlave uWireSlave; typedef struct VirtIODevice VirtIODevice; typedef struct Visitor Visitor; diff --git a/util/throttle.c b/util/throttle.c index b38e742..e7db2ad 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -27,6 +27,8 @@ #include "qemu/throttle.h" #include "qemu/timer.h" #include "block/aio.h" +#include "qemu/option.h" +#include "qemu/throttle-options.h" /* This function make a bucket leak * @@ -636,3 +638,69 @@ void throttle_config_to_limits(ThrottleConfig *cfg, ThrottleLimits *var) var->has_iops_write_max_length = true; var->has_iops_size = true; } + +/* parse the throttle options + * + * @opts: qemu options + * @throttle_cfg: throttle configuration + */ +void throttle_parse_options(ThrottleConfig *throttle_cfg, QemuOpts *opts) +{ + throttle_config_init(throttle_cfg); + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_TOTAL, 0); + throttle_cfg->buckets[THROTTLE_BPS_READ].avg = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_READ, 0); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_WRITE, 0); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_TOTAL, 0); + throttle_cfg->buckets[THROTTLE_OPS_READ].avg = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_READ, 0); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_WRITE, 0); + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_TOTAL_MAX, 0); + throttle_cfg->buckets[THROTTLE_BPS_READ].max = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_READ_MAX, 0); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_WRITE_MAX, 0); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_TOTAL_MAX, 0); + throttle_cfg->buckets[THROTTLE_OPS_READ].max = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_READ_MAX, 0); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_WRITE_MAX, 0); + throttle_cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_TOTAL_MAX_LENGTH, 1); + throttle_cfg->buckets[THROTTLE_BPS_READ].burst_length = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_READ_MAX_LENGTH, 1); + throttle_cfg->buckets[THROTTLE_BPS_WRITE].burst_length = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_BPS_WRITE_MAX_LENGTH, 1); + throttle_cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_TOTAL_MAX_LENGTH, 1); + throttle_cfg->buckets[THROTTLE_OPS_READ].burst_length = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_READ_MAX_LENGTH, 1); + throttle_cfg->buckets[THROTTLE_OPS_WRITE].burst_length = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX + QEMU_OPT_IOPS_WRITE_MAX_LENGTH, 1); + throttle_cfg->op_size = + qemu_opt_get_number(opts, THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_SIZE, 0); +} -- 1.8.3.1