Cleanups the code a little bit and reduces amount of arguments passed throughout the functions. Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/qemu/qemu_capabilities.c | 44 +++++++++++++++++++++----------------------- src/qemu/qemu_capspriv.h | 8 ++------ tests/qemucapabilitiestest.c | 4 ++-- tests/testutilsqemu.c | 5 +---- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6659744a34..c9c28da556 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -474,11 +474,13 @@ struct _virQEMUCaps { char *binary; time_t ctime; + time_t libvirtCtime; virBitmapPtr flags; unsigned int version; unsigned int kvmVersion; + unsigned int libvirtVersion; char *package; virArch arch; @@ -3783,9 +3785,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps, int virQEMUCapsLoadCache(virCapsPtr caps, virQEMUCapsPtr qemuCaps, - const char *filename, - time_t *selfctime, - unsigned long *selfvers) + const char *filename) { xmlDocPtr doc = NULL; int ret = -1; @@ -3827,11 +3827,11 @@ virQEMUCapsLoadCache(virCapsPtr caps, _("missing selfctime in QEMU capabilities XML")); goto cleanup; } - *selfctime = (time_t)l; + qemuCaps->libvirtCtime = (time_t)l; - *selfvers = 0; + qemuCaps->libvirtVersion = 0; if (virXPathULong("string(./selfvers)", ctxt, &lu) == 0) - *selfvers = lu; + qemuCaps->libvirtVersion = lu; qemuCaps->usedQMP = virXPathBoolean("count(./usedQMP) > 0", ctxt) > 0; @@ -4104,9 +4104,7 @@ virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps, char * -virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps, - time_t selfCTime, - unsigned long selfVersion) +virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) { virBuffer buf = VIR_BUFFER_INITIALIZER; char *ret = NULL; @@ -4118,9 +4116,9 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps, virBufferAsprintf(&buf, "<qemuctime>%llu</qemuctime>\n", (long long) qemuCaps->ctime); virBufferAsprintf(&buf, "<selfctime>%llu</selfctime>\n", - (long long) selfCTime); + (long long) qemuCaps->libvirtCtime); virBufferAsprintf(&buf, "<selfvers>%lu</selfvers>\n", - (unsigned long) selfVersion); + (unsigned long) qemuCaps->libvirtVersion); if (qemuCaps->usedQMP) virBufferAddLit(&buf, "<usedQMP/>\n"); @@ -4195,9 +4193,7 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename) char *xml = NULL; int ret = -1; - xml = virQEMUCapsFormatCache(qemuCaps, - virGetSelfLastChanged(), - LIBVIR_VERSION_NUMBER); + xml = virQEMUCapsFormatCache(qemuCaps); if (virFileWriteStr(filename, xml, 0600) < 0) { virReportSystemError(errno, @@ -4209,7 +4205,7 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename) VIR_DEBUG("Saved caps '%s' for '%s' with (%lld, %lld)", filename, qemuCaps->binary, (long long)qemuCaps->ctime, - (long long)virGetSelfLastChanged()); + (long long)qemuCaps->libvirtCtime); ret = 0; cleanup: @@ -4299,8 +4295,6 @@ virQEMUCapsInitCached(virCapsPtr caps, char *binaryhash = NULL; struct stat sb; time_t qemuctime = qemuCaps->ctime; - time_t selfctime; - unsigned long selfvers; if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0) goto cleanup; @@ -4333,8 +4327,7 @@ virQEMUCapsInitCached(virCapsPtr caps, goto cleanup; } - if (virQEMUCapsLoadCache(caps, qemuCaps, capsfile, - &selfctime, &selfvers) < 0) { + if (virQEMUCapsLoadCache(caps, qemuCaps, capsfile) < 0) { VIR_WARN("Failed to load cached caps from '%s' for '%s': %s", capsfile, qemuCaps->binary, virGetLastErrorMessage()); virResetLastError(); @@ -4345,13 +4338,15 @@ virQEMUCapsInitCached(virCapsPtr caps, goto discard; /* Discard cache if QEMU binary or libvirtd changed */ - if (selfctime != virGetSelfLastChanged() || - selfvers != LIBVIR_VERSION_NUMBER) { + if (qemuCaps->libvirtCtime != virGetSelfLastChanged() || + qemuCaps->libvirtVersion != LIBVIR_VERSION_NUMBER) { VIR_DEBUG("Outdated capabilities for '%s': libvirt changed " "(%lld vs %lld, %lu vs %lu)", qemuCaps->binary, - (long long)selfctime, (long long)virGetSelfLastChanged(), - selfvers, (unsigned long)LIBVIR_VERSION_NUMBER); + (long long)qemuCaps->libvirtCtime, + (long long)virGetSelfLastChanged(), + (unsigned long)qemuCaps->libvirtVersion, + (unsigned long)LIBVIR_VERSION_NUMBER); goto discard; } @@ -5248,6 +5243,9 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, goto error; } + qemuCaps->libvirtCtime = virGetSelfLastChanged(); + qemuCaps->libvirtVersion = LIBVIR_VERSION_NUMBER; + if (cacheDir && virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0) goto error; diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 94fa75b960..1162e0b284 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -50,12 +50,8 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, int virQEMUCapsLoadCache(virCapsPtr caps, virQEMUCapsPtr qemuCaps, - const char *filename, - time_t *selfctime, - unsigned long *selfvers); -char *virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps, - time_t selfCTime, - unsigned long selfVersion); + const char *filename); +char *virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps); int virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index bbb683eb83..45d2a885bd 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -66,7 +66,7 @@ testQemuCaps(const void *opaque) qemuMonitorTestGetMonitor(mon)) < 0) goto cleanup; - if (!(actual = virQEMUCapsFormatCache(capsActual, 0, 0))) + if (!(actual = virQEMUCapsFormatCache(capsActual))) goto cleanup; if (virTestCompareToFile(actual, capsFile) < 0) @@ -108,7 +108,7 @@ testQemuCapsCopy(const void *opaque) if (!(copy = virQEMUCapsNewCopy(orig))) goto cleanup; - if (!(actual = virQEMUCapsFormatCache(copy, 0, 0))) + if (!(actual = virQEMUCapsFormatCache(copy))) goto cleanup; if (virTestCompareToFile(actual, capsFile) < 0) diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index ee4853841c..88e11ba14a 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -568,12 +568,9 @@ qemuTestParseCapabilities(virCapsPtr caps, const char *capsFile) { virQEMUCapsPtr qemuCaps = NULL; - time_t selfctime; - unsigned long version; if (!(qemuCaps = virQEMUCapsNew()) || - virQEMUCapsLoadCache(caps, qemuCaps, capsFile, - &selfctime, &version) < 0) + virQEMUCapsLoadCache(caps, qemuCaps, capsFile) < 0) goto error; return qemuCaps; -- 2.13.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list