9ae3a8
From 6407962af839506d7dcd956d48986324264a3587 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Mon, 9 Sep 2013 14:28:19 +0200
9ae3a8
Subject: [PATCH 28/38] blockdev: Rename I/O throttling options for QMP
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1378736903-18489-29-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 54215
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 28/32] blockdev: Rename I/O throttling options for QMP
9ae3a8
Bugzilla: 1005818
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1005818
9ae3a8
9ae3a8
In QMP, we want to use dashes instead of underscores in QMP argument
9ae3a8
names, and use nested options for throttling.
9ae3a8
9ae3a8
The new option names affect the command line as well, but for
9ae3a8
compatibility drive_init() will convert the old option names before
9ae3a8
calling into the code that will be shared between -drive and
9ae3a8
blockdev-add.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
(cherry picked from commit 57975222b6a928dd4a4a8a7b37093cc8ecba5045)
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 blockdev.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
9ae3a8
 1 file changed, 39 insertions(+), 13 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 blockdev.c |   52 +++++++++++++++++++++++++++++++++++++++-------------
9ae3a8
 1 files changed, 39 insertions(+), 13 deletions(-)
9ae3a8
9ae3a8
diff --git a/blockdev.c b/blockdev.c
9ae3a8
index 1c9ca4d..08b1aaf 100644
9ae3a8
--- a/blockdev.c
9ae3a8
+++ b/blockdev.c
9ae3a8
@@ -312,7 +312,8 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp)
9ae3a8
     return true;
9ae3a8
 }
9ae3a8
 
9ae3a8
-DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
+static DriveInfo *blockdev_init(QemuOpts *all_opts,
9ae3a8
+                                BlockInterfaceType block_default_type)
9ae3a8
 {
9ae3a8
     const char *buf;
9ae3a8
     const char *file = NULL;
9ae3a8
@@ -485,17 +486,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
 
9ae3a8
     /* disk I/O throttling */
9ae3a8
     io_limits.bps[BLOCK_IO_LIMIT_TOTAL]  =
9ae3a8
-                           qemu_opt_get_number(opts, "bps", 0);
9ae3a8
+        qemu_opt_get_number(opts, "throttling.bps-total", 0);
9ae3a8
     io_limits.bps[BLOCK_IO_LIMIT_READ]   =
9ae3a8
-                           qemu_opt_get_number(opts, "bps_rd", 0);
9ae3a8
+        qemu_opt_get_number(opts, "throttling.bps-read", 0);
9ae3a8
     io_limits.bps[BLOCK_IO_LIMIT_WRITE]  =
9ae3a8
-                           qemu_opt_get_number(opts, "bps_wr", 0);
9ae3a8
+        qemu_opt_get_number(opts, "throttling.bps-write", 0);
9ae3a8
     io_limits.iops[BLOCK_IO_LIMIT_TOTAL] =
9ae3a8
-                           qemu_opt_get_number(opts, "iops", 0);
9ae3a8
+        qemu_opt_get_number(opts, "throttling.iops-total", 0);
9ae3a8
     io_limits.iops[BLOCK_IO_LIMIT_READ]  =
9ae3a8
-                           qemu_opt_get_number(opts, "iops_rd", 0);
9ae3a8
+        qemu_opt_get_number(opts, "throttling.iops-read", 0);
9ae3a8
     io_limits.iops[BLOCK_IO_LIMIT_WRITE] =
9ae3a8
-                           qemu_opt_get_number(opts, "iops_wr", 0);
9ae3a8
+        qemu_opt_get_number(opts, "throttling.iops-write", 0);
9ae3a8
 
9ae3a8
     if (!do_check_io_limits(&io_limits, &error)) {
9ae3a8
         error_report("%s", error_get_pretty(error));
9ae3a8
@@ -726,6 +727,31 @@ err:
9ae3a8
     return NULL;
9ae3a8
 }
9ae3a8
 
9ae3a8
+static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
9ae3a8
+{
9ae3a8
+    const char *value;
9ae3a8
+
9ae3a8
+    value = qemu_opt_get(opts, from);
9ae3a8
+    if (value) {
9ae3a8
+        qemu_opt_set(opts, to, value);
9ae3a8
+        qemu_opt_unset(opts, from);
9ae3a8
+    }
9ae3a8
+}
9ae3a8
+
9ae3a8
+DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
+{
9ae3a8
+    /* Change legacy command line options into QMP ones */
9ae3a8
+    qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
9ae3a8
+    qemu_opt_rename(all_opts, "iops_rd", "throttling.iops-read");
9ae3a8
+    qemu_opt_rename(all_opts, "iops_wr", "throttling.iops-write");
9ae3a8
+
9ae3a8
+    qemu_opt_rename(all_opts, "bps", "throttling.bps-total");
9ae3a8
+    qemu_opt_rename(all_opts, "bps_rd", "throttling.bps-read");
9ae3a8
+    qemu_opt_rename(all_opts, "bps_wr", "throttling.bps-write");
9ae3a8
+
9ae3a8
+    return blockdev_init(all_opts, block_default_type);
9ae3a8
+}
9ae3a8
+
9ae3a8
 void do_commit(Monitor *mon, const QDict *qdict)
9ae3a8
 {
9ae3a8
     const char *device = qdict_get_str(qdict, "device");
9ae3a8
@@ -1679,27 +1705,27 @@ QemuOptsList qemu_common_drive_opts = {
9ae3a8
             .type = QEMU_OPT_BOOL,
9ae3a8
             .help = "open drive file as read-only",
9ae3a8
         },{
9ae3a8
-            .name = "iops",
9ae3a8
+            .name = "throttling.iops-total",
9ae3a8
             .type = QEMU_OPT_NUMBER,
9ae3a8
             .help = "limit total I/O operations per second",
9ae3a8
         },{
9ae3a8
-            .name = "iops_rd",
9ae3a8
+            .name = "throttling.iops-read",
9ae3a8
             .type = QEMU_OPT_NUMBER,
9ae3a8
             .help = "limit read operations per second",
9ae3a8
         },{
9ae3a8
-            .name = "iops_wr",
9ae3a8
+            .name = "throttling.iops-write",
9ae3a8
             .type = QEMU_OPT_NUMBER,
9ae3a8
             .help = "limit write operations per second",
9ae3a8
         },{
9ae3a8
-            .name = "bps",
9ae3a8
+            .name = "throttling.bps-total",
9ae3a8
             .type = QEMU_OPT_NUMBER,
9ae3a8
             .help = "limit total bytes per second",
9ae3a8
         },{
9ae3a8
-            .name = "bps_rd",
9ae3a8
+            .name = "throttling.bps-read",
9ae3a8
             .type = QEMU_OPT_NUMBER,
9ae3a8
             .help = "limit read bytes per second",
9ae3a8
         },{
9ae3a8
-            .name = "bps_wr",
9ae3a8
+            .name = "throttling.bps-write",
9ae3a8
             .type = QEMU_OPT_NUMBER,
9ae3a8
             .help = "limit write bytes per second",
9ae3a8
         },{
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8