From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725898; cv=none; d=zoho.com; s=zohoarc; b=VclGEJkwtr94si9IlzMLabLNYZsGnowkJXCTtPdKVqpYfek/Pt8bDnRYMjVhddrhEC+4Dd9kV1BuMfMpyIYA6vpDjNbt2fcELg3jroBDuhOOQG+SwDJ+cIfouSURQlceCkhyzjKJ9UNBBtYM2UwuNUBo1XRM9CJmU4UyykHs5Y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725898; 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:ARC-Authentication-Results; bh=Msr57q4J7HhE3JMpDd3BeUjBD333phM9YewdGydhdoA=; b=X7PKuJ+KVcRDKLRBwRQ4O5XFFmCF9ohsO5Fr56+a7LpkVSqGDZvrGJXfoKK1+g8ohkU0OvFkTGy/SjCwv2H3uRxVzhQftBGkrWnoC63suHfA3XZYLiW8mPNmPtlZTkLL2ay88RC4Sc7bBs1CJprVRmFk+WhBEgKn7LCO9K3xolA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725898091553.7842837326358; Wed, 5 Jun 2019 02:11:38 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4927E3162903; Wed, 5 Jun 2019 09:11:08 +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 CF0C55D9D6; Wed, 5 Jun 2019 09:11: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 31C76206D4; Wed, 5 Jun 2019 09:10:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599SoS005922 for ; Wed, 5 Jun 2019 05:09:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2734618ED0; Wed, 5 Jun 2019 09:09:28 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E17B60A35; Wed, 5 Jun 2019 09:09:27 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:09 +0200 Message-Id: <8ec891850b7effea4cbf801c205dcec6f05e7809.1559725591.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 01/11] virDomainObjListAddObjLocked: Don't expect vm->def to be set 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 05 Jun 2019 09:11:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In near future vm->def might be not set when calling this function. Therefore, have caller explicitly state what UUID and name the domain object should be stored under. Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/conf/virdomainobjlist.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index d58d25f847..28cccd0035 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -223,6 +223,8 @@ virDomainObjListFindByName(virDomainObjListPtr doms, /** * @doms: Domain object list pointer * @vm: Domain object to be added + * @uuid: domain UUID + * @name: domain name * * Upon entry @vm should have at least 1 ref and be locked. * @@ -238,16 +240,18 @@ virDomainObjListFindByName(virDomainObjListPtr doms, */ static int virDomainObjListAddObjLocked(virDomainObjListPtr doms, - virDomainObjPtr vm) + virDomainObjPtr vm, + const unsigned char *uuid, + const char *name) { char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - virUUIDFormat(vm->def->uuid, uuidstr); + virUUIDFormat(uuid, uuidstr); if (virHashAddEntry(doms->objs, uuidstr, vm) < 0) return -1; virObjectRef(vm); =20 - if (virHashAddEntry(doms->objsName, vm->def->name, vm) < 0) { + if (virHashAddEntry(doms->objsName, name, vm) < 0) { virHashRemoveEntry(doms->objs, uuidstr); return -1; } @@ -335,7 +339,7 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, goto error; vm->def =3D def; =20 - if (virDomainObjListAddObjLocked(doms, vm) < 0) { + if (virDomainObjListAddObjLocked(doms, vm, def->uuid, def->name) <= 0) { vm->def =3D NULL; goto error; } @@ -564,7 +568,7 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms, goto error; } =20 - if (virDomainObjListAddObjLocked(doms, obj) < 0) + if (virDomainObjListAddObjLocked(doms, obj, obj->def->uuid, obj->def->= name) < 0) goto error; =20 if (notify) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725949; cv=none; d=zoho.com; s=zohoarc; b=MhkbPdndu7Qagh0uX3H3Uzn3y0mnMBaRVHqA21c0vW7N3dzhBRHtLsLEvwATymesPyXPnauOZhA0y7q+GbkuX1LUEoerPSlx5qIQEobfYZ8tbag9b3EnKzsrxkaeeEXH4tpHFfBoofxALuyFkVNk5LroC4kI8fv8a75whh5YEig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725949; 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:ARC-Authentication-Results; bh=MDf9snix+DTAakIVJwVNodZYM/xuAN95XaaFC7fJeZ4=; b=GOwfeuuyx1f4DNsN+WHhkUYgSvaKQMPqpC4LnLWvJF4as/qHfUG0E1DyetHDtjca/GFMgxJlUqRzi/pnC5bdJWSkCoL+ODVcDSOAJmWxzf+xDFPJILMnjVIzPc1WSiihDvoaTLC1sbWKG5tVtdGTmSvYtqWd2TaLJjdd61MHJWE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725949911206.5199063969162; Wed, 5 Jun 2019 02:12:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B121930C1214; Wed, 5 Jun 2019 09:12:12 +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 809AF600CC; Wed, 5 Jun 2019 09:12:09 +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 3F2691806B15; Wed, 5 Jun 2019 09:12:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599Tej005930 for ; Wed, 5 Jun 2019 05:09:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1B8A518ED0; Wed, 5 Jun 2019 09:09:29 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72D3A60A35; Wed, 5 Jun 2019 09:09:28 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:10 +0200 Message-Id: <2e172018b54ae434d03723e53972010a2f540007.1559725591.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 02/11] virDomainObjListAddLocked: Set vm->def only in success path 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 05 Jun 2019 09:12:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Because of past limitation of virDomainObjListAddObjLocked() we had to set vm->def even before the object was on the domains list. Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/conf/virdomainobjlist.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 28cccd0035..1086aec421 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -337,12 +337,11 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, =20 if (!(vm =3D virDomainObjNew(xmlopt))) goto error; + + if (virDomainObjListAddObjLocked(doms, vm, def->uuid, def->name) <= 0) + goto error; + vm->def =3D def; - - if (virDomainObjListAddObjLocked(doms, vm, def->uuid, def->name) <= 0) { - vm->def =3D NULL; - goto error; - } } =20 return vm; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725941; cv=none; d=zoho.com; s=zohoarc; b=U6s7Y2w7XrVe2Ve9b/XKRAzl6hQBG8hZgQ/7XBv8nW5xqndXHDQutuYi2qMVzGuQA1vfJy16zRchO4623G3Za4qEpw/iZVyQ6+6/GlECa+l1q8KxX+IPPudhwIq1uFf3s6j17q6kYOD7eVTVAwzOGOucP+DKh7RImZ35OFVWJhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725941; 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:ARC-Authentication-Results; bh=nHS2j2Q4NbhRrlIT2GBFh3hVhaF0KyLZSjZvMvM9bNU=; b=TCioES7bjOnlDNOseuu0TJUQn2TEsvlu8F1OzUV2Q8VaNsnerWs+9/UY5dn4rDWe2SCVIKslcHRrdyYhMnFyioetPByZcIgrdDmL+U8nMs/KdOJdQ2+KU8B8Vq1wlzjIM7LVYaNOxqtCfYOA2cTwjt8tfQ790+uHd6G9IASZJJ0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725941888654.7275671474631; Wed, 5 Jun 2019 02:12:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1E503078ABD; Wed, 5 Jun 2019 09:12:14 +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 920BE5D6A9; Wed, 5 Jun 2019 09:12:11 +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 538A41806B19; Wed, 5 Jun 2019 09:12:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599U0I005937 for ; Wed, 5 Jun 2019 05:09:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1052360A35; Wed, 5 Jun 2019 09:09:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6799B5F7C0; Wed, 5 Jun 2019 09:09:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:11 +0200 Message-Id: <94b06d78fe21de7f7793879089a6570b5029ad6d.1559725591.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 03/11] virDomainObjIsActive: Allow vm->def to be NULL 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 05 Jun 2019 09:12:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/conf/domain_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4c3ab07062..92c734e13d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2767,7 +2767,7 @@ int virDomainDefValidate(virDomainDefPtr def, static inline bool virDomainObjIsActive(virDomainObjPtr dom) { - return dom->def->id !=3D -1; + return dom->def && dom->def->id !=3D -1; } =20 int virDomainObjCheckActive(virDomainObjPtr dom); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725885; cv=none; d=zoho.com; s=zohoarc; b=YJuFEtPKgYE+N0SmzYsxx/BsY+77ROv7UQSYD6VP+1AtaEEcBob7ymX804Qgepdb8B/o9yCLPHmmSZDsE9+JMXfCsAVgEP8foPypRJGF9XwWn0drgd+cDou3e4O5aeSUoid1bczE9o6JlkhFNWl3TIIpexEkn8TdKA+DFiMRq/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725885; 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:ARC-Authentication-Results; bh=f9L/bGXTgu7l9RNeXkSf6dwC7fQr7YJ2ezHBNT+Ol5s=; b=Z6Jgwhwok5/lV9nEeWQ9/iKTXFlg4Ca7rxOyLHkubW/8c2SzCKPZPmXDHcU7Y16KqWYRRHntjVeCttxla8FV9xgp4vDknuWkxKdzKuvvAj9csKzfGiYOp1LKHBdi2imH9buDaZDlNAHrKUP9P6gNvMYSKuV5ij5K8zFy1GcRPn0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15597258858371.3829591016557288; Wed, 5 Jun 2019 02:11:25 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 6ADBC300BEB4; Wed, 5 Jun 2019 09:10:45 +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 C67F75D9E5; Wed, 5 Jun 2019 09:10:32 +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 07408206D2; Wed, 5 Jun 2019 09:10:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599VYi005942 for ; Wed, 5 Jun 2019 05:09:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2CFF260A35; Wed, 5 Jun 2019 09:09:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BBAD5F7C0; Wed, 5 Jun 2019 09:09:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:12 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 04/11] virDomainObjListAdd: Leave def assigning as an exercise for caller 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 05 Jun 2019 09:11:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Some driver have concept of jobs (e.g. qemu, lxc, libxl and vz). This means that whenever something wants to modify a domain object it needs to acquire job (to mutually exclude with other threads trying to modify the same object). And aforementioned drivers do that more or less successfully. Except for virDomainObjListAdd() which may modify the domain object without acquiring job. This is harmful because if a thread that's executing say an API in qemu driver unlock a domain object and locks it again the object has changed even though the thread acquired job before. Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/bhyve/bhyve_driver.c | 10 ++++++---- src/conf/virdomainobjlist.c | 29 +++++++---------------------- src/conf/virdomainobjlist.h | 3 +-- src/libxl/libxl_driver.c | 22 ++++++++++++---------- src/libxl/libxl_migration.c | 12 ++++++------ src/lxc/lxc_driver.c | 10 +++++----- src/openvz/openvz_conf.c | 12 ++++++------ src/openvz/openvz_driver.c | 17 +++++++++-------- src/qemu/qemu_driver.c | 22 +++++++++++----------- src/qemu/qemu_migration.c | 6 +++--- src/test/test_driver.c | 21 ++++++++++++--------- src/vmware/vmware_conf.c | 4 ++-- src/vmware/vmware_driver.c | 9 ++++----- src/vz/vz_sdk.c | 4 +++- 14 files changed, 87 insertions(+), 94 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 061888ab0b..23b916406a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -540,9 +540,10 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int flag goto cleanup; =20 if (!(vm =3D virDomainObjListAdd(privconn->domains, def, - privconn->xmlopt, - 0, &oldDef))) + privconn->xmlopt, 0))) goto cleanup; + + virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; vm->persistent =3D 1; =20 @@ -941,9 +942,10 @@ bhyveDomainCreateXML(virConnectPtr conn, =20 if (!(vm =3D virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NUL= L))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (virBhyveProcessStart(conn, privconn, vm, diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 1086aec421..e2b829b91c 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -265,12 +265,7 @@ virDomainObjListAddObjLocked(virDomainObjListPtr doms, * virDomainObjListAddLocked: * * If flags & VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE then - * this will refuse updating an existing def if the - * current def is Live - * - * If flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE then - * the @def being added is assumed to represent a - * live config, not a future inactive config + * this will fail if domain is already active or starting up. * * The returned @vm from this function will be locked and ref * counted. The caller is expected to use virDomainObjEndAPI @@ -280,15 +275,11 @@ static virDomainObjPtr virDomainObjListAddLocked(virDomainObjListPtr doms, virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - unsigned int flags, - virDomainDefPtr *oldDef) + unsigned int flags) { virDomainObjPtr vm; char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 - if (oldDef) - *oldDef =3D NULL; - /* See if a VM with matching UUID already exists */ if ((vm =3D virDomainObjListFindByUUIDLocked(doms, def->uuid))) { if (vm->removing) { @@ -320,11 +311,6 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, goto error; } } - - virDomainObjAssignDef(vm, - def, - !!(flags & VIR_DOMAIN_OBJ_LIST_ADD_LIVE), - oldDef); } else { /* UUID does not match, but if a name matches, refuse it */ if ((vm =3D virDomainObjListFindByNameLocked(doms, def->name))) { @@ -340,8 +326,6 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, =20 if (virDomainObjListAddObjLocked(doms, vm, def->uuid, def->name) <= 0) goto error; - - vm->def =3D def; } =20 return vm; @@ -355,13 +339,12 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - unsigned int flags, - virDomainDefPtr *oldDef) + unsigned int flags) { virDomainObjPtr ret; =20 virObjectRWLockWrite(doms); - ret =3D virDomainObjListAddLocked(doms, def, xmlopt, flags, oldDef); + ret =3D virDomainObjListAddLocked(doms, def, xmlopt, flags); virObjectRWUnlock(doms); return ret; } @@ -513,9 +496,11 @@ virDomainObjListLoadConfig(virDomainObjListPtr 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))) goto error; =20 + virDomainObjAssignDef(dom, def, false, &oldDef); + dom->autostart =3D autostart; =20 if (notify) diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index c1ffee76ad..552a7cfaf2 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -44,8 +44,7 @@ enum { virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, virDomainDefPtr def, virDomainXMLOptionPtr xmlopt, - unsigned int flags, - virDomainDefPtr *oldDef); + unsigned int flags); =20 typedef int (*virDomainObjListRenameCallback)(virDomainObjPtr dom, const char *new_name, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2b9c6f1866..809d298ac1 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -603,9 +603,10 @@ libxlAddDom0(libxlDriverPrivatePtr driver) =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - 0, - &oldDef))) + 0))) goto cleanup; + + virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; =20 vm->persistent =3D 1; @@ -1031,10 +1032,10 @@ libxlDomainCreateXML(virConnectPtr conn, const char= *xml, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { @@ -1951,10 +1952,10 @@ libxlDomainRestoreFlags(virConnectPtr conn, const c= har *from, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { @@ -2851,9 +2852,10 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const = char *xml, unsigned int flag =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - 0, - &oldDef))) + 0))) goto cleanup; + + virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; =20 vm->persistent =3D 1; diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 76bcb66a11..35403380d0 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -568,10 +568,10 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr d= conn, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, *def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; + + virDomainObjAssignDef(vm, *def, true, NULL); *def =3D NULL; =20 /* @@ -677,10 +677,10 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, *def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; + + virDomainObjAssignDef(vm, *def, true, NULL); *def =3D NULL; =20 /* diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 9db2a02dee..eaf26563f5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -445,10 +445,10 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const cha= r *xml, unsigned int flags) } =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - 0, &oldDef))) + driver->xmlopt, 0))) goto cleanup; =20 + virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; vm->persistent =3D 1; =20 @@ -1193,10 +1193,10 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) { diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index be5f89ea45..2ee8af067c 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -517,7 +517,8 @@ int openvzLoadDomains(struct openvz_driver *driver) =20 line =3D outbuf; while (line[0] !=3D '\0') { - unsigned int flags =3D 0; + bool active =3D false; + if (virStrToLong_i(line, &status, 10, &veid) < 0 || *status++ !=3D ' ' || (line =3D strchr(status, '\n')) =3D=3D NULL) { @@ -578,17 +579,16 @@ int openvzLoadDomains(struct openvz_driver *driver) openvzReadMemConf(def, veid); =20 virUUIDFormat(def->uuid, uuidstr); - flags =3D VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE; - if (STRNEQ(status, "stopped")) - flags |=3D VIR_DOMAIN_OBJ_LIST_ADD_LIVE; + active =3D STRNEQ(status, "stopped"); =20 if (!(dom =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - flags, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE= ))) goto cleanup; =20 + virDomainObjAssignDef(dom, def, active, NULL); + if (STREQ(status, "stopped")) { virDomainObjSetState(dom, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 39eeb2c12e..6d4f7325b5 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -918,9 +918,10 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const c= har *xml, unsigned int fla goto cleanup; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, - driver->xmlopt, - 0, NULL))) + driver->xmlopt, 0))) goto cleanup; + + virDomainObjAssignDef(vm, vmdef, false, NULL); vmdef =3D NULL; vm->persistent =3D 1; =20 @@ -1007,10 +1008,10 @@ openvzDomainCreateXML(virConnectPtr conn, const cha= r *xml, if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, vmdef, true, NULL); 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= */ @@ -2174,10 +2175,10 @@ openvzDomainMigratePrepare3Params(virConnectPtr dco= nn, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; + + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (!uri_in) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 42b1ce2521..8bbac339e0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1703,10 +1703,10 @@ static virDomainPtr qemuDomainCreateXML(virConnectP= tr conn, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START, @@ -6973,10 +6973,10 @@ qemuDomainRestoreFlags(virConnectPtr conn, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (flags & VIR_DOMAIN_SAVE_RUNNING) @@ -7648,9 +7648,10 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, goto cleanup; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - 0, &oldDef))) + driver->xmlopt, 0))) goto cleanup; + + virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; =20 vm->persistent =3D 1; @@ -16885,11 +16886,10 @@ static virDomainPtr qemuDomainQemuAttach(virConne= ctPtr conn, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; =20 + virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 32b3040473..9e19c923ee 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2405,10 +2405,10 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, =20 if (!(vm =3D virDomainObjListAdd(driver->domains, *def, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(vm, *def, true, NULL); *def =3D NULL; =20 priv =3D vm->privateData; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index cae2521b21..1215deffd3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -913,11 +913,13 @@ testParseDomains(testDriverPtr privconn, !(obj =3D virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, - 0, NULL))) { + 0))) { virDomainDefFree(def); goto error; } =20 + virDomainObjAssignDef(obj, def, false, NULL); + if (testParseDomainSnapshots(privconn, obj, file, ctxt) < 0) goto error; =20 @@ -1620,10 +1622,10 @@ testDomainCreateXML(virConnectPtr conn, const char = *xml, if (!(dom =3D virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(dom, def, true, NULL); def =3D NULL; =20 if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_BOOTED) < 0= ) { @@ -2167,10 +2169,10 @@ testDomainRestoreFlags(virConnectPtr conn, if (!(dom =3D virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; + + virDomainObjAssignDef(dom, def, true, NULL); def =3D NULL; =20 if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_RESTORED) <= 0) { @@ -2746,9 +2748,10 @@ static virDomainPtr testDomainDefineXMLFlags(virConn= ectPtr conn, if (!(dom =3D virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, - 0, - &oldDef))) + 0))) goto cleanup; + + virDomainObjAssignDef(dom, def, false, &oldDef); def =3D NULL; dom->persistent =3D 1; =20 diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 963e7a9876..3ab7125b60 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -169,10 +169,10 @@ vmwareLoadDomains(struct vmware_driver *driver) } =20 if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, - driver->xmlopt, - 0, NULL))) + driver->xmlopt, 0))) goto cleanup; =20 + virDomainObjAssignDef(vm, vmdef, false, NULL); pDomain =3D vm->privateData; =20 if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 1bc8a06c39..d27313095d 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -442,10 +442,10 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const = char *xml, unsigned int fla if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; =20 + virDomainObjAssignDef(vm, vmdef, false, NULL); pDomain =3D vm->privateData; if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) goto cleanup; @@ -702,11 +702,10 @@ vmwareDomainCreateXML(virConnectPtr conn, const char = *xml, if (!(vm =3D virDomainObjListAdd(driver->domains, vmdef, driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, - NULL))) + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; =20 + virDomainObjAssignDef(vm, vmdef, true, NULL); pDomain =3D vm->privateData; if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) goto cleanup; diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 478443298f..4e934ec526 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1955,9 +1955,11 @@ prlsdkLoadDomain(vzDriverPtr driver, =20 virObjectLock(driver); if (!(olddom =3D virDomainObjListFindByUUID(driver->domains, def->= uuid))) - dom =3D virDomainObjListAdd(driver->domains, def, driver->xmlo= pt, 0, NULL); + dom =3D virDomainObjListAdd(driver->domains, def, driver->xmlo= pt, 0); virObjectUnlock(driver); =20 + virDomainObjAssignDef(dom, def, false, NULL); + if (olddom) { virDomainDefFree(def); return olddom; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725943; cv=none; d=zoho.com; s=zohoarc; b=ND4o5oC+vHSzZjuYDVSLZQ5KklGdSB4bP1ajLKBYOF5kqmzAI6H/7bNKmviahTtsYH0K5cLm+tKPN72LM4ArkuUmK4cXyayzdePujAN4lUClHvoRmOtvaMGDo6WAFwdyj7VgVyWU+ubfqhPKhOnBatrtY4YifYXoKGcocAztEhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725943; 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:ARC-Authentication-Results; bh=JVsyPRmB8bIGiYs/Fphepj9mPtq5N/546LUogf6eRGM=; b=kx7Pk9aRPIzqocRu6nL1YmyyaE9KCLSthMO5jvsZHCnOJp8Pvc1QlaoNmdyT79QRParJMgUqxoUBLew0GLSfP8arhULKJFgc+voJEfRGxpjYfU54lE1eL9fyEc9XPMFhxk2mxtB1xuUnOrGjjqetjARUYUNMM/875gmvir+auio= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725943805830.1803936375621; Wed, 5 Jun 2019 02:12:23 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A5462307D963; Wed, 5 Jun 2019 09:12:11 +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 7BAC91001E86; Wed, 5 Jun 2019 09:12:09 +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 3BC36206D5; Wed, 5 Jun 2019 09:12:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599WW4005957 for ; Wed, 5 Jun 2019 05:09:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 209A660A35; Wed, 5 Jun 2019 09:09:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78E042C8C8; Wed, 5 Jun 2019 09:09:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:13 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 05/11] virDomainObjListAdd: Remove unused flag 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 05 Jun 2019 09:12:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" After the previous commit the VIR_DOMAIN_OBJ_LIST_ADD_LIVE flag is not used anymore. Let's remove it. Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/conf/virdomainobjlist.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index 552a7cfaf2..54e7871c67 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -38,8 +38,7 @@ virDomainObjPtr virDomainObjListFindByName(virDomainObjLi= stPtr doms, const char *name); =20 enum { - VIR_DOMAIN_OBJ_LIST_ADD_LIVE =3D (1 << 0), - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE =3D (1 << 1), + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE =3D (1 << 0), }; virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, virDomainDefPtr def, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725965; cv=none; d=zoho.com; s=zohoarc; b=mA7bJqdSKy16bj9y4t3sf9HbA1PI2yxdAg41+3budsJByQiAQ+uw2CoXAhCBLJZeIaGEZlONBwAAjpjxYf49dzfVhTsnswKPHqw7FgCk/crKjZL1vRbzAg+FijgshwCQ3ReE1q68eCVa3er4nnQggrvNg9fkvwx9vYuIVss2SUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725965; 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:ARC-Authentication-Results; bh=mqTD++j/fo2lmfXa4ckTL0/GDx0tlD1OU8z89EGtDHo=; b=QJCjUC6852/M5+ayDZQTSmZlFICp4RO/GbEEmgtsBuihH6ae1ixoLTMY3EnxRnv2SRXaHBHbHLTlXvQWUkNNpQShATiXJwj6WIndTiB9QrE3JFKZNelxPc2NXex5bmK43Ewkf9VOkQ9ELuhDU+tZ46w2dc5XebTAXFZy5/M7Ez8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725965790715.013430714266; Wed, 5 Jun 2019 02:12:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FE02C04FFF1; Wed, 5 Jun 2019 09:12:34 +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 626905D739; Wed, 5 Jun 2019 09:12:33 +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 2074D206D2; Wed, 5 Jun 2019 09:12:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599XbL005968 for ; Wed, 5 Jun 2019 05:09:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14BE82C8C4; Wed, 5 Jun 2019 09:09:33 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C92860A35; Wed, 5 Jun 2019 09:09:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:14 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 06/11] qemu: Grab modify job for changing domain XML 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 05 Jun 2019 09:12:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Changing domain definition must be guarded with acquiring modify job. The problem is if there is a thread executing say qemuDomainSetMemoryStatsPeriod() which is an API that acquires modify job and then possibly unlock the domain object and locks it again. However, becasue virDomainObjAssignDef() does not take a job (only object lock) it may have changed the domain definition while the other thread unlocked the domain object in order to talk on the monitor. For instance: Thread1: 1) lookup domain object and lock it 2) acquire job 3) get pointers to live and persistent defs 4) unlock the domain object 5) talk to qemu on the monitor Thread2 (Execute qemuDomainDefineXMLFlags): 1) lookup domain object and lock it 2) virDomainObjAssignDef() which overwrites persistent def and frees the old one 3) unlock domain object Thread1: 6) lock the domain object again 7) try to access the persistent def via pointer stored in 3) Now, this will crash because the pointer from step 3) points to a memory that was freed. However, if Thread2 waited and acquired modify job (just like Thread1) then these two would serialize and no harm would be done. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 55 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 6 +++++ src/qemu/qemu_driver.c | 27 ++++++------------- src/qemu/qemu_migration.c | 5 +--- 4 files changed, 70 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 4d3a8868b2..f6b677c69e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7055,6 +7055,61 @@ virDomainDefParserConfig virQEMUDriverDomainDefParse= rConfig =3D { }; =20 =20 +/** + * qemuDomainObjListAdd: + * @driver: qemu driver + * @def: domain definition + * @oldDef: previous domain definition + * @live: whether @def is live definition + * @flags: an bitwise-OR of virDomainObjListAdd flags + * + * Add a domain onto the list of domain object and sets its + * definition. If @oldDef is not NULL and there was pre-existing + * definition it's returned in @oldDef. + * + * In addition to that, if definition of an existing domain is + * changed a MODIFY job is acquired prior to that. + * + * Returns: domain object pointer on success, + * NULL otherwise. + */ +virDomainObjPtr +qemuDomainObjListAdd(virQEMUDriverPtr driver, + virDomainDefPtr def, + virDomainDefPtr *oldDef, + bool live, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + + if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt,= flags))) + return NULL; + + /* At this point, @vm is locked. If it doesn't have any + * definition set, then the call above just added it and + * there can't be anybody else using the object. It's safe to + * just set the definition without acquiring job. */ + if (!vm->def) { + virDomainObjAssignDef(vm, def, live, oldDef); + VIR_RETURN_PTR(vm); + } + + /* Bad luck. Domain was pre-existing and this call is trying + * to update its definition. Modify job MUST be acquired. */ + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { + qemuDomainRemoveInactive(driver, vm); + virDomainObjEndAPI(&vm); + return NULL; + } + + virDomainObjAssignDef(vm, def, live, oldDef); + + qemuDomainObjEndJob(driver, vm); + + return vm; +} + + static void qemuDomainObjSaveJob(virQEMUDriverPtr driver, virDomainObjPtr obj) { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f92f0dbc27..f469f8eaca 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -543,6 +543,12 @@ void qemuDomainEventFlush(int timer, void *opaque); void qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver, virDomainObjPtr vm); =20 +virDomainObjPtr qemuDomainObjListAdd(virQEMUDriverPtr driver, + virDomainDefPtr def, + virDomainDefPtr *oldDef, + bool live, + unsigned int flags); + int qemuDomainObjBeginJob(virQEMUDriverPtr driver, virDomainObjPtr obj, qemuDomainJob job) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8bbac339e0..fa93a686b7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1701,12 +1701,9 @@ static virDomainPtr qemuDomainCreateXML(virConnectPt= r conn, if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) + if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; - - virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START, @@ -2405,6 +2402,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPt= r dom, int period, =20 qemuDomainObjEnterMonitor(driver, vm); r =3D qemuMonitorSetMemoryStatsPeriod(priv->mon, def->memballoon, = period); + sleep(60); if (qemuDomainObjExitMonitor(driver, vm) < 0) goto endjob; if (r < 0) { @@ -6971,12 +6969,9 @@ qemuDomainRestoreFlags(virConnectPtr conn, def =3D tmp; } =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) + if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; - - virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (flags & VIR_DOMAIN_SAVE_RUNNING) @@ -7647,11 +7642,8 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, 0))) + if (!(vm =3D qemuDomainObjListAdd(driver, def, &oldDef, false, 0))) goto cleanup; - - virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; =20 vm->persistent =3D 1; @@ -16884,12 +16876,9 @@ static virDomainPtr qemuDomainQemuAttach(virConnec= tPtr conn, if (qemuAssignDeviceAliases(def, qemuCaps) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) + if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; - - virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 9e19c923ee..13f0bc7e45 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2403,12 +2403,9 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, QEMU_MIGRATION_COOKIE_CAPS))) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, *def, - driver->xmlopt, + if (!(vm =3D qemuDomainObjListAdd(driver, *def, NULL, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; - - virDomainObjAssignDef(vm, *def, true, NULL); *def =3D NULL; =20 priv =3D vm->privateData; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725968; cv=none; d=zoho.com; s=zohoarc; b=Yp/442heBjkwOpAEaWzVqAXtogXP0uVAzzJoAMKbZGiXMQzyVVl46TXqCekfnRMSloGYfhIHzVbagaSyeJDJQMDnnJ89gCgt38vR9eHiJmGndgMQ01kXQojw9D91ij5HfNmm3DdInbgaojvEdLv6Qzo03rcvOzZ5CFgMBvX+Eo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725968; 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:ARC-Authentication-Results; bh=kBZNTGFvctfcbQnFFgJ3gV4D5SGYBn3R46hskhxg5uk=; b=lYtTA4cCT96YYsDgjZX1uKXLCv01KPKKTieDBuq/dLmmzfuZdOTLEenAGyQP3irFAfhoqDuxchSPJmCINkUvD2mMjPSlDaRhxk0+4kj86MmavkWwMiIG2cgTH5cZeWUvoHQP0c75kOu3CXbAjySocKNUnxxmf6vg3jRq8nxiGQ8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725968248943.040802762766; Wed, 5 Jun 2019 02:12:48 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 70C65308421A; Wed, 5 Jun 2019 09:12:36 +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 3CC66601A5; Wed, 5 Jun 2019 09:12:34 +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 EC889206D4; Wed, 5 Jun 2019 09:12:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599YVc005974 for ; Wed, 5 Jun 2019 05:09:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A26160A35; Wed, 5 Jun 2019 09:09:34 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 609605F7C0; Wed, 5 Jun 2019 09:09:33 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:15 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 07/11] qemu_domain: Allow qemuDomainObjListAdd to keep job upon return 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 05 Jun 2019 09:12:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In some cases, caller of qemuDomainObjListAdd() tries to acquire MODIFY job after the call. Let's adjust qemuDomainObjListAdd() so that it will keep the job set upon return (if requested by caller). Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/qemu/qemu_domain.c | 17 ++++++++++++++--- src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 24 +++++++++++------------- src/qemu/qemu_migration.c | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f6b677c69e..b0b3fa5fd8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7061,6 +7061,7 @@ virDomainDefParserConfig virQEMUDriverDomainDefParser= Config =3D { * @def: domain definition * @oldDef: previous domain definition * @live: whether @def is live definition + * @keepJob: whether to leave MODIFY job set on returned object * @flags: an bitwise-OR of virDomainObjListAdd flags * * Add a domain onto the list of domain object and sets its @@ -7070,6 +7071,10 @@ virDomainDefParserConfig virQEMUDriverDomainDefParse= rConfig =3D { * In addition to that, if definition of an existing domain is * changed a MODIFY job is acquired prior to that. * + * If @keepJob is true, then the MODIFY job is not ended upon + * successful return from this function. This might be handy if + * caller would try to acquire the job anyway. + * * Returns: domain object pointer on success, * NULL otherwise. */ @@ -7078,9 +7083,11 @@ qemuDomainObjListAdd(virQEMUDriverPtr driver, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags) { virDomainObjPtr vm =3D NULL; + bool defSet =3D false; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt,= flags))) return NULL; @@ -7091,7 +7098,9 @@ qemuDomainObjListAdd(virQEMUDriverPtr driver, * just set the definition without acquiring job. */ if (!vm->def) { virDomainObjAssignDef(vm, def, live, oldDef); - VIR_RETURN_PTR(vm); + defSet =3D true; + if (!keepJob) + VIR_RETURN_PTR(vm); } =20 /* Bad luck. Domain was pre-existing and this call is trying @@ -7102,9 +7111,11 @@ qemuDomainObjListAdd(virQEMUDriverPtr driver, return NULL; } =20 - virDomainObjAssignDef(vm, def, live, oldDef); + if (!defSet) + virDomainObjAssignDef(vm, def, live, oldDef); =20 - qemuDomainObjEndJob(driver, vm); + if (!keepJob) + qemuDomainObjEndJob(driver, vm); =20 return vm; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f469f8eaca..52b708babb 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -547,6 +547,7 @@ virDomainObjPtr qemuDomainObjListAdd(virQEMUDriverPtr d= river, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags); =20 int qemuDomainObjBeginJob(virQEMUDriverPtr driver, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fa93a686b7..34359c9500 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1701,7 +1701,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr= conn, if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, + if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, false, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def =3D NULL; @@ -6969,7 +6969,7 @@ qemuDomainRestoreFlags(virConnectPtr conn, def =3D tmp; } =20 - if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, + if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, false, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def =3D NULL; @@ -7642,7 +7642,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D qemuDomainObjListAdd(driver, def, &oldDef, false, 0))) + if (!(vm =3D qemuDomainObjListAdd(driver, def, &oldDef, false, true, 0= ))) goto cleanup; def =3D NULL; =20 @@ -7663,9 +7663,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, /* Brand new domain. Remove it */ VIR_INFO("Deleting domain '%s'", vm->def->name); vm->persistent =3D 0; - qemuDomainRemoveInactiveJob(driver, vm); + qemuDomainRemoveInactive(driver, vm); } - goto cleanup; + goto endjob; } =20 event =3D virDomainEventLifecycleNewFromObj(vm, @@ -7677,6 +7677,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, VIR_INFO("Creating domain '%s'", vm->def->name); dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 + endjob: + qemuDomainObjEndJob(driver, vm); + cleanup: virDomainDefFree(oldDef); virDomainDefFree(def); @@ -16876,25 +16879,20 @@ static virDomainPtr qemuDomainQemuAttach(virConne= ctPtr conn, if (qemuAssignDeviceAliases(def, qemuCaps) < 0) goto cleanup; =20 - if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, + if (!(vm =3D qemuDomainObjListAdd(driver, def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def =3D NULL; =20 - if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) { - qemuDomainRemoveInactive(driver, vm); - goto cleanup; - } - if (qemuProcessAttach(conn, driver, vm, pid, pidfile, monConfig, monJSON) < 0) { qemuDomainRemoveInactive(driver, vm); - qemuDomainObjEndJob(driver, vm); - goto cleanup; + goto endjob; } =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 + endjob: qemuDomainObjEndJob(driver, vm); =20 cleanup: diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 13f0bc7e45..4e1c57c273 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2403,7 +2403,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, QEMU_MIGRATION_COOKIE_CAPS))) goto cleanup; =20 - if (!(vm =3D qemuDomainObjListAdd(driver, *def, NULL, true, + if (!(vm =3D qemuDomainObjListAdd(driver, *def, NULL, true, false, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; *def =3D NULL; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725976; cv=none; d=zoho.com; s=zohoarc; b=kz9u4nGenrui6SJaKTey5rXI/KjD9uQmceLi9x5L7F6C7yKZ8PiZ+luqxzDOCK9u7o5tBxgpnN8i1g04vZr6tAZ4FxAMh7284B8b8jLr/r3R5I6wQHwTsfSouLFuAKZvLwxCylOpfcrLCLVQTMnty/woNQto4pxbEJ9KTlxbtOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725976; 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:ARC-Authentication-Results; bh=OngQaNQ+/wfk1crlgalrPIllahALhLz+tfTWQwqMMuk=; b=MleYXQOFdlYIhyQVPnafEXgqIvzbaqtnzVdlYKfrEAbbsSn3to/xqmL1akSzglRfT6+bG2MAJ9WLS0b04v4y4Y6hnJWeudyrU46P7Oy39qkZ5uD+w41zzrSvQyj5duFluriWZB3bLquf8FfEkQQkRjWhQIewmqyaSfptYlL0Tsw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725976964885.8509881644056; Wed, 5 Jun 2019 02:12:56 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 902BB3B72D; Wed, 5 Jun 2019 09:12:52 +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 693B812A73; Wed, 5 Jun 2019 09:12:52 +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 2DFB41806B15; Wed, 5 Jun 2019 09:12:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599Z8g005979 for ; Wed, 5 Jun 2019 05:09:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id F331D18ED0; Wed, 5 Jun 2019 09:09:34 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 563D760A35; Wed, 5 Jun 2019 09:09:34 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:16 +0200 Message-Id: <5362599f4050c042cbebb9117c5eb7e2d0946635.1559725591.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 08/11] lxc: Grab modify job for changing domain XML 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 05 Jun 2019 09:12:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The reasoning here is the same as in qemu driver fixed in previous commit. Long story short, changing an XML of a domain requires modify job to be acquired. Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/lxc/lxc_domain.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/lxc/lxc_domain.h | 7 ++++++ src/lxc/lxc_driver.c | 11 +++------ 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 51a9fd36eb..800999cbed 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -47,6 +47,63 @@ VIR_ENUM_IMPL(virLXCDomainJob, =20 VIR_LOG_INIT("lxc.lxc_domain"); =20 + +/** + * lxcDomainObjListAdd: + * @driver: LXC driver + * @def: domain definition + * @oldDef: previous domain definition + * @live: whether @def is live definition + * @flags: an bitwise-OR of virDomainObjListAdd flags + * + * Add a domain onto the list of domain object and sets its + * definition. If @oldDef is not NULL and there was pre-existing + * definition it's returned in @oldDef. + * + * In addition to that, if definition of an existing domain is + * changed a MODIFY job is acquired prior to that. + * + * Returns: domain object pointer on success, + * NULL otherwise. + */ +virDomainObjPtr +lxcDomainObjListAdd(virLXCDriverPtr driver, + virDomainDefPtr def, + virDomainDefPtr *oldDef, + bool live, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + + if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt,= flags))) + return NULL; + + /* At this point, @vm is locked. If it doesn't have any + * definition set, then the call above just added it and + * there can't be anybody else using the object. It's safe to + * just set the definition without acquiring job. */ + if (!vm->def) { + virDomainObjAssignDef(vm, def, live, oldDef); + VIR_RETURN_PTR(vm); + } + + /* Bad luck. Domain was pre-existing and this call is trying + * to update its definition. Modify job MUST be acquired. */ + if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) { + if (!vm->persistent) + virDomainObjListRemove(driver->domains, vm); + virDomainObjEndAPI(&vm); + return NULL; + } + + virDomainObjAssignDef(vm, def, live, oldDef); + + virLXCDomainObjEndJob(driver, vm); + + return vm; +} + + static int virLXCDomainObjInitJob(virLXCDomainObjPrivatePtr priv) { diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h index 2048481829..522cf7917d 100644 --- a/src/lxc/lxc_domain.h +++ b/src/lxc/lxc_domain.h @@ -96,6 +96,13 @@ extern virDomainXMLNamespace virLXCDriverDomainXMLNamesp= ace; extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks; extern virDomainDefParserConfig virLXCDriverDomainDefParserConfig; =20 +virDomainObjPtr +lxcDomainObjListAdd(virLXCDriverPtr driver, + virDomainDefPtr def, + virDomainDefPtr *oldDef, + bool live, + unsigned int flags); + int virLXCDomainObjBeginJob(virLXCDriverPtr driver, virDomainObjPtr obj, diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index eaf26563f5..41e6b59927 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -444,12 +444,10 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const cha= r *xml, unsigned int flags) goto cleanup; } =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, 0))) + if (!(vm =3D lxcDomainObjListAdd(driver, def, &oldDef, false, 0))) goto cleanup; - - virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; + vm->persistent =3D 1; =20 if (virDomainSaveConfig(cfg->configDir, driver->caps, @@ -1191,12 +1189,9 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, } =20 =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, + if (!(vm =3D lxcDomainObjListAdd(driver, def, NULL, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; - - virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725969; cv=none; d=zoho.com; s=zohoarc; b=Bdrvm/s+UTlbv0aBDZdspLNZROLlfAJMZWlitRRTc+SrBUFi3QWRbSh8NNcdyB07GVXQ+BxAbWyfXBt1js+hyVUYkHXPXDi3j8bTe8cd2Kxbtv9U7wVyeaawladUx8dGs/1fakicyiag0rPtIMhvR/oHw7EI3ljJh6g4lbAknfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725969; 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:ARC-Authentication-Results; bh=0h0C6OmWMyCuN8xG/uv2gJdGzebKDqzlyFBFf7y2u6g=; b=B+FoYtErBxKrzWhzhMKJBNSRVbmTekCTIuaP3wJv2PbKgv0QEwBJNWlVGJOUfWthUIsc11f85gu//IiOWsxIVBZbuuyKcd4WBwzRkexJLOxrYpzIGJOPLL1CkJqxZwfOzXT2eUKVqIc+LwunOGV06YD5SHSeYL2b3k4p4Y3I8ek= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725969638128.85880320994022; Wed, 5 Jun 2019 02:12:49 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D632B5AFE9; Wed, 5 Jun 2019 09:12:47 +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 A903A60576; Wed, 5 Jun 2019 09:12:46 +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 630CC1806B0F; Wed, 5 Jun 2019 09:12:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599Z5b006002 for ; Wed, 5 Jun 2019 05:09:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id E845018ED0; Wed, 5 Jun 2019 09:09:35 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B75E60A35; Wed, 5 Jun 2019 09:09:35 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:17 +0200 Message-Id: <21f919a170d0978ce25ae2d46a0f6e22ed15c32b.1559725591.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 09/11] lxc_domain: Allow lxcDomainObjListAdd to keep job upon return 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 05 Jun 2019 09:12:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In some cases, caller of lxcDomainObjListAdd() tries to acquire MODIFY job after the call. Let's adjust lxcDomainObjListAdd() so that it will keep the job set upon return (if requested by caller). Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/lxc/lxc_domain.c | 17 ++++++++++++++--- src/lxc/lxc_domain.h | 1 + src/lxc/lxc_driver.c | 19 ++++++++----------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 800999cbed..2249d38757 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -54,6 +54,7 @@ VIR_LOG_INIT("lxc.lxc_domain"); * @def: domain definition * @oldDef: previous domain definition * @live: whether @def is live definition + * @keepJob: whether to leave MODIFY job set on returned object* * @flags: an bitwise-OR of virDomainObjListAdd flags * * Add a domain onto the list of domain object and sets its @@ -63,6 +64,10 @@ VIR_LOG_INIT("lxc.lxc_domain"); * In addition to that, if definition of an existing domain is * changed a MODIFY job is acquired prior to that. * + * If @keepJob is true, then the MODIFY job is not ended upon + * successful return from this function. This might be handy if + * caller would try to acquire the job anyway. + * * Returns: domain object pointer on success, * NULL otherwise. */ @@ -71,9 +76,11 @@ lxcDomainObjListAdd(virLXCDriverPtr driver, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags) { virDomainObjPtr vm =3D NULL; + bool defSet =3D false; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt,= flags))) return NULL; @@ -84,7 +91,9 @@ lxcDomainObjListAdd(virLXCDriverPtr driver, * just set the definition without acquiring job. */ if (!vm->def) { virDomainObjAssignDef(vm, def, live, oldDef); - VIR_RETURN_PTR(vm); + defSet =3D true; + if (!keepJob) + VIR_RETURN_PTR(vm); } =20 /* Bad luck. Domain was pre-existing and this call is trying @@ -96,9 +105,11 @@ lxcDomainObjListAdd(virLXCDriverPtr driver, return NULL; } =20 - virDomainObjAssignDef(vm, def, live, oldDef); + if (!defSet) + virDomainObjAssignDef(vm, def, live, oldDef); =20 - virLXCDomainObjEndJob(driver, vm); + if (!keepJob) + virLXCDomainObjEndJob(driver, vm); =20 return vm; } diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h index 522cf7917d..539914e0a8 100644 --- a/src/lxc/lxc_domain.h +++ b/src/lxc/lxc_domain.h @@ -101,6 +101,7 @@ lxcDomainObjListAdd(virLXCDriverPtr driver, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags); =20 int diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 41e6b59927..e77df15772 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -444,7 +444,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char = *xml, unsigned int flags) goto cleanup; } =20 - if (!(vm =3D lxcDomainObjListAdd(driver, def, &oldDef, false, 0))) + if (!(vm =3D lxcDomainObjListAdd(driver, def, &oldDef, false, true, 0)= )) goto cleanup; def =3D NULL; =20 @@ -453,7 +453,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char = *xml, unsigned int flags) if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->newDef ? vm->newDef : vm->def) < 0) { virDomainObjListRemove(driver->domains, vm); - goto cleanup; + goto endjob; } =20 event =3D virDomainEventLifecycleNewFromObj(vm, @@ -464,6 +464,9 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char = *xml, unsigned int flags) =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 + endjob: + virLXCDomainObjEndJob(driver, vm); + cleanup: virDomainDefFree(def); virDomainDefFree(oldDef); @@ -1189,26 +1192,19 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, } =20 =20 - if (!(vm =3D lxcDomainObjListAdd(driver, def, NULL, true, + if (!(vm =3D lxcDomainObjListAdd(driver, def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def =3D NULL; =20 - if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) { - if (!vm->persistent) - virDomainObjListRemove(driver->domains, vm); - goto cleanup; - } - if (virLXCProcessStart(conn, driver, vm, nfiles, files, (flags & VIR_DOMAIN_START_AUTODESTROY), VIR_DOMAIN_RUNNING_BOOTED) < 0) { virDomainAuditStart(vm, "booted", false); - virLXCDomainObjEndJob(driver, vm); if (!vm->persistent) virDomainObjListRemove(driver->domains, vm); - goto cleanup; + goto endjob; } =20 event =3D virDomainEventLifecycleNewFromObj(vm, @@ -1218,6 +1214,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 + endjob: virLXCDomainObjEndJob(driver, vm); =20 cleanup: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559725986; cv=none; d=zoho.com; s=zohoarc; b=M0CAGGuyvCKkI5Rks65umjW00u/iaRcZnK2HXc80E0I2Wdo33OtrJM6A6DtVAjuMKVzxiF15V4Nlw6RnUMmjE6+FEph61ZrA/QC7Bvtz84i69525RZwLUOzjWVttSkuXxHCUpnHnc5nXd2cs3n1sph1e61tcf4ivi3u+MX6mxhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559725986; 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:ARC-Authentication-Results; bh=lCDCYc42E/6qQMo+Ggy/DhAxGiOadpvPcr/0G5/UIZk=; b=M8LHo/LoMifLqgK8zyA3MGFhlFqxKueqXcD6XBRa+TRkEY2rAxjbJKKvaggiMJXwCjMdBy7Ajdt4GUhj7oLP5yqVfgEnm2yuWU4JHUv4OqelPekwjiBdnn/6MehNhwef5s2D7po1d3mvgcVAGpH1sRYIXeLVzBQoWQtfsZTmKc8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559725986513445.4688485976302; Wed, 5 Jun 2019 02:13:06 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7884730860DF; Wed, 5 Jun 2019 09:13: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 440D119741; Wed, 5 Jun 2019 09:13: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 F422D1806B1C; Wed, 5 Jun 2019 09:13:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599aXg006009 for ; Wed, 5 Jun 2019 05:09:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id DD3F918ED0; Wed, 5 Jun 2019 09:09:36 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4056760A35; Wed, 5 Jun 2019 09:09:36 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:18 +0200 Message-Id: <469c3c508fecbaa7b4a0ed37c065d740e5e545a3.1559725591.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 10/11] libxl: Grab modify job for changing domain XML 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 05 Jun 2019 09:13:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The reasoning here is the same as in qemu driver fixed in previous commit. Long story short, changing an XML of a domain requires modify job to be acquired. Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/libxl/libxl_domain.c | 57 +++++++++++++++++++++++++++++++++++++ src/libxl/libxl_domain.h | 7 +++++ src/libxl/libxl_driver.c | 24 ++++------------ src/libxl/libxl_migration.c | 14 +++------ 4 files changed, 73 insertions(+), 29 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 2d8569e592..f2e1af52e5 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -65,6 +65,63 @@ libxlDomainObjPrivateOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(libxlDomainObjPrivate); =20 + +/** + * libxlDomainObjListAdd: + * @driver: libxl driver + * @def: domain definition + * @oldDef: previous domain definition + * @live: whether @def is live definition + * @flags: an bitwise-OR of virDomainObjListAdd flags + * + * Add a domain onto the list of domain object and sets its + * definition. If @oldDef is not NULL and there was pre-existing + * definition it's returned in @oldDef. + * + * In addition to that, if definition of an existing domain is + * changed a MODIFY job is acquired prior to that. + * + * Returns: domain object pointer on success, + * NULL otherwise. + */ +virDomainObjPtr +libxlDomainObjListAdd(libxlDriverPrivatePtr driver, + virDomainDefPtr def, + virDomainDefPtr *oldDef, + bool live, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + + if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt,= flags))) + return NULL; + + /* At this point, @vm is locked. If it doesn't have any + * definition set, then the call above just added it and + * there can't be anybody else using the object. It's safe to + * just set the definition without acquiring job. */ + if (!vm->def) { + virDomainObjAssignDef(vm, def, live, oldDef); + VIR_RETURN_PTR(vm); + } + + /* Bad luck. Domain was pre-existing and this call is trying + * to update its definition. Modify job MUST be acquired. */ + if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { + if (!vm->persistent) + virDomainObjListRemove(driver->domains, vm); + virDomainObjEndAPI(&vm); + return NULL; + } + + virDomainObjAssignDef(vm, def, live, oldDef); + + libxlDomainObjEndJob(driver, vm); + + return vm; +} + + static int libxlDomainObjInitJob(libxlDomainObjPrivatePtr priv) { diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h index 769ee8ec4d..b5d5127e91 100644 --- a/src/libxl/libxl_domain.h +++ b/src/libxl/libxl_domain.h @@ -83,6 +83,13 @@ extern const struct libxl_event_hooks ev_hooks; int libxlDomainObjPrivateInitCtx(virDomainObjPtr vm); =20 +virDomainObjPtr +libxlDomainObjListAdd(libxlDriverPrivatePtr driver, + virDomainDefPtr def, + virDomainDefPtr *oldDef, + bool live, + unsigned int flags); + int libxlDomainObjBeginJob(libxlDriverPrivatePtr driver, virDomainObjPtr obj, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 809d298ac1..9c9a30bb90 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -601,12 +601,8 @@ libxlAddDom0(libxlDriverPrivatePtr driver) if (virUUIDParse("00000000-0000-0000-0000-000000000000", def->uuid) < = 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - 0))) + if (!(vm =3D libxlDomainObjListAdd(driver, def, &oldDef, false, 0))) goto cleanup; - - virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; =20 vm->persistent =3D 1; @@ -1030,12 +1026,9 @@ libxlDomainCreateXML(virConnectPtr conn, const char = *xml, if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) + if (!(vm =3D libxlDomainObjListAdd(driver, def, NULL, true, + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; - - virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { @@ -1950,12 +1943,9 @@ libxlDomainRestoreFlags(virConnectPtr conn, const ch= ar *from, if (virDomainRestoreFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, + if (!(vm =3D libxlDomainObjListAdd(driver, def, NULL, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; - - virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { @@ -2850,12 +2840,8 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const = char *xml, unsigned int flag if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, def, - driver->xmlopt, - 0))) + if (!(vm =3D libxlDomainObjListAdd(driver, def, &oldDef, false, 0))) goto cleanup; - - virDomainObjAssignDef(vm, def, false, &oldDef); def =3D NULL; =20 vm->persistent =3D 1; diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 35403380d0..d0b0142900 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -566,12 +566,9 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dc= onn, &mig, &xmlout, &taint_hook) < 0) goto error; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, *def, - driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) + if (!(vm =3D libxlDomainObjListAdd(driver, *def, NULL, true, + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; - - virDomainObjAssignDef(vm, *def, true, NULL); *def =3D NULL; =20 /* @@ -675,12 +672,9 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, &mig, &xmlout, &taint_hook) < 0) goto error; =20 - if (!(vm =3D virDomainObjListAdd(driver->domains, *def, - driver->xmlopt, - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) + if (!(vm =3D libxlDomainObjListAdd(driver, *def, NULL, true, + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; - - virDomainObjAssignDef(vm, *def, true, NULL); *def =3D NULL; =20 /* --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Mar 29 07:42:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559726005; cv=none; d=zoho.com; s=zohoarc; b=I+rY1BdCyXH35d1IXY0KLMpup5F08nSZCr90EaFX00TPPa0TfmFFWr8NKzQs1uzUxVaPk/il07MdeNQGoAXDG5v4Hpjc/Va0MfWlvUJCwCBuV0NQQ8R9Iehg9HluA+0itFhQXWmbI2fB1oYnSZ7NKy/Z+chrIqYdimSd3WVpZZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559726005; 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:ARC-Authentication-Results; bh=GRRFZwnlbNefCbfqAWgMZSlYWOn2Njy/DMKKgaRxgFE=; b=X4Dvf+KWsEcWJqL2ko/2v40uyhnGQvjfKNuilxuOCZbGXjSZyYze7PmnXfOSlMG8dSGUlbyz9aWXbDzAQuWAxR9fjHcCCi4RXykHwXFYGZzkm22/kqaeqxg6+L2J88uD7MJxMEcHlXoF5EY3LuU729MbtchHAmHyhs+OuvlXB2Q= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559726005487115.49391682145949; Wed, 5 Jun 2019 02:13:25 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D207A308626C; Wed, 5 Jun 2019 09:13:18 +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 A13F318ED0; Wed, 5 Jun 2019 09:13:18 +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 592A7206D2; Wed, 5 Jun 2019 09:13:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5599bDZ006014 for ; Wed, 5 Jun 2019 05:09:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id D20C160A35; Wed, 5 Jun 2019 09:09:37 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3521022710; Wed, 5 Jun 2019 09:09:37 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 5 Jun 2019 11:09:19 +0200 Message-Id: <060613a637d74eef8fe8d6b044c16a4bca960e22.1559725591.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v2 11/11] libxl_domain: Allow libxlDomainObjListAdd to keep job upon return 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 05 Jun 2019 09:13:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In some cases, caller of libxlDomainObjListAdd() tries to acquire MODIFY job after the call. Let's adjust libxlDomainObjListAdd() so that it will keep the job set upon return (if requested by caller). Signed-off-by: Michal Privoznik Reviewed-by: Nikolay Shirokovskiy --- src/libxl/libxl_domain.c | 17 ++++++++++++++--- src/libxl/libxl_domain.h | 1 + src/libxl/libxl_driver.c | 24 +++++++----------------- src/libxl/libxl_migration.c | 18 ++---------------- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f2e1af52e5..8e45ac512a 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -72,6 +72,7 @@ VIR_ONCE_GLOBAL_INIT(libxlDomainObjPrivate); * @def: domain definition * @oldDef: previous domain definition * @live: whether @def is live definition + * @keepJob: whether to leave MODIFY job set on returned object * @flags: an bitwise-OR of virDomainObjListAdd flags * * Add a domain onto the list of domain object and sets its @@ -81,6 +82,10 @@ VIR_ONCE_GLOBAL_INIT(libxlDomainObjPrivate); * In addition to that, if definition of an existing domain is * changed a MODIFY job is acquired prior to that. * + * If @keepJob is true, then the MODIFY job is not ended upon + * successful return from this function. This might be handy if + * caller would try to acquire the job anyway. + * * Returns: domain object pointer on success, * NULL otherwise. */ @@ -89,9 +94,11 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags) { virDomainObjPtr vm =3D NULL; + bool defSet =3D false; =20 if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt,= flags))) return NULL; @@ -102,7 +109,9 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, * just set the definition without acquiring job. */ if (!vm->def) { virDomainObjAssignDef(vm, def, live, oldDef); - VIR_RETURN_PTR(vm); + defSet =3D true; + if (!keepJob) + VIR_RETURN_PTR(vm); } =20 /* Bad luck. Domain was pre-existing and this call is trying @@ -114,9 +123,11 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, return NULL; } =20 - virDomainObjAssignDef(vm, def, live, oldDef); + if (!defSet) + virDomainObjAssignDef(vm, def, live, oldDef); =20 - libxlDomainObjEndJob(driver, vm); + if (!keepJob) + libxlDomainObjEndJob(driver, vm); =20 return vm; } diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h index b5d5127e91..b04bbb6c51 100644 --- a/src/libxl/libxl_domain.h +++ b/src/libxl/libxl_domain.h @@ -88,6 +88,7 @@ libxlDomainObjListAdd(libxlDriverPrivatePtr driver, virDomainDefPtr def, virDomainDefPtr *oldDef, bool live, + bool keepJob, unsigned int flags); =20 int diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 9c9a30bb90..8a9a8baf79 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -601,7 +601,7 @@ libxlAddDom0(libxlDriverPrivatePtr driver) if (virUUIDParse("00000000-0000-0000-0000-000000000000", def->uuid) < = 0) goto cleanup; =20 - if (!(vm =3D libxlDomainObjListAdd(driver, def, &oldDef, false, 0))) + if (!(vm =3D libxlDomainObjListAdd(driver, def, &oldDef, false, false,= 0))) goto cleanup; def =3D NULL; =20 @@ -1026,17 +1026,11 @@ libxlDomainCreateXML(virConnectPtr conn, const char= *xml, if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D libxlDomainObjListAdd(driver, def, NULL, true, + if (!(vm =3D libxlDomainObjListAdd(driver, def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def =3D NULL; =20 - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { - if (!vm->persistent) - virDomainObjListRemove(driver->domains, vm); - goto cleanup; - } - if (libxlDomainStartNew(driver, vm, (flags & VIR_DOMAIN_START_PAUSED) !=3D 0) < 0) { if (!vm->persistent) @@ -1943,17 +1937,11 @@ libxlDomainRestoreFlags(virConnectPtr conn, const c= har *from, if (virDomainRestoreFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D libxlDomainObjListAdd(driver, def, NULL, true, + if (!(vm =3D libxlDomainObjListAdd(driver, def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto cleanup; def =3D NULL; =20 - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) { - if (!vm->persistent) - virDomainObjListRemove(driver->domains, vm); - goto cleanup; - } - ret =3D libxlDomainStartRestore(driver, vm, (flags & VIR_DOMAIN_SAVE_PAUSED) !=3D 0, fd, hdr.version); @@ -2840,7 +2828,7 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const c= har *xml, unsigned int flag if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 - if (!(vm =3D libxlDomainObjListAdd(driver, def, &oldDef, false, 0))) + if (!(vm =3D libxlDomainObjListAdd(driver, def, &oldDef, false, true, = 0))) goto cleanup; def =3D NULL; =20 @@ -2850,7 +2838,7 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const c= har *xml, unsigned int flag cfg->caps, vm->newDef ? vm->newDef : vm->def) < 0) { virDomainObjListRemove(driver->domains, vm); - goto cleanup; + goto endjob; } =20 dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); @@ -2859,6 +2847,8 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const c= har *xml, unsigned int flag !oldDef ? VIR_DOMAIN_EVENT_DEFINED_ADDED : VIR_DOMAIN_EVENT_DEFINED_UPDATED); + endjob: + libxlDomainObjEndJob(driver, vm); =20 cleanup: virDomainDefFree(def); diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index d0b0142900..e498846371 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -566,18 +566,11 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr d= conn, &mig, &xmlout, &taint_hook) < 0) goto error; =20 - if (!(vm =3D libxlDomainObjListAdd(driver, *def, NULL, true, + if (!(vm =3D libxlDomainObjListAdd(driver, *def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; *def =3D NULL; =20 - /* - * Unless an error is encountered in this function, the job will - * be terminated in the finish phase. - */ - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) - goto error; - priv =3D vm->privateData; =20 if (taint_hook) { @@ -672,18 +665,11 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn, &mig, &xmlout, &taint_hook) < 0) goto error; =20 - if (!(vm =3D libxlDomainObjListAdd(driver, *def, NULL, true, + if (!(vm =3D libxlDomainObjListAdd(driver, *def, NULL, true, true, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE))) goto error; *def =3D NULL; =20 - /* - * Unless an error is encountered in this function, the job will - * be terminated in the finish phase. - */ - if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) - goto error; - priv =3D vm->privateData; =20 if (taint_hook) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list