Introduce a new function for the check. virDomainMigrateUnmanagedParams is not a good candidate for this functionality as it is used by migrate family functions too and its have its own checks that are superset of extracted and we don't need to check twice. Actually name of the function is slightly misleading as there is also a check for consitensy of flags parameter alone. So it could be refactored further and reused by all migrate functions bu for now let it be a matter of a different patchset. It is *not* a pure refactoring patch as it introduces offline check for all versions. Looks like it must be done that way and no one will be broken too. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- src/libvirt-domain.c | 81 +++++++++++++++++++------------------------------ 1 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 483537a..2d98997 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -4108,6 +4108,35 @@ virDomainMigrate3(virDomainPtr domain, return NULL; } +static +int virDomainMigrateUnmanagedCheckCompat(virDomainPtr domain, unsigned int flags) +{ + VIR_EXCLUSIVE_FLAGS_RET(VIR_MIGRATE_NON_SHARED_DISK, + VIR_MIGRATE_NON_SHARED_INC, + -1); + + if (flags & VIR_MIGRATE_OFFLINE && + !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn, + VIR_DRV_FEATURE_MIGRATION_OFFLINE)) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("offline migration is not supported by " + "the source host")); + return -1; + } + + 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(); + return -1; + } + + return 0; +} + /** * virDomainMigrateToURI: @@ -4195,34 +4224,12 @@ virDomainMigrateToURI(virDomainPtr domain, virResetLastError(); - /* First checkout the source */ virCheckDomainReturn(domain, -1); virCheckReadOnlyGoto(domain->conn->flags, error); - virCheckNonNullArgGoto(duri, error); - VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK, - VIR_MIGRATE_NON_SHARED_INC, - error); - - if (flags & VIR_MIGRATE_OFFLINE && - !VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn, - VIR_DRV_FEATURE_MIGRATION_OFFLINE)) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("offline migration is not supported by " - "the source host")); - 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(); + if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0) goto error; - } if (flags & VIR_MIGRATE_PEER2PEER) dconnuri = duri; @@ -4343,23 +4350,11 @@ virDomainMigrateToURI2(virDomainPtr domain, virResetLastError(); - /* First checkout the source */ virCheckDomainReturn(domain, -1); virCheckReadOnlyGoto(domain->conn->flags, error); - VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK, - VIR_MIGRATE_NON_SHARED_INC, - 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(); + if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0) goto error; - } if (!(flags & VIR_MIGRATE_PEER2PEER)) dconnuri = NULL; @@ -4426,23 +4421,11 @@ virDomainMigrateToURI3(virDomainPtr domain, virResetLastError(); - /* First checkout the source */ virCheckDomainReturn(domain, -1); virCheckReadOnlyGoto(domain->conn->flags, error); - VIR_EXCLUSIVE_FLAGS_GOTO(VIR_MIGRATE_NON_SHARED_DISK, - VIR_MIGRATE_NON_SHARED_INC, - 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(); + if (virDomainMigrateUnmanagedCheckCompat(domain, flags) < 0) goto error; - } if (!(flags & VIR_MIGRATE_PEER2PEER)) dconnuri = NULL; -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list