All toURI functions have same checks for flags and features compatibility for
direct and p2p case. Let's factor this checks out before we reuse common code
in toURI functions family. As a side affect we have a more clear code
representation of uri passing conventions for p2p and direct cases.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/libvirt-domain.c | 126 +++++++++++++++++++------------------------------
1 files changed, 49 insertions(+), 77 deletions(-)
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index f7d0777..483537a 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -4187,6 +4187,9 @@ virDomainMigrateToURI(virDomainPtr domain,
const char *dname,
unsigned long bandwidth)
{
+ const char *dconnuri = NULL;
+ const char *miguri = NULL;
+
VIR_DOMAIN_DEBUG(domain, "duri=%p, flags=%lx, dname=%s, bandwidth=%lu",
NULLSTR(duri), flags, NULLSTR(dname), bandwidth);
@@ -4211,34 +4214,25 @@ virDomainMigrateToURI(virDomainPtr domain,
goto error;
}
- if (flags & VIR_MIGRATE_PEER2PEER) {
- if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
- VIR_DRV_FEATURE_MIGRATION_P2P)) {
- VIR_DEBUG("Using peer2peer migration");
- if (virDomainMigrateUnmanaged(domain, NULL, flags,
- dname, duri, NULL, bandwidth) < 0)
- goto error;
- } else {
- /* No peer to peer migration supported */
- virReportUnsupportedError();
- goto error;
- }
- } else {
- if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
- VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
- VIR_DEBUG("Using direct migration");
- if (virDomainMigrateUnmanaged(domain, NULL, flags,
- dname, NULL, duri, bandwidth) < 0)
- goto error;
- } else {
- /* Cannot do a migration with only the perform step */
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("direct migration is not supported by the"
- " connection driver"));
- goto error;
- }
+ if (((flags & VIR_MIGRATE_PEER2PEER) &&
+ !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+ VIR_DRV_FEATURE_MIGRATION_P2P)) ||
+ (!(flags & VIR_MIGRATE_PEER2PEER) &&
+ !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+ VIR_DRV_FEATURE_MIGRATION_DIRECT))) {
+ virReportUnsupportedError();
+ goto error;
}
+ if (flags & VIR_MIGRATE_PEER2PEER)
+ dconnuri = duri;
+ else
+ miguri = duri;
+
+ if (virDomainMigrateUnmanaged(domain, NULL, flags,
+ dname, dconnuri, miguri, bandwidth) < 0)
+ goto error;
+
return 0;
error:
@@ -4357,34 +4351,23 @@ virDomainMigrateToURI2(virDomainPtr domain,
VIR_MIGRATE_NON_SHARED_INC,
error);
- if (flags & VIR_MIGRATE_PEER2PEER) {
- if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
- VIR_DRV_FEATURE_MIGRATION_P2P)) {
- VIR_DEBUG("Using peer2peer migration");
- if (virDomainMigrateUnmanaged(domain, dxml, flags,
- dname, dconnuri, miguri, bandwidth) < 0)
- goto error;
- } else {
- /* No peer to peer migration supported */
- virReportUnsupportedError();
- goto error;
- }
- } else {
- if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
- VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
- VIR_DEBUG("Using direct migration");
- if (virDomainMigrateUnmanaged(domain, dxml, flags,
- dname, NULL, miguri, bandwidth) < 0)
- goto error;
- } else {
- /* Cannot do a migration with only the perform step */
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("direct migration is not supported by the"
- " connection driver"));
- goto error;
- }
+ if (((flags & VIR_MIGRATE_PEER2PEER) &&
+ !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+ VIR_DRV_FEATURE_MIGRATION_P2P)) ||
+ (!(flags & VIR_MIGRATE_PEER2PEER) &&
+ !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+ VIR_DRV_FEATURE_MIGRATION_DIRECT))) {
+ virReportUnsupportedError();
+ goto error;
}
+ if (!(flags & VIR_MIGRATE_PEER2PEER))
+ dconnuri = NULL;
+
+ if (virDomainMigrateUnmanaged(domain, NULL, flags,
+ dname, dconnuri, miguri, bandwidth) < 0)
+ goto error;
+
return 0;
error:
@@ -4451,33 +4434,22 @@ virDomainMigrateToURI3(virDomainPtr domain,
VIR_MIGRATE_NON_SHARED_INC,
error);
- if (flags & VIR_MIGRATE_PEER2PEER) {
- if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
- VIR_DRV_FEATURE_MIGRATION_P2P)) {
- virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
- _("Peer-to-peer migration is not supported by "
- "the connection driver"));
- goto error;
- }
+ if (((flags & VIR_MIGRATE_PEER2PEER) &&
+ !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+ VIR_DRV_FEATURE_MIGRATION_P2P)) ||
+ (!(flags & VIR_MIGRATE_PEER2PEER) &&
+ !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
+ VIR_DRV_FEATURE_MIGRATION_DIRECT))) {
+ virReportUnsupportedError();
+ goto error;
+ }
- VIR_DEBUG("Using peer2peer migration");
- if (virDomainMigrateUnmanagedParams(domain, dconnuri, params, nparams, flags)
< 0)
- goto error;
- } else {
- if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
- VIR_DRV_FEATURE_MIGRATION_DIRECT)) {
- /* Cannot do a migration with only the perform step */
- virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
- _("Direct migration is not supported by the"
- " connection driver"));
- goto error;
- }
+ if (!(flags & VIR_MIGRATE_PEER2PEER))
+ dconnuri = NULL;
- VIR_DEBUG("Using direct migration");
- if (virDomainMigrateUnmanagedParams(domain, NULL, params,
- nparams, flags) < 0)
- goto error;
- }
+ if (virDomainMigrateUnmanagedParams(domain, dconnuri,
+ params, nparams, flags) < 0)
+ goto error;
return 0;
--
1.7.1