From 34b9fe6101d515f0e5baa9aaf59863cbe3d7d351 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 20 Oct 2015 15:48:33 +0200 Subject: [PATCH] qemu: Move incoming URI code to qemu_migration Signed-off-by: Jiri Denemark --- src/qemu/qemu_command.c | 39 -------------------------------------- src/qemu/qemu_command.h | 5 ----- src/qemu/qemu_migration.c | 40 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_migration.h | 6 ++++++ src/qemu/qemu_process.c | 4 ++-- tests/qemuxml2argvtest.c | 5 +++-- 6 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9e5cc78a12..91c55cb0a2 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9088,45 +9088,6 @@ qemuBuildTPMCommandLine(virDomainDefPtr def, return 0; } -int -qemuBuildIncomingCheckProtocol(virQEMUCapsPtr qemuCaps, - const char *migrateFrom) -{ - if (STRPREFIX(migrateFrom, "rdma")) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MIGRATE_RDMA)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("incoming RDMA migration is not supported " - "with this QEMU binary")); - return -1; - } - } else if (!STRPREFIX(migrateFrom, "tcp") && - !STRPREFIX(migrateFrom, "exec") && - !STRPREFIX(migrateFrom, "fd") && - !STRPREFIX(migrateFrom, "unix") && - STRNEQ(migrateFrom, "stdio")) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("unknown migration protocol")); - return -1; - } - - return 0; -} - - -char * -qemuBuildIncomingURI(const char *migrateFrom, - int migrateFd) -{ - char *uri = NULL; - - if (STREQ(migrateFrom, "stdio")) - ignore_value(virAsprintf(&uri, "fd:%d", migrateFd)); - else - ignore_value(VIR_STRDUP(uri, migrateFrom)); - - return uri; -} - qemuBuildCommandLineCallbacks buildCommandLineCallbacks = { .qemuGetSCSIDeviceSgName = virSCSIDeviceGetSgName, diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index db8204336a..3d9f98cb96 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -319,10 +319,5 @@ bool qemuCheckCCWS390AddressSupport(virDomainDefPtr def, virDomainDeviceInfo info, virQEMUCapsPtr qemuCaps, const char *devicename); -int qemuBuildIncomingCheckProtocol(virQEMUCapsPtr qemuCaps, - const char *migrateFrom); - -char *qemuBuildIncomingURI(const char *migrateFrom, - int migrateFd); #endif /* __QEMU_COMMAND_H__*/ diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index e6b3484fa3..4d5b966b25 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2911,6 +2911,46 @@ qemuDomainMigrateOPDRelocate(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, } +int +qemuMigrationCheckIncoming(virQEMUCapsPtr qemuCaps, + const char *migrateFrom) +{ + if (STRPREFIX(migrateFrom, "rdma")) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MIGRATE_RDMA)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("incoming RDMA migration is not supported " + "with this QEMU binary")); + return -1; + } + } else if (!STRPREFIX(migrateFrom, "tcp") && + !STRPREFIX(migrateFrom, "exec") && + !STRPREFIX(migrateFrom, "fd") && + !STRPREFIX(migrateFrom, "unix") && + STRNEQ(migrateFrom, "stdio")) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("unknown migration protocol")); + return -1; + } + + return 0; +} + + +char * +qemuMigrationIncomingURI(const char *migrateFrom, + int migrateFd) +{ + char *uri = NULL; + + if (STREQ(migrateFrom, "stdio")) + ignore_value(virAsprintf(&uri, "fd:%d", migrateFd)); + else + ignore_value(VIR_STRDUP(uri, migrateFrom)); + + return uri; +} + + /* This is called for outgoing non-p2p migrations when a connection to the * client which initiated the migration was closed but we were waiting for it * to follow up with the next phase, that is, in between diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index 8175f4bf7f..ff4fe30b88 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -199,4 +199,10 @@ void qemuMigrationErrorSave(virQEMUDriverPtr driver, void qemuMigrationErrorReport(virQEMUDriverPtr driver, const char *name); +int qemuMigrationCheckIncoming(virQEMUCapsPtr qemuCaps, + const char *migrateFrom); + +char *qemuMigrationIncomingURI(const char *migrateFrom, + int migrateFd); + #endif /* __QEMU_MIGRATION_H__ */ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0bafef927c..fdd640d8de 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4514,10 +4514,10 @@ int qemuProcessStart(virConnectPtr conn, } if (migrateFrom) { - if (qemuBuildIncomingCheckProtocol(priv->qemuCaps, migrateFrom) < 0) + if (qemuMigrationCheckIncoming(priv->qemuCaps, migrateFrom) < 0) goto error; - if (!(migrateURI = qemuBuildIncomingURI(migrateFrom, stdin_fd))) + if (!(migrateURI = qemuMigrationIncomingURI(migrateFrom, stdin_fd))) goto error; } diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e72318fb78..dc8654ed70 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -17,6 +17,7 @@ # include "qemu/qemu_capabilities.h" # include "qemu/qemu_command.h" # include "qemu/qemu_domain.h" +# include "qemu/qemu_migration.h" # include "datatypes.h" # include "conf/storage_conf.h" # include "cpu/cpu_map.h" @@ -410,8 +411,8 @@ testCompareXMLToArgvHelper(const void *data) char *migrateURI = NULL; if (info->migrateFrom && - !(migrateURI = qemuBuildIncomingURI(info->migrateFrom, - info->migrateFd))) + !(migrateURI = qemuMigrationIncomingURI(info->migrateFrom, + info->migrateFd))) goto cleanup; if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",