[libvirt] [PATCH v3 11/14] migration: refactor: introduce parameter checking function

Jiri Denemark jdenemar at redhat.com
Wed Sep 30 13:38:27 UTC 2015


On Fri, Sep 18, 2015 at 18:05:49 +0300, Nikolay Shirokovskiy wrote:
> 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 consistensy of flags parameter alone. So it could be refactored further and
> reused by all migrate functions but for now let it be a matter of a different
> patchset.
> 
> Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
> ---
>  src/libvirt-domain.c |   83 +++++++++++++++++++++++++++-----------------------
>  1 files changed, 45 insertions(+), 38 deletions(-)
> 
> diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
> index 5c22460..eec45bd 100644
> --- a/src/libvirt-domain.c
> +++ b/src/libvirt-domain.c
> @@ -4131,6 +4131,39 @@ virDomainMigrate3(virDomainPtr domain,
>  }
>  
>  
> +static
> +int virDomainMigrateUnmanagedCheckCompat(virDomainPtr domain,
> +                                         unsigned int flags)
> +{
> +    int feat;
> +
> +    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)
> +        feat = VIR_DRV_FEATURE_MIGRATION_P2P;
> +    else
> +        feat = VIR_DRV_FEATURE_MIGRATION_DIRECT;
> +
> +    if (!VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn, feat)) {
> +        virReportUnsupportedError();

Use virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, ...),
virReportUnsupportedError is for unsupported APIs while
VIR_ERR_ARGUMENT_UNSUPPORTED says the API is supported but some of its
arguments are not. While at it, I think it's better to keep the code a
bit verbose and separate checks for p2p and direct migration to be able
to provide a usable error message.

Jirka




More information about the libvir-list mailing list