thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-qmp-access-the-local-QemuOptsLists-for-drive-option.patch

0a122b
From 6d981002b5ccbcb4905e5fa45b4606cf4ddc9c9e Mon Sep 17 00:00:00 2001
0a122b
From: Amos Kong <akong@redhat.com>
0a122b
Date: Tue, 25 Feb 2014 07:56:50 +0100
0a122b
Subject: [PATCH 1/6] qmp: access the local QemuOptsLists for drive option
0a122b
0a122b
RH-Author: Amos Kong <akong@redhat.com>
0a122b
Message-id: <1393315010-20614-1-git-send-email-akong@redhat.com>
0a122b
Patchwork-id: 57771
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v3] qmp: access the local QemuOptsLists for drive option
0a122b
Bugzilla: 1026184
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
0a122b
Bugzilla: 1026184
0a122b
Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7104270
0a122b
0a122b
Currently we have three QemuOptsList (qemu_common_drive_opts,
0a122b
qemu_legacy_drive_opts, and qemu_drive_opts), only qemu_drive_opts
0a122b
is added to vm_config_groups[].
0a122b
0a122b
This patch changes query-command-line-options to access three local
0a122b
QemuOptsLists for drive option, and merge the description items
0a122b
together.
0a122b
0a122b
Signed-off-by: Amos Kong <akong@redhat.com>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
(cherry picked from commit 968854c8a106243eae7a68394ce1cb85dc138837)
0a122b
---
0a122b
v2: re-backport when patch is merged to mainline
0a122b
v3: rebase to latest qemu-kvm-rhel7
0a122b
---
0a122b
redo/fix query-command-line-options isn't finished, let's fix the
0a122b
blkdev issue in rhel7.0 by this backport.
0a122b
---
0a122b
 blockdev.c                 |    1 -
0a122b
 include/qemu/config-file.h |    1 +
0a122b
 include/sysemu/sysemu.h    |    2 +
0a122b
 util/qemu-config.c         |   77 +++++++++++++++++++++++++++++++++++++++++++-
0a122b
 vl.c                       |    3 ++
0a122b
 5 files changed, 82 insertions(+), 2 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 blockdev.c                 |    1 -
0a122b
 include/qemu/config-file.h |    1 +
0a122b
 include/sysemu/sysemu.h    |    2 +
0a122b
 util/qemu-config.c         |   77 +++++++++++++++++++++++++++++++++++++++++++-
0a122b
 vl.c                       |    3 ++
0a122b
 5 files changed, 82 insertions(+), 2 deletions(-)
0a122b
0a122b
diff --git a/blockdev.c b/blockdev.c
0a122b
index 80c6bb4..e51203c 100644
0a122b
--- a/blockdev.c
0a122b
+++ b/blockdev.c
0a122b
@@ -47,7 +47,6 @@
0a122b
 #include "sysemu/arch_init.h"
0a122b
 
0a122b
 static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
0a122b
-extern QemuOptsList qemu_common_drive_opts;
0a122b
 
0a122b
 static const char *const if_name[IF_COUNT] = {
0a122b
     [IF_NONE] = "none",
0a122b
diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h
0a122b
index ccfccae..3f92282 100644
0a122b
--- a/include/qemu/config-file.h
0a122b
+++ b/include/qemu/config-file.h
0a122b
@@ -9,6 +9,7 @@
0a122b
 QemuOptsList *qemu_find_opts(const char *group);
0a122b
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
0a122b
 void qemu_add_opts(QemuOptsList *list);
0a122b
+void qemu_add_drive_opts(QemuOptsList *list);
0a122b
 int qemu_set_option(const char *str);
0a122b
 int qemu_global_option(const char *str);
0a122b
 void qemu_add_globals(void);
0a122b
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
0a122b
index c70d2dd..8dc0a4c 100644
0a122b
--- a/include/sysemu/sysemu.h
0a122b
+++ b/include/sysemu/sysemu.h
0a122b
@@ -191,6 +191,8 @@ QemuOpts *qemu_get_machine_opts(void);
0a122b
 
0a122b
 bool usb_enabled(bool default_usb);
0a122b
 
0a122b
+extern QemuOptsList qemu_legacy_drive_opts;
0a122b
+extern QemuOptsList qemu_common_drive_opts;
0a122b
 extern QemuOptsList qemu_drive_opts;
0a122b
 extern QemuOptsList qemu_simple_drive_opts;
0a122b
 extern QemuOptsList qemu_chardev_opts;
0a122b
diff --git a/util/qemu-config.c b/util/qemu-config.c
0a122b
index a59568d..04da942 100644
0a122b
--- a/util/qemu-config.c
0a122b
+++ b/util/qemu-config.c
0a122b
@@ -8,6 +8,7 @@
0a122b
 #include "qmp-commands.h"
0a122b
 
0a122b
 static QemuOptsList *vm_config_groups[32];
0a122b
+static QemuOptsList *drive_config_groups[4];
0a122b
 
0a122b
 static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
0a122b
                                Error **errp)
0a122b
@@ -77,6 +78,59 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
0a122b
     return param_list;
0a122b
 }
0a122b
 
