yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qemu-help-Sort-devices-by-logical-functionality.patch

218e99
From 28b2998fb1285514c2c342d174a36330734cd79c Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Wed, 6 Nov 2013 14:41:08 +0100
218e99
Subject: [PATCH 32/81] qemu-help: Sort devices by logical functionality
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1383748882-22831-4-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 55529
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 03/17] qemu-help: Sort devices by logical functionality
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: Marcel Apfelbaum <marcel.a@redhat.com>
218e99
218e99
Categorize devices that appear as output to "-device ?" command
218e99
by logical functionality. Sort the devices by logical categories
218e99
before showing them to user.
218e99
218e99
The sort is done by functionality rather than alphabetical.
218e99
218e99
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
218e99
Message-id: 1375107465-25767-3-git-send-email-marcel.a@redhat.com
218e99
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
218e99
(cherry picked from commit 3d1237fb2ab4edb926c717767bb5e31d6053a7c5)
218e99
Signed-off-by: Markus Armbruster <armbru@redhat.com>
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 include/hw/qdev-core.h | 29 +++++++++++++++++++++++++++++
218e99
 qdev-monitor.c         | 48 +++++++++++++++++++++++++++++++++++++++---------
218e99
 2 files changed, 68 insertions(+), 9 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 include/hw/qdev-core.h |   29 +++++++++++++++++++++++++++++
218e99
 qdev-monitor.c         |   48 +++++++++++++++++++++++++++++++++++++++---------
218e99
 2 files changed, 68 insertions(+), 9 deletions(-)
218e99
218e99
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
218e99
index 9d995bf..18596e9 100644
218e99
--- a/include/hw/qdev-core.h
218e99
+++ b/include/hw/qdev-core.h
218e99
@@ -18,6 +18,34 @@ enum {
218e99
 #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
218e99
 #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
218e99
 
218e99
+typedef enum DeviceCategory {
218e99
+    DEVICE_CATEGORY_BRIDGE,
218e99
+    DEVICE_CATEGORY_USB,
218e99
+    DEVICE_CATEGORY_STORAGE,
218e99
+    DEVICE_CATEGORY_NETWORK,
218e99
+    DEVICE_CATEGORY_INPUT,
218e99
+    DEVICE_CATEGORY_DISPLAY,
218e99
+    DEVICE_CATEGORY_SOUND,
218e99
+    DEVICE_CATEGORY_MISC,
218e99
+    DEVICE_CATEGORY_MAX
218e99
+} DeviceCategory;
218e99
+
218e99
+static inline const char *qdev_category_get_name(DeviceCategory category)
218e99
+{
218e99
+    static const char *category_names[DEVICE_CATEGORY_MAX] = {
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
+    };
218e99
+
218e99
+    return category_names[category];
218e99
+};
218e99
+
218e99
 typedef int (*qdev_initfn)(DeviceState *dev);
218e99
 typedef int (*qdev_event)(DeviceState *dev);
218e99
 typedef void (*qdev_resetfn)(DeviceState *dev);
218e99
@@ -81,6 +109,7 @@ typedef struct DeviceClass {
218e99
     ObjectClass parent_class;
218e99
     /*< public >*/
218e99
 
218e99
+    DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX);
218e99
     const char *fw_name;
218e99
     const char *desc;
218e99
     Property *props;
218e99
diff --git a/qdev-monitor.c b/qdev-monitor.c
218e99
index e54dbc2..230a8df 100644
218e99
--- a/qdev-monitor.c
218e99
+++ b/qdev-monitor.c
218e99
@@ -75,24 +75,27 @@ 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_class_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
+    DeviceCategory category;
218e99
 
218e99
-    if (!dc || (show_no_user && !*show_no_user && dc->no_user)) {
218e99
+    if (!dc) {
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
     if (qdev_class_has_alias(dc)) {
218e99
         error_printf(", alias \"%s\"", qdev_class_get_alias(dc));
218e99
     }
218e99
+    error_printf(", categories");
218e99
+    for (category = 0; category < DEVICE_CATEGORY_MAX; ++category) {
218e99
+        if (test_bit(category, dc->categories)) {
218e99
+            error_printf(" \"%s\"", qdev_category_get_name(category));
218e99
+        }
218e99
+    }
218e99
     if (dc->desc) {
218e99
         error_printf(", desc \"%s\"", dc->desc);
218e99
     }
218e99
@@ -102,6 +105,15 @@ static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
218e99
     error_printf("\n");
218e99
 }
218e99
 
218e99
+static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
218e99
+{
218e99
+    DeviceClass *dc;
218e99
+
218e99
+    dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE);
218e99
+
218e99
+    qdev_print_class_devinfo(dc);
218e99
+}
218e99
+
218e99
 static int set_property(const char *name, const char *value, void *opaque)
218e99
 {
218e99
     DeviceState *dev = opaque;
218e99
@@ -139,6 +151,21 @@ static const char *find_typename_by_alias(const char *alias)
218e99
     return NULL;
218e99
 }
218e99
 
218e99
+static void qdev_print_category_devices(DeviceCategory category)
218e99
+{
218e99
+    DeviceClass *dc;
218e99
+    GSList *list, *curr;
218e99
+
218e99
+    list = object_class_get_list(TYPE_DEVICE, false);
218e99
+    for (curr = list; curr; curr = g_slist_next(curr)) {
218e99
+        dc = (DeviceClass *)object_class_dynamic_cast(curr->data, TYPE_DEVICE);
218e99
+        if (!dc->no_user && test_bit(category, dc->categories)) {
218e99
+            qdev_print_class_devinfo(dc);
218e99
+        }
218e99
+    }
218e99
+    g_slist_free(list);
218e99
+}
218e99
+
218e99
 int qdev_device_help(QemuOpts *opts)
218e99
 {
218e99
     const char *driver;
218e99
@@ -147,8 +174,11 @@ 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
+        DeviceCategory category;
218e99
+        for (category = 0; category < DEVICE_CATEGORY_MAX; ++category) {
218e99
+            qdev_print_category_devices(category);
218e99
+        }
218e99
+
218e99
         return 1;
218e99
     }
218e99
 
218e99
-- 
218e99
1.7.1
218e99