mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: Implement private data formatting and parsing for disks
Allow storing of private data in the status XML for disks. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
e436881b02
commit
a6ea791e25
@ -9679,6 +9679,33 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
virDomainDiskDefParsePrivateData(xmlXPathContextPtr ctxt,
|
||||||
|
virDomainDiskDefPtr disk,
|
||||||
|
virDomainXMLOptionPtr xmlopt)
|
||||||
|
{
|
||||||
|
xmlNodePtr private_node = virXPathNode("./privateData", ctxt);
|
||||||
|
xmlNodePtr save_node = ctxt->node;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!xmlopt ||
|
||||||
|
!xmlopt->privateData.diskParse ||
|
||||||
|
!private_node)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ctxt->node = private_node;
|
||||||
|
|
||||||
|
if (xmlopt->privateData.diskParse(ctxt, disk) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
ctxt->node = save_node;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define VENDOR_LEN 8
|
#define VENDOR_LEN 8
|
||||||
#define PRODUCT_LEN 16
|
#define PRODUCT_LEN 16
|
||||||
|
|
||||||
@ -10094,6 +10121,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_DEF_PARSE_STATUS &&
|
||||||
|
virDomainDiskDefParsePrivateData(ctxt, def, xmlopt) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (virDomainDiskDefParseValidate(def, vmSeclabels, nvmSeclabels) < 0)
|
if (virDomainDiskDefParseValidate(def, vmSeclabels, nvmSeclabels) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -24206,6 +24237,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
|
static int
|
||||||
virDomainDiskDefFormat(virBufferPtr buf,
|
virDomainDiskDefFormat(virBufferPtr buf,
|
||||||
virDomainDiskDefPtr def,
|
virDomainDiskDefPtr def,
|
||||||
@ -24319,6 +24379,9 @@ virDomainDiskDefFormat(virBufferPtr buf,
|
|||||||
virDomainDeviceInfoFormat(buf, &def->info,
|
virDomainDeviceInfoFormat(buf, &def->info,
|
||||||
flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);
|
flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);
|
||||||
|
|
||||||
|
if (virDomainDiskDefFormatPrivateData(buf, def, flags, xmlopt) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</disk>\n");
|
virBufferAddLit(buf, "</disk>\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2738,6 +2738,11 @@ typedef int (*virDomainXMLPrivateDataParseFunc)(xmlXPathContextPtr,
|
|||||||
|
|
||||||
typedef void *(*virDomainXMLPrivateDataGetParseOpaqueFunc)(virDomainObjPtr vm);
|
typedef void *(*virDomainXMLPrivateDataGetParseOpaqueFunc)(virDomainObjPtr vm);
|
||||||
|
|
||||||
|
typedef int (*virDomainXMLPrivateDataDiskParseFunc)(xmlXPathContextPtr ctxt,
|
||||||
|
virDomainDiskDefPtr disk);
|
||||||
|
typedef int (*virDomainXMLPrivateDataDiskFormatFunc)(virDomainDiskDefPtr disk,
|
||||||
|
virBufferPtr buf);
|
||||||
|
|
||||||
typedef int (*virDomainXMLPrivateDataStorageSourceParseFunc)(xmlXPathContextPtr ctxt,
|
typedef int (*virDomainXMLPrivateDataStorageSourceParseFunc)(xmlXPathContextPtr ctxt,
|
||||||
virStorageSourcePtr src);
|
virStorageSourcePtr src);
|
||||||
typedef int (*virDomainXMLPrivateDataStorageSourceFormatFunc)(virStorageSourcePtr src,
|
typedef int (*virDomainXMLPrivateDataStorageSourceFormatFunc)(virStorageSourcePtr src,
|
||||||
@ -2752,6 +2757,8 @@ struct _virDomainXMLPrivateDataCallbacks {
|
|||||||
/* note that private data for devices are not copied when using
|
/* note that private data for devices are not copied when using
|
||||||
* virDomainDefCopy and similar functions */
|
* virDomainDefCopy and similar functions */
|
||||||
virDomainXMLPrivateDataNewFunc diskNew;
|
virDomainXMLPrivateDataNewFunc diskNew;
|
||||||
|
virDomainXMLPrivateDataDiskParseFunc diskParse;
|
||||||
|
virDomainXMLPrivateDataDiskFormatFunc diskFormat;
|
||||||
virDomainXMLPrivateDataNewFunc vcpuNew;
|
virDomainXMLPrivateDataNewFunc vcpuNew;
|
||||||
virDomainXMLPrivateDataNewFunc chrSourceNew;
|
virDomainXMLPrivateDataNewFunc chrSourceNew;
|
||||||
virDomainXMLPrivateDataNewFunc vsockNew;
|
virDomainXMLPrivateDataNewFunc vsockNew;
|
||||||
|
Loading…
Reference in New Issue
Block a user