0a122b
+/* remove repeated entry from the info list */
0a122b
+static void cleanup_infolist(CommandLineParameterInfoList *head)
0a122b
+{
0a122b
+    CommandLineParameterInfoList *pre_entry, *cur, *del_entry;
0a122b
+
0a122b
+    cur = head;
0a122b
+    while (cur->next) {
0a122b
+        pre_entry = head;
0a122b
+        while (pre_entry != cur->next) {
0a122b
+            if (!strcmp(pre_entry->value->name, cur->next->value->name)) {
0a122b
+                del_entry = cur->next;
0a122b
+                cur->next = cur->next->next;
0a122b
+                g_free(del_entry);
0a122b
+                break;
0a122b
+            }
0a122b
+            pre_entry = pre_entry->next;
0a122b
+        }
0a122b
+        cur = cur->next;
0a122b
+    }
0a122b
+}
0a122b
+
0a122b
+/* merge the description items of two parameter infolists */
0a122b
+static void connect_infolist(CommandLineParameterInfoList *head,
0a122b
+                             CommandLineParameterInfoList *new)
0a122b
+{
0a122b
+    CommandLineParameterInfoList *cur;
0a122b
+
0a122b
+    cur = head;
0a122b
+    while (cur->next) {
0a122b
+        cur = cur->next;
0a122b
+    }
0a122b
+    cur->next = new;
0a122b
+}
0a122b
+
0a122b
+/* access all the local QemuOptsLists for drive option */
0a122b
+static CommandLineParameterInfoList *get_drive_infolist(void)
0a122b
+{
0a122b
+    CommandLineParameterInfoList *head = NULL, *cur;
0a122b
+    int i;
0a122b
+
0a122b
+    for (i = 0; drive_config_groups[i] != NULL; i++) {
0a122b
+        if (!head) {
0a122b
+            head = query_option_descs(drive_config_groups[i]->desc);
0a122b
+        } else {
0a122b
+            cur = query_option_descs(drive_config_groups[i]->desc);
0a122b
+            connect_infolist(head, cur);
0a122b
+        }
0a122b
+    }
0a122b
+    cleanup_infolist(head);
0a122b
+
0a122b
+    return head;
0a122b
+}
0a122b
+
0a122b
 CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option,
0a122b
                                                           const char *option,
0a122b
                                                           Error **errp)
0a122b
@@ -89,7 +143,12 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option,
0a122b
         if (!has_option || !strcmp(option, vm_config_groups[i]->name)) {
0a122b
             info = g_malloc0(sizeof(*info));
0a122b
             info->option = g_strdup(vm_config_groups[i]->name);
0a122b
-            info->parameters = query_option_descs(vm_config_groups[i]->desc);
0a122b
+            if (!strcmp("drive", vm_config_groups[i]->name)) {
0a122b
+                info->parameters = get_drive_infolist();
0a122b
+            } else {
0a122b
+                info->parameters =
0a122b
+                    query_option_descs(vm_config_groups[i]->desc);
0a122b
+            }
0a122b
             entry = g_malloc0(sizeof(*entry));
0a122b
             entry->value = info;
0a122b
             entry->next = conf_list;
0a122b
@@ -109,6 +168,22 @@ QemuOptsList *qemu_find_opts_err(const char *group, Error **errp)
0a122b
     return find_list(vm_config_groups, group, errp);
0a122b
 }
0a122b
 
0a122b
+void qemu_add_drive_opts(QemuOptsList *list)
0a122b
+{
0a122b
+    int entries, i;
0a122b
+
0a122b
+    entries = ARRAY_SIZE(drive_config_groups);
0a122b
+    entries--; /* keep list NULL terminated */
0a122b
+    for (i = 0; i < entries; i++) {
0a122b
+        if (drive_config_groups[i] == NULL) {
0a122b
+            drive_config_groups[i] = list;
0a122b
+            return;
0a122b
+        }
0a122b
+    }
0a122b
+    fprintf(stderr, "ran out of space in drive_config_groups");
0a122b
+    abort();
0a122b
+}
0a122b
+
0a122b
 void qemu_add_opts(QemuOptsList *list)
0a122b
 {
0a122b
     int entries, i;
0a122b
diff --git a/vl.c b/vl.c
0a122b
index deb5884..51300e7 100644
0a122b
--- a/vl.c
0a122b
+++ b/vl.c
0a122b
@@ -2851,6 +2851,9 @@ int main(int argc, char **argv, char **envp)
0a122b
 
0a122b
     qemu_add_opts(&qemu_drive_opts);
0a122b
     qemu_add_opts(&qemu_simple_drive_opts);
0a122b
+    qemu_add_drive_opts(&qemu_legacy_drive_opts);
0a122b
+    qemu_add_drive_opts(&qemu_common_drive_opts);
0a122b
+    qemu_add_drive_opts(&qemu_drive_opts);
0a122b
     qemu_add_opts(&qemu_chardev_opts);
0a122b
     qemu_add_opts(&qemu_device_opts);
0a122b
     qemu_add_opts(&qemu_netdev_opts);
0a122b
-- 
0a122b
1.7.1
0a122b