yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qdev-monitor-Group-device_add-help-and-info-qdm-by-c.patch

218e99
From 4729118339de86313e09cb20414ba699510a80cc Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Wed, 6 Nov 2013 14:41:11 +0100
218e99
Subject: [PATCH 35/81] qdev-monitor: Group "device_add help" and "info qdm" by category
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1383748882-22831-7-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 55532
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 06/17] qdev-monitor: Group "device_add help" and "info qdm" by category
218e99
Bugzilla: 1001216
218e99
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
From: Markus Armbruster <armbru@redhat.com>
218e99
218e99
Output is a long, unsorted list.  Not very helpful.  Print one list
218e99
per device category instead, with a header line identifying the
218e99
category, plus a list of uncategorized devices.  Print each list in
218e99
case-insenitive alphabetical order.
218e99
218e99
Devices with multiple categories are listed multiple times.
218e99
218e99
Signed-off-by: Markus Armbruster <armbru@redhat.com>
218e99
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
218e99
Message-id: 1381410021-1538-3-git-send-email-armbru@redhat.com
218e99
Signed-off-by: Anthony Liguori <aliguori@amazon.com>
218e99
(cherry picked from commit a3400aeede46c6c30b6fefb20fc90a43f1f6e7b2)
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 qdev-monitor.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++------------
218e99
 1 file changed, 53 insertions(+), 14 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 qdev-monitor.c |   67 ++++++++++++++++++++++++++++++++++++++++++++-----------
218e99
 1 files changed, 53 insertions(+), 14 deletions(-)
218e99
218e99
diff --git a/qdev-monitor.c b/qdev-monitor.c
218e99
index e54dbc2..aa6a261 100644
218e99
--- a/qdev-monitor.c
218e99
+++ b/qdev-monitor.c
218e99
@@ -75,18 +75,9 @@ static bool qdev_class_has_alias(DeviceClass *dc)
218e99
     return (qdev_class_get_alias(dc) != NULL);
218e99
 }
218e99
 
218e99
-static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
218e99
+static void qdev_print_devinfo(DeviceClass *dc)
218e99
 {
218e99
-    DeviceClass *dc;
218e99
-    bool *show_no_user = opaque;
218e99
-
218e99
-    dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE);
218e99
-
218e99
-    if (!dc || (show_no_user && !*show_no_user && dc->no_user)) {
218e99
-        return;
218e99
-    }
218e99
-
218e99
-    error_printf("name \"%s\"", object_class_get_name(klass));
218e99
+    error_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc)));
218e99
     if (dc->bus_type) {
218e99
         error_printf(", bus %s", dc->bus_type);
218e99
     }
218e99
@@ -102,6 +93,55 @@ static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
218e99
     error_printf("\n");
218e99
 }
218e99
 
218e99
+static gint devinfo_cmp(gconstpointer a, gconstpointer b)
218e99
+{
218e99
+    return strcasecmp(object_class_get_name((ObjectClass *)a),
218e99
+                      object_class_get_name((ObjectClass *)b));
218e99
+}
218e99
+
218e99
+static void qdev_print_devinfos(bool show_no_user)
218e99
+{
218e99
+    static const char *cat_name[DEVICE_CATEGORY_MAX + 1] = {
218e99
+        [DEVICE_CATEGORY_BRIDGE]  = "Controller/Bridge/Hub",
218e99
+        [DEVICE_CATEGORY_USB]     = "USB",
218e99
+        [DEVICE_CATEGORY_STORAGE] = "Storage",
218e99
+        [DEVICE_CATEGORY_NETWORK] = "Network",
218e99
+        [DEVICE_CATEGORY_INPUT]   = "Input",
218e99
+        [DEVICE_CATEGORY_DISPLAY] = "Display",
218e99
+        [DEVICE_CATEGORY_SOUND]   = "Sound",
218e99
+        [DEVICE_CATEGORY_MISC]    = "Misc",
218e99
+        [DEVICE_CATEGORY_MAX]     = "Uncategorized",
218e99
+    };
218e99
+    GSList *list, *elt;
218e99
+    int i;
218e99
+    bool cat_printed;
218e99
+
218e99
+    list = g_slist_sort(object_class_get_list(TYPE_DEVICE, false),
218e99
+                        devinfo_cmp);
218e99
+
218e99
+    for (i = 0; i <= DEVICE_CATEGORY_MAX; i++) {
218e99
+        cat_printed = false;
218e99
+        for (elt = list; elt; elt = elt->next) {
218e99
+            DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt->data,
218e99
+                                                 TYPE_DEVICE);
218e99
+            if ((i < DEVICE_CATEGORY_MAX
218e99
+                 ? !test_bit(i, dc->categories)
218e99
+                 : !bitmap_empty(dc->categories, DEVICE_CATEGORY_MAX))
218e99
+                || (!show_no_user && dc->no_user)) {
218e99
+                continue;
218e99
+            }
218e99
+            if (!cat_printed) {
218e99
+                error_printf("%s%s devices:\n", i ? "\n" : "",
218e99
+                             cat_name[i]);
218e99
+                cat_printed = true;
218e99
+            }
218e99
+            qdev_print_devinfo(dc);
218e99
+        }
218e99
+    }
218e99
+
218e99
+    g_slist_free(list);
218e99
+}
218e99
+
218e99
 static int set_property(const char *name, const char *value, void *opaque)
218e99
 {
218e99
     DeviceState *dev = opaque;
218e99
@@ -147,8 +187,7 @@ int qdev_device_help(QemuOpts *opts)
218e99
 
218e99
     driver = qemu_opt_get(opts, "driver");
218e99
     if (driver && is_help_option(driver)) {
218e99
-        bool show_no_user = false;
218e99
-        object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, &show_no_user);
218e99
+        qdev_print_devinfos(false);
218e99
         return 1;
218e99
     }
218e99
 
218e99
@@ -587,7 +626,7 @@ void do_info_qtree(Monitor *mon, const QDict *qdict)
218e99
 
218e99
 void do_info_qdm(Monitor *mon, const QDict *qdict)
218e99
 {
218e99
-    object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, NULL);
218e99
+    qdev_print_devinfos(true);
218e99
 }
218e99
 
218e99
 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
218e99
-- 
218e99
1.7.1
218e99