conf: Add save cookie callbacks to xmlopt

virDomainXMLOption gains driver specific callbacks for parsing and
formatting save cookies.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Jiri Denemark 2017-06-02 00:44:46 +02:00
parent e37daa1fb6
commit 25af7e950a
23 changed files with 54 additions and 21 deletions

View File

@ -144,7 +144,7 @@ virBhyveDriverCreateXMLConf(bhyveConnPtr driver)
virBhyveDriverDomainDefParserConfig.priv = driver;
return virDomainXMLOptionNew(&virBhyveDriverDomainDefParserConfig,
&virBhyveDriverPrivateDataCallbacks,
NULL, NULL);
NULL, NULL, NULL);
}
virDomainDefParserConfig virBhyveDriverDomainDefParserConfig = {

View File

@ -79,6 +79,9 @@ struct _virDomainXMLOption {
/* ABI stability callbacks */
virDomainABIStability abi;
/* Private data for save image stored in snapshot XML */
virSaveCookieCallbacks saveCookie;
};
#define VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS \
@ -1054,7 +1057,8 @@ virDomainXMLOptionPtr
virDomainXMLOptionNew(virDomainDefParserConfigPtr config,
virDomainXMLPrivateDataCallbacksPtr priv,
virDomainXMLNamespacePtr xmlns,
virDomainABIStabilityPtr abi)
virDomainABIStabilityPtr abi,
virSaveCookieCallbacksPtr saveCookie)
{
virDomainXMLOptionPtr xmlopt;
@ -1076,6 +1080,9 @@ virDomainXMLOptionNew(virDomainDefParserConfigPtr config,
if (abi)
xmlopt->abi = *abi;
if (saveCookie)
xmlopt->saveCookie = *saveCookie;
/* Technically this forbids to use one of Xerox's MAC address prefixes in
* our hypervisor drivers. This shouldn't ever be a problem.
*
@ -1106,6 +1113,13 @@ virDomainXMLOptionGetNamespace(virDomainXMLOptionPtr xmlopt)
}
virSaveCookieCallbacksPtr
virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPtr xmlopt)
{
return &xmlopt->saveCookie;
}
void
virBlkioDeviceArrayClear(virBlkioDevicePtr devices,
int ndevices)

View File

@ -55,6 +55,7 @@
# include "virgic.h"
# include "virperf.h"
# include "virtypedparam.h"
# include "virsavecookie.h"
/* forward declarations of all device types, required by
* virDomainDeviceDef
@ -2549,7 +2550,11 @@ struct _virDomainABIStability {
virDomainXMLOptionPtr virDomainXMLOptionNew(virDomainDefParserConfigPtr config,
virDomainXMLPrivateDataCallbacksPtr priv,
virDomainXMLNamespacePtr xmlns,
virDomainABIStabilityPtr abi);
virDomainABIStabilityPtr abi,
virSaveCookieCallbacksPtr saveCookie);
virSaveCookieCallbacksPtr
virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPtr xmlopt);
void virDomainNetGenerateMAC(virDomainXMLOptionPtr xmlopt, virMacAddrPtr mac);

View File

@ -102,6 +102,7 @@ void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
virDomainSnapshotDiskDefClear(&def->disks[i]);
VIR_FREE(def->disks);
virDomainDefFree(def->dom);
virObjectUnref(def->cookie);
VIR_FREE(def);
}
@ -214,6 +215,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
char *memorySnapshot = NULL;
char *memoryFile = NULL;
bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE);
virSaveCookieCallbacksPtr saveCookie = virDomainXMLOptionGetSaveCookie(xmlopt);
if (VIR_ALLOC(def) < 0)
goto cleanup;
@ -365,6 +367,9 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
def->current = active != 0;
}
if (!offline && virSaveCookieParse(ctxt, &def->cookie, saveCookie) < 0)
goto cleanup;
ret = def;
cleanup:
@ -691,7 +696,7 @@ char *
virDomainSnapshotDefFormat(const char *domain_uuid,
virDomainSnapshotDefPtr def,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED,
virDomainXMLOptionPtr xmlopt,
unsigned int flags,
int internal)
{
@ -751,6 +756,10 @@ virDomainSnapshotDefFormat(const char *domain_uuid,
virBufferAddLit(&buf, "</domain>\n");
}
if (virSaveCookieFormatBuf(&buf, def->cookie,
virDomainXMLOptionGetSaveCookie(xmlopt)) < 0)
goto error;
if (internal)
virBufferAsprintf(&buf, "<active>%d</active>\n", def->current);

View File

@ -76,6 +76,8 @@ struct _virDomainSnapshotDef {
virDomainDefPtr dom;
virObjectPtr cookie;
/* Internal use. */
bool current; /* At most one snapshot in the list should have this set */
};

View File

@ -535,6 +535,7 @@ virDomainWatchdogActionTypeToString;
virDomainWatchdogModelTypeFromString;
virDomainWatchdogModelTypeToString;
virDomainXMLOptionGetNamespace;
virDomainXMLOptionGetSaveCookie;
virDomainXMLOptionNew;

View File

@ -2255,5 +2255,5 @@ libxlCreateXMLConf(void)
{
return virDomainXMLOptionNew(&libxlDomainDefParserConfig,
&libxlDomainXMLPrivateDataCallbacks,
NULL, NULL);
NULL, NULL, NULL);
}

View File

@ -216,7 +216,7 @@ lxcDomainXMLConfInit(void)
return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
&virLXCDriverPrivateDataCallbacks,
&virLXCDriverDomainXMLNamespace,
NULL);
NULL, NULL);
}

View File

@ -1483,7 +1483,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
goto cleanup;
if (!(driver->xmlopt = virDomainXMLOptionNew(&openvzDomainDefParserConfig,
NULL, NULL, NULL)))
NULL, NULL, NULL, NULL)))
goto cleanup;
if (openvzLoadDomains(driver) < 0)

View File

@ -1202,7 +1202,7 @@ phypConnectOpen(virConnectPtr conn,
goto failure;
if (!(phyp_driver->xmlopt = virDomainXMLOptionNew(&virPhypDriverDomainDefParserConfig,
NULL, NULL, NULL)))
NULL, NULL, NULL, NULL)))
goto failure;
conn->privateData = phyp_driver;

View File

@ -5026,7 +5026,7 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd,
goto ignore;
}
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL)) ||
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
!(cmd->vm = virDomainObjNew(xmlopt)))
goto cleanup;

View File

@ -910,7 +910,8 @@ virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver)
return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig,
&virQEMUDriverPrivateDataCallbacks,
&virQEMUDriverDomainXMLNamespace,
&virQEMUDriverDomainABIStability);
&virQEMUDriverDomainABIStability,
NULL);
}

View File

@ -667,7 +667,7 @@ get_definition(vahControl * ctl, const char *xmlStr)
goto exit;
}
if (!(ctl->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL))) {
if (!(ctl->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL))) {
vah_error(ctl, 0, _("Failed to create XML config object"));
goto exit;
}

View File

@ -414,7 +414,7 @@ testDriverNew(void)
goto error;
}
if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, NULL, &ns, NULL)) ||
if (!(ret->xmlopt = virDomainXMLOptionNew(NULL, NULL, &ns, NULL, NULL)) ||
!(ret->eventState = virObjectEventStateNew()) ||
!(ret->ifaces = virInterfaceObjListNew()) ||
!(ret->domains = virDomainObjListNew()) ||

View File

@ -533,7 +533,7 @@ umlStateInitialize(bool privileged,
goto out_of_memory;
if (!(uml_driver->xmlopt = virDomainXMLOptionNew(&umlDriverDomainDefParserConfig,
&privcb, NULL, NULL)))
&privcb, NULL, NULL, NULL)))
goto error;
if ((uml_driver->inotifyFD = inotify_init()) < 0) {

View File

@ -142,7 +142,7 @@ vboxDriverObjNew(void)
if (!(driver->caps = vboxCapsInit()) ||
!(driver->xmlopt = virDomainXMLOptionNew(&vboxDomainDefParserConfig,
NULL, NULL, NULL)))
NULL, NULL, NULL, NULL)))
goto cleanup;
return driver;

View File

@ -114,7 +114,8 @@ vmwareDomainXMLConfigInit(void)
virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc,
.free = vmwareDataFreeFunc };
return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv, NULL, NULL);
return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv,
NULL, NULL, NULL);
}
static virDrvOpenStatus

View File

@ -591,7 +591,7 @@ virDomainXMLOptionPtr
virVMXDomainXMLConfInit(void)
{
return virDomainXMLOptionNew(&virVMXDomainDefParserConfig, NULL,
&virVMXDomainXMLNamespace, NULL);
&virVMXDomainXMLNamespace, NULL, NULL);
}
char *

View File

@ -328,7 +328,7 @@ vzDriverObjNew(void)
if (!(driver->caps = vzBuildCapabilities()) ||
!(driver->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig,
&vzDomainXMLPrivateDataCallbacksPtr,
NULL, NULL)) ||
NULL, NULL, NULL)) ||
!(driver->domains = virDomainObjListNew()) ||
!(driver->domainEventState = virObjectEventStateNew()) ||
(vzInitVersion(driver) < 0) ||

View File

@ -401,7 +401,7 @@ virDomainXMLOptionPtr
xenDomainXMLConfInit(void)
{
return virDomainXMLOptionNew(&xenDomainDefParserConfig,
NULL, NULL, NULL);
NULL, NULL, NULL, NULL);
}

View File

@ -200,7 +200,7 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
}
if (!(privP->xmlopt = virDomainXMLOptionNew(&xenapiDomainDefParserConfig,
NULL, NULL, NULL))) {
NULL, NULL, NULL, NULL))) {
xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR,
_("Failed to create XML conf object"));
goto error;

View File

@ -131,7 +131,7 @@ mymain(void)
return EXIT_FAILURE;
if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL,
NULL, NULL)) == NULL)
NULL, NULL, NULL)) == NULL)
return EXIT_FAILURE;
# define DO_TEST_FULL(name, flags) \

View File

@ -1136,7 +1136,7 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void)
{
return virDomainXMLOptionNew(&virTestGenericDomainDefParserConfig,
&virTestGenericPrivateDataCallbacks,
NULL, NULL);
NULL, NULL, NULL);
}