[PATCH RFC 15/39] conf: Implement private data formatting and parsing for disks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow storing of private data in the status XML for disks.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 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 55f356ef23..cf52f9af5f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9523,6 +9523,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

@@ -9938,6 +9962,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;

@@ -23878,6 +23906,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,
@@ -23991,6 +24048,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 5e2f21dea3..68c24e0748 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux