2014-06-25 11:24:53 +00:00
|
|
|
/*
|
|
|
|
* domain_capabilities.c: domain capabilities XML processing
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2019-04-04 17:09:18 +00:00
|
|
|
#include "device_conf.h"
|
2014-06-25 11:24:53 +00:00
|
|
|
#include "domain_capabilities.h"
|
|
|
|
#include "domain_conf.h"
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
|
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virDomainCapsCPUUsable,
|
|
|
|
VIR_DOMCAPS_CPU_USABLE_LAST,
|
2019-01-20 16:30:15 +00:00
|
|
|
"unknown", "yes", "no",
|
|
|
|
);
|
2016-06-15 14:15:44 +00:00
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
static virClassPtr virDomainCapsClass;
|
2016-04-22 09:08:57 +00:00
|
|
|
static virClassPtr virDomainCapsCPUModelsClass;
|
2014-06-25 11:24:53 +00:00
|
|
|
|
|
|
|
static void virDomainCapsDispose(void *obj);
|
2016-04-22 09:08:57 +00:00
|
|
|
static void virDomainCapsCPUModelsDispose(void *obj);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
|
|
|
static int virDomainCapsOnceInit(void)
|
|
|
|
{
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virDomainCaps, virClassForObjectLockable()))
|
2014-06-25 11:24:53 +00:00
|
|
|
return -1;
|
2016-04-22 09:08:57 +00:00
|
|
|
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virDomainCapsCPUModels, virClassForObject()))
|
2016-04-22 09:08:57 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virDomainCaps);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
|
|
|
|
2014-09-16 23:52:54 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsStringValuesFree(virDomainCapsStringValuesPtr values)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!values || !values->values)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < values->nvalues; i++)
|
|
|
|
VIR_FREE(values->values[i]);
|
|
|
|
VIR_FREE(values->values);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-08 14:40:51 +00:00
|
|
|
void
|
|
|
|
virSEVCapabilitiesFree(virSEVCapability *cap)
|
|
|
|
{
|
|
|
|
if (!cap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(cap->pdh);
|
|
|
|
VIR_FREE(cap->cert_chain);
|
|
|
|
VIR_FREE(cap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsDispose(void *obj)
|
|
|
|
{
|
|
|
|
virDomainCapsPtr caps = obj;
|
|
|
|
|
|
|
|
VIR_FREE(caps->path);
|
|
|
|
VIR_FREE(caps->machine);
|
2016-04-22 09:08:57 +00:00
|
|
|
virObjectUnref(caps->cpu.custom);
|
2017-04-09 10:43:45 +00:00
|
|
|
virCPUDefFree(caps->cpu.hostModel);
|
2018-06-08 14:40:52 +00:00
|
|
|
virSEVCapabilitiesFree(caps->sev);
|
2014-09-16 23:52:54 +00:00
|
|
|
|
|
|
|
virDomainCapsStringValuesFree(&caps->os.loader.values);
|
2014-06-25 11:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-22 09:08:57 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsCPUModelsDispose(void *obj)
|
|
|
|
{
|
|
|
|
virDomainCapsCPUModelsPtr cpuModels = obj;
|
|
|
|
size_t i;
|
|
|
|
|
2017-10-26 10:20:45 +00:00
|
|
|
for (i = 0; i < cpuModels->nmodels; i++) {
|
2016-04-22 09:08:57 +00:00
|
|
|
VIR_FREE(cpuModels->models[i].name);
|
2017-10-26 10:20:45 +00:00
|
|
|
virStringListFree(cpuModels->models[i].blockers);
|
|
|
|
}
|
2016-04-22 09:08:57 +00:00
|
|
|
|
|
|
|
VIR_FREE(cpuModels->models);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
virDomainCapsPtr
|
|
|
|
virDomainCapsNew(const char *path,
|
|
|
|
const char *machine,
|
|
|
|
virArch arch,
|
|
|
|
virDomainVirtType virttype)
|
|
|
|
{
|
|
|
|
virDomainCapsPtr caps = NULL;
|
|
|
|
|
|
|
|
if (virDomainCapsInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(caps = virObjectLockableNew(virDomainCapsClass)))
|
|
|
|
return NULL;
|
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
caps->path = g_strdup(path);
|
|
|
|
caps->machine = g_strdup(machine);
|
2014-06-25 11:24:53 +00:00
|
|
|
caps->arch = arch;
|
|
|
|
caps->virttype = virttype;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-22 09:08:57 +00:00
|
|
|
virDomainCapsCPUModelsPtr
|
|
|
|
virDomainCapsCPUModelsNew(size_t nmodels)
|
|
|
|
{
|
|
|
|
virDomainCapsCPUModelsPtr cpuModels = NULL;
|
|
|
|
|
|
|
|
if (virDomainCapsInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(cpuModels = virObjectNew(virDomainCapsCPUModelsClass)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(cpuModels->models, nmodels) < 0)
|
|
|
|
goto error;
|
|
|
|
cpuModels->nmodels_max = nmodels;
|
|
|
|
|
|
|
|
return cpuModels;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(cpuModels);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virDomainCapsCPUModelsPtr
|
|
|
|
virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
|
|
|
|
{
|
|
|
|
virDomainCapsCPUModelsPtr cpuModels;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!(cpuModels = virDomainCapsCPUModelsNew(old->nmodels)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < old->nmodels; i++) {
|
2016-06-15 14:15:44 +00:00
|
|
|
if (virDomainCapsCPUModelsAdd(cpuModels,
|
|
|
|
old->models[i].name, -1,
|
2017-09-19 16:35:08 +00:00
|
|
|
old->models[i].usable,
|
|
|
|
old->models[i].blockers) < 0)
|
2016-04-22 09:08:57 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpuModels;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(cpuModels);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-29 08:42:56 +00:00
|
|
|
virDomainCapsCPUModelsPtr
|
|
|
|
virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
|
2016-11-20 22:21:19 +00:00
|
|
|
const char **models,
|
|
|
|
const char **blacklist)
|
2016-04-29 08:42:56 +00:00
|
|
|
{
|
|
|
|
virDomainCapsCPUModelsPtr cpuModels;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!(cpuModels = virDomainCapsCPUModelsNew(0)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < old->nmodels; i++) {
|
2016-11-25 08:18:35 +00:00
|
|
|
if (models && !virStringListHasString(models, old->models[i].name))
|
2016-04-29 08:42:56 +00:00
|
|
|
continue;
|
|
|
|
|
2016-11-20 22:21:19 +00:00
|
|
|
if (blacklist && virStringListHasString(blacklist, old->models[i].name))
|
|
|
|
continue;
|
|
|
|
|
2016-04-29 08:42:56 +00:00
|
|
|
if (virDomainCapsCPUModelsAdd(cpuModels,
|
2016-06-15 14:15:44 +00:00
|
|
|
old->models[i].name, -1,
|
2017-09-19 16:35:08 +00:00
|
|
|
old->models[i].usable,
|
|
|
|
old->models[i].blockers) < 0)
|
2016-04-29 08:42:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpuModels;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(cpuModels);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-22 09:08:57 +00:00
|
|
|
int
|
|
|
|
virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
|
2016-06-15 14:15:44 +00:00
|
|
|
char **name,
|
2017-09-19 16:35:08 +00:00
|
|
|
virDomainCapsCPUUsable usable,
|
|
|
|
char ***blockers)
|
2016-04-22 09:08:57 +00:00
|
|
|
{
|
|
|
|
if (VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
|
|
|
|
cpuModels->nmodels, 1) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-06-15 14:15:44 +00:00
|
|
|
cpuModels->models[cpuModels->nmodels].usable = usable;
|
2019-10-16 11:43:01 +00:00
|
|
|
cpuModels->models[cpuModels->nmodels].name = g_steal_pointer(&*name);
|
2017-09-19 16:35:08 +00:00
|
|
|
|
|
|
|
if (blockers)
|
2019-10-16 11:43:01 +00:00
|
|
|
cpuModels->models[cpuModels->nmodels].blockers = g_steal_pointer(&*blockers);
|
2017-09-19 16:35:08 +00:00
|
|
|
|
2016-06-15 14:15:44 +00:00
|
|
|
cpuModels->nmodels++;
|
2016-04-22 09:08:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
|
|
|
|
const char *name,
|
2016-06-15 14:15:44 +00:00
|
|
|
ssize_t nameLen,
|
2017-09-19 16:35:08 +00:00
|
|
|
virDomainCapsCPUUsable usable,
|
|
|
|
char **blockers)
|
2016-04-22 09:08:57 +00:00
|
|
|
{
|
2017-09-19 16:35:08 +00:00
|
|
|
char *nameCopy = NULL;
|
|
|
|
char **blockersCopy = NULL;
|
|
|
|
|
|
|
|
if (VIR_STRNDUP(nameCopy, name, nameLen) < 0)
|
|
|
|
goto error;
|
2016-04-22 09:08:57 +00:00
|
|
|
|
2017-09-19 16:35:08 +00:00
|
|
|
if (virStringListCopy(&blockersCopy, (const char **)blockers) < 0)
|
2016-04-22 09:08:57 +00:00
|
|
|
goto error;
|
|
|
|
|
2017-09-19 16:35:08 +00:00
|
|
|
if (virDomainCapsCPUModelsAddSteal(cpuModels, &nameCopy,
|
|
|
|
usable, &blockersCopy) < 0)
|
2016-04-22 09:08:57 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2017-09-19 16:35:08 +00:00
|
|
|
VIR_FREE(nameCopy);
|
|
|
|
virStringListFree(blockersCopy);
|
2016-04-22 09:08:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-13 15:37:34 +00:00
|
|
|
virDomainCapsCPUModelPtr
|
|
|
|
virDomainCapsCPUModelsGet(virDomainCapsCPUModelsPtr cpuModels,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!cpuModels)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < cpuModels->nmodels; i++) {
|
2018-05-16 14:58:47 +00:00
|
|
|
if (STREQ(cpuModels->models[i].name, name))
|
2017-10-13 15:37:34 +00:00
|
|
|
return cpuModels->models + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
int
|
|
|
|
virDomainCapsEnumSet(virDomainCapsEnumPtr capsEnum,
|
|
|
|
const char *capsEnumName,
|
|
|
|
size_t nvalues,
|
|
|
|
unsigned int *values)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nvalues; i++) {
|
|
|
|
unsigned int val = 1 << values[i];
|
|
|
|
|
|
|
|
if (!val) {
|
|
|
|
/* Integer overflow */
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("integer overflow on %s. Please contact the "
|
|
|
|
"libvirt development team at libvir-list@redhat.com"),
|
|
|
|
capsEnumName);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
capsEnum->values |= val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virDomainCapsEnumClear(virDomainCapsEnumPtr capsEnum)
|
|
|
|
{
|
|
|
|
capsEnum->values = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virDomainCapsEnumFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsEnumPtr capsEnum,
|
|
|
|
const char *capsEnumName,
|
|
|
|
virDomainCapsValToStr valToStr)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
|
2019-03-06 23:22:01 +00:00
|
|
|
if (!capsEnum->report) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
virBufferAsprintf(buf, "<enum name='%s'", capsEnumName);
|
|
|
|
if (!capsEnum->values) {
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
virBufferAddLit(buf, ">\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(capsEnum->values) * CHAR_BIT; i++) {
|
|
|
|
const char *val;
|
|
|
|
|
|
|
|
if (!(capsEnum->values & (1 << i)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((val = (valToStr)(i)))
|
|
|
|
virBufferAsprintf(buf, "<value>%s</value>\n", val);
|
|
|
|
}
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</enum>\n");
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-16 23:52:54 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
virDomainCapsStringValuesFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsStringValuesPtr values)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < values->nvalues; i++)
|
|
|
|
virBufferEscapeString(buf, "<value>%s</value>\n", values->values[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define FORMAT_PROLOGUE(item) \
|
|
|
|
do { \
|
2019-02-19 19:12:47 +00:00
|
|
|
if (item->supported == VIR_TRISTATE_BOOL_ABSENT) \
|
|
|
|
return; \
|
2017-11-03 12:09:47 +00:00
|
|
|
virBufferAsprintf(buf, "<" #item " supported='%s'%s\n", \
|
2019-02-08 23:03:20 +00:00
|
|
|
(item->supported == VIR_TRISTATE_BOOL_YES) ? "yes" : "no", \
|
|
|
|
(item->supported == VIR_TRISTATE_BOOL_YES) ? ">" : "/>"); \
|
2019-02-19 19:12:47 +00:00
|
|
|
if (item->supported == VIR_TRISTATE_BOOL_NO) \
|
2017-11-03 12:09:47 +00:00
|
|
|
return; \
|
|
|
|
virBufferAdjustIndent(buf, 2); \
|
2014-06-25 11:24:53 +00:00
|
|
|
} while (0)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define FORMAT_EPILOGUE(item) \
|
|
|
|
do { \
|
|
|
|
virBufferAdjustIndent(buf, -2); \
|
|
|
|
virBufferAddLit(buf, "</" #item ">\n"); \
|
2014-06-25 11:24:53 +00:00
|
|
|
} while (0)
|
|
|
|
|
2019-02-08 23:32:48 +00:00
|
|
|
#define FORMAT_SINGLE(name, supported) \
|
|
|
|
do { \
|
2019-02-19 19:12:47 +00:00
|
|
|
if (supported != VIR_TRISTATE_BOOL_ABSENT) { \
|
|
|
|
virBufferAsprintf(&buf, "<%s supported='%s'/>\n", name, \
|
|
|
|
(supported == VIR_TRISTATE_BOOL_YES) ? "yes" : "no"); \
|
|
|
|
} \
|
2019-02-08 23:32:48 +00:00
|
|
|
} while (0)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define ENUM_PROCESS(master, capsEnum, valToStr) \
|
|
|
|
do { \
|
|
|
|
virDomainCapsEnumFormat(buf, &master->capsEnum, \
|
|
|
|
#capsEnum, valToStr); \
|
2014-06-25 11:24:53 +00:00
|
|
|
} while (0)
|
|
|
|
|
2014-09-16 12:47:47 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
virDomainCapsLoaderFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsLoaderPtr loader)
|
|
|
|
{
|
|
|
|
FORMAT_PROLOGUE(loader);
|
|
|
|
|
2014-09-16 23:52:54 +00:00
|
|
|
virDomainCapsStringValuesFormat(buf, &loader->values);
|
2014-09-16 12:47:47 +00:00
|
|
|
ENUM_PROCESS(loader, type, virDomainLoaderTypeToString);
|
|
|
|
ENUM_PROCESS(loader, readonly, virTristateBoolTypeToString);
|
2019-04-04 10:42:14 +00:00
|
|
|
ENUM_PROCESS(loader, secure, virTristateBoolTypeToString);
|
2014-09-16 12:47:47 +00:00
|
|
|
|
|
|
|
FORMAT_EPILOGUE(loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virDomainCapsOSFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsOSPtr os)
|
|
|
|
{
|
|
|
|
virDomainCapsLoaderPtr loader = &os->loader;
|
|
|
|
|
|
|
|
FORMAT_PROLOGUE(os);
|
|
|
|
|
2019-04-04 10:42:14 +00:00
|
|
|
ENUM_PROCESS(os, firmware, virDomainOsDefFirmwareTypeToString);
|
|
|
|
|
2014-09-16 12:47:47 +00:00
|
|
|
virDomainCapsLoaderFormat(buf, loader);
|
|
|
|
|
|
|
|
FORMAT_EPILOGUE(os);
|
|
|
|
}
|
|
|
|
|
2016-04-22 09:08:57 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsCPUCustomFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsCPUModelsPtr custom)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
|
|
|
|
for (i = 0; i < custom->nmodels; i++) {
|
2016-06-15 14:15:44 +00:00
|
|
|
virDomainCapsCPUModelPtr model = custom->models + i;
|
|
|
|
virBufferAsprintf(buf, "<model usable='%s'>%s</model>\n",
|
|
|
|
virDomainCapsCPUUsableTypeToString(model->usable),
|
|
|
|
model->name);
|
2016-04-22 09:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virDomainCapsCPUFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsCPUPtr cpu)
|
|
|
|
{
|
|
|
|
virBufferAddLit(buf, "<cpu>\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
|
|
|
|
virBufferAsprintf(buf, "<mode name='%s' supported='%s'/>\n",
|
|
|
|
virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH),
|
|
|
|
cpu->hostPassthrough ? "yes" : "no");
|
|
|
|
|
2016-06-15 14:45:47 +00:00
|
|
|
virBufferAsprintf(buf, "<mode name='%s' ",
|
|
|
|
virCPUModeTypeToString(VIR_CPU_MODE_HOST_MODEL));
|
|
|
|
if (cpu->hostModel) {
|
|
|
|
virBufferAddLit(buf, "supported='yes'>\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
virCPUDefFormatBuf(buf, cpu->hostModel);
|
2016-06-15 14:45:47 +00:00
|
|
|
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</mode>\n");
|
|
|
|
} else {
|
|
|
|
virBufferAddLit(buf, "supported='no'/>\n");
|
|
|
|
}
|
2016-04-22 09:08:57 +00:00
|
|
|
|
|
|
|
virBufferAsprintf(buf, "<mode name='%s' ",
|
|
|
|
virCPUModeTypeToString(VIR_CPU_MODE_CUSTOM));
|
|
|
|
if (cpu->custom && cpu->custom->nmodels) {
|
|
|
|
virBufferAddLit(buf, "supported='yes'>\n");
|
|
|
|
virDomainCapsCPUCustomFormat(buf, cpu->custom);
|
|
|
|
virBufferAddLit(buf, "</mode>\n");
|
|
|
|
} else {
|
|
|
|
virBufferAddLit(buf, "supported='no'/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</cpu>\n");
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsDeviceDiskFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsDeviceDiskPtr const disk)
|
|
|
|
{
|
|
|
|
FORMAT_PROLOGUE(disk);
|
|
|
|
|
|
|
|
ENUM_PROCESS(disk, diskDevice, virDomainDiskDeviceTypeToString);
|
|
|
|
ENUM_PROCESS(disk, bus, virDomainDiskBusTypeToString);
|
2019-02-20 19:18:40 +00:00
|
|
|
ENUM_PROCESS(disk, model, virDomainDiskModelTypeToString);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
|
|
|
FORMAT_EPILOGUE(disk);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-08 15:57:20 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsDeviceGraphicsFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsDeviceGraphicsPtr const graphics)
|
|
|
|
{
|
|
|
|
FORMAT_PROLOGUE(graphics);
|
|
|
|
|
|
|
|
ENUM_PROCESS(graphics, type, virDomainGraphicsTypeToString);
|
|
|
|
|
|
|
|
FORMAT_EPILOGUE(graphics);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-08 16:11:39 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsDeviceVideoFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsDeviceVideoPtr const video)
|
|
|
|
{
|
|
|
|
FORMAT_PROLOGUE(video);
|
|
|
|
|
|
|
|
ENUM_PROCESS(video, modelType, virDomainVideoTypeToString);
|
|
|
|
|
|
|
|
FORMAT_EPILOGUE(video);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-25 11:24:53 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsDeviceHostdevFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsDeviceHostdevPtr const hostdev)
|
|
|
|
{
|
|
|
|
FORMAT_PROLOGUE(hostdev);
|
|
|
|
|
|
|
|
ENUM_PROCESS(hostdev, mode, virDomainHostdevModeTypeToString);
|
|
|
|
ENUM_PROCESS(hostdev, startupPolicy, virDomainStartupPolicyTypeToString);
|
|
|
|
ENUM_PROCESS(hostdev, subsysType, virDomainHostdevSubsysTypeToString);
|
|
|
|
ENUM_PROCESS(hostdev, capsType, virDomainHostdevCapsTypeToString);
|
|
|
|
ENUM_PROCESS(hostdev, pciBackend, virDomainHostdevSubsysPCIBackendTypeToString);
|
|
|
|
|
|
|
|
FORMAT_EPILOGUE(hostdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-31 21:19:33 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsDeviceRNGFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsDeviceRNGPtr const rng)
|
|
|
|
{
|
|
|
|
FORMAT_PROLOGUE(rng);
|
|
|
|
|
|
|
|
ENUM_PROCESS(rng, model, virDomainRNGModelTypeToString);
|
|
|
|
ENUM_PROCESS(rng, backendModel, virDomainRNGBackendTypeToString);
|
|
|
|
|
|
|
|
FORMAT_EPILOGUE(rng);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-09 17:28:59 +00:00
|
|
|
/**
|
|
|
|
* virDomainCapsFeatureGICFormat:
|
|
|
|
* @buf: target buffer
|
|
|
|
* @gic: GIC features
|
|
|
|
*
|
|
|
|
* Format GIC features for inclusion in the domcapabilities XML.
|
|
|
|
*
|
|
|
|
* The resulting XML will look like
|
|
|
|
*
|
|
|
|
* <gic supported='yes'>
|
|
|
|
* <enum name='version>
|
|
|
|
* <value>2</value>
|
|
|
|
* <value>3</value>
|
|
|
|
* </enum>
|
|
|
|
* </gic>
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
virDomainCapsFeatureGICFormat(virBufferPtr buf,
|
|
|
|
virDomainCapsFeatureGICPtr const gic)
|
|
|
|
{
|
|
|
|
FORMAT_PROLOGUE(gic);
|
|
|
|
|
|
|
|
ENUM_PROCESS(gic, version, virGICVersionTypeToString);
|
|
|
|
|
|
|
|
FORMAT_EPILOGUE(gic);
|
|
|
|
}
|
|
|
|
|
2018-06-08 14:40:52 +00:00
|
|
|
static void
|
|
|
|
virDomainCapsFeatureSEVFormat(virBufferPtr buf,
|
|
|
|
virSEVCapabilityPtr const sev)
|
|
|
|
{
|
2018-06-14 12:18:30 +00:00
|
|
|
if (!sev) {
|
|
|
|
virBufferAddLit(buf, "<sev supported='no'/>\n");
|
|
|
|
} else {
|
|
|
|
virBufferAddLit(buf, "<sev supported='yes'>\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
virBufferAsprintf(buf, "<cbitpos>%d</cbitpos>\n", sev->cbitpos);
|
|
|
|
virBufferAsprintf(buf, "<reducedPhysBits>%d</reducedPhysBits>\n",
|
2018-06-08 14:40:52 +00:00
|
|
|
sev->reduced_phys_bits);
|
2018-06-14 12:18:30 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</sev>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2018-06-08 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 17:28:59 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
char *
|
|
|
|
virDomainCapsFormat(virDomainCapsPtr const caps)
|
2014-06-25 11:24:53 +00:00
|
|
|
{
|
2017-08-21 06:50:47 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2014-06-25 11:24:53 +00:00
|
|
|
const char *virttype_str = virDomainVirtTypeToString(caps->virttype);
|
|
|
|
const char *arch_str = virArchToString(caps->arch);
|
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAddLit(&buf, "<domainCapabilities>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferEscapeString(&buf, "<path>%s</path>\n", caps->path);
|
|
|
|
virBufferAsprintf(&buf, "<domain>%s</domain>\n", virttype_str);
|
2017-03-21 14:23:35 +00:00
|
|
|
if (caps->machine)
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAsprintf(&buf, "<machine>%s</machine>\n", caps->machine);
|
|
|
|
virBufferAsprintf(&buf, "<arch>%s</arch>\n", arch_str);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
|
|
|
if (caps->maxvcpus)
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAsprintf(&buf, "<vcpu max='%d'/>\n", caps->maxvcpus);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
2019-02-08 23:32:48 +00:00
|
|
|
FORMAT_SINGLE("iothreads", caps->iothreads);
|
2017-10-19 12:19:38 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virDomainCapsOSFormat(&buf, &caps->os);
|
|
|
|
virDomainCapsCPUFormat(&buf, &caps->cpu);
|
2014-09-16 12:47:47 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAddLit(&buf, "<devices>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virDomainCapsDeviceDiskFormat(&buf, &caps->disk);
|
|
|
|
virDomainCapsDeviceGraphicsFormat(&buf, &caps->graphics);
|
|
|
|
virDomainCapsDeviceVideoFormat(&buf, &caps->video);
|
|
|
|
virDomainCapsDeviceHostdevFormat(&buf, &caps->hostdev);
|
2019-03-31 21:19:33 +00:00
|
|
|
virDomainCapsDeviceRNGFormat(&buf, &caps->rng);
|
2014-06-25 11:24:53 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</devices>\n");
|
2014-06-25 11:24:53 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAddLit(&buf, "<features>\n");
|
|
|
|
virBufferAdjustIndent(&buf, 2);
|
2016-03-09 17:28:59 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virDomainCapsFeatureGICFormat(&buf, &caps->gic);
|
2019-02-08 23:32:48 +00:00
|
|
|
FORMAT_SINGLE("vmcoreinfo", caps->vmcoreinfo);
|
|
|
|
FORMAT_SINGLE("genid", caps->genid);
|
2018-06-08 14:40:52 +00:00
|
|
|
virDomainCapsFeatureSEVFormat(&buf, caps->sev);
|
2018-04-27 12:16:40 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</features>\n");
|
2016-03-09 17:28:59 +00:00
|
|
|
|
2017-08-21 06:50:47 +00:00
|
|
|
virBufferAdjustIndent(&buf, -2);
|
|
|
|
virBufferAddLit(&buf, "</domainCapabilities>\n");
|
2014-06-25 11:24:53 +00:00
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
2019-04-04 17:09:18 +00:00
|
|
|
|
|
|
|
|
2019-03-31 21:56:48 +00:00
|
|
|
#define ENUM_VALUE_MISSING(capsEnum, value) !(capsEnum.values & (1 << value))
|
|
|
|
|
|
|
|
#define ENUM_VALUE_ERROR(valueLabel, valueString) \
|
|
|
|
do { \
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \
|
|
|
|
_("domain configuration does not support '%s' value '%s'"), \
|
|
|
|
valueLabel, valueString); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virDomainCapsDeviceRNGDefValidate(virDomainCapsPtr const caps,
|
|
|
|
const virDomainRNGDef *dev)
|
|
|
|
{
|
|
|
|
if (ENUM_VALUE_MISSING(caps->rng.model, dev->model)) {
|
|
|
|
ENUM_VALUE_ERROR("rng model",
|
|
|
|
virDomainRNGModelTypeToString(dev->model));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-04 17:09:18 +00:00
|
|
|
int
|
2019-03-31 21:56:48 +00:00
|
|
|
virDomainCapsDeviceDefValidate(virDomainCapsPtr const caps,
|
2019-04-04 17:09:18 +00:00
|
|
|
const virDomainDeviceDef *dev,
|
2019-10-14 12:45:33 +00:00
|
|
|
const virDomainDef *def G_GNUC_UNUSED)
|
2019-04-04 17:09:18 +00:00
|
|
|
{
|
2019-03-31 21:56:48 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2019-04-04 17:09:18 +00:00
|
|
|
switch ((virDomainDeviceType) dev->type) {
|
2019-03-31 21:56:48 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_RNG:
|
|
|
|
ret = virDomainCapsDeviceRNGDefValidate(caps, dev->data.rng);
|
|
|
|
break;
|
|
|
|
|
2019-04-04 17:09:18 +00:00
|
|
|
case VIR_DOMAIN_DEVICE_DISK:
|
|
|
|
case VIR_DOMAIN_DEVICE_REDIRDEV:
|
|
|
|
case VIR_DOMAIN_DEVICE_NET:
|
|
|
|
case VIR_DOMAIN_DEVICE_CONTROLLER:
|
|
|
|
case VIR_DOMAIN_DEVICE_CHR:
|
|
|
|
case VIR_DOMAIN_DEVICE_SMARTCARD:
|
|
|
|
case VIR_DOMAIN_DEVICE_HOSTDEV:
|
|
|
|
case VIR_DOMAIN_DEVICE_VIDEO:
|
|
|
|
case VIR_DOMAIN_DEVICE_MEMORY:
|
|
|
|
case VIR_DOMAIN_DEVICE_VSOCK:
|
|
|
|
case VIR_DOMAIN_DEVICE_INPUT:
|
|
|
|
case VIR_DOMAIN_DEVICE_SHMEM:
|
|
|
|
case VIR_DOMAIN_DEVICE_LEASE:
|
|
|
|
case VIR_DOMAIN_DEVICE_FS:
|
|
|
|
case VIR_DOMAIN_DEVICE_SOUND:
|
|
|
|
case VIR_DOMAIN_DEVICE_WATCHDOG:
|
|
|
|
case VIR_DOMAIN_DEVICE_GRAPHICS:
|
|
|
|
case VIR_DOMAIN_DEVICE_HUB:
|
|
|
|
case VIR_DOMAIN_DEVICE_MEMBALLOON:
|
|
|
|
case VIR_DOMAIN_DEVICE_NVRAM:
|
|
|
|
case VIR_DOMAIN_DEVICE_TPM:
|
|
|
|
case VIR_DOMAIN_DEVICE_PANIC:
|
|
|
|
case VIR_DOMAIN_DEVICE_IOMMU:
|
|
|
|
case VIR_DOMAIN_DEVICE_NONE:
|
|
|
|
case VIR_DOMAIN_DEVICE_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-31 21:56:48 +00:00
|
|
|
return ret;
|
2019-04-04 17:09:18 +00:00
|
|
|
}
|