mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +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;
|
char *binary;
|
||||||
time_t ctime;
|
time_t ctime;
|
||||||
|
time_t libvirtCtime;
|
||||||
|
|
||||||
virBitmapPtr flags;
|
virBitmapPtr flags;
|
||||||
|
|
||||||
unsigned int version;
|
unsigned int version;
|
||||||
unsigned int kvmVersion;
|
unsigned int kvmVersion;
|
||||||
|
unsigned int libvirtVersion;
|
||||||
char *package;
|
char *package;
|
||||||
|
|
||||||
virArch arch;
|
virArch arch;
|
||||||
@ -3782,9 +3784,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
|
|||||||
int
|
int
|
||||||
virQEMUCapsLoadCache(virCapsPtr caps,
|
virQEMUCapsLoadCache(virCapsPtr caps,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
const char *filename,
|
const char *filename)
|
||||||
time_t *selfctime,
|
|
||||||
unsigned long *selfvers)
|
|
||||||
{
|
{
|
||||||
xmlDocPtr doc = NULL;
|
xmlDocPtr doc = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -3826,11 +3826,11 @@ virQEMUCapsLoadCache(virCapsPtr caps,
|
|||||||
_("missing selfctime in QEMU capabilities XML"));
|
_("missing selfctime in QEMU capabilities XML"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
*selfctime = (time_t)l;
|
qemuCaps->libvirtCtime = (time_t)l;
|
||||||
|
|
||||||
*selfvers = 0;
|
qemuCaps->libvirtVersion = 0;
|
||||||
if (virXPathULong("string(./selfvers)", ctxt, &lu) == 0)
|
if (virXPathULong("string(./selfvers)", ctxt, &lu) == 0)
|
||||||
*selfvers = lu;
|
qemuCaps->libvirtVersion = lu;
|
||||||
|
|
||||||
qemuCaps->usedQMP = virXPathBoolean("count(./usedQMP) > 0",
|
qemuCaps->usedQMP = virXPathBoolean("count(./usedQMP) > 0",
|
||||||
ctxt) > 0;
|
ctxt) > 0;
|
||||||
@ -4103,9 +4103,7 @@ virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps,
|
|||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps)
|
||||||
time_t selfCTime,
|
|
||||||
unsigned long selfVersion)
|
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
@ -4117,9 +4115,9 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps,
|
|||||||
virBufferAsprintf(&buf, "<qemuctime>%llu</qemuctime>\n",
|
virBufferAsprintf(&buf, "<qemuctime>%llu</qemuctime>\n",
|
||||||
(long long) qemuCaps->ctime);
|
(long long) qemuCaps->ctime);
|
||||||
virBufferAsprintf(&buf, "<selfctime>%llu</selfctime>\n",
|
virBufferAsprintf(&buf, "<selfctime>%llu</selfctime>\n",
|
||||||
(long long) selfCTime);
|
(long long) qemuCaps->libvirtCtime);
|
||||||
virBufferAsprintf(&buf, "<selfvers>%lu</selfvers>\n",
|
virBufferAsprintf(&buf, "<selfvers>%lu</selfvers>\n",
|
||||||
(unsigned long) selfVersion);
|
(unsigned long) qemuCaps->libvirtVersion);
|
||||||
|
|
||||||
if (qemuCaps->usedQMP)
|
if (qemuCaps->usedQMP)
|
||||||
virBufferAddLit(&buf, "<usedQMP/>\n");
|
virBufferAddLit(&buf, "<usedQMP/>\n");
|
||||||
@ -4194,9 +4192,7 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename)
|
|||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
xml = virQEMUCapsFormatCache(qemuCaps,
|
xml = virQEMUCapsFormatCache(qemuCaps);
|
||||||
virGetSelfLastChanged(),
|
|
||||||
LIBVIR_VERSION_NUMBER);
|
|
||||||
|
|
||||||
if (virFileWriteStr(filename, xml, 0600) < 0) {
|
if (virFileWriteStr(filename, xml, 0600) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -4208,7 +4204,7 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename)
|
|||||||
VIR_DEBUG("Saved caps '%s' for '%s' with (%lld, %lld)",
|
VIR_DEBUG("Saved caps '%s' for '%s' with (%lld, %lld)",
|
||||||
filename, qemuCaps->binary,
|
filename, qemuCaps->binary,
|
||||||
(long long)qemuCaps->ctime,
|
(long long)qemuCaps->ctime,
|
||||||
(long long)virGetSelfLastChanged());
|
(long long)qemuCaps->libvirtCtime);
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -4298,8 +4294,6 @@ virQEMUCapsInitCached(virCapsPtr caps,
|
|||||||
char *binaryhash = NULL;
|
char *binaryhash = NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
time_t qemuctime = qemuCaps->ctime;
|
time_t qemuctime = qemuCaps->ctime;
|
||||||
time_t selfctime;
|
|
||||||
unsigned long selfvers;
|
|
||||||
|
|
||||||
if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0)
|
if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -4332,8 +4326,7 @@ virQEMUCapsInitCached(virCapsPtr caps,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virQEMUCapsLoadCache(caps, qemuCaps, capsfile,
|
if (virQEMUCapsLoadCache(caps, qemuCaps, capsfile) < 0) {
|
||||||
&selfctime, &selfvers) < 0) {
|
|
||||||
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();
|
||||||
@ -4344,13 +4337,15 @@ virQEMUCapsInitCached(virCapsPtr caps,
|
|||||||
goto discard;
|
goto discard;
|
||||||
|
|
||||||
/* Discard cache if QEMU binary or libvirtd changed */
|
/* Discard cache if QEMU binary or libvirtd changed */
|
||||||
if (selfctime != virGetSelfLastChanged() ||
|
if (qemuCaps->libvirtCtime != virGetSelfLastChanged() ||
|
||||||
selfvers != LIBVIR_VERSION_NUMBER) {
|
qemuCaps->libvirtVersion != LIBVIR_VERSION_NUMBER) {
|
||||||
VIR_DEBUG("Outdated capabilities for '%s': libvirt changed "
|
VIR_DEBUG("Outdated capabilities for '%s': libvirt changed "
|
||||||
"(%lld vs %lld, %lu vs %lu)",
|
"(%lld vs %lld, %lu vs %lu)",
|
||||||
qemuCaps->binary,
|
qemuCaps->binary,
|
||||||
(long long)selfctime, (long long)virGetSelfLastChanged(),
|
(long long)qemuCaps->libvirtCtime,
|
||||||
selfvers, (unsigned long)LIBVIR_VERSION_NUMBER);
|
(long long)virGetSelfLastChanged(),
|
||||||
|
(unsigned long)qemuCaps->libvirtVersion,
|
||||||
|
(unsigned long)LIBVIR_VERSION_NUMBER);
|
||||||
goto discard;
|
goto discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5246,6 +5241,9 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qemuCaps->libvirtCtime = virGetSelfLastChanged();
|
||||||
|
qemuCaps->libvirtVersion = LIBVIR_VERSION_NUMBER;
|
||||||
|
|
||||||
if (cacheDir &&
|
if (cacheDir &&
|
||||||
virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
|
virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -50,12 +50,8 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps,
|
|||||||
|
|
||||||
int virQEMUCapsLoadCache(virCapsPtr caps,
|
int virQEMUCapsLoadCache(virCapsPtr caps,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
const char *filename,
|
const char *filename);
|
||||||
time_t *selfctime,
|
char *virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps);
|
||||||
unsigned long *selfvers);
|
|
||||||
char *virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps,
|
|
||||||
time_t selfCTime,
|
|
||||||
unsigned long selfVersion);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
|
||||||
|
@ -66,7 +66,7 @@ testQemuCaps(const void *opaque)
|
|||||||
qemuMonitorTestGetMonitor(mon)) < 0)
|
qemuMonitorTestGetMonitor(mon)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(actual = virQEMUCapsFormatCache(capsActual, 0, 0)))
|
if (!(actual = virQEMUCapsFormatCache(capsActual)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virTestCompareToFile(actual, capsFile) < 0)
|
if (virTestCompareToFile(actual, capsFile) < 0)
|
||||||
@ -108,7 +108,7 @@ testQemuCapsCopy(const void *opaque)
|
|||||||
if (!(copy = virQEMUCapsNewCopy(orig)))
|
if (!(copy = virQEMUCapsNewCopy(orig)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(actual = virQEMUCapsFormatCache(copy, 0, 0)))
|
if (!(actual = virQEMUCapsFormatCache(copy)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virTestCompareToFile(actual, capsFile) < 0)
|
if (virTestCompareToFile(actual, capsFile) < 0)
|
||||||
|
@ -568,12 +568,9 @@ qemuTestParseCapabilities(virCapsPtr caps,
|
|||||||
const char *capsFile)
|
const char *capsFile)
|
||||||
{
|
{
|
||||||
virQEMUCapsPtr qemuCaps = NULL;
|
virQEMUCapsPtr qemuCaps = NULL;
|
||||||
time_t selfctime;
|
|
||||||
unsigned long version;
|
|
||||||
|
|
||||||
if (!(qemuCaps = virQEMUCapsNew()) ||
|
if (!(qemuCaps = virQEMUCapsNew()) ||
|
||||||
virQEMUCapsLoadCache(caps, qemuCaps, capsFile,
|
virQEMUCapsLoadCache(caps, qemuCaps, capsFile) < 0)
|
||||||
&selfctime, &version) < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return qemuCaps;
|
return qemuCaps;
|
||||||
|
Loading…
Reference in New Issue
Block a user