From patchwork Sun May 15 19:11:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 67816 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1206584qge; Sun, 15 May 2016 12:16:18 -0700 (PDT) X-Received: by 10.140.159.143 with SMTP id f137mr27190462qhf.61.1463339778636; Sun, 15 May 2016 12:16:18 -0700 (PDT) Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com. [209.132.183.39]) by mx.google.com with ESMTPS id x3si20172434qkd.96.2016.05.15.12.16.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 May 2016 12:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.39 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 mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4FJBiY7040896; Sun, 15 May 2016 15:11:44 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u4FJBYk4006016 for ; Sun, 15 May 2016 15:11:34 -0400 Received: from colepc.redhat.com (ovpn-116-31.phx2.redhat.com [10.3.116.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4FJBVPk015799; Sun, 15 May 2016 15:11:33 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Sun, 15 May 2016 15:11:28 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Andrea Bolognani Subject: [libvirt] [PATCH v2 3/4] 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 | 25 ++++++++++++ .../qemuxml2argv-pci-autofill-addr.xml | 35 ++++++++++++++++ tests/qemuxml2argvtest.c | 1 + .../qemuxml2xmlout-pci-autofill-addr.xml | 41 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 6 files changed, 150 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.7.4 -- 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 9d09b3a..90050ec 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1456,6 +1456,45 @@ qemuDomainAddressFindNewBusNr(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) @@ -1471,6 +1510,10 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPE_PCI_DEVICE; + if (virDomainDeviceInfoIterate(def, qemuDomainPrepPCIAutoAllocate, + NULL) < 0) + goto cleanup; + for (i = 0; i < def->ncontrollers; i++) { if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) { if ((int) def->controllers[i]->idx > max_idx) @@ -1616,6 +1659,10 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, } } + if (virDomainDeviceInfoIterate(def, qemuDomainFinishPCIAutoAllocate, + NULL) < 0) + goto cleanup; + if (obj && obj->privateData) { priv = obj->privateData; if (addrs) { diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.args b/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.args new file mode 100644 index 0000000..ddb8c8d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.args @@ -0,0 +1,25 @@ +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 \ +-no-acpi \ +-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..e5256fe --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-pci-autofill-addr.xml @@ -0,0 +1,35 @@ + + fdr-br + 3ec6cbe1-b5a2-4515-b800-31a61855df41 + 2097152 + 2097152 + 2 + + hvm + + + + /usr/libexec/qemu-kvm + + + + + +
+ + +
+ + +
+ + +