From nobody Sat Apr 27 20:34:04 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499864226345644.5846628357277; Wed, 12 Jul 2017 05:57:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E0FD81138; Wed, 12 Jul 2017 12:57:01 +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 A80A060E3A; Wed, 12 Jul 2017 12:57:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 31A763FADF; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6CCuvnl022834 for ; Wed, 12 Jul 2017 08:56:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED114709F4; Wed, 12 Jul 2017 12:56:57 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE2FD709FC for ; Wed, 12 Jul 2017 12:56:55 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A86601000E7; Wed, 12 Jul 2017 14:56:54 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0E0FD81138 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0E0FD81138 From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 12 Jul 2017 14:56:47 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/7] qemu: Add qemuProcessFetchGuestCPU 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Jul 2017 12:57:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Separated from qemuProcessUpdateLiveGuestCPU. Its purpose is to fetch guest CPU data from a running QEMU process. The data can later be used to verify and update the active guest CPU definition. Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 58 +++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index e6522a294..b2d27b6be 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3945,6 +3945,47 @@ qemuProcessVerifyCPUFeatures(virDomainDefPtr def, =20 =20 static int +qemuProcessFetchGuestCPU(virQEMUDriverPtr driver, + virDomainObjPtr vm, + qemuDomainAsyncJob asyncJob, + virCPUDataPtr *enabled, + virCPUDataPtr *disabled) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virCPUDataPtr dataEnabled =3D NULL; + virCPUDataPtr dataDisabled =3D NULL; + int rc; + + *enabled =3D NULL; + *disabled =3D NULL; + + if (!ARCH_IS_X86(vm->def->os.arch)) + return 0; + + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + goto error; + + rc =3D qemuMonitorGetGuestCPU(priv->mon, vm->def->os.arch, + &dataEnabled, &dataDisabled); + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + goto error; + + if (rc =3D=3D -1) + goto error; + + *enabled =3D dataEnabled; + *disabled =3D dataDisabled; + return 0; + + error: + virCPUDataFree(dataEnabled); + virCPUDataFree(dataDisabled); + return -1; +} + + +static int qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob) @@ -3957,21 +3998,10 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driv= er, int ret =3D -1; virCPUDefPtr orig =3D NULL; =20 - if (ARCH_IS_X86(def->os.arch)) { - if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) - goto cleanup; - - rc =3D qemuMonitorGetGuestCPU(priv->mon, def->os.arch, &cpu, &disa= bled); - - if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto cleanup; - - if (rc < 0) { - if (rc =3D=3D -2) - ret =3D 0; - goto cleanup; - } + if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < = 0) + goto cleanup; =20 + if (cpu) { if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 || qemuProcessVerifyHypervFeatures(def, cpu) < 0) goto cleanup; --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 20:34:04 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499864223263850.7166411362136; Wed, 12 Jul 2017 05:57:03 -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 CE911C0587D4; Wed, 12 Jul 2017 12:57:00 +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 AAEB560466; Wed, 12 Jul 2017 12:57:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5707A1800C94; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6CCuvLW022833 for ; Wed, 12 Jul 2017 08:56:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id EBECF60E3A; Wed, 12 Jul 2017 12:56:57 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF2A870BA0 for ; Wed, 12 Jul 2017 12:56:55 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id AA767100869; Wed, 12 Jul 2017 14:56:54 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE911C0587D4 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CE911C0587D4 From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 12 Jul 2017 14:56:48 +0200 Message-Id: <27d5ad1f9893c7330c235fdcd266f9805bdeb72a.1499864108.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/7] qemu: Add qemuProcessVerifyCPU 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.32]); Wed, 12 Jul 2017 12:57:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Separated from qemuProcessUpdateLiveGuestCPU. The function makes sure a guest CPU provides all features required by a domain definition. Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b2d27b6be..198f68d93 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3986,6 +3986,31 @@ qemuProcessFetchGuestCPU(virQEMUDriverPtr driver, =20 =20 static int +qemuProcessVerifyCPU(virDomainObjPtr vm, + virCPUDataPtr cpu) +{ + virDomainDefPtr def =3D vm->def; + + if (!cpu) + return 0; + + if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 || + qemuProcessVerifyHypervFeatures(def, cpu) < 0) + return -1; + + if (!def->cpu || + (def->cpu->mode =3D=3D VIR_CPU_MODE_CUSTOM && + !def->cpu->model)) + return 0; + + if (qemuProcessVerifyCPUFeatures(def, cpu) < 0) + return -1; + + return 0; +} + + +static int qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob) @@ -4001,11 +4026,10 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driv= er, if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < = 0) goto cleanup; =20 - if (cpu) { - if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 || - qemuProcessVerifyHypervFeatures(def, cpu) < 0) - goto cleanup; + if (qemuProcessVerifyCPU(vm, cpu) < 0) + goto cleanup; =20 + if (cpu) { if (!def->cpu || (def->cpu->mode =3D=3D VIR_CPU_MODE_CUSTOM && !def->cpu->model)) { @@ -4013,9 +4037,6 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver, goto cleanup; } =20 - if (qemuProcessVerifyCPUFeatures(def, cpu) < 0) - goto cleanup; - if (!(orig =3D virCPUDefCopy(def->cpu))) goto cleanup; =20 --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 20:34:04 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499864238907358.6534267842427; Wed, 12 Jul 2017 05:57:18 -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 F1E52C0587D1; Wed, 12 Jul 2017 12:57: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 71CBB6E50A; Wed, 12 Jul 2017 12:57:15 +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 A7DE11853E33; Wed, 12 Jul 2017 12:57:14 +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 v6CCuwjp022852 for ; Wed, 12 Jul 2017 08:56:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4530E17AAE; Wed, 12 Jul 2017 12:56:58 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1669A6E503 for ; Wed, 12 Jul 2017 12:56:55 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id ACB1D10086A; Wed, 12 Jul 2017 14:56:54 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1E52C0587D1 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F1E52C0587D1 From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 12 Jul 2017 14:56:49 +0200 Message-Id: <82e7f5cae634c6bafbe3045661144dd56d7030ea.1499864108.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/7] qemu: Rename qemuProcessUpdateLiveGuestCPU 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 12 Jul 2017 12:57:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In addition to updating a guest CPU definition the function verifies that all required features are provided to the guest. Let's make it obvious by calling it qemuProcessUpdateAndVerifyCPU. Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 198f68d93..ebd13057b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4011,7 +4011,7 @@ qemuProcessVerifyCPU(virDomainObjPtr vm, =20 =20 static int -qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver, +qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob) { @@ -5928,7 +5928,7 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; =20 VIR_DEBUG("Verifying and updating provided guest CPU"); - if (qemuProcessUpdateLiveGuestCPU(driver, vm, asyncJob) < 0) + if (qemuProcessUpdateAndVerifyCPU(driver, vm, asyncJob) < 0) goto cleanup; =20 VIR_DEBUG("Setting up post-init cgroup restrictions"); --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 20:34:04 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499864223723295.38717644947917; Wed, 12 Jul 2017 05:57:03 -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 0F0FA4E909; Wed, 12 Jul 2017 12:57:01 +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 A6C165D6A6; Wed, 12 Jul 2017 12:57:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ACB271800217; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6CCuv6c022832 for ; Wed, 12 Jul 2017 08:56:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id E93904D745; Wed, 12 Jul 2017 12:56:57 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAE884D748 for ; Wed, 12 Jul 2017 12:56:55 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id AF51510086B; Wed, 12 Jul 2017 14:56:54 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F0FA4E909 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0F0FA4E909 From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 12 Jul 2017 14:56:50 +0200 Message-Id: <876f7287ace9fcec1283da71efcc2572f42529cf.1499864108.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] qemu: Add qemuProcessUpdateLiveGuestCPU 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 12 Jul 2017 12:57:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Separated from qemuProcessUpdateAndVerifyCPU to handle updating of an active guest CPU definition according to live data from QEMU. Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 70 +++++++++++++++++++++++++++++----------------= ---- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ebd13057b..926c64197 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4011,17 +4011,53 @@ qemuProcessVerifyCPU(virDomainObjPtr vm, =20 =20 static int +qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm, + virCPUDataPtr enabled, + virCPUDataPtr disabled) +{ + virDomainDefPtr def =3D vm->def; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virCPUDefPtr orig =3D NULL; + int rc; + int ret =3D -1; + + if (!enabled || + !def->cpu || + (def->cpu->mode =3D=3D VIR_CPU_MODE_CUSTOM && + !def->cpu->model)) + return 0; + + if (!(orig =3D virCPUDefCopy(def->cpu))) + goto cleanup; + + if ((rc =3D virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled= )) < 0) { + goto cleanup; + } else if (rc =3D=3D 0) { + /* Store the original CPU in priv if QEMU changed it and we didn't + * get the original CPU via migration, restore, or snapshot revert. + */ + if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false)) + VIR_STEAL_PTR(priv->origCPU, orig); + + def->cpu->check =3D VIR_CPU_CHECK_FULL; + } + + ret =3D 0; + + cleanup: + virCPUDefFree(orig); + return ret; +} + + +static int qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob) { - virDomainDefPtr def =3D vm->def; virCPUDataPtr cpu =3D NULL; virCPUDataPtr disabled =3D NULL; - qemuDomainObjPrivatePtr priv =3D vm->privateData; - int rc; int ret =3D -1; - virCPUDefPtr orig =3D NULL; =20 if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < = 0) goto cleanup; @@ -4029,36 +4065,14 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driv= er, if (qemuProcessVerifyCPU(vm, cpu) < 0) goto cleanup; =20 - if (cpu) { - if (!def->cpu || - (def->cpu->mode =3D=3D VIR_CPU_MODE_CUSTOM && - !def->cpu->model)) { - ret =3D 0; - goto cleanup; - } - - if (!(orig =3D virCPUDefCopy(def->cpu))) - goto cleanup; - - if ((rc =3D virCPUUpdateLive(def->os.arch, def->cpu, cpu, disabled= )) < 0) { - goto cleanup; - } else if (rc =3D=3D 0) { - /* Store the original CPU in priv if QEMU changed it and we di= dn't - * get the original CPU via migration, restore, or snapshot re= vert. - */ - if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false)) - VIR_STEAL_PTR(priv->origCPU, orig); - - def->cpu->check =3D VIR_CPU_CHECK_FULL; - } - } + if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0) + goto cleanup; =20 ret =3D 0; =20 cleanup: virCPUDataFree(cpu); virCPUDataFree(disabled); - virCPUDefFree(orig); return ret; } =20 --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 20:34:04 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499864235757725.5205771708648; Wed, 12 Jul 2017 05:57:15 -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 30D894E4D3; Wed, 12 Jul 2017 12:57:12 +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 081436F925; Wed, 12 Jul 2017 12:57:12 +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 71A5D3FAE5; Wed, 12 Jul 2017 12:57:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6CCv1TP022885 for ; Wed, 12 Jul 2017 08:57:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F7C2600CE; Wed, 12 Jul 2017 12:57:01 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6C026046D for ; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B157B10086C; Wed, 12 Jul 2017 14:56:54 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 30D894E4D3 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 30D894E4D3 From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 12 Jul 2017 14:56:51 +0200 Message-Id: <13724b2aed0b96fdef42bc96d234540e303a81c2.1499864108.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/7] qemu: Export virQEMUCapsGuestIsNative 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.38]); Wed, 12 Jul 2017 12:57:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_capabilities.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index db9f9b8b1..7cce4b18d 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -545,7 +545,7 @@ static const char *virQEMUCapsArchToString(virArch arch) =20 /* Checks whether a domain with @guest arch can run natively on @host. */ -static bool +bool virQEMUCapsGuestIsNative(virArch host, virArch guest) { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index fb22815e9..275e33c72 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -547,4 +547,7 @@ int virQEMUCapsFillDomainCaps(virCapsPtr caps, virFirmwarePtr *firmwares, size_t nfirmwares); =20 +bool virQEMUCapsGuestIsNative(virArch host, + virArch guest); + #endif /* __QEMU_CAPABILITIES_H__*/ --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 20:34:04 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149986431705763.12694994812637; Wed, 12 Jul 2017 05:58:37 -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 915974E4CB; Wed, 12 Jul 2017 12:58:32 +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 590955D9CE; Wed, 12 Jul 2017 12:58: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 F090B3FAE0; Wed, 12 Jul 2017 12:58: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 v6CCux3a022865 for ; Wed, 12 Jul 2017 08:56:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id CA1AD60A98; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BD186E501 for ; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B35C010086D; Wed, 12 Jul 2017 14:56:54 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 915974E4CB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 915974E4CB From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 12 Jul 2017 14:56:52 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/7] qemu: Move qemuProcessReconnect to the end of qemu_process.c 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 12 Jul 2017 12:58:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" qemuProcessReconnect will need to call additional functions which were originally defined further in qemu_process.c. Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 645 ++++++++++++++++++++++++--------------------= ---- 1 file changed, 323 insertions(+), 322 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 926c64197..2339de41c 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3371,328 +3371,6 @@ qemuProcessBuildDestroyHugepagesPath(virQEMUDriverP= tr driver, } =20 =20 -struct qemuProcessReconnectData { - virConnectPtr conn; - virQEMUDriverPtr driver; - virDomainObjPtr obj; -}; -/* - * Open an existing VM's monitor, re-detect VCPU threads - * and re-reserve the security labels in use - * - * We own the virConnectPtr we are passed here - whoever started - * this thread function has increased the reference counter to it - * so that we now have to close it. - * - * This function also inherits a locked and ref'd domain object. - * - * This function needs to: - * 1. Enter job - * 1. just before monitor reconnect do lightweight MonitorEnter - * (increase VM refcount and unlock VM) - * 2. reconnect to monitor - * 3. do lightweight MonitorExit (lock VM) - * 4. continue reconnect process - * 5. EndJob - * - * We can't do normal MonitorEnter & MonitorExit because these two lock the - * monitor lock, which does not exists in this early phase. - */ -static void -qemuProcessReconnect(void *opaque) -{ - struct qemuProcessReconnectData *data =3D opaque; - virQEMUDriverPtr driver =3D data->driver; - virDomainObjPtr obj =3D data->obj; - qemuDomainObjPrivatePtr priv; - virConnectPtr conn =3D data->conn; - struct qemuDomainJobObj oldjob; - int state; - int reason; - virQEMUDriverConfigPtr cfg; - size_t i; - unsigned int stopFlags =3D 0; - bool jobStarted =3D false; - virCapsPtr caps =3D NULL; - - VIR_FREE(data); - - qemuDomainObjRestoreJob(obj, &oldjob); - if (oldjob.asyncJob =3D=3D QEMU_ASYNC_JOB_MIGRATION_IN) - stopFlags |=3D VIR_QEMU_PROCESS_STOP_MIGRATED; - - cfg =3D virQEMUDriverGetConfig(driver); - priv =3D obj->privateData; - - if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) - goto error; - - if (qemuDomainObjBeginJob(driver, obj, QEMU_JOB_MODIFY) < 0) - goto error; - jobStarted =3D true; - - /* XXX If we ever gonna change pid file pattern, come up with - * some intelligence here to deal with old paths. */ - if (!(priv->pidfile =3D virPidFileBuildPath(cfg->stateDir, obj->def->n= ame))) - goto error; - - /* Restore the masterKey */ - if (qemuDomainMasterKeyReadFile(priv) < 0) - goto error; - - virNWFilterReadLockFilterUpdates(); - - VIR_DEBUG("Reconnect monitor to %p '%s'", obj, obj->def->name); - - /* XXX check PID liveliness & EXE path */ - if (qemuConnectMonitor(driver, obj, QEMU_ASYNC_JOB_NONE, NULL) < 0) - goto error; - - if (qemuHostdevUpdateActiveDomainDevices(driver, obj->def) < 0) - goto error; - - if (qemuConnectCgroup(driver, obj) < 0) - goto error; - - if (qemuDomainPerfRestart(obj) < 0) - goto error; - - /* XXX: Need to change as long as lock is introduced for - * qemu_driver->sharedDevices. - */ - for (i =3D 0; i < obj->def->ndisks; i++) { - virDomainDeviceDef dev; - - if (virStorageTranslateDiskSourcePool(conn, obj->def->disks[i]) < = 0) - goto error; - - /* XXX we should be able to restore all data from XML in the futur= e. - * This should be the only place that calls qemuDomainDetermineDis= kChain - * with @report_broken =3D=3D false to guarantee best-effort domain - * reconnect */ - if (qemuDomainDetermineDiskChain(driver, obj, obj->def->disks[i], - true, false) < 0) - goto error; - - dev.type =3D VIR_DOMAIN_DEVICE_DISK; - dev.data.disk =3D obj->def->disks[i]; - if (qemuAddSharedDevice(driver, &dev, obj->def->name) < 0) - goto error; - } - - if (qemuProcessUpdateState(driver, obj) < 0) - goto error; - - state =3D virDomainObjGetState(obj, &reason); - if (state =3D=3D VIR_DOMAIN_SHUTOFF || - (state =3D=3D VIR_DOMAIN_PAUSED && - reason =3D=3D VIR_DOMAIN_PAUSED_STARTING_UP)) { - VIR_DEBUG("Domain '%s' wasn't fully started yet, killing it", - obj->def->name); - goto error; - } - - /* If upgrading from old libvirtd we won't have found any - * caps in the domain status, so re-query them - */ - if (!priv->qemuCaps && - !(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(caps, - driver->qemuCapsCach= e, - obj->def->emulator, - obj->def->os.machine= ))) - goto error; - - /* In case the domain shutdown while we were not running, - * we need to finish the shutdown process. And we need to do it after - * we have virQEMUCaps filled in. - */ - if (state =3D=3D VIR_DOMAIN_SHUTDOWN || - (state =3D=3D VIR_DOMAIN_PAUSED && - reason =3D=3D VIR_DOMAIN_PAUSED_SHUTTING_DOWN)) { - VIR_DEBUG("Finishing shutdown sequence for domain %s", - obj->def->name); - qemuProcessShutdownOrReboot(driver, obj); - goto cleanup; - } - - if (qemuProcessBuildDestroyHugepagesPath(driver, obj, NULL, true) < 0) - goto error; - - if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps, - driver, obj, false)) < 0) { - goto error; - } - - /* if domain requests security driver we haven't loaded, report error,= but - * do not kill the domain - */ - ignore_value(qemuSecurityCheckAllLabel(driver->securityManager, - obj->def)); - - if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) = < 0) - goto error; - - qemuDomainVcpuPersistOrder(obj->def); - - if (qemuSecurityReserveLabel(driver->securityManager, obj->def, obj->p= id) < 0) - goto error; - - qemuProcessNotifyNets(obj->def); - - if (qemuProcessFiltersInstantiate(obj->def)) - goto error; - - if (qemuProcessRefreshDisks(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) - goto error; - - if (qemuBlockNodeNamesDetect(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) - goto error; - - if (qemuRefreshVirtioChannelState(driver, obj, QEMU_ASYNC_JOB_NONE) < = 0) - goto error; - - /* If querying of guest's RTC failed, report error, but do not kill th= e domain. */ - qemuRefreshRTC(driver, obj); - - if (qemuProcessRefreshBalloonState(driver, obj, QEMU_ASYNC_JOB_NONE) <= 0) - goto error; - - if (qemuProcessRecoverJob(driver, obj, conn, &oldjob, &stopFlags) < 0) - goto error; - - if (qemuProcessUpdateDevices(driver, obj) < 0) - goto error; - - qemuProcessReconnectCheckMemAliasOrderMismatch(obj); - - if (qemuConnectAgent(driver, obj) < 0) - goto error; - - /* update domain state XML with possibly updated state in virDomainObj= */ - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, obj, driver->ca= ps) < 0) - goto error; - - /* Run an hook to allow admins to do some magic */ - if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { - char *xml =3D qemuDomainDefFormatXML(driver, obj->def, 0); - int hookret; - - hookret =3D virHookCall(VIR_HOOK_DRIVER_QEMU, obj->def->name, - VIR_HOOK_QEMU_OP_RECONNECT, VIR_HOOK_SUBOP_B= EGIN, - NULL, xml, NULL); - VIR_FREE(xml); - - /* - * If the script raised an error abort the launch - */ - if (hookret < 0) - goto error; - } - - if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitCallb= ack) - driver->inhibitCallback(true, driver->inhibitOpaque); - - cleanup: - if (jobStarted) - qemuDomainObjEndJob(driver, obj); - if (!virDomainObjIsActive(obj)) - qemuDomainRemoveInactive(driver, obj); - virDomainObjEndAPI(&obj); - virObjectUnref(conn); - virObjectUnref(cfg); - virObjectUnref(caps); - virNWFilterUnlockFilterUpdates(); - return; - - error: - if (virDomainObjIsActive(obj)) { - /* We can't get the monitor back, so must kill the VM - * to remove danger of it ending up running twice if - * user tries to start it again later - */ - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NO_SHUTDOWN)) { - /* If we couldn't get the monitor and qemu supports - * no-shutdown, we can safely say that the domain - * crashed ... */ - state =3D VIR_DOMAIN_SHUTOFF_CRASHED; - } else { - /* ... but if it doesn't we can't say what the state - * really is and FAILED means "failed to start" */ - state =3D VIR_DOMAIN_SHUTOFF_UNKNOWN; - } - /* If BeginJob failed, we jumped here without a job, let's hope an= other - * thread didn't have a chance to start playing with the domain yet - * (it's all we can do anyway). - */ - qemuProcessStop(driver, obj, state, QEMU_ASYNC_JOB_NONE, stopFlags= ); - } - goto cleanup; -} - -static int -qemuProcessReconnectHelper(virDomainObjPtr obj, - void *opaque) -{ - virThread thread; - struct qemuProcessReconnectData *src =3D opaque; - struct qemuProcessReconnectData *data; - - /* If the VM was inactive, we don't need to reconnect */ - if (!obj->pid) - return 0; - - if (VIR_ALLOC(data) < 0) - return -1; - - memcpy(data, src, sizeof(*data)); - data->obj =3D obj; - - /* this lock and reference will be eventually transferred to the thread - * that handles the reconnect */ - virObjectLock(obj); - virObjectRef(obj); - - /* Since we close the connection later on, we have to make sure that t= he - * threads we start see a valid connection throughout their lifetime. = We - * simply increase the reference counter here. - */ - virObjectRef(data->conn); - - if (virThreadCreate(&thread, false, qemuProcessReconnect, data) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not create thread. QEMU initialization " - "might be incomplete")); - /* We can't spawn a thread and thus connect to monitor. Kill qemu. - * It's safe to call qemuProcessStop without a job here since there - * is no thread that could be doing anything else with the same do= main - * object. - */ - qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED, - QEMU_ASYNC_JOB_NONE, 0); - qemuDomainRemoveInactive(src->driver, obj); - - virDomainObjEndAPI(&obj); - virObjectUnref(data->conn); - VIR_FREE(data); - return -1; - } - - return 0; -} - -/** - * qemuProcessReconnectAll - * - * Try to re-open the resources for live VMs that we care - * about. - */ -void -qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver) -{ - struct qemuProcessReconnectData data =3D {.conn =3D conn, .driver =3D = driver}; - virDomainObjListForEach(driver->domains, qemuProcessReconnectHelper, &= data); -} - static int qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver, virDomainGraphicsDefPtr graphics, @@ -7012,3 +6690,326 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver, virHashFree(table); return ret; } + + +struct qemuProcessReconnectData { + virConnectPtr conn; + virQEMUDriverPtr driver; + virDomainObjPtr obj; +}; +/* + * Open an existing VM's monitor, re-detect VCPU threads + * and re-reserve the security labels in use + * + * We own the virConnectPtr we are passed here - whoever started + * this thread function has increased the reference counter to it + * so that we now have to close it. + * + * This function also inherits a locked and ref'd domain object. + * + * This function needs to: + * 1. Enter job + * 1. just before monitor reconnect do lightweight MonitorEnter + * (increase VM refcount and unlock VM) + * 2. reconnect to monitor + * 3. do lightweight MonitorExit (lock VM) + * 4. continue reconnect process + * 5. EndJob + * + * We can't do normal MonitorEnter & MonitorExit because these two lock the + * monitor lock, which does not exists in this early phase. + */ +static void +qemuProcessReconnect(void *opaque) +{ + struct qemuProcessReconnectData *data =3D opaque; + virQEMUDriverPtr driver =3D data->driver; + virDomainObjPtr obj =3D data->obj; + qemuDomainObjPrivatePtr priv; + virConnectPtr conn =3D data->conn; + struct qemuDomainJobObj oldjob; + int state; + int reason; + virQEMUDriverConfigPtr cfg; + size_t i; + unsigned int stopFlags =3D 0; + bool jobStarted =3D false; + virCapsPtr caps =3D NULL; + + VIR_FREE(data); + + qemuDomainObjRestoreJob(obj, &oldjob); + if (oldjob.asyncJob =3D=3D QEMU_ASYNC_JOB_MIGRATION_IN) + stopFlags |=3D VIR_QEMU_PROCESS_STOP_MIGRATED; + + cfg =3D virQEMUDriverGetConfig(driver); + priv =3D obj->privateData; + + if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) + goto error; + + if (qemuDomainObjBeginJob(driver, obj, QEMU_JOB_MODIFY) < 0) + goto error; + jobStarted =3D true; + + /* XXX If we ever gonna change pid file pattern, come up with + * some intelligence here to deal with old paths. */ + if (!(priv->pidfile =3D virPidFileBuildPath(cfg->stateDir, obj->def->n= ame))) + goto error; + + /* Restore the masterKey */ + if (qemuDomainMasterKeyReadFile(priv) < 0) + goto error; + + virNWFilterReadLockFilterUpdates(); + + VIR_DEBUG("Reconnect monitor to %p '%s'", obj, obj->def->name); + + /* XXX check PID liveliness & EXE path */ + if (qemuConnectMonitor(driver, obj, QEMU_ASYNC_JOB_NONE, NULL) < 0) + goto error; + + if (qemuHostdevUpdateActiveDomainDevices(driver, obj->def) < 0) + goto error; + + if (qemuConnectCgroup(driver, obj) < 0) + goto error; + + if (qemuDomainPerfRestart(obj) < 0) + goto error; + + /* XXX: Need to change as long as lock is introduced for + * qemu_driver->sharedDevices. + */ + for (i =3D 0; i < obj->def->ndisks; i++) { + virDomainDeviceDef dev; + + if (virStorageTranslateDiskSourcePool(conn, obj->def->disks[i]) < = 0) + goto error; + + /* XXX we should be able to restore all data from XML in the futur= e. + * This should be the only place that calls qemuDomainDetermineDis= kChain + * with @report_broken =3D=3D false to guarantee best-effort domain + * reconnect */ + if (qemuDomainDetermineDiskChain(driver, obj, obj->def->disks[i], + true, false) < 0) + goto error; + + dev.type =3D VIR_DOMAIN_DEVICE_DISK; + dev.data.disk =3D obj->def->disks[i]; + if (qemuAddSharedDevice(driver, &dev, obj->def->name) < 0) + goto error; + } + + if (qemuProcessUpdateState(driver, obj) < 0) + goto error; + + state =3D virDomainObjGetState(obj, &reason); + if (state =3D=3D VIR_DOMAIN_SHUTOFF || + (state =3D=3D VIR_DOMAIN_PAUSED && + reason =3D=3D VIR_DOMAIN_PAUSED_STARTING_UP)) { + VIR_DEBUG("Domain '%s' wasn't fully started yet, killing it", + obj->def->name); + goto error; + } + + /* If upgrading from old libvirtd we won't have found any + * caps in the domain status, so re-query them + */ + if (!priv->qemuCaps && + !(priv->qemuCaps =3D virQEMUCapsCacheLookupCopy(caps, + driver->qemuCapsCach= e, + obj->def->emulator, + obj->def->os.machine= ))) + goto error; + + /* In case the domain shutdown while we were not running, + * we need to finish the shutdown process. And we need to do it after + * we have virQEMUCaps filled in. + */ + if (state =3D=3D VIR_DOMAIN_SHUTDOWN || + (state =3D=3D VIR_DOMAIN_PAUSED && + reason =3D=3D VIR_DOMAIN_PAUSED_SHUTTING_DOWN)) { + VIR_DEBUG("Finishing shutdown sequence for domain %s", + obj->def->name); + qemuProcessShutdownOrReboot(driver, obj); + goto cleanup; + } + + if (qemuProcessBuildDestroyHugepagesPath(driver, obj, NULL, true) < 0) + goto error; + + if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps, + driver, obj, false)) < 0) { + goto error; + } + + /* if domain requests security driver we haven't loaded, report error,= but + * do not kill the domain + */ + ignore_value(qemuSecurityCheckAllLabel(driver->securityManager, + obj->def)); + + if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) = < 0) + goto error; + + qemuDomainVcpuPersistOrder(obj->def); + + if (qemuSecurityReserveLabel(driver->securityManager, obj->def, obj->p= id) < 0) + goto error; + + qemuProcessNotifyNets(obj->def); + + if (qemuProcessFiltersInstantiate(obj->def)) + goto error; + + if (qemuProcessRefreshDisks(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) + goto error; + + if (qemuBlockNodeNamesDetect(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) + goto error; + + if (qemuRefreshVirtioChannelState(driver, obj, QEMU_ASYNC_JOB_NONE) < = 0) + goto error; + + /* If querying of guest's RTC failed, report error, but do not kill th= e domain. */ + qemuRefreshRTC(driver, obj); + + if (qemuProcessRefreshBalloonState(driver, obj, QEMU_ASYNC_JOB_NONE) <= 0) + goto error; + + if (qemuProcessRecoverJob(driver, obj, conn, &oldjob, &stopFlags) < 0) + goto error; + + if (qemuProcessUpdateDevices(driver, obj) < 0) + goto error; + + qemuProcessReconnectCheckMemAliasOrderMismatch(obj); + + if (qemuConnectAgent(driver, obj) < 0) + goto error; + + /* update domain state XML with possibly updated state in virDomainObj= */ + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, obj, driver->ca= ps) < 0) + goto error; + + /* Run an hook to allow admins to do some magic */ + if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { + char *xml =3D qemuDomainDefFormatXML(driver, obj->def, 0); + int hookret; + + hookret =3D virHookCall(VIR_HOOK_DRIVER_QEMU, obj->def->name, + VIR_HOOK_QEMU_OP_RECONNECT, VIR_HOOK_SUBOP_B= EGIN, + NULL, xml, NULL); + VIR_FREE(xml); + + /* + * If the script raised an error abort the launch + */ + if (hookret < 0) + goto error; + } + + if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitCallb= ack) + driver->inhibitCallback(true, driver->inhibitOpaque); + + cleanup: + if (jobStarted) + qemuDomainObjEndJob(driver, obj); + if (!virDomainObjIsActive(obj)) + qemuDomainRemoveInactive(driver, obj); + virDomainObjEndAPI(&obj); + virObjectUnref(conn); + virObjectUnref(cfg); + virObjectUnref(caps); + virNWFilterUnlockFilterUpdates(); + return; + + error: + if (virDomainObjIsActive(obj)) { + /* We can't get the monitor back, so must kill the VM + * to remove danger of it ending up running twice if + * user tries to start it again later + */ + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NO_SHUTDOWN)) { + /* If we couldn't get the monitor and qemu supports + * no-shutdown, we can safely say that the domain + * crashed ... */ + state =3D VIR_DOMAIN_SHUTOFF_CRASHED; + } else { + /* ... but if it doesn't we can't say what the state + * really is and FAILED means "failed to start" */ + state =3D VIR_DOMAIN_SHUTOFF_UNKNOWN; + } + /* If BeginJob failed, we jumped here without a job, let's hope an= other + * thread didn't have a chance to start playing with the domain yet + * (it's all we can do anyway). + */ + qemuProcessStop(driver, obj, state, QEMU_ASYNC_JOB_NONE, stopFlags= ); + } + goto cleanup; +} + +static int +qemuProcessReconnectHelper(virDomainObjPtr obj, + void *opaque) +{ + virThread thread; + struct qemuProcessReconnectData *src =3D opaque; + struct qemuProcessReconnectData *data; + + /* If the VM was inactive, we don't need to reconnect */ + if (!obj->pid) + return 0; + + if (VIR_ALLOC(data) < 0) + return -1; + + memcpy(data, src, sizeof(*data)); + data->obj =3D obj; + + /* this lock and reference will be eventually transferred to the thread + * that handles the reconnect */ + virObjectLock(obj); + virObjectRef(obj); + + /* Since we close the connection later on, we have to make sure that t= he + * threads we start see a valid connection throughout their lifetime. = We + * simply increase the reference counter here. + */ + virObjectRef(data->conn); + + if (virThreadCreate(&thread, false, qemuProcessReconnect, data) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not create thread. QEMU initialization " + "might be incomplete")); + /* We can't spawn a thread and thus connect to monitor. Kill qemu. + * It's safe to call qemuProcessStop without a job here since there + * is no thread that could be doing anything else with the same do= main + * object. + */ + qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED, + QEMU_ASYNC_JOB_NONE, 0); + qemuDomainRemoveInactive(src->driver, obj); + + virDomainObjEndAPI(&obj); + virObjectUnref(data->conn); + VIR_FREE(data); + return -1; + } + + return 0; +} + +/** + * qemuProcessReconnectAll + * + * Try to re-open the resources for live VMs that we care + * about. + */ +void +qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver) +{ + struct qemuProcessReconnectData data =3D {.conn =3D conn, .driver =3D = driver}; + virDomainObjListForEach(driver->domains, qemuProcessReconnectHelper, &= data); +} --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 20:34:04 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499864235484963.3415417860775; Wed, 12 Jul 2017 05:57:15 -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 72AE7C057FAB; Wed, 12 Jul 2017 12:57:10 +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 4E5A26E501; Wed, 12 Jul 2017 12:57:10 +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 EEB1C3FAE4; Wed, 12 Jul 2017 12:57:09 +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 v6CCuxP5022858 for ; Wed, 12 Jul 2017 08:56:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 786EB6BF63; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BCD360841 for ; Wed, 12 Jul 2017 12:56:59 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B586B10086E; Wed, 12 Jul 2017 14:56:54 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 72AE7C057FAB Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 72AE7C057FAB From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 12 Jul 2017 14:56:53 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/7] qemu: Update host-model CPUs on reconnect 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 12 Jul 2017 12:57:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When libvirt starts a new QEMU domain, it replaces host-model CPUs with the appropriate custom CPU definition. However, when reconnecting to a domain started by older libvirt (< 2.3), the domain would still have a host-model CPU in its active definition. https://bugzilla.redhat.com/show_bug.cgi?id=3D1463957 Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 48 +++++++++++++++++++++++++++++++++++++++++++++= +++ 1 file changed, 48 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 2339de41c..0193c3591 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3756,6 +3756,30 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr drive= r, =20 =20 static int +qemuProcessUpdateCPU(virQEMUDriverPtr driver, + virDomainObjPtr vm, + qemuDomainAsyncJob asyncJob) +{ + virCPUDataPtr cpu =3D NULL; + virCPUDataPtr disabled =3D NULL; + int ret =3D -1; + + if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < = 0) + goto cleanup; + + if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virCPUDataFree(cpu); + virCPUDataFree(disabled); + return ret; +} + + +static int qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg, virDomainObjPtr vm) { @@ -6850,6 +6874,30 @@ qemuProcessReconnect(void *opaque) ignore_value(qemuSecurityCheckAllLabel(driver->securityManager, obj->def)); =20 + /* If the domain with a host-model CPU was started by an old libvirt + * (< 2.3) which didn't replace the CPU with a custom one, let's do it= now + * since the rest of our code does not really expect a host-model CPU = in a + * running domain. + */ + if (virQEMUCapsGuestIsNative(caps->host.arch, obj->def->os.arch) && + caps->host.cpu && + obj->def->cpu && + obj->def->cpu->mode =3D=3D VIR_CPU_MODE_HOST_MODEL) { + virCPUDefPtr host; + + if (!(host =3D virCPUCopyMigratable(caps->host.cpu->arch, caps->ho= st.cpu))) + goto error; + + if (virCPUUpdate(obj->def->os.arch, obj->def->cpu, host) < 0) { + virCPUDefFree(host); + goto error; + } + virCPUDefFree(host); + + if (qemuProcessUpdateCPU(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) + goto error; + } + if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) = < 0) goto error; =20 --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list