From patchwork Tue Mar 8 16:36:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 63692 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2130494lbc; Tue, 8 Mar 2016 08:39:49 -0800 (PST) X-Received: by 10.28.195.136 with SMTP id t130mr15497574wmf.27.1457455188021; Tue, 08 Mar 2016 08:39:48 -0800 (PST) Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com. [209.132.183.39]) by mx.google.com with ESMTPS id cj3si4835024wjc.46.2016.03.08.08.39.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Mar 2016 08:39:47 -0800 (PST) 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 u28GbKCK000986; Tue, 8 Mar 2016 11:37:20 -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 u28GaqR2012388 for ; Tue, 8 Mar 2016 11:36:52 -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 u28GalpU004012; Tue, 8 Mar 2016 11:36:51 -0500 From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 8 Mar 2016 11:36:37 -0500 Message-Id: <0ca25abc9ce0847397068860c18d57f624380e4d.1457454944.git.crobinso@redhat.com> 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 6/8] 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 XML format time to ensure no device addresses still have auto_allocate set; this ensures we aren't formatting any bogus address XML, and informing 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 it's XML properties, rather than comparing specifically against parsed values, which seems easier to maintain. --- docs/schemas/domaincommon.rng | 5 +++- src/conf/domain_conf.c | 29 +++++++++++++++++++++- src/conf/domain_conf.h | 1 + .../generic-pci-autofill-addr.xml | 27 ++++++++++++++++++++ tests/genericxml2xmltest.c | 17 +++++++++---- 5 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 tests/genericxml2xmlindata/generic-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/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 6ca937c..d083250 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4471,7 +4471,10 @@ pci - + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bc4e369..bbc42a4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3827,6 +3827,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; +} + + static int virDomainDefPostParseInternal(virDomainDefPtr def, virCapsPtr caps ATTRIBUTE_UNUSED, @@ -3851,6 +3868,11 @@ virDomainDefPostParseInternal(virDomainDefPtr def, if (virDomainDefPostParseTimer(def) < 0) return -1; + /* ensure the driver filled in any auto_allocate addrs */ + if (virDomainDeviceInfoIterate(def, virDomainCheckUnallocatedDeviceAddrs, + NULL) < 0) + return -1; + if (virDomainDefAddImplicitDevices(def) < 0) return -1; @@ -4872,8 +4894,13 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, switch ((virDomainDeviceAddressType) info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: - if (virDevicePCIAddressParseXML(address, &info->addr.pci) < 0) + if (virXMLPropertyCount(address) == 1) { + /* Bare
is a request to allocate + the address. */ + info->auto_allocate = true; + } else if (virDevicePCIAddressParseXML(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 aba53a2..dd9d0b1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -346,6 +346,7 @@ struct _virDomainDeviceInfo { */ char *alias; int type; /* virDomainDeviceAddressType */ + bool auto_allocate; union { virDevicePCIAddress 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 666fc86..b329d10 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -21,6 +21,7 @@ struct testInfo { const char *name; int different; bool inactive_only; + testCompareDomXML2XMLFlags compare_flags; }; static int @@ -39,7 +40,7 @@ testCompareXMLToXMLHelper(const void *data) ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, info->different ? xml_out : xml_in, - !info->inactive_only, 0, + !info->inactive_only, info->compare_flags, NULL, NULL, 0); cleanup: VIR_FREE(xml_in); @@ -59,21 +60,27 @@ mymain(void) if (!(xmlopt = virTestGenericDomainXMLConfInit())) return EXIT_FAILURE; -#define DO_TEST_FULL(name, is_different, inactive) \ +#define DO_TEST_FULL(name, is_different, inactive, compare_flags) \ do { \ - const struct testInfo info = {name, is_different, inactive}; \ + const struct testInfo info = {name, is_different, \ + inactive, compare_flags}; \ if (virtTestRun("GENERIC XML-2-XML " name, \ testCompareXMLToXMLHelper, &info) < 0) \ ret = -1; \ } while (0) #define DO_TEST(name) \ - DO_TEST_FULL(name, 0, false) + DO_TEST_FULL(name, 0, false, 0) + +#define DO_TEST_PARSE_ERROR(name) \ + DO_TEST_FULL(name, 0, false, \ + TEST_COMPARE_DOM_XML2XML_FLAG_EXPECT_PARSE_ERROR) #define DO_TEST_DIFFERENT(name) \ - DO_TEST_FULL(name, 1, false) + DO_TEST_FULL(name, 1, false, 0) DO_TEST_DIFFERENT("disk-virtio"); + DO_TEST_PARSE_ERROR("pci-autofill-addr"); virObjectUnref(caps); virObjectUnref(xmlopt);