From nobody Sat Apr 27 14:39:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507029927003666.3270187133063; Tue, 3 Oct 2017 04:25:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79272711F9; Tue, 3 Oct 2017 11:25:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33F324F9C3; Tue, 3 Oct 2017 11:25:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 27B4C18355C5; Tue, 3 Oct 2017 11:25:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v93Ax5fl027083 for ; Tue, 3 Oct 2017 06:59:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 45DF46017C; Tue, 3 Oct 2017 10:59:05 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B3E360487 for ; Tue, 3 Oct 2017 10:59:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 79272711F9 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 3 Oct 2017 12:58:57 +0200 Message-Id: <5eb9fbf0497b70a05829f9b0bbdc26ae8886700f.1507028214.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/3] virDomainDeviceInfoParseXML: Separate address parsing into separate func 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 03 Oct 2017 11:25:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There's one 'return' in the middle of the function body. It's very easy to miss and so it makes adding new code harder. Also the function doesn't follow our style 100%. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 174 ++++++++++++++++++++++++++-------------------= ---- 1 file changed, 93 insertions(+), 81 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87192eb2d..0bc2e2f94 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6303,6 +6303,93 @@ virDomainDeviceDimmAddressParseXML(xmlNodePtr node, } =20 =20 +static int +virDomainDeviceAddressParseXML(xmlNodePtr address, + virDomainDeviceInfoPtr info) +{ + int ret =3D -1; + char *type =3D virXMLPropString(address, "type"); + + if (type) { + if ((info->type =3D virDomainDeviceAddressTypeFromString(type)) <= =3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown address type '%s'"), type); + goto cleanup; + } + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("No type specified for device address")); + goto cleanup; + } + + switch ((virDomainDeviceAddressType) info->type) { + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: + if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: + if (virDomainDeviceDriveAddressParseXML(address, &info->addr.drive= ) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL: + if (virDomainDeviceVirtioSerialAddressParseXML + (address, &info->addr.vioserial) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID: + if (virDomainDeviceCcidAddressParseXML(address, &info->addr.ccid) = < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: + if (virDomainDeviceUSBAddressParseXML(address, &info->addr.usb) < = 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: + if (virDomainDeviceSpaprVioAddressParseXML(address, &info->addr.sp= aprvio) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: + if (virDomainDeviceCCWAddressParseXML + (address, &info->addr.ccw) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: + if (virDomainDeviceISAAddressParseXML(address, &info->addr.isa) < = 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: + virReportError(VIR_ERR_XML_ERROR, "%s", + _("virtio-s390 bus doesn't have an address")); + goto cleanup; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: + if (virDomainDeviceDimmAddressParseXML(address, &info->addr.dimm) = < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: + case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: + break; + } + + ret =3D 0; + cleanup: + VIR_FREE(type); + return ret; +} + + /* Parse the XML definition for a device address * @param node XML nodeset to parse for device address definition */ @@ -6319,6 +6406,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, xmlNodePtr boot =3D NULL; xmlNodePtr rom =3D NULL; char *type =3D NULL; + char *rombar =3D NULL; int ret =3D -1; =20 virDomainDeviceInfoClear(info); @@ -6364,102 +6452,26 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, } =20 if (rom) { - char *rombar =3D virXMLPropString(rom, "bar"); - if (rombar && + if ((rombar =3D virXMLPropString(rom, "bar")) && ((info->rombar =3D virTristateSwitchTypeFromString(rombar)) <= =3D 0)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown rom bar value '%s'"), rombar); - VIR_FREE(rombar); goto cleanup; } - VIR_FREE(rombar); info->romfile =3D virXMLPropString(rom, "file"); } =20 - if (!address) - return 0; - - type =3D virXMLPropString(address, "type"); - - if (type) { - if ((info->type =3D virDomainDeviceAddressTypeFromString(type)) <= =3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown address type '%s'"), type); - goto cleanup; - } - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("No type specified for device address")); - goto cleanup; - } - - switch ((virDomainDeviceAddressType) info->type) { - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: - if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: - if (virDomainDeviceDriveAddressParseXML(address, &info->addr.drive= ) < 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL: - if (virDomainDeviceVirtioSerialAddressParseXML - (address, &info->addr.vioserial) < 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID: - if (virDomainDeviceCcidAddressParseXML(address, &info->addr.ccid) = < 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: - if (virDomainDeviceUSBAddressParseXML(address, &info->addr.usb) < = 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: - if (virDomainDeviceSpaprVioAddressParseXML(address, &info->addr.sp= aprvio) < 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: - if (virDomainDeviceCCWAddressParseXML - (address, &info->addr.ccw) < 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: - if (virDomainDeviceISAAddressParseXML(address, &info->addr.isa) < = 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: - virReportError(VIR_ERR_XML_ERROR, "%s", - _("virtio-s390 bus doesn't have an address")); + if (address && + virDomainDeviceAddressParseXML(address, info) < 0) goto cleanup; =20 - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: - if (virDomainDeviceDimmAddressParseXML(address, &info->addr.dimm) = < 0) - goto cleanup; - break; - - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: - case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST: - break; - } =20 ret =3D 0; - cleanup: - if (ret =3D=3D -1) + if (ret < 0) VIR_FREE(info->alias); VIR_FREE(type); + VIR_FREE(rombar); return ret; } =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 14:39:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507028569001163.67650922859946; Tue, 3 Oct 2017 04:02:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47638883CD; Tue, 3 Oct 2017 11:02:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C920C61F28; Tue, 3 Oct 2017 11:02:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9A06A410AE; Tue, 3 Oct 2017 11:02:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v93Ax6Sq027092 for ; Tue, 3 Oct 2017 06:59:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 178E16017C; Tue, 3 Oct 2017 10:59:06 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 934E660475 for ; Tue, 3 Oct 2017 10:59:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 47638883CD Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 3 Oct 2017 12:58:58 +0200 Message-Id: <0f518431df6bd5d150739a4cd141eab2f84d93c9.1507028215.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/3] virDomainDeviceInfoParseXML: Clear whole @info on failure 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 03 Oct 2017 11:02:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, if parsing of device info fails info->alias is freed. It doesn't make much sense to leave the rest of the struct behind. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0bc2e2f94..67095114c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6469,7 +6469,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, ret =3D 0; cleanup: if (ret < 0) - VIR_FREE(info->alias); + virDomainDeviceInfoClear(info); VIR_FREE(type); VIR_FREE(rombar); return ret; --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 14:39:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507029950520826.6436544816287; Tue, 3 Oct 2017 04:25:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5E8AC04B31B; Tue, 3 Oct 2017 11:25:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C2B355D72E; Tue, 3 Oct 2017 11:25:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 74C74410B5; Tue, 3 Oct 2017 11:25:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v93Ax6Vr027102 for ; Tue, 3 Oct 2017 06:59:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id DD73D6017C; Tue, 3 Oct 2017 10:59:06 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 655B160475 for ; Tue, 3 Oct 2017 10:59:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E5E8AC04B31B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 3 Oct 2017 12:58:59 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/3] conf: Allow users to define UUID for devices 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 03 Oct 2017 11:25:49 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1434451 It comes handy for management application to be able to have a per-device label so that it can uniquely identify devices it cares about. The advantage of this approach is that we don't have to generate aliases at define time (non trivial amount of work and problems). The only thing we do is parse the user supplied UUID and format it back. For instance: 1efaf08b-9317-4b0f-b227-912e4bd9f483
Signed-off-by: Michal Privoznik --- This is just a very basic implementation. If I get a green light on this, I= can implement the feature further, i.e. allow device lookup on the UUID. For instance: virsh domiftune fedora $UUID $bandwidth docs/formatdomain.html.in | 21 +++++++++++++++ docs/schemas/domaincommon.rng | 21 ++++++++++----- src/conf/device_conf.c | 1 + src/conf/device_conf.h | 1 + src/conf/domain_conf.c | 25 +++++++++++++++++ tests/genericxml2xmlindata/generic-device-uuid.xml | 31 ++++++++++++++++++= ++++ tests/genericxml2xmltest.c | 1 + 7 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 tests/genericxml2xmlindata/generic-device-uuid.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 5dcf2fedb..b4b2751fd 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -3512,6 +3512,27 @@ =20 +

+ To help management applications identify devices they care about, de= vices + have an optional <uuid/> sub-element which can ho= ld + UUID label generated by the management application. For instance: +

+ +
+  <disk type=3D'block' device=3D'disk'>
+    <driver name=3D'qemu' type=3D'raw'/>
+    <source dev=3D'/dev/HostVG/QEMUGuest1'/>
+    <target dev=3D'hda' bus=3D'ide'/>
+    <uuid>2d0ad0dc-3eaa-4295-9d62-3e531197ed7a</uuid>
+    <address type=3D'drive' controller=3D'0' bus=3D'0' target=3D'0' uni=
t=3D'0'/>
+  </disk>
+
+ +

+ The <uuid/> is available + since 3.9.0. +

+

Virtio-related options

=20

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index bac371ea3..61d8430bb 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5863,12 +5863,21 @@ - - - - - - + + + + + + + + + + + + + + + diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index d69f94fad..a732731eb 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -57,6 +57,7 @@ void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info) { VIR_FREE(info->alias); + VIR_FREE(info->uuid); memset(&info->addr, 0, sizeof(info->addr)); info->type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE; VIR_FREE(info->romfile); diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index f87d6f1fc..f80017291 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -135,6 +135,7 @@ typedef struct _virDomainDeviceInfo virDomainDeviceInfo; typedef virDomainDeviceInfo *virDomainDeviceInfoPtr; struct _virDomainDeviceInfo { char *alias; + unsigned char *uuid; /* user defined UUID for the device, might be = NULL */ int type; /* virDomainDeviceAddressType */ union { virPCIDeviceAddress pci; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 67095114c..2ea26dd9f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5764,11 +5764,18 @@ virDomainDeviceInfoFormat(virBufferPtr buf, =20 virBufferAddLit(buf, "/>\n"); } + if (info->alias && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { virBufferAsprintf(buf, "\n", info->alias); } =20 + if (info->uuid) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(info->uuid, uuidstr); + virBufferAsprintf(buf, "%s\n", uuidstr); + } + if (info->mastertype =3D=3D VIR_DOMAIN_CONTROLLER_MASTER_USB) { virBufferAsprintf(buf, "\n", info->master.usb.startport); @@ -6403,10 +6410,12 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, xmlNodePtr address =3D NULL; xmlNodePtr master =3D NULL; xmlNodePtr alias =3D NULL; + xmlNodePtr uuid =3D NULL; xmlNodePtr boot =3D NULL; xmlNodePtr rom =3D NULL; char *type =3D NULL; char *rombar =3D NULL; + char *uuidstr =3D NULL; int ret =3D -1; =20 virDomainDeviceInfoClear(info); @@ -6418,6 +6427,9 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && virXMLNodeNameEqual(cur, "alias")) { alias =3D cur; + } else if (uuid =3D=3D NULL && + virXMLNodeNameEqual(cur, "uuid")) { + uuid =3D cur; } else if (address =3D=3D NULL && virXMLNodeNameEqual(cur, "address")) { address =3D cur; @@ -6440,6 +6452,18 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, if (alias) info->alias =3D virXMLPropString(alias, "name"); =20 + if (uuid && + (uuidstr =3D virXMLNodeContentString(uuid))) { + if (VIR_ALLOC_N(info->uuid, VIR_UUID_BUFLEN) < 0) + goto cleanup; + + if (virUUIDParse(uuidstr, info->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed uuid element")); + goto cleanup; + } + } + if (master) { info->mastertype =3D VIR_DOMAIN_CONTROLLER_MASTER_USB; if (virDomainDeviceUSBMasterParseXML(master, &info->master.usb) < = 0) @@ -6472,6 +6496,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, virDomainDeviceInfoClear(info); VIR_FREE(type); VIR_FREE(rombar); + VIR_FREE(uuidstr); return ret; } =20 diff --git a/tests/genericxml2xmlindata/generic-device-uuid.xml b/tests/gen= ericxml2xmlindata/generic-device-uuid.xml new file mode 100644 index 000000000..6deac5f9c --- /dev/null +++ b/tests/genericxml2xmlindata/generic-device-uuid.xml @@ -0,0 +1,31 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + 2d0ad0dc-3eaa-4295-9d62-3e531197ed7a +

+ + + 4d21cdd8-ab68-4964-a879-9b9198f9f097 + + + + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 0377a05e9..e0665aa25 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -130,6 +130,7 @@ mymain(void) DO_TEST_FULL("chardev-reconnect-invalid-mode", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); =20 + DO_TEST("device-uuid"); virObjectUnref(caps); virObjectUnref(xmlopt); =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list