From nobody Sun Feb 8 21:33:27 2026 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=1637687413; cv=none; d=zohomail.com; s=zohoarc; b=T/iqLDf1H/fs7wCfNnyjms8qQW7DzfFPaZ7gog7CShwoPpDEjB2hdwyMfmc6EFB3ErfTkMVX6ysAKtM0aFuhhu/ypzBKLC+cvsLsqo2K0/0RrWfWR5FP2Rl2Zr9xsExYahVaXbkJngrIelelUXkBPjS6Id9c2np5OiZY8pBE4tM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687413; 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=dRTQw2yojJm9AcbY3/PkaFijmpQx0B6eRM/Mvot7VBA=; b=cbeatgnENoqIMOPTKHvQnDX9TJ1EKyexJ9X2/v4DhAQK60FEM2WcGS73De0/pm2DbN83SRL2k/DzufIjs4s5NCBlnzjorZLQw1acm1YQvYN94bK3BlvmfGGyHSIoyQZgNNhfFK1DD9X/uFnYTJ8QYEctxReKyLyipaMVV/L7j4A= 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 1637687413482103.25696780771477; Tue, 23 Nov 2021 09:10:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-3Rw7uAb0NkO3A0TPytZ1Ag-1; Tue, 23 Nov 2021 12:10:10 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C4661DDF7; Tue, 23 Nov 2021 17:10:04 +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 F3CB56784E; Tue, 23 Nov 2021 17: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 C022E1832E84; Tue, 23 Nov 2021 17:10:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1ANH9r1x023144 for ; Tue, 23 Nov 2021 12:09:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id C11FA5C232; Tue, 23 Nov 2021 17:09:53 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 230B65C1D5; Tue, 23 Nov 2021 17:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637687412; 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=dRTQw2yojJm9AcbY3/PkaFijmpQx0B6eRM/Mvot7VBA=; b=fJg5uPL/oRCxGvqrjvPfU+P3GQ5mFPGHZ+57RumQGrX4yrblZqMaUIiKg8S69bpzt/GwUM p9ImZTObxx9CrUzYgXJPsArGJqeSfs686/1hnuag2wRAxAi0bFwdXjSSnOaU3gkKu0I3aT 1DFAd8g3f0qTpl8HGu1+ZALkz8hQw6o= X-MC-Unique: 3Rw7uAb0NkO3A0TPytZ1Ag-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/4] virStoragePoolObjListAdd: Transfer definition ownership Date: Tue, 23 Nov 2021 18:09:39 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.79 on 10.5.11.11 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: 1637687415449100001 Content-Type: text/plain; charset="utf-8" Upon successful return from virStoragePoolObjListAdd() the virStoragePoolObj is the owner of secret definition. To make this ownership transfer even more visible, lets pass the definition as a double pointer and use g_steal_pointer(). Signed-off-by: Michal Privoznik --- src/conf/virstorageobj.c | 29 ++++++++++++++++------------- src/conf/virstorageobj.h | 2 +- src/storage/storage_driver.c | 5 ++--- src/test/test_driver.c | 8 +++----- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index f906c5b141..2c29339b6a 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1513,20 +1513,20 @@ virStoragePoolObjSourceFindDuplicate(virStoragePool= ObjList *pools, =20 static void virStoragePoolObjAssignDef(virStoragePoolObj *obj, - virStoragePoolDef *def, + virStoragePoolDef **def, unsigned int flags) { if (virStoragePoolObjIsActive(obj) || virStoragePoolObjIsStarting(obj)) { virStoragePoolDefFree(obj->newDef); - obj->newDef =3D def; + obj->newDef =3D g_steal_pointer(def); } else { if (!obj->newDef && flags & VIR_STORAGE_POOL_OBJ_LIST_ADD_LIVE) obj->newDef =3D g_steal_pointer(&obj->def); =20 virStoragePoolDefFree(obj->def); - obj->def =3D def; + obj->def =3D g_steal_pointer(def); } } =20 @@ -1548,11 +1548,16 @@ virStoragePoolObjAssignDef(virStoragePoolObj *obj, * If VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE is set in @flags * then this will fail if the pool exists and is active. * + * Upon successful return the virStoragePool object is the owner + * of @def and callers should use virStoragePoolObjGetDef() or + * virStoragePoolObjGetNewDef() if they need to access the + * definition as @def is set to NULL. + * * Returns locked and reffed object pointer or NULL on error */ virStoragePoolObj * virStoragePoolObjListAdd(virStoragePoolObjList *pools, - virStoragePoolDef *def, + virStoragePoolDef **def, unsigned int flags) { virStoragePoolObj *obj =3D NULL; @@ -1561,10 +1566,10 @@ virStoragePoolObjListAdd(virStoragePoolObjList *poo= ls, =20 virObjectRWLockWrite(pools); =20 - if (virStoragePoolObjSourceFindDuplicate(pools, def) < 0) + if (virStoragePoolObjSourceFindDuplicate(pools, *def) < 0) goto error; =20 - rc =3D virStoragePoolObjIsDuplicate(pools, def, + rc =3D virStoragePoolObjIsDuplicate(pools, *def, !!(flags & VIR_STORAGE_POOL_OBJ_LIST= _ADD_CHECK_LIVE), &obj); =20 @@ -1579,17 +1584,17 @@ virStoragePoolObjListAdd(virStoragePoolObjList *poo= ls, if (!(obj =3D virStoragePoolObjNew())) goto error; =20 - virUUIDFormat(def->uuid, uuidstr); + virUUIDFormat((*def)->uuid, uuidstr); if (virHashAddEntry(pools->objs, uuidstr, obj) < 0) goto error; virObjectRef(obj); =20 - if (virHashAddEntry(pools->objsName, def->name, obj) < 0) { + if (virHashAddEntry(pools->objsName, (*def)->name, obj) < 0) { virHashRemoveEntry(pools->objs, uuidstr); goto error; } virObjectRef(obj); - obj->def =3D def; + obj->def =3D g_steal_pointer(def); virObjectRWUnlock(pools); return obj; =20 @@ -1620,9 +1625,8 @@ virStoragePoolObjLoad(virStoragePoolObjList *pools, return NULL; } =20 - if (!(obj =3D virStoragePoolObjListAdd(pools, def, 0))) + if (!(obj =3D virStoragePoolObjListAdd(pools, &def, 0))) return NULL; - def =3D NULL; =20 VIR_FREE(obj->configFile); /* for driver reload */ obj->configFile =3D g_strdup(path); @@ -1673,10 +1677,9 @@ virStoragePoolObjLoadState(virStoragePoolObjList *po= ols, } =20 /* create the object */ - if (!(obj =3D virStoragePoolObjListAdd(pools, def, + if (!(obj =3D virStoragePoolObjListAdd(pools, &def, VIR_STORAGE_POOL_OBJ_LIST_ADD_CHE= CK_LIVE))) return NULL; - def =3D NULL; =20 /* XXX: future handling of some additional useful status data, * for now, if a status file for a pool exists, the pool will be marked diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 65f2ae8175..523bdec244 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -203,7 +203,7 @@ typedef enum { =20 virStoragePoolObj * virStoragePoolObjListAdd(virStoragePoolObjList *pools, - virStoragePoolDef *def, + virStoragePoolDef **def, unsigned int flags); =20 int diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 51daf6a05d..4df2c75a2b 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -746,11 +746,10 @@ storagePoolCreateXML(virConnectPtr conn, if ((backend =3D virStorageBackendForType(newDef->type)) =3D=3D NULL) goto cleanup; =20 - if (!(obj =3D virStoragePoolObjListAdd(driver->pools, newDef, + if (!(obj =3D virStoragePoolObjListAdd(driver->pools, &newDef, VIR_STORAGE_POOL_OBJ_LIST_ADD_LIV= E | VIR_STORAGE_POOL_OBJ_LIST_ADD_CHE= CK_LIVE))) goto cleanup; - newDef =3D NULL; def =3D virStoragePoolObjGetDef(obj); =20 virStoragePoolObjSetStarting(obj, true); @@ -830,7 +829,7 @@ storagePoolDefineXML(virConnectPtr conn, if (virStorageBackendForType(newDef->type) =3D=3D NULL) goto cleanup; =20 - if (!(obj =3D virStoragePoolObjListAdd(driver->pools, newDef, 0))) + if (!(obj =3D virStoragePoolObjListAdd(driver->pools, &newDef, 0))) goto cleanup; newDef =3D virStoragePoolObjGetNewDef(obj); def =3D virStoragePoolObjGetDef(obj); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 92c0462170..369edacf29 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1226,7 +1226,7 @@ testParseStorage(testDriver *privconn, if (!def) return -1; =20 - if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, def, 0))) { + if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, &def, 0)))= { virStoragePoolDefFree(def); return -1; } @@ -6675,10 +6675,9 @@ testStoragePoolCreateXML(virConnectPtr conn, if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 - if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, newDef, + if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, &newDef, VIR_STORAGE_POOL_OBJ_LIST_ADD_CHE= CK_LIVE))) goto cleanup; - newDef =3D NULL; def =3D virStoragePoolObjGetDef(obj); =20 if (def->source.adapter.type =3D=3D VIR_STORAGE_ADAPTER_TYPE_FC_HOST) { @@ -6742,9 +6741,8 @@ testStoragePoolDefineXML(virConnectPtr conn, newDef->allocation =3D defaultPoolAlloc; newDef->available =3D defaultPoolCap - defaultPoolAlloc; =20 - if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, newDef, 0))) + if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, &newDef, 0))) goto cleanup; - newDef =3D NULL; def =3D virStoragePoolObjGetDef(obj); =20 event =3D virStoragePoolEventLifecycleNew(def->name, def->uuid, --=20 2.32.0