From nobody Thu May 2 06:12:48 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 1513243898956201.04021043850253; Thu, 14 Dec 2017 01:31:38 -0800 (PST) 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 7EA8181DE8; Thu, 14 Dec 2017 09:31:37 +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 15DF318174; Thu, 14 Dec 2017 09:31:37 +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 CAAEB4BB79; Thu, 14 Dec 2017 09:31:36 +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 vBE9VQDd016772 for ; Thu, 14 Dec 2017 04:31:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 542B07EE9D; Thu, 14 Dec 2017 09:31:26 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2397D7EE9B; Thu, 14 Dec 2017 09:31:24 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Dec 2017 10:30:49 +0100 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 Cc: mprivozn@redhat.com, Peter Krempa Subject: [libvirt] [PATCH 1/3] conf: Add infrastructure for disk source private data XML 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.25]); Thu, 14 Dec 2017 09:31:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" VM drivers may need to store additional private data to the status XML so that it can be restored after libvirtd restart. Since not everything is needed add a callback infrastructure, where VM drivers can add only stuff they need. Note that the private data is formatted as a sub-element of the or sub-element. This is done since storing it out of band (in the VM private data) would require a complex matching process to allow to put the data into correct place. --- src/conf/domain_conf.c | 136 ++++++++++++++++++++++++++++++++++------= ---- src/conf/domain_conf.h | 17 +++++- src/conf/snapshot_conf.c | 18 +++--- src/network/bridge_driver.c | 2 +- src/qemu/qemu_domain.c | 2 +- tests/qemublocktest.c | 4 +- tests/virstoragetest.c | 2 +- 7 files changed, 136 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 66e21c4bdb..9a62bc472c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8553,11 +8553,43 @@ virDomainDiskSourceEncryptionParse(xmlNodePtr node, } +static int +virDomainDiskSourcePrivateDataParse(xmlXPathContextPtr ctxt, + virStorageSourcePtr src, + unsigned int flags, + virDomainXMLOptionPtr xmlopt) +{ + xmlNodePtr saveNode =3D ctxt->node; + xmlNodePtr node; + int ret =3D -1; + + if (!(flags & VIR_DOMAIN_DEF_PARSE_STATUS) || + !xmlopt || !xmlopt->privateData.storageParse) + return 0; + + if (!(node =3D virXPathNode("./privateData", ctxt))) + return 0; + + ctxt->node =3D node; + + if (xmlopt->privateData.storageParse(ctxt, src) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + ctxt->node =3D saveNode; + + return ret; +} + + int virDomainDiskSourceParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virStorageSourcePtr src, - unsigned int flags) + unsigned int flags, + virDomainXMLOptionPtr xmlopt) { int ret =3D -1; xmlNodePtr saveNode =3D ctxt->node; @@ -8596,6 +8628,9 @@ virDomainDiskSourceParse(xmlNodePtr node, if (virDomainDiskSourceEncryptionParse(node, &src->encryption) < 0) goto cleanup; + if (virDomainDiskSourcePrivateDataParse(ctxt, src, flags, xmlopt) < 0) + goto cleanup; + /* People sometimes pass a bogus '' source path when they mean to omit= the * source element completely (e.g. CDROM without media). This is just a * little compatibility check to help those broken apps */ @@ -8613,7 +8648,8 @@ virDomainDiskSourceParse(xmlNodePtr node, static int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, virStorageSourcePtr src, - unsigned int flags) + unsigned int flags, + virDomainXMLOptionPtr xmlopt) { virStorageSourcePtr backingStore =3D NULL; xmlNodePtr save_ctxt =3D ctxt->node; @@ -8671,8 +8707,8 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, goto cleanup; } - if (virDomainDiskSourceParse(source, ctxt, backingStore, flags) < 0 || - virDomainDiskBackingStoreParse(ctxt, backingStore, flags) < 0) + if (virDomainDiskSourceParse(source, ctxt, backingStore, flags, xmlopt= ) < 0 || + virDomainDiskBackingStoreParse(ctxt, backingStore, flags, xmlopt) = < 0) goto cleanup; VIR_STEAL_PTR(src->backingStore, backingStore); @@ -8774,7 +8810,8 @@ static int virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, xmlNodePtr cur, xmlXPathContextPtr ctxt, - unsigned int flags) + unsigned int flags, + virDomainXMLOptionPtr xmlopt) { xmlNodePtr mirrorNode; char *mirrorFormat =3D NULL; @@ -8812,7 +8849,8 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, goto cleanup; } - if (virDomainDiskSourceParse(mirrorNode, ctxt, def->mirror, flags)= < 0) + if (virDomainDiskSourceParse(mirrorNode, ctxt, def->mirror, + flags, xmlopt) < 0) goto cleanup; } else { /* For back-compat reasons, we handle a file name @@ -9238,7 +9276,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, if (!source && virXMLNodeNameEqual(cur, "source")) { sourceNode =3D cur; - if (virDomainDiskSourceParse(cur, ctxt, def->src, flags) < 0) + if (virDomainDiskSourceParse(cur, ctxt, def->src, flags, xmlop= t) < 0) goto error; /* If we've already found an as a child of and @@ -9319,7 +9357,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } else if (!def->mirror && virXMLNodeNameEqual(cur, "mirror") && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { - if (virDomainDiskDefMirrorParse(def, cur, ctxt, flags) < 0) + if (virDomainDiskDefMirrorParse(def, cur, ctxt, flags, xmlopt)= < 0) goto error; } else if (!authdef && virXMLNodeNameEqual(cur, "auth")) { @@ -9590,7 +9628,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, product =3D NULL; if (!(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) { - if (virDomainDiskBackingStoreParse(ctxt, def->src, flags) < 0) + if (virDomainDiskBackingStoreParse(ctxt, def->src, flags, xmlopt) = < 0) goto error; } @@ -22356,12 +22394,43 @@ virDomainDiskSourceFormatNetwork(virBufferPtr att= rBuf, } +static int +virDomainDiskSourceFormatPrivateData(virBufferPtr buf, + virStorageSourcePtr src, + unsigned int flags, + virDomainXMLOptionPtr xmlopt) +{ + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) || + !xmlopt || !xmlopt->privateData.storageFormat) + return 0; + + virBufferSetChildIndent(&childBuf, buf); + + if (xmlopt->privateData.storageFormat(src, &childBuf) < 0) + goto cleanup; + + if (virXMLFormatElement(buf, "privateData", NULL, &childBuf) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&childBuf); + + return ret; +} + + static int virDomainDiskSourceFormatInternal(virBufferPtr buf, virStorageSourcePtr src, int policy, unsigned int flags, - bool skipSeclabels) + bool skipSeclabels, + virDomainXMLOptionPtr xmlopt) { const char *startupPolicy =3D NULL; virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; @@ -22443,6 +22512,9 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf, virStorageEncryptionFormat(&childBuf, src->encryption) < 0) return -1; + if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xm= lopt) < 0) + return -1; + if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) goto error; } @@ -22460,15 +22532,18 @@ int virDomainDiskSourceFormat(virBufferPtr buf, virStorageSourcePtr src, int policy, - unsigned int flags) + unsigned int flags, + virDomainXMLOptionPtr xmlopt) { - return virDomainDiskSourceFormatInternal(buf, src, policy, flags, fals= e); + return virDomainDiskSourceFormatInternal(buf, src, policy, flags, fals= e, xmlopt); } static int virDomainDiskBackingStoreFormat(virBufferPtr buf, - virStorageSourcePtr backingStore) + virStorageSourcePtr backingStore, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) { const char *format; @@ -22497,9 +22572,9 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, virBufferAsprintf(buf, "\n", format); /* We currently don't output seclabels for backing chain element */ - if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, 0, true) <= 0 || - virDomainDiskBackingStoreFormat(buf, - backingStore->backingStore) < 0) + if (virDomainDiskSourceFormatInternal(buf, backingStore, 0, flags, tru= e, xmlopt) < 0 || + virDomainDiskBackingStoreFormat(buf, backingStore->backingStore, + xmlopt, flags) < 0) return -1; virBufferAdjustIndent(buf, -2); @@ -22517,7 +22592,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, static int virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, - unsigned int flags) + unsigned int flags, + virDomainXMLOptionPtr xmlopt) { const char *type =3D virStorageTypeToString(def->src->type); const char *device =3D virDomainDiskDeviceTypeToString(def->device); @@ -22630,13 +22706,14 @@ virDomainDiskDefFormat(virBufferPtr buf, } if (virDomainDiskSourceFormat(buf, def->src, def->startupPolicy, - flags) < 0) + flags, xmlopt) < 0) return -1; /* Don't format backingStore to inactive XMLs until the code for * persistent storage of backing chains is ready. */ if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) && - virDomainDiskBackingStoreFormat(buf, def->src->backingStore) < 0) + virDomainDiskBackingStoreFormat(buf, def->src->backingStore, + xmlopt, flags) < 0) return -1; virBufferEscapeString(buf, "\n", def->doma= in_name); @@ -22673,7 +22750,7 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); virBufferEscapeString(buf, "\n", formatStr); - if (virDomainDiskSourceFormat(buf, def->mirror, 0, 0) < 0) + if (virDomainDiskSourceFormat(buf, def->mirror, 0, 0, xmlopt) < 0) return -1; virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); @@ -25904,7 +25981,8 @@ int virDomainDefFormatInternal(virDomainDefPtr def, virCapsPtr caps, unsigned int flags, - virBufferPtr buf) + virBufferPtr buf, + virDomainXMLOptionPtr xmlopt) { unsigned char *uuid; char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -25959,10 +26037,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, * but no leading indentation before the starting element. * Thankfully, libxml maps what looks like globals into * thread-local uses, so we are thread-safe. */ - xmlIndentTreeOutput =3D 1; - xmlbuf =3D xmlBufferCreate(); - if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + xmlIndentTreeOutput =3D 1; + xmlbuf =3D xmlBufferCreate(); + if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, + virBufferGetIndent(buf, false) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput =3D oldIndentTreeOutput; goto error; @@ -26535,7 +26613,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, def->emulator); for (n =3D 0; n < def->ndisks; n++) - if (virDomainDiskDefFormat(buf, def->disks[n], flags) < 0) + if (virDomainDiskDefFormat(buf, def->disks[n], flags, xmlopt) < 0) goto error; for (n =3D 0; n < def->ncontrollers; n++) @@ -26722,7 +26800,7 @@ virDomainDefFormat(virDomainDefPtr def, virCapsPtr = caps, unsigned int flags) virBuffer buf =3D VIR_BUFFER_INITIALIZER; virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS, NULL); - if (virDomainDefFormatInternal(def, caps, flags, &buf) < 0) + if (virDomainDefFormatInternal(def, caps, flags, &buf, NULL) < 0) return NULL; return virBufferContentAndReset(&buf); @@ -26757,7 +26835,7 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt, xmlopt->privateData.format(&buf, obj) < 0) goto error; - if (virDomainDefFormatInternal(obj->def, caps, flags, &buf) < 0) + if (virDomainDefFormatInternal(obj->def, caps, flags, &buf, xmlopt) < = 0) goto error; virBufferAdjustIndent(&buf, -2); @@ -27711,7 +27789,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, switch ((virDomainDeviceType) src->type) { case VIR_DOMAIN_DEVICE_DISK: - rc =3D virDomainDiskDefFormat(&buf, src->data.disk, flags); + rc =3D virDomainDiskDefFormat(&buf, src->data.disk, flags, xmlopt); break; case VIR_DOMAIN_DEVICE_LEASE: rc =3D virDomainLeaseDefFormat(&buf, src->data.lease); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 59f250ac96..6f7f96b3dd 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2631,6 +2631,12 @@ typedef int (*virDomainXMLPrivateDataParseFunc)(xmlX= PathContextPtr, virDomainObjPtr, virDomainDefParserConfigPt= r); +typedef int (*virDomainXMLPrivateDataStorageSourceParseFunc)(xmlXPathConte= xtPtr ctxt, + virStorageSou= rcePtr src); +typedef int (*virDomainXMLPrivateDataStorageSourceFormatFunc)(virStorageSo= urcePtr src, + virBufferPtr= buf); + + typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCa= llbacks; typedef virDomainXMLPrivateDataCallbacks *virDomainXMLPrivateDataCallbacks= Ptr; struct _virDomainXMLPrivateDataCallbacks { @@ -2643,6 +2649,8 @@ struct _virDomainXMLPrivateDataCallbacks { virDomainXMLPrivateDataNewFunc chrSourceNew; virDomainXMLPrivateDataFormatFunc format; virDomainXMLPrivateDataParseFunc parse; + virDomainXMLPrivateDataStorageSourceParseFunc storageParse; + virDomainXMLPrivateDataStorageSourceFormatFunc storageFormat; }; typedef bool (*virDomainABIStabilityDomain)(const virDomainDef *src, @@ -2967,12 +2975,14 @@ char *virDomainObjFormat(virDomainXMLOptionPtr xmlo= pt, int virDomainDefFormatInternal(virDomainDefPtr def, virCapsPtr caps, unsigned int flags, - virBufferPtr buf); + virBufferPtr buf, + virDomainXMLOptionPtr xmlopt); int virDomainDiskSourceFormat(virBufferPtr buf, virStorageSourcePtr src, int policy, - unsigned int flags); + unsigned int flags, + virDomainXMLOptionPtr xmlopt); int virDomainNetDefFormat(virBufferPtr buf, virDomainNetDefPtr def, @@ -3021,7 +3031,8 @@ virDomainDiskRemoveByName(virDomainDefPtr def, const = char *name); int virDomainDiskSourceParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virStorageSourcePtr src, - unsigned int flags); + unsigned int flags, + virDomainXMLOptionPtr xmlopt); int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net); virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *devic= e); diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index f0e852c92b..d7b086242b 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -110,7 +110,8 @@ static int virDomainSnapshotDiskDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt, virDomainSnapshotDiskDefPtr def, - unsigned int flags) + unsigned int flags, + virDomainXMLOptionPtr xmlopt) { int ret =3D -1; char *snapshot =3D NULL; @@ -155,7 +156,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, } if ((cur =3D virXPathNode("./source", ctxt)) && - virDomainDiskSourceParse(cur, ctxt, def->src, flags) < 0) + virDomainDiskSourceParse(cur, ctxt, def->src, flags, xmlopt) < 0) goto cleanup; if ((driver =3D virXPathString("string(./driver/@type)", ctxt))) { @@ -348,8 +349,8 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, goto cleanup; def->ndisks =3D n; for (i =3D 0; i < def->ndisks; i++) { - if (virDomainSnapshotDiskDefParseXML(nodes[i], ctxt, - &def->disks[i], flags) < = 0) + if (virDomainSnapshotDiskDefParseXML(nodes[i], ctxt, &def->dis= ks[i], + flags, xmlopt) < 0) goto cleanup; } VIR_FREE(nodes); @@ -663,7 +664,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, static void virDomainSnapshotDiskDefFormat(virBufferPtr buf, - virDomainSnapshotDiskDefPtr disk) + virDomainSnapshotDiskDefPtr disk, + virDomainXMLOptionPtr xmlopt) { int type =3D disk->src->type; @@ -686,7 +688,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, if (disk->src->format > 0) virBufferEscapeString(buf, "\n", virStorageFileFormatTypeToString(disk->src->= format)); - virDomainDiskSourceFormat(buf, disk->src, 0, 0); + virDomainDiskSourceFormat(buf, disk->src, 0, 0, xmlopt); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); @@ -740,13 +742,13 @@ virDomainSnapshotDefFormat(const char *domain_uuid, virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); for (i =3D 0; i < def->ndisks; i++) - virDomainSnapshotDiskDefFormat(&buf, &def->disks[i]); + virDomainSnapshotDiskDefFormat(&buf, &def->disks[i], xmlopt); virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); } if (def->dom) { - if (virDomainDefFormatInternal(def->dom, caps, flags, &buf) < 0) + if (virDomainDefFormatInternal(def->dom, caps, flags, &buf, xmlopt= ) < 0) goto error; } else if (domain_uuid) { virBufferAddLit(&buf, "\n"); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index fcaa66df91..334da7a85d 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -233,7 +233,7 @@ networkRunHook(virNetworkObjPtr obj, goto cleanup; if (virNetworkDefFormatBuf(&buf, def, 0) < 0) goto cleanup; - if (dom && virDomainDefFormatInternal(dom, NULL, 0, &buf) < 0) + if (dom && virDomainDefFormatInternal(dom, NULL, 0, &buf, NULL) < = 0) goto cleanup; virBufferAdjustIndent(&buf, -2); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 347fc07425..18c2d2cb8a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5325,7 +5325,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr drive= r, format: ret =3D virDomainDefFormatInternal(def, caps, virDomainDefFormatConvertXMLFlags(fla= gs), - buf); + buf, driver->xmlopt); cleanup: virDomainDefFree(copy); diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index d1665756ab..e8fac100dd 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -57,7 +57,7 @@ testBackingXMLjsonXML(const void *args) if (!(xml =3D virXMLParseStringCtxt(data->xml, "(test storage source X= ML)", &ctxt))) goto cleanup; - if (virDomainDiskSourceParse(ctxt->node, ctxt, xmlsrc, 0) < 0) { + if (virDomainDiskSourceParse(ctxt->node, ctxt, xmlsrc, 0, NULL) < 0) { fprintf(stderr, "failed to parse disk source xml\n"); goto cleanup; } @@ -83,7 +83,7 @@ testBackingXMLjsonXML(const void *args) goto cleanup; } - if (virDomainDiskSourceFormat(&buf, jsonsrc, 0, 0) < 0 || + if (virDomainDiskSourceFormat(&buf, jsonsrc, 0, 0, NULL) < 0 || !(actualxml =3D virBufferContentAndReset(&buf))) { fprintf(stderr, "failed to format disk source xml\n"); goto cleanup; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 806c5465ce..7a0d4a8260 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -693,7 +693,7 @@ testBackingParse(const void *args) goto cleanup; } - if (virDomainDiskSourceFormat(&buf, src, 0, 0) < 0 || + if (virDomainDiskSourceFormat(&buf, src, 0, 0, NULL) < 0 || !(xml =3D virBufferContentAndReset(&buf))) { fprintf(stderr, "failed to format disk source xml\n"); goto cleanup; --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 06:12:48 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 1513243902350881.5512283509198; Thu, 14 Dec 2017 01:31:42 -0800 (PST) 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 F40EA6016A; Thu, 14 Dec 2017 09:31:40 +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 C490418174; Thu, 14 Dec 2017 09:31:40 +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 3BE744A469; Thu, 14 Dec 2017 09:31:40 +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 vBE9VRNd016780 for ; Thu, 14 Dec 2017 04:31:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7823A7EE9E; Thu, 14 Dec 2017 09:31:27 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id A36C17EE9B; Thu, 14 Dec 2017 09:31:26 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Dec 2017 10:30:50 +0100 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 Cc: mprivozn@redhat.com, Peter Krempa Subject: [libvirt] [PATCH 2/3] util: storage: Add helpers to parse and format relPath into privateData 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.25]); Thu, 14 Dec 2017 09:31:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will be the first private piece of data that will need to be stored in the XML for some drivers. Add helpers which will do it. --- src/libvirt_private.syms | 2 ++ src/util/virstoragefile.c | 20 ++++++++++++++++++++ src/util/virstoragefile.h | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b4b72c0734..d5c3b9abb5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2734,6 +2734,8 @@ virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; virStorageSourcePoolModeTypeToString; +virStorageSourcePrivateDataFormatRelPath; +virStorageSourcePrivateDataParseRelPath; virStorageSourceUpdateBackingSizes; virStorageSourceUpdateCapacity; virStorageSourceUpdatePhysicalSize; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 6594715e5e..5780180a94 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -4086,3 +4086,23 @@ virStorageSourceNetworkAssignDefaultPorts(virStorage= SourcePtr src) src->hosts[i].port =3D virStorageSourceNetworkDefaultPort(src-= >protocol); } } + + +int +virStorageSourcePrivateDataParseRelPath(xmlXPathContextPtr ctxt, + virStorageSourcePtr src) +{ + src->relPath =3D virXPathString("string(./relPath)", ctxt); + return 0; +} + + +int +virStorageSourcePrivateDataFormatRelPath(virStorageSourcePtr src, + virBufferPtr buf) +{ + if (src->relPath) + virBufferEscapeString(buf, "%s\n", src->relPath= ); + + return 0; +} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 24382a0a6b..ecd806c93f 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -441,4 +441,12 @@ bool virStorageSourceHasBacking(const virStorageSource *src); +int +virStorageSourcePrivateDataParseRelPath(xmlXPathContextPtr ctxt, + virStorageSourcePtr src); +int +virStorageSourcePrivateDataFormatRelPath(virStorageSourcePtr src, + virBufferPtr buf); + + #endif /* __VIR_STORAGE_FILE_H__ */ --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 06:12:48 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 1513243906874630.1144178401576; Thu, 14 Dec 2017 01:31:46 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87C90C014169; Thu, 14 Dec 2017 09:31:45 +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 5496C71905; Thu, 14 Dec 2017 09:31:45 +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 407821800FC4; Thu, 14 Dec 2017 09:31:44 +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 vBE9VSpC016788 for ; Thu, 14 Dec 2017 04:31:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id A11477EE9D; Thu, 14 Dec 2017 09:31:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C61907EF40; Thu, 14 Dec 2017 09:31:27 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Dec 2017 10:30:51 +0100 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 Cc: mprivozn@redhat.com, Peter Krempa Subject: [libvirt] [PATCH 3/3] qemu: domain: Parse and format relPath into disk source private data 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 14 Dec 2017 09:31:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Register the helpers directly to format and parse the data. https://bugzilla.redhat.com/show_bug.cgi?id=3D1523261 --- src/qemu/qemu_domain.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 18c2d2cb8a..74b82450b4 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2451,6 +2451,8 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivate= DataCallbacks =3D { .chrSourceNew =3D qemuDomainChrSourcePrivateNew, .parse =3D qemuDomainObjPrivateXMLParse, .format =3D qemuDomainObjPrivateXMLFormat, + .storageParse =3D virStorageSourcePrivateDataParseRelPath, + .storageFormat =3D virStorageSourcePrivateDataFormatRelPath, }; --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list