From nobody Wed May 1 19:12:16 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 1506669950018844.796315659163; Fri, 29 Sep 2017 00:25:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C08C2CFEA1; Fri, 29 Sep 2017 07:25:47 +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 06397189B6; Fri, 29 Sep 2017 07:25: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 EE8561855946; Fri, 29 Sep 2017 07:25:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8T766Io031091 for ; Fri, 29 Sep 2017 03:06:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id BF0AA18147; Fri, 29 Sep 2017 07:06:06 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F53418150 for ; Fri, 29 Sep 2017 07:06:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C08C2CFEA1 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: Fri, 29 Sep 2017 09:06:01 +0200 Message-Id: <8d65c733e2fc5fdbac24d51c0a0918af9d740a74.1506668328.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH alt] conf: Allow user define their own alias 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Sep 2017 07:25:48 +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 tag and format it back. For instance:
Signed-off-by: Michal Privoznik --- An alternative approach to: https://www.redhat.com/archives/libvir-list/2017-September/msg00765.html Honestly, I prefer this one as it's simpler and we don't have to care about devices changing their aliases on cold plug. I mean, on cold (un-)plug we'd have to regenerate the aliases so it might be hard to track certain device. But with this approach, it's no problem. Also, I'm not completely convinced about the name of @user attribute. So I'm open for suggestions. docs/schemas/domaincommon.rng | 13 +++++++--- src/conf/device_conf.c | 1 + src/conf/device_conf.h | 1 + src/conf/domain_conf.c | 20 ++++++++++----- tests/genericxml2xmlindata/generic-user-alias.xml | 31 +++++++++++++++++++= ++++ tests/genericxml2xmltest.c | 2 ++ 6 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 tests/genericxml2xmlindata/generic-user-alias.xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index bac371ea3..69c121ce9 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5864,9 +5864,16 @@ - - - + + + + + + + + + + diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index d69f94fad..ced5db123 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->user); 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..08a9e57e3 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; + char *user; /* user defined ID for the device */ int type; /* virDomainDeviceAddressType */ union { virPCIDeviceAddress pci; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87192eb2d..885825226 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5756,6 +5756,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf, virDomainDeviceInfoPtr info, unsigned int flags) { + bool formatAlias =3D info->alias && !(flags & VIR_DOMAIN_DEF_FORMAT_IN= ACTIVE); + if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) { virBufferAsprintf(buf, "bootIndex); =20 @@ -5764,9 +5766,13 @@ virDomainDeviceInfoFormat(virBufferPtr buf, =20 virBufferAddLit(buf, "/>\n"); } - if (info->alias && - !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { - virBufferAsprintf(buf, "\n", info->alias); + if (formatAlias || info->user) { + virBufferAddLit(buf, "alias); + if (info->user) + virBufferAsprintf(buf, " user=3D'%s'", info->user); + virBufferAddLit(buf, "/>\n"); } =20 if (info->mastertype =3D=3D VIR_DOMAIN_CONTROLLER_MASTER_USB) { @@ -6327,7 +6333,6 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE) { if (alias =3D=3D NULL && - !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && virXMLNodeNameEqual(cur, "alias")) { alias =3D cur; } else if (address =3D=3D NULL && @@ -6349,8 +6354,11 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, cur =3D cur->next; } =20 - if (alias) - info->alias =3D virXMLPropString(alias, "name"); + if (alias) { + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + info->alias =3D virXMLPropString(alias, "name"); + info->user =3D virXMLPropString(alias, "user"); + } =20 if (master) { info->mastertype =3D VIR_DOMAIN_CONTROLLER_MASTER_USB; diff --git a/tests/genericxml2xmlindata/generic-user-alias.xml b/tests/gene= ricxml2xmlindata/generic-user-alias.xml new file mode 100644 index 000000000..025924442 --- /dev/null +++ b/tests/genericxml2xmlindata/generic-user-alias.xml @@ -0,0 +1,31 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + + +
+ + + + + + + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 0377a05e9..63a62f6a5 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -130,6 +130,8 @@ mymain(void) DO_TEST_FULL("chardev-reconnect-invalid-mode", 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE); =20 + DO_TEST("user-alias"); + 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