From patchwork Tue Mar 8 16:36:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 63695 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2130810lbc; Tue, 8 Mar 2016 08:40:24 -0800 (PST) X-Received: by 10.129.134.133 with SMTP id w127mr14995228ywf.252.1457455211670; Tue, 08 Mar 2016 08:40:11 -0800 (PST) Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com. [209.132.183.24]) by mx.google.com with ESMTPS id t188si1196689ywd.26.2016.03.08.08.40.10 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 08 Mar 2016 08:40:11 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u28GbVKZ002753; Tue, 8 Mar 2016 11:37:31 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u28Gar8k012396 for ; Tue, 8 Mar 2016 11:36:53 -0500 Received: from colepc.redhat.com (ovpn-113-126.phx2.redhat.com [10.3.113.126]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u28GalpV004012; Tue, 8 Mar 2016 11:36:52 -0500 From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 8 Mar 2016 11:36:38 -0500 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: Andrea Bolognani Subject: [libvirt] [PATCH 7/8] qemu: Wire up address type=pci auto_allocate X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com We do this in 2 passes: before PCI addresses are about to be collected, we convert type=pci auto_allocate=true to type=none auto_allocate=true, since the existing code is already expecting type=none here. After all PCI allocation should be complete, we do another pass of the device addresses converting type=pci auto_allocate=true to auto_allocate=false, so we don't trigger the unallocated address validation check in generic domain code. --- src/qemu/qemu_domain_address.c | 47 ++++++++++++++++++++++ .../qemuxml2argv-pci-autofill-addr.args | 24 +++++++++++ .../qemuxml2argv-pci-autofill-addr.xml | 44 ++++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + .../qemuxml2xmlout-pci-autofill-addr.xml | 46 +++++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 6 files changed, 163 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-pci-autofill-addr.xml -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index eff33fc..74d13b6 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1399,6 +1399,45 @@ qemuDomainSupportsPCI(virDomainDefPtr def, static int +qemuDomainPrepPCIAutoAllocate(virDomainDefPtr def ATTRIBUTE_UNUSED, + virDomainDeviceDefPtr device ATTRIBUTE_UNUSED, + virDomainDeviceInfoPtr info, + void *opaque ATTRIBUTE_UNUSED) +{ + /* If PCI auto_allocate requested, set type to NONE since the rest + of the code expects it. */ + if (info->auto_allocate && + info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) + info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE; + + return 0; +} + + +static int +qemuDomainFinishPCIAutoAllocate(virDomainDefPtr def ATTRIBUTE_UNUSED, + virDomainDeviceDefPtr device ATTRIBUTE_UNUSED, + virDomainDeviceInfoPtr info, + void *opaque ATTRIBUTE_UNUSED) +{ + /* A PCI device was allocated as requested, unset auto_allocate so + we don't trip the domain error about unallocated addresses */ + if (info->auto_allocate && + info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) + info->auto_allocate = false; + + /* We wanted to allocate a PCI address but it was never filled in... + this is likely an XML error. Re-set type=PCI to give a correct + error from domain conf */ + if (info->auto_allocate && + info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) + info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + + return 0; +} + + +static int qemuDomainAssignPCIAddresses(virDomainDefPtr def, virQEMUCapsPtr qemuCaps, virDomainObjPtr obj) @@ -1423,6 +1462,10 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, } } + if (virDomainDeviceInfoIterate(def, qemuDomainPrepPCIAutoAllocate, + NULL) < 0) + goto cleanup; + nbuses = max_idx + 1; if (nbuses > 0 && @@ -1553,6 +1596,10 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, } } } + + if (virDomainDeviceInfoIterate(def, qemuDomainFinishPCIAutoAllocate, + NULL) < 0) + goto cleanup; } if (obj && obj->privateData) { diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.args b/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.args new file mode 100644 index 0000000..2ab305e --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.args @@ -0,0 +1,24 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/libexec/qemu-kvm \ +-name fdr-br \ +-S \ +-M pc-1.2 \ +-m 2048 \ +-smp 2 \ +-uuid 3ec6cbe1-b5a2-4515-b800-31a61855df41 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-fdr-br/monitor.sock,server,nowait \ +-boot c \ +-usb \ +-drive file=/var/iso/f18kde.iso,format=raw,if=none,media=cdrom,\ +id=drive-virtio-disk0 \ +-device virtio-blk-pci,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,\ +id=virtio-disk0 \ +-vga cirrus \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.xml b/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.xml new file mode 100644 index 0000000..8e7b6ab --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.xml @@ -0,0 +1,44 @@ + + fdr-br + 3ec6cbe1-b5a2-4515-b800-31a61855df41 + 2097152 + 2097152 + 2 + + hvm + + + + + + + + + destroy + restart + restart + + /usr/libexec/qemu-kvm + + + + + +
+ + +
+ + +
+ + +