@@ -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);
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(-)