The virDomainNetDef struct has privateData (which is currently
used by QEMU driver to store FDs opened during cmd line building
phase and pass them onto cmd line).

Soon, we will need to store additional information that needs to
survive daemon restart. Let's introduce machinery for parsing and
formatting privateData.

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 src/conf/domain_conf.c | 51 ++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h |  7 ++++++
 2 files changed, 58 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4920f04bd0..6e33a4472f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9254,6 +9254,29 @@ virDomainNetDefParseXMLRequireSource(virDomainNetDef 
*def,
 }
 
 
+static int
+virDomainNetDefParsePrivateData(xmlXPathContextPtr ctxt,
+                                virDomainNetDef *net,
+                                virDomainXMLOption *xmlopt)
+{
+    xmlNodePtr private_node = virXPathNode("./privateData", ctxt);
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
+
+    if (!xmlopt ||
+        !xmlopt->privateData.networkParse ||
+        !private_node)
+        return 0;
+
+    ctxt->node = private_node;
+
+    if (xmlopt->privateData.networkParse(ctxt, net) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+
 static virDomainNetDef *
 virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
                         xmlNodePtr node,
@@ -9672,6 +9695,10 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
     if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0)
         return NULL;
 
+    if (flags & VIR_DOMAIN_DEF_PARSE_STATUS &&
+        virDomainNetDefParsePrivateData(ctxt, def, xmlopt) < 0)
+        return NULL;
+
     return g_steal_pointer(&def);
 }
 
@@ -23668,6 +23695,27 @@ virDomainNetPortForwardsFormat(virBuffer *buf,
 }
 
 
+static int
+virDomainNetDefFormatPrivateData(virBuffer *buf,
+                                 virDomainNetDef *net,
+                                 unsigned int flags,
+                                 virDomainXMLOption *xmlopt)
+{
+    g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+
+    if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) ||
+        !xmlopt ||
+        !xmlopt->privateData.networkFormat)
+        return 0;
+
+    if (xmlopt->privateData.networkFormat(net, &childBuf) < 0)
+        return -1;
+
+    virXMLFormatElement(buf, "privateData", NULL, &childBuf);
+    return 0;
+}
+
+
 int
 virDomainNetDefFormat(virBuffer *buf,
                       virDomainNetDef *def,
@@ -23965,6 +24013,9 @@ virDomainNetDefFormat(virBuffer *buf,
     virDomainDeviceInfoFormat(buf, &def->info, flags | 
VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT
                                                      | 
VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM);
 
+    if (virDomainNetDefFormatPrivateData(buf, def, flags, xmlopt) < 0)
+        return -1;
+
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</interface>\n");
     return 0;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 631cef03fd..1a80399c9c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3357,6 +3357,11 @@ typedef int 
(*virDomainXMLPrivateDataTPMParseFunc)(xmlXPathContextPtr ctxt,
 typedef int (*virDomainXMLPrivateDataTPMFormatFunc)(const virDomainTPMDef *tpm,
                                                     virBuffer *buf);
 
+typedef int (*virDomainXMLPrivateDataNetParseFunc)(xmlXPathContextPtr ctxt,
+                                                   virDomainNetDef *net);
+typedef int (*virDomainXMLPrivateDataNetFormatFunc)(const virDomainNetDef *net,
+                                                    virBuffer *buf);
+
 struct _virDomainXMLPrivateDataCallbacks {
     virDomainXMLPrivateDataAllocFunc  alloc;
     virDomainXMLPrivateDataFreeFunc   free;
@@ -3371,6 +3376,8 @@ struct _virDomainXMLPrivateDataCallbacks {
     virDomainXMLPrivateDataNewFunc    cryptoNew;
     virDomainXMLPrivateDataNewFunc    graphicsNew;
     virDomainXMLPrivateDataNewFunc    networkNew;
+    virDomainXMLPrivateDataNetParseFunc networkParse;
+    virDomainXMLPrivateDataNetFormatFunc networkFormat;
     virDomainXMLPrivateDataNewFunc    videoNew;
     virDomainXMLPrivateDataNewFunc    fsNew;
     virDomainXMLPrivateDataTPMParseFunc tpmParse;
-- 
2.39.1

Reply via email to