conf: domcaps: use virTristateBool for 'supported'

Switch most 'supported' handling to use virTristateBool, so eventually
we can handle the ABSENT state.

For now the XML formatter treats ABSENT the same as FALSE, so there's
no functional output change. This will be addressed in later patches

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2019-02-08 18:03:20 -05:00
parent bf68454c46
commit 871093b6a3
5 changed files with 38 additions and 36 deletions

View File

@ -75,7 +75,7 @@ virBhyveDomainCapsFill(virDomainCapsPtr caps,
unsigned int bhyvecaps, unsigned int bhyvecaps,
virDomainCapsStringValuesPtr firmwares) virDomainCapsStringValuesPtr firmwares)
{ {
caps->disk.supported = true; caps->disk.supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(caps->disk.diskDevice, VIR_DOMAIN_CAPS_ENUM_SET(caps->disk.diskDevice,
VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_DEVICE_DISK,
VIR_DOMAIN_DISK_DEVICE_CDROM); VIR_DOMAIN_DISK_DEVICE_CDROM);
@ -84,10 +84,10 @@ virBhyveDomainCapsFill(virDomainCapsPtr caps,
VIR_DOMAIN_DISK_BUS_SATA, VIR_DOMAIN_DISK_BUS_SATA,
VIR_DOMAIN_DISK_BUS_VIRTIO); VIR_DOMAIN_DISK_BUS_VIRTIO);
caps->os.supported = true; caps->os.supported = VIR_TRISTATE_BOOL_YES;
if (bhyvecaps & BHYVE_CAP_LPC_BOOTROM) { if (bhyvecaps & BHYVE_CAP_LPC_BOOTROM) {
caps->os.loader.supported = true; caps->os.loader.supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(caps->os.loader.type, VIR_DOMAIN_CAPS_ENUM_SET(caps->os.loader.type,
VIR_DOMAIN_LOADER_TYPE_PFLASH); VIR_DOMAIN_LOADER_TYPE_PFLASH);
VIR_DOMAIN_CAPS_ENUM_SET(caps->os.loader.readonly, VIR_DOMAIN_CAPS_ENUM_SET(caps->os.loader.readonly,
@ -99,8 +99,8 @@ virBhyveDomainCapsFill(virDomainCapsPtr caps,
if (bhyvecaps & BHYVE_CAP_FBUF) { if (bhyvecaps & BHYVE_CAP_FBUF) {
caps->graphics.supported = true; caps->graphics.supported = VIR_TRISTATE_BOOL_YES;
caps->video.supported = true; caps->video.supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(caps->graphics.type, VIR_DOMAIN_GRAPHICS_TYPE_VNC); VIR_DOMAIN_CAPS_ENUM_SET(caps->graphics.type, VIR_DOMAIN_GRAPHICS_TYPE_VNC);
VIR_DOMAIN_CAPS_ENUM_SET(caps->video.modelType, VIR_DOMAIN_VIDEO_TYPE_GOP); VIR_DOMAIN_CAPS_ENUM_SET(caps->video.modelType, VIR_DOMAIN_VIDEO_TYPE_GOP);
} }

View File

@ -371,9 +371,9 @@ virDomainCapsStringValuesFormat(virBufferPtr buf,
#define FORMAT_PROLOGUE(item) \ #define FORMAT_PROLOGUE(item) \
do { \ do { \
virBufferAsprintf(buf, "<" #item " supported='%s'%s\n", \ virBufferAsprintf(buf, "<" #item " supported='%s'%s\n", \
item->supported ? "yes" : "no", \ (item->supported == VIR_TRISTATE_BOOL_YES) ? "yes" : "no", \
item->supported ? ">" : "/>"); \ (item->supported == VIR_TRISTATE_BOOL_YES) ? ">" : "/>"); \
if (!item->supported) \ if (item->supported != VIR_TRISTATE_BOOL_YES) \
return; \ return; \
virBufferAdjustIndent(buf, 2); \ virBufferAdjustIndent(buf, 2); \
} while (0) } while (0)
@ -387,7 +387,7 @@ virDomainCapsStringValuesFormat(virBufferPtr buf,
#define FORMAT_SINGLE(name, supported) \ #define FORMAT_SINGLE(name, supported) \
do { \ do { \
virBufferAsprintf(&buf, "<%s supported='%s'/>\n", name, \ virBufferAsprintf(&buf, "<%s supported='%s'/>\n", name, \
supported ? "yes" : "no"); \ (supported == VIR_TRISTATE_BOOL_YES) ? "yes" : "no"); \
} while (0) } while (0)
#define ENUM_PROCESS(master, capsEnum, valToStr) \ #define ENUM_PROCESS(master, capsEnum, valToStr) \

View File

@ -46,7 +46,7 @@ struct _virDomainCapsStringValues {
typedef struct _virDomainCapsLoader virDomainCapsLoader; typedef struct _virDomainCapsLoader virDomainCapsLoader;
typedef virDomainCapsLoader *virDomainCapsLoaderPtr; typedef virDomainCapsLoader *virDomainCapsLoaderPtr;
struct _virDomainCapsLoader { struct _virDomainCapsLoader {
bool supported; virTristateBool supported;
virDomainCapsStringValues values; /* Info about values for the element */ virDomainCapsStringValues values; /* Info about values for the element */
virDomainCapsEnum type; /* Info about virDomainLoader */ virDomainCapsEnum type; /* Info about virDomainLoader */
virDomainCapsEnum readonly; /* Info about readonly:virTristateBool */ virDomainCapsEnum readonly; /* Info about readonly:virTristateBool */
@ -55,14 +55,14 @@ struct _virDomainCapsLoader {
typedef struct _virDomainCapsOS virDomainCapsOS; typedef struct _virDomainCapsOS virDomainCapsOS;
typedef virDomainCapsOS *virDomainCapsOSPtr; typedef virDomainCapsOS *virDomainCapsOSPtr;
struct _virDomainCapsOS { struct _virDomainCapsOS {
bool supported; virTristateBool supported;
virDomainCapsLoader loader; /* Info about virDomainLoaderDef */ virDomainCapsLoader loader; /* Info about virDomainLoaderDef */
}; };
typedef struct _virDomainCapsDeviceDisk virDomainCapsDeviceDisk; typedef struct _virDomainCapsDeviceDisk virDomainCapsDeviceDisk;
typedef virDomainCapsDeviceDisk *virDomainCapsDeviceDiskPtr; typedef virDomainCapsDeviceDisk *virDomainCapsDeviceDiskPtr;
struct _virDomainCapsDeviceDisk { struct _virDomainCapsDeviceDisk {
bool supported; virTristateBool supported;
virDomainCapsEnum diskDevice; /* Info about virDomainDiskDevice enum values */ virDomainCapsEnum diskDevice; /* Info about virDomainDiskDevice enum values */
virDomainCapsEnum bus; /* Info about virDomainDiskBus enum values */ virDomainCapsEnum bus; /* Info about virDomainDiskBus enum values */
virDomainCapsEnum model; /* Info about virDomainDiskModel enum values */ virDomainCapsEnum model; /* Info about virDomainDiskModel enum values */
@ -72,21 +72,21 @@ struct _virDomainCapsDeviceDisk {
typedef struct _virDomainCapsDeviceGraphics virDomainCapsDeviceGraphics; typedef struct _virDomainCapsDeviceGraphics virDomainCapsDeviceGraphics;
typedef virDomainCapsDeviceGraphics *virDomainCapsDeviceGraphicsPtr; typedef virDomainCapsDeviceGraphics *virDomainCapsDeviceGraphicsPtr;
struct _virDomainCapsDeviceGraphics { struct _virDomainCapsDeviceGraphics {
bool supported; virTristateBool supported;
virDomainCapsEnum type; /* virDomainGraphicsType */ virDomainCapsEnum type; /* virDomainGraphicsType */
}; };
typedef struct _virDomainCapsDeviceVideo virDomainCapsDeviceVideo; typedef struct _virDomainCapsDeviceVideo virDomainCapsDeviceVideo;
typedef virDomainCapsDeviceVideo *virDomainCapsDeviceVideoPtr; typedef virDomainCapsDeviceVideo *virDomainCapsDeviceVideoPtr;
struct _virDomainCapsDeviceVideo { struct _virDomainCapsDeviceVideo {
bool supported; virTristateBool supported;
virDomainCapsEnum modelType; /* virDomainVideoType */ virDomainCapsEnum modelType; /* virDomainVideoType */
}; };
typedef struct _virDomainCapsDeviceHostdev virDomainCapsDeviceHostdev; typedef struct _virDomainCapsDeviceHostdev virDomainCapsDeviceHostdev;
typedef virDomainCapsDeviceHostdev *virDomainCapsDeviceHostdevPtr; typedef virDomainCapsDeviceHostdev *virDomainCapsDeviceHostdevPtr;
struct _virDomainCapsDeviceHostdev { struct _virDomainCapsDeviceHostdev {
bool supported; virTristateBool supported;
virDomainCapsEnum mode; /* Info about virDomainHostdevMode */ virDomainCapsEnum mode; /* Info about virDomainHostdevMode */
virDomainCapsEnum startupPolicy; /* Info about virDomainStartupPolicy */ virDomainCapsEnum startupPolicy; /* Info about virDomainStartupPolicy */
virDomainCapsEnum subsysType; /* Info about virDomainHostdevSubsysType */ virDomainCapsEnum subsysType; /* Info about virDomainHostdevSubsysType */
@ -98,7 +98,7 @@ struct _virDomainCapsDeviceHostdev {
typedef struct _virDomainCapsFeatureGIC virDomainCapsFeatureGIC; typedef struct _virDomainCapsFeatureGIC virDomainCapsFeatureGIC;
typedef virDomainCapsFeatureGIC *virDomainCapsFeatureGICPtr; typedef virDomainCapsFeatureGIC *virDomainCapsFeatureGICPtr;
struct _virDomainCapsFeatureGIC { struct _virDomainCapsFeatureGIC {
bool supported; virTristateBool supported;
virDomainCapsEnum version; /* Info about virGICVersion */ virDomainCapsEnum version; /* Info about virGICVersion */
}; };
@ -156,7 +156,7 @@ struct _virDomainCaps {
/* Some machine specific info */ /* Some machine specific info */
int maxvcpus; int maxvcpus;
bool iothreads; /* Whether I/O threads are supported or not. */ virTristateBool iothreads; /* Whether I/O threads are supported or not. */
virDomainCapsOS os; virDomainCapsOS os;
virDomainCapsCPU cpu; virDomainCapsCPU cpu;
@ -167,8 +167,8 @@ struct _virDomainCaps {
/* add new domain devices here */ /* add new domain devices here */
virDomainCapsFeatureGIC gic; virDomainCapsFeatureGIC gic;
bool vmcoreinfo; virTristateBool vmcoreinfo;
bool genid; virTristateBool genid;
virSEVCapabilityPtr sev; virSEVCapabilityPtr sev;
/* add new domain features here */ /* add new domain features here */
}; };

View File

@ -603,12 +603,12 @@ libxlMakeDomainOSCaps(const char *machine,
virDomainCapsLoaderPtr capsLoader = &os->loader; virDomainCapsLoaderPtr capsLoader = &os->loader;
size_t i; size_t i;
os->supported = true; os->supported = VIR_TRISTATE_BOOL_YES;
if (STREQ(machine, "xenpv") || STREQ(machine, "xenpvh")) if (STREQ(machine, "xenpv") || STREQ(machine, "xenpvh"))
return 0; return 0;
capsLoader->supported = true; capsLoader->supported = VIR_TRISTATE_BOOL_YES;
if (VIR_ALLOC_N(capsLoader->values.values, nfirmwares) < 0) if (VIR_ALLOC_N(capsLoader->values.values, nfirmwares) < 0)
return -1; return -1;
@ -631,7 +631,7 @@ libxlMakeDomainOSCaps(const char *machine,
static int static int
libxlMakeDomainDeviceDiskCaps(virDomainCapsDeviceDiskPtr dev) libxlMakeDomainDeviceDiskCaps(virDomainCapsDeviceDiskPtr dev)
{ {
dev->supported = true; dev->supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(dev->diskDevice, VIR_DOMAIN_CAPS_ENUM_SET(dev->diskDevice,
VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_DEVICE_DISK,
@ -648,7 +648,7 @@ libxlMakeDomainDeviceDiskCaps(virDomainCapsDeviceDiskPtr dev)
static int static int
libxlMakeDomainDeviceGraphicsCaps(virDomainCapsDeviceGraphicsPtr dev) libxlMakeDomainDeviceGraphicsCaps(virDomainCapsDeviceGraphicsPtr dev)
{ {
dev->supported = true; dev->supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(dev->type, VIR_DOMAIN_CAPS_ENUM_SET(dev->type,
VIR_DOMAIN_GRAPHICS_TYPE_SDL, VIR_DOMAIN_GRAPHICS_TYPE_SDL,
@ -661,7 +661,7 @@ libxlMakeDomainDeviceGraphicsCaps(virDomainCapsDeviceGraphicsPtr dev)
static int static int
libxlMakeDomainDeviceVideoCaps(virDomainCapsDeviceVideoPtr dev) libxlMakeDomainDeviceVideoCaps(virDomainCapsDeviceVideoPtr dev)
{ {
dev->supported = true; dev->supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType,
VIR_DOMAIN_VIDEO_TYPE_VGA, VIR_DOMAIN_VIDEO_TYPE_VGA,
@ -683,7 +683,7 @@ bool libxlCapsHasPVUSB(void)
static int static int
libxlMakeDomainDeviceHostdevCaps(virDomainCapsDeviceHostdevPtr dev) libxlMakeDomainDeviceHostdevCaps(virDomainCapsDeviceHostdevPtr dev)
{ {
dev->supported = true; dev->supported = VIR_TRISTATE_BOOL_YES;
/* VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES is for containers only */ /* VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES is for containers only */
VIR_DOMAIN_CAPS_ENUM_SET(dev->mode, VIR_DOMAIN_CAPS_ENUM_SET(dev->mode,
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS); VIR_DOMAIN_HOSTDEV_MODE_SUBSYS);

View File

@ -4918,7 +4918,7 @@ virQEMUCapsFillDomainLoaderCaps(virDomainCapsLoaderPtr capsLoader,
{ {
size_t i; size_t i;
capsLoader->supported = true; capsLoader->supported = VIR_TRISTATE_BOOL_YES;
if (VIR_ALLOC_N(capsLoader->values.values, nfirmwares) < 0) if (VIR_ALLOC_N(capsLoader->values.values, nfirmwares) < 0)
return -1; return -1;
@ -4958,7 +4958,7 @@ virQEMUCapsFillDomainOSCaps(virDomainCapsOSPtr os,
{ {
virDomainCapsLoaderPtr capsLoader = &os->loader; virDomainCapsLoaderPtr capsLoader = &os->loader;
os->supported = true; os->supported = VIR_TRISTATE_BOOL_YES;
if (virQEMUCapsFillDomainLoaderCaps(capsLoader, firmwares, nfirmwares) < 0) if (virQEMUCapsFillDomainLoaderCaps(capsLoader, firmwares, nfirmwares) < 0)
return -1; return -1;
return 0; return 0;
@ -5011,7 +5011,8 @@ static int
virQEMUCapsFillDomainIOThreadCaps(virQEMUCapsPtr qemuCaps, virQEMUCapsFillDomainIOThreadCaps(virQEMUCapsPtr qemuCaps,
virDomainCapsPtr domCaps) virDomainCapsPtr domCaps)
{ {
domCaps->iothreads = virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_IOTHREAD); domCaps->iothreads = virTristateBoolFromBool(
virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_IOTHREAD));
return 0; return 0;
} }
@ -5022,7 +5023,7 @@ virQEMUCapsFillDomainDeviceDiskCaps(virQEMUCapsPtr qemuCaps,
const char *machine, const char *machine,
virDomainCapsDeviceDiskPtr disk) virDomainCapsDeviceDiskPtr disk)
{ {
disk->supported = true; disk->supported = VIR_TRISTATE_BOOL_YES;
/* QEMU supports all of these */ /* QEMU supports all of these */
VIR_DOMAIN_CAPS_ENUM_SET(disk->diskDevice, VIR_DOMAIN_CAPS_ENUM_SET(disk->diskDevice,
VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_DEVICE_DISK,
@ -5067,7 +5068,7 @@ static int
virQEMUCapsFillDomainDeviceGraphicsCaps(virQEMUCapsPtr qemuCaps, virQEMUCapsFillDomainDeviceGraphicsCaps(virQEMUCapsPtr qemuCaps,
virDomainCapsDeviceGraphicsPtr dev) virDomainCapsDeviceGraphicsPtr dev)
{ {
dev->supported = true; dev->supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(dev->type, VIR_DOMAIN_GRAPHICS_TYPE_SDL); VIR_DOMAIN_CAPS_ENUM_SET(dev->type, VIR_DOMAIN_GRAPHICS_TYPE_SDL);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC)) if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC))
@ -5083,7 +5084,7 @@ static int
virQEMUCapsFillDomainDeviceVideoCaps(virQEMUCapsPtr qemuCaps, virQEMUCapsFillDomainDeviceVideoCaps(virQEMUCapsPtr qemuCaps,
virDomainCapsDeviceVideoPtr dev) virDomainCapsDeviceVideoPtr dev)
{ {
dev->supported = true; dev->supported = VIR_TRISTATE_BOOL_YES;
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VGA)) if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VGA))
VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_VIDEO_TYPE_VGA); VIR_DOMAIN_CAPS_ENUM_SET(dev->modelType, VIR_DOMAIN_VIDEO_TYPE_VGA);
@ -5107,7 +5108,7 @@ virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCapsPtr qemuCaps,
bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy(); bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO(); bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
hostdev->supported = true; hostdev->supported = VIR_TRISTATE_BOOL_YES;
/* VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES is for containers only */ /* VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES is for containers only */
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->mode, VIR_DOMAIN_CAPS_ENUM_SET(hostdev->mode,
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS); VIR_DOMAIN_HOSTDEV_MODE_SUBSYS);
@ -5222,7 +5223,7 @@ virQEMUCapsFillDomainFeatureGICCaps(virQEMUCapsPtr qemuCaps,
version)) version))
continue; continue;
gic->supported = true; gic->supported = VIR_TRISTATE_BOOL_YES;
VIR_DOMAIN_CAPS_ENUM_SET(gic->version, VIR_DOMAIN_CAPS_ENUM_SET(gic->version,
version); version);
} }
@ -5293,10 +5294,11 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps,
domCaps->maxvcpus = MIN(domCaps->maxvcpus, hostmaxvcpus); domCaps->maxvcpus = MIN(domCaps->maxvcpus, hostmaxvcpus);
} }
domCaps->vmcoreinfo = virQEMUCapsGet(qemuCaps, domCaps->vmcoreinfo = virTristateBoolFromBool(
QEMU_CAPS_DEVICE_VMCOREINFO); virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMCOREINFO));
domCaps->genid = virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMGENID); domCaps->genid = virTristateBoolFromBool(
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMGENID));
if (virQEMUCapsFillDomainOSCaps(os, firmwares, nfirmwares) < 0 || if (virQEMUCapsFillDomainOSCaps(os, firmwares, nfirmwares) < 0 ||
virQEMUCapsFillDomainCPUCaps(caps, qemuCaps, domCaps) < 0 || virQEMUCapsFillDomainCPUCaps(caps, qemuCaps, domCaps) < 0 ||