conf: Add new VIR_DOMAIN_VIRT_NONE enum

Introduce VIR_DOMAIN_VIRT_NONE to give domaintype the default value of zero.
This is specially helpful in constructing better error messages
when we don't want to look up the default emulator by virtType.

The test data in vircapstest.c is also modified to reflect this change.
This commit is contained in:
Shivangi Dhir 2015-09-17 14:16:55 +05:30 committed by John Ferlan
parent fd00f0e6c7
commit 62569e45ea
5 changed files with 29 additions and 26 deletions

View File

@ -1,7 +1,7 @@
/*
* capabilities.c: hypervisor capabilities
*
* Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006-2015 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@ -573,7 +573,7 @@ virCapsDomainDataCompare(virCapsGuestPtr guest,
virCapsGuestMachinePtr machine,
int ostype,
virArch arch,
int domaintype,
virDomainVirtType domaintype,
const char *emulator,
const char *machinetype)
{
@ -584,7 +584,8 @@ virCapsDomainDataCompare(virCapsGuestPtr guest,
if ((arch != VIR_ARCH_NONE) && (guest->arch.id != arch))
return false;
if (domaintype != -1 && (!domain || domain->type != domaintype))
if (domaintype != VIR_DOMAIN_VIRT_NONE &&
(!domain || domain->type != domaintype))
return false;
if (emulator) {
@ -611,7 +612,7 @@ static virCapsDomainDataPtr
virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
int ostype,
virArch arch,
int domaintype,
virDomainVirtType domaintype,
const char *emulator,
const char *machinetype)
{
@ -678,7 +679,7 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
virDomainOSTypeToString(ostype));
if (arch)
virBufferAsprintf(&buf, "arch=%s ", virArchToString(arch));
if (domaintype != -1)
if (domaintype > VIR_DOMAIN_VIRT_NONE)
virBufferAsprintf(&buf, "domaintype=%s ",
virDomainVirtTypeToString(domaintype));
if (emulator)
@ -723,7 +724,7 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
* @caps: capabilities to query
* @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
* @arch: Architecture to search for
* @domaintype: domain type to search for, of enum VIR_DOMAIN_VIRT
* @domaintype: domain type to search for, of enum virDomainVirtType
* @emulator: Emulator path to search for
* @machinetype: Machine type to search for
*

View File

@ -1,7 +1,7 @@
/*
* capabilities.h: hypervisor capabilities
*
* Copyright (C) 2006-2014 Red Hat, Inc.
* Copyright (C) 2006-2015 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@ -61,7 +61,7 @@ struct _virCapsGuestDomainInfo {
typedef struct _virCapsGuestDomain virCapsGuestDomain;
typedef virCapsGuestDomain *virCapsGuestDomainPtr;
struct _virCapsGuestDomain {
int type;
int type; /* virDomainVirtType */
virCapsGuestDomainInfo info;
};
@ -197,7 +197,7 @@ typedef virCapsDomainData *virCapsDomainDataPtr;
struct _virCapsDomainData {
int ostype;
int arch;
int domaintype;
int domaintype; /* virDomainVirtType */
const char *emulator;
const char *machinetype;
};

View File

@ -106,6 +106,7 @@ VIR_ENUM_IMPL(virDomainTaint, VIR_DOMAIN_TAINT_LAST,
"custom-dtb");
VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
"none",
"qemu",
"kqemu",
"kvm",
@ -14738,7 +14739,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virCapsDomainDataPtr capsdata = NULL;
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
def->os.arch, use_virttype ? def->virtType : -1,
def->os.arch, use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE,
NULL, NULL)))
goto error;

View File

@ -209,6 +209,7 @@ struct _virDomainDeviceDef {
/* Different types of hypervisor */
/* NB: Keep in sync with virDomainVirtTypeToString impl */
typedef enum {
VIR_DOMAIN_VIRT_NONE = 0,
VIR_DOMAIN_VIRT_QEMU,
VIR_DOMAIN_VIRT_KQEMU,
VIR_DOMAIN_VIRT_KVM,

View File

@ -223,39 +223,39 @@ test_virCapsDomainDataLookupQEMU(const void *data ATTRIBUTE_UNUSED)
}
/* Checking each parameter individually */
CAPSCOMP(-1, VIR_ARCH_NONE, -1, NULL, NULL,
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-x86_64", "pc-0.11");
CAPSCOMP(VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_NONE, -1, NULL, NULL,
CAPSCOMP(VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-x86_64", "pc-0.11");
CAPSCOMP(-1, VIR_ARCH_AARCH64, -1, NULL, NULL,
CAPSCOMP(-1, VIR_ARCH_AARCH64, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_AARCH64,
VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-aarch64", "virt");
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_KVM, NULL, NULL,
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
VIR_DOMAIN_VIRT_KVM, "/usr/bin/kvm", "pc");
CAPSCOMP(-1, VIR_ARCH_NONE, -1, "/usr/bin/qemu-system-ppc64", NULL,
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, "/usr/bin/qemu-system-ppc64", NULL,
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64,
VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-ppc64", "pseries");
CAPSCOMP(-1, VIR_ARCH_NONE, -1, NULL, "s390-virtio",
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, "s390-virtio",
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_S390X,
VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-s390x",
"s390-virtio");
CAPSCOMP(-1, VIR_ARCH_NONE, -1, NULL, "pseries",
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, "pseries",
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64,
VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-ppc64", "pseries");
CAPSCOMP(-1, VIR_ARCH_PPC64LE, -1, NULL, "pseries",
CAPSCOMP(-1, VIR_ARCH_PPC64LE, VIR_DOMAIN_VIRT_NONE, NULL, "pseries",
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64LE,
VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-ppc64", "pseries");
CAPS_EXPECT_ERR(VIR_DOMAIN_OSTYPE_LINUX, VIR_ARCH_NONE, -1, NULL, NULL);
CAPS_EXPECT_ERR(-1, VIR_ARCH_PPC64LE, -1, NULL, "pc");
CAPS_EXPECT_ERR(-1, VIR_ARCH_MIPS, -1, NULL, NULL);
CAPS_EXPECT_ERR(VIR_DOMAIN_OSTYPE_LINUX, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL);
CAPS_EXPECT_ERR(-1, VIR_ARCH_PPC64LE, VIR_DOMAIN_VIRT_NONE, NULL, "pc");
CAPS_EXPECT_ERR(-1, VIR_ARCH_MIPS, VIR_DOMAIN_VIRT_NONE, NULL, NULL);
CAPS_EXPECT_ERR(-1, VIR_ARCH_AARCH64, VIR_DOMAIN_VIRT_KVM,
"/usr/bin/qemu-system-aarch64", NULL);
CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, -1,
CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE,
"/usr/bin/qemu-system-aarch64", "pc");
CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc");
@ -277,14 +277,14 @@ test_virCapsDomainDataLookupXen(const void *data ATTRIBUTE_UNUSED)
goto out;
}
CAPSCOMP(-1, VIR_ARCH_NONE, -1, NULL, NULL,
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686, VIR_DOMAIN_VIRT_XEN,
"/usr/lib/xen/bin/qemu-dm", "xenfv");
CAPSCOMP(VIR_DOMAIN_OSTYPE_XEN, VIR_ARCH_NONE, -1, NULL, NULL,
CAPSCOMP(VIR_DOMAIN_OSTYPE_XEN, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_XEN, VIR_ARCH_I686, VIR_DOMAIN_VIRT_XEN,
"/usr/lib/xen/bin/qemu-dm", "xenpv");
CAPS_EXPECT_ERR(VIR_DOMAIN_OSTYPE_XEN, VIR_ARCH_NONE, -1, NULL, "xenfv");
CAPS_EXPECT_ERR(VIR_DOMAIN_OSTYPE_XEN, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, "xenfv");
ret = 0;
out:
@ -305,10 +305,10 @@ test_virCapsDomainDataLookupLXC(const void *data ATTRIBUTE_UNUSED)
goto out;
}
CAPSCOMP(-1, VIR_ARCH_NONE, -1, NULL, NULL,
CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64,
VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL);
CAPSCOMP(-1, VIR_ARCH_X86_64, -1, NULL, NULL,
CAPSCOMP(-1, VIR_ARCH_X86_64, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64,
VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL);