From nobody Mon Feb 9 19:05:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1612600447; cv=none; d=zohomail.com; s=zohoarc; b=GxYtYJb5AYxhG2HC6a21FwAMVajPobX4R0487o1ARtISxuBWiclM4tFBD71i1DYHGOaG3WbyCn1oEAbdyc2kI969/hN3/Jdj0Lugi4h9A+CrvsFtYAC/b8QCky+qyQ1bPz/GI+BX1Uycga4A5lTDLfsjAGrHiN/z+Wdx+hITRSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600447; 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=wExZRxyzOF0gsYrgFFoPupZayVJFkXDUBDK1eSlF3Ic=; b=fP3nxnVnvpLqFkf8qq0cm4Co0Uk2jlOrxMpnY5VVwZL4k3Ao4HuzL+1NX7mfgTovVmvZwyUxMF2tUyOsMn+usZv7plX0OCC3Xl0/hifZL0VBaKlEcjek0xYY8LpBxv30sggEPpC2r0bHwVTveIzo+fJ24PV3uENICuntR6BGf3o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612600447226655.8380800773243; Sat, 6 Feb 2021 00:34:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-4v9B5_5VNGeIiwXVXuFbgw-1; Sat, 06 Feb 2021 03:34:03 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C277100CCC6; Sat, 6 Feb 2021 08:33:58 +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 DC1451010F4E; Sat, 6 Feb 2021 08:33:57 +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 A451218077CE; Sat, 6 Feb 2021 08:33:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1168XtlY005091 for ; Sat, 6 Feb 2021 03:33:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id B351360C77; Sat, 6 Feb 2021 08:33:55 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E850360C76 for ; Sat, 6 Feb 2021 08:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600446; 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=wExZRxyzOF0gsYrgFFoPupZayVJFkXDUBDK1eSlF3Ic=; b=ARHtKx13bDSlFiVugpFQWP0MwOZQ4oNPPmtQQ1GIaI8v8EhocZCMjvLDWvpUct5J0wLlB2 YL8cc/XSmjePyy1aMbFc9iLRYJYAtJ7aVR9WWSh7zHfi3o6aaeY5zpJeLpiHaXpXpBZKHv r14ecwg6807UQfuzgj26Qp+SUow0F8s= X-MC-Unique: 4v9B5_5VNGeIiwXVXuFbgw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 20/40] qemusecuritytest: Store 'notRestored' files in a hash table Date: Sat, 6 Feb 2021 09:32:42 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The validation code looks whether certain paths are in the 'notRestored' list. For the purpose of lookup it's better to use a hash table rather than a string list. Signed-off-by: Peter Krempa --- tests/qemusecuritymock.c | 19 +++++++++++-------- tests/qemusecuritytest.c | 14 ++++++-------- tests/qemusecuritytest.h | 4 +++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 1fa4e522cc..5daf27ccd7 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -398,7 +398,7 @@ int virFileUnlock(int fd G_GNUC_UNUSED, typedef struct _checkOwnerData checkOwnerData; struct _checkOwnerData { - const char **paths; + GHashTable *paths; bool chown_fail; bool selinux_fail; }; @@ -413,7 +413,7 @@ checkSELinux(void *payload, char *label =3D payload; if (STRNEQ(label, DEFAULT_SELINUX_LABEL) && - !virStringListHasString(data->paths, name)) { + !g_hash_table_contains(data->paths, name)) { fprintf(stderr, "Path %s wasn't restored back to its original SELinux labe= l\n", name); @@ -434,7 +434,7 @@ checkOwner(void *payload, if ((owner % 16 !=3D DEFAULT_UID || owner >> 16 !=3D DEFAULT_GID) && - !virStringListHasString(data->paths, name)) { + !g_hash_table_contains(data->paths, name)) { fprintf(stderr, "Path %s wasn't restored back to its original owner\n", name); @@ -473,19 +473,22 @@ printXATTR(void *payload, * can be passed in @paths argument. If a path is not restored * but it's on the list no error is indicated. */ -int checkPaths(const char **paths) +int checkPaths(GHashTable *paths) { int ret =3D -1; checkOwnerData data =3D { .paths =3D paths, .chown_fail =3D false, .se= linux_fail =3D false }; bool xattr_fail =3D false; - size_t i; + GHashTableIter htitr; + void *key; virMutexLock(&m); init_hash(); - for (i =3D 0; paths && paths[i]; i++) { - if (!virHashLookup(chown_paths, paths[i])) { - fprintf(stderr, "Unexpected path restored: %s\n", paths[i]); + g_hash_table_iter_init(&htitr, paths); + + while (g_hash_table_iter_next(&htitr, &key, NULL)) { + if (!virHashLookup(chown_paths, key)) { + fprintf(stderr, "Unexpected path restored: %s\n", (const char = *) key); goto cleanup; } } diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 1750018137..74a25f2be1 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -87,7 +87,7 @@ testDomain(const void *opaque) { const struct testData *data =3D opaque; g_autoptr(virDomainObj) vm =3D NULL; - g_auto(GStrv) notRestored =3D NULL; + g_autoptr(GHashTable) notRestored =3D virHashNew(NULL); size_t i; int ret =3D -1; @@ -102,14 +102,12 @@ testDomain(const void *opaque) continue; if (virStorageSourceIsLocalStorage(src) && src->path && - (src->shared || src->readonly) && - virStringListAdd(¬Restored, src->path) < 0) - return -1; + (src->shared || src->readonly)) + g_hash_table_insert(notRestored, g_strdup(src->path), NULL); for (n =3D src->backingStore; virStorageSourceIsBacking(n); n =3D = n->backingStore) { - if (virStorageSourceIsLocalStorage(n) && n->path && - virStringListAdd(¬Restored, n->path) < 0) - return -1; + if (virStorageSourceIsLocalStorage(n) && n->path) + g_hash_table_insert(notRestored, g_strdup(n->path), NULL); } } @@ -123,7 +121,7 @@ testDomain(const void *opaque) qemuSecurityRestoreAllLabel(data->driver, vm, false); - if (checkPaths((const char **) notRestored) < 0) + if (checkPaths(notRestored) < 0) goto cleanup; ret =3D 0; diff --git a/tests/qemusecuritytest.h b/tests/qemusecuritytest.h index cc3918ddf5..696cfb4b63 100644 --- a/tests/qemusecuritytest.h +++ b/tests/qemusecuritytest.h @@ -20,6 +20,8 @@ #define ENVVAR "LIBVIRT_QEMU_SECURITY_TEST" -extern int checkPaths(const char **paths); +#include "internal.h" + +extern int checkPaths(GHashTable *paths); extern void freePaths(void); --=20 2.29.2