migration: refactor: introduce params version of unmanaged

Let's put main functionality into params version of virDomainMigrateUnmanaged
as a preparation step for merging it with virDomainMigratePeer2PeerParams.
virDomainMigrateUnmanaged then does nothing more then just adapting arguments.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
This commit is contained in:
Nikolay Shirokovskiy 2015-10-02 10:52:47 +03:00 committed by Jiri Denemark
parent 323ba66eaa
commit 8db77b372e

View File

@ -3330,21 +3330,32 @@ virDomainMigrateCheckNotLocal(const char *dconnuri)
* does not need to be involved at all, or even running. * does not need to be involved at all, or even running.
*/ */
static int static int
virDomainMigrateUnmanaged(virDomainPtr domain, virDomainMigrateUnmanagedParams(virDomainPtr domain,
const char *xmlin, const char *dconnuri,
unsigned int flags, virTypedParameterPtr params,
const char *dname, int nparams,
const char *dconnuri, unsigned int flags)
const char *miguri,
unsigned long long bandwidth)
{ {
const char *uri = NULL; const char *uri = NULL;
const char *miguri = NULL;
const char *dname = NULL;
const char *xmlin = NULL;
unsigned long long bandwidth = 0;
VIR_DOMAIN_DEBUG(domain, VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparams=%d, flags=%x",
"dconnuri=%s, xmlin=%s, dname=%s, migrui=%s, " dconnuri, params, nparams, flags);
"bandwidth=%llu, flags=%x", VIR_TYPED_PARAMS_DEBUG(params, nparams);
dconnuri, NULLSTR(xmlin), NULLSTR(dname), NULLSTR(miguri),
bandwidth, flags); if (virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_URI, &miguri) < 0 ||
virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_DEST_NAME, &dname) < 0 ||
virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_DEST_XML, &xmlin) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_MIGRATE_PARAM_BANDWIDTH, &bandwidth) < 0) {
return -1;
}
if ((flags & VIR_MIGRATE_PEER2PEER) && if ((flags & VIR_MIGRATE_PEER2PEER) &&
virDomainMigrateCheckNotLocal(dconnuri) < 0) virDomainMigrateCheckNotLocal(dconnuri) < 0)
@ -3414,6 +3425,46 @@ virDomainMigratePeer2PeerParams(virDomainPtr domain,
} }
static int
virDomainMigrateUnmanaged(virDomainPtr domain,
const char *xmlin,
unsigned int flags,
const char *dname,
const char *dconnuri,
const char *miguri,
unsigned long long bandwidth)
{
int ret = -1;
virTypedParameterPtr params = NULL;
int nparams = 0;
int maxparams = 0;
if (miguri &&
virTypedParamsAddString(&params, &nparams, &maxparams,
VIR_MIGRATE_PARAM_URI, miguri) < 0)
goto cleanup;
if (dname &&
virTypedParamsAddString(&params, &nparams, &maxparams,
VIR_MIGRATE_PARAM_DEST_NAME, dname) < 0)
goto cleanup;
if (xmlin &&
virTypedParamsAddString(&params, &nparams, &maxparams,
VIR_MIGRATE_PARAM_DEST_XML, xmlin) < 0)
goto cleanup;
if (virTypedParamsAddULLong(&params, &nparams, &maxparams,
VIR_MIGRATE_PARAM_BANDWIDTH, bandwidth) < 0)
goto cleanup;
ret = virDomainMigrateUnmanagedParams(domain, dconnuri, params,
nparams, flags);
cleanup:
virTypedParamsFree(params, nparams);
return ret;
}
/** /**
* virDomainMigrate: * virDomainMigrate:
* @domain: a domain object * @domain: a domain object
@ -4380,10 +4431,6 @@ virDomainMigrateToURI3(virDomainPtr domain,
VIR_MIGRATE_PARAM_DEST_NAME, VIR_MIGRATE_PARAM_DEST_NAME,
VIR_MIGRATE_PARAM_DEST_XML, VIR_MIGRATE_PARAM_DEST_XML,
VIR_MIGRATE_PARAM_BANDWIDTH }; VIR_MIGRATE_PARAM_BANDWIDTH };
const char *uri = NULL;
const char *dname = NULL;
const char *dxml = NULL;
unsigned long long bandwidth = 0;
VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparms=%u flags=%x", VIR_DOMAIN_DEBUG(domain, "dconnuri=%s, params=%p, nparms=%u flags=%x",
NULLSTR(dconnuri), params, nparams, flags); NULLSTR(dconnuri), params, nparams, flags);
@ -4402,17 +4449,6 @@ virDomainMigrateToURI3(virDomainPtr domain,
compat = virTypedParamsCheck(params, nparams, compatParams, compat = virTypedParamsCheck(params, nparams, compatParams,
ARRAY_CARDINALITY(compatParams)); ARRAY_CARDINALITY(compatParams));
if (virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_URI, &uri) < 0 ||
virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_DEST_NAME, &dname) < 0 ||
virTypedParamsGetString(params, nparams,
VIR_MIGRATE_PARAM_DEST_XML, &dxml) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_MIGRATE_PARAM_BANDWIDTH, &bandwidth) < 0) {
goto error;
}
if (flags & VIR_MIGRATE_PEER2PEER) { if (flags & VIR_MIGRATE_PEER2PEER) {
if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn, if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
VIR_DRV_FEATURE_MIGRATION_P2P)) { VIR_DRV_FEATURE_MIGRATION_P2P)) {
@ -4430,8 +4466,8 @@ virDomainMigrateToURI3(virDomainPtr domain,
goto error; goto error;
} else if (compat) { } else if (compat) {
VIR_DEBUG("Using peer2peer migration"); VIR_DEBUG("Using peer2peer migration");
if (virDomainMigrateUnmanaged(domain, dxml, flags, dname, if (virDomainMigrateUnmanagedParams(domain, dconnuri, params,
dconnuri, uri, bandwidth) < 0) nparams, flags) < 0)
goto error; goto error;
} else { } else {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
@ -4458,8 +4494,8 @@ virDomainMigrateToURI3(virDomainPtr domain,
} }
VIR_DEBUG("Using direct migration"); VIR_DEBUG("Using direct migration");
if (virDomainMigrateUnmanaged(domain, dxml, flags, if (virDomainMigrateUnmanagedParams(domain, NULL, params,
dname, NULL, uri, bandwidth) < 0) nparams, flags) < 0)
goto error; goto error;
} }