From nobody Fri May 16 03:47:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499690841391504.0509377268826; Mon, 10 Jul 2017 05:47:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8839C624C0; Mon, 10 Jul 2017 12:47:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 534967D51B; Mon, 10 Jul 2017 12:47:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 064E927F; Mon, 10 Jul 2017 12:47:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6ACkxW0024853 for ; Mon, 10 Jul 2017 08:46:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B29017A6B; Mon, 10 Jul 2017 12:46:59 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id A70405C6A1 for ; Mon, 10 Jul 2017 12:46:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8839C624C0 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8839C624C0 From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 10 Jul 2017 14:46:43 +0200 Message-Id: <641033b75b510e4ad43703b4428a3b188dfeeb34.1499690733.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/11] qemu: move libvirt ctime and version into _virQEMUCaps struct X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 10 Jul 2017 12:47:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cleanups the code a little bit and reduces amount of arguments passed throughout the functions. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- 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 { =20 char *binary; time_t ctime; + time_t libvirtCtime; =20 virBitmapPtr flags; =20 unsigned int version; unsigned int kvmVersion; + unsigned int libvirtVersion; char *package; =20 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 =3D NULL; int ret =3D -1; @@ -3827,11 +3827,11 @@ virQEMUCapsLoadCache(virCapsPtr caps, _("missing selfctime in QEMU capabilities XML")); goto cleanup; } - *selfctime =3D (time_t)l; + qemuCaps->libvirtCtime =3D (time_t)l; =20 - *selfvers =3D 0; + qemuCaps->libvirtVersion =3D 0; if (virXPathULong("string(./selfvers)", ctxt, &lu) =3D=3D 0) - *selfvers =3D lu; + qemuCaps->libvirtVersion =3D lu; =20 qemuCaps->usedQMP =3D virXPathBoolean("count(./usedQMP) > 0", ctxt) > 0; @@ -4104,9 +4104,7 @@ virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps, =20 =20 char * -virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps, - time_t selfCTime, - unsigned long selfVersion) +virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *ret =3D NULL; @@ -4118,9 +4116,9 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps, virBufferAsprintf(&buf, "%llu\n", (long long) qemuCaps->ctime); virBufferAsprintf(&buf, "%llu\n", - (long long) selfCTime); + (long long) qemuCaps->libvirtCtime); virBufferAsprintf(&buf, "%lu\n", - (unsigned long) selfVersion); + (unsigned long) qemuCaps->libvirtVersion); =20 if (qemuCaps->usedQMP) virBufferAddLit(&buf, "\n"); @@ -4195,9 +4193,7 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const c= har *filename) char *xml =3D NULL; int ret =3D -1; =20 - xml =3D virQEMUCapsFormatCache(qemuCaps, - virGetSelfLastChanged(), - LIBVIR_VERSION_NUMBER); + xml =3D virQEMUCapsFormatCache(qemuCaps); =20 if (virFileWriteStr(filename, xml, 0600) < 0) { virReportSystemError(errno, @@ -4209,7 +4205,7 @@ virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const c= har *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); =20 ret =3D 0; cleanup: @@ -4299,8 +4295,6 @@ virQEMUCapsInitCached(virCapsPtr caps, char *binaryhash =3D NULL; struct stat sb; time_t qemuctime =3D qemuCaps->ctime; - time_t selfctime; - unsigned long selfvers; =20 if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0) goto cleanup; @@ -4333,8 +4327,7 @@ virQEMUCapsInitCached(virCapsPtr caps, goto cleanup; } =20 - 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; =20 /* Discard cache if QEMU binary or libvirtd changed */ - if (selfctime !=3D virGetSelfLastChanged() || - selfvers !=3D LIBVIR_VERSION_NUMBER) { + if (qemuCaps->libvirtCtime !=3D virGetSelfLastChanged() || + qemuCaps->libvirtVersion !=3D 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; } =20 @@ -5248,6 +5243,9 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, goto error; } =20 + qemuCaps->libvirtCtime =3D virGetSelfLastChanged(); + qemuCaps->libvirtVersion =3D 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, =20 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); =20 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; =20 - if (!(actual =3D virQEMUCapsFormatCache(capsActual, 0, 0))) + if (!(actual =3D virQEMUCapsFormatCache(capsActual))) goto cleanup; =20 if (virTestCompareToFile(actual, capsFile) < 0) @@ -108,7 +108,7 @@ testQemuCapsCopy(const void *opaque) if (!(copy =3D virQEMUCapsNewCopy(orig))) goto cleanup; =20 - if (!(actual =3D virQEMUCapsFormatCache(copy, 0, 0))) + if (!(actual =3D virQEMUCapsFormatCache(copy))) goto cleanup; =20 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 =3D NULL; - time_t selfctime; - unsigned long version; =20 if (!(qemuCaps =3D virQEMUCapsNew()) || - virQEMUCapsLoadCache(caps, qemuCaps, capsFile, - &selfctime, &version) < 0) + virQEMUCapsLoadCache(caps, qemuCaps, capsFile) < 0) goto error; =20 return qemuCaps; --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list