提交 ecd81131 编写于 作者: J Jiri Denemark

qemu: Move common parts of Prepare phase to qemu_migration.c

上级 d3ce7363
......@@ -9962,25 +9962,14 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
virCapsPtr caps = NULL;
virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
if (!dom_xml) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no domain XML passed"));
goto cleanup;
}
if (!(flags & VIR_MIGRATE_TUNNELLED)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("PrepareTunnel called but no TUNNELLED flag set"));
goto cleanup;
}
if (st == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("tunnelled migration requested but NULL stream passed"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("PrepareTunnel called but no TUNNELLED flag set"));
goto cleanup;
}
......@@ -9991,20 +9980,9 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
goto cleanup;
}
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
goto cleanup;
if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (dname) {
VIR_FREE(def->name);
if (VIR_STRDUP(def->name, dname) < 0)
goto cleanup;
}
if (virDomainMigratePrepareTunnelEnsureACL(dconn, def) < 0)
goto cleanup;
......@@ -10014,7 +9992,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
cleanup:
virDomainDefFree(def);
virObjectUnref(caps);
return ret;
}
......@@ -10034,49 +10011,30 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
virCapsPtr caps = NULL;
virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
*uri_out = NULL;
if (virLockManagerPluginUsesState(driver->lockManager)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cannot use migrate v2 protocol with lock manager %s"),
virLockManagerPluginGetName(driver->lockManager));
goto cleanup;
}
if (flags & VIR_MIGRATE_TUNNELLED) {
/* this is a logical error; we never should have gotten here with
* VIR_MIGRATE_TUNNELLED set
*/
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Tunnelled migration requested but invalid RPC method called"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Tunnelled migration requested but invalid "
"RPC method called"));
goto cleanup;
}
if (!dom_xml) {
if (virLockManagerPluginUsesState(driver->lockManager)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no domain XML passed"));
_("Cannot use migrate v2 protocol with lock manager %s"),
virLockManagerPluginGetName(driver->lockManager));
goto cleanup;
}
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (dname) {
VIR_FREE(def->name);
if (VIR_STRDUP(def->name, dname) < 0)
if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
goto cleanup;
}
if (virDomainMigratePrepare2EnsureACL(dconn, def) < 0)
goto cleanup;
......@@ -10092,7 +10050,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
cleanup:
virDomainDefFree(def);
virObjectUnref(caps);
return ret;
}
......@@ -10230,43 +10187,24 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
virCapsPtr caps = NULL;
virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
*uri_out = NULL;
if (flags & VIR_MIGRATE_TUNNELLED) {
/* this is a logical error; we never should have gotten here with
* VIR_MIGRATE_TUNNELLED set
*/
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Tunnelled migration requested but invalid RPC method called"));
goto cleanup;
}
if (!dom_xml) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no domain XML passed"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Tunnelled migration requested but invalid "
"RPC method called"));
goto cleanup;
}
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
goto cleanup;
if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (dname) {
VIR_FREE(def->name);
if (VIR_STRDUP(def->name, dname) < 0)
goto cleanup;
}
if (virDomainMigratePrepare3EnsureACL(dconn, def) < 0)
goto cleanup;
......@@ -10278,7 +10216,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
cleanup:
virDomainDefFree(def);
virObjectUnref(caps);
return ret;
}
......@@ -10296,42 +10233,20 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
virCapsPtr caps = NULL;
virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
if (!dom_xml) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no domain XML passed"));
goto cleanup;
}
if (!(flags & VIR_MIGRATE_TUNNELLED)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("PrepareTunnel called but no TUNNELLED flag set"));
goto cleanup;
}
if (st == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("tunnelled migration requested but NULL stream passed"));
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("PrepareTunnel called but no TUNNELLED flag set"));
goto cleanup;
}
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
goto cleanup;
if (dname) {
VIR_FREE(def->name);
if (VIR_STRDUP(def->name, dname) < 0)
goto cleanup;
}
if (virDomainMigratePrepareTunnel3EnsureACL(dconn, def) < 0)
goto cleanup;
......@@ -10342,7 +10257,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
cleanup:
virDomainDefFree(def);
virObjectUnref(caps);
return ret;
}
......
......@@ -2442,6 +2442,12 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
driver, dconn, NULLSTR(cookiein), cookieinlen,
cookieout, cookieoutlen, st, *def, flags);
if (st == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("tunnelled migration requested but NULL stream passed"));
return -1;
}
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def,
st, 0, flags);
......@@ -2476,6 +2482,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
cookieout, cookieoutlen, NULLSTR(uri_in), uri_out,
*def, flags);
*uri_out = NULL;
/* The URI passed in may be NULL or a string "tcp://somehostname:port".
*
* If the URI passed in is NULL then we allocate a port number
......@@ -2580,6 +2588,42 @@ cleanup:
}
virDomainDefPtr
qemuMigrationPrepareDef(virQEMUDriverPtr driver,
const char *dom_xml,
const char *dname)
{
virCapsPtr caps = NULL;
virDomainDefPtr def;
if (!dom_xml) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no domain XML passed"));
return NULL;
}
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
return NULL;
if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
if (dname) {
VIR_FREE(def->name);
if (VIR_STRDUP(def->name, dname) < 0) {
virDomainDefFree(def);
def = NULL;
}
}
cleanup:
virObjectUnref(caps);
return def;
}
enum qemuMigrationDestinationType {
MIGRATION_DEST_HOST,
MIGRATION_DEST_CONNECT_HOST,
......
......@@ -92,6 +92,10 @@ char *qemuMigrationBegin(virConnectPtr conn,
int *cookieoutlen,
unsigned long flags);
virDomainDefPtr qemuMigrationPrepareDef(virQEMUDriverPtr driver,
const char *dom_xml,
const char *dname);
int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
virConnectPtr dconn,
const char *cookiein,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册