mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemu: move libvirt ctime and version into _virQEMUCaps struct
Cleanups the code a little bit and reduces amount of arguments passed throughout the functions. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
38e516a524
commit
a63ef87709
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user