From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, patches@linaro.org,
Markus Armbruster <armbru@redhat.com>,
Alexander Graf <agraf@suse.de>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Cornelia Huck <cornelia.huck@de.ibm.com>
Subject: [Qemu-devel] [PATCH v2 2/3] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives
Date: Tue, 9 Jun 2015 18:48:22 +0100 [thread overview]
Message-ID: <1433872103-30642-3-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1433872103-30642-1-git-send-email-peter.maydell@linaro.org>
If a user requests an IF_VIRTIO drive on the command line, don't
create the implicit PCI virtio device immediately, but wait until
the rest of the command line has been processed and only create the
device if the drive would otherwise be orphaned. This means that
if the user said drive,id=something,... -device drive=something,..,.
we'll allow the drive to be connected to the user's specified
device rather than stealing it to connect to the implicit virtio
device.
This change does reorder device creation (which will mean a
migration break, and guest visible changes like which PCI
slot implicitly created devices appear in). We can do this
because no machine currently specifies a block_default_type of
IF_VIRTIO except for the S390 machines, and those machines
do not currently support cross-version migration anyway.
Although at first glance it looks like this commit is changing
the behaviour for hotplugged devices, it is not: although
hotplugged devices used to call the code to create an implicit
virtio device, this had no effect because the code in vl.c to
create devices from the devopts list had already run once and
would not be run again.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
blockdev.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 9cf6123..68cdbfe 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -46,6 +46,7 @@
#include "qmp-commands.h"
#include "trace.h"
#include "sysemu/arch_init.h"
+#include "monitor/qdev.h"
static const char *const if_name[IF_COUNT] = {
[IF_NONE] = "none",
@@ -231,6 +232,15 @@ static void create_implicit_virtio_device(const char *driveid,
if (devaddr) {
qemu_opt_set(devopts, "addr", devaddr, &error_abort);
}
+
+ /* We're called after vl.c has processed the -device options,
+ * so we need to create the device ourselves now.
+ */
+ DeviceState *dev = qdev_device_add(devopts);
+ if (!dev) {
+ exit(1);
+ }
+ object_unref(OBJECT(dev));
}
bool drive_check_orphaned(void)
@@ -245,6 +255,14 @@ bool drive_check_orphaned(void)
/* Unless this is a default drive, this may be an oversight. */
if (!blk_get_attached_dev(blk) && !dinfo->is_default &&
dinfo->type != IF_NONE) {
+ if (dinfo->type == IF_VIRTIO) {
+ /* An orphaned virtio drive might be waiting for us to
+ * create the implicit device for it.
+ */
+ create_implicit_virtio_device(blk_name(blk), dinfo->devaddr);
+ continue;
+ }
+
fprintf(stderr, "Warning: Orphaned drive without device: "
"id=%s,file=%s,if=%s,bus=%d,unit=%d\n",
blk_name(blk), blk_bs(blk)->filename, if_name[dinfo->type],
@@ -949,10 +967,6 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
goto fail;
}
- if (type == IF_VIRTIO) {
- create_implicit_virtio_device(qdict_get_str(bs_opts, "id"), devaddr);
- }
-
filename = qemu_opt_get(legacy_opts, "file");
/* Check werror/rerror compatibility with if=... */
--
1.9.1
next prev parent reply other threads:[~2015-06-09 17:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-09 17:48 [Qemu-devel] [PATCH v2 0/3] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives Peter Maydell
2015-06-09 17:48 ` [Qemu-devel] [PATCH v2 1/3] blockdev: Factor out create_implicit_virtio_device Peter Maydell
2015-06-09 17:48 ` Peter Maydell [this message]
2015-06-09 17:48 ` [Qemu-devel] [PATCH v2 3/3] hw/arm/virt: Make block devices default to virtio Peter Maydell
2015-06-09 18:23 ` [Qemu-devel] [PATCH v2 0/3] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives Peter Maydell
2015-06-20 15:09 ` Markus Armbruster
2015-06-09 19:16 ` Peter Maydell
2015-06-20 15:37 ` Markus Armbruster
2015-06-20 15:00 ` Markus Armbruster
2015-06-20 15:27 ` Peter Maydell
2015-06-20 16:39 ` Markus Armbruster
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=1433872103-30642-3-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=agraf@suse.de \
--cc=armbru@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=kwolf@redhat.com \
--cc=patches@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.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).