From patchwork Sun May 15 19:11:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 67817 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1206626qge; Sun, 15 May 2016 12:16:29 -0700 (PDT) X-Received: by 10.31.204.196 with SMTP id c187mr13258496vkg.34.1463339789058; Sun, 15 May 2016 12:16:29 -0700 (PDT) Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com. [209.132.183.25]) by mx.google.com with ESMTPS id 23si1774751uav.50.2016.05.15.12.16.28 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 15 May 2016 12:16:29 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 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 mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u4FJBmwt031705; Sun, 15 May 2016 15:11:48 -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 u4FJBXMn006009 for ; Sun, 15 May 2016 15:11:33 -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 u4FJBVPj015799; Sun, 15 May 2016 15:11:32 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Sun, 15 May 2016 15:11:27 -0400 Message-Id: <051db1fce537ae7a7b12416bf9ceb27dbded047f.1463339181.git.crobinso@redhat.com> 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 2/4] domain: Make
request address allocation 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 If a bare device
is specified, set an internal flag address->auto_allocate. Individual hv drivers can then check for this and act on it if they want, nothing is allocated in generic code. If drivers allocate an address, they are expected to unset auto_allocate. Generic domain conf code then checks at the end of PostParse to ensure no device addresses still have auto_allocate set; this ensures we aren't formatting any bogus address XML, and it informs the user if their request didn't work. Add a genericxml2xml test case for this. The auto_allocate property is a part of the generic address structure and not the PCI specific bits, this will make it easier to reuse with other address types too. One note: we detect
by counting its XML properties, rather than comparing specifically against parsed values, which seems easier to maintain. --- docs/formatdomain.html.in | 5 +++- docs/schemas/domaincommon.rng | 5 +++- src/conf/domain_conf.c | 30 +++++++++++++++++++++- src/conf/domain_conf.h | 1 + .../generic-pci-autofill-addr.xml | 27 +++++++++++++++++++ tests/genericxml2xmltest.c | 3 +++ 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/genericxml2xmlindata/generic-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/docs/formatdomain.html.in b/docs/formatdomain.html.in index 58b8cb6..150938d 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2930,7 +2930,10 @@ (since 0.9.7, requires QEMU 0.13). multifunction defaults to 'off', but should be set to 'on' for function 0 of a slot that will - have multiple functions used. + have multiple functions used.
+ Since 1.3.5, some hypervisor drivers + may accept a bare <address type='pci'/> XML block + as an explicit request to allocate a PCI address for the device.
drive
Drive addresses have the following additional diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 8798001..94ffab2 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4538,7 +4538,10 @@ pci - + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1c8d326..fd21dba 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3924,6 +3924,23 @@ virDomainDefPostParseTimer(virDomainDefPtr def) } +static int +virDomainCheckUnallocatedDeviceAddrs(virDomainDefPtr def ATTRIBUTE_UNUSED, + virDomainDeviceDefPtr dev, + virDomainDeviceInfoPtr info, + void *data ATTRIBUTE_UNUSED) +{ + if (!info->auto_allocate) + return 0; + + virReportError(VIR_ERR_INTERNAL_ERROR, + _("driver didn't allocate requested address type '%s' for device '%s'"), + virDomainDeviceAddressTypeToString(info->type), + virDomainDeviceTypeToString(dev->type)); + return -1; +} + + /* Check if a drive type address $controller:$bus:$target:$unit is already * taken by a disk or not. */ @@ -4455,6 +4472,12 @@ virDomainDefPostParse(virDomainDefPtr def, return ret; } + /* Ensure the driver filled in any auto_allocate addresses. + This must come after the assignAddressesCallback */ + if (virDomainDeviceInfoIterate(def, virDomainCheckUnallocatedDeviceAddrs, + NULL) < 0) + return -1; + if (virDomainDefPostParseCheckFeatures(def, xmlopt) < 0) return -1; @@ -5091,8 +5114,13 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, switch ((virDomainDeviceAddressType) info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: - if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0) + if (virXMLPropertyCount(address) == 1) { + /* Bare
is a request to allocate + the address. */ + info->auto_allocate = true; + } else if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0) { goto cleanup; + } break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 02594fe..d347e8f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -347,6 +347,7 @@ struct _virDomainDeviceInfo { */ char *alias; int type; /* virDomainDeviceAddressType */ + bool auto_allocate; union { virPCIDeviceAddress pci; virDomainDeviceDriveAddress drive; diff --git a/tests/genericxml2xmlindata/generic-pci-autofill-addr.xml b/tests/genericxml2xmlindata/generic-pci-autofill-addr.xml new file mode 100644 index 0000000..06eadb6 --- /dev/null +++ b/tests/genericxml2xmlindata/generic-pci-autofill-addr.xml @@ -0,0 +1,27 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + +
+ + +
+ + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 70ecd2d..2c492c3 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -91,6 +91,9 @@ mymain(void) DO_TEST_FULL("name-slash-parse", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); + DO_TEST_FULL("pci-autofill-addr", 0, false, + TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); + virObjectUnref(caps); virObjectUnref(xmlopt);