Patchwork [26/50] qdev: Hide "ptr" properties from users

login
register
mail settings
Submitter Markus Armbruster
Date March 4, 2010, 3:56 p.m.
Message ID <1267718231-13303-27-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/46929/
State New
Headers show

Comments

Markus Armbruster - March 4, 2010, 3:56 p.m.
Users can't set them, so qdev_device_help() shouldn't list them.  Fix
that.  Also make qdev_prop_parse() hide them instead of printing a
meaningless "has no parser" error message.

Their value means nothing to users, so qdev_print_props() shouldn't
print it.  Fix by removing their print method.

Their only use is dirty hacks.  Document that.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/qdev-properties.c |   21 ++++++++-------------
 hw/qdev.c            |   15 +++++++++++++++
 2 files changed, 23 insertions(+), 13 deletions(-)

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 277ff9e..11f7b76 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -399,17 +399,11 @@  PropertyInfo qdev_prop_vlan = {
 
 /* --- pointer --- */
 
-static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
-{
-    void **ptr = qdev_get_prop_ptr(dev, prop);
-    return snprintf(dest, len, "<%p>", *ptr);
-}
-
+/* Not a proper property, just for dirty hacks.  TODO Remove it!  */
 PropertyInfo qdev_prop_ptr = {
     .name  = "ptr",
     .type  = PROP_TYPE_PTR,
     .size  = sizeof(void*),
-    .print = print_ptr,
 };
 
 /* --- mac address --- */
@@ -543,16 +537,17 @@  int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
     Property *prop;
 
     prop = qdev_prop_find(dev, name);
-    if (!prop) {
+    /*
+     * TODO Properties without a parse method are just for dirty
+     * hacks.  qdev_prop_ptr is the only such PropertyInfo.  It's
+     * marked for removal.  The test !prop->info->parse should be
+     * removed along with it.
+     */
+    if (!prop || !prop->info->parse) {
         fprintf(stderr, "property \"%s.%s\" not found\n",
                 dev->info->name, name);
         return -1;
     }
-    if (!prop->info->parse) {
-        fprintf(stderr, "property \"%s.%s\" has no parser\n",
-                dev->info->name, name);
-        return -1;
-    }
     if (prop->info->parse(dev, prop, value) != 0) {
         fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n",
                 dev->info->name, name, value);
diff --git a/hw/qdev.c b/hw/qdev.c
index 5ebf013..1a6f257 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -180,6 +180,15 @@  int qdev_device_help(QemuOpts *opts)
     }
 
     for (prop = info->props; prop && prop->name; prop++) {
+        /*
+         * TODO Properties without a parser are just for dirty hacks.
+         * qdev_prop_ptr is the only such PropertyInfo.  It's marked
+         * for removal.  This conditional should be removed along with
+         * it.
+         */
+        if (!prop->info->parse) {
+            continue;           /* no way to set it, don't show */
+        }
         error_printf("%s.%s=%s\n", info->name, prop->name, prop->info->name);
     }
     return 1;
@@ -682,6 +691,12 @@  static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
     if (!props)
         return;
     while (props->name) {
+        /*
+         * TODO Properties without a print method are just for dirty
+         * hacks.  qdev_prop_ptr is the only such PropertyInfo.  It's
+         * marked for removal.  The test props->info->print should be
+         * removed along with it.
+         */
         if (props->info->print) {
             props->info->print(dev, props, buf, sizeof(buf));
             qdev_printf("%s-prop: %s = %s\n", prefix, props->name, buf);