From patchwork Thu Jun 4 16:20:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 49536 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A03152154F for ; Thu, 4 Jun 2015 16:21:14 +0000 (UTC) Received: by wibut5 with SMTP id ut5sf14951003wib.0 for ; Thu, 04 Jun 2015 09:21:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=0YYA1WjiofwoOqgJ9b+KW5iX2XTF1SdC+h9LGy6WXAk=; b=bUIWeuDWVhbJ+DbNxVllP/DFpJcg8TFVl1PzSuEEgEf1i0x256D/1LeWaBt3WpVbVF +VlErqXk5PGxvo1LHdSkkaItR4HPAzVPYQQhCm/BELW1du3GNIvChaEQj+6zQM0KBW6i ONe/c58fcaPKeO1Vj7kaiwixPX6B2QqJRad431v1Up2iYBCXz2gqZJu5w/+VFCN8eDzU MUU/j/uDkhzpF003mCDQ6XWbyeS18ZewM6bEgVRtyjIaRU/WMinQazK+uKFaqH3WXK/N Rs3UA1lPfMQXQCBDgDfc6vCZ/udxHWFFqFsum74Y/Pu7+DgAxs23I8uvXgB7k4DcE8I3 663w== X-Gm-Message-State: ALoCoQkyJ9WGEbKDzjUbN8v0HW3Vn22wL3+4V+D3AWs/qRRnDLXBxw5lUrRX8RpO5BSrSpebpRca X-Received: by 10.112.122.13 with SMTP id lo13mr22241320lbb.5.1433434873918; Thu, 04 Jun 2015 09:21:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.226 with SMTP id q2ls235346lae.73.gmail; Thu, 04 Jun 2015 09:21:13 -0700 (PDT) X-Received: by 10.112.190.10 with SMTP id gm10mr37170286lbc.2.1433434873779; Thu, 04 Jun 2015 09:21:13 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id v10si2267832laz.27.2015.06.04.09.21.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2015 09:21:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by labpy14 with SMTP id py14so35812407lab.0 for ; Thu, 04 Jun 2015 09:21:13 -0700 (PDT) X-Received: by 10.112.182.4 with SMTP id ea4mr33628083lbc.35.1433434873337; Thu, 04 Jun 2015 09:21:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp729233lbb; Thu, 4 Jun 2015 09:21:12 -0700 (PDT) X-Received: by 10.68.133.131 with SMTP id pc3mr32486328pbb.107.1433434861488; Thu, 04 Jun 2015 09:21:01 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id ed4si6541185pbc.132.2015.06.04.09.20.59 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 04 Jun 2015 09:21:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Z0Xsz-00050o-Ur; Thu, 04 Jun 2015 17:20:53 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Markus Armbruster , Kevin Wolf , qemu-block@nongnu.org, Christian Borntraeger , Cornelia Huck , Alexander Graf Subject: [PATCH 3/4] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives Date: Thu, 4 Jun 2015 17:20:52 +0100 Message-Id: <1433434853-19229-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1433434853-19229-1-git-send-email-peter.maydell@linaro.org> References: <1433434853-19229-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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);