]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
qom: add new command to search for types
authorAnthony Liguori <aliguori@us.ibm.com>
Thu, 22 Dec 2011 20:40:54 +0000 (14:40 -0600)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 3 Feb 2012 16:41:07 +0000 (10:41 -0600)
This adds a command that allows searching for types that implement a property.
This allows you to do things like search for all available PCIDevices.  In the
future, we'll also have a standard interface for things with a BlockDriverState
property that a PCIDevice could implement.

This will enable search queries like, "any type that implements the BlockDevice
interface" which would allow management tools to present available block devices
without having to hard code device names.  Since an object can implement
multiple interfaces, one device could act both as a BlockDevice and a
NetworkDevice.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qapi-schema.json
qerror.c
qmp-commands.hx
qmp.c

index 80debe679a64577bd104d853cdd3093a8c5cef0f..56a4123b5bb2d1fcbf001c022b55d9a1560990ae 100644 (file)
 # Since: 1.1
 ##
 { 'command': 'block_job_cancel', 'data': { 'device': 'str' } }
+
+##
+# @ObjectTypeInfo:
+#
+# This structure describes a search result from @qom-list-types
+#
+# @name: the type name found in the search
+#
+# Since: 1.1
+#
+# Notes: This command is experimental and may change syntax in future releases.
+##
+{ 'type': 'ObjectTypeInfo',
+  'data': { 'name': 'str' } }
+
+##
+# @qom-list-types:
+#
+# This command will return a list of types given search parameters
+#
+# @implements: if specified, only return types that implement this type name
+#
+# @abstract: if true, include abstract types in the results
+#
+# Returns: a list of @ObjectTypeInfo or an empty list if no results are found
+#
+# Since: 1.1
+#
+# Notes: This command is experimental and may change syntax in future releases.
+##
+{ 'command': 'qom-list-types',
+  'data': { '*implements': 'str', '*abstract': 'bool' },
+  'returns': [ 'ObjectTypeInfo' ] }
index 637eca793c1fe1a134440240e6d30efdbbe3c1e7..3d179c87ea83ad78a17d115e012507d85eb528f4 100644 (file)
--- a/qerror.c
+++ b/qerror.c
@@ -161,7 +161,7 @@ static const QErrorStringTable qerror_table[] = {
     },
     {
         .error_fmt = QERR_INVALID_PARAMETER_TYPE,
-        .desc      = "Invalid parameter type, expected: %(expected)",
+        .desc      = "Invalid parameter type for '%(name)', expected: %(expected)",
     },
     {
         .error_fmt = QERR_INVALID_PARAMETER_VALUE,
index bd6b6410ad9ce9651b05a0733b255846a89617ff..b5e2ab857448275e4b7344b2652e4d43af320664 100644 (file)
@@ -2042,3 +2042,8 @@ EQMP
         .args_type  = "password:s",
         .mhandler.cmd_new = qmp_marshal_input_change_vnc_password,
     },
+    {
+        .name       = "qom-list-types",
+        .args_type  = "implements:s?,abstract:b?",
+        .mhandler.cmd_new = qmp_marshal_input_qom_list_types,
+    },
diff --git a/qmp.c b/qmp.c
index 1222b6c9c4ac83dd323aef450a87879403df3be3..75049ed884da9620e8e65326778e7c0ce8d70a40 100644 (file)
--- a/qmp.c
+++ b/qmp.c
@@ -395,3 +395,30 @@ void qmp_change(const char *device, const char *target,
         qmp_change_blockdev(device, target, has_arg, arg, err);
     }
 }
+
+static void qom_list_types_tramp(ObjectClass *klass, void *data)
+{
+    ObjectTypeInfoList *e, **pret = data;
+    ObjectTypeInfo *info;
+
+    info = g_malloc0(sizeof(*info));
+    info->name = g_strdup(object_class_get_name(klass));
+
+    e = g_malloc0(sizeof(*e));
+    e->value = info;
+    e->next = *pret;
+    *pret = e;
+}
+
+ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
+                                       const char *implements,
+                                       bool has_abstract,
+                                       bool abstract,
+                                       Error **errp)
+{
+    ObjectTypeInfoList *ret = NULL;
+
+    object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
+
+    return ret;
+}