Cleanups the code a little bit and reduces amount of arguments passed
throughout the functions.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
Reviewed-by: Jiri Denemark <jdenemar(a)redhat.com>
---
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 dbebf61961..61dc5f4a82 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -475,11 +475,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;
@@ -3782,9 +3784,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;
@@ -3826,11 +3826,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;
@@ -4103,9 +4103,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;
@@ -4117,9 +4115,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");
@@ -4194,9 +4192,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,
@@ -4208,7 +4204,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:
@@ -4298,8 +4294,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;
@@ -4332,8 +4326,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();
@@ -4344,13 +4337,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;
}
@@ -5246,6 +5241,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 037a4279dd..d254adf27c 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.3