mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
qemu: Unify cached caps validity checks
Let's keep all run time validation of cached QEMU capabilities in virQEMUCapsIsValid and call it whenever we access the cache. virQEMUCapsInitCached should keep only the checks which do not make sense once the cache is loaded in memory. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
729aa67db7
commit
c29e6d4805
@ -3492,25 +3492,21 @@ virQEMUCapsInitCached(virCapsPtr caps,
|
|||||||
VIR_WARN("Failed to load cached caps from '%s' for '%s': %s",
|
VIR_WARN("Failed to load cached caps from '%s' for '%s': %s",
|
||||||
capsfile, qemuCaps->binary, virGetLastErrorMessage());
|
capsfile, qemuCaps->binary, virGetLastErrorMessage());
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
ret = 0;
|
goto discard;
|
||||||
virQEMUCapsReset(qemuCaps);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!virQEMUCapsIsValid(qemuCaps, qemuctime))
|
||||||
|
goto discard;
|
||||||
|
|
||||||
/* Discard cache if QEMU binary or libvirtd changed */
|
/* Discard cache if QEMU binary or libvirtd changed */
|
||||||
if (qemuctime != qemuCaps->ctime ||
|
if (selfctime != virGetSelfLastChanged() ||
|
||||||
selfctime != virGetSelfLastChanged() ||
|
|
||||||
selfvers != LIBVIR_VERSION_NUMBER) {
|
selfvers != LIBVIR_VERSION_NUMBER) {
|
||||||
VIR_DEBUG("Outdated cached capabilities '%s' for '%s' "
|
VIR_DEBUG("Outdated capabilities for '%s': libvirt changed "
|
||||||
"(%lld vs %lld, %lld vs %lld, %lu vs %lu)",
|
"(%lld vs %lld, %lu vs %lu)",
|
||||||
capsfile, qemuCaps->binary,
|
qemuCaps->binary,
|
||||||
(long long)qemuCaps->ctime, (long long)qemuctime,
|
|
||||||
(long long)selfctime, (long long)virGetSelfLastChanged(),
|
(long long)selfctime, (long long)virGetSelfLastChanged(),
|
||||||
selfvers, (unsigned long)LIBVIR_VERSION_NUMBER);
|
selfvers, (unsigned long)LIBVIR_VERSION_NUMBER);
|
||||||
ignore_value(unlink(capsfile));
|
goto discard;
|
||||||
virQEMUCapsReset(qemuCaps);
|
|
||||||
ret = 0;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=%d",
|
VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=%d",
|
||||||
@ -3524,6 +3520,14 @@ virQEMUCapsInitCached(virCapsPtr caps,
|
|||||||
VIR_FREE(capsfile);
|
VIR_FREE(capsfile);
|
||||||
VIR_FREE(capsdir);
|
VIR_FREE(capsdir);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
discard:
|
||||||
|
VIR_DEBUG("Dropping cached capabilities '%s' for '%s'",
|
||||||
|
capsfile, qemuCaps->binary);
|
||||||
|
ignore_value(unlink(capsfile));
|
||||||
|
virQEMUCapsReset(qemuCaps);
|
||||||
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4076,17 +4080,35 @@ virQEMUCapsNewForBinary(virCapsPtr caps,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps)
|
bool
|
||||||
|
virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps,
|
||||||
|
time_t ctime)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
if (!qemuCaps->binary)
|
if (!qemuCaps->binary)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (stat(qemuCaps->binary, &sb) < 0)
|
if (!ctime) {
|
||||||
return false;
|
struct stat sb;
|
||||||
|
|
||||||
return sb.st_ctime == qemuCaps->ctime;
|
if (stat(qemuCaps->binary, &sb) < 0) {
|
||||||
|
char ebuf[1024];
|
||||||
|
VIR_DEBUG("Failed to stat QEMU binary '%s': %s",
|
||||||
|
qemuCaps->binary,
|
||||||
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ctime = sb.st_ctime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctime != qemuCaps->ctime) {
|
||||||
|
VIR_DEBUG("Outdated capabilities for '%s': QEMU binary changed "
|
||||||
|
"(%lld vs %lld)",
|
||||||
|
qemuCaps->binary,
|
||||||
|
(long long) ctime, (long long) qemuCaps->ctime);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4179,7 +4201,7 @@ virQEMUCapsCacheLookup(virCapsPtr caps,
|
|||||||
virMutexLock(&cache->lock);
|
virMutexLock(&cache->lock);
|
||||||
ret = virHashLookup(cache->binaries, binary);
|
ret = virHashLookup(cache->binaries, binary);
|
||||||
if (ret &&
|
if (ret &&
|
||||||
!virQEMUCapsIsValid(ret)) {
|
!virQEMUCapsIsValid(ret, 0)) {
|
||||||
VIR_DEBUG("Cached capabilities %p no longer valid for %s",
|
VIR_DEBUG("Cached capabilities %p no longer valid for %s",
|
||||||
ret, binary);
|
ret, binary);
|
||||||
virHashRemoveEntry(cache->binaries, binary);
|
virHashRemoveEntry(cache->binaries, binary);
|
||||||
|
@ -451,7 +451,8 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
|
|||||||
size_t *nmachines,
|
size_t *nmachines,
|
||||||
virCapsGuestMachinePtr **machines);
|
virCapsGuestMachinePtr **machines);
|
||||||
|
|
||||||
bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps);
|
bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps,
|
||||||
|
time_t ctime);
|
||||||
|
|
||||||
void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
|
void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
|
||||||
const char *machineType);
|
const char *machineType);
|
||||||
|
Loading…
Reference in New Issue
Block a user