From nobody Sat May 4 04:29:03 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=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1559060005; cv=none; d=zoho.com; s=zohoarc; b=UOTqZlmH4VqIEb47S+0MR0+5m1vsENnRDIiBtJurLdX9q3lEZNYc8uw6x5zSXII6VnGCSEEZ/r3TruGuNWdej+SbiABEgV/rM3j9xgWzSAbPZEUYaT1zmUkoJR1L24FuNL1OKYqYVUB+9We6YC7aMsuPvL1TZrvtKKwaiYulmpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559060005; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=2ejp4xD1gEfrRL65vylt9veHmNm+tMHtNeOWlGtCoVI=; b=aR6Chd43Bx8MYaw/57URLMsdUuv10lHyheN9L7ko+dGv25boFWOpw7c+O+BNt0CwMgGS1l2gHajyWkLXcRclZB6iVQqOoXE7LXJZ89WZgUocRoLXV7Isv7Ruf0f6lF0eClvg2fE9JEhFuZMo5LqAne0nbDslddRH8OFKF99qYcw= 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=fail 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 1559060005711186.0990353117944; Tue, 28 May 2019 09:13:25 -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 5D39F307EA8C; Tue, 28 May 2019 16:13:15 +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 2C6BD6A24E; Tue, 28 May 2019 16:13:14 +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 DFF951833004; Tue, 28 May 2019 16:13:12 +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 x4SGBFHK025713 for ; Tue, 28 May 2019 12:11:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 06EB317999; Tue, 28 May 2019 16:11:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 001C0611B6 for ; Tue, 28 May 2019 16:11:12 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0D953179B41 for ; Tue, 28 May 2019 16:11:04 +0000 (UTC) Received: from [10.94.3.220] (helo=dim-vz7.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hVego-0005oe-2k for libvir-list@redhat.com; Tue, 28 May 2019 19:11:02 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Tue, 28 May 2019 19:11:00 +0300 Message-Id: <1559059860-99902-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Sender passed SPF test, ACL 242 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 28 May 2019 16:11:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 28 May 2019 16:11:05 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: 0.002 (SPF_HELO_NONE, SPF_NONE) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] qemu: aquire job in qemuDomainDefineXMLFlags 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: , MIME-Version: 1.0 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.44]); Tue, 28 May 2019 16:13:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function updates vm->newDef and frees previous pesistent definition which can be used by in different thread by some API that unlocks domain to communicate to qemu. So we have an access to freed memory in that thread. Let's acquire job condition in case of updating exiting domain. Signed-off-by: Nikolay Shirokovskiy --- diff from v1 [1]: - pay a bit of attention to the problem Reproducer in the Michal's reply to the [1]. [1] https://www.redhat.com/archives/libvir-list/2019-May/msg00804.html src/qemu/qemu_driver.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 42b1ce2..2dd4442 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7620,6 +7620,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, virDomainDefPtr def =3D NULL; virDomainDefPtr oldDef =3D NULL; virDomainObjPtr vm =3D NULL; + virDomainObjPtr exvm =3D NULL; virDomainPtr dom =3D NULL; virObjectEventPtr event =3D NULL; virQEMUDriverConfigPtr cfg; @@ -7647,10 +7648,34 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; =20 + if ((exvm =3D virDomainObjListFindByUUID(driver->domains, def->uuid)))= { + if (qemuDomainObjBeginJob(driver, exvm, QEMU_JOB_MODIFY) < 0) { + virDomainObjEndAPI(&exvm); + goto cleanup; + } + virObjectUnlock(exvm); + } + if (!(vm =3D virDomainObjListAdd(driver->domains, def, driver->xmlopt, - 0, &oldDef))) + 0, &oldDef))) { + if (exvm) + virObjectLock(exvm); goto cleanup; + } + + if (exvm) { + if (vm !=3D exvm) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("domain '%s' is removed"), def->name); + virObjectLock(exvm); + goto cleanup; + } + + /* we don't need extra reference for same domain */ + virObjectUnref(exvm); + } + def =3D NULL; =20 vm->persistent =3D 1; @@ -7670,7 +7695,10 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, /* Brand new domain. Remove it */ VIR_INFO("Deleting domain '%s'", vm->def->name); vm->persistent =3D 0; - qemuDomainRemoveInactiveJob(driver, vm); + if (exvm) + qemuDomainRemoveInactive(driver, vm); + else + qemuDomainRemoveInactiveJob(driver, vm); } goto cleanup; } @@ -7685,8 +7713,13 @@ qemuDomainDefineXMLFlags(virConnectPtr conn, dom =3D virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); =20 cleanup: + if (exvm) + qemuDomainObjEndJob(driver, exvm); + virDomainDefFree(oldDef); virDomainDefFree(def); + if (exvm && exvm !=3D vm) + virDomainObjEndAPI(&exvm); virDomainObjEndAPI(&vm); virObjectEventStateQueue(driver->domainEventState, event); virObjectUnref(caps); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list