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 3/4] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives
Date: Thu, 4 Jun 2015 17:20:52 +0100 [thread overview]
Message-ID: <1433434853-19229-4-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1433434853-19229-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 deferral is *not* done for S390 devices, purely to ensure that
we retain backwards compatibility with command lines. We can
change the behaviour for PCI because right now no machine
specifies a block_default_type of IF_VIRTIO except for the
S390 machines.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
blockdev.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 177b285..c480f64 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",
@@ -236,6 +237,17 @@ static void create_implicit_virtio_device(const char *driveid,
if (devaddr) {
qemu_opt_set(devopts, "addr", devaddr, &error_abort);
}
+
+ if (done_orphan_check) {
+ /* If we're called after vl.c has processed the -device options
+ * then 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)
@@ -252,6 +264,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],
@@ -956,8 +976,13 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
goto fail;
}
- if (type == IF_VIRTIO && !done_orphan_check) {
- /* Drives created via the monitor (hotplugged) do not get the
+ if (type == IF_VIRTIO && !done_orphan_check
+ && arch_type == QEMU_ARCH_S390X) {
+ /* Virtio drives created on the command line get an implicit device
+ * created for them. For non-s390x command line drives, the creation
+ * of the implicit device is deferred to drive_check_orphaned. (S390x
+ * is special-cased purely for backwards compatibility.)
+ * Drives created via the monitor (hotplugged) do not get the
* magic implicit device created for them.
*/
create_implicit_virtio_device(qdict_get_str(bs_opts, "id"), devaddr);
--
1.9.1
next prev parent reply other threads:[~2015-06-04 16:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-04 16:20 [Qemu-devel] [PATCH 0/4] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives Peter Maydell
2015-06-04 16:20 ` [Qemu-devel] [PATCH 1/4] blockdev: Factor out create_implicit_virtio_device Peter Maydell
2015-06-04 16:20 ` [Qemu-devel] [PATCH 2/4] blockdev: Don't call create_implicit_virtio_device() when it has no effect Peter Maydell
2015-06-04 16:20 ` Peter Maydell [this message]
2015-06-04 16:20 ` [Qemu-devel] [PATCH 4/4] hw/arm/virt: Make block devices default to virtio Peter Maydell
2015-06-08 8:02 ` [Qemu-devel] [PATCH 0/4] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives Christian Borntraeger
2015-06-08 8:18 ` Christian Borntraeger
2015-06-08 12:37 ` Peter Maydell
2015-06-08 14:18 ` Markus Armbruster
2015-06-08 14:53 ` Peter Maydell
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=1433434853-19229-4-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).