qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Juan Quintela <quintela@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	peterx@redhat.com
Subject: [Qemu-devel] [PATCH v3 02/13] qdev: enhance global_prop_list_add()
Date: Mon, 19 Jun 2017 20:49:37 +0800	[thread overview]
Message-ID: <1497876588-947-3-git-send-email-peterx@redhat.com> (raw)
In-Reply-To: <1497876588-947-1-git-send-email-peterx@redhat.com>

Originally it can only alloc new entries and insert. Let it be smarter
that it can update existing fields, and even delete elements. This is
preparation of (finally) the replacement of x86_cpu_apply_props(). If
you see x86_cpu_apply_props(), it allows to skip entries when value is
NULL. Here, it works just like deleting an existing entry.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 hw/core/qdev-properties.c    | 28 +++++++++++++++++++++++++++-
 include/hw/qdev-properties.h | 10 ++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 4b74382..dc3b0ac 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1045,7 +1045,33 @@ static GList *global_props;
 GList *global_prop_list_add(GList *list, const char *driver,
                             const char *property, const char *value)
 {
-    GlobalProperty *p = g_new0(GlobalProperty, 1);
+    GList *l;
+    GlobalProperty *p;
+
+    /* Look up the (property, value) first in the list */
+    for (l = list; l; l = l->next) {
+        p = l->data;
+        if (!strcmp(driver, p->driver) && !strcmp(property, p->property)) {
+            if (value) {
+                /* Modify existing value */
+                p->value = value;
+            } else {
+                /* Delete this entry entirely */
+                list = g_list_remove_link(list, l);
+                g_free(p);
+                g_list_free(l);
+            }
+            return list;
+        }
+    }
+
+    /* Entry not exist. If we are deleting one entry, we're done. */
+    if (!value) {
+        return list;
+    }
+
+    /* If not found and value is set, we try to create a new entry */
+    p = g_new0(GlobalProperty, 1);
 
     /* These properties cannot fail the apply */
     p->errp = &error_abort;
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 15ee6ba..55ad507 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -201,6 +201,16 @@ void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
                                     Property *prop, const char *value);
 
+/*
+ * Register global property on the list. Elements of list should be
+ * GlobalProperty.
+ *
+ * - If (driver, property) is not existing on the list, create a new
+ *   one and link to the list.
+ * - If (driver, property) exists on the list, then:
+ *   - if value != NULL, update with new value
+ *   - if value == NULL, delete the entry
+ */
 GList *global_prop_list_add(GList *list, const char *driver,
                             const char *property, const char *value);
 void register_compat_prop(const char *driver, const char *property,
-- 
2.7.4

  parent reply	other threads:[~2017-06-19 12:50 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-19 12:49 [Qemu-devel] [PATCH v3 00/13] migration: objectify MigrationState Peter Xu
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 01/13] machine: export register_compat_prop() Peter Xu
2017-06-19 14:27   ` Laurent Vivier
2017-06-19 12:49 ` Peter Xu [this message]
2017-06-19 15:24   ` [Qemu-devel] [PATCH v3 02/13] qdev: enhance global_prop_list_add() Eduardo Habkost
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 03/13] qdev: remove qdev_prop_register_global() Peter Xu
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 04/13] accel: introduce AccelState.global_props Peter Xu
2017-06-19 16:17   ` Eduardo Habkost
2017-06-20 13:20     ` Peter Xu
2017-06-20 13:41       ` Eduardo Habkost
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 05/13] tests: avoid check GlobalProperty.used Peter Xu
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 06/13] kvm: let kvm use AccelState.global_props Peter Xu
2017-06-19 16:14   ` Eduardo Habkost
2017-06-20 13:55     ` Peter Xu
2017-06-20 14:07       ` Eduardo Habkost
2017-06-21  3:00         ` Peter Xu
2017-06-21 12:09           ` Eduardo Habkost
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 07/13] tcg: " Peter Xu
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 08/13] trace: add qdev_global_prop_apply Peter Xu
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 09/13] migration: let MigrationState be a qdev Peter Xu
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 10/13] migration: move global_state.optional out Peter Xu
2017-06-19 15:47   ` Juan Quintela
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 11/13] migration: move only_migratable to MigrationState Peter Xu
2017-06-19 15:50   ` Juan Quintela
2017-06-21  3:07     ` Peter Xu
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 12/13] migration: move skip_configuration out Peter Xu
2017-06-19 15:56   ` Juan Quintela
2017-06-21  3:33     ` Peter Xu
2017-06-21  7:28       ` Juan Quintela
2017-06-19 12:49 ` [Qemu-devel] [PATCH v3 13/13] migration: move skip_section_footers Peter Xu
2017-06-19 15:57   ` Juan Quintela
2017-06-19 15:59 ` [Qemu-devel] [PATCH v3 00/13] migration: objectify MigrationState Juan Quintela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1497876588-947-3-git-send-email-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).