From nobody Fri Dec 19 19:13:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1679064956; cv=none; d=zohomail.com; s=zohoarc; b=j1XZCHg/YaeUzLJDl8tietyhJU3udYL6xts4/vxPrCqklBXhV1sTlhUwH+E1ecH8THDTr4ozZG4MckErXSna0sdz8vYO1pdO4KjYTuqFEtj154ZeVf+8EjNdTKNNyawG5Fkmj7/jCjul13zYWPVIkNXsag4+4K+iyGJqOT8ZnCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679064956; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Yn4Gdi+/pcwTocgyrYKewM38tNaZDqSMMaLI2ibErEQ=; b=mq7QYaE0z+ySc+ukCKdmsEjJH2OQmLSMMRLN5+bLLNjYtYjCSqu57PBBd3NDOjQWiYt6L8udfsxe3/zNEigxEGTX9xnk+SCewt6/DwTYV5P5XTvJuMlVueJKniRw/y+SkH34NDIpc+BiZ4eOjaWb2J5CkWutw5Nf15sxKZ4MKRQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1679064956916954.7609184319358; Fri, 17 Mar 2023 07:55:56 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-481-oOIkDam9Mma2sG2M1AqK4A-1; Fri, 17 Mar 2023 10:55:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABA0587A9E0; Fri, 17 Mar 2023 14:55:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97E1A6B590; Fri, 17 Mar 2023 14:55:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 74CDD1946597; Fri, 17 Mar 2023 14:55:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1AF971946587 for ; Thu, 16 Mar 2023 16:12:13 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 18EA72166B26; Thu, 16 Mar 2023 16:12:13 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01DB42166B29 for ; Thu, 16 Mar 2023 16:12:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064955; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Yn4Gdi+/pcwTocgyrYKewM38tNaZDqSMMaLI2ibErEQ=; b=D8dDxI4Ci8VVDzylFeNO+Io6sO0JkZaHfv18TxGEmpg+SmalkmzE8/jW9y4ouy55M+2NND fnGOUckpxWjANmi9C5vlLMq3P13+9PwpnJYLR2Z3ZeO29DD7LHMJ8EAmkD3mkVBJuegP9y lFCjKSoRrD84EEivHOadB+SJpyBk1Yc= X-MC-Unique: oOIkDam9Mma2sG2M1AqK4A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/24] testQemuGetLatestCaps: Process capabilities for all architectures in one pass Date: Thu, 16 Mar 2023 17:11:35 +0100 Message-Id: <8c8ef5b391bbd580b43a25f641fa1cf781c87bd4.1678982996.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1679064958058100002 Content-Type: text/plain; charset="utf-8" Rather than finding the newest caps file iteratively for specific architectures in multiple passes over the directory we can simply load the latest for everything in one pass by storing the version in the hash table and filling it progressively. Signed-off-by: Peter Krempa --- tests/testutilsqemu.c | 86 +++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 8c2cb6aa45..946f985d58 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -710,6 +710,23 @@ testQemuCapsSetGIC(virQEMUCaps *qemuCaps, #endif +struct testQemuCapsFile { + unsigned long long ver; + char *path; +}; + + +static void +testQemuCapsFileFree(struct testQemuCapsFile *f) +{ + if (!f) + return; + + g_free(f->path); + g_free(f); +} + + char * testQemuGetLatestCapsForArch(const char *arch, const char *suffix) @@ -766,32 +783,60 @@ testQemuGetLatestCapsForArch(const char *arch, GHashTable * testQemuGetLatestCaps(void) { - const char *archs[] =3D { - "aarch64", - "ppc64", - "riscv64", - "s390x", - "x86_64", - "sparc", - "ppc", - }; - g_autoptr(GHashTable) capslatest =3D virHashNew(g_free); - size_t i; + g_autoptr(GHashTable) caps =3D virHashNew((GDestroyNotify)testQemuCaps= FileFree); + struct dirent *ent; + g_autoptr(DIR) dir =3D NULL; + int rc; + + if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0) + return NULL; + + while ((rc =3D virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) { + g_autofree char *version =3D NULL; + char *arch =3D NULL; + unsigned long long ver; + struct testQemuCapsFile *f; + + if (!(version =3D g_strdup(STRSKIP(ent->d_name, "caps_")))) + continue; + + if (!virStringStripSuffix(version, ".xml")) + continue; - VIR_TEST_VERBOSE(""); + if (!(arch =3D strchr(version, '_'))) { + VIR_TEST_VERBOSE("malformed caps file name '%s'", ent->d_name); + return NULL; + } - for (i =3D 0; i < G_N_ELEMENTS(archs); ++i) { - char *cap =3D testQemuGetLatestCapsForArch(archs[i], "xml"); + *arch =3D '\0'; + arch++; - if (!cap || virHashAddEntry(capslatest, archs[i], cap) < 0) + if (virStringParseVersion(&ver, version, false) < 0) { + VIR_TEST_VERBOSE("malformed caps file name '%s'", ent->d_name); return NULL; + } + + if (!(f =3D g_hash_table_lookup(caps, arch))) { + VIR_TEST_DEBUG("CAPS: '%s': 'X' -> '%llu'", arch, ver); + f =3D g_new0(struct testQemuCapsFile, 1); + f->ver =3D ver; + f->path =3D g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, ent-= >d_name); + g_hash_table_insert(caps, g_strdup(arch), f); + continue; + } - VIR_TEST_VERBOSE("latest caps for %s: %s", archs[i], cap); + if (f->ver < ver) { + VIR_TEST_DEBUG("CAPS: '%s': '%llu' -> '%llu'", arch, f->ver, v= er); + f->ver =3D ver; + g_free(f->path); + f->path =3D g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, ent-= >d_name); + } } - VIR_TEST_VERBOSE(""); + if (rc < 0) + return NULL; - return g_steal_pointer(&capslatest); + return g_steal_pointer(&caps); } @@ -1002,13 +1047,14 @@ testQemuInfoInitArgs(struct testQemuInfo *info) info->arch =3D virArchFromString(info->args.capsarch); if (STREQ(info->args.capsver, "latest")) { - capsfile =3D g_strdup(virHashLookup(info->conf->capslatest, in= fo->args.capsarch)); + struct testQemuCapsFile *f =3D g_hash_table_lookup(info->conf-= >capslatest, info->args.capsarch); - if (!capsfile) { + if (!f) { fprintf(stderr, "'latest' caps for '%s' were not found\n",= info->args.capsarch); return -1; } + capsfile =3D g_strdup(f->path); stripmachinealiases =3D true; } else { capsfile =3D g_strdup_printf("%s/caps_%s_%s.xml", --=20 2.39.2