提交 c29e6d48 编写于 作者: J Jiri Denemark

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: NJiri Denemark <jdenemar@redhat.com>
上级 729aa67d
...@@ -3492,25 +3492,21 @@ virQEMUCapsInitCached(virCapsPtr caps, ...@@ -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, ...@@ -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, ...@@ -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) {
struct stat sb;
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 false;
}
return sb.st_ctime == qemuCaps->ctime; return true;
} }
...@@ -4179,7 +4201,7 @@ virQEMUCapsCacheLookup(virCapsPtr caps, ...@@ -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, ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册