From: Pradeep Jagadeesh <pradeepkiruvale@gmail.com>
To: eric blake <eblake@redhat.com>, greg kurz <groug@kaod.org>
Cc: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>,
alberto garcia <berto@igalia.com>,
jani kokkonen <jani.kokkonen@huawei.com>,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v4 3/4] qmp: refactor duplicate code
Date: Wed, 10 May 2017 04:41:22 -0400 [thread overview]
Message-ID: <1494405683-20877-4-git-send-email-pradeep.jagadeesh@huawei.com> (raw)
In-Reply-To: <1494405683-20877-1-git-send-email-pradeep.jagadeesh@huawei.com>
This patch factor out the duplicate qmp throttle interface code
that was present in both block and fsdev device files.
Signed-off-by: Pradeep Jagadeesh <pradeep.jagadeesh@huawei.com>
---
blockdev.c | 53 +++-------------------------------------
hmp.c | 21 +++++++++++-----
include/qemu/throttle-options.h | 2 ++
util/throttle-options.c | 54 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 56 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index a0eb2ed..a55f6be 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2593,6 +2593,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)
BlockDriverState *bs;
BlockBackend *blk;
AioContext *aio_context;
+ IOThrottle *iothrottle;
blk = qmp_get_blk(arg->has_device ? arg->device : NULL,
arg->has_id ? arg->id : NULL,
@@ -2610,56 +2611,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)
goto out;
}
- throttle_config_init(&cfg);
- cfg.buckets[THROTTLE_BPS_TOTAL].avg = arg->bps;
- cfg.buckets[THROTTLE_BPS_READ].avg = arg->bps_rd;
- cfg.buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr;
-
- cfg.buckets[THROTTLE_OPS_TOTAL].avg = arg->iops;
- cfg.buckets[THROTTLE_OPS_READ].avg = arg->iops_rd;
- cfg.buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr;
-
- if (arg->has_bps_max) {
- cfg.buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max;
- }
- if (arg->has_bps_rd_max) {
- cfg.buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max;
- }
- if (arg->has_bps_wr_max) {
- cfg.buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max;
- }
- if (arg->has_iops_max) {
- cfg.buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max;
- }
- if (arg->has_iops_rd_max) {
- cfg.buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max;
- }
- if (arg->has_iops_wr_max) {
- cfg.buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max;
- }
-
- if (arg->has_bps_max_length) {
- cfg.buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length;
- }
- if (arg->has_bps_rd_max_length) {
- cfg.buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length;
- }
- if (arg->has_bps_wr_max_length) {
- cfg.buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length;
- }
- if (arg->has_iops_max_length) {
- cfg.buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length;
- }
- if (arg->has_iops_rd_max_length) {
- cfg.buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length;
- }
- if (arg->has_iops_wr_max_length) {
- cfg.buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length;
- }
-
- if (arg->has_iops_size) {
- cfg.op_size = arg->iops_size;
- }
+ iothrottle = qapi_BlockIOThrottle_base(arg);
+ qmp_set_io_throttle(&cfg, iothrottle);
if (!throttle_is_valid(&cfg, errp)) {
goto out;
diff --git a/hmp.c b/hmp.c
index ab407d6..9660373 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1552,20 +1552,29 @@ void hmp_change(Monitor *mon, const QDict *qdict)
hmp_handle_error(mon, &err);
}
+static void hmp_initialize_io_throttle(IOThrottle *iot, const QDict *qdict)
+{
+ iot->has_id = true;
+ iot->id = (char *) qdict_get_str(qdict, "id");
+ iot->bps = qdict_get_int(qdict, "bps");
+ iot->bps_rd = qdict_get_int(qdict, "bps_rd");
+ iot->bps_wr = qdict_get_int(qdict, "bps_wr");
+ iot->iops = qdict_get_int(qdict, "iops");
+ iot->iops_rd = qdict_get_int(qdict, "iops_rd");
+ iot->iops_wr = qdict_get_int(qdict, "iops_wr");
+}
+
void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
+ IOThrottle *iothrottle;
BlockIOThrottle throttle = {
.has_device = true,
.device = (char *) qdict_get_str(qdict, "device"),
- .bps = qdict_get_int(qdict, "bps"),
- .bps_rd = qdict_get_int(qdict, "bps_rd"),
- .bps_wr = qdict_get_int(qdict, "bps_wr"),
- .iops = qdict_get_int(qdict, "iops"),
- .iops_rd = qdict_get_int(qdict, "iops_rd"),
- .iops_wr = qdict_get_int(qdict, "iops_wr"),
};
+ iothrottle = qapi_BlockIOThrottle_base(&throttle);
+ hmp_initialize_io_throttle(iothrottle, qdict);
qmp_block_set_io_throttle(&throttle, &err);
hmp_handle_error(mon, &err);
}
diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h
index 9b68eb8..ccf10cc 100644
--- a/include/qemu/throttle-options.h
+++ b/include/qemu/throttle-options.h
@@ -94,4 +94,6 @@
void parse_io_throttle_options(ThrottleConfig *, QemuOpts *);
+void qmp_set_io_throttle(ThrottleConfig *, IOThrottle *);
+
#endif
diff --git a/util/throttle-options.c b/util/throttle-options.c
index 02b26b8..ded57bc 100644
--- a/util/throttle-options.c
+++ b/util/throttle-options.c
@@ -49,3 +49,57 @@ void parse_io_throttle_options(ThrottleConfig *throttle_cfg, QemuOpts *opts)
qemu_opt_get_number(opts, "throttling.iops-size", 0);
}
+
+void qmp_set_io_throttle(ThrottleConfig *cfg, IOThrottle *arg)
+{
+ throttle_config_init(cfg);
+ cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps;
+ cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_rd;
+ cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_wr;
+
+ cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops;
+ cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_rd;
+ cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_wr;
+
+ if (arg->has_bps_max) {
+ cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_max;
+ }
+ if (arg->has_bps_rd_max) {
+ cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_rd_max;
+ }
+ if (arg->has_bps_wr_max) {
+ cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_wr_max;
+ }
+ if (arg->has_iops_max) {
+ cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_max;
+ }
+ if (arg->has_iops_rd_max) {
+ cfg->buckets[THROTTLE_OPS_READ].max = arg->iops_rd_max;
+ }
+ if (arg->has_iops_wr_max) {
+ cfg->buckets[THROTTLE_OPS_WRITE].max = arg->iops_wr_max;
+ }
+
+ if (arg->has_bps_max_length) {
+ cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_max_length;
+ }
+ if (arg->has_bps_rd_max_length) {
+ cfg->buckets[THROTTLE_BPS_READ].burst_length = arg->bps_rd_max_length;
+ }
+ if (arg->has_bps_wr_max_length) {
+ cfg->buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_wr_max_length;
+ }
+ if (arg->has_iops_max_length) {
+ cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_max_length;
+ }
+ if (arg->has_iops_rd_max_length) {
+ cfg->buckets[THROTTLE_OPS_READ].burst_length = arg->iops_rd_max_length;
+ }
+ if (arg->has_iops_wr_max_length) {
+ cfg->buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_wr_max_length;
+ }
+
+ if (arg->has_iops_size) {
+ cfg->op_size = arg->iops_size;
+ }
+}
--
1.8.3.1
next prev parent reply other threads:[~2017-05-10 8:42 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-10 8:41 [Qemu-devel] [PATCH v4 0/4] fsdev: qmp interface for io throttling Pradeep Jagadeesh
2017-05-10 8:41 ` [Qemu-devel] [PATCH v4 1/4] throttle: factor out duplicate code Pradeep Jagadeesh
2017-05-10 14:12 ` Greg Kurz
2017-05-10 15:27 ` Pradeep Jagadeesh
2017-05-10 19:48 ` Eric Blake
2017-05-11 16:12 ` Pradeep Jagadeesh
2017-05-10 8:41 ` [Qemu-devel] [PATCH v4 2/4] qmp: Create IOThrottle structure Pradeep Jagadeesh
2017-05-10 8:41 ` Pradeep Jagadeesh [this message]
2017-05-10 19:56 ` [Qemu-devel] [PATCH v4 3/4] qmp: refactor duplicate code Eric Blake
2017-05-11 16:14 ` Pradeep Jagadeesh
2017-05-11 7:50 ` Greg Kurz
2017-05-12 8:03 ` Pradeep Jagadeesh
2017-06-08 14:20 ` Greg Kurz
2017-06-09 8:32 ` Pradeep Jagadeesh
2017-05-10 8:41 ` [Qemu-devel] [PATCH v4 4/4] fsdev: QMP interface for throttling Pradeep Jagadeesh
2017-05-10 20:00 ` Eric Blake
2017-05-17 14:53 ` Pradeep Jagadeesh
2017-05-17 15:28 ` Eric Blake
2017-05-17 16:29 ` Greg Kurz
2017-05-17 17:09 ` Eric Blake
2017-05-18 13:30 ` Pradeep Jagadeesh
2017-06-08 16:49 ` Greg Kurz
2017-06-09 8:31 ` Pradeep Jagadeesh
2017-06-09 9:07 ` Greg Kurz
2017-06-09 9:13 ` Pradeep Jagadeesh
2017-06-09 9:20 ` Greg Kurz
2017-05-10 10:02 ` [Qemu-devel] [PATCH v4 0/4] fsdev: qmp interface for io throttling no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1494405683-20877-4-git-send-email-pradeep.jagadeesh@huawei.com \
--to=pradeepkiruvale@gmail.com \
--cc=berto@igalia.com \
--cc=eblake@redhat.com \
--cc=groug@kaod.org \
--cc=jani.kokkonen@huawei.com \
--cc=pradeep.jagadeesh@huawei.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).