From nobody Mon Feb 9 16:33:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1649775543; cv=none; d=zohomail.com; s=zohoarc; b=H+Oxd2b5dCwRvLMz9q35crhLUwJPmqvS0yCeifAA/uHX5wM5WNPD28y2tE6ouoldXKgZ+5s7n4YNq9UWfCs0Nh4Yd3kqlyiF+0mHE0F5VxTITVTr9elNMzOGaO9a0bDhYwj0eRVkuntwxRebc/LIKbk/LKFTUaWxNGPF4sqE3c4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649775543; h=Content-Type:Content-Transfer-Encoding:Cc: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=c/wkSE9mhmPllj3beykIrN2w3KuilU9s0Exvl6Tcs94=; b=ElfERvlw6U5jJoNVJyg7/fEFWhN93RjCK955ONL96FKSMiiDtNNsvU0ntRx12gRy417nI2xSzoxFnZs+0EbT15iz29egAES/w462GHtesrivAf63XYtkWKZ7gM4Jz9S2CAZUMgcp1nPLmD61fCoPOkZL8E3tvZCk45AB8Ta5d+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1649775543576206.04065148734003; Tue, 12 Apr 2022 07:59:03 -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-284-Gt9KLMakP7uQCG964tsu9A-1; Tue, 12 Apr 2022 10:58:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5236188FA4D; Tue, 12 Apr 2022 14:57:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3712440F4944; Tue, 12 Apr 2022 14:57:31 +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 F0A4F1940373; Tue, 12 Apr 2022 14:57:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 18DB61940365 for ; Tue, 12 Apr 2022 14:57:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 03351432033; Tue, 12 Apr 2022 14:57:30 +0000 (UTC) Received: from work.redhat.com (unknown [10.39.194.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 820AE432036; Tue, 12 Apr 2022 14:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649775542; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=c/wkSE9mhmPllj3beykIrN2w3KuilU9s0Exvl6Tcs94=; b=ivkbeRDbz/hVcB7x+yLe6DY4ahVj7DPs/Avnlx93IaykYptBLailE01fQKlsK7z8tTWSh1 04i2dU0ArGUePeZknSOyIE8U/w2GlQXlWiDnGmIaCmT3mr7pmwOMd3diEECgzsVh5Dyu2L xrQ+0e5PtASJYPDi0PX8IS+/nyGLwMw= X-MC-Unique: Gt9KLMakP7uQCG964tsu9A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 01/10] virstorageobj: Replace deprecated virHash functions Date: Tue, 12 Apr 2022 16:57:18 +0200 Message-Id: <20220412145727.69564-2-twiederh@redhat.com> In-Reply-To: <20220412145727.69564-1-twiederh@redhat.com> References: <20220412145727.69564-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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: , Cc: Tim Wiederhake Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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) X-ZM-MESSAGEID: 1649775545496100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Checking for duplicate / NULL keys beforehand will simplify error handling in a later patch significantly. Signed-off-by: Tim Wiederhake --- src/conf/virstorageobj.c | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index b57c1cb8b2..99aee9ffb4 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -521,8 +521,8 @@ virStoragePoolObjRemove(virStoragePoolObjList *pools, virObjectUnlock(obj); virObjectRWLockWrite(pools); virObjectLock(obj); - virHashRemoveEntry(pools->objs, uuidstr); - virHashRemoveEntry(pools->objsName, obj->def->name); + g_hash_table_remove(pools->objs, uuidstr); + g_hash_table_remove(pools->objsName, obj->def->name); virObjectUnref(obj); virObjectRWUnlock(pools); } @@ -621,9 +621,9 @@ virStoragePoolObjClearVols(virStoragePoolObj *obj) if (!obj->volumes) return; =20 - virHashRemoveAll(obj->volumes->objsKey); - virHashRemoveAll(obj->volumes->objsName); - virHashRemoveAll(obj->volumes->objsPath); + g_hash_table_remove_all(obj->volumes->objsKey); + g_hash_table_remove_all(obj->volumes->objsName); + g_hash_table_remove_all(obj->volumes->objsPath); } =20 =20 @@ -639,21 +639,19 @@ virStoragePoolObjAddVol(virStoragePoolObj *obj, if (!(volobj =3D virStorageVolObjNew())) goto error; =20 - if (virHashAddEntry(volumes->objsKey, voldef->key, volobj) < 0) + if (!voldef->key || !voldef->name || !voldef->target.path || + g_hash_table_contains(volumes->objsKey, voldef->key) || + g_hash_table_contains(volumes->objsName, voldef->name) || + g_hash_table_contains(volumes->objsPath, voldef->target.path)) goto error; + + g_hash_table_insert(volumes->objsKey, g_strdup(voldef->key), volobj); virObjectRef(volobj); =20 - if (virHashAddEntry(volumes->objsName, voldef->name, volobj) < 0) { - virHashRemoveEntry(volumes->objsKey, voldef->key); - goto error; - } + g_hash_table_insert(volumes->objsName, g_strdup(voldef->name), volobj); virObjectRef(volobj); =20 - if (virHashAddEntry(volumes->objsPath, voldef->target.path, volobj) < = 0) { - virHashRemoveEntry(volumes->objsKey, voldef->key); - virHashRemoveEntry(volumes->objsName, voldef->name); - goto error; - } + g_hash_table_insert(volumes->objsPath, g_strdup(voldef->target.path), = volobj); virObjectRef(volobj); =20 volobj->voldef =3D voldef; @@ -688,9 +686,9 @@ virStoragePoolObjRemoveVol(virStoragePoolObj *obj, =20 virObjectRef(volobj); virObjectLock(volobj); - virHashRemoveEntry(volumes->objsKey, voldef->key); - virHashRemoveEntry(volumes->objsName, voldef->name); - virHashRemoveEntry(volumes->objsPath, voldef->target.path); + g_hash_table_remove(volumes->objsKey, voldef->key); + g_hash_table_remove(volumes->objsName, voldef->name); + g_hash_table_remove(volumes->objsPath, voldef->target.path); virStorageVolObjEndAPI(&volobj); =20 virObjectRWUnlock(volumes); @@ -1582,15 +1580,18 @@ virStoragePoolObjListAdd(virStoragePoolObjList *poo= ls, goto error; =20 virUUIDFormat((*def)->uuid, uuidstr); - if (virHashAddEntry(pools->objs, uuidstr, obj) < 0) + + if (!(*def)->name || + g_hash_table_contains(pools->objs, uuidstr) || + g_hash_table_contains(pools->objsName, (*def)->name)) goto error; + + g_hash_table_insert(pools->objs, g_strdup(uuidstr), obj); virObjectRef(obj); =20 - if (virHashAddEntry(pools->objsName, (*def)->name, obj) < 0) { - virHashRemoveEntry(pools->objs, uuidstr); - goto error; - } + g_hash_table_insert(pools->objsName, g_strdup((*def)->name), obj); virObjectRef(obj); + obj->def =3D g_steal_pointer(def); virObjectRWUnlock(pools); return obj; --=20 2.31.1