Allow storing of private data in the status XML for disks.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 7 ++++++
2 files changed, 67 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 93d745bb74..c10e0a9eca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9676,6 +9676,30 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
}
+static int
+virDomainDiskDefParsePrivateData(xmlXPathContextPtr ctxt,
+ virDomainDiskDefPtr disk,
+ virDomainXMLOptionPtr xmlopt)
+{
+ xmlNodePtr save_node = ctxt->node;
+ int ret = 0;
+
+ if (!xmlopt ||
+ !xmlopt->privateData.diskParse)
+ return 0;
+
+ if (!(ctxt->node = virXPathNode("./privateData", ctxt)))
+ goto cleanup;
+
+ if (xmlopt->privateData.diskParse(ctxt, disk) < 0)
+ ret = -1;
+
+ cleanup:
+ ctxt->node = save_node;
+ return ret;
+}
+
+
#define VENDOR_LEN 8
#define PRODUCT_LEN 16
@@ -10091,6 +10115,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
goto error;
}
+ if (flags & VIR_DOMAIN_DEF_PARSE_STATUS &&
+ virDomainDiskDefParsePrivateData(ctxt, def, xmlopt) < 0)
+ goto error;
+
if (virDomainDiskDefParseValidate(def, vmSeclabels, nvmSeclabels) < 0)
goto error;
@@ -24006,6 +24034,35 @@ virDomainDiskDefFormatMirror(virBufferPtr buf,
}
+static int
+virDomainDiskDefFormatPrivateData(virBufferPtr buf,
+ virDomainDiskDefPtr disk,
+ unsigned int flags,
+ virDomainXMLOptionPtr xmlopt)
+{
+ virBuffer childBuf = VIR_BUFFER_INITIALIZER;
+
+ if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) ||
+ !xmlopt ||
+ !xmlopt->privateData.diskFormat)
+ return 0;
+
+ virBufferSetChildIndent(&childBuf, buf);
+
+ if (xmlopt->privateData.diskFormat(disk, &childBuf) < 0)
+ goto error;
+
+ if (virXMLFormatElement(buf, "privateData", NULL, &childBuf) < 0)
+ goto error;
+
+ return 0;
+
+ error:
+ virBufferFreeAndReset(&childBuf);
+ return -1;
+}
+
+
static int
virDomainDiskDefFormat(virBufferPtr buf,
virDomainDiskDefPtr def,
@@ -24119,6 +24176,9 @@ virDomainDiskDefFormat(virBufferPtr buf,
virDomainDeviceInfoFormat(buf, &def->info,
flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);
+ if (virDomainDiskDefFormatPrivateData(buf, def, flags, xmlopt) < 0)
+ return -1;
+
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</disk>\n");
return 0;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c1dfa37fdf..50d2ead607 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2735,6 +2735,11 @@ typedef int
(*virDomainXMLPrivateDataParseFunc)(xmlXPathContextPtr,
typedef void *(*virDomainXMLPrivateDataGetParseOpaqueFunc)(virDomainObjPtr vm);
+typedef int (*virDomainXMLPrivateDataDiskParseFunc)(xmlXPathContextPtr ctxt,
+ virDomainDiskDefPtr disk);
+typedef int (*virDomainXMLPrivateDataDiskFormatFunc)(virDomainDiskDefPtr disk,
+ virBufferPtr buf);
+
typedef int (*virDomainXMLPrivateDataStorageSourceParseFunc)(xmlXPathContextPtr ctxt,
virStorageSourcePtr src);
typedef int (*virDomainXMLPrivateDataStorageSourceFormatFunc)(virStorageSourcePtr src,
@@ -2749,6 +2754,8 @@ struct _virDomainXMLPrivateDataCallbacks {
/* note that private data for devices are not copied when using
* virDomainDefCopy and similar functions */
virDomainXMLPrivateDataNewFunc diskNew;
+ virDomainXMLPrivateDataDiskParseFunc diskParse;
+ virDomainXMLPrivateDataDiskFormatFunc diskFormat;
virDomainXMLPrivateDataNewFunc vcpuNew;
virDomainXMLPrivateDataNewFunc chrSourceNew;
virDomainXMLPrivateDataNewFunc vsockNew;
--
2.16.2