qemu: Make virQEMUCapsNewForBinary usable from tests

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@redhat.com>
This commit is contained in:
Jiri Denemark 2016-04-26 15:03:06 +02:00
parent 18f63c17a4
commit b0b8517eeb
2 changed files with 39 additions and 7 deletions

View File

@ -3713,11 +3713,13 @@ virQEMUCapsLogProbeFailure(const char *binary)
} }
virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary, virQEMUCapsPtr
const char *libDir, virQEMUCapsNewForBinaryInternal(const char *binary,
const char *cacheDir, const char *libDir,
uid_t runUid, const char *cacheDir,
gid_t runGid) uid_t runUid,
gid_t runGid,
bool qmpOnly)
{ {
virQEMUCapsPtr qemuCaps; virQEMUCapsPtr qemuCaps;
struct stat sb; struct stat sb;
@ -3749,7 +3751,9 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
goto error; goto error;
} }
if ((rv = virQEMUCapsInitCached(qemuCaps, cacheDir)) < 0) if (!cacheDir)
rv = 0;
else if ((rv = virQEMUCapsInitCached(qemuCaps, cacheDir)) < 0)
goto error; goto error;
if (rv == 0) { if (rv == 0) {
@ -3758,13 +3762,22 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
goto error; 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 && if (!qemuCaps->usedQMP &&
virQEMUCapsInitHelp(qemuCaps, runUid, runGid, qmperr) < 0) { virQEMUCapsInitHelp(qemuCaps, runUid, runGid, qmperr) < 0) {
virQEMUCapsLogProbeFailure(binary); virQEMUCapsLogProbeFailure(binary);
goto error; goto error;
} }
if (virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0) if (cacheDir &&
virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
goto error; goto error;
} }
@ -3778,6 +3791,17 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
return NULL; 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) bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps)
{ {

View File

@ -37,4 +37,12 @@ struct _virQEMUCapsCache {
gid_t runGid; gid_t runGid;
}; };
virQEMUCapsPtr
virQEMUCapsNewForBinaryInternal(const char *binary,
const char *libDir,
const char *cacheDir,
uid_t runUid,
gid_t runGid,
bool qmpOnly);
#endif #endif