virQEMUCapsNewForBinary unconditionally loads data from cache and probes
using both QMP and -help parsing, which is suboptimal when we want to
use it in tests.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 38 +++++++++++++++++++++++++++++++-------
src/qemu/qemu_capspriv.h | 8 ++++++++
2 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 65c3d69..c2ba69d 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3713,11 +3713,13 @@ virQEMUCapsLogProbeFailure(const char *binary)
}
-virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
- const char *libDir,
- const char *cacheDir,
- uid_t runUid,
- gid_t runGid)
+virQEMUCapsPtr
+virQEMUCapsNewForBinaryInternal(const char *binary,
+ const char *libDir,
+ const char *cacheDir,
+ uid_t runUid,
+ gid_t runGid,
+ bool qmpOnly)
{
virQEMUCapsPtr qemuCaps;
struct stat sb;
@@ -3749,7 +3751,9 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
goto error;
}
- if ((rv = virQEMUCapsInitCached(qemuCaps, cacheDir)) < 0)
+ if (!cacheDir)
+ rv = 0;
+ else if ((rv = virQEMUCapsInitCached(qemuCaps, cacheDir)) < 0)
goto error;
if (rv == 0) {
@@ -3758,13 +3762,22 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
goto error;
}
+ if (qmpOnly && !qemuCaps->usedQMP) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to probe QEMU binary with QMP: %s"),
+ qmperr ? qmperr : _("unknown error"));
+ virQEMUCapsLogProbeFailure(binary);
+ goto error;
+ }
+
if (!qemuCaps->usedQMP &&
virQEMUCapsInitHelp(qemuCaps, runUid, runGid, qmperr) < 0) {
virQEMUCapsLogProbeFailure(binary);
goto error;
}
- if (virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
+ if (cacheDir &&
+ virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
goto error;
}
@@ -3778,6 +3791,17 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
return NULL;
}
+virQEMUCapsPtr
+virQEMUCapsNewForBinary(const char *binary,
+ const char *libDir,
+ const char *cacheDir,
+ uid_t runUid,
+ gid_t runGid)
+{
+ return virQEMUCapsNewForBinaryInternal(binary, libDir, cacheDir,
+ runUid, runGid, false);
+}
+
bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps)
{
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index e4610bb..2a5d8d1 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -37,4 +37,12 @@ struct _virQEMUCapsCache {
gid_t runGid;
};
+virQEMUCapsPtr
+virQEMUCapsNewForBinaryInternal(const char *binary,
+ const char *libDir,
+ const char *cacheDir,
+ uid_t runUid,
+ gid_t runGid,
+ bool qmpOnly);
+
#endif
--
2.8.2