Migration capabilities are closely related to migration parameters and
it makes sense to keep them in a single data structure. Similarly to
migration parameters the capabilities are all send to QEMU at once in
qemuMigrationParamsApply, all other APIs operate on the
qemuMigrationParams structure.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_migration.c | 100 ++++++-------------------------
src/qemu/qemu_migration.h | 7 ---
src/qemu/qemu_migration_params.c | 99 +++++++++++++++++++++++-------
src/qemu/qemu_migration_params.h | 11 ++++
4 files changed, 107 insertions(+), 110 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 602ccdfdd5..e01c2a209d 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1174,66 +1174,6 @@ qemuMigrationAnyPostcopyFailed(virQEMUDriverPtr driver,
}
-int
-qemuMigrationOptionSet(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuMonitorMigrationCaps capability,
- bool state,
- qemuDomainAsyncJob job)
-{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- int ret;
-
- if (!qemuMigrationCapsGet(vm, capability)) {
- if (!state) {
- /* Unsupported but we want it off anyway */
- return 0;
- }
-
- if (job == QEMU_ASYNC_JOB_MIGRATION_IN) {
- virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
- _("Migration option '%s' is not supported by
"
- "target QEMU binary"),
- qemuMonitorMigrationCapsTypeToString(capability));
- } else {
- virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
- _("Migration option '%s' is not supported by
"
- "source QEMU binary"),
- qemuMonitorMigrationCapsTypeToString(capability));
- }
- return -1;
- }
-
- if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0)
- return -1;
-
- ret = qemuMonitorSetMigrationCapability(priv->mon, capability, state);
-
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- ret = -1;
-
- return ret;
-}
-
-
-static int
-qemuMigrationOptionSetPostCopy(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- bool state,
- qemuDomainAsyncJob job)
-{
- qemuDomainObjPrivatePtr priv = vm->privateData;
-
- if (qemuMigrationOptionSet(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
- state, job) < 0)
- return -1;
-
- priv->job.postcopyEnabled = state;
- return 0;
-}
-
-
static int
qemuMigrationSrcWaitForSpice(virDomainObjPtr vm)
{
@@ -2465,15 +2405,14 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
goto stopjob;
}
- if (qemuMigrationOptionSet(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
- flags & VIR_MIGRATE_RDMA_PIN_ALL,
- QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+ if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
+ flags & VIR_MIGRATE_RDMA_PIN_ALL,
+ migParams) < 0)
goto stopjob;
- if (qemuMigrationOptionSetPostCopy(driver, vm,
- flags & VIR_MIGRATE_POSTCOPY,
- QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+ if (qemuMigrationParamsSetPostCopy(vm, flags & VIR_MIGRATE_POSTCOPY,
+ migParams) < 0)
goto stopjob;
if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
@@ -3448,27 +3387,26 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
compression, migParams) < 0)
goto error;
- if (qemuMigrationOptionSet(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
- flags & VIR_MIGRATE_AUTO_CONVERGE,
- QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+ if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
+ flags & VIR_MIGRATE_AUTO_CONVERGE,
+ migParams) < 0)
goto error;
- if (qemuMigrationOptionSet(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
- flags & VIR_MIGRATE_RDMA_PIN_ALL,
- QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+ if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
+ flags & VIR_MIGRATE_RDMA_PIN_ALL,
+ migParams) < 0)
goto error;
- if (qemuMigrationOptionSetPostCopy(driver, vm,
- flags & VIR_MIGRATE_POSTCOPY,
- QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+ if (qemuMigrationParamsSetPostCopy(vm, flags & VIR_MIGRATE_POSTCOPY,
+ migParams) < 0)
goto error;
if (qemuMigrationCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER)
&&
- qemuMigrationOptionSet(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER,
- true, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+ qemuMigrationParamsSetCapability(vm,
+
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER,
+ true, migParams) < 0)
goto error;
if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index e59296fd63..fc81eb5016 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -273,11 +273,4 @@ qemuMigrationSrcFetchMirrorStats(virQEMUDriverPtr driver,
qemuDomainAsyncJob asyncJob,
qemuDomainJobInfoPtr jobInfo);
-int
-qemuMigrationOptionSet(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuMonitorMigrationCaps capability,
- bool state,
- qemuDomainAsyncJob job);
-
#endif /* __QEMU_MIGRATION_H__ */
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 4ca49d942e..d934a93086 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -39,6 +39,7 @@ VIR_LOG_INIT("qemu.qemu_migration_params");
#define QEMU_MIGRATION_TLS_ALIAS_BASE "libvirt_migrate"
struct _qemuMigrationParams {
+ virBitmapPtr caps;
qemuMonitorMigrationParams params;
};
@@ -51,7 +52,15 @@ qemuMigrationParamsNew(void)
if (VIR_ALLOC(params) < 0)
return NULL;
+ params->caps = virBitmapNew(QEMU_MONITOR_MIGRATION_CAPS_LAST);
+ if (!params->caps)
+ goto error;
+
return params;
+
+ error:
+ qemuMigrationParamsFree(params);
+ return NULL;
}
@@ -61,6 +70,7 @@ qemuMigrationParamsFree(qemuMigrationParamsPtr migParams)
if (!migParams)
return;
+ virBitmapFree(migParams->caps);
VIR_FREE(migParams->params.tlsCreds);
VIR_FREE(migParams->params.tlsHostname);
VIR_FREE(migParams);
@@ -136,6 +146,10 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
+ if (qemuMonitorSetMigrationCapabilities(priv->mon, priv->migrationCaps,
+ migParams->caps) < 0)
+ goto cleanup;
+
if (qemuMonitorSetMigrationParams(priv->mon, &migParams->params) < 0)
goto cleanup;
@@ -149,6 +163,50 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
}
+int
+qemuMigrationParamsSetCapability(virDomainObjPtr vm,
+ qemuMonitorMigrationCaps capability,
+ bool state,
+ qemuMigrationParamsPtr migParams)
+{
+ if (!qemuMigrationCapsGet(vm, capability)) {
+ if (!state) {
+ /* Unsupported but we want it off anyway */
+ return 0;
+ }
+
+ virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
+ _("Migration option '%s' is not supported by QEMU
binary"),
+ qemuMonitorMigrationCapsTypeToString(capability));
+ return -1;
+ }
+
+ if (state)
+ ignore_value(virBitmapSetBit(migParams->caps, capability));
+ else
+ ignore_value(virBitmapClearBit(migParams->caps, capability));
+
+ return 0;
+}
+
+
+int
+qemuMigrationParamsSetPostCopy(virDomainObjPtr vm,
+ bool state,
+ qemuMigrationParamsPtr migParams)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+
+ if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
+ state, migParams) < 0)
+ return -1;
+
+ priv->job.postcopyEnabled = state;
+ return 0;
+}
+
+
/* qemuMigrationParamsEnableTLS
* @driver: pointer to qemu driver
* @vm: domain object
@@ -272,18 +330,18 @@ qemuMigrationParamsSetCompression(virQEMUDriverPtr driver,
int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData;
- if (qemuMigrationOptionSet(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
- compression->methods &
- (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE),
- asyncJob) < 0)
+ if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
+ compression->methods &
+ (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE),
+ migParams) < 0)
return -1;
- if (qemuMigrationOptionSet(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_COMPRESS,
- compression->methods &
- (1ULL << QEMU_MIGRATION_COMPRESS_MT),
- asyncJob) < 0)
+ if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_COMPRESS,
+ compression->methods &
+ (1ULL << QEMU_MIGRATION_COMPRESS_MT),
+ migParams) < 0)
return -1;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
@@ -369,6 +427,11 @@ qemuMigrationParamsCheck(virQEMUDriverPtr driver,
if (!(origParams = qemuMigrationParamsNew()))
goto cleanup;
+ /*
+ * We want to disable all migration capabilities after migration, no need
+ * to ask QEMU for their current settings.
+ */
+
if (qemuMonitorGetMigrationParams(priv->mon, &origParams->params) < 0)
goto cleanup;
@@ -398,25 +461,17 @@ qemuMigrationParamsReset(virQEMUDriverPtr driver,
int asyncJob,
qemuMigrationParamsPtr origParams)
{
- qemuMonitorMigrationCaps cap;
virErrorPtr err = virSaveLastError();
VIR_DEBUG("Resetting migration parameters %p", origParams);
- if (!virDomainObjIsActive(vm))
+ if (!virDomainObjIsActive(vm) || !origParams)
goto cleanup;
- if (origParams) {
- if (qemuMigrationParamsApply(driver, vm, asyncJob, origParams) < 0)
- goto cleanup;
- qemuMigrationParamsResetTLS(driver, vm, asyncJob, origParams);
- }
+ if (qemuMigrationParamsApply(driver, vm, asyncJob, origParams) < 0)
+ goto cleanup;
- for (cap = 0; cap < QEMU_MONITOR_MIGRATION_CAPS_LAST; cap++) {
- if (qemuMigrationCapsGet(vm, cap) &&
- qemuMigrationOptionSet(driver, vm, cap, false, asyncJob) < 0)
- goto cleanup;
- }
+ qemuMigrationParamsResetTLS(driver, vm, asyncJob, origParams);
cleanup:
if (err) {
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 37e528f36c..e341f73900 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -68,6 +68,17 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
int asyncJob,
qemuMigrationParamsPtr migParams);
+int
+qemuMigrationParamsSetCapability(virDomainObjPtr vm,
+ qemuMonitorMigrationCaps capability,
+ bool state,
+ qemuMigrationParamsPtr migParams);
+
+int
+qemuMigrationParamsSetPostCopy(virDomainObjPtr vm,
+ bool state,
+ qemuMigrationParamsPtr migParams);
+
int
qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
virDomainObjPtr vm,
--
2.17.0