From: Stefano Stabellini <sstabellini@kernel.org>
To: stefanha@gmail.com
Cc: stefanha@redhat.com, peter.maydell@linaro.org,
sstabellini@kernel.org, anthony.perard@citrix.com,
xen-devel@lists.xenproject.org, qemu-devel@nongnu.org,
Juergen Gross <jgross@suse.com>
Subject: [Qemu-devel] [PULL 3/5] qdev: add function qdev_set_id()
Date: Tue, 22 Nov 2016 10:46:07 -0800 [thread overview]
Message-ID: <1479840369-19503-3-git-send-email-sstabellini@kernel.org> (raw)
In-Reply-To: <1479840369-19503-1-git-send-email-sstabellini@kernel.org>
From: Juergen Gross <jgross@suse.com>
In order to have an easy way to add a new qdev with a specific id
carve out the needed functionality from qdev_device_add() into a new
function qdev_set_id().
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
---
include/monitor/qdev.h | 1 +
qdev-monitor.c | 36 ++++++++++++++++++++----------------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index 8e504bc..0ff3331 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -12,5 +12,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
int qdev_device_help(QemuOpts *opts);
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
+void qdev_set_id(DeviceState *dev, const char *id);
#endif
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 4f78ecb..c73410c 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -539,10 +539,28 @@ static BusState *qbus_find(const char *path, Error **errp)
return bus;
}
+void qdev_set_id(DeviceState *dev, const char *id)
+{
+ if (id) {
+ dev->id = id;
+ }
+
+ if (dev->id) {
+ object_property_add_child(qdev_get_peripheral(), dev->id,
+ OBJECT(dev), NULL);
+ } else {
+ static int anon_count;
+ gchar *name = g_strdup_printf("device[%d]", anon_count++);
+ object_property_add_child(qdev_get_peripheral_anon(), name,
+ OBJECT(dev), NULL);
+ g_free(name);
+ }
+}
+
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
{
DeviceClass *dc;
- const char *driver, *path, *id;
+ const char *driver, *path;
DeviceState *dev;
BusState *bus = NULL;
Error *err = NULL;
@@ -591,21 +609,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
qdev_set_parent_bus(dev, bus);
}
- id = qemu_opts_id(opts);
- if (id) {
- dev->id = id;
- }
-
- if (dev->id) {
- object_property_add_child(qdev_get_peripheral(), dev->id,
- OBJECT(dev), NULL);
- } else {
- static int anon_count;
- gchar *name = g_strdup_printf("device[%d]", anon_count++);
- object_property_add_child(qdev_get_peripheral_anon(), name,
- OBJECT(dev), NULL);
- g_free(name);
- }
+ qdev_set_id(dev, qemu_opts_id(opts));
/* set properties */
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
--
1.9.1
next prev parent reply other threads:[~2016-11-22 18:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-22 18:45 [Qemu-devel] [PULL 0/5] xen-20161122-tag Stefano Stabellini
2016-11-22 18:46 ` [Qemu-devel] [PULL 1/5] xen: fix ioreq handling Stefano Stabellini
2016-11-22 18:46 ` [Qemu-devel] [PULL 2/5] xen: add an own bus for xen backend devices Stefano Stabellini
2016-11-22 18:46 ` Stefano Stabellini [this message]
2016-11-22 18:46 ` [Qemu-devel] [PULL 4/5] xen: create qdev for each backend device Stefano Stabellini
2016-11-22 18:46 ` [Qemu-devel] [PULL 5/5] xen: attach pvusb usb bus to backend qdev Stefano Stabellini
2016-11-22 19:31 ` [Qemu-devel] [PULL 0/5] xen-20161122-tag Stefan Hajnoczi
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=1479840369-19503-3-git-send-email-sstabellini@kernel.org \
--to=sstabellini@kernel.org \
--cc=anthony.perard@citrix.com \
--cc=jgross@suse.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
--cc=stefanha@redhat.com \
--cc=xen-devel@lists.xenproject.org \
/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).