From 310287b1c94d337cbbb8e6c7bb0d3100752272e6 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 17 Oct 2017 22:00:35 +0200 Subject: [PATCH] qemu: Use bitmap with migration capabilities All calls to qemuMonitorGetMigrationCapability in QEMU driver are replaced with qemuMigrationCapsGet. Signed-off-by: Jiri Denemark Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 7 ++++++ src/qemu/qemu_driver.c | 32 +++++++++++----------------- src/qemu/qemu_migration.c | 45 ++++++++++++++++++++++----------------- src/qemu/qemu_migration.h | 4 ++++ 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e34b8be284..ece8ee7dd2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10304,6 +10304,13 @@ qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver, } } + /* Migration events capability must always be enabled, clearing it from + * migration capabilities bitmap makes sure it won't be touched anywhere + * else. + */ + ignore_value(virBitmapClearBit(priv->migrationCaps, + QEMU_MONITOR_MIGRATION_CAPS_EVENTS)); + ret = 0; cleanup: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d56992fbb1..826d1340e0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13434,20 +13434,17 @@ qemuDomainMigrateGetCompressionCache(virDomainPtr dom, priv = vm->privateData; - qemuDomainObjEnterMonitor(driver, vm); - - ret = qemuMonitorGetMigrationCapability( - priv->mon, - QEMU_MONITOR_MIGRATION_CAPS_XBZRLE); - if (ret == 0) { + if (!qemuMigrationCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("Compressed migration is not supported by " "QEMU binary")); - ret = -1; - } else if (ret > 0) { - ret = qemuMonitorGetMigrationCacheSize(priv->mon, cacheSize); + goto endjob; } + qemuDomainObjEnterMonitor(driver, vm); + + ret = qemuMonitorGetMigrationCacheSize(priv->mon, cacheSize); + if (qemuDomainObjExitMonitor(driver, vm) < 0) ret = -1; @@ -13488,21 +13485,18 @@ qemuDomainMigrateSetCompressionCache(virDomainPtr dom, priv = vm->privateData; - qemuDomainObjEnterMonitor(driver, vm); - - ret = qemuMonitorGetMigrationCapability( - priv->mon, - QEMU_MONITOR_MIGRATION_CAPS_XBZRLE); - if (ret == 0) { + if (!qemuMigrationCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("Compressed migration is not supported by " "QEMU binary")); - ret = -1; - } else if (ret > 0) { - VIR_DEBUG("Setting compression cache to %llu B", cacheSize); - ret = qemuMonitorSetMigrationCacheSize(priv->mon, cacheSize); + goto endjob; } + qemuDomainObjEnterMonitor(driver, vm); + + VIR_DEBUG("Setting compression cache to %llu B", cacheSize); + ret = qemuMonitorSetMigrationCacheSize(priv->mon, cacheSize); + if (qemuDomainObjExitMonitor(driver, vm) < 0) ret = -1; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 57544ee837..e299b6b852 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1274,17 +1274,12 @@ qemuMigrationSetOption(virQEMUDriverPtr driver, qemuDomainObjPrivatePtr priv = vm->privateData; int ret; - if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0) - return -1; - - ret = qemuMonitorGetMigrationCapability(priv->mon, capability); + if (!qemuMigrationCapsGet(vm, capability)) { + if (!state) { + /* Unsupported but we want it off anyway */ + return 0; + } - if (ret < 0) { - goto cleanup; - } else if (ret == 0 && !state) { - /* Unsupported but we want it off anyway */ - goto cleanup; - } else if (ret == 0) { if (job == QEMU_ASYNC_JOB_MIGRATION_IN) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, _("Migration option '%s' is not supported by " @@ -1296,15 +1291,17 @@ qemuMigrationSetOption(virQEMUDriverPtr driver, "source QEMU binary"), qemuMonitorMigrationCapsTypeToString(capability)); } - ret = -1; - goto cleanup; + return -1; } + if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0) + return -1; + ret = qemuMonitorSetMigrationCapability(priv->mon, capability, state); - cleanup: if (qemuDomainObjExitMonitor(driver, vm) < 0) ret = -1; + return ret; } @@ -5928,12 +5925,8 @@ qemuMigrationReset(virQEMUDriverPtr driver, goto cleanup; for (cap = 0; cap < QEMU_MONITOR_MIGRATION_CAPS_LAST; cap++) { - /* "events" capability is set (when supported) in qemuConnectMonitor - * and should never be cleared */ - if (cap == QEMU_MONITOR_MIGRATION_CAPS_EVENTS) - continue; - - if (qemuMigrationSetOption(driver, vm, cap, false, job) < 0) + if (qemuMigrationCapsGet(vm, cap) && + qemuMigrationSetOption(driver, vm, cap, false, job) < 0) goto cleanup; } @@ -5994,3 +5987,17 @@ qemuMigrationFetchMirrorStats(virQEMUDriverPtr driver, virHashFree(blockinfo); return 0; } + + +bool +qemuMigrationCapsGet(virDomainObjPtr vm, + qemuMonitorMigrationCaps cap) +{ + qemuDomainObjPrivatePtr priv = vm->privateData; + bool enabled = false; + + if (priv->migrationCaps) + ignore_value(virBitmapGetBit(priv->migrationCaps, cap, &enabled)); + + return enabled; +} diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index 63a4325624..f634138f4d 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -326,4 +326,8 @@ qemuMigrationFetchMirrorStats(virQEMUDriverPtr driver, qemuDomainAsyncJob asyncJob, qemuDomainJobInfoPtr jobInfo); +bool +qemuMigrationCapsGet(virDomainObjPtr vm, + qemuMonitorMigrationCaps cap); + #endif /* __QEMU_MIGRATION_H__ */ -- GitLab