Since CPU capabilities depend on accelerator used when probing QEMU the cache becomes invalid when KVM becomes available or if it is not available anymore. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/qemu/qemu_capabilities.c | 37 ++++++++++++++++++++++++++++++++----- src/qemu/qemu_capabilities.h | 4 +++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d1c31ad..9fe4363 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3469,7 +3469,9 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps) static int virQEMUCapsInitCached(virCapsPtr caps, virQEMUCapsPtr qemuCaps, - const char *cacheDir) + const char *cacheDir, + uid_t runUid, + gid_t runGid) { char *capsdir = NULL; char *capsfile = NULL; @@ -3519,7 +3521,7 @@ virQEMUCapsInitCached(virCapsPtr caps, goto discard; } - if (!virQEMUCapsIsValid(qemuCaps, qemuctime)) + if (!virQEMUCapsIsValid(qemuCaps, qemuctime, runUid, runGid)) goto discard; /* Discard cache if QEMU binary or libvirtd changed */ @@ -4067,7 +4069,8 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, if (!cacheDir) rv = 0; - else if ((rv = virQEMUCapsInitCached(caps, qemuCaps, cacheDir)) < 0) + else if ((rv = virQEMUCapsInitCached(caps, qemuCaps, cacheDir, + runUid, runGid)) < 0) goto error; if (rv == 0) { @@ -4115,8 +4118,12 @@ virQEMUCapsNewForBinary(virCapsPtr caps, bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, - time_t ctime) + time_t ctime, + uid_t runUid, + gid_t runGid) { + bool kvmUsable; + if (!qemuCaps->binary) return true; @@ -4142,6 +4149,26 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, return false; } + kvmUsable = virFileAccessibleAs("/dev/kvm", R_OK | W_OK, + runUid, runGid) == 0; + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM) && + kvmUsable) { + VIR_DEBUG("Dropping cached capabilities for '%s': KVM was not " + "enabled when probing, but it should be usable now", + qemuCaps->binary); + return false; + } + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && + !kvmUsable) { + VIR_DEBUG("Dropping cached capabilities for '%s': KVM was enabled " + "when probing, but it is not available now", + qemuCaps->binary); + return false; + } + return true; } @@ -4235,7 +4262,7 @@ virQEMUCapsCacheLookup(virCapsPtr caps, virMutexLock(&cache->lock); ret = virHashLookup(cache->binaries, binary); if (ret && - !virQEMUCapsIsValid(ret, 0)) { + !virQEMUCapsIsValid(ret, 0, cache->runUid, cache->runGid)) { VIR_DEBUG("Cached capabilities %p no longer valid for %s", ret, binary); virHashRemoveEntry(cache->binaries, binary); diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 6c45a67..5310416 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -450,7 +450,9 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, virCapsGuestMachinePtr **machines); bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, - time_t ctime); + time_t ctime, + uid_t runUid, + gid_t runGid); void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps, const char *machineType); -- 2.10.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list