Not all machine types support all devices, device properties, backends,
etc. So until we create a matrix of [machineType, qemuCaps], lets just
filter out some capabilities before we return them to the consumer
(which is going to make decisions based on them straight away).
Currently, as qemu is unable to tell which capabilities are (not)
enabled for given machine types, it's us who has to hardcode the matrix.
One day maybe the hardcoding will go away and we can create the matrix
dynamically on the fly based on a few monitor calls.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 39 ++++++++++++++++++++++++++++++++++++++-
src/qemu/qemu_capabilities.h | 2 ++
tests/qemuxml2argvtest.c | 2 ++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 3992b2b..233449b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3511,6 +3511,42 @@ bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps)
}
+struct virQEMUCapsMachineTypeFilter {
+ const char *machineType;
+ virQEMUCapsFlags *flags;
+ size_t nflags;
+};
+
+static const struct virQEMUCapsMachineTypeFilter virQEMUCapsMachineFilter[] = {
+ /* { "blah", virQEMUCapsMachineBLAHFilter,
+ ARRAY_CARDINALITY(virQEMUCapsMachineBLAHFilter) }, */
+ { "", NULL, 0 },
+};
+
+
+void
+virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
+ const char *machineType)
+{
+ size_t i;
+
+ if (!machineType)
+ return;
+
+ for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsMachineFilter); i++) {
+ const struct virQEMUCapsMachineTypeFilter *filter =
&virQEMUCapsMachineFilter[i];
+ size_t j;
+
+ if (STRNEQ(filter->machineType, machineType))
+ continue;
+
+ for (j = 0; j < filter->nflags; j++)
+ virQEMUCapsClear(qemuCaps, filter->flags[j]);
+ }
+
+}
+
+
virQEMUCapsCachePtr
virQEMUCapsCacheNew(const char *libDir,
const char *cacheDir,
@@ -3585,7 +3621,7 @@ virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, const char
*binary)
virQEMUCapsPtr
virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache,
const char *binary,
- const char *machineType ATTRIBUTE_UNUSED)
+ const char *machineType)
{
virQEMUCapsPtr qemuCaps = virQEMUCapsCacheLookup(cache, binary);
virQEMUCapsPtr ret;
@@ -3595,6 +3631,7 @@ virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache,
ret = virQEMUCapsNewCopy(qemuCaps);
virObjectUnref(qemuCaps);
+ virQEMUCapsFilterByMachineType(ret, machineType);
return ret;
}
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 242a33d..5d87c18 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -284,6 +284,8 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps);
+void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
+ const char *machineType);
virQEMUCapsCachePtr virQEMUCapsCacheNew(const char *libDir,
const char *cacheDir,
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 316f479..f2120dd 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -308,6 +308,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
goto out;
}
+ virQEMUCapsFilterByMachineType(extraFlags, vmdef->os.machine);
+
if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DEVICE)) {
if (qemuDomainAssignAddresses(vmdef, extraFlags, NULL)) {
if (flags & FLAG_EXPECT_ERROR)
--
2.0.5