From patchwork Tue Jun 9 17:48:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 49669 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 6CFBB245D4 for ; Tue, 9 Jun 2015 17:56:49 +0000 (UTC) Received: by wibdt2 with SMTP id dt2sf6404555wib.3 for ; Tue, 09 Jun 2015 10:56:48 -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=3CJ8xGmVDY7KHz3rfp9Oqkyp+jKMEX9vGwfZK09XG4E=; b=d+w27bIGYTAExZ7PpjL6/RjeicUugj2OVNoHTLLI1RuZ4chRhSWIJYVG5jAsJ+/Zd5 btdYIThQFAHThv2D1rvhI5DVDczqqTlUH7oVSPJsmStvMS4sURnY5fvwAmqzDbyXD4AP bTV4TJRiFWLv2dAnx8cytEOTdTqJhDQEdNlgzTOAhiov2y3+YGa83W4Tgzi4o0aLmT34 HjMns/NnFf2C6UBuEp4ZqslQ4UO2cdpz1v2ou3sgT4hjYzkt6d0A9gtAmJ9ilhXrZCap UvOZWZPVV6Gey6f5NvV0gfm6dKc5E5NweR9hKlK90/g6xyUneY5XXACZP/R63PsY8sZ0 pDhQ== X-Gm-Message-State: ALoCoQkiUodiIPm8ArVIer6TiLsDRr+FYSkQCtc2PB6OL/UjtK6/ghIrEhIdC62EU4rLaaWEMgmh X-Received: by 10.152.26.134 with SMTP id l6mr22782270lag.10.1433872608405; Tue, 09 Jun 2015 10:56:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.103 with SMTP id kx7ls116004lac.62.gmail; Tue, 09 Jun 2015 10:56:48 -0700 (PDT) X-Received: by 10.152.27.230 with SMTP id w6mr14975465lag.111.1433872608261; Tue, 09 Jun 2015 10:56:48 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id n2si6360321lae.61.2015.06.09.10.56.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jun 2015 10:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by labko7 with SMTP id ko7so17442090lab.2 for ; Tue, 09 Jun 2015 10:56:48 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr24203162lbb.56.1433872122884; Tue, 09 Jun 2015 10:48:42 -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 hn6csp2771478lbb; Tue, 9 Jun 2015 10:48:40 -0700 (PDT) X-Received: by 10.152.23.167 with SMTP id n7mr17373687laf.108.1433872106688; Tue, 09 Jun 2015 10:48:26 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id pu2si6342985lbb.69.2015.06.09.10.48.26 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 09 Jun 2015 10:48:26 -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 1Z2NdP-0007yp-Ix; Tue, 09 Jun 2015 18:48:23 +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 v2 2/3] blockdev: Defer creation of implicit PCI devices for IF_VIRTIO drives Date: Tue, 9 Jun 2015 18:48:22 +0100 Message-Id: <1433872103-30642-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1433872103-30642-1-git-send-email-peter.maydell@linaro.org> References: <1433872103-30642-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.51 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 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 --- 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=... */