From nobody Thu May 15 13:25:59 2025 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