From nobody Fri Mar 29 02:22:25 2024 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=1637687424; cv=none; d=zohomail.com; s=zohoarc; b=HhERid86/QrhpHOHS7cNts0u6YB5QppfS8L2zVOuCiyArhKHjUU1Yyb1+NK/wDdcOVXTTWJsVeRyDqm2RJb8kfbAbxthv6y1AJ87rTh6hETURxipt41w9IWmf2s735qLi9xhCUCVw1fF/nAXFBcw4Oxjzf7ntxLBswhACEfe+9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687424; 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=Bquw8oEzT8yqB7HulnY9MEwYn0/e/xczJI8FZ7kLan4=; b=ZeOv8M2fIarpe2PQg5GdE7xIxH/X6Nupgw6thaJHKo26ol6SF0Tct9AbEVQsZzWYj0dUgpnYJtmEyXjPEW5h6uZuHBLrNxRvDBXOh5eAtl8pHCjV1sbkMCQcV2OflSWZ5Mqsbo4syBTF2wFUhU2en661pxk12aAfGqd/Jp6IvsU= 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 1637687424945850.9075732288746; Tue, 23 Nov 2021 09:10:24 -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-545-Zr8l_f3cMWi-A-ZPNxpwig-1; Tue, 23 Nov 2021 12:10:19 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA40419611C9; Tue, 23 Nov 2021 17:10:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC07760843; Tue, 23 Nov 2021 17:10:00 +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 887024E9F5; Tue, 23 Nov 2021 17:10:00 +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 1ANH9ptg023118 for ; Tue, 23 Nov 2021 12:09:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id D26635C232; Tue, 23 Nov 2021 17:09:51 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 337146788C; Tue, 23 Nov 2021 17:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637687423; 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=Bquw8oEzT8yqB7HulnY9MEwYn0/e/xczJI8FZ7kLan4=; b=aC1FdiOW6/2Jy/z4pkg8GPnLwIutXXQ14eDMEsJh8gf9cUoaxW/zohtc36vLfWmiRUWa4W cNrauINIuFVHyIm6xEdO/cHCsxTE0+AX59uuu2FgFIpKTleAFFQ9gPEY2RvJC5tyU3FT73 1IZEvsnHFOt4T6QKK++/AWc9SNiz6Mg= X-MC-Unique: Zr8l_f3cMWi-A-ZPNxpwig-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/4] virInterfaceObjListAssignDef: Transfer definition ownership Date: Tue, 23 Nov 2021 18:09:37 +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.13 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: 1637687426935100001 Content-Type: text/plain; charset="utf-8" Upon successful return from virInterfaceObjListAssignDef() the virInterfaceObj 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 Reviewed-by: Martin Kletzander --- src/conf/virinterfaceobj.c | 25 +++++++++++++++++++------ src/conf/virinterfaceobj.h | 2 +- src/test/test_driver.c | 6 ++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index c5dfa6c7f5..daac74e88c 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -377,9 +377,8 @@ virInterfaceObjListCloneCb(void *payload, goto error; VIR_FREE(xml); =20 - if (!(obj =3D virInterfaceObjListAssignDef(data->dest, backup))) + if (!(obj =3D virInterfaceObjListAssignDef(data->dest, &backup))) goto error; - backup =3D NULL; virInterfaceObjEndAPI(&obj); =20 virObjectUnlock(srcObj); @@ -420,25 +419,39 @@ virInterfaceObjListClone(virInterfaceObjList *interfa= ces) } =20 =20 +/** + * virInterfaceObjListAssignDef: + * @interfaces: virInterface object list + * @def: new definition + * + * Assigns new definition to either an existing or newly created + * virInterface object. Upon successful return the virInterface + * object is the owner of @def and callers should use + * virInterfaceObjGetDef() if they need to access the definition + * as @def is set to NULL. + * + * Returns: a virInterface object instance on success, or + * NULL on error. + */ virInterfaceObj * virInterfaceObjListAssignDef(virInterfaceObjList *interfaces, - virInterfaceDef *def) + virInterfaceDef **def) { virInterfaceObj *obj; =20 virObjectRWLockWrite(interfaces); - if ((obj =3D virInterfaceObjListFindByNameLocked(interfaces, def->name= ))) { + if ((obj =3D virInterfaceObjListFindByNameLocked(interfaces, (*def)->n= ame))) { virInterfaceDefFree(obj->def); } else { if (!(obj =3D virInterfaceObjNew())) goto error; =20 - if (virHashAddEntry(interfaces->objsName, def->name, obj) < 0) + if (virHashAddEntry(interfaces->objsName, (*def)->name, obj) < 0) goto error; virObjectRef(obj); } =20 - obj->def =3D def; + obj->def =3D g_steal_pointer(def); virObjectRWUnlock(interfaces); =20 return obj; diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index d60faa95f2..5927484167 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -59,7 +59,7 @@ virInterfaceObjListClone(virInterfaceObjList *interfaces); =20 virInterfaceObj * virInterfaceObjListAssignDef(virInterfaceObjList *interfaces, - virInterfaceDef *def); + virInterfaceDef **def); =20 void virInterfaceObjListRemove(virInterfaceObjList *interfaces, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e45748c5fc..92c0462170 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1141,9 +1141,8 @@ testParseInterfaces(testDriver *privconn, if (!def) return -1; =20 - if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def))) + if (!(obj =3D virInterfaceObjListAssignDef(privconn->ifaces, &def)= )) return -1; - def =3D NULL; =20 virInterfaceObjSetActive(obj, true); virInterfaceObjEndAPI(&obj); @@ -6203,9 +6202,8 @@ testInterfaceDefineXML(virConnectPtr conn, if ((def =3D virInterfaceDefParseString(xmlStr, flags)) =3D=3D NULL) goto cleanup; =20 - if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, def)) =3D= =3D NULL) + if ((obj =3D virInterfaceObjListAssignDef(privconn->ifaces, &def)) =3D= =3D NULL) goto cleanup; - def =3D NULL; objdef =3D virInterfaceObjGetDef(obj); =20 ret =3D virGetInterface(conn, objdef->name, objdef->mac); --=20 2.32.0 From nobody Fri Mar 29 02:22:25 2024 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=1637687405; cv=none; d=zohomail.com; s=zohoarc; b=YjFI3EfMRgaC2P/6CCktlOkzlYPbcJbkYXCNUkVTUEb0e1gbe/o/4mpjZP7VO30w0bwn3nfk6ogfxaNbKaRhXArmJF7kbxbKA2ENM9xYT87DNTTuAAJcEzN/2HFJqp/VYn3wSXEm/8lgmkouIHyEZGEq3/gYfxTSk+P7URS6N1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687405; 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=9/3I0ANb2+pGkdf1NnxmDLg2cNbYwRQ3BCX30+/3h74=; b=CKk/p2lGZN12lxI1dp4O9h4iKH33kW5AnVCRNzQfjUGJAOSsN3U28pePy528LHlQ+ybSqEY1/7YQlZcJFDxGqIITs16iy+Raf2WEa4z0d5cvvygEzSttcsJ43hd1DXUwgSuIUABw6p10aLpju+FSM4Ah4xJWNfNeM9m06tSWT+Y= 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 1637687405792188.51835736950318; Tue, 23 Nov 2021 09:10:05 -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-361-skao-aknMdaYVk3yM4Ey9g-1; Tue, 23 Nov 2021 12:10:01 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E63D8799F1; Tue, 23 Nov 2021 17:09:55 +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 5C37219D9F; Tue, 23 Nov 2021 17:09:55 +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 1490E1809C81; Tue, 23 Nov 2021 17:09:54 +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 1ANH9qMt023136 for ; Tue, 23 Nov 2021 12:09:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id C8EB95FC25; Tue, 23 Nov 2021 17:09:52 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AF8B5C1D5; 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=1637687404; 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=9/3I0ANb2+pGkdf1NnxmDLg2cNbYwRQ3BCX30+/3h74=; b=Kx01H9/zXt8PWRviBOwuABM4QSdl7PUSGfdoz1np5ikDu9PoGHSAY4V/BFEPWggapma0fG VC0USpa/6c3aaYXiIH0IQyuqC7ESUyJV3Cmc9HDctK1JwGQceANoIdqYTrt9dFfcXDOatg CBeEAYD82OdJyjCbrOmiffbYVvNiyjE= X-MC-Unique: skao-aknMdaYVk3yM4Ey9g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/4] virSecretObjListAdd: Transfer definition ownership Date: Tue, 23 Nov 2021 18:09:38 +0100 Message-Id: <0c6c7a3a5b10789689da22bc74cddbf70242cc91.1637686811.git.mprivozn@redhat.com> 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.84 on 10.5.11.23 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: 1637687406564100003 Content-Type: text/plain; charset="utf-8" Upon successful return from virSecretObjListAdd() the virSecretObj 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 Reviewed-by: Martin Kletzander --- src/conf/virsecretobj.c | 26 ++++++++++++++------------ src/conf/virsecretobj.h | 2 +- src/secret/secret_driver.c | 4 ++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 212cfe103c..3fbee6f6ec 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -313,13 +313,16 @@ virSecretObjListRemove(virSecretObjList *secrets, * @configDir: directory to place secret config files * @oldDef: Former secret def (e.g. a reload path perhaps) * - * Add the new @newdef to the secret obj table hash + * Add the new @newdef to the secret obj table hash. Upon + * successful the virSecret object is the owner of @newdef and + * callers should use virSecretObjGetDef() if they need to access + * the definition as @newdef is set to NULL. * * Returns: locked and ref'd secret or NULL if failure to add */ virSecretObj * virSecretObjListAdd(virSecretObjList *secrets, - virSecretDef *newdef, + virSecretDef **newdef, const char *configDir, virSecretDef **oldDef) { @@ -333,14 +336,14 @@ virSecretObjListAdd(virSecretObjList *secrets, if (oldDef) *oldDef =3D NULL; =20 - virUUIDFormat(newdef->uuid, uuidstr); + virUUIDFormat((*newdef)->uuid, uuidstr); =20 /* Is there a secret already matching this UUID */ if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, uuidstr))) { virObjectLock(obj); objdef =3D obj->def; =20 - if (STRNEQ_NULLABLE(objdef->usage_id, newdef->usage_id)) { + if (STRNEQ_NULLABLE(objdef->usage_id, (*newdef)->usage_id)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), @@ -348,7 +351,7 @@ virSecretObjListAdd(virSecretObjList *secrets, goto cleanup; } =20 - if (objdef->isprivate && !newdef->isprivate) { + if (objdef->isprivate && !(*newdef)->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); goto cleanup; @@ -358,20 +361,20 @@ virSecretObjListAdd(virSecretObjList *secrets, *oldDef =3D objdef; else virSecretDefFree(objdef); - obj->def =3D newdef; + obj->def =3D g_steal_pointer(newdef); } else { /* No existing secret with same UUID, * try look for matching usage instead */ if ((obj =3D virSecretObjListFindByUsageLocked(secrets, - newdef->usage_type, - newdef->usage_id))) { + (*newdef)->usage_type, + (*newdef)->usage_id))= ) { virObjectLock(obj); objdef =3D obj->def; virUUIDFormat(objdef->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s already defined for " "use with %s"), - uuidstr, newdef->usage_id); + uuidstr, (*newdef)->usage_id); goto cleanup; } =20 @@ -388,7 +391,7 @@ virSecretObjListAdd(virSecretObjList *secrets, if (virHashAddEntry(secrets->objs, uuidstr, obj) < 0) goto cleanup; =20 - obj->def =3D newdef; + obj->def =3D g_steal_pointer(newdef); virObjectRef(obj); } =20 @@ -874,9 +877,8 @@ virSecretLoad(virSecretObjList *secrets, if (virSecretLoadValidateUUID(def, file) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(secrets, def, configDir, NULL))) + if (!(obj =3D virSecretObjListAdd(secrets, &def, configDir, NULL))) goto cleanup; - def =3D NULL; =20 if (virSecretLoadValue(obj) < 0) { virSecretObjListRemove(secrets, obj); diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index e91b9518eb..93b4a46acf 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -50,7 +50,7 @@ virSecretObjListRemove(virSecretObjList *secrets, =20 virSecretObj * virSecretObjListAdd(virSecretObjList *secrets, - virSecretDef *newdef, + virSecretDef **newdef, const char *configDir, virSecretDef **oldDef); =20 diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 43aeae9568..de635bba3a 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -228,10 +228,10 @@ secretDefineXML(virConnectPtr conn, if (virSecretDefineXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(obj =3D virSecretObjListAdd(driver->secrets, def, + if (!(obj =3D virSecretObjListAdd(driver->secrets, &def, driver->configDir, &backup))) goto cleanup; - objDef =3D g_steal_pointer(&def); + objDef =3D virSecretObjGetDef(obj); =20 if (!objDef->isephemeral) { if (backup && backup->isephemeral) { --=20 2.32.0 From nobody Fri Mar 29 02:22:25 2024 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 Reviewed-by: Martin Kletzander --- 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 From nobody Fri Mar 29 02:22:25 2024 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=1637687417; cv=none; d=zohomail.com; s=zohoarc; b=RY74/bjRkpn+R/KS0Ib8vhgyh8asSoCUbknhvi1dhDHXwklcl5LXAh8CgaWmAjQ7GtrrIB12tvLvWSjauog5K8DCTWYA3fphNPvNtjOA7S23DoEc1V/F5BUvyHTROxPhm8JmgkrBER/j4bomfaxSVmUHbnqqQhLx0H+hboRIfgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637687417; 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=ucR8/GnLg4PIAMYZlxOhS4ueX3XDtnzbvfM96PJ/7Z4=; b=JVAJqKGuhUHLvS3Tg1vqnFI3gY4H2ukjP12d5JF13M4PUuNFAOw5460BIRFMaFiNjIQ29NtW35UD3qA2FWpwcN7rUacky6w4eut/aT9/rIBKSzPWKqBsGTXeeuH6+/HeXH3LZr9uQ5WOL7noaZfAgTFJIU7ou3UPp0z5w80IOYQ= 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 1637687417493323.8367363856065; Tue, 23 Nov 2021 09:10:17 -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-180-X6BbOuIsMF6fu2QkRwVKxA-1; Tue, 23 Nov 2021 12:10:12 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B9FB1DDFD; Tue, 23 Nov 2021 17:10:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC11929403; Tue, 23 Nov 2021 17:10:06 +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 B2EDF4EA38; Tue, 23 Nov 2021 17:10:06 +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 1ANH9tZK023153 for ; Tue, 23 Nov 2021 12:09:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id 10EE25C1D5; Tue, 23 Nov 2021 17:09:55 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A8FB5C232; Tue, 23 Nov 2021 17:09:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637687416; 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=ucR8/GnLg4PIAMYZlxOhS4ueX3XDtnzbvfM96PJ/7Z4=; b=cDqP3/nHi0R9rMb/WwBWgXXjJMsYbaf+a2pfNjXq/xXg29oljX+bPNoabHaOCR4gKzZ22Z bv1ir/ty+uytEZXpBnKevBDDonKe6B9b/0hH+ldZ5RNemYIONDWw6SG463pioxdSGHy6ct gS3m2M6Pwpopk/0yFJZChmX/fRRY1x8= X-MC-Unique: X6BbOuIsMF6fu2QkRwVKxA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/4] virDomainObjListAdd: Transfer definition ownership Date: Tue, 23 Nov 2021 18:09:40 +0100 Message-Id: <4c2c3fa06b76b436d6112963927017760e15c89f.1637686811.git.mprivozn@redhat.com> 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.14 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: 1637687418579100001 Content-Type: text/plain; charset="utf-8" Upon successful return from virDomainObjListAdd() the virDomainObj 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 Reviewed-by: Martin Kletzander --- src/bhyve/bhyve_driver.c | 6 ++---- src/ch/ch_driver.c | 7 ++----- src/conf/domain_conf.c | 8 ++++---- src/conf/domain_conf.h | 2 +- src/conf/virdomainobjlist.c | 22 +++++++++++++--------- src/conf/virdomainobjlist.h | 2 +- src/libxl/libxl_domain.c | 3 +-- src/libxl/libxl_driver.c | 30 ++++++++++-------------------- src/libxl/libxl_migration.c | 6 ++---- src/lxc/lxc_driver.c | 24 ++++++++---------------- src/openvz/openvz_conf.c | 3 +-- src/openvz/openvz_driver.c | 10 ++++------ src/qemu/qemu_driver.c | 30 ++++++++++-------------------- src/qemu/qemu_migration.c | 3 +-- src/qemu/qemu_snapshot.c | 9 +++------ src/test/test_driver.c | 17 +++++++---------- src/vmware/vmware_conf.c | 6 ++---- src/vmware/vmware_driver.c | 10 ++++------ 18 files changed, 76 insertions(+), 122 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 516490f6cd..eccf9b44a8 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -533,11 +533,10 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const c= har *xml, unsigned int flag if (bhyveDomainAssignAddresses(def, NULL) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(privconn->domains, def, + if (!(vm =3D virDomainObjListAdd(privconn->domains, &def, privconn->xmlopt, 0, &oldDef))) goto cleanup; - def =3D NULL; vm->persistent =3D 1; =20 if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, @@ -915,12 +914,11 @@ bhyveDomainCreateXML(virConnectPtr conn, if (bhyveDomainAssignAddresses(def, NULL) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(privconn->domains, def, + if (!(vm =3D virDomainObjListAdd(privconn->domains, &def, privconn->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NUL= L))) goto cleanup; - def =3D NULL; =20 if (virBhyveProcessStart(conn, vm, VIR_DOMAIN_RUNNING_BOOTED, diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 9eaf3ee499..464bcef907 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -237,15 +237,13 @@ chDomainCreateXML(virConnectPtr conn, goto cleanup; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, - vmdef, + &vmdef, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; =20 - vmdef =3D NULL; - if (virCHDomainObjBeginJob(vm, CH_JOB_MODIFY) < 0) goto cleanup; =20 @@ -323,12 +321,11 @@ chDomainDefineXMLFlags(virConnectPtr conn, const char= *xml, unsigned int flags) if (virDomainDefineXMLFlagsEnsureACL(conn, vmdef) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, + if (!(vm =3D virDomainObjListAdd(driver->domains, &vmdef, driver->xmlopt, 0, NULL))) goto cleanup; =20 - vmdef =3D NULL; vm->persistent =3D 1; =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 552d43b845..9b04071259 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3865,7 +3865,7 @@ virDomainDefNew(virDomainXMLOption *xmlopt) =20 =20 void virDomainObjAssignDef(virDomainObj *domain, - virDomainDef *def, + virDomainDef **def, bool live, virDomainDef **oldDef) { @@ -3876,7 +3876,7 @@ void virDomainObjAssignDef(virDomainObj *domain, *oldDef =3D domain->newDef; else virDomainDefFree(domain->newDef); - domain->newDef =3D def; + domain->newDef =3D g_steal_pointer(def); } else { if (live) { /* save current configuration to be restored on domain shutdow= n */ @@ -3884,13 +3884,13 @@ void virDomainObjAssignDef(virDomainObj *domain, domain->newDef =3D domain->def; else virDomainDefFree(domain->def); - domain->def =3D def; + domain->def =3D g_steal_pointer(def); } else { if (oldDef) *oldDef =3D domain->def; else virDomainDefFree(domain->def); - domain->def =3D def; + domain->def =3D g_steal_pointer(def); } } } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8634960313..c4a8dcc2ea 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3388,7 +3388,7 @@ virDomainNetDefNew(virDomainXMLOption *xmlopt); virDomainDef *virDomainDefNew(virDomainXMLOption *xmlopt); =20 void virDomainObjAssignDef(virDomainObj *domain, - virDomainDef *def, + virDomainDef **def, bool live, virDomainDef **oldDef); int virDomainObjSetDefTransient(virDomainXMLOption *xmlopt, diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index ff6c4c1b4f..063c63cd30 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -257,13 +257,17 @@ virDomainObjListAddObjLocked(virDomainObjList *doms, * the @def being added is assumed to represent a * live config, not a future inactive config * + * Upon successful return the virDomain object is the owner of + * @def and callers should use @vm->def if they need to access + * the definition as @def is set to NULL. + * * The returned @vm from this function will be locked and ref * counted. The caller is expected to use virDomainObjEndAPI * when it completes usage. */ static virDomainObj * virDomainObjListAddLocked(virDomainObjList *doms, - virDomainDef *def, + virDomainDef **def, virDomainXMLOption *xmlopt, unsigned int flags, virDomainDef **oldDef) @@ -275,13 +279,13 @@ virDomainObjListAddLocked(virDomainObjList *doms, *oldDef =3D NULL; =20 /* See if a VM with matching UUID already exists */ - if ((vm =3D virDomainObjListFindByUUIDLocked(doms, def->uuid))) { + if ((vm =3D virDomainObjListFindByUUIDLocked(doms, (*def)->uuid))) { if (vm->removing) { virReportError(VIR_ERR_OPERATION_FAILED, _("domain '%s' is already being removed"), vm->def->name); goto error; - } else if (STRNEQ(vm->def->name, def->name)) { + } else if (STRNEQ(vm->def->name, (*def)->name)) { /* UUID matches, but if names don't match, refuse it */ virUUIDFormat(vm->def->uuid, uuidstr); virReportError(VIR_ERR_OPERATION_FAILED, @@ -312,20 +316,20 @@ virDomainObjListAddLocked(virDomainObjList *doms, oldDef); } else { /* UUID does not match, but if a name matches, refuse it */ - if ((vm =3D virDomainObjListFindByNameLocked(doms, def->name))) { + if ((vm =3D virDomainObjListFindByNameLocked(doms, (*def)->name)))= { virUUIDFormat(vm->def->uuid, uuidstr); virReportError(VIR_ERR_OPERATION_FAILED, _("domain '%s' already exists with uuid %s"), - def->name, uuidstr); + (*def)->name, uuidstr); goto error; } =20 if (!(vm =3D virDomainObjNew(xmlopt))) goto error; - vm->def =3D def; + vm->def =3D g_steal_pointer(def); =20 if (virDomainObjListAddObjLocked(doms, vm) < 0) { - vm->def =3D NULL; + *def =3D g_steal_pointer(&vm->def); goto error; } } @@ -340,7 +344,7 @@ virDomainObjListAddLocked(virDomainObjList *doms, =20 virDomainObj * virDomainObjListAdd(virDomainObjList *doms, - virDomainDef *def, + virDomainDef **def, virDomainXMLOption *xmlopt, unsigned int flags, virDomainDef **oldDef) @@ -498,7 +502,7 @@ virDomainObjListLoadConfig(virDomainObjList *doms, if ((autostart =3D virFileLinkPointsTo(autostartLink, configFile)) < 0) goto error; =20 - if (!(dom =3D virDomainObjListAddLocked(doms, def, xmlopt, 0, &oldDef)= )) + if (!(dom =3D virDomainObjListAddLocked(doms, &def, xmlopt, 0, &oldDef= ))) goto error; =20 dom->autostart =3D autostart; diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index 7b4e34b951..4169eb4f78 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -40,7 +40,7 @@ enum { VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE =3D (1 << 1), }; virDomainObj *virDomainObjListAdd(virDomainObjList *doms, - virDomainDef *def, + virDomainDef **def, virDomainXMLOption *xmlopt, unsigned int flags, virDomainDef **oldDef); diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 4f61584ceb..d9dca370c6 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1482,8 +1482,7 @@ libxlDomainStartNew(libxlDriverPrivate *driver, goto cleanup; } =20 - virDomainObjAssignDef(vm, def, true, NULL); - def =3D NULL; + virDomainObjAssignDef(vm, &def, true, NULL); =20 if (unlink(managed_save_path) < 0) VIR_WARN("Failed to remove the managed state %s", diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 39da10983e..23a28dc124 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -595,13 +595,12 @@ libxlAddDom0(libxlDriverPrivate *driver) if (virUUIDParse("00000000-0000-0000-0000-000000000000", def->uuid= ) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, 0, NULL))) goto cleanup; =20 - def =3D NULL; vm->persistent =3D 1; virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BO= OTED); } @@ -1028,13 +1027,12 @@ libxlDomainCreateXML(virConnectPtr conn, const char= *xml, if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def =3D NULL; =20 if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { if (!vm->persistent) @@ -1948,13 +1946,12 @@ libxlDomainRestoreFlags(virConnectPtr conn, const c= har *from, if (virDomainRestoreFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def =3D NULL; =20 if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { if (!vm->persistent) @@ -2826,12 +2823,11 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const= char *xml, unsigned int flag if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, 0, &oldDef))) goto cleanup; - def =3D NULL; =20 vm->persistent =3D 1; =20 @@ -4143,10 +4139,8 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const= char *xml, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { ret =3D virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); - if (!ret) { - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; - } + if (!ret) + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 endjob: @@ -4234,10 +4228,8 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const= char *xml, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { ret =3D virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); - if (!ret) { - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; - } + if (!ret) + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 endjob: @@ -4319,10 +4311,8 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const= char *xml, /* Finally, if no error until here, we can save config. */ if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) { ret =3D virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); - if (!ret) { - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; - } + if (!ret) + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 cleanup: diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index be5cc7e049..cdd714d6b8 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -548,13 +548,12 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr d= conn, &mig, &xmlout, &taint_hook) < 0) goto error; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, *def, + if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto error; - *def =3D NULL; =20 /* * Unless an error is encountered in this function, the job will @@ -658,13 +657,12 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, &mig, &xmlout, &taint_hook) < 0) goto error; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, *def, + if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto error; - *def =3D NULL; =20 /* * Unless an error is encountered in this function, the job will diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e2720a6f89..3cdf73c69f 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -435,12 +435,11 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const cha= r *xml, unsigned int flags) goto cleanup; } =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, 0, &oldDef))) goto cleanup; =20 - def =3D NULL; vm->persistent =3D 1; =20 if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def, @@ -1118,13 +1117,12 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, } =20 =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def =3D NULL; =20 if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) { if (!vm->persistent) @@ -1917,8 +1915,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, if (rc < 0) goto endjob; =20 - virDomainObjAssignDef(vm, persistentDefCopy, false, NULL); - persistentDefCopy =3D NULL; + virDomainObjAssignDef(vm, &persistentDefCopy, false, NULL); } =20 ret =3D 0; @@ -4368,10 +4365,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr d= om, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { ret =3D virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); - if (!ret) { - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; - } + if (!ret) + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 endjob: @@ -4444,8 +4439,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr do= m, if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) goto endjob; =20 - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; + virDomainObjAssignDef(vm, &vmdef, false, NULL); ret =3D 0; =20 endjob: @@ -4537,10 +4531,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr d= om, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { ret =3D virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); - if (!ret) { - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; - } + if (!ret) + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 endjob: diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 9f879e90eb..e2fbc28abc 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -527,7 +527,7 @@ int openvzLoadDomains(struct openvz_driver *driver) flags |=3D VIR_DOMAIN_OBJ_LIST_ADD_LIVE; =20 if (!(dom =3D virDomainObjListAdd(driver->domains, - def, + &def, driver->xmlopt, flags, NULL))) @@ -547,7 +547,6 @@ int openvzLoadDomains(struct openvz_driver *driver) =20 virDomainObjEndAPI(&dom); dom =3D NULL; - def =3D NULL; } =20 virCommandFree(cmd); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 681eb734ce..d9c71a5722 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -842,11 +842,10 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const = char *xml, unsigned int fla if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, + if (!(vm =3D virDomainObjListAdd(driver->domains, &vmdef, driver->xmlopt, 0, NULL))) goto cleanup; - vmdef =3D NULL; vm->persistent =3D 1; =20 if (openvzSetInitialConfig(vm->def) < 0) { @@ -930,13 +929,13 @@ openvzDomainCreateXML(virConnectPtr conn, const char = *xml, goto cleanup; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, - vmdef, + &vmdef, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - vmdef =3D NULL; + /* All OpenVZ domains seem to be persistent - this is a bit of a viola= tion * of this libvirt API which is intended for transient domain creation= */ vm->persistent =3D 1; @@ -2094,13 +2093,12 @@ openvzDomainMigratePrepare3Params(virConnectPtr dco= nn, VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE= ))) goto error; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto error; - def =3D NULL; =20 if (!uri_in) { if ((my_hostname =3D virGetHostname()) =3D=3D NULL) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d954635dde..503b98228a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1752,13 +1752,12 @@ static virDomainPtr qemuDomainCreateXML(virConnectP= tr conn, if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def =3D NULL; =20 if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START, flags) < 0) { @@ -5972,13 +5971,12 @@ qemuDomainRestoreFlags(virConnectPtr conn, def =3D tmp; } =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def =3D NULL; =20 if (flags & VIR_DOMAIN_SAVE_RUNNING) data->header.was_running =3D 1; @@ -6259,8 +6257,7 @@ qemuDomainObjRestore(virConnectPtr conn, goto cleanup; } =20 - virDomainObjAssignDef(vm, def, true, NULL); - def =3D NULL; + virDomainObjAssignDef(vm, &def, true, NULL); =20 ret =3D qemuSaveImageStartVM(conn, driver, vm, &fd, data, path, start_paused, asyncJob); @@ -6629,11 +6626,10 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, + if (!(vm =3D virDomainObjListAdd(driver->domains, &def, driver->xmlopt, 0, &oldDef))) goto cleanup; - def =3D NULL; =20 if (!oldDef && qemuDomainNamePathsCleanup(cfg, vm->def->name, false) <= 0) goto cleanup; @@ -7958,8 +7954,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm, if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) return -1; =20 - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 return 0; @@ -8095,10 +8090,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr = dom, /* Finally, if no error until here, we can save config. */ if (flags & VIR_DOMAIN_AFFECT_CONFIG) { ret =3D virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir); - if (!ret) { - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; - } + if (!ret) + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 endjob: @@ -8182,8 +8175,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *dr= iver, if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) goto cleanup; =20 - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 ret =3D 0; @@ -8252,8 +8244,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDrive= r *driver, if (vmdef) { if (virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir) < 0) return -1; - virDomainObjAssignDef(vm, vmdef, false, NULL); - vmdef =3D NULL; + virDomainObjAssignDef(vm, &vmdef, false, NULL); } =20 return 0; @@ -9640,8 +9631,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr do= m, if (rc < 0) goto endjob; =20 - virDomainObjAssignDef(vm, persistentDefCopy, false, NULL); - persistentDefCopy =3D NULL; + virDomainObjAssignDef(vm, &persistentDefCopy, false, NULL); } =20 ret =3D 0; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 9729041846..8001792f5a 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2878,13 +2878,12 @@ qemuMigrationDstPrepareAny(virQEMUDriver *driver, QEMU_MIGRATION_COOKIE_BLOCK_DIRTY= _BITMAPS))) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, *def, + if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - *def =3D NULL; =20 priv =3D vm->privateData; jobPriv =3D priv->job.privateData; diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 7a1c2097cb..661aeeb8aa 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1984,13 +1984,11 @@ qemuSnapshotRevert(virDomainObj *vm, } =20 if (inactiveConfig) { - virDomainObjAssignDef(vm, inactiveConfig, false, NULL); - inactiveConfig =3D NULL; + virDomainObjAssignDef(vm, &inactiveConfig, false, NULL); defined =3D true; } =20 - virDomainObjAssignDef(vm, config, true, NULL); - config =3D NULL; + virDomainObjAssignDef(vm, &config, true, NULL); =20 /* No cookie means libvirt which saved the domain was too old to * mess up the CPU definitions. @@ -2065,8 +2063,7 @@ qemuSnapshotRevert(virDomainObj *vm, } =20 if (inactiveConfig) { - virDomainObjAssignDef(vm, inactiveConfig, false, NULL); - inactiveConfig =3D NULL; + virDomainObjAssignDef(vm, &inactiveConfig, false, NULL); defined =3D true; } =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 369edacf29..b6bca884f0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1043,7 +1043,7 @@ testParseDomains(testDriver *privconn, =20 if (testDomainGenerateIfnames(def) < 0 || !(obj =3D virDomainObjListAdd(privconn->domains, - def, + &def, privconn->xmlopt, 0, NULL))) { virDomainDefFree(def); @@ -1053,7 +1053,7 @@ testParseDomains(testDriver *privconn, if (testParseDomainSnapshots(privconn, obj, file, ctxt) < 0) goto error; =20 - nsdata =3D def->namespaceData; + nsdata =3D obj->def->namespaceData; obj->persistent =3D !nsdata->transient; obj->hasManagedSave =3D nsdata->hasManagedSave; =20 @@ -1768,13 +1768,12 @@ testDomainCreateXML(virConnectPtr conn, const char = *xml, if (testDomainGenerateIfnames(def) < 0) goto cleanup; if (!(dom =3D virDomainObjListAdd(privconn->domains, - def, + &def, privconn->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def =3D NULL; =20 if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_BOOTED) < 0= ) { if (!dom->persistent) @@ -2517,13 +2516,12 @@ testDomainRestoreFlags(virConnectPtr conn, if (testDomainGenerateIfnames(def) < 0) goto cleanup; if (!(dom =3D virDomainObjListAdd(privconn->domains, - def, + &def, privconn->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def =3D NULL; =20 if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_RESTORED) <= 0) { if (!dom->persistent) @@ -4208,12 +4206,11 @@ static virDomainPtr testDomainDefineXMLFlags(virCon= nectPtr conn, if (testDomainGenerateIfnames(def) < 0) goto cleanup; if (!(dom =3D virDomainObjListAdd(privconn->domains, - def, + &def, privconn->xmlopt, 0, &oldDef))) goto cleanup; - def =3D NULL; dom->persistent =3D 1; =20 event =3D virDomainEventLifecycleNewFromObj(dom, @@ -9065,7 +9062,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snaps= hot, virObjectEventStateQueue(privconn->eventState, event); } =20 - virDomainObjAssignDef(vm, config, false, NULL); + virDomainObjAssignDef(vm, &config, false, NULL); if (testDomainStartState(privconn, vm, VIR_DOMAIN_RUNNING_FROM_SNAPSHOT) < 0) goto cleanup; @@ -9086,7 +9083,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snaps= hot, } } else { /* Transitions 1, 4, 7 */ - virDomainObjAssignDef(vm, config, false, NULL); + virDomainObjAssignDef(vm, &config, false, NULL); =20 if (virDomainObjIsActive(vm)) { /* Transitions 4, 7 */ diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 811507cd55..ab03617d95 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -156,7 +156,7 @@ vmwareLoadDomains(struct vmware_driver *driver) goto cleanup; } =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, + if (!(vm =3D virDomainObjListAdd(driver->domains, &vmdef, driver->xmlopt, 0, NULL))) goto cleanup; @@ -165,7 +165,7 @@ vmwareLoadDomains(struct vmware_driver *driver) =20 pDomain->vmxPath =3D g_strdup(vmxPath); =20 - vmwareDomainConfigDisplay(pDomain, vmdef); + vmwareDomainConfigDisplay(pDomain, vm->def); =20 if ((vm->def->id =3D vmwareExtractPid(vmxPath)) < 0) goto cleanup; @@ -175,8 +175,6 @@ vmwareLoadDomains(struct vmware_driver *driver) vm->persistent =3D 1; =20 virDomainObjEndAPI(&vm); - - vmdef =3D NULL; } =20 ret =3D 0; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 3bd6d4d440..e6843ee745 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -438,7 +438,7 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int fla =20 /* assign def */ if (!(vm =3D virDomainObjListAdd(driver->domains, - vmdef, + &vmdef, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -447,9 +447,8 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int fla pDomain =3D vm->privateData; pDomain->vmxPath =3D g_strdup(vmxPath); =20 - vmwareDomainConfigDisplay(pDomain, vmdef); + vmwareDomainConfigDisplay(pDomain, vm->def); =20 - vmdef =3D NULL; vm->persistent =3D 1; =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, -1); @@ -689,7 +688,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *x= ml, =20 /* assign def */ if (!(vm =3D virDomainObjListAdd(driver->domains, - vmdef, + &vmdef, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, @@ -699,8 +698,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *x= ml, pDomain =3D vm->privateData; pDomain->vmxPath =3D g_strdup(vmxPath); =20 - vmwareDomainConfigDisplay(pDomain, vmdef); - vmdef =3D NULL; + vmwareDomainConfigDisplay(pDomain, vm->def); =20 if (vmwareStartVM(driver, vm) < 0) { if (!vm->persistent) --=20 2.32.0