--- src/qemu/qemu_driver.c | 277 +++++++++++----------------------------------- src/qemu/qemu_migration.c | 70 +++++++++++- src/qemu/qemu_migration.h | 31 ++---- 3 files changed, 145 insertions(+), 233 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 14397f5..80ec379 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9670,57 +9670,28 @@ 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")); - goto cleanup; + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("PrepareTunnel called but no TUNNELLED flag set")); + return -1; } if (virLockManagerPluginUsesState(driver->lockManager)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("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) - goto cleanup; + return -1; } - ret = qemuMigrationPrepareTunnel(driver, dconn, - NULL, 0, NULL, NULL, /* No cookies in v2 */ - st, &def, flags); - -cleanup: - virDomainDefFree(def); - virObjectUnref(caps); - return ret; + /* Do not use cookies in v2 protocol, since the cookie + * length was not sufficiently large, causing failures + * migrating between old & new libvirtd + */ + return qemuMigrationPrepare(dconn, dom_xml, dname, NULL, st, + NULL, 0, NULL, NULL, NULL, flags); } /* Prepare is the first step, and it runs on the destination host. @@ -9739,63 +9710,32 @@ 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")); - goto cleanup; + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Tunnelled migration requested but invalid RPC " + "method called")); + return -1; } - if (!dom_xml) { + if (virLockManagerPluginUsesState(driver->lockManager)) { virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("no domain XML passed")); - 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) - goto cleanup; + _("Cannot use migrate v2 protocol with lock manager %s"), + virLockManagerPluginGetName(driver->lockManager)); + return -1; } /* Do not use cookies in v2 protocol, since the cookie * length was not sufficiently large, causing failures * migrating between old & new libvirtd */ - ret = qemuMigrationPrepareDirect(driver, dconn, - NULL, 0, NULL, NULL, /* No cookies */ - uri_in, uri_out, - &def, flags); - -cleanup: - virDomainDefFree(def); - virObjectUnref(caps); - return ret; + return qemuMigrationPrepare(dconn, dom_xml, dname, uri_in, NULL, + NULL, 0, NULL, NULL, uri_out, flags); } @@ -9942,66 +9882,6 @@ qemuDomainMigrateBegin3Params(virDomainPtr domain, static int -qemuDomainMigratePrepare3Internal(virConnectPtr dconn, - const char *dom_xml, - const char *dname, - const char *uri_in, - const char *cookiein, - int cookieinlen, - char **cookieout, - int *cookieoutlen, - char **uri_out, - unsigned long flags) -{ - virQEMUDriverPtr driver = dconn->privateData; - virCapsPtr caps = NULL; - virDomainDefPtr def = NULL; - int ret = -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")); - 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) - goto cleanup; - } - - ret = qemuMigrationPrepareDirect(driver, dconn, - cookiein, cookieinlen, - cookieout, cookieoutlen, - uri_in, uri_out, - &def, flags); - -cleanup: - virDomainDefFree(def); - virObjectUnref(caps); - return ret; -} - -static int qemuDomainMigratePrepare3(virConnectPtr dconn, const char *cookiein, int cookieinlen, @@ -10016,9 +9896,19 @@ qemuDomainMigratePrepare3(virConnectPtr dconn, { virCheckFlags(QEMU_MIGRATION_FLAGS, -1); - return qemuDomainMigratePrepare3Internal(dconn, dom_xml, dname, uri_in, - cookiein, cookieinlen, cookieout, - cookieoutlen, uri_out, flags); + 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")); + return -1; + } + + return qemuMigrationPrepare(dconn, dom_xml, dname, uri_in, NULL, + cookiein, cookieinlen, cookieout, + cookieoutlen, uri_out, flags); } static int @@ -10037,6 +9927,17 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn, const char *uri_in = NULL; virCheckFlags(QEMU_MIGRATION_FLAGS, -1); + + 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")); + return -1; + } + if (virTypedParamsValidate(params, nparams, QEMU_MIGRATION_PARAMETERS) < 0) return -1; @@ -10051,70 +9952,13 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn, &uri_in) < 0) return -1; - return qemuDomainMigratePrepare3Internal(dconn, dom_xml, dname, uri_in, - cookiein, cookieinlen, cookieout, - cookieoutlen, uri_out, flags); + return qemuMigrationPrepare(dconn, dom_xml, dname, uri_in, NULL, + cookiein, cookieinlen, cookieout, + cookieoutlen, uri_out, flags); } static int -qemuDomainMigratePrepareTunnel3Internal(virConnectPtr dconn, - virStreamPtr st, - const char *dom_xml, - const char *dname, - const char *cookiein, - int cookieinlen, - char **cookieout, - int *cookieoutlen, - unsigned long flags) -{ - virQEMUDriverPtr driver = dconn->privateData; - virCapsPtr caps = NULL; - virDomainDefPtr def = NULL; - int ret = -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")); - 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) - goto cleanup; - } - - ret = qemuMigrationPrepareTunnel(driver, dconn, - cookiein, cookieinlen, - cookieout, cookieoutlen, - st, &def, flags); - -cleanup: - virDomainDefFree(def); - virObjectUnref(caps); - return ret; -} - -static int qemuDomainMigratePrepareTunnel3(virConnectPtr dconn, virStreamPtr st, const char *cookiein, @@ -10128,10 +9972,15 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn, { virCheckFlags(QEMU_MIGRATION_FLAGS, -1); - return qemuDomainMigratePrepareTunnel3Internal(dconn, st, dom_xml, dname, - cookiein, cookieinlen, - cookieout, cookieoutlen, - flags); + if (!(flags & VIR_MIGRATE_TUNNELLED)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("PrepareTunnel called but no TUNNELLED flag set")); + return -1; + } + + return qemuMigrationPrepare(dconn, dom_xml, dname, NULL, st, + cookiein, cookieinlen, cookieout, + cookieoutlen, NULL, flags); } static int @@ -10149,6 +9998,13 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn, const char *dname = NULL; virCheckFlags(QEMU_MIGRATION_FLAGS, -1); + + if (!(flags & VIR_MIGRATE_TUNNELLED)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("PrepareTunnel called but no TUNNELLED flag set")); + return -1; + } + if (virTypedParamsValidate(params, nparams, QEMU_MIGRATION_PARAMETERS) < 0) return -1; @@ -10160,10 +10016,9 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn, &dname) < 0) return -1; - return qemuDomainMigratePrepareTunnel3Internal(dconn, st, dom_xml, dname, - cookiein, cookieinlen, - cookieout, cookieoutlen, - flags); + return qemuMigrationPrepare(dconn, dom_xml, dname, NULL, st, + cookiein, cookieinlen, cookieout, + cookieoutlen, NULL, flags); } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index c0b721a..7559625 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2424,7 +2424,7 @@ endjob: * This version starts an empty VM listening on a localhost TCP port, and * sets up the corresponding virStream to handle the incoming data. */ -int +static int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver, virConnectPtr dconn, const char *cookiein, @@ -2450,7 +2450,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver, } -int +static int qemuMigrationPrepareDirect(virQEMUDriverPtr driver, virConnectPtr dconn, const char *cookiein, @@ -2477,6 +2477,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 +2582,70 @@ cleanup: return ret; } +int +qemuMigrationPrepare(virConnectPtr dconn, + const char *dom_xml, + const char *dname, + const char *uri_in, + virStreamPtr st, + const char *cookiein, + int cookieinlen, + char **cookieout, + int *cookieoutlen, + char **uri_out, + unsigned long flags) +{ + virQEMUDriverPtr driver = dconn->privateData; + virCapsPtr caps = NULL; + virDomainDefPtr def = NULL; + int ret = -1; + + if ((flags & VIR_MIGRATE_TUNNELLED) && !st) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("tunnelled migration requested but NULL stream " + "passed")); + goto cleanup; + } + + if (!dom_xml) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("no domain XML passed")); + 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) + goto cleanup; + } + + if (flags & VIR_MIGRATE_TUNNELLED) { + ret = qemuMigrationPrepareTunnel(driver, dconn, + cookiein, cookieinlen, + cookieout, cookieoutlen, + st, &def, flags); + } else { + ret = qemuMigrationPrepareDirect(driver, dconn, + cookiein, cookieinlen, + cookieout, cookieoutlen, + uri_in, uri_out, + &def, flags); + } + +cleanup: + virDomainDefFree(def); + virObjectUnref(caps); + return ret; +} + enum qemuMigrationDestinationType { MIGRATION_DEST_HOST, diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index ef7307e..2e03b78 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -102,26 +102,17 @@ char *qemuMigrationBegin(virQEMUDriverPtr driver, int *cookieoutlen, unsigned long flags); -int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver, - virConnectPtr dconn, - const char *cookiein, - int cookieinlen, - char **cookieout, - int *cookieoutlen, - virStreamPtr st, - virDomainDefPtr *def, - unsigned long flags); - -int qemuMigrationPrepareDirect(virQEMUDriverPtr driver, - virConnectPtr dconn, - const char *cookiein, - int cookieinlen, - char **cookieout, - int *cookieoutlen, - const char *uri_in, - char **uri_out, - virDomainDefPtr *def, - unsigned long flags); +int qemuMigrationPrepare(virConnectPtr dconn, + const char *dom_xml, + const char *dname, + const char *uri_in, + virStreamPtr st, + const char *cookiein, + int cookieinlen, + char **cookieout, + int *cookieoutlen, + char **uri_out, + unsigned long flags); int qemuMigrationPerform(virQEMUDriverPtr driver, virConnectPtr conn, -- 1.8.2.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list