From nobody Wed May 1 02:47:10 2024 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 1500477008879107.88750106367638; Wed, 19 Jul 2017 08:10:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE79B7CE1D; Wed, 19 Jul 2017 15:10:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 960CA17C26; Wed, 19 Jul 2017 15:10:03 +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 8FD981853E34; Wed, 19 Jul 2017 15:10:02 +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 v6JFA09v029583 for ; Wed, 19 Jul 2017 11:10:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14F7378217; Wed, 19 Jul 2017 15:10:00 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BDC4783BD for ; Wed, 19 Jul 2017 15:09:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE79B7CE1D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 CE79B7CE1D From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 17:09:46 +0200 Message-Id: <184150617ee8b0a4245d137831b6821eda941d63.1500476925.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 v2 1/6] util/virhash: add name parameter to virHashSearch 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 19 Jul 2017 15:10:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" While searching for an element using a function it may be desirable to know the element key for future operation. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- src/conf/virdomainobjlist.c | 2 +- src/conf/virnetworkobj.c | 4 ++-- src/conf/virsecretobj.c | 2 +- src/qemu/qemu_capabilities.c | 5 +++-- src/util/virhash.c | 11 ++++++++--- src/util/virhash.h | 2 +- src/xen/xm_internal.c | 5 +++-- tests/virhashtest.c | 2 +- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index c121382bcb..7bd4cd29b9 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -119,7 +119,7 @@ virDomainObjListFindByIDInternal(virDomainObjListPtr do= ms, { virDomainObjPtr obj; virObjectLock(doms); - obj =3D virHashSearch(doms->objs, virDomainObjListSearchID, &id); + obj =3D virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL); if (ref) { virObjectRef(obj); virObjectUnlock(doms); diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 88e42b5b3e..ccde72e727 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -208,7 +208,7 @@ virNetworkObjFindByNameLocked(virNetworkObjListPtr nets, { virNetworkObjPtr ret =3D NULL; =20 - ret =3D virHashSearch(nets->objs, virNetworkObjSearchName, name); + ret =3D virHashSearch(nets->objs, virNetworkObjSearchName, name, NULL); if (ret) virObjectRef(ret); return ret; @@ -980,7 +980,7 @@ virNetworkObjBridgeInUse(virNetworkObjListPtr nets, struct virNetworkObjBridgeInUseHelperData data =3D {bridge, skipname}; =20 virObjectLock(nets); - obj =3D virHashSearch(nets->objs, virNetworkObjBridgeInUseHelper, &dat= a); + obj =3D virHashSearch(nets->objs, virNetworkObjBridgeInUseHelper, &dat= a, NULL); virObjectUnlock(nets); =20 return obj !=3D NULL; diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index e3bcbe593d..792ceb1f15 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -247,7 +247,7 @@ virSecretObjListFindByUsageLocked(virSecretObjListPtr s= ecrets, struct virSecretSearchData data =3D { .usageType =3D usageType, .usageID =3D usageID }; =20 - obj =3D virHashSearch(secrets->objs, virSecretObjSearchName, &data); + obj =3D virHashSearch(secrets->objs, virSecretObjSearchName, &data, NU= LL); if (obj) virObjectRef(obj); return obj; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 04aa8d53c0..dbebf61961 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5502,14 +5502,15 @@ virQEMUCapsCacheLookupByArch(virCapsPtr caps, struct virQEMUCapsSearchData data =3D { .arch =3D arch }; =20 virMutexLock(&cache->lock); - ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data); + ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data, = NULL); if (!ret) { /* If the first attempt at finding capabilities has failed, try * again using the QEMU target as lookup key instead */ target =3D virQEMUCapsFindTarget(virArchFromHost(), data.arch); if (target !=3D data.arch) { data.arch =3D target; - ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch,= &data); + ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, + &data, NULL); } } =20 diff --git a/src/util/virhash.c b/src/util/virhash.c index a8e0edfd3b..7fa2992f18 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -702,15 +702,18 @@ virHashRemoveAll(virHashTablePtr table) * @table: the hash table to search * @iter: an iterator to identify the desired element * @data: extra opaque information passed to the iter + * @name: the name of found user data, pass NULL to ignore * * Iterates over the hash table calling the 'iter' callback * for each element. The first element for which the iter * returns non-zero will be returned by this function. - * The elements are processed in a undefined order + * The elements are processed in a undefined order. Caller is + * responsible for freeing the @name. */ void *virHashSearch(const virHashTable *ctable, virHashSearcher iter, - const void *data) + const void *data, + void **name) { size_t i; =20 @@ -730,6 +733,8 @@ void *virHashSearch(const virHashTable *ctable, for (entry =3D table->table[i]; entry; entry =3D entry->next) { if (iter(entry->payload, entry->name, data)) { table->iterating =3D false; + if (name) + *name =3D table->keyCopy(entry->name); return entry->payload; } } @@ -824,7 +829,7 @@ bool virHashEqual(const virHashTable *table1, virHashSize(table1) !=3D virHashSize(table2)) return false; =20 - virHashSearch(table1, virHashEqualSearcher, &data); + virHashSearch(table1, virHashEqualSearcher, &data, NULL); =20 return data.equal; } diff --git a/src/util/virhash.h b/src/util/virhash.h index 61c172b9e0..00b2550e70 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -194,7 +194,7 @@ bool virHashEqual(const virHashTable *table1, int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data= ); ssize_t virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, cons= t void *data); void *virHashSearch(const virHashTable *table, virHashSearcher iter, - const void *data); + const void *data, void **name); =20 /* Convenience for when VIR_FREE(value) is sufficient as a data freer. */ void virHashValueFree(void *value, const void *name); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index fba814aa19..123f379572 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -880,7 +880,8 @@ xenXMDomainLookupByUUID(virConnectPtr conn, const unsig= ned char *uuid) if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh(conn) < 0) goto cleanup; =20 - if (!(entry =3D virHashSearch(priv->configCache, xenXMDomainSearchForU= UID, (const void *)uuid))) + if (!(entry =3D virHashSearch(priv->configCache, xenXMDomainSearchForU= UID, + (const void *)uuid, NULL))) goto cleanup; =20 ret =3D virDomainDefNewFull(entry->def->name, uuid, -1); @@ -971,7 +972,7 @@ xenXMDomainDefineXML(virConnectPtr conn, virDomainDefPt= r def) * it has the same name */ if ((entry =3D virHashSearch(priv->configCache, xenXMDomainSearchForUU= ID, - (const void *)&(def->uuid))) !=3D NULL) { + (const void *)&(def->uuid), NULL)) !=3D NUL= L) { if ((entry->def !=3D NULL) && (entry->def->name !=3D NULL) && (STRNEQ(def->name, entry->def->name))) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/tests/virhashtest.c b/tests/virhashtest.c index dbf07ae7f7..9407f98c4b 100644 --- a/tests/virhashtest.c +++ b/tests/virhashtest.c @@ -436,7 +436,7 @@ testHashSearch(const void *data ATTRIBUTE_UNUSED) if (!(hash =3D testHashInit(0))) return -1; =20 - entry =3D virHashSearch(hash, testHashSearchIter, NULL); + entry =3D virHashSearch(hash, testHashSearchIter, NULL, NULL); =20 if (!entry || STRNEQ(uuids_subset[testSearchIndex], entry)) { VIR_TEST_VERBOSE("\nvirHashSearch didn't find entry '%s'\n", --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 02:47:10 2024 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 150047701688370.82777244876422; Wed, 19 Jul 2017 08:10:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A193C04F4B1; Wed, 19 Jul 2017 15:10:08 +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 6CF525D6A7; Wed, 19 Jul 2017 15:10:08 +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 088873FAE1; Wed, 19 Jul 2017 15:10:08 +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 v6JFA1k3029608 for ; Wed, 19 Jul 2017 11:10:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 62BC660606; Wed, 19 Jul 2017 15:10:01 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBB2C78217 for ; Wed, 19 Jul 2017 15:10:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9A193C04F4B1 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 9A193C04F4B1 From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 17:09:47 +0200 Message-Id: <1870eba0ff906e75da0b2e0c37958dfb386dc2bf.1500476925.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 v2 2/6] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 19 Jul 2017 15:10:09 +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 dbebf61961..61dc5f4a82 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -475,11 +475,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; @@ -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 =3D NULL; int ret =3D -1; @@ -3826,11 +3826,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; @@ -4103,9 +4103,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; @@ -4117,9 +4115,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"); @@ -4194,9 +4192,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, @@ -4208,7 +4204,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: @@ -4298,8 +4294,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; @@ -4332,8 +4326,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(); @@ -4344,13 +4337,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 @@ -5246,6 +5241,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 037a4279dd..d254adf27c 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.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 02:47:10 2024 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 1500477016112213.00503590648407; Wed, 19 Jul 2017 08:10:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66CEBD0A86; Wed, 19 Jul 2017 15:10:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C324617B61; Wed, 19 Jul 2017 15:10:05 +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 6275D1853E37; Wed, 19 Jul 2017 15:10:05 +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 v6JFA38v029621 for ; Wed, 19 Jul 2017 11:10:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CDCA78217; Wed, 19 Jul 2017 15:10:03 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id E914D7840C for ; Wed, 19 Jul 2017 15:10:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 66CEBD0A86 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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 66CEBD0A86 From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 17:09:48 +0200 Message-Id: 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 v2 3/6] qemu: move virQEMUCapsIsValid before its usage and make it static 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 19 Jul 2017 15:10:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 112 +++++++++++++++++++++------------------= ---- src/qemu/qemu_capabilities.h | 5 -- 2 files changed, 56 insertions(+), 61 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 61dc5f4a82..1eaba204e3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4281,6 +4281,62 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps) } =20 =20 +static bool +virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, + time_t qemuctime, + uid_t runUid, + gid_t runGid) +{ + bool kvmUsable; + + if (!qemuCaps->binary) + return true; + + if (!qemuctime) { + struct stat sb; + + if (stat(qemuCaps->binary, &sb) < 0) { + char ebuf[1024]; + VIR_DEBUG("Failed to stat QEMU binary '%s': %s", + qemuCaps->binary, + virStrerror(errno, ebuf, sizeof(ebuf))); + return false; + } + qemuctime =3D sb.st_ctime; + } + + if (qemuctime !=3D qemuCaps->ctime) { + VIR_DEBUG("Outdated capabilities for '%s': QEMU binary changed " + "(%lld vs %lld)", + qemuCaps->binary, + (long long) qemuctime, (long long) qemuCaps->ctime); + return false; + } + + kvmUsable =3D virFileAccessibleAs("/dev/kvm", R_OK | W_OK, + runUid, runGid) =3D=3D 0; + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM) && + kvmUsable) { + VIR_DEBUG("KVM was not enabled when probing '%s', " + "but it should be usable now", + qemuCaps->binary); + return false; + } + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && + !kvmUsable) { + VIR_DEBUG("KVM was enabled when probing '%s', " + "but it is not available now", + qemuCaps->binary); + return false; + } + + return true; +} + + static int virQEMUCapsInitCached(virCapsPtr caps, virQEMUCapsPtr qemuCaps, @@ -5275,62 +5331,6 @@ virQEMUCapsNewForBinary(virCapsPtr caps, } =20 =20 -bool -virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, - time_t qemuctime, - uid_t runUid, - gid_t runGid) -{ - bool kvmUsable; - - if (!qemuCaps->binary) - return true; - - if (!qemuctime) { - struct stat sb; - - if (stat(qemuCaps->binary, &sb) < 0) { - char ebuf[1024]; - VIR_DEBUG("Failed to stat QEMU binary '%s': %s", - qemuCaps->binary, - virStrerror(errno, ebuf, sizeof(ebuf))); - return false; - } - qemuctime =3D sb.st_ctime; - } - - if (qemuctime !=3D qemuCaps->ctime) { - VIR_DEBUG("Outdated capabilities for '%s': QEMU binary changed " - "(%lld vs %lld)", - qemuCaps->binary, - (long long) qemuctime, (long long) qemuCaps->ctime); - return false; - } - - kvmUsable =3D virFileAccessibleAs("/dev/kvm", R_OK | W_OK, - runUid, runGid) =3D=3D 0; - - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM) && - kvmUsable) { - VIR_DEBUG("KVM was not enabled when probing '%s', " - "but it should be usable now", - qemuCaps->binary); - return false; - } - - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && - !kvmUsable) { - VIR_DEBUG("KVM was enabled when probing '%s', " - "but it is not available now", - qemuCaps->binary); - return false; - } - - return true; -} - - struct virQEMUCapsMachineTypeFilter { const char *machineType; virQEMUCapsFlags *flags; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 8250b57b46..bd44b90002 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -495,11 +495,6 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemu= Caps, size_t *nmachines, virCapsGuestMachinePtr **machines); =20 -bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, - time_t ctime, - uid_t runUid, - gid_t runGid); - void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps, const char *machineType); =20 --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 02:47:10 2024 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 1500477020488735.3269794589186; Wed, 19 Jul 2017 08:10:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72F2764D85; Wed, 19 Jul 2017 15:10:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4959F5D963; Wed, 19 Jul 2017 15:10:13 +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 E5DE21853E3A; Wed, 19 Jul 2017 15:10:12 +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 v6JFA8rR029642 for ; Wed, 19 Jul 2017 11:10:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id B0A7A78412; Wed, 19 Jul 2017 15:10:08 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A6BB78428 for ; Wed, 19 Jul 2017 15:10:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 72F2764D85 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 72F2764D85 From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 17:09:49 +0200 Message-Id: <78d799739f42a2469b904745db8d6231c2dcce2c.1500476925.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 v2 4/6] qemu: move libvirt ctime and version check into virQEMUCapsIsValid 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 19 Jul 2017 15:10:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 1eaba204e3..dd52a5f688 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4292,6 +4292,18 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, if (!qemuCaps->binary) return true; =20 + 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)qemuCaps->libvirtCtime, + (long long)virGetSelfLastChanged(), + (unsigned long)qemuCaps->libvirtVersion, + (unsigned long)LIBVIR_VERSION_NUMBER); + return false; + } + if (!qemuctime) { struct stat sb; =20 @@ -4392,19 +4404,6 @@ virQEMUCapsInitCached(virCapsPtr caps, if (!virQEMUCapsIsValid(qemuCaps, qemuctime, runUid, runGid)) goto discard; =20 - /* Discard cache if QEMU binary or libvirtd changed */ - 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)qemuCaps->libvirtCtime, - (long long)virGetSelfLastChanged(), - (unsigned long)qemuCaps->libvirtVersion, - (unsigned long)LIBVIR_VERSION_NUMBER); - goto discard; - } - VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=3D%d", capsfile, qemuCaps->binary, (long long)qemuCaps->ctime, qemuCaps->usedQMP); --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 02:47:10 2024 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 1500477020099636.4091181799078; Wed, 19 Jul 2017 08:10:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80729356CF; Wed, 19 Jul 2017 15:10:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5212A783B7; Wed, 19 Jul 2017 15:10:17 +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 E91C01853E3E; Wed, 19 Jul 2017 15:10:16 +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 v6JFA9o7029652 for ; Wed, 19 Jul 2017 11:10:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7CA3660606; Wed, 19 Jul 2017 15:10:09 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06D047840D for ; Wed, 19 Jul 2017 15:10:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80729356CF Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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 80729356CF From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 17:09:50 +0200 Message-Id: <9a5ac0bb32986f43e061ffa856e797019fa69da9.1500476925.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 v2 5/6] qemu: don't pass qemuctime into virQEMUCapsIsValid 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 19 Jul 2017 15:10:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It's not required and following patches will change the code. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index dd52a5f688..948a7d900b 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4283,11 +4283,11 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps) =20 static bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, - time_t qemuctime, uid_t runUid, gid_t runGid) { bool kvmUsable; + struct stat sb; =20 if (!qemuCaps->binary) return true; @@ -4304,24 +4304,19 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, return false; } =20 - if (!qemuctime) { - struct stat sb; - - if (stat(qemuCaps->binary, &sb) < 0) { - char ebuf[1024]; - VIR_DEBUG("Failed to stat QEMU binary '%s': %s", - qemuCaps->binary, - virStrerror(errno, ebuf, sizeof(ebuf))); - return false; - } - qemuctime =3D sb.st_ctime; + if (stat(qemuCaps->binary, &sb) < 0) { + char ebuf[1024]; + VIR_DEBUG("Failed to stat QEMU binary '%s': %s", + qemuCaps->binary, + virStrerror(errno, ebuf, sizeof(ebuf))); + return false; } =20 - if (qemuctime !=3D qemuCaps->ctime) { + if (sb.st_ctime !=3D qemuCaps->ctime) { VIR_DEBUG("Outdated capabilities for '%s': QEMU binary changed " "(%lld vs %lld)", qemuCaps->binary, - (long long) qemuctime, (long long) qemuCaps->ctime); + (long long) sb.st_ctime, (long long) qemuCaps->ctime); return false; } =20 @@ -4401,7 +4396,7 @@ virQEMUCapsInitCached(virCapsPtr caps, goto discard; } =20 - if (!virQEMUCapsIsValid(qemuCaps, qemuctime, runUid, runGid)) + if (!virQEMUCapsIsValid(qemuCaps, runUid, runGid)) goto discard; =20 VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=3D%d", @@ -5411,7 +5406,7 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache, virQEMUCapsPtr *qemuCaps) { if (*qemuCaps && - !virQEMUCapsIsValid(*qemuCaps, 0, cache->runUid, cache->runGid)) { + !virQEMUCapsIsValid(*qemuCaps, cache->runUid, cache->runGid)) { VIR_DEBUG("Cached capabilities %p no longer valid for %s", *qemuCaps, binary); virHashRemoveEntry(cache->binaries, binary); --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 02:47:10 2024 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 1500477026371482.412225832943; Wed, 19 Jul 2017 08:10:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B63857A176; Wed, 19 Jul 2017 15:10:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 801FF7D667; Wed, 19 Jul 2017 15:10:24 +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 B84B61853E3F; Wed, 19 Jul 2017 15:10:20 +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 v6JFABQE029666 for ; Wed, 19 Jul 2017 11:10:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2AACE78369; Wed, 19 Jul 2017 15:10:11 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id A976E783BD for ; Wed, 19 Jul 2017 15:10:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B63857A176 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 B63857A176 From: Pavel Hrdina To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 17:09:51 +0200 Message-Id: <541269cecd4073ea9893bda3f0d2500779983890.1500476925.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 v2 6/6] qemu: separate virQEMUCapsInitCached out of virQEMUCapsNewForBinaryInternal 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 19 Jul 2017 15:10:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Preparation for switching to virFileCache where there are two callbacks, one to get a new data and second one to load a cached data. This also removes virQEMUCapsReset which is no longer required. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 143 +++++++++++++++++++--------------------= ---- src/qemu/qemu_capspriv.h | 1 - tests/qemucapsprobe.c | 2 +- 3 files changed, 63 insertions(+), 83 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 948a7d900b..b7351322bc 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4250,37 +4250,6 @@ virQEMUCapsRememberCached(virQEMUCapsPtr qemuCaps, c= onst char *cacheDir) } =20 =20 -static void -virQEMUCapsReset(virQEMUCapsPtr qemuCaps) -{ - size_t i; - - virBitmapClearAll(qemuCaps->flags); - qemuCaps->version =3D qemuCaps->kvmVersion =3D 0; - VIR_FREE(qemuCaps->package); - qemuCaps->arch =3D VIR_ARCH_NONE; - qemuCaps->usedQMP =3D false; - - virObjectUnref(qemuCaps->kvmCPUModels); - qemuCaps->kvmCPUModels =3D NULL; - virObjectUnref(qemuCaps->tcgCPUModels); - qemuCaps->tcgCPUModels =3D NULL; - - for (i =3D 0; i < qemuCaps->nmachineTypes; i++) { - VIR_FREE(qemuCaps->machineTypes[i].name); - VIR_FREE(qemuCaps->machineTypes[i].alias); - } - VIR_FREE(qemuCaps->machineTypes); - qemuCaps->nmachineTypes =3D 0; - - VIR_FREE(qemuCaps->gicCapabilities); - qemuCaps->ngicCapabilities =3D 0; - - virQEMUCapsHostCPUDataClear(&qemuCaps->kvmCPU); - virQEMUCapsHostCPUDataClear(&qemuCaps->tcgCPU); -} - - static bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, uid_t runUid, @@ -4346,7 +4315,8 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps, =20 static int virQEMUCapsInitCached(virCapsPtr caps, - virQEMUCapsPtr qemuCaps, + virQEMUCapsPtr *qemuCaps, + const char *binary, const char *cacheDir, uid_t runUid, gid_t runGid) @@ -4356,14 +4326,12 @@ virQEMUCapsInitCached(virCapsPtr caps, int ret =3D -1; char *binaryhash =3D NULL; struct stat sb; - time_t qemuctime =3D qemuCaps->ctime; + virQEMUCapsPtr qemuCapsNew =3D NULL; =20 if (virAsprintf(&capsdir, "%s/capabilities", cacheDir) < 0) goto cleanup; =20 - if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, - qemuCaps->binary, - &binaryhash) < 0) + if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, binary, &binaryhash) <= 0) goto cleanup; =20 if (virAsprintf(&capsfile, "%s/%s.xml", capsdir, binaryhash) < 0) @@ -4379,33 +4347,39 @@ virQEMUCapsInitCached(virCapsPtr caps, if (stat(capsfile, &sb) < 0) { if (errno =3D=3D ENOENT) { VIR_DEBUG("No cached capabilities '%s' for '%s'", - capsfile, qemuCaps->binary); + capsfile, binary); ret =3D 0; goto cleanup; } virReportSystemError(errno, _("Unable to access cache '%s' for '%s'"), - capsfile, qemuCaps->binary); + capsfile, binary); goto cleanup; } =20 - if (virQEMUCapsLoadCache(caps, qemuCaps, capsfile) < 0) { + if (!(qemuCapsNew =3D virQEMUCapsNew())) + goto cleanup; + + if (VIR_STRDUP(qemuCapsNew->binary, binary) < 0) + goto discard; + + if (virQEMUCapsLoadCache(caps, qemuCapsNew, capsfile) < 0) { VIR_WARN("Failed to load cached caps from '%s' for '%s': %s", - capsfile, qemuCaps->binary, virGetLastErrorMessage()); + capsfile, qemuCapsNew->binary, virGetLastErrorMessage()); virResetLastError(); goto discard; } =20 - if (!virQEMUCapsIsValid(qemuCaps, runUid, runGid)) + if (!virQEMUCapsIsValid(qemuCapsNew, runUid, runGid)) goto discard; =20 VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=3D%d", - capsfile, qemuCaps->binary, - (long long)qemuCaps->ctime, qemuCaps->usedQMP); + capsfile, qemuCapsNew->binary, + (long long)qemuCapsNew->ctime, qemuCapsNew->usedQMP); =20 ret =3D 1; + *qemuCaps =3D qemuCapsNew; cleanup: - qemuCaps->ctime =3D qemuctime; VIR_FREE(binaryhash); VIR_FREE(capsfile); VIR_FREE(capsdir); @@ -4413,9 +4387,9 @@ virQEMUCapsInitCached(virCapsPtr caps, =20 discard: VIR_DEBUG("Dropping cached capabilities '%s' for '%s'", - capsfile, qemuCaps->binary); + capsfile, qemuCapsNew->binary); ignore_value(unlink(capsfile)); - virQEMUCapsReset(qemuCaps); + virObjectUnref(qemuCapsNew); ret =3D 0; goto cleanup; } @@ -5230,14 +5204,12 @@ virQEMUCapsPtr virQEMUCapsNewForBinaryInternal(virCapsPtr caps, const char *binary, const char *libDir, - const char *cacheDir, uid_t runUid, gid_t runGid, bool qmpOnly) { virQEMUCapsPtr qemuCaps; struct stat sb; - int rv; char *qmperr =3D NULL; =20 if (!(qemuCaps =3D virQEMUCapsNew())) @@ -5265,42 +5237,30 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps, goto error; } =20 - if (!cacheDir) - rv =3D 0; - else if ((rv =3D virQEMUCapsInitCached(caps, qemuCaps, cacheDir, - runUid, runGid)) < 0) + if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) < 0)= { + virQEMUCapsLogProbeFailure(binary); goto error; + } =20 - if (rv =3D=3D 0) { - if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) = < 0) { - virQEMUCapsLogProbeFailure(binary); - goto error; - } - - if (qmpOnly && !qemuCaps->usedQMP) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to probe QEMU binary with QMP: %s"), - qmperr ? qmperr : _("unknown error")); - virQEMUCapsLogProbeFailure(binary); - goto error; - } - - if (!qemuCaps->usedQMP && - virQEMUCapsInitHelp(qemuCaps, runUid, runGid, qmperr) < 0) { - virQEMUCapsLogProbeFailure(binary); - goto error; - } + if (qmpOnly && !qemuCaps->usedQMP) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to probe QEMU binary with QMP: %s"), + qmperr ? qmperr : _("unknown error")); + virQEMUCapsLogProbeFailure(binary); + goto error; + } =20 - qemuCaps->libvirtCtime =3D virGetSelfLastChanged(); - qemuCaps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; + if (!qemuCaps->usedQMP && + virQEMUCapsInitHelp(qemuCaps, runUid, runGid, qmperr) < 0) { + virQEMUCapsLogProbeFailure(binary); + goto error; + } =20 - if (cacheDir && - virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0) - goto error; + qemuCaps->libvirtCtime =3D virGetSelfLastChanged(); + qemuCaps->libvirtVersion =3D LIBVIR_VERSION_NUMBER; =20 - virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_KVM); - virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_QEMU); - } + virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_KVM); + virQEMUCapsInitHostCPUModel(qemuCaps, caps, VIR_DOMAIN_VIRT_QEMU); =20 cleanup: VIR_FREE(qmperr); @@ -5320,8 +5280,29 @@ virQEMUCapsNewForBinary(virCapsPtr caps, uid_t runUid, gid_t runGid) { - return virQEMUCapsNewForBinaryInternal(caps, binary, libDir, cacheDir, - runUid, runGid, false); + int rv; + virQEMUCapsPtr qemuCaps =3D NULL; + + if ((rv =3D virQEMUCapsInitCached(caps, &qemuCaps, binary, cacheDir, + runUid, runGid)) < 0) + goto error; + + if (rv =3D=3D 0) { + if (!(qemuCaps =3D virQEMUCapsNewForBinaryInternal(caps, binary, + libDir, runUid, + runGid, false))) { + goto error; + } + + if (virQEMUCapsRememberCached(qemuCaps, cacheDir) < 0) + goto error; + } + + return qemuCaps; + + error: + virObjectUnref(qemuCaps); + return NULL; } =20 =20 diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 1162e0b284..3458fc0700 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -43,7 +43,6 @@ virQEMUCapsPtr virQEMUCapsNewForBinaryInternal(virCapsPtr caps, const char *binary, const char *libDir, - const char *cacheDir, uid_t runUid, gid_t runGid, bool qmpOnly); diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c index 662c7036ed..581ac38465 100644 --- a/tests/qemucapsprobe.c +++ b/tests/qemucapsprobe.c @@ -70,7 +70,7 @@ main(int argc, char **argv) if (virThreadCreate(&thread, false, eventLoop, NULL) < 0) return EXIT_FAILURE; =20 - if (!(caps =3D virQEMUCapsNewForBinaryInternal(NULL, argv[1], "/tmp", = NULL, + if (!(caps =3D virQEMUCapsNewForBinaryInternal(NULL, argv[1], "/tmp", -1, -1, true))) return EXIT_FAILURE; =20 --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list