From nobody Thu May 15 12:45:48 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 1510563071129840.2997950880524; Mon, 13 Nov 2017 00:51:11 -0800 (PST) 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 B235525C37; Mon, 13 Nov 2017 08:51:07 +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 8F3C25E7B7; Mon, 13 Nov 2017 08:51:07 +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 5D0F51802127; Mon, 13 Nov 2017 08:51:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAD8okjl016288 for ; Mon, 13 Nov 2017 03:50:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5BD8A7A202; Mon, 13 Nov 2017 08:50:46 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FA147A206 for ; Mon, 13 Nov 2017 08:50:46 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 8E2A3123A7F for ; Mon, 13 Nov 2017 09:50:41 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 13 Nov 2017 09:50:25 +0100 Message-Id: <46af7130891cdc77a0fe6e4b3689eeef990070af.1510560300.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/21] conf: Sort cache banks in capabilities XML 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.30]); Mon, 13 Nov 2017 08:51:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Because the cache banks are initialized based on the order in which their respective directories exist on the filesystem, they can appear in diferrent order. This is here mainly for tests because the cache directory might have different order of children nodes and tests would fail otherwise. It shoul= d not be the case with sysfs, but one can never be sure. And this does not take almost any extra time, mainly because it gets initialized once per driver. Signed-off-by: Martin Kletzander Reviewed-by: John Ferlan --- src/conf/capabilities.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 9920a675aca3..095ef51c424a 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1561,6 +1561,20 @@ virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr) VIR_FREE(ptr); } =20 +static int +virCapsHostCacheBankSorter(const void *a, const void *b) +{ + virCapsHostCacheBankPtr ca =3D *(virCapsHostCacheBankPtr *)a; + virCapsHostCacheBankPtr cb =3D *(virCapsHostCacheBankPtr *)b; + + if (ca->level < cb->level) + return -1; + if (ca->level > cb->level) + return 1; + + return ca->id - cb->id; +} + int virCapabilitiesInitCaches(virCapsPtr caps) { @@ -1700,6 +1714,12 @@ virCapabilitiesInitCaches(virCapsPtr caps) goto cleanup; } =20 + /* Sort the array in order for the tests to be predicable. This way w= e can + * still traverse the directory instead of guessing names (in case the= re is + * 'index1' and 'index3' but no 'index2'). */ + qsort(caps->host.caches, caps->host.ncaches, + sizeof(*caps->host.caches), virCapsHostCacheBankSorter); + ret =3D 0; cleanup: VIR_FREE(type); --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list