1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

conf: Format and parse private data for virDomainNetDef

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 <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2023-02-01 09:02:19 +01:00
parent c0f671e7c9
commit db4ea3986a
2 changed files with 58 additions and 0 deletions

View File

@ -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;

View File

@ -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;