From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612457896; cv=none; d=zohomail.com; s=zohoarc; b=JvLacKLYqr/9K9wMEoSLGxn1sMgF/J5oxLOIiaErDgAmKgv4wLH9KukCKY17758eMpp8c1+z4wDxGCCLgZ/2b3hNTyGsNdsDCYGoLKWKzsTYwg2NpxM+BvMtds9D+RrYrN5fer84XKrTg9EMQNZM2cAsVowlwtxW5WUw+JhfjUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612457896; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HqI8wcuIzgCOY6SV8v1+SOlkUHDqTVOPvRGtc8JjW1M=; b=TtSXWbkJDzw2NN/iw6nzUgIL5nbTtol+tf9KDW/cAMfPqedC159tfdenrex5sdjdy0mTiRrvF2kvwlrK+sGAqZxqFOEJis/X04CQapUWnXsW71LUKZjrutbusgN2h4xP+rkWeExVvVZDL4At/gSiRtwjDZLS4YOkwCceq/eKkUg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612457896204647.0423740569174; Thu, 4 Feb 2021 08:58:16 -0800 (PST) Received: from localhost ([::1]:53746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7hxO-0004H0-W2 for importer@patchew.org; Thu, 04 Feb 2021 11:58:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hg4-0000oF-1J for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hfx-0004eA-IY for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-2S-9JDjgPuenPbxs5DCagQ-1; Thu, 04 Feb 2021 11:40:10 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E680D18A08BB; Thu, 4 Feb 2021 16:40:08 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B86D1A38C; Thu, 4 Feb 2021 16:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HqI8wcuIzgCOY6SV8v1+SOlkUHDqTVOPvRGtc8JjW1M=; b=OCTzPhw8ls6+Nw0OEdrWnnRurSdKENiwRjx9IMIn26dLDHFcu4T0LDnBeKKwMFUfPLCn+r 2Oayg14KIOaf2MJej6WkDodi/y/DlflpMFq3ld8CxY4HfbP2euWxrJQ07Y+1XYdckeTwpQ v+IB6T9KtLHjyKLjuDm1DDBVr96VRBE= X-MC-Unique: 2S-9JDjgPuenPbxs5DCagQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 01/27] spapr_pci: Fix memory leak of vmstate_spapr_pci Date: Thu, 4 Feb 2021 16:39:33 +0000 Message-Id: <20210204163959.377618-2-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of spapr_pci, the field(msi_devs) of spapr_pci having a flag of VMS_ALLOC need to allocate memory. If the src doesn't free memory of msi_devs in SaveStateEntry of spapr_pci after QEMUFile save VMState of spapr_pci, it may result in memory leak of msi_devs. We add the post_save func to free memory, which prevents memory leak. Reported-by: Euler Robot Signed-off-by: Jinhao Gao Acked-by: David Gibson Reviewed-by: Michael S. Tsirkin Message-Id: <20201231061020.828-2-gaojinhao@huawei.com> Signed-off-by: Dr. David Alan Gilbert --- hw/ppc/spapr_pci.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 76d7c91e9c..1b2b940606 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2173,6 +2173,16 @@ static int spapr_pci_pre_save(void *opaque) return 0; } =20 +static int spapr_pci_post_save(void *opaque) +{ + SpaprPhbState *sphb =3D opaque; + + g_free(sphb->msi_devs); + sphb->msi_devs =3D NULL; + sphb->msi_devs_num =3D 0; + return 0; +} + static int spapr_pci_post_load(void *opaque, int version_id) { SpaprPhbState *sphb =3D opaque; @@ -2205,6 +2215,7 @@ static const VMStateDescription vmstate_spapr_pci =3D= { .version_id =3D 2, .minimum_version_id =3D 2, .pre_save =3D spapr_pci_pre_save, + .post_save =3D spapr_pci_post_save, .post_load =3D spapr_pci_post_load, .fields =3D (VMStateField[]) { VMSTATE_UINT64_EQUAL(buid, SpaprPhbState, NULL), --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459260; cv=none; d=zohomail.com; s=zohoarc; b=LK8hZDOV7J9AuDUoRbFcitvmjawnbj4EafEVLO+AvfJ31GRZu5FkxdvuoY6OD9YyFTd2a2dXzf1JCcrj4eGAZz5Vz5nNGb1U7Qp3Uf04QE1xLK5gY6y+vjAaMPEx5pyY07t8SDKKL4+ZlB5fh+6BbV+vksz/t0v3cMw0rBP+DaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459260; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8TC0oIbcH2+Jl5Clk2QXKmW8utKg37UsUy5kd2yakaA=; b=L11DpmC8nBlFozjTBZTB9QdORwCK3p3nMrnf9iCa+D8B5fwu9e7CGOIwXtXBOONmOyW+KjdOsR+ENprrjvmpSBttNvArFwyOQfuug1Lixk38ia/cCzaPd5gdMuMj5+VBNkoJlVkN7gApZwEP5B4AoFWPGac0Gahpk8zdTpxaRsA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161245926074298.04387596651509; Thu, 4 Feb 2021 09:21:00 -0800 (PST) Received: from localhost ([::1]:53854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iJP-0007n7-Mj for importer@patchew.org; Thu, 04 Feb 2021 12:20:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgA-0000qm-5c for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hfz-0004eR-ED for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:25 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-QvdY4RmIPoeTn1x2NoMgfQ-1; Thu, 04 Feb 2021 11:40:12 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BA9B9126D; Thu, 4 Feb 2021 16:40:11 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BADE17F6B; Thu, 4 Feb 2021 16:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8TC0oIbcH2+Jl5Clk2QXKmW8utKg37UsUy5kd2yakaA=; b=jTOaWrpaV2s6G/dqzC03d81zuxFegjEsGhkpun6qS/KGs0KULFci+JDejkNRow3EB4tTY1 Tb5URbE1YDbFQToJF5CwH+TSjwauYvwzVz7a5uGfHeHfXSp5lWmYtY6UfwoDoFjJ27ij2i lwUSwOKGmU8tt3bK+Vsl8fiEtxdSx5M= X-MC-Unique: QvdY4RmIPoeTn1x2NoMgfQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 02/27] savevm: Fix memory leak of vmstate_configuration Date: Thu, 4 Feb 2021 16:39:34 +0000 Message-Id: <20210204163959.377618-3-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of configuration, the fields(name and capabilities) of configuration having a flag of VMS_ALLOC need to allocate memory. If the src doesn't free memory of capabilities in SaveState after save VMState of configuration, or the dst doesn't free memory of name and capabilities in p= ost load of configuration, it may result in memory leak of name and capabilitie= s. We free memory in configuration_post_save and configuration_post_load func, which prevents memory leak. Reported-by: Euler Robot Signed-off-by: Jinhao Gao Reviewed-by: Michael S. Tsirkin Message-Id: <20201231061020.828-3-gaojinhao@huawei.com> Signed-off-by: Dr. David Alan Gilbert --- migration/savevm.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 4f3b69ecfc..d1e6aaed60 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -315,6 +315,16 @@ static int configuration_pre_save(void *opaque) return 0; } =20 +static int configuration_post_save(void *opaque) +{ + SaveState *state =3D opaque; + + g_free(state->capabilities); + state->capabilities =3D NULL; + state->caps_count =3D 0; + return 0; +} + static int configuration_pre_load(void *opaque) { SaveState *state =3D opaque; @@ -365,24 +375,36 @@ static int configuration_post_load(void *opaque, int = version_id) { SaveState *state =3D opaque; const char *current_name =3D MACHINE_GET_CLASS(current_machine)->name; + int ret =3D 0; =20 if (strncmp(state->name, current_name, state->len) !=3D 0) { error_report("Machine type received is '%.*s' and local is '%s'", (int) state->len, state->name, current_name); - return -EINVAL; + ret =3D -EINVAL; + goto out; } =20 if (state->target_page_bits !=3D qemu_target_page_bits()) { error_report("Received TARGET_PAGE_BITS is %d but local is %d", state->target_page_bits, qemu_target_page_bits()); - return -EINVAL; + ret =3D -EINVAL; + goto out; } =20 if (!configuration_validate_capabilities(state)) { - return -EINVAL; + ret =3D -EINVAL; + goto out; } =20 - return 0; +out: + g_free((void *)state->name); + state->name =3D NULL; + state->len =3D 0; + g_free(state->capabilities); + state->capabilities =3D NULL; + state->caps_count =3D 0; + + return ret; } =20 static int get_capability(QEMUFile *f, void *pv, size_t size, @@ -516,6 +538,7 @@ static const VMStateDescription vmstate_configuration = =3D { .pre_load =3D configuration_pre_load, .post_load =3D configuration_post_load, .pre_save =3D configuration_pre_save, + .post_save =3D configuration_post_save, .fields =3D (VMStateField[]) { VMSTATE_UINT32(len, SaveState), VMSTATE_VBUFFER_ALLOC_UINT32(name, SaveState, 0, NULL, len), --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612458889; cv=none; d=zohomail.com; s=zohoarc; b=Q5NVOGFlnN+KZlwruxngxudvEMrUh+AZL9V/UICZm6Fm6bx1Gsgj7+yQTzNdAOlrw5XW0KNc0cRK7yAg9wIog1Pl932zTbM07Ak53V4CqykemaxEfelkpkKUPsF+Nzol0CrywEi+JXtrxPKCjjrZTAaPY43MR8PoFxWdjv3UCLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612458889; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qq8PHy6Wlmp7l579fTWql1UlYrUS7y4sJ0f4EoZn+jg=; b=BI84WURINNhIriMXleSjfsoNysMPgAHvFvpYKwsFXPVStwOj6RoYfXvcz/bI1GfqF11Vt8ynPSaokNOfvCNtOU2TWJ+avAoTE55VQn9ONh9Krem+IlJSahz2Rio/wSWM+jGQTxbb2xCPdSS2rhSHHuXpROugPfVT3I3xRPg2wFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612458889303572.2522988651755; Thu, 4 Feb 2021 09:14:49 -0800 (PST) Received: from localhost ([::1]:37610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iDQ-0000eK-0e for importer@patchew.org; Thu, 04 Feb 2021 12:14:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hg4-0000oN-Tk for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hg2-0004hW-MN for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:20 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-314-uQztrlNdPg6EyOfirTKSvQ-1; Thu, 04 Feb 2021 11:40:15 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0B1B80197E; Thu, 4 Feb 2021 16:40:13 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57F7E1A26A; Thu, 4 Feb 2021 16:40:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qq8PHy6Wlmp7l579fTWql1UlYrUS7y4sJ0f4EoZn+jg=; b=LeG53sjOGHxnOt8iKpph+Q/PwSGzftE/IRrekkfbGH0SGrSh9n/8ALpe/fCle1vrug654l F5YWOX+SOShPjS01CHoUDSCkAr91dqse6hzulImsFlVw1dF4ca0Oombxcfip9MRQmCzMBc rohqLOZL6iGJgabxze0pjLdwYH536T0= X-MC-Unique: uQztrlNdPg6EyOfirTKSvQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 03/27] vmstate: Fix memory leak in vmstate_handle_alloc() Date: Thu, 4 Feb 2021 16:39:35 +0000 Message-Id: <20210204163959.377618-4-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Jinhao Gao Some memory allocated for fields having a flag of VMS_ALLOC in SaveState may not free before VM load vmsd in migration. So we pre-free memory before allocation in vmstate_handle_alloc() to avoid memleaks. Reported-by: Euler Robot Signed-off-by: Jinhao Gao Signed-off-by: Michael S. Tsirkin Message-Id: <20201231061020.828-4-gaojinhao@huawei.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/vmstate.c | 1 + 1 file changed, 1 insertion(+) diff --git a/migration/vmstate.c b/migration/vmstate.c index 05f87cdddc..cc3dfcbae8 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -70,6 +70,7 @@ static void vmstate_handle_alloc(void *ptr, const VMState= Field *field, gsize size =3D vmstate_size(opaque, field); size *=3D vmstate_n_elems(opaque, field); if (size) { + g_free(*(void **)ptr); *(void **)ptr =3D g_malloc(size); } } --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612458166; cv=none; d=zohomail.com; s=zohoarc; b=LZ7ZI7qjzFCRjnZcg7VuUsDbU8PyD60P3IOT5RcgxQalLqqToSvRz0/wwy5FQMb2Ao9oSGzeDuEbf7A1U0TpeZOUnuAstqCLg2XIvLWPzg2zoVI94cPWFhTBwtZ61r5+cura+w/N5i19/N+sR6wBKuKCSE41GcK1FB67s2XF7jQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612458166; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3vXMSx8tBHjuAR1hOP6K8bLGwgTN6GjxBU+w/TaZl5M=; b=QuvNlOq2iBpFtJhzgE4iGMY6kRYba+DyQV4SU8Dx50CeO2MxvBxtYGjFWrDI+UlBiZDWNFu+8dNGqJpy+0rOU/Qb5fRwNVYUnOJhfQY5aqwR8JcG6l8A8+Zb6ahgupW2qoLQeEzHLWXPiW49CYGF2n7wT2+0zfTuZF+pTFWG/7Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612458166549391.4429926795117; Thu, 4 Feb 2021 09:02:46 -0800 (PST) Received: from localhost ([::1]:34226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7i1k-00013v-4z for importer@patchew.org; Thu, 04 Feb 2021 12:02:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgG-0000su-Hf for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39772) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hg4-0004if-Ig for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:32 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-190-0I8otypBPVOUyXK7fItCqA-1; Thu, 04 Feb 2021 11:40:17 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE5EE1935790; Thu, 4 Feb 2021 16:40:15 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16D781A38C; Thu, 4 Feb 2021 16:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3vXMSx8tBHjuAR1hOP6K8bLGwgTN6GjxBU+w/TaZl5M=; b=PLfFuZAbbqaUYwdB1VlUm07aBCf3Qf6I53lbyR/DYpxtmU5btHXWxHgb1FL6Z0amrBfmSa qlAILb0pM+rJk4li0BLaH01BG9XQvyVMhZQFaB4zGKTnJdDmcv8BjXRIeI+5Qnkenr9EMc 7bs2WKA9iK/BdCc8nCm4cYrQJTxzFT0= X-MC-Unique: 0I8otypBPVOUyXK7fItCqA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 04/27] migration/qemu-file: Fix maybe uninitialized on qemu_get_buffer_in_place() Date: Thu, 4 Feb 2021 16:39:36 +0000 Message-Id: <20210204163959.377618-5-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Wainer dos Santos Moschetta Fixed error when compiling migration/qemu-file.c with -Werror=3Dmaybe-unini= tialized as shown here: ../migration/qemu-file.c: In function 'qemu_get_buffer_in_place': ../migration/qemu-file.c:604:18: error: 'src' may be used uninitialized in = this function [-Werror=3Dmaybe-uninitialized] 604 | *buf =3D src; | ~~~~~^~~~~ cc1: all warnings being treated as errors Signed-off-by: Wainer dos Santos Moschetta Message-Id: <20210128130625.569900-1-wainersm@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index be21518c57..d6e03dbc0e 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -595,7 +595,7 @@ size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **= buf, size_t size) { if (size < IO_BUF_SIZE) { size_t res; - uint8_t *src; + uint8_t *src =3D NULL; =20 res =3D qemu_peek_buffer(f, &src, size, 0); =20 --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459132; cv=none; d=zohomail.com; s=zohoarc; b=cA5gpTNLh4TP5ivpLVDij9RX9OupvUN7hmpDgu+Wf+5BDdRf7Bx3BZYT0ubMGrEephqSwBCq3JJHrbxZKBD+bHpFk2v4H0htXHBz+EQoECBAJcI4uE0yprd6RHHPNmrhzUixjs5sNCuqni464gkEPjNnpwf+qsef3ZuDmxq9Eik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459132; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xcb4G8369t2XeFuLgAX+GndF/xmjtPSZoLxt6aho764=; b=koIdDOHX5maKgOzaAcbADip7y2+yFbgJ4cfQXq2oGeInm8imiVEI0SR87IxPS2KWzl8/YwnuoQlT8ay3ivrabdpzt9e4uKOJPFLkD03MivEjdvnS/xF2xEMHtjQ2qD6W8K1sP7WTE83/lDs45ZNH4onafnucKIa6wLHLFDf0Zm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459132615708.4180747096685; Thu, 4 Feb 2021 09:18:52 -0800 (PST) Received: from localhost ([::1]:49376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iHL-0005hA-9I for importer@patchew.org; Thu, 04 Feb 2021 12:18:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgN-00012L-5o for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hgI-0004mm-EH for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-3-ug24MOxXM5uK3PZbnERUuw-1; Thu, 04 Feb 2021 11:40:26 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B7E5801962; Thu, 4 Feb 2021 16:40:25 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 702491A26A; Thu, 4 Feb 2021 16:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xcb4G8369t2XeFuLgAX+GndF/xmjtPSZoLxt6aho764=; b=ND8C1eH4dGd9aL8aIzv6i4Ryx6Z5hkZfbniKRQZEEEMfGnq03dBCsZRp9HYupxQ3v5c+cz PphtuK7DZrP8pFeBW/b2beKlWFBd7AY72pFTSJJUR1tLn3hDEJFTOrjUwS65QwRdlBq3BL RnB4hJ63dx2NVMInaxP4Rrri7PQTk6k= X-MC-Unique: ug24MOxXM5uK3PZbnERUuw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 05/27] migration: introduce 'background-snapshot' migration capability Date: Thu, 4 Feb 2021 16:39:37 +0000 Message-Id: <20210204163959.377618-6-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Andrey Gruzdev Add new capability to 'qapi/migration.json' schema. Update migrate_caps_check() to validate enabled capability set against introduced one. Perform checks for required kernel features and compatibility with guest memory backends. Signed-off-by: Andrey Gruzdev Reviewed-by: Peter Xu Acked-by: Markus Armbruster Message-Id: <20210129101407.103458-2-andrey.gruzdev@virtuozzo.com> Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 102 ++++++++++++++++++++++++++++++++++++++++++ migration/migration.h | 1 + migration/ram.c | 21 +++++++++ migration/ram.h | 4 ++ qapi/migration.json | 7 ++- 5 files changed, 134 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 1986cb8573..2262f348af 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -58,6 +58,7 @@ #include "qemu/queue.h" #include "multifd.h" #include "qemu/yank.h" +#include "sysemu/cpus.h" =20 #ifdef CONFIG_VFIO #include "hw/vfio/vfio-common.h" @@ -134,6 +135,38 @@ enum mig_rp_message_type { MIG_RP_MSG_MAX }; =20 +/* Migration capabilities set */ +struct MigrateCapsSet { + int size; /* Capability set size */ + MigrationCapability caps[]; /* Variadic array of capabilities */ +}; +typedef struct MigrateCapsSet MigrateCapsSet; + +/* Define and initialize MigrateCapsSet */ +#define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \ + MigrateCapsSet _name =3D { \ + .size =3D sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \ + .caps =3D { __VA_ARGS__ } \ + } + +/* Background-snapshot compatibility check list */ +static const +INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot, + MIGRATION_CAPABILITY_POSTCOPY_RAM, + MIGRATION_CAPABILITY_DIRTY_BITMAPS, + MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME, + MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE, + MIGRATION_CAPABILITY_RETURN_PATH, + MIGRATION_CAPABILITY_MULTIFD, + MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER, + MIGRATION_CAPABILITY_AUTO_CONVERGE, + MIGRATION_CAPABILITY_RELEASE_RAM, + MIGRATION_CAPABILITY_RDMA_PIN_ALL, + MIGRATION_CAPABILITY_COMPRESS, + MIGRATION_CAPABILITY_XBZRLE, + MIGRATION_CAPABILITY_X_COLO, + MIGRATION_CAPABILITY_VALIDATE_UUID); + /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add dynamic creation of migration */ @@ -1089,6 +1122,31 @@ static void fill_source_migration_info(MigrationInfo= *info) info->status =3D s->state; } =20 +typedef enum WriteTrackingSupport { + WT_SUPPORT_UNKNOWN =3D 0, + WT_SUPPORT_ABSENT, + WT_SUPPORT_AVAILABLE, + WT_SUPPORT_COMPATIBLE +} WriteTrackingSupport; + +static +WriteTrackingSupport migrate_query_write_tracking(void) +{ + /* Check if kernel supports required UFFD features */ + if (!ram_write_tracking_available()) { + return WT_SUPPORT_ABSENT; + } + /* + * Check if current memory configuration is + * compatible with required UFFD features. + */ + if (!ram_write_tracking_compatible()) { + return WT_SUPPORT_AVAILABLE; + } + + return WT_SUPPORT_COMPATIBLE; +} + /** * @migration_caps_check - check capability validity * @@ -1150,6 +1208,39 @@ static bool migrate_caps_check(bool *cap_list, } } =20 + if (cap_list[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { + WriteTrackingSupport wt_support; + int idx; + /* + * Check if 'background-snapshot' capability is supported by + * host kernel and compatible with guest memory configuration. + */ + wt_support =3D migrate_query_write_tracking(); + if (wt_support < WT_SUPPORT_AVAILABLE) { + error_setg(errp, "Background-snapshot is not supported by host= kernel"); + return false; + } + if (wt_support < WT_SUPPORT_COMPATIBLE) { + error_setg(errp, "Background-snapshot is not compatible " + "with guest memory configuration"); + return false; + } + + /* + * Check if there are any migration capabilities + * incompatible with 'background-snapshot'. + */ + for (idx =3D 0; idx < check_caps_background_snapshot.size; idx++) { + int incomp_cap =3D check_caps_background_snapshot.caps[idx]; + if (cap_list[incomp_cap]) { + error_setg(errp, + "Background-snapshot is not compatible with %s", + MigrationCapability_str(incomp_cap)); + return false; + } + } + } + return true; } =20 @@ -2491,6 +2582,15 @@ bool migrate_use_block_incremental(void) return s->parameters.block_incremental; } =20 +bool migrate_background_snapshot(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHO= T]; +} + /* migration thread support */ /* * Something bad happened to the RP stream, mark an error @@ -3784,6 +3884,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK), DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH), DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD), + DEFINE_PROP_MIG_CAP("x-background-snapshot", + MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT), =20 DEFINE_PROP_END_OF_LIST(), }; diff --git a/migration/migration.h b/migration/migration.h index d096b77f74..f40338cfbf 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -341,6 +341,7 @@ int migrate_compress_wait_thread(void); int migrate_decompress_threads(void); bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); +bool migrate_background_snapshot(void); =20 /* Sending on the return path - generic and then for each message type */ void migrate_send_rp_shut(MigrationIncomingState *mis, diff --git a/migration/ram.c b/migration/ram.c index 7811cde643..ae8de17153 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3788,6 +3788,27 @@ static int ram_resume_prepare(MigrationState *s, voi= d *opaque) return 0; } =20 +/* ram_write_tracking_available: check if kernel supports required UFFD fe= atures + * + * Returns true if supports, false otherwise + */ +bool ram_write_tracking_available(void) +{ + /* TODO: implement */ + return false; +} + +/* ram_write_tracking_compatible: check if guest configuration is + * compatible with 'write-tracking' + * + * Returns true if compatible, false otherwise + */ +bool ram_write_tracking_compatible(void) +{ + /* TODO: implement */ + return false; +} + static SaveVMHandlers savevm_ram_handlers =3D { .save_setup =3D ram_save_setup, .save_live_iterate =3D ram_save_iterate, diff --git a/migration/ram.h b/migration/ram.h index 011e85414e..1a9ff90304 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -79,4 +79,8 @@ void colo_flush_ram_cache(void); void colo_release_ram_cache(void); void colo_incoming_start_dirty_log(void); =20 +/* Background snapshot */ +bool ram_write_tracking_available(void); +bool ram_write_tracking_compatible(void); + #endif diff --git a/qapi/migration.json b/qapi/migration.json index d1d9632c2a..6c12b368aa 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -442,6 +442,11 @@ # @validate-uuid: Send the UUID of the source to allow the destination # to ensure it is the same. (since 4.2) # +# @background-snapshot: If enabled, the migration stream will be a snapshot +# of the VM exactly at the point when the migration +# procedure starts. The VM RAM is saved with running= VM. +# (since 6.0) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', @@ -449,7 +454,7 @@ 'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram', 'block', 'return-path', 'pause-before-switchover', 'multifd', 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', - 'x-ignore-shared', 'validate-uuid' ] } + 'x-ignore-shared', 'validate-uuid', 'background-snapshot'] } =20 ## # @MigrationCapabilityStatus: --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459377; cv=none; d=zohomail.com; s=zohoarc; b=Ek2Q15HwNrk1dyhzGDyTRiIgN3pBpTRbasBpauVtUg+J3c5TGT0U5OBIIBYqFCUKReWfkAK8CcKJVr5miyXGeivV1nJJRKtCmP7mGjXqCPzEP7CmuregkU1sOkPA/2QhqQxrloaXE4olNhRrDm7HWj0aVaUVm1dqyrxc27TCJuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459377; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pKN/6mhZxJuaALzAGSZX4YBfiVSNJSmIaYCbzbvtIT8=; b=ZmdoSVlMpXCsVfFj5EVc8trza4w0/vVN8iagTj1sNt2ypAxOHsxCBU3bMoM1UdjRhDQtXXkvFcD6wCEw6Tik7JW3aA5/RU5bmlLWwPZgSXmj5mpsN99B237yKF8vCx/OVDOAyQMPDjeCXkO7a+OPxzAkdJ2z28eUFPYtjjdz6qg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459377542141.33913818848703; Thu, 4 Feb 2021 09:22:57 -0800 (PST) Received: from localhost ([::1]:57892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iLH-0001Ty-3l for importer@patchew.org; Thu, 04 Feb 2021 12:22:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgO-00016Z-Lf for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hgM-0004pi-0g for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-319-1SFSq0OyNdyN_kIHQvToGg-1; Thu, 04 Feb 2021 11:40:35 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1645804022; Thu, 4 Feb 2021 16:40:33 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AAE719708; Thu, 4 Feb 2021 16:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456837; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pKN/6mhZxJuaALzAGSZX4YBfiVSNJSmIaYCbzbvtIT8=; b=KY2vpf4YsDhj0mbPOIWDrR2siSDsURf5VrPzscO/eKWpQcKFI9znqAf3kY09NcmsHmjNiH 0JmpJl7g9iHegWfyAJw9JTmUDGPuPdmO6G0zlb0UZwA4mssdelM/ULaeup3XS7mWTEcuVM JIjyOLUxGFTTPzTeiLAKDQ4SItQqenM= X-MC-Unique: 1SFSq0OyNdyN_kIHQvToGg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 06/27] migration: introduce UFFD-WP low-level interface helpers Date: Thu, 4 Feb 2021 16:39:38 +0000 Message-Id: <20210204163959.377618-7-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Andrey Gruzdev Glue code to the userfaultfd kernel implementation. Querying feature support, createing file descriptor, feature control, memory region registration, IOCTLs on registered registered regions. Signed-off-by: Andrey Gruzdev Reviewed-by: Peter Xu Message-Id: <20210129101407.103458-3-andrey.gruzdev@virtuozzo.com> Signed-off-by: Dr. David Alan Gilbert Fixed up range.start casting for 32bit --- include/exec/memory.h | 1 + include/qemu/userfaultfd.h | 35 ++++ util/meson.build | 1 + util/trace-events | 9 + util/userfaultfd.c | 345 +++++++++++++++++++++++++++++++++++++ 5 files changed, 391 insertions(+) create mode 100644 include/qemu/userfaultfd.h create mode 100644 util/userfaultfd.c diff --git a/include/exec/memory.h b/include/exec/memory.h index c6ce74fb79..37096217e7 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -149,6 +149,7 @@ typedef struct IOMMUTLBEvent { /* RAM is a persistent kind memory */ #define RAM_PMEM (1 << 5) =20 + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, diff --git a/include/qemu/userfaultfd.h b/include/qemu/userfaultfd.h new file mode 100644 index 0000000000..6b74f92792 --- /dev/null +++ b/include/qemu/userfaultfd.h @@ -0,0 +1,35 @@ +/* + * Linux UFFD-WP support + * + * Copyright Virtuozzo GmbH, 2020 + * + * Authors: + * Andrey Gruzdev + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef USERFAULTFD_H +#define USERFAULTFD_H + +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include + +int uffd_query_features(uint64_t *features); +int uffd_create_fd(uint64_t features, bool non_blocking); +void uffd_close_fd(int uffd_fd); +int uffd_register_memory(int uffd_fd, void *addr, uint64_t length, + uint64_t mode, uint64_t *ioctls); +int uffd_unregister_memory(int uffd_fd, void *addr, uint64_t length); +int uffd_change_protection(int uffd_fd, void *addr, uint64_t length, + bool wp, bool dont_wake); +int uffd_copy_page(int uffd_fd, void *dst_addr, void *src_addr, + uint64_t length, bool dont_wake); +int uffd_zero_page(int uffd_fd, void *addr, uint64_t length, bool dont_wak= e); +int uffd_wakeup(int uffd_fd, void *addr, uint64_t length); +int uffd_read_events(int uffd_fd, struct uffd_msg *msgs, int count); +bool uffd_poll_events(int uffd_fd, int tmo); + +#endif /* USERFAULTFD_H */ diff --git a/util/meson.build b/util/meson.build index 3eccdbe596..984fba965f 100644 --- a/util/meson.build +++ b/util/meson.build @@ -52,6 +52,7 @@ if have_system util_ss.add(files('crc-ccitt.c')) util_ss.add(when: 'CONFIG_GIO', if_true: [files('dbus.c'), gio]) util_ss.add(files('yank.c')) + util_ss.add(when: 'CONFIG_LINUX', if_true: files('userfaultfd.c')) endif =20 if have_block diff --git a/util/trace-events b/util/trace-events index 61e0d4bcdf..bac0924899 100644 --- a/util/trace-events +++ b/util/trace-events @@ -91,3 +91,12 @@ qemu_vfio_pci_read_config(void *buf, int ofs, int size, = uint64_t region_ofs, uin qemu_vfio_pci_write_config(void *buf, int ofs, int size, uint64_t region_o= fs, uint64_t region_size) "write cfg ptr %p ofs 0x%x size 0x%x (region addr= 0x%"PRIx64" size 0x%"PRIx64")" qemu_vfio_region_info(const char *desc, uint64_t region_ofs, uint64_t regi= on_size, uint32_t cap_offset) "region '%s' addr 0x%"PRIx64" size 0x%"PRIx64= " cap_ofs 0x%"PRIx32 qemu_vfio_pci_map_bar(int index, uint64_t region_ofs, uint64_t region_size= , int ofs, void *host) "map region bar#%d addr 0x%"PRIx64" size 0x%"PRIx64"= ofs 0x%x host %p" + +#userfaultfd.c +uffd_query_features_nosys(int err) "errno: %i" +uffd_query_features_api_failed(int err) "errno: %i" +uffd_create_fd_nosys(int err) "errno: %i" +uffd_create_fd_api_failed(int err) "errno: %i" +uffd_create_fd_api_noioctl(uint64_t ioctl_req, uint64_t ioctl_supp) "ioctl= _req: 0x%" PRIx64 "ioctl_supp: 0x%" PRIx64 +uffd_register_memory_failed(void *addr, uint64_t length, uint64_t mode, in= t err) "addr: %p length: %" PRIu64 " mode: 0x%" PRIx64 " errno: %i" +uffd_unregister_memory_failed(void *addr, uint64_t length, int err) "addr:= %p length: %" PRIu64 " errno: %i" diff --git a/util/userfaultfd.c b/util/userfaultfd.c new file mode 100644 index 0000000000..f1cd6af2b1 --- /dev/null +++ b/util/userfaultfd.c @@ -0,0 +1,345 @@ +/* + * Linux UFFD-WP support + * + * Copyright Virtuozzo GmbH, 2020 + * + * Authors: + * Andrey Gruzdev + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/bitops.h" +#include "qemu/error-report.h" +#include "qemu/userfaultfd.h" +#include "trace.h" +#include +#include +#include + +/** + * uffd_query_features: query UFFD features + * + * Returns: 0 on success, negative value in case of an error + * + * @features: parameter to receive 'uffdio_api.features' + */ +int uffd_query_features(uint64_t *features) +{ + int uffd_fd; + struct uffdio_api api_struct =3D { 0 }; + int ret =3D -1; + + uffd_fd =3D syscall(__NR_userfaultfd, O_CLOEXEC); + if (uffd_fd < 0) { + trace_uffd_query_features_nosys(errno); + return -1; + } + + api_struct.api =3D UFFD_API; + api_struct.features =3D 0; + + if (ioctl(uffd_fd, UFFDIO_API, &api_struct)) { + trace_uffd_query_features_api_failed(errno); + goto out; + } + *features =3D api_struct.features; + ret =3D 0; + +out: + close(uffd_fd); + return ret; +} + +/** + * uffd_create_fd: create UFFD file descriptor + * + * Returns non-negative file descriptor or negative value in case of an er= ror + * + * @features: UFFD features to request + * @non_blocking: create UFFD file descriptor for non-blocking operation + */ +int uffd_create_fd(uint64_t features, bool non_blocking) +{ + int uffd_fd; + int flags; + struct uffdio_api api_struct =3D { 0 }; + uint64_t ioctl_mask =3D BIT(_UFFDIO_REGISTER) | BIT(_UFFDIO_UNREGISTER= ); + + flags =3D O_CLOEXEC | (non_blocking ? O_NONBLOCK : 0); + uffd_fd =3D syscall(__NR_userfaultfd, flags); + if (uffd_fd < 0) { + trace_uffd_create_fd_nosys(errno); + return -1; + } + + api_struct.api =3D UFFD_API; + api_struct.features =3D features; + if (ioctl(uffd_fd, UFFDIO_API, &api_struct)) { + trace_uffd_create_fd_api_failed(errno); + goto fail; + } + if ((api_struct.ioctls & ioctl_mask) !=3D ioctl_mask) { + trace_uffd_create_fd_api_noioctl(ioctl_mask, api_struct.ioctls); + goto fail; + } + + return uffd_fd; + +fail: + close(uffd_fd); + return -1; +} + +/** + * uffd_close_fd: close UFFD file descriptor + * + * @uffd_fd: UFFD file descriptor + */ +void uffd_close_fd(int uffd_fd) +{ + assert(uffd_fd >=3D 0); + close(uffd_fd); +} + +/** + * uffd_register_memory: register memory range via UFFD-IO + * + * Returns 0 in case of success, negative value in case of an error + * + * @uffd_fd: UFFD file descriptor + * @addr: base address of memory range + * @length: length of memory range + * @mode: UFFD register mode (UFFDIO_REGISTER_MODE_MISSING, ...) + * @ioctls: optional pointer to receive supported IOCTL mask + */ +int uffd_register_memory(int uffd_fd, void *addr, uint64_t length, + uint64_t mode, uint64_t *ioctls) +{ + struct uffdio_register uffd_register; + + uffd_register.range.start =3D (uintptr_t) addr; + uffd_register.range.len =3D length; + uffd_register.mode =3D mode; + + if (ioctl(uffd_fd, UFFDIO_REGISTER, &uffd_register)) { + trace_uffd_register_memory_failed(addr, length, mode, errno); + return -1; + } + if (ioctls) { + *ioctls =3D uffd_register.ioctls; + } + + return 0; +} + +/** + * uffd_unregister_memory: un-register memory range with UFFD-IO + * + * Returns 0 in case of success, negative value in case of an error + * + * @uffd_fd: UFFD file descriptor + * @addr: base address of memory range + * @length: length of memory range + */ +int uffd_unregister_memory(int uffd_fd, void *addr, uint64_t length) +{ + struct uffdio_range uffd_range; + + uffd_range.start =3D (uintptr_t) addr; + uffd_range.len =3D length; + + if (ioctl(uffd_fd, UFFDIO_UNREGISTER, &uffd_range)) { + trace_uffd_unregister_memory_failed(addr, length, errno); + return -1; + } + + return 0; +} + +/** + * uffd_change_protection: protect/un-protect memory range for writes via = UFFD-IO + * + * Returns 0 on success, negative value in case of error + * + * @uffd_fd: UFFD file descriptor + * @addr: base address of memory range + * @length: length of memory range + * @wp: write-protect/unprotect + * @dont_wake: do not wake threads waiting on wr-protected page + */ +int uffd_change_protection(int uffd_fd, void *addr, uint64_t length, + bool wp, bool dont_wake) +{ + struct uffdio_writeprotect uffd_writeprotect; + + uffd_writeprotect.range.start =3D (uintptr_t) addr; + uffd_writeprotect.range.len =3D length; + if (!wp && dont_wake) { + /* DONTWAKE is meaningful only on protection release */ + uffd_writeprotect.mode =3D UFFDIO_WRITEPROTECT_MODE_DONTWAKE; + } else { + uffd_writeprotect.mode =3D (wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0); + } + + if (ioctl(uffd_fd, UFFDIO_WRITEPROTECT, &uffd_writeprotect)) { + error_report("uffd_change_protection() failed: addr=3D%p len=3D%" = PRIu64 + " mode=3D%" PRIx64 " errno=3D%i", addr, length, + (uint64_t) uffd_writeprotect.mode, errno); + return -1; + } + + return 0; +} + +/** + * uffd_copy_page: copy range of pages to destination via UFFD-IO + * + * Copy range of source pages to the destination to resolve + * missing page fault somewhere in the destination range. + * + * Returns 0 on success, negative value in case of an error + * + * @uffd_fd: UFFD file descriptor + * @dst_addr: destination base address + * @src_addr: source base address + * @length: length of the range to copy + * @dont_wake: do not wake threads waiting on missing page + */ +int uffd_copy_page(int uffd_fd, void *dst_addr, void *src_addr, + uint64_t length, bool dont_wake) +{ + struct uffdio_copy uffd_copy; + + uffd_copy.dst =3D (uintptr_t) dst_addr; + uffd_copy.src =3D (uintptr_t) src_addr; + uffd_copy.len =3D length; + uffd_copy.mode =3D dont_wake ? UFFDIO_COPY_MODE_DONTWAKE : 0; + + if (ioctl(uffd_fd, UFFDIO_COPY, &uffd_copy)) { + error_report("uffd_copy_page() failed: dst_addr=3D%p src_addr=3D%p= length=3D%" PRIu64 + " mode=3D%" PRIx64 " errno=3D%i", dst_addr, src_addr, + length, (uint64_t) uffd_copy.mode, errno); + return -1; + } + + return 0; +} + +/** + * uffd_zero_page: fill range of pages with zeroes via UFFD-IO + * + * Fill range pages with zeroes to resolve missing page fault within the r= ange. + * + * Returns 0 on success, negative value in case of an error + * + * @uffd_fd: UFFD file descriptor + * @addr: base address + * @length: length of the range to fill with zeroes + * @dont_wake: do not wake threads waiting on missing page + */ +int uffd_zero_page(int uffd_fd, void *addr, uint64_t length, bool dont_wak= e) +{ + struct uffdio_zeropage uffd_zeropage; + + uffd_zeropage.range.start =3D (uintptr_t) addr; + uffd_zeropage.range.len =3D length; + uffd_zeropage.mode =3D dont_wake ? UFFDIO_ZEROPAGE_MODE_DONTWAKE : 0; + + if (ioctl(uffd_fd, UFFDIO_ZEROPAGE, &uffd_zeropage)) { + error_report("uffd_zero_page() failed: addr=3D%p length=3D%" PRIu64 + " mode=3D%" PRIx64 " errno=3D%i", addr, length, + (uint64_t) uffd_zeropage.mode, errno); + return -1; + } + + return 0; +} + +/** + * uffd_wakeup: wake up threads waiting on page UFFD-managed page fault re= solution + * + * Wake up threads waiting on any page/pages from the designated range. + * The main use case is when during some period, page faults are resolved + * via UFFD-IO IOCTLs with MODE_DONTWAKE flag set, then after that all wai= ts + * for the whole memory range are satisfied in a single call to uffd_wakeu= p(). + * + * Returns 0 on success, negative value in case of an error + * + * @uffd_fd: UFFD file descriptor + * @addr: base address + * @length: length of the range + */ +int uffd_wakeup(int uffd_fd, void *addr, uint64_t length) +{ + struct uffdio_range uffd_range; + + uffd_range.start =3D (uintptr_t) addr; + uffd_range.len =3D length; + + if (ioctl(uffd_fd, UFFDIO_WAKE, &uffd_range)) { + error_report("uffd_wakeup() failed: addr=3D%p length=3D%" PRIu64 "= errno=3D%i", + addr, length, errno); + return -1; + } + + return 0; +} + +/** + * uffd_read_events: read pending UFFD events + * + * Returns number of fetched messages, 0 if non is available or + * negative value in case of an error + * + * @uffd_fd: UFFD file descriptor + * @msgs: pointer to message buffer + * @count: number of messages that can fit in the buffer + */ +int uffd_read_events(int uffd_fd, struct uffd_msg *msgs, int count) +{ + ssize_t res; + do { + res =3D read(uffd_fd, msgs, count * sizeof(struct uffd_msg)); + } while (res < 0 && errno =3D=3D EINTR); + + if ((res < 0 && errno =3D=3D EAGAIN)) { + return 0; + } + if (res < 0) { + error_report("uffd_read_events() failed: errno=3D%i", errno); + return -1; + } + + return (int) (res / sizeof(struct uffd_msg)); +} + +/** + * uffd_poll_events: poll UFFD file descriptor for read + * + * Returns true if events are available for read, false otherwise + * + * @uffd_fd: UFFD file descriptor + * @tmo: timeout value + */ +bool uffd_poll_events(int uffd_fd, int tmo) +{ + int res; + struct pollfd poll_fd =3D { .fd =3D uffd_fd, .events =3D POLLIN, .reve= nts =3D 0 }; + + do { + res =3D poll(&poll_fd, 1, tmo); + } while (res < 0 && errno =3D=3D EINTR); + + if (res =3D=3D 0) { + return false; + } + if (res < 0) { + error_report("uffd_poll_events() failed: errno=3D%i", errno); + return false; + } + + return (poll_fd.revents & POLLIN) !=3D 0; +} --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459249; cv=none; d=zohomail.com; s=zohoarc; b=bksj2kfdIa8jpTfghLI5P4HBZSrvcVTaaIExNL4BpRcQFy46Er4JdStHhAMk9abbCXfM6Tj+JxBue1ewt//wLVXoJogDi+8AwupMbywWRcydXAOd+JpmyEfnrgg1TPGHgBCiwiHhkktLffr5vaZ3lxfbkh1ZNzrsfstO39nFSNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459249; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TFm5Ym9lRFuRYCfOAFW0tWn/PAoPK/Ezau01U7EEF/k=; b=RMS06bWxUUAMaeKZ61QiqsWKtcEfVhj6aWy5y92QU01Z+iyXrFYMkkh9/1zFBSp5nbtK+DdvNiDyiRLFTnlNzib+lyeSTc3ds6oomIkSyNNKFoR0RcG1JgNzHsq8/LYc8ywNiPEayPrBMzunoemuosLgK5reLyyc5cPiYJ7CQKc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459249668404.0557148020389; Thu, 4 Feb 2021 09:20:49 -0800 (PST) Received: from localhost ([::1]:52670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iJE-0007Be-1b for importer@patchew.org; Thu, 04 Feb 2021 12:20:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgV-0001PQ-FO for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37124) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hgT-0004vz-0L for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:47 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-44-naCXf4u7OOiZhHRtxcluZw-1; Thu, 04 Feb 2021 11:40:42 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D635107ACE3; Thu, 4 Feb 2021 16:40:41 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 290F41A38C; Thu, 4 Feb 2021 16:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TFm5Ym9lRFuRYCfOAFW0tWn/PAoPK/Ezau01U7EEF/k=; b=DT1znCSAw4QmG6EabX+BePYppXNG3hUfwL2x+hx+nwIYSoks0FVPUv2QuNqLI+X7Wa5bTg nXlTb6oBIcto+6EExhe2g70Ngvq43nylngPR4AxWMYOQt1Sk7rksTORYs5GKQZuS4D96VA t8A68Rzb2uaAiruvRMQ5J8Rgfzg60dM= X-MC-Unique: naCXf4u7OOiZhHRtxcluZw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 07/27] migration: support UFFD write fault processing in ram_save_iterate() Date: Thu, 4 Feb 2021 16:39:39 +0000 Message-Id: <20210204163959.377618-8-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Andrey Gruzdev In this particular implementation the same single migration thread is responsible for both normal linear dirty page migration and procesing UFFD page fault events. Processing write faults includes reading UFFD file descriptor, finding respective RAM block and saving faulting page to the migration stream. After page has been saved, write protection can be removed. Since asynchronous version of qemu_put_buffer() is expected to be used to save pages, we also have to flush migraion stream prior to un-protecting saved memory range. Write protection is being removed for any previously protected memory chunk that has hit the migration stream. That's valid for pages from linear page scan along with write fault pages. Signed-off-by: Andrey Gruzdev Acked-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210129101407.103458-4-andrey.gruzdev@virtuozzo.com> Signed-off-by: Dr. David Alan Gilbert fixup pagefault.address cast for 32bit --- include/exec/memory.h | 7 + migration/ram.c | 324 +++++++++++++++++++++++++++++++++++++---- migration/ram.h | 2 + migration/trace-events | 2 + 4 files changed, 306 insertions(+), 29 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 37096217e7..e58c09f130 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -150,6 +150,13 @@ typedef struct IOMMUTLBEvent { #define RAM_PMEM (1 << 5) =20 =20 +/* + * UFFDIO_WRITEPROTECT is used on this RAMBlock to + * support 'write-tracking' migration type. + * Implies ram_state->ram_wt_enabled. + */ +#define RAM_UF_WRITEPROTECT (1 << 6) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, diff --git a/migration/ram.c b/migration/ram.c index ae8de17153..26adb55aa9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -56,6 +56,11 @@ #include "savevm.h" #include "qemu/iov.h" #include "multifd.h" +#include "sysemu/runstate.h" + +#if defined(__linux__) +#include "qemu/userfaultfd.h" +#endif /* defined(__linux__) */ =20 /***********************************************************/ /* ram save/restore */ @@ -298,6 +303,8 @@ struct RAMSrcPageRequest { struct RAMState { /* QEMUFile used for this migration */ QEMUFile *f; + /* UFFD file descriptor, used in 'write-tracking' migration */ + int uffdio_fd; /* Last block that we have visited searching for dirty pages */ RAMBlock *last_seen_block; /* Last block from where we have sent data */ @@ -1434,6 +1441,269 @@ static RAMBlock *unqueue_page(RAMState *rs, ram_add= r_t *offset) return block; } =20 +#if defined(__linux__) +/** + * poll_fault_page: try to get next UFFD write fault page and, if pending = fault + * is found, return RAM block pointer and page offset + * + * Returns pointer to the RAMBlock containing faulting page, + * NULL if no write faults are pending + * + * @rs: current RAM state + * @offset: page offset from the beginning of the block + */ +static RAMBlock *poll_fault_page(RAMState *rs, ram_addr_t *offset) +{ + struct uffd_msg uffd_msg; + void *page_address; + RAMBlock *bs; + int res; + + if (!migrate_background_snapshot()) { + return NULL; + } + + res =3D uffd_read_events(rs->uffdio_fd, &uffd_msg, 1); + if (res <=3D 0) { + return NULL; + } + + page_address =3D (void *)(uintptr_t) uffd_msg.arg.pagefault.address; + bs =3D qemu_ram_block_from_host(page_address, false, offset); + assert(bs && (bs->flags & RAM_UF_WRITEPROTECT) !=3D 0); + return bs; +} + +/** + * ram_save_release_protection: release UFFD write protection after + * a range of pages has been saved + * + * @rs: current RAM state + * @pss: page-search-status structure + * @start_page: index of the first page in the range relative to pss->block + * + * Returns 0 on success, negative value in case of an error +*/ +static int ram_save_release_protection(RAMState *rs, PageSearchStatus *pss, + unsigned long start_page) +{ + int res =3D 0; + + /* Check if page is from UFFD-managed region. */ + if (pss->block->flags & RAM_UF_WRITEPROTECT) { + void *page_address =3D pss->block->host + (start_page << TARGET_PA= GE_BITS); + uint64_t run_length =3D (pss->page - start_page + 1) << TARGET_PAG= E_BITS; + + /* Flush async buffers before un-protect. */ + qemu_fflush(rs->f); + /* Un-protect memory range. */ + res =3D uffd_change_protection(rs->uffdio_fd, page_address, run_le= ngth, + false, false); + } + + return res; +} + +/* ram_write_tracking_available: check if kernel supports required UFFD fe= atures + * + * Returns true if supports, false otherwise + */ +bool ram_write_tracking_available(void) +{ + uint64_t uffd_features; + int res; + + res =3D uffd_query_features(&uffd_features); + return (res =3D=3D 0 && + (uffd_features & UFFD_FEATURE_PAGEFAULT_FLAG_WP) !=3D 0); +} + +/* ram_write_tracking_compatible: check if guest configuration is + * compatible with 'write-tracking' + * + * Returns true if compatible, false otherwise + */ +bool ram_write_tracking_compatible(void) +{ + const uint64_t uffd_ioctls_mask =3D BIT(_UFFDIO_WRITEPROTECT); + int uffd_fd; + RAMBlock *bs; + bool ret =3D false; + + /* Open UFFD file descriptor */ + uffd_fd =3D uffd_create_fd(UFFD_FEATURE_PAGEFAULT_FLAG_WP, false); + if (uffd_fd < 0) { + return false; + } + + RCU_READ_LOCK_GUARD(); + + RAMBLOCK_FOREACH_NOT_IGNORED(bs) { + uint64_t uffd_ioctls; + + /* Nothing to do with read-only and MMIO-writable regions */ + if (bs->mr->readonly || bs->mr->rom_device) { + continue; + } + /* Try to register block memory via UFFD-IO to track writes */ + if (uffd_register_memory(uffd_fd, bs->host, bs->max_length, + UFFDIO_REGISTER_MODE_WP, &uffd_ioctls)) { + goto out; + } + if ((uffd_ioctls & uffd_ioctls_mask) !=3D uffd_ioctls_mask) { + goto out; + } + } + ret =3D true; + +out: + uffd_close_fd(uffd_fd); + return ret; +} + +/* + * ram_write_tracking_start: start UFFD-WP memory tracking + * + * Returns 0 for success or negative value in case of error + */ +int ram_write_tracking_start(void) +{ + int uffd_fd; + RAMState *rs =3D ram_state; + RAMBlock *bs; + + /* Open UFFD file descriptor */ + uffd_fd =3D uffd_create_fd(UFFD_FEATURE_PAGEFAULT_FLAG_WP, true); + if (uffd_fd < 0) { + return uffd_fd; + } + rs->uffdio_fd =3D uffd_fd; + + RCU_READ_LOCK_GUARD(); + + RAMBLOCK_FOREACH_NOT_IGNORED(bs) { + /* Nothing to do with read-only and MMIO-writable regions */ + if (bs->mr->readonly || bs->mr->rom_device) { + continue; + } + + /* Register block memory with UFFD to track writes */ + if (uffd_register_memory(rs->uffdio_fd, bs->host, + bs->max_length, UFFDIO_REGISTER_MODE_WP, NULL)) { + goto fail; + } + /* Apply UFFD write protection to the block memory range */ + if (uffd_change_protection(rs->uffdio_fd, bs->host, + bs->max_length, true, false)) { + goto fail; + } + bs->flags |=3D RAM_UF_WRITEPROTECT; + memory_region_ref(bs->mr); + + trace_ram_write_tracking_ramblock_start(bs->idstr, bs->page_size, + bs->host, bs->max_length); + } + + return 0; + +fail: + error_report("ram_write_tracking_start() failed: restoring initial mem= ory state"); + + RAMBLOCK_FOREACH_NOT_IGNORED(bs) { + if ((bs->flags & RAM_UF_WRITEPROTECT) =3D=3D 0) { + continue; + } + /* + * In case some memory block failed to be write-protected + * remove protection and unregister all succeeded RAM blocks + */ + uffd_change_protection(rs->uffdio_fd, bs->host, bs->max_length, fa= lse, false); + uffd_unregister_memory(rs->uffdio_fd, bs->host, bs->max_length); + /* Cleanup flags and remove reference */ + bs->flags &=3D ~RAM_UF_WRITEPROTECT; + memory_region_unref(bs->mr); + } + + uffd_close_fd(uffd_fd); + rs->uffdio_fd =3D -1; + return -1; +} + +/** + * ram_write_tracking_stop: stop UFFD-WP memory tracking and remove protec= tion + */ +void ram_write_tracking_stop(void) +{ + RAMState *rs =3D ram_state; + RAMBlock *bs; + + RCU_READ_LOCK_GUARD(); + + RAMBLOCK_FOREACH_NOT_IGNORED(bs) { + if ((bs->flags & RAM_UF_WRITEPROTECT) =3D=3D 0) { + continue; + } + /* Remove protection and unregister all affected RAM blocks */ + uffd_change_protection(rs->uffdio_fd, bs->host, bs->max_length, fa= lse, false); + uffd_unregister_memory(rs->uffdio_fd, bs->host, bs->max_length); + + trace_ram_write_tracking_ramblock_stop(bs->idstr, bs->page_size, + bs->host, bs->max_length); + + /* Cleanup flags and remove reference */ + bs->flags &=3D ~RAM_UF_WRITEPROTECT; + memory_region_unref(bs->mr); + } + + /* Finally close UFFD file descriptor */ + uffd_close_fd(rs->uffdio_fd); + rs->uffdio_fd =3D -1; +} + +#else +/* No target OS support, stubs just fail or ignore */ + +static RAMBlock *poll_fault_page(RAMState *rs, ram_addr_t *offset) +{ + (void) rs; + (void) offset; + + return NULL; +} + +static int ram_save_release_protection(RAMState *rs, PageSearchStatus *pss, + unsigned long start_page) +{ + (void) rs; + (void) pss; + (void) start_page; + + return 0; +} + +bool ram_write_tracking_available(void) +{ + return false; +} + +bool ram_write_tracking_compatible(void) +{ + assert(0); + return false; +} + +int ram_write_tracking_start(void) +{ + assert(0); + return -1; +} + +void ram_write_tracking_stop(void) +{ + assert(0); +} +#endif /* defined(__linux__) */ + /** * get_queued_page: unqueue a page from the postcopy requests * @@ -1473,6 +1743,14 @@ static bool get_queued_page(RAMState *rs, PageSearch= Status *pss) =20 } while (block && !dirty); =20 + if (!block) { + /* + * Poll write faults too if background snapshot is enabled; that's + * when we have vcpus got blocked by the write protected pages. + */ + block =3D poll_fault_page(rs, &offset); + } + if (block) { /* * As soon as we start servicing pages out of order, then we have @@ -1715,6 +1993,8 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss, int tmppages, pages =3D 0; size_t pagesize_bits =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; + unsigned long start_page =3D pss->page; + int res; =20 if (ramblock_is_ignored(pss->block)) { error_report("block %s should not be migrated !", pss->block->idst= r); @@ -1740,10 +2020,11 @@ static int ram_save_host_page(RAMState *rs, PageSea= rchStatus *pss, } while ((pss->page & (pagesize_bits - 1)) && offset_in_ramblock(pss->block, ((ram_addr_t)pss->page) << TARGET_PAGE_BIT= S)); - /* The offset we leave with is the last one we looked at */ pss->page--; - return pages; + + res =3D ram_save_release_protection(rs, pss, start_page); + return (res < 0 ? res : pages); } =20 /** @@ -1880,10 +2161,13 @@ static void ram_save_cleanup(void *opaque) RAMState **rsp =3D opaque; RAMBlock *block; =20 - /* caller have hold iothread lock or is in a bh, so there is - * no writing race against the migration bitmap - */ - memory_global_dirty_log_stop(); + /* We don't use dirty log with background snapshots */ + if (!migrate_background_snapshot()) { + /* caller have hold iothread lock or is in a bh, so there is + * no writing race against the migration bitmap + */ + memory_global_dirty_log_stop(); + } =20 RAMBLOCK_FOREACH_NOT_IGNORED(block) { g_free(block->clear_bmap); @@ -2343,8 +2627,11 @@ static void ram_init_bitmaps(RAMState *rs) =20 WITH_RCU_READ_LOCK_GUARD() { ram_list_init_bitmaps(); - memory_global_dirty_log_start(); - migration_bitmap_sync_precopy(rs); + /* We don't use dirty log with background snapshots */ + if (!migrate_background_snapshot()) { + memory_global_dirty_log_start(); + migration_bitmap_sync_precopy(rs); + } } qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_iothread(); @@ -3788,27 +4075,6 @@ static int ram_resume_prepare(MigrationState *s, voi= d *opaque) return 0; } =20 -/* ram_write_tracking_available: check if kernel supports required UFFD fe= atures - * - * Returns true if supports, false otherwise - */ -bool ram_write_tracking_available(void) -{ - /* TODO: implement */ - return false; -} - -/* ram_write_tracking_compatible: check if guest configuration is - * compatible with 'write-tracking' - * - * Returns true if compatible, false otherwise - */ -bool ram_write_tracking_compatible(void) -{ - /* TODO: implement */ - return false; -} - static SaveVMHandlers savevm_ram_handlers =3D { .save_setup =3D ram_save_setup, .save_live_iterate =3D ram_save_iterate, diff --git a/migration/ram.h b/migration/ram.h index 1a9ff90304..c25540cb93 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -82,5 +82,7 @@ void colo_incoming_start_dirty_log(void); /* Background snapshot */ bool ram_write_tracking_available(void); bool ram_write_tracking_compatible(void); +int ram_write_tracking_start(void); +void ram_write_tracking_stop(void); =20 #endif diff --git a/migration/trace-events b/migration/trace-events index 75de5004ac..668c562fed 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -111,6 +111,8 @@ save_xbzrle_page_skipping(void) "" save_xbzrle_page_overflow(void) "" ram_save_iterate_big_wait(uint64_t milliconds, int iterations) "big wait: = %" PRIu64 " milliseconds, %d iterations" ram_load_complete(int ret, uint64_t seq_iter) "exit_code %d seq iteration = %" PRIu64 +ram_write_tracking_ramblock_start(const char *block_id, size_t page_size, = void *addr, size_t length) "%s: page_size: %zu addr: %p length: %zu" +ram_write_tracking_ramblock_stop(const char *block_id, size_t page_size, v= oid *addr, size_t length) "%s: page_size: %zu addr: %p length: %zu" =20 # multifd.c multifd_new_send_channel_async(uint8_t id) "channel %d" --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459554; cv=none; d=zohomail.com; s=zohoarc; b=N35LyXEcRzq2lkxz+Lq7V/mNipg3Ip5dI8y3YMni4s9QdT3Rrb0i6gzhcS+UP4MO7bQ8rCn6E46Pc7BOvlCn6zbYZkq19AY671NK7lE8PGpXnq6FKxehdhuXIxvNkX2PotymreFBAK7UgQ6lZZRN3hcx/Z+b2e3e5yjj4Xy/BGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459554; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6nfrvNfSCyKfA/BX2b5QmFJgrDmLnqzA9oepRR5UN3I=; b=QL4C3pleerCuxr2ObIT+a7GhArFwLLc2e2qCjhk15NwwLjr/jBqUjr4ZQiIrQsGei41Zjhj5isNDE381bWpSBvPvWvXnf1rhRQyGiZo5e4vialA/irO7oOcktXYXMyaFVJcEuGAFSk7e9jL4DYM4mu1My8g09pyTUPmLxRThB0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459554288200.72468717337472; Thu, 4 Feb 2021 09:25:54 -0800 (PST) Received: from localhost ([::1]:37146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iO9-0004ju-0u for importer@patchew.org; Thu, 04 Feb 2021 12:25:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgd-0001TF-2t for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hgY-0004y3-2d for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:54 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-388-oZ_g8wI7OxOSVbRJ20Evpw-1; Thu, 04 Feb 2021 11:40:47 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 00577804022; Thu, 4 Feb 2021 16:40:46 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AB421A26A; Thu, 4 Feb 2021 16:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456849; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6nfrvNfSCyKfA/BX2b5QmFJgrDmLnqzA9oepRR5UN3I=; b=ewqrRTqsIW/4W+CD2JjjpliFhsOCXWSazYhjgNiOIlMnEegcTrIzWm922HA1/+3jKCtOWL 0y8REsvPEJaX+pV9dKMuDOw8N6e0JhS8yVYf+nNQsAAqXf77gKxAfiwvki0iDSw9jQmm0L ix1mMVDoQcoI8YupyAbgRxSSEFv+S04= X-MC-Unique: oZ_g8wI7OxOSVbRJ20Evpw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 08/27] migration: implementation of background snapshot thread Date: Thu, 4 Feb 2021 16:39:40 +0000 Message-Id: <20210204163959.377618-9-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URG_BIZ=0.573 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Andrey Gruzdev Introducing implementation of 'background' snapshot thread which in overall follows the logic of precopy migration while internally utilizes completely different mechanism to 'freeze' vmstate at the start of snapshot creation. This mechanism is based on userfault_fd with wr-protection support and is Linux-specific. Signed-off-by: Andrey Gruzdev Acked-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210129101407.103458-5-andrey.gruzdev@virtuozzo.com> Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 255 +++++++++++++++++++++++++++++++++++++++++- migration/migration.h | 3 + migration/savevm.c | 1 - migration/savevm.h | 2 + 4 files changed, 258 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 2262f348af..ecb4115d68 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2000,6 +2000,7 @@ void migrate_init(MigrationState *s) * locks. */ s->cleanup_bh =3D 0; + s->vm_start_bh =3D 0; s->to_dst_file =3D NULL; s->state =3D MIGRATION_STATUS_NONE; s->rp_state.from_dst_file =3D NULL; @@ -3217,6 +3218,50 @@ fail: MIGRATION_STATUS_FAILED); } =20 +/** + * bg_migration_completion: Used by bg_migration_thread when after all the + * RAM has been saved. The caller 'breaks' the loop when this returns. + * + * @s: Current migration state + */ +static void bg_migration_completion(MigrationState *s) +{ + int current_active_state =3D s->state; + + /* + * Stop tracking RAM writes - un-protect memory, un-register UFFD + * memory ranges, flush kernel wait queues and wake up threads + * waiting for write fault to be resolved. + */ + ram_write_tracking_stop(); + + if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + /* + * By this moment we have RAM content saved into the migration str= eam. + * The next step is to flush the non-RAM content (device state) + * right after the ram content. The device state has been stored i= nto + * the temporary buffer before RAM saving started. + */ + qemu_put_buffer(s->to_dst_file, s->bioc->data, s->bioc->usage); + qemu_fflush(s->to_dst_file); + } else if (s->state =3D=3D MIGRATION_STATUS_CANCELLING) { + goto fail; + } + + if (qemu_file_get_error(s->to_dst_file)) { + trace_migration_completion_file_err(); + goto fail; + } + + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_COMPLETED); + return; + +fail: + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_FAILED); +} + bool migrate_colo_enabled(void) { MigrationState *s =3D migrate_get_current(); @@ -3557,6 +3602,47 @@ static void migration_iteration_finish(MigrationStat= e *s) qemu_mutex_unlock_iothread(); } =20 +static void bg_migration_iteration_finish(MigrationState *s) +{ + qemu_mutex_lock_iothread(); + switch (s->state) { + case MIGRATION_STATUS_COMPLETED: + migration_calculate_complete(s); + break; + + case MIGRATION_STATUS_ACTIVE: + case MIGRATION_STATUS_FAILED: + case MIGRATION_STATUS_CANCELLED: + case MIGRATION_STATUS_CANCELLING: + break; + + default: + /* Should not reach here, but if so, forgive the VM. */ + error_report("%s: Unknown ending state %d", __func__, s->state); + break; + } + + migrate_fd_cleanup_schedule(s); + qemu_mutex_unlock_iothread(); +} + +/* + * Return true if continue to the next iteration directly, false + * otherwise. + */ +static MigIterateState bg_migration_iteration_run(MigrationState *s) +{ + int res; + + res =3D qemu_savevm_state_iterate(s->to_dst_file, false); + if (res > 0) { + bg_migration_completion(s); + return MIG_ITERATE_BREAK; + } + + return MIG_ITERATE_RESUME; +} + void migration_make_urgent_request(void) { qemu_sem_post(&migrate_get_current()->rate_limit_sem); @@ -3704,6 +3790,165 @@ static void *migration_thread(void *opaque) return NULL; } =20 +static void bg_migration_vm_start_bh(void *opaque) +{ + MigrationState *s =3D opaque; + + qemu_bh_delete(s->vm_start_bh); + s->vm_start_bh =3D NULL; + + vm_start(); + s->downtime =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - s->downtime_s= tart; +} + +/** + * Background snapshot thread, based on live migration code. + * This is an alternative implementation of live migration mechanism + * introduced specifically to support background snapshots. + * + * It takes advantage of userfault_fd write protection mechanism introduced + * in v5.7 kernel. Compared to existing dirty page logging migration much + * lesser stream traffic is produced resulting in smaller snapshot images, + * simply cause of no page duplicates can get into the stream. + * + * Another key point is that generated vmstate stream reflects machine sta= te + * 'frozen' at the beginning of snapshot creation compared to dirty page l= ogging + * mechanism, which effectively results in that saved snapshot is the stat= e of VM + * at the end of the process. + */ +static void *bg_migration_thread(void *opaque) +{ + MigrationState *s =3D opaque; + int64_t setup_start; + MigThrError thr_error; + QEMUFile *fb; + bool early_fail =3D true; + + rcu_register_thread(); + object_ref(OBJECT(s)); + + qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX); + + setup_start =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); + /* + * We want to save vmstate for the moment when migration has been + * initiated but also we want to save RAM content while VM is running. + * The RAM content should appear first in the vmstate. So, we first + * stash the non-RAM part of the vmstate to the temporary buffer, + * then write RAM part of the vmstate to the migration stream + * with vCPUs running and, finally, write stashed non-RAM part of + * the vmstate from the buffer to the migration stream. + */ + s->bioc =3D qio_channel_buffer_new(128 * 1024); + qio_channel_set_name(QIO_CHANNEL(s->bioc), "vmstate-buffer"); + fb =3D qemu_fopen_channel_output(QIO_CHANNEL(s->bioc)); + object_unref(OBJECT(s->bioc)); + + update_iteration_initial_status(s); + + qemu_savevm_state_header(s->to_dst_file); + qemu_savevm_state_setup(s->to_dst_file); + + if (qemu_savevm_state_guest_unplug_pending()) { + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_WAIT_UNPLUG); + + while (s->state =3D=3D MIGRATION_STATUS_WAIT_UNPLUG && + qemu_savevm_state_guest_unplug_pending()) { + qemu_sem_timedwait(&s->wait_unplug_sem, 250); + } + + migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG, + MIGRATION_STATUS_ACTIVE); + } else { + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_ACTIVE); + } + s->setup_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; + + trace_migration_thread_setup_complete(); + s->downtime_start =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + + qemu_mutex_lock_iothread(); + + /* + * If VM is currently in suspended state, then, to make a valid runsta= te + * transition in vm_stop_force_state() we need to wakeup it up. + */ + qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL); + s->vm_was_running =3D runstate_is_running(); + + if (global_state_store()) { + goto fail; + } + /* Forcibly stop VM before saving state of vCPUs and devices */ + if (vm_stop_force_state(RUN_STATE_PAUSED)) { + goto fail; + } + /* + * Put vCPUs in sync with shadow context structures, then + * save their state to channel-buffer along with devices. + */ + cpu_synchronize_all_states(); + if (qemu_savevm_state_complete_precopy_non_iterable(fb, false, false))= { + goto fail; + } + /* Now initialize UFFD context and start tracking RAM writes */ + if (ram_write_tracking_start()) { + goto fail; + } + early_fail =3D false; + + /* + * Start VM from BH handler to avoid write-fault lock here. + * UFFD-WP protection for the whole RAM is already enabled so + * calling VM state change notifiers from vm_start() would initiate + * writes to virtio VQs memory which is in write-protected region. + */ + s->vm_start_bh =3D qemu_bh_new(bg_migration_vm_start_bh, s); + qemu_bh_schedule(s->vm_start_bh); + + qemu_mutex_unlock_iothread(); + + while (migration_is_active(s)) { + MigIterateState iter_state =3D bg_migration_iteration_run(s); + if (iter_state =3D=3D MIG_ITERATE_SKIP) { + continue; + } else if (iter_state =3D=3D MIG_ITERATE_BREAK) { + break; + } + + /* + * Try to detect any kind of failures, and see whether we + * should stop the migration now. + */ + thr_error =3D migration_detect_error(s); + if (thr_error =3D=3D MIG_THR_ERR_FATAL) { + /* Stop migration */ + break; + } + + migration_update_counters(s, qemu_clock_get_ms(QEMU_CLOCK_REALTIME= )); + } + + trace_migration_thread_after_loop(); + +fail: + if (early_fail) { + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + qemu_mutex_unlock_iothread(); + } + + bg_migration_iteration_finish(s); + + qemu_fclose(fb); + object_unref(OBJECT(s)); + rcu_unregister_thread(); + + return NULL; +} + void migrate_fd_connect(MigrationState *s, Error *error_in) { Error *local_err =3D NULL; @@ -3767,8 +4012,14 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) migrate_fd_cleanup(s); return; } - qemu_thread_create(&s->thread, "live_migration", migration_thread, s, - QEMU_THREAD_JOINABLE); + + if (migrate_background_snapshot()) { + qemu_thread_create(&s->thread, "bg_snapshot", + bg_migration_thread, s, QEMU_THREAD_JOINABLE); + } else { + qemu_thread_create(&s->thread, "live_migration", + migration_thread, s, QEMU_THREAD_JOINABLE); + } s->migration_thread_running =3D true; } =20 diff --git a/migration/migration.h b/migration/migration.h index f40338cfbf..0723955cd7 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -20,6 +20,7 @@ #include "qemu/thread.h" #include "qemu/coroutine_int.h" #include "io/channel.h" +#include "io/channel-buffer.h" #include "net/announce.h" #include "qom/object.h" =20 @@ -147,8 +148,10 @@ struct MigrationState { =20 /*< public >*/ QemuThread thread; + QEMUBH *vm_start_bh; QEMUBH *cleanup_bh; QEMUFile *to_dst_file; + QIOChannelBuffer *bioc; /* * Protects to_dst_file pointer. We need to make sure we won't * yield or hang during the critical section, since this lock will diff --git a/migration/savevm.c b/migration/savevm.c index d1e6aaed60..d5bf53388f 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1378,7 +1378,6 @@ int qemu_savevm_state_complete_precopy_iterable(QEMUF= ile *f, bool in_postcopy) return 0; } =20 -static int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, bool in_postcopy, bool inactivate_disks) diff --git a/migration/savevm.h b/migration/savevm.h index ba64a7e271..aaee2528ed 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -64,5 +64,7 @@ int qemu_loadvm_state(QEMUFile *f); void qemu_loadvm_state_cleanup(void); int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis); int qemu_load_device_state(QEMUFile *f); +int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, + bool in_postcopy, bool inactivate_disks); =20 #endif --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612458373; cv=none; d=zohomail.com; s=zohoarc; b=DWiODpzCYiISk/JUjtUwuBLnGW6F54fEdTrPpTSN7ejzsDfDLIVsmP4xIbo9mxsYoNmi770HH2mLN0aICnDGW27epaBg5bpI5mro4nXZE7gVCa0Az43ZGnlt305U5LAP4W5KBSpORG+NXAU+HGnavgCFs//UXvP/Dv0S78z31Oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612458373; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Se5PgBvmj/igHU2KtSDhk45/M6qHCrQMbFcqOM72qf0=; b=ijmKm4krTyGVhl1kdFvfHpTGzTXk/NUHRBdCh1UXG312uLjGD26+f1f2CXmPtahtUVnQr6TjBzfhtr+LzqbK4pxx1e2OnqZzlBoeuXHTCap8ACJXou5R7WR4iAZmAOp8lbE3L2pX3+FBa6R29SRZVZg7rE7bJ76iHHqJ8J+fs7A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612458373205711.8511213562816; Thu, 4 Feb 2021 09:06:13 -0800 (PST) Received: from localhost ([::1]:42764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7i54-0005qH-Pp for importer@patchew.org; Thu, 04 Feb 2021 12:06:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgf-0001Wr-Ml for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hgd-000515-TV for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:40:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-376-yo2veudPNyO7C1FyLyqDBw-1; Thu, 04 Feb 2021 11:40:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12505100C611; Thu, 4 Feb 2021 16:40:52 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D5871A38C; Thu, 4 Feb 2021 16:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Se5PgBvmj/igHU2KtSDhk45/M6qHCrQMbFcqOM72qf0=; b=H50tWOV4b2yvRt81D5pHKm/WfP/ECMzDCFKcdRGbISzW9qJI34Wl/minge3ZGuNYf4cUJZ vMTU2WdcfnlV9TciTYRsBcT6S6R2ooAE76LylxLWCey5Pg3tBS0EAzeh6ZOoMeop+xEONm MGK3WSIrBfbMEHu0DGoR6+txPynjUSM= X-MC-Unique: yo2veudPNyO7C1FyLyqDBw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 09/27] migration: introduce 'userfaultfd-wrlat.py' script Date: Thu, 4 Feb 2021 16:39:41 +0000 Message-Id: <20210204163959.377618-10-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Andrey Gruzdev Add BCC/eBPF script to analyze userfaultfd write fault latency distribution. Signed-off-by: Andrey Gruzdev Reviewed-by: Peter Xu Message-Id: <20210129101407.103458-6-andrey.gruzdev@virtuozzo.com> Signed-off-by: Dr. David Alan Gilbert --- scripts/userfaultfd-wrlat.py | 122 +++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 scripts/userfaultfd-wrlat.py diff --git a/scripts/userfaultfd-wrlat.py b/scripts/userfaultfd-wrlat.py new file mode 100755 index 0000000000..0684be4e04 --- /dev/null +++ b/scripts/userfaultfd-wrlat.py @@ -0,0 +1,122 @@ +#!/usr/bin/python3 +# +# userfaultfd-wrlat Summarize userfaultfd write fault latencies. +# Events are continuously accumulated for the +# run, while latency distribution histogram is +# dumped each 'interval' seconds. +# +# For Linux, uses BCC, eBPF. +# +# USAGE: userfaultfd-lat [interval [count]] +# +# Copyright Virtuozzo GmbH, 2020 +# +# Authors: +# Andrey Gruzdev +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +from __future__ import print_function +from bcc import BPF +from ctypes import c_ushort, c_int, c_ulonglong +from time import sleep +from sys import argv + +def usage(): + print("USAGE: %s [interval [count]]" % argv[0]) + exit() + +# define BPF program +bpf_text =3D """ +#include +#include + +BPF_HASH(ev_start, u32, u64); +BPF_HISTOGRAM(ev_delta_hist, u64); + +/* Trace UFFD page fault start event. */ +static void do_event_start() +{ + /* Using "(u32)" to drop group ID which is upper 32 bits */ + u32 tid =3D (u32) bpf_get_current_pid_tgid(); + u64 ts =3D bpf_ktime_get_ns(); + + ev_start.update(&tid, &ts); +} + +/* Trace UFFD page fault end event. */ +static void do_event_end() +{ + /* Using "(u32)" to drop group ID which is upper 32 bits */ + u32 tid =3D (u32) bpf_get_current_pid_tgid(); + u64 ts =3D bpf_ktime_get_ns(); + u64 *tsp; + + tsp =3D ev_start.lookup(&tid); + if (tsp) { + u64 delta =3D ts - (*tsp); + /* Transform time delta to milliseconds */ + ev_delta_hist.increment(bpf_log2l(delta / 1000000)); + ev_start.delete(&tid); + } +} + +/* KPROBE for handle_userfault(). */ +int probe_handle_userfault(struct pt_regs *ctx, struct vm_fault *vmf, + unsigned long reason) +{ + /* Trace only UFFD write faults. */ + if (reason & VM_UFFD_WP) { + do_event_start(); + } + return 0; +} + +/* KRETPROBE for handle_userfault(). */ +int retprobe_handle_userfault(struct pt_regs *ctx) +{ + do_event_end(); + return 0; +} +""" + +# arguments +interval =3D 10 +count =3D -1 +if len(argv) > 1: + try: + interval =3D int(argv[1]) + if interval =3D=3D 0: + raise + if len(argv) > 2: + count =3D int(argv[2]) + except: # also catches -h, --help + usage() + +# load BPF program +b =3D BPF(text=3Dbpf_text) +# attach KRPOBEs +b.attach_kprobe(event=3D"handle_userfault", fn_name=3D"probe_handle_userfa= ult") +b.attach_kretprobe(event=3D"handle_userfault", fn_name=3D"retprobe_handle_= userfault") + +# header +print("Tracing UFFD-WP write fault latency... Hit Ctrl-C to end.") + +# output +loop =3D 0 +do_exit =3D 0 +while (1): + if count > 0: + loop +=3D 1 + if loop > count: + exit() + try: + sleep(interval) + except KeyboardInterrupt: + pass; do_exit =3D 1 + + print() + b["ev_delta_hist"].print_log2_hist("msecs") + if do_exit: + exit() --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459743; cv=none; d=zohomail.com; s=zohoarc; b=fJv6N/YxDz7ehA32uL+i0V04PR00hlrwryXkQm0+wvBsXf/DgbPP2z4xGOviYxTtk22oWQhfpJLkiU8AX8MAPs1uxL+ElFjbHJF8rq+3yySMpV1n+I6d+mjQJijHP6xiz/2zr2opVpEVT93aA3kxqvOilaqezfRl4XNUX9yEiwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459743; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Etjjb/ZNxUmqSYfxmZH66oH2lwLCD2uyoHJXXo7d+XY=; b=VKIL5u+LlMUyXXUYToRUnniv5t1G5fCZZFOi4CWGAwfkrKiUFkt0Fw/pYHE9RMvu7PpgJmod9vo33J5VkDCcljxdXJcj6ErEh3daz3dxRvZn/ilAAHjjV0F8RUC+lYFIMSeyBNOw2D2qhYe02W2EOqtuasQ8/T+vNnxBYSBV/2U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459743368915.5636512257315; Thu, 4 Feb 2021 09:29:03 -0800 (PST) Received: from localhost ([::1]:45536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iRC-0000CO-7H for importer@patchew.org; Thu, 04 Feb 2021 12:29:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hgm-0001iH-NB for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47066) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hgk-00054N-LD for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:04 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-519-O371G5QJO5WEgYWVYJ4Cvg-1; Thu, 04 Feb 2021 11:40:59 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BEF81935799; Thu, 4 Feb 2021 16:40:58 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C50C19709; Thu, 4 Feb 2021 16:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Etjjb/ZNxUmqSYfxmZH66oH2lwLCD2uyoHJXXo7d+XY=; b=ORfU2mjKITN7rh2pWQRDchNqZnn659Xsrj0PsqsX6Ywcozmh8aT3L20fF+eoMoUdzposUR GcYGlCYMZFYehh10tsxwQSXLPbeQfImeAT8h7gkoYCEdY0TFC2Cx2po+uB9Th0oH18bfPh BzQyPpMT1AVrfTFvsKg4b/ieuG64HOU= X-MC-Unique: O371G5QJO5WEgYWVYJ4Cvg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 10/27] migration: Fix migrate-set-parameters argument validation Date: Thu, 4 Feb 2021 16:39:42 +0000 Message-Id: <20210204163959.377618-11-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Commit 741d4086c8 "migration: Use proper types in json" (v2.12.0) switched MigrationParameters to narrower integer types, and removed the simplified qmp_migrate_set_parameters()'s argument checking accordingly. Good idea, except qmp_migrate_set_parameters() takes MigrateSetParameters, not MigrationParameters. Its job is updating migrate_get_current()->parameters (which *is* of type MigrationParameters) according to its argument. The integers now get truncated silently. Reproducer: ---> {'execute': 'query-migrate-parameters'} <--- {"return": {[...] "compress-threads": 8, [...]}} ---> {"execute": "migrate-set-parameters", "arguments": {"compress-thre= ads": 257}} <--- {"return": {}} ---> {'execute': 'query-migrate-parameters'} <--- {"return": {[...] "compress-threads": 1, [...]}} Fix by resynchronizing MigrateSetParameters with MigrationParameters. Fixes: 741d4086c856320807a2575389d7c0505578270b Signed-off-by: Markus Armbruster Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210202141734.2488076-2-armbru@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- monitor/hmp-cmds.c | 24 ++++++++++++------------ qapi/migration.json | 28 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index a48bc1e904..509d6b01ee 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1294,11 +1294,11 @@ void hmp_migrate_set_parameter(Monitor *mon, const = QDict *qdict) switch (val) { case MIGRATION_PARAMETER_COMPRESS_LEVEL: p->has_compress_level =3D true; - visit_type_int(v, param, &p->compress_level, &err); + visit_type_uint8(v, param, &p->compress_level, &err); break; case MIGRATION_PARAMETER_COMPRESS_THREADS: p->has_compress_threads =3D true; - visit_type_int(v, param, &p->compress_threads, &err); + visit_type_uint8(v, param, &p->compress_threads, &err); break; case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: p->has_compress_wait_thread =3D true; @@ -1306,19 +1306,19 @@ void hmp_migrate_set_parameter(Monitor *mon, const = QDict *qdict) break; case MIGRATION_PARAMETER_DECOMPRESS_THREADS: p->has_decompress_threads =3D true; - visit_type_int(v, param, &p->decompress_threads, &err); + visit_type_uint8(v, param, &p->decompress_threads, &err); break; case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: p->has_throttle_trigger_threshold =3D true; - visit_type_int(v, param, &p->throttle_trigger_threshold, &err); + visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err); break; case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: p->has_cpu_throttle_initial =3D true; - visit_type_int(v, param, &p->cpu_throttle_initial, &err); + visit_type_uint8(v, param, &p->cpu_throttle_initial, &err); break; case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: p->has_cpu_throttle_increment =3D true; - visit_type_int(v, param, &p->cpu_throttle_increment, &err); + visit_type_uint8(v, param, &p->cpu_throttle_increment, &err); break; case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW: p->has_cpu_throttle_tailslow =3D true; @@ -1326,7 +1326,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) break; case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: p->has_max_cpu_throttle =3D true; - visit_type_int(v, param, &p->max_cpu_throttle, &err); + visit_type_uint8(v, param, &p->max_cpu_throttle, &err); break; case MIGRATION_PARAMETER_TLS_CREDS: p->has_tls_creds =3D true; @@ -1362,11 +1362,11 @@ void hmp_migrate_set_parameter(Monitor *mon, const = QDict *qdict) break; case MIGRATION_PARAMETER_DOWNTIME_LIMIT: p->has_downtime_limit =3D true; - visit_type_int(v, param, &p->downtime_limit, &err); + visit_type_size(v, param, &p->downtime_limit, &err); break; case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: p->has_x_checkpoint_delay =3D true; - visit_type_int(v, param, &p->x_checkpoint_delay, &err); + visit_type_uint32(v, param, &p->x_checkpoint_delay, &err); break; case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: p->has_block_incremental =3D true; @@ -1374,7 +1374,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) break; case MIGRATION_PARAMETER_MULTIFD_CHANNELS: p->has_multifd_channels =3D true; - visit_type_int(v, param, &p->multifd_channels, &err); + visit_type_uint8(v, param, &p->multifd_channels, &err); break; case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: p->has_multifd_compression =3D true; @@ -1383,11 +1383,11 @@ void hmp_migrate_set_parameter(Monitor *mon, const = QDict *qdict) break; case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: p->has_multifd_zlib_level =3D true; - visit_type_int(v, param, &p->multifd_zlib_level, &err); + visit_type_uint8(v, param, &p->multifd_zlib_level, &err); break; case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: p->has_multifd_zstd_level =3D true; - visit_type_int(v, param, &p->multifd_zstd_level, &err); + visit_type_uint8(v, param, &p->multifd_zstd_level, &err); break; case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: p->has_xbzrle_cache_size =3D true; diff --git a/qapi/migration.json b/qapi/migration.json index 6c12b368aa..37026643ab 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -890,28 +890,28 @@ '*announce-max': 'size', '*announce-rounds': 'size', '*announce-step': 'size', - '*compress-level': 'int', - '*compress-threads': 'int', + '*compress-level': 'uint8', + '*compress-threads': 'uint8', '*compress-wait-thread': 'bool', - '*decompress-threads': 'int', - '*throttle-trigger-threshold': 'int', - '*cpu-throttle-initial': 'int', - '*cpu-throttle-increment': 'int', + '*decompress-threads': 'uint8', + '*throttle-trigger-threshold': 'uint8', + '*cpu-throttle-initial': 'uint8', + '*cpu-throttle-increment': 'uint8', '*cpu-throttle-tailslow': 'bool', '*tls-creds': 'StrOrNull', '*tls-hostname': 'StrOrNull', '*tls-authz': 'StrOrNull', - '*max-bandwidth': 'int', - '*downtime-limit': 'int', - '*x-checkpoint-delay': 'int', + '*max-bandwidth': 'size', + '*downtime-limit': 'uint64', + '*x-checkpoint-delay': 'uint32', '*block-incremental': 'bool', - '*multifd-channels': 'int', + '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int', + '*max-cpu-throttle': 'uint8', '*multifd-compression': 'MultiFDCompression', - '*multifd-zlib-level': 'int', - '*multifd-zstd-level': 'int', + '*multifd-zlib-level': 'uint8', + '*multifd-zstd-level': 'uint8', '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } =20 ## @@ -1098,7 +1098,7 @@ '*max-bandwidth': 'size', '*downtime-limit': 'uint64', '*x-checkpoint-delay': 'uint32', - '*block-incremental': 'bool' , + '*block-incremental': 'bool', '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459573; cv=none; d=zohomail.com; s=zohoarc; b=KNfKKsHyFRmLn9ZSyW7MT1UmFG+e4MBdp2yOpvu2D4uEhvOsdMaZ/81BRDvfyA0T71ZyUC8kpWHKHW6So94M8ayTfLEjiXoSWC9kS5lIohJoG8UcnBAylBcIwFFGZi3AqK/WLF3j3xx5I7dz9gY+tt7Od2wz0VyGdV1IAvcVtiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459573; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=26Mtuo57Y1Oel1+39shSBQglrhSQaNbIdpDb4ZX1OS4=; b=QJVKWbQ9XMexsM6BVJSn2lYqj9wJd1bSyCDEtgcqS1VGbU0AGg9uxW3YFAy27VdxgDgdVFWT7yXpCGod7sJr+McrqjpqWN1kZaVf7dqycRgJdUv82LrpslAM4I7idSDIPByv5mi8MMrqmPmZs5uSFvreVQBjhYLneLCcLa4Qe7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16124595732071000.3505184368929; Thu, 4 Feb 2021 09:26:13 -0800 (PST) Received: from localhost ([::1]:38034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iOS-00056m-1h for importer@patchew.org; Thu, 04 Feb 2021 12:26:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hh0-000270-2o for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55443) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hgw-0005B2-L6 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-SgNTvHbjNzysZ-ZVYn-goA-1; Thu, 04 Feb 2021 11:41:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1AA36100C61C; Thu, 4 Feb 2021 16:41:07 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16BA61A38C; Thu, 4 Feb 2021 16:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=26Mtuo57Y1Oel1+39shSBQglrhSQaNbIdpDb4ZX1OS4=; b=WfVwzvftrLp2cOZXT6+KVyj+visZoKRwy1snWoa3CHQ1D8+bt7ZkmPcx75KJconS3JcMq2 vGRdSu6rAtMoZiAumdPgqVaenprECQi18mjvVuy7zLyMCoYQt7bI5plzZ6YAnhtkGOd0i8 lF3t/4iSSHuctX0LycWXABURnGcpjkk= X-MC-Unique: SgNTvHbjNzysZ-ZVYn-goA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 11/27] migration: Clean up signed vs. unsigned XBZRLE cache-size Date: Thu, 4 Feb 2021 16:39:43 +0000 Message-Id: <20210204163959.377618-12-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Markus Armbruster 73af8dd8d7 "migration: Make xbzrle_cache_size a migration parameter" (v2.11.0) made the new parameter unsigned (QAPI type 'size', uint64_t in C). It neglected to update existing code, which continues to use int64_t. migrate_xbzrle_cache_size() returns the new parameter. Adjust its return type. QMP query-migrate-cache-size returns migrate_xbzrle_cache_size(). Adjust its return type. migrate-set-parameters passes the new parameter to xbzrle_cache_resize(). Adjust its parameter type. xbzrle_cache_resize() passes it on to cache_init(). Adjust its parameter type. Signed-off-by: Markus Armbruster Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210202141734.2488076-3-armbru@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 4 ++-- migration/migration.h | 2 +- migration/page_cache.c | 2 +- migration/page_cache.h | 2 +- migration/ram.c | 2 +- migration/ram.h | 2 +- qapi/migration.json | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index ecb4115d68..77b0c39b50 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2308,7 +2308,7 @@ void qmp_migrate_set_cache_size(int64_t value, Error = **errp) qmp_migrate_set_parameters(&p, errp); } =20 -int64_t qmp_query_migrate_cache_size(Error **errp) +uint64_t qmp_query_migrate_cache_size(Error **errp) { return migrate_xbzrle_cache_size(); } @@ -2538,7 +2538,7 @@ int migrate_use_xbzrle(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_XBZRLE]; } =20 -int64_t migrate_xbzrle_cache_size(void) +uint64_t migrate_xbzrle_cache_size(void) { MigrationState *s; =20 diff --git a/migration/migration.h b/migration/migration.h index 0723955cd7..db6708326b 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -327,7 +327,7 @@ int migrate_multifd_zlib_level(void); int migrate_multifd_zstd_level(void); =20 int migrate_use_xbzrle(void); -int64_t migrate_xbzrle_cache_size(void); +uint64_t migrate_xbzrle_cache_size(void); bool migrate_colo_enabled(void); =20 bool migrate_use_block(void); diff --git a/migration/page_cache.c b/migration/page_cache.c index 098b436223..b384f265fb 100644 --- a/migration/page_cache.c +++ b/migration/page_cache.c @@ -38,7 +38,7 @@ struct PageCache { size_t num_items; }; =20 -PageCache *cache_init(int64_t new_size, size_t page_size, Error **errp) +PageCache *cache_init(uint64_t new_size, size_t page_size, Error **errp) { int64_t i; size_t num_pages =3D new_size / page_size; diff --git a/migration/page_cache.h b/migration/page_cache.h index 0cb94498a0..8733b4df6e 100644 --- a/migration/page_cache.h +++ b/migration/page_cache.h @@ -28,7 +28,7 @@ typedef struct PageCache PageCache; * @page_size: cache page size * @errp: set *errp if the check failed, with reason */ -PageCache *cache_init(int64_t cache_size, size_t page_size, Error **errp); +PageCache *cache_init(uint64_t cache_size, size_t page_size, Error **errp); /** * cache_fini: free all cache resources * @cache pointer to the PageCache struct diff --git a/migration/ram.c b/migration/ram.c index 26adb55aa9..46e9d4d145 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -131,7 +131,7 @@ static void XBZRLE_cache_unlock(void) * @new_size: new cache size * @errp: set *errp if the check failed, with reason */ -int xbzrle_cache_resize(int64_t new_size, Error **errp) +int xbzrle_cache_resize(uint64_t new_size, Error **errp) { PageCache *new_cache; int64_t ret =3D 0; diff --git a/migration/ram.h b/migration/ram.h index c25540cb93..6378bb3ebc 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -47,7 +47,7 @@ bool ramblock_is_ignored(RAMBlock *block); INTERNAL_RAMBLOCK_FOREACH(block) \ if (!qemu_ram_is_migratable(block)) {} else =20 -int xbzrle_cache_resize(int64_t new_size, Error **errp); +int xbzrle_cache_resize(uint64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); =20 diff --git a/qapi/migration.json b/qapi/migration.json index 37026643ab..797f9edbc2 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -78,7 +78,7 @@ # Since: 1.2 ## { 'struct': 'XBZRLECacheStats', - 'data': {'cache-size': 'int', 'bytes': 'int', 'pages': 'int', + 'data': {'cache-size': 'size', 'bytes': 'int', 'pages': 'int', 'cache-miss': 'int', 'cache-miss-rate': 'number', 'encoding-rate': 'number', 'overflow': 'int' } } =20 @@ -1470,7 +1470,7 @@ # <- { "return": 67108864 } # ## -{ 'command': 'query-migrate-cache-size', 'returns': 'int', +{ 'command': 'query-migrate-cache-size', 'returns': 'size', 'features': [ 'deprecated' ] } =20 ## --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459422; cv=none; d=zohomail.com; s=zohoarc; b=Lt4NO4xzCqaqSY6Ny3Y78SeinWGvOw4HkFew/t929LKR0ubx8gcdx+bOEYwnAn1TsRvZdcLBhT89k4q4mdNbTBUGdQ18ELhsEiP6ap9+1tzLO0fAN7waFwBn2O2maY8q0vcT82OKnpKIivgzy3IA2pNSi7Q1DsZuD+3sL1QhPzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459422; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HjLOWmZArq6FQ4QbVsGRrFuusXByKswK9vWyVZhQ+2g=; b=YrtOYYy6dX0qJSVVyrkp04EIvjG8N1PFvws8kG9qHhsBi0ZkeuOlSm7qf1iOPg8F15tLfWMN5Bl8g3aPce+a+/WjL14XQ7zZUeNS5IceouLn3eJCaivIlzIEn/ECOU/Hdh37Dhr/Q1QzSJWyDvTITZIxUrQCDg0kbTfwuN4m7cQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161245942247946.52623335062742; Thu, 4 Feb 2021 09:23:42 -0800 (PST) Received: from localhost ([::1]:32954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iM1-0002ta-8E for importer@patchew.org; Thu, 04 Feb 2021 12:23:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hh5-0002Fk-W9 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hh3-0005Ev-MR for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:23 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-XZwG0sI6NIS41_HZ7JDDqA-1; Thu, 04 Feb 2021 11:41:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E726980403B; Thu, 4 Feb 2021 16:41:17 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF4AE19708; Thu, 4 Feb 2021 16:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HjLOWmZArq6FQ4QbVsGRrFuusXByKswK9vWyVZhQ+2g=; b=D8TXqc8UiikI2hlYV1T87qHx5Dg1r7PPRx8JEeD02LuGNwIKOKUdzluxDov0Z1VTAFUjWV rdjzNfzq4Eba1zRlZGh2xJbncAZaxMXIgGeBqQsB68H7f3YyhRYvAZjFATuoEatMfZ4J4r OXbhTLKJiO3ptyckTEX+PrHr0CqtWng= X-MC-Unique: XZwG0sI6NIS41_HZ7JDDqA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 12/27] migration: Fix cache_init()'s "Failed to allocate" error messages Date: Thu, 4 Feb 2021 16:39:44 +0000 Message-Id: <20210204163959.377618-13-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Markus Armbruster cache_init() attempts to handle allocation failure. The two error messages are garbage, as untested error messages commonly are: Parameter 'cache size' expects Failed to allocate cache Parameter 'cache size' expects Failed to allocate page cache Fix them to just Failed to allocate cache Failed to allocate page cache Signed-off-by: Markus Armbruster Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210202141734.2488076-4-armbru@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/page_cache.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/migration/page_cache.c b/migration/page_cache.c index b384f265fb..6d4f7a9bbc 100644 --- a/migration/page_cache.c +++ b/migration/page_cache.c @@ -60,8 +60,7 @@ PageCache *cache_init(uint64_t new_size, size_t page_size= , Error **errp) /* We prefer not to abort if there is no memory */ cache =3D g_try_malloc(sizeof(*cache)); if (!cache) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "Failed to allocate cache"); + error_setg(errp, "Failed to allocate cache"); return NULL; } cache->page_size =3D page_size; @@ -74,8 +73,7 @@ PageCache *cache_init(uint64_t new_size, size_t page_size= , Error **errp) cache->page_cache =3D g_try_malloc((cache->max_num_items) * sizeof(*cache->page_cache)); if (!cache->page_cache) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "Failed to allocate page cache"); + error_setg(errp, "Failed to allocate page cache"); g_free(cache); return NULL; } --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459619; cv=none; d=zohomail.com; s=zohoarc; b=QFoXOjPNWmiOq1AnyeeMuszObXTUUomMDuXL9hQN53W93xAqIZS4t6KEWYwVwf3G7PR2t0PXwnErxDDhkbQfsnCoA5mUz3JDkHd9OlQPx4hMPTIOhGCpuQIM3mFbradMOFuWVOdzLKcNboyiGJY8JlSpUyI+DwHz5kHkT0KPBJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459619; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C2MXwALsDH8SfU3T1u4oBtPowlnQBSHSYO9aYVFdlVA=; b=alZEFuylKzBSQJ8BgAuaEy0+WBFQIkgBr5lDVWuGtwHwFjK2qlGI4EI/bb/o3D62ZLe13IdgyN2RTgi6FvWhEXtNLJI7VyzDF+x1sSns1bzpUWv5jficV+j+XI6T1BzepjR9rY1ncOwEC3u/woRmXp+mQeLK9duPOTu4cB5jY1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459619162379.2944801188271; Thu, 4 Feb 2021 09:26:59 -0800 (PST) Received: from localhost ([::1]:41188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iPC-0006bF-2R for importer@patchew.org; Thu, 04 Feb 2021 12:26:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hhB-0002RD-K8 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hh9-0005Hv-PR for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:29 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-5VXhAx7SPW-mkH9lGyDmnA-1; Thu, 04 Feb 2021 11:41:24 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE402C7405; Thu, 4 Feb 2021 16:41:23 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CF2219708; Thu, 4 Feb 2021 16:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C2MXwALsDH8SfU3T1u4oBtPowlnQBSHSYO9aYVFdlVA=; b=L6vvayDOvgYzqGRdkBCGjgP94sYV9mcyUCNSMHb9uxBoVHUV1As6gtsgDiiHMSCjpejgpS bWtahTsvPIsqumX9JG0Z/ozmexpCgwT/eCu7wnrB7lgRV8q0FcEygNvxpIcIlSLXxZX/OH ij1WV2cTcz4L6C7Y6u5obddKfmcLLSY= X-MC-Unique: 5VXhAx7SPW-mkH9lGyDmnA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 13/27] migration: Fix a few absurdly defective error messages Date: Thu, 4 Feb 2021 16:39:45 +0000 Message-Id: <20210204163959.377618-14-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Markus Armbruster migrate_params_check() has a number of error messages of the form Parameter 'NAME' expects is invalid, it should be ... Fix them to something like Parameter 'NAME' expects a ... Signed-off-by: Markus Armbruster Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210202141734.2488076-5-armbru@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 77b0c39b50..38efaeee94 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1317,21 +1317,21 @@ static bool migrate_params_check(MigrationParameter= s *params, Error **errp) if (params->has_compress_level && (params->compress_level > 9)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level", - "is invalid, it should be in the range of 0 to 9"); + "a value between 0 and 9"); return false; } =20 if (params->has_compress_threads && (params->compress_threads < 1)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_threads", - "is invalid, it should be in the range of 1 to 255"); + "a value between 1 and 255"); return false; } =20 if (params->has_decompress_threads && (params->decompress_threads < 1)= ) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "decompress_threads", - "is invalid, it should be in the range of 1 to 255"); + "a value between 1 and 255"); return false; } =20 @@ -1384,21 +1384,21 @@ static bool migrate_params_check(MigrationParameter= s *params, Error **errp) if (params->has_multifd_channels && (params->multifd_channels < 1)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_channels", - "is invalid, it should be in the range of 1 to 255"); + "a value between 1 and 255"); return false; } =20 if (params->has_multifd_zlib_level && (params->multifd_zlib_level > 9)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zlib_level= ", - "is invalid, it should be in the range of 0 to 9"); + "a value between 0 and 9"); return false; } =20 if (params->has_multifd_zstd_level && (params->multifd_zstd_level > 20)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "multifd_zstd_level= ", - "is invalid, it should be in the range of 0 to 20"); + "a value between 0 and 20"); return false; } =20 @@ -1407,8 +1407,7 @@ static bool migrate_params_check(MigrationParameters = *params, Error **errp) !is_power_of_2(params->xbzrle_cache_size))) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "xbzrle_cache_size", - "is invalid, it should be bigger than target page size" - " and a power of 2"); + "a power of two no less than the target page size"); return false; } =20 @@ -1425,21 +1424,21 @@ static bool migrate_params_check(MigrationParameter= s *params, Error **errp) params->announce_initial > 100000) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "announce_initial", - "is invalid, it must be less than 100000 ms"); + "a value between 0 and 100000"); return false; } if (params->has_announce_max && params->announce_max > 100000) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "announce_max", - "is invalid, it must be less than 100000 ms"); + "a value between 0 and 100000"); return false; } if (params->has_announce_rounds && params->announce_rounds > 1000) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "announce_rounds", - "is invalid, it must be in the range of 0 to 1000"); + "a value between 0 and 1000"); return false; } if (params->has_announce_step && @@ -1447,7 +1446,7 @@ static bool migrate_params_check(MigrationParameters = *params, Error **errp) params->announce_step > 10000)) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "announce_step", - "is invalid, it must be in the range of 1 to 10000 ms"); + "a value between 0 and 10000"); return false; } =20 --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459771; cv=none; d=zohomail.com; s=zohoarc; b=Hy+G7E02B+cewc9K1Wqk/yjJVJdtkwovFDVpe/doKnh/qDvxy76TiK4rpSDJYBoevIWLvaDaBr+tQPFE8BlKsByWyvUhE+tHdq7e9Qm9G8XQRyn4lggcf50lieyhxxEbub/yEGXjj1rQBvYnZ3JVuu5okkEFYjfmpZHUYVHoyJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459771; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yc5g1VS7wdhZq/cGxyQhXZtjOQfWi4uMaZthHjR1GTU=; b=WdsEByhZVsXKU/WzYf1FT+z3cQkCFp0/fEggjvZAtt2XrS8D+jWcu6UhIVU/YszPuO/7JAT04u0TnMva9eNWY62uLMmLTmgoCD9SLicKWQ5ndej0ZCTt/5CFwLWilfRQ18v0HVcAQPwRsvu/2ZvKC7Nkm1TbQfxDnRBcjFN0A6A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459771004876.7369899386729; Thu, 4 Feb 2021 09:29:31 -0800 (PST) Received: from localhost ([::1]:46420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iRd-0000ar-QK for importer@patchew.org; Thu, 04 Feb 2021 12:29:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hhE-0002ZH-Jm for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32361) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hhC-0005Ko-R8 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:32 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-rzh1E29yNb67F4vNh4nMAg-1; Thu, 04 Feb 2021 11:41:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3E3480402C; Thu, 4 Feb 2021 16:41:26 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 150ED1A38C; Thu, 4 Feb 2021 16:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yc5g1VS7wdhZq/cGxyQhXZtjOQfWi4uMaZthHjR1GTU=; b=GnOmMTnlmi5vdW4mg+WpBSbouw3IC4t0Vxl4bjvemEod+UR6yAgZpWcLaFjSg/0WJ8O8Ou wEk2MVix+LkloCOVJWVX2RjWjM/tJmEKb6DmOeAMhByzkxgGn4GdbpDqNIhANdVj9Y+fOc mTDMakU1uu46yymO1qm2WWIOeYCjbew= X-MC-Unique: rzh1E29yNb67F4vNh4nMAg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 14/27] migration: Add blocker information Date: Thu, 4 Feb 2021 16:39:46 +0000 Message-Id: <20210204163959.377618-15-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Modify query-migrate so that it has a flag indicating if outbound migration is blocked, and if it is a list of reasons. Signed-off-by: Dr. David Alan Gilbert Message-Id: <20210202135522.127380-2-dgilbert@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 25 +++++++++++++++++++++++-- migration/savevm.c | 13 +++++++++++++ migration/savevm.h | 1 + qapi/migration.json | 6 ++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 38efaeee94..a5ddf43559 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -174,6 +174,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snaps= hot, static MigrationState *current_migration; static MigrationIncomingState *current_incoming; =20 +static GSList *migration_blockers; + static bool migration_object_check(MigrationState *ms, Error **errp); static int migration_maybe_pause(MigrationState *s, int *current_active_state, @@ -1074,6 +1076,27 @@ static void fill_source_migration_info(MigrationInfo= *info) { MigrationState *s =3D migrate_get_current(); =20 + info->blocked =3D migration_is_blocked(NULL); + info->has_blocked_reasons =3D info->blocked; + info->blocked_reasons =3D NULL; + if (info->blocked) { + GSList *cur_blocker =3D migration_blockers; + + /* + * There are two types of reasons a migration might be blocked; + * a) devices marked in VMState as non-migratable, and + * b) Explicit migration blockers + * We need to add both of them here. + */ + qemu_savevm_non_migratable_list(&info->blocked_reasons); + + while (cur_blocker) { + QAPI_LIST_PREPEND(info->blocked_reasons, + g_strdup(error_get_pretty(cur_blocker->data)= )); + cur_blocker =3D g_slist_next(cur_blocker); + } + } + switch (s->state) { case MIGRATION_STATUS_NONE: /* no migration has happened ever */ @@ -2025,8 +2048,6 @@ void migrate_init(MigrationState *s) s->threshold_size =3D 0; } =20 -static GSList *migration_blockers; - int migrate_add_blocker(Error *reason, Error **errp) { if (only_migratable) { diff --git a/migration/savevm.c b/migration/savevm.c index d5bf53388f..1178c6ca90 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1154,6 +1154,19 @@ bool qemu_savevm_state_blocked(Error **errp) return false; } =20 +void qemu_savevm_non_migratable_list(strList **reasons) +{ + SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->vmsd && se->vmsd->unmigratable) { + QAPI_LIST_PREPEND(*reasons, + g_strdup_printf("non-migratable device: %s", + se->idstr)); + } + } +} + void qemu_savevm_state_header(QEMUFile *f) { trace_savevm_state_header(); diff --git a/migration/savevm.h b/migration/savevm.h index aaee2528ed..6461342cb4 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -30,6 +30,7 @@ #define QEMU_VM_SECTION_FOOTER 0x7e =20 bool qemu_savevm_state_blocked(Error **errp); +void qemu_savevm_non_migratable_list(strList **reasons); void qemu_savevm_state_setup(QEMUFile *f); bool qemu_savevm_state_guest_unplug_pending(void); int qemu_savevm_state_resume_prepare(MigrationState *s); diff --git a/qapi/migration.json b/qapi/migration.json index 797f9edbc2..076d2d5634 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -224,6 +224,10 @@ # only returned if VFIO device is present, migration is supported b= y all # VFIO devices and status is 'active' or 'completed' (since 5.2) # +# @blocked: True if outgoing migration is blocked (since 6.0) +# +# @blocked-reasons: A list of reasons an outgoing migration is blocked (si= nce 6.0) +# # Since: 0.14 ## { 'struct': 'MigrationInfo', @@ -237,6 +241,8 @@ '*setup-time': 'int', '*cpu-throttle-percentage': 'int', '*error-desc': 'str', + 'blocked': 'bool', + '*blocked-reasons': ['str'], '*postcopy-blocktime' : 'uint32', '*postcopy-vcpu-blocktime': ['uint32'], '*compression': 'CompressionStats', --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612458759; cv=none; d=zohomail.com; s=zohoarc; b=ZeK4kiT5SY4XMAfK2lziNnBiMsUfH2tBBnWLJJyXL6n32e+wvjgPyAjuvr8seYwkaEajitPezTentsEGtrn85htj64/ulVZBZM0Tr0xX0OGUP243b3Q9ZLuv70K/yQf/fpXvbx5OQ2Bn8IywuAZgD29ST3y3Sg5XaVUAMITTbRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612458759; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2/g6xzZ/kCZp2f4ptDqdlxGVJM9ZkpZgAyouxgPX+5A=; b=T19FfB9WmRUOHdgLdKW+clrwWk+puN80nA6Hc6SbsBJQgJSS6hT+CreLjwI7o3vqGqld8lybK7Irg2FVFc9v2IIKXYeq44uqrFg/LIPpjQoEkw+0JY1sVPhpwLX4ls65Fk7LDyN3edz4OV4KmXSi+t3lj4+kNq4WC01/dOnTUmw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612458759371415.75353951421073; Thu, 4 Feb 2021 09:12:39 -0800 (PST) Received: from localhost ([::1]:60140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iBK-0006gE-8q for importer@patchew.org; Thu, 04 Feb 2021 12:12:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hhM-0002u6-7L for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hhJ-0005OM-C1 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:39 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-uy2_nTcvM3CrHW6Rnilchg-1; Thu, 04 Feb 2021 11:41:32 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75295C7400; Thu, 4 Feb 2021 16:41:31 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF33F19708; Thu, 4 Feb 2021 16:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2/g6xzZ/kCZp2f4ptDqdlxGVJM9ZkpZgAyouxgPX+5A=; b=LiVxvRe6JoMJXObGLqH1BtEGv9AjkTJNsgLmZEd5Mx7naVklMx+3w5iToQhhwr2xnv18d3 ioGV1Xa4gAYW0cE1TWxMAykH2rcAFzbdMBb3T7TA2gwzQfQA8idYGkYLr1Zhn2cmVHTVz7 Avbgk5VqP+TVtcR00BQBzN021wVsrHs= X-MC-Unique: uy2_nTcvM3CrHW6Rnilchg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 15/27] migration: Display the migration blockers Date: Thu, 4 Feb 2021 16:39:47 +0000 Message-Id: <20210204163959.377618-16-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Update 'info migrate' to display migration blocking information. If the outbound migration is not blocked, there is no change, however if it is blocked a message is displayed with a list of reasons why, e.g. qemu-system-x86_64 -nographic -smp 4 -m 4G -M pc,usb=3Don \ -chardev null,id=3Dn -device usb-serial,chardev=3Dn \ -virtfs local,path=3D/home,mount_tag=3Dfs,security_model=3Dnone \ -drive if=3Dvirtio,file=3Dmyimage.qcow2 (qemu) info migrate globals: store-global-state: on only-migratable: off send-configuration: on send-section-footer: on decompress-error-check: on clear-bitmap-shift: 18 Outgoing migration blocked: Migration is disabled when VirtFS export path '/home' is mounted in the g= uest using mount_tag 'fs' non-migratable device: 0000:00:01.2/1/usb-serial Signed-off-by: Dr. David Alan Gilbert Message-Id: <20210202135522.127380-3-dgilbert@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- monitor/hmp-cmds.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 509d6b01ee..992ecf6f04 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -224,6 +224,15 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) =20 migration_global_dump(mon); =20 + if (info->blocked) { + strList *reasons =3D info->blocked_reasons; + monitor_printf(mon, "Outgoing migration blocked:\n"); + while (reasons) { + monitor_printf(mon, " %s\n", reasons->value); + reasons =3D reasons->next; + } + } + if (info->has_status) { monitor_printf(mon, "Migration status: %s", MigrationStatus_str(info->status)); --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460198; cv=none; d=zohomail.com; s=zohoarc; b=HExOSTuTYv7gfbqJMPzqOGiUqa5IpaY4lxjvAh6/l3Bvs/74lxTevP5oVx2aPNLSs8pAP1FclNsCtFn1iosFvVRuzKeSrWyNkFEjlzw2P/nTcfvnXKsC9/BlbkIfHwtQ0QAzxrxIfGobryRRrIQWqizoPDnzvlIpEhllSsmq2zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460198; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hUWamYU21yHx0lZ1uvO8Nq9sAhO1HE51cuYk8gqkjLc=; b=RTXFdHo0mCFB51jzHHRr1sJTg+5pL7DTMBJ7fd10OsDwP/4+JxZitSzKAL9oub6AckR+KA09nkecDnzRAW64X8Dx4ae5Q7GAudfqZMeTS1LUyLUMzC9AgURC1AnkOZknDCjzDAU5Z/V/pBt7NCtZdaXYDRnPImcxzPOWUDDoG58= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460198703645.2684286818737; Thu, 4 Feb 2021 09:36:38 -0800 (PST) Received: from localhost ([::1]:35184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iYV-0007vx-Hc for importer@patchew.org; Thu, 04 Feb 2021 12:36:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hhS-0003B0-VU for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hhQ-0005SS-FP for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-43-31rnn8uZM3iHF14PBj3Wow-1; Thu, 04 Feb 2021 11:41:41 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77EFE1800D50; Thu, 4 Feb 2021 16:41:40 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4515D19708; Thu, 4 Feb 2021 16:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456903; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hUWamYU21yHx0lZ1uvO8Nq9sAhO1HE51cuYk8gqkjLc=; b=eJrC8/X7XhTPjbMBOK+YY0qXW0d+pyT/ksjtSEzoNy30/6ymGbL8jbBFWZizhqj0Wbs+eA 5E6ZW/4aM7/wuxKtNVhHSnLU2AItEfhxXtsAVE8+d3xJba6Y2r7VSITsHekP7aEuA8eJyI Q5Z020bu3hJgTbyBDmx3ZOdxzgrufuM= X-MC-Unique: 31rnn8uZM3iHF14PBj3Wow-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 16/27] block: push error reporting into bdrv_all_*_snapshot functions Date: Thu, 4 Feb 2021 16:39:48 +0000 Message-Id: <20210204163959.377618-17-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 The bdrv_all_*_snapshot functions return a BlockDriverState pointer for the invalid backend, which the callers then use to report an error message. In some cases multiple callers are reporting the same error message, but with slightly different text. In the future there will be more error scenarios for some of these methods, which will benefit from fine grained error message reporting. So it is helpful to push error reporting down a level. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 [PMD: Initialize variables] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20210204124834.774401-2-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 7 ++-- block/snapshot.c | 77 +++++++++++++++++----------------- include/block/snapshot.h | 14 +++---- migration/savevm.c | 39 +++++------------ monitor/hmp-cmds.c | 7 +--- replay/replay-debugging.c | 4 +- tests/qemu-iotests/267.out | 10 ++--- 7 files changed, 68 insertions(+), 90 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index afd75ab628..9532d085ea 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -900,10 +900,11 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qd= ict) =20 ImageEntry *image_entry, *next_ie; SnapshotEntry *snapshot_entry; + Error *err =3D NULL; =20 - bs =3D bdrv_all_find_vmstate_bs(); + bs =3D bdrv_all_find_vmstate_bs(&err); if (!bs) { - monitor_printf(mon, "No available block device supports snapshots\= n"); + error_report_err(err); return; } aio_context =3D bdrv_get_aio_context(bs); @@ -953,7 +954,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdic= t) total =3D 0; for (i =3D 0; i < nb_sns; i++) { SnapshotEntry *next_sn; - if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) =3D=3D 0) { + if (bdrv_all_find_snapshot(sn_tab[i].name, NULL) =3D=3D 0) { global_snapshots[total] =3D i; total++; QTAILQ_FOREACH(image_entry, &image_list, next) { diff --git a/block/snapshot.c b/block/snapshot.c index a2bf3a54eb..482e3fc7b7 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -462,14 +462,14 @@ static bool bdrv_all_snapshots_includes_bs(BlockDrive= rState *bs) * These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers) */ =20 -bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs) +bool bdrv_all_can_snapshot(Error **errp) { - bool ok =3D true; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + bool ok =3D true; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs)) { @@ -477,26 +477,25 @@ bool bdrv_all_can_snapshot(BlockDriverState **first_b= ad_bs) } aio_context_release(ctx); if (!ok) { + error_setg(errp, "Device '%s' is writable but does not support= " + "snapshots", bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return false; } } =20 -fail: - *first_bad_bs =3D bs; - return ok; + return true; } =20 -int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_ba= d_bs, - Error **errp) +int bdrv_all_delete_snapshot(const char *name, Error **errp) { - int ret =3D 0; BlockDriverState *bs; BdrvNextIterator it; QEMUSnapshotInfo sn1, *snapshot =3D &sn1; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret =3D 0; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs) && @@ -507,26 +506,25 @@ int bdrv_all_delete_snapshot(const char *name, BlockD= riverState **first_bad_bs, } aio_context_release(ctx); if (ret < 0) { + error_prepend(errp, "Could not delete snapshot '%s' on '%s': ", + name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return ret; + return 0; } =20 =20 -int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_= bs, - Error **errp) +int bdrv_all_goto_snapshot(const char *name, Error **errp) { - int ret =3D 0; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret =3D 0; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs)) { @@ -534,75 +532,75 @@ int bdrv_all_goto_snapshot(const char *name, BlockDri= verState **first_bad_bs, } aio_context_release(ctx); if (ret < 0) { + error_prepend(errp, "Could not load snapshot '%s' on '%s': ", + name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return ret; + return 0; } =20 -int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_= bs) +int bdrv_all_find_snapshot(const char *name, Error **errp) { QEMUSnapshotInfo sn; - int err =3D 0; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret =3D 0; =20 aio_context_acquire(ctx); if (bdrv_all_snapshots_includes_bs(bs)) { - err =3D bdrv_snapshot_find(bs, &sn, name); + ret =3D bdrv_snapshot_find(bs, &sn, name); } aio_context_release(ctx); - if (err < 0) { + if (ret < 0) { + error_setg(errp, "Could not find snapshot '%s' on '%s'", + name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return err; + return 0; } =20 int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, - BlockDriverState **first_bad_bs) + Error **errp) { - int err =3D 0; BlockDriverState *bs; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *ctx =3D bdrv_get_aio_context(bs); + int ret =3D 0; =20 aio_context_acquire(ctx); if (bs =3D=3D vm_state_bs) { sn->vm_state_size =3D vm_state_size; - err =3D bdrv_snapshot_create(bs, sn); + ret =3D bdrv_snapshot_create(bs, sn); } else if (bdrv_all_snapshots_includes_bs(bs)) { sn->vm_state_size =3D 0; - err =3D bdrv_snapshot_create(bs, sn); + ret =3D bdrv_snapshot_create(bs, sn); } aio_context_release(ctx); - if (err < 0) { + if (ret < 0) { + error_setg(errp, "Could not create snapshot '%s' on '%s'", + sn->name, bdrv_get_device_or_node_name(bs)); bdrv_next_cleanup(&it); - goto fail; + return -1; } } =20 -fail: - *first_bad_bs =3D bs; - return err; + return 0; } =20 -BlockDriverState *bdrv_all_find_vmstate_bs(void) +BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp) { BlockDriverState *bs; BdrvNextIterator it; @@ -620,5 +618,8 @@ BlockDriverState *bdrv_all_find_vmstate_bs(void) break; } } + if (!bs) { + error_setg(errp, "No block device supports snapshots"); + } return bs; } diff --git a/include/block/snapshot.h b/include/block/snapshot.h index b0fe42993d..5cb2b696ad 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -77,17 +77,15 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverSta= te *bs, * These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers */ =20 -bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs); -int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bs= d_bs, - Error **errp); -int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_= bs, - Error **errp); -int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_= bs); +bool bdrv_all_can_snapshot(Error **errp); +int bdrv_all_delete_snapshot(const char *name, Error **errp); +int bdrv_all_goto_snapshot(const char *name, Error **errp); +int bdrv_all_find_snapshot(const char *name, Error **errp); int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, - BlockDriverState **first_bad_bs); + Error **errp); =20 -BlockDriverState *bdrv_all_find_vmstate_bs(void); +BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 1178c6ca90..948e82c9ed 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2766,7 +2766,7 @@ int qemu_load_device_state(QEMUFile *f) =20 int save_snapshot(const char *name, Error **errp) { - BlockDriverState *bs, *bs1; + BlockDriverState *bs; QEMUSnapshotInfo sn1, *sn =3D &sn1; int ret =3D -1, ret2; QEMUFile *f; @@ -2786,25 +2786,19 @@ int save_snapshot(const char *name, Error **errp) return ret; } =20 - if (!bdrv_all_can_snapshot(&bs)) { - error_setg(errp, "Device '%s' is writable but does not support " - "snapshots", bdrv_get_device_or_node_name(bs)); + if (!bdrv_all_can_snapshot(errp)) { return ret; } =20 /* Delete old snapshots of the same name */ if (name) { - ret =3D bdrv_all_delete_snapshot(name, &bs1, errp); - if (ret < 0) { - error_prepend(errp, "Error while deleting snapshot on device " - "'%s': ", bdrv_get_device_or_node_name(bs1)); + if (bdrv_all_delete_snapshot(name, errp) < 0) { return ret; } } =20 - bs =3D bdrv_all_find_vmstate_bs(); + bs =3D bdrv_all_find_vmstate_bs(errp); if (bs =3D=3D NULL) { - error_setg(errp, "No block device can accept snapshots"); return ret; } aio_context =3D bdrv_get_aio_context(bs); @@ -2868,11 +2862,9 @@ int save_snapshot(const char *name, Error **errp) aio_context_release(aio_context); aio_context =3D NULL; =20 - ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs); + ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, errp); if (ret < 0) { - error_setg(errp, "Error while creating snapshot on '%s'", - bdrv_get_device_or_node_name(bs)); - bdrv_all_delete_snapshot(sn->name, &bs, NULL); + bdrv_all_delete_snapshot(sn->name, NULL); goto the_end; } =20 @@ -2975,30 +2967,23 @@ void qmp_xen_load_devices_state(const char *filenam= e, Error **errp) =20 int load_snapshot(const char *name, Error **errp) { - BlockDriverState *bs, *bs_vm_state; + BlockDriverState *bs_vm_state; QEMUSnapshotInfo sn; QEMUFile *f; int ret; AioContext *aio_context; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 - if (!bdrv_all_can_snapshot(&bs)) { - error_setg(errp, - "Device '%s' is writable but does not support snapshots= ", - bdrv_get_device_or_node_name(bs)); + if (!bdrv_all_can_snapshot(errp)) { return -ENOTSUP; } - ret =3D bdrv_all_find_snapshot(name, &bs); + ret =3D bdrv_all_find_snapshot(name, errp); if (ret < 0) { - error_setg(errp, - "Device '%s' does not have the requested snapshot '%s'", - bdrv_get_device_or_node_name(bs), name); return ret; } =20 - bs_vm_state =3D bdrv_all_find_vmstate_bs(); + bs_vm_state =3D bdrv_all_find_vmstate_bs(errp); if (!bs_vm_state) { - error_setg(errp, "No block device supports snapshots"); return -ENOTSUP; } aio_context =3D bdrv_get_aio_context(bs_vm_state); @@ -3024,10 +3009,8 @@ int load_snapshot(const char *name, Error **errp) /* Flush all IO requests so they don't interfere with the new state. = */ bdrv_drain_all_begin(); =20 - ret =3D bdrv_all_goto_snapshot(name, &bs, errp); + ret =3D bdrv_all_goto_snapshot(name, errp); if (ret < 0) { - error_prepend(errp, "Could not load snapshot '%s' on '%s': ", - name, bdrv_get_device_or_node_name(bs)); goto err_drain; } =20 diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 992ecf6f04..2b954763e4 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1155,15 +1155,10 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) =20 void hmp_delvm(Monitor *mon, const QDict *qdict) { - BlockDriverState *bs; Error *err =3D NULL; const char *name =3D qdict_get_str(qdict, "name"); =20 - if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { - error_prepend(&err, - "deleting snapshot on device '%s': ", - bdrv_get_device_name(bs)); - } + bdrv_all_delete_snapshot(name, &err); hmp_handle_error(mon, err); } =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 5ec574724a..3a9b609e62 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -148,7 +148,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, =20 *snapshot_icount =3D -1; =20 - bs =3D bdrv_all_find_vmstate_bs(); + bs =3D bdrv_all_find_vmstate_bs(NULL); if (!bs) { goto fail; } @@ -159,7 +159,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, aio_context_release(aio_context); =20 for (i =3D 0; i < nb_sns; i++) { - if (bdrv_all_find_snapshot(sn_tab[i].name, &bs) =3D=3D 0) { + if (bdrv_all_find_snapshot(sn_tab[i].name, NULL) =3D=3D 0) { if (sn_tab[i].icount !=3D -1ULL && sn_tab[i].icount <=3D icount && (!nearest || nearest->icount < sn_tab[i].icount)) { diff --git a/tests/qemu-iotests/267.out b/tests/qemu-iotests/267.out index 27471ffae8..6149029b25 100644 --- a/tests/qemu-iotests/267.out +++ b/tests/qemu-iotests/267.out @@ -6,9 +6,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1342177= 28 Testing: QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 -Error: No block device can accept snapshots +Error: No block device supports snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: No block device supports snapshots (qemu) quit @@ -22,7 +22,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) quit @@ -58,7 +58,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) quit @@ -83,7 +83,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) info snapshots -No available block device supports snapshots +No block device supports snapshots (qemu) loadvm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) quit --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612458952; cv=none; d=zohomail.com; s=zohoarc; b=AY9TjY/txX21ykD7+t+oIf224Xrj0+fseiipmFUPFyWUHxLo8SbW4G4YJNisxu/dteKky88+a2VJJxDWVsf41TH0NFAGCrv1uj6s6xBVb2IpfBLDN4ABodQ6ifvM8rzaH4pyRHhAl9g675fr+ulPaH17eTXwESxuVurgyUIW2FU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612458952; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IJlWNOZuDIfpXA6INj9klRTUjTDuqsHP4GxCCBGl+qM=; b=gffjkPzMKdkcTNz631abZ7YOQ2q31sgYgEcqTBBDOTzCVN0yzcl/nvbHdj2gA7pTaTpVCvLkT6u7gheVBSjqQ1V7s+6dY1ky2Iee9D6uKgw+eB/ICjN9Rip7gDs/fZJQmAEybi5ETYsmkaEE0GJ2XdNx52hSPNX++ohjIXQRl90= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612458952973591.4029417728021; Thu, 4 Feb 2021 09:15:52 -0800 (PST) Received: from localhost ([::1]:40500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iER-0001qJ-Mz for importer@patchew.org; Thu, 04 Feb 2021 12:15:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hhZ-0003Eg-TP for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hhX-0005Zw-Oe for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-_6nC2JpENviidVldj81L_A-1; Thu, 04 Feb 2021 11:41:47 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C787D193578E; Thu, 4 Feb 2021 16:41:46 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3A4719708; Thu, 4 Feb 2021 16:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IJlWNOZuDIfpXA6INj9klRTUjTDuqsHP4GxCCBGl+qM=; b=NKRt5ZyeTvl/8Bc4csby69gq5JyOhaa585NzFy4mBYTFMCr77Oc9z3KU9nEDdtXCPoWqrT 4s9s0uxCSauQOEMdyZvqsKOPNDgH9dFgWwx8o+8qoQsdaM3xPtYIwM/umhUJsI7+QvZ6DP PJhUQCq5yh51FahDUQN6p/JGKdGxjY0= X-MC-Unique: _6nC2JpENviidVldj81L_A-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 17/27] migration: Make save_snapshot() return bool, not 0/-1 Date: Thu, 4 Feb 2021 16:39:49 +0000 Message-Id: <20210204163959.377618-18-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Philippe Mathieu-Daud=C3=A9 Just for consistency, following the example documented since commit e3fe3988d7 ("error: Document Error API usage rules"), return a boolean value indicating an error is set or not. Reviewed-by: Dr. David Alan Gilbert Acked-by: Pavel Dovgalyuk Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20210204124834.774401-3-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/snapshot.h | 9 ++++++++- migration/savevm.c | 16 ++++++++-------- replay/replay-debugging.c | 2 +- replay/replay-snapshot.c | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h index c85b6ec75b..0eaf1ba0b1 100644 --- a/include/migration/snapshot.h +++ b/include/migration/snapshot.h @@ -15,7 +15,14 @@ #ifndef QEMU_MIGRATION_SNAPSHOT_H #define QEMU_MIGRATION_SNAPSHOT_H =20 -int save_snapshot(const char *name, Error **errp); +/** + * save_snapshot: Save an internal snapshot. + * @name: name of internal snapshot + * @errp: pointer to error object + * On success, return %true. + * On failure, store an error through @errp and return %false. + */ +bool save_snapshot(const char *name, Error **errp); int load_snapshot(const char *name, Error **errp); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 948e82c9ed..63f1e63e51 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2764,7 +2764,7 @@ int qemu_load_device_state(QEMUFile *f) return 0; } =20 -int save_snapshot(const char *name, Error **errp) +bool save_snapshot(const char *name, Error **errp) { BlockDriverState *bs; QEMUSnapshotInfo sn1, *sn =3D &sn1; @@ -2777,29 +2777,29 @@ int save_snapshot(const char *name, Error **errp) AioContext *aio_context; =20 if (migration_is_blocked(errp)) { - return ret; + return false; } =20 if (!replay_can_snapshot()) { error_setg(errp, "Record/replay does not allow making snapshot " "right now. Try once more later."); - return ret; + return false; } =20 if (!bdrv_all_can_snapshot(errp)) { - return ret; + return false; } =20 /* Delete old snapshots of the same name */ if (name) { if (bdrv_all_delete_snapshot(name, errp) < 0) { - return ret; + return false; } } =20 bs =3D bdrv_all_find_vmstate_bs(errp); if (bs =3D=3D NULL) { - return ret; + return false; } aio_context =3D bdrv_get_aio_context(bs); =20 @@ -2808,7 +2808,7 @@ int save_snapshot(const char *name, Error **errp) ret =3D global_state_store(); if (ret) { error_setg(errp, "Error saving global state"); - return ret; + return false; } vm_stop(RUN_STATE_SAVE_VM); =20 @@ -2880,7 +2880,7 @@ int save_snapshot(const char *name, Error **errp) if (saved_vm_running) { vm_start(); } - return ret; + return ret =3D=3D 0; } =20 void qmp_xen_save_devices_state(const char *filename, bool has_live, bool = live, diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 3a9b609e62..8e0050915d 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -323,7 +323,7 @@ void replay_gdb_attached(void) */ if (replay_mode =3D=3D REPLAY_MODE_PLAY && !replay_snapshot) { - if (save_snapshot("start_debugging", NULL) !=3D 0) { + if (!save_snapshot("start_debugging", NULL)) { /* Can't create the snapshot. Continue conventional debugging.= */ } } diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index e26fa4c892..4f2560d156 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -77,7 +77,7 @@ void replay_vmstate_init(void) =20 if (replay_snapshot) { if (replay_mode =3D=3D REPLAY_MODE_RECORD) { - if (save_snapshot(replay_snapshot, &err) !=3D 0) { + if (!save_snapshot(replay_snapshot, &err)) { error_report_err(err); error_report("Could not create snapshot for icount record"= ); exit(1); --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459865; cv=none; d=zohomail.com; s=zohoarc; b=emkXFGVyWIqDWC63OIz/xRJnBTowyHnnHBLPkKywe/F1odTrRypnUopnP3A1mTHOduZ+BLjVH9o1fRyJL6se9WumDQsqajGg1BhP3A51palfFZti5pAZI35o/jygU1fxLIxqTrDnsidH29ZQ0pGuE6RUem61V3hoOjhkosywre4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459865; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RzSiG31GZpch7CNzgVIJxgn4C4GbPSNt1gSmegwQ1ok=; b=PUkJNj0RYOKNuJryE4s8nEcs9AukD1nBAhu4cZ2/Mq6IW7/HuK9i35ZKrx1+BGzUWOuzSbX/7gXIxS7KQ3p9nWyo5fT4bPOsRcUx5ZRLZ67iHkUA0FB5JtJGr2M17xtMIExQZGmeANcXxaqcNyOMtnUWCIO0KLesZeg/UFjz4K8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459865486440.9771902907255; Thu, 4 Feb 2021 09:31:05 -0800 (PST) Received: from localhost ([::1]:49508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iT9-0001wO-Se for importer@patchew.org; Thu, 04 Feb 2021 12:31:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hhe-0003H2-1M for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hha-0005cI-Vh for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:41:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-erbM7LhWPtWBFvnWPZ5ZxQ-1; Thu, 04 Feb 2021 11:41:50 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76A0680402C; Thu, 4 Feb 2021 16:41:49 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 774EA19708; Thu, 4 Feb 2021 16:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RzSiG31GZpch7CNzgVIJxgn4C4GbPSNt1gSmegwQ1ok=; b=SaG4d7Y05KIagGksm0OugP/d8Aqp5w6ANHUtcqYpsjapr0uMAKf87T58lkDyFKi/1ynqyc Pps2ix+lLJ/YS9kcKykuWJJkVkCXvVQDJIIjfXOzkx+k72VhEQyBJ0Y93A2nKL62fSmPcm Lo4a3rT8HSAODf/mJ5JJSAZZFIGYnj8= X-MC-Unique: erbM7LhWPtWBFvnWPZ5ZxQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 18/27] migration: stop returning errno from load_snapshot() Date: Thu, 4 Feb 2021 16:39:50 +0000 Message-Id: <20210204163959.377618-19-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 None of the callers care about the errno value since there is a full Error object populated. This gives consistency with save_snapshot() which already just returns a boolean value. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 [PMD: Return false/true instead of -1/0, document function] Acked-by: Pavel Dovgalyuk Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20210204124834.774401-4-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/snapshot.h | 10 +++++++++- migration/savevm.c | 19 +++++++++---------- monitor/hmp-cmds.c | 2 +- replay/replay-snapshot.c | 2 +- softmmu/vl.c | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h index 0eaf1ba0b1..d7d210820c 100644 --- a/include/migration/snapshot.h +++ b/include/migration/snapshot.h @@ -23,6 +23,14 @@ * On failure, store an error through @errp and return %false. */ bool save_snapshot(const char *name, Error **errp); -int load_snapshot(const char *name, Error **errp); + +/** + * load_snapshot: Load an internal snapshot. + * @name: name of internal snapshot + * @errp: pointer to error object + * On success, return %true. + * On failure, store an error through @errp and return %false. + */ +bool load_snapshot(const char *name, Error **errp); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 63f1e63e51..b85eefd682 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2965,7 +2965,7 @@ void qmp_xen_load_devices_state(const char *filename,= Error **errp) migration_incoming_state_destroy(); } =20 -int load_snapshot(const char *name, Error **errp) +bool load_snapshot(const char *name, Error **errp) { BlockDriverState *bs_vm_state; QEMUSnapshotInfo sn; @@ -2975,16 +2975,16 @@ int load_snapshot(const char *name, Error **errp) MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 if (!bdrv_all_can_snapshot(errp)) { - return -ENOTSUP; + return false; } ret =3D bdrv_all_find_snapshot(name, errp); if (ret < 0) { - return ret; + return false; } =20 bs_vm_state =3D bdrv_all_find_vmstate_bs(errp); if (!bs_vm_state) { - return -ENOTSUP; + return false; } aio_context =3D bdrv_get_aio_context(bs_vm_state); =20 @@ -2993,11 +2993,11 @@ int load_snapshot(const char *name, Error **errp) ret =3D bdrv_snapshot_find(bs_vm_state, &sn, name); aio_context_release(aio_context); if (ret < 0) { - return ret; + return false; } else if (sn.vm_state_size =3D=3D 0) { error_setg(errp, "This is a disk-only snapshot. Revert to it " " offline using qemu-img"); - return -EINVAL; + return false; } =20 /* @@ -3018,7 +3018,6 @@ int load_snapshot(const char *name, Error **errp) f =3D qemu_fopen_bdrv(bs_vm_state, 0); if (!f) { error_setg(errp, "Could not open VM state file"); - ret =3D -EINVAL; goto err_drain; } =20 @@ -3038,14 +3037,14 @@ int load_snapshot(const char *name, Error **errp) =20 if (ret < 0) { error_setg(errp, "Error %d while loading VM state", ret); - return ret; + return false; } =20 - return 0; + return true; =20 err_drain: bdrv_drain_all_end(); - return ret; + return false; } =20 void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 2b954763e4..6ff050ac3d 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1139,7 +1139,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict) =20 vm_stop(RUN_STATE_RESTORE_VM); =20 - if (load_snapshot(name, &err) =3D=3D 0 && saved_vm_running) { + if (!load_snapshot(name, &err) && saved_vm_running) { vm_start(); } hmp_handle_error(mon, err); diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 4f2560d156..b289365937 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -83,7 +83,7 @@ void replay_vmstate_init(void) exit(1); } } else if (replay_mode =3D=3D REPLAY_MODE_PLAY) { - if (load_snapshot(replay_snapshot, &err) !=3D 0) { + if (!load_snapshot(replay_snapshot, &err)) { error_report_err(err); error_report("Could not load snapshot for icount replay"); exit(1); diff --git a/softmmu/vl.c b/softmmu/vl.c index bd55468669..8f655086b7 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2529,7 +2529,7 @@ void qmp_x_exit_preconfig(Error **errp) =20 if (loadvm) { Error *local_err =3D NULL; - if (load_snapshot(loadvm, &local_err) < 0) { + if (!load_snapshot(loadvm, &local_err)) { error_report_err(local_err); autostart =3D 0; exit(1); --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460072; cv=none; d=zohomail.com; s=zohoarc; b=TxfjtmTP9iSBM4uc4TflRVNtXExTf/kSl/rdnAUqEPlZZfLEXsG4fTxChmMNTVDQDQUzCYQcNQwZtVLTy4fyoQpeLkJWf5jqXeyvnntYh64JdSkVU0Z9TV8Q0fR/wjgLwtjeaFCVA+bS5PEpLNayYCAfhr+1hlMB83hN0Yi9pbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460072; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=95YWl6BHPqbbaiKSP4iONeoXerjI8f1E4zl5Ow0Ooy4=; b=PK5jHNAb0e+VEBfb24/pou36lkmc4nzdXMMtlguAf2egPktuQiZxP6w/XMJMZ1XSnH6Ap5ayDVH+NRSf/GYr7be0flhL/o9ChRGI90lzb0t74ZmIH1rWKmpY4YNpJShWWCGa3gYG28C18g5AbGI4f5XAiIuBCVgUh6BkdwEWkxY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460072776559.2221303633529; Thu, 4 Feb 2021 09:34:32 -0800 (PST) Received: from localhost ([::1]:58408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iWV-0005oy-B6 for importer@patchew.org; Thu, 04 Feb 2021 12:34:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hhh-0003Mr-BE for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hhe-0005ek-Ut for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:01 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-W69GcviWOkaM1ht9b5Wd_Q-1; Thu, 04 Feb 2021 11:41:52 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC2B7C7406; Thu, 4 Feb 2021 16:41:51 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id A54AA1A38C; Thu, 4 Feb 2021 16:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=95YWl6BHPqbbaiKSP4iONeoXerjI8f1E4zl5Ow0Ooy4=; b=bazgs6Cq/CtMWn3ZNeRG6Qq8wIumw/lCTkPhjofuBEc+kVk67B5QU6cOGg9j5NvoW4JyM5 V8htngH1oKg+4rjLbb7p+vp8nJgSEMOTD/v41+ZOdTniA8FoP/Geew54YN37AWCaS61HrT xHrNldhT42cfktG3WC1rxwuuRQEg8RE= X-MC-Unique: W69GcviWOkaM1ht9b5Wd_Q-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 19/27] block: add ability to specify list of blockdevs during snapshot Date: Thu, 4 Feb 2021 16:39:51 +0000 Message-Id: <20210204163959.377618-20-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 When running snapshot operations, there are various rules for which blockdevs are included/excluded. While this provides reasonable default behaviour, there are scenarios that are not well handled by the default logic. Some of the conditions do not have a single correct answer. Thus there needs to be a way for the mgmt app to provide an explicit list of blockdevs to perform snapshots across. This can be achieved by passing a list of node names that should be used. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-5-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 4 +- block/snapshot.c | 172 ++++++++++++++++++++++++--------- include/block/snapshot.h | 22 +++-- migration/savevm.c | 18 ++-- monitor/hmp-cmds.c | 2 +- replay/replay-debugging.c | 4 +- 6 files changed, 159 insertions(+), 63 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 9532d085ea..e15121be1f 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -902,7 +902,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdic= t) SnapshotEntry *snapshot_entry; Error *err =3D NULL; =20 - bs =3D bdrv_all_find_vmstate_bs(&err); + bs =3D bdrv_all_find_vmstate_bs(false, NULL, &err); if (!bs) { error_report_err(err); return; @@ -954,7 +954,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdic= t) total =3D 0; for (i =3D 0; i < nb_sns; i++) { SnapshotEntry *next_sn; - if (bdrv_all_find_snapshot(sn_tab[i].name, NULL) =3D=3D 0) { + if (bdrv_all_find_snapshot(sn_tab[i].name, false, NULL, NULL) =3D= =3D 0) { global_snapshots[total] =3D i; total++; QTAILQ_FOREACH(image_entry, &image_list, next) { diff --git a/block/snapshot.c b/block/snapshot.c index 482e3fc7b7..220173deae 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -447,6 +447,41 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverSt= ate *bs, return ret; } =20 + +static int bdrv_all_get_snapshot_devices(bool has_devices, strList *device= s, + GList **all_bdrvs, + Error **errp) +{ + g_autoptr(GList) bdrvs =3D NULL; + + if (has_devices) { + if (!devices) { + error_setg(errp, "At least one device is required for snapshot= "); + return -1; + } + + while (devices) { + BlockDriverState *bs =3D bdrv_find_node(devices->value); + if (!bs) { + error_setg(errp, "No block device node '%s'", devices->val= ue); + return -1; + } + bdrvs =3D g_list_append(bdrvs, bs); + devices =3D devices->next; + } + } else { + BlockDriverState *bs; + BdrvNextIterator it; + for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + bdrvs =3D g_list_append(bdrvs, bs); + } + } + + *all_bdrvs =3D g_steal_pointer(&bdrvs); + return 0; +} + + static bool bdrv_all_snapshots_includes_bs(BlockDriverState *bs) { if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) { @@ -462,43 +497,59 @@ static bool bdrv_all_snapshots_includes_bs(BlockDrive= rState *bs) * These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers) */ =20 -bool bdrv_all_can_snapshot(Error **errp) +bool bdrv_all_can_snapshot(bool has_devices, strList *devices, + Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) = < 0) { + return false; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); bool ok =3D true; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs)) { + if (devices || bdrv_all_snapshots_includes_bs(bs)) { ok =3D bdrv_can_snapshot(bs); } aio_context_release(ctx); if (!ok) { error_setg(errp, "Device '%s' is writable but does not support= " "snapshots", bdrv_get_device_or_node_name(bs)); - bdrv_next_cleanup(&it); return false; } + + iterbdrvs =3D iterbdrvs->next; } =20 return true; } =20 -int bdrv_all_delete_snapshot(const char *name, Error **errp) +int bdrv_all_delete_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; - QEMUSnapshotInfo sn1, *snapshot =3D &sn1; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; + + if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) = < 0) { + return -1; + } =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); + QEMUSnapshotInfo sn1, *snapshot =3D &sn1; int ret =3D 0; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs) && + if ((devices || bdrv_all_snapshots_includes_bs(bs)) && bdrv_snapshot_find(bs, snapshot, name) >=3D 0) { ret =3D bdrv_snapshot_delete(bs, snapshot->id_str, @@ -508,61 +559,80 @@ int bdrv_all_delete_snapshot(const char *name, Error = **errp) if (ret < 0) { error_prepend(errp, "Could not delete snapshot '%s' on '%s': ", name, bdrv_get_device_or_node_name(bs)); - bdrv_next_cleanup(&it); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; } =20 =20 -int bdrv_all_goto_snapshot(const char *name, Error **errp) +int bdrv_all_goto_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) = < 0) { + return -1; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); int ret =3D 0; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs)) { + if (devices || bdrv_all_snapshots_includes_bs(bs)) { ret =3D bdrv_snapshot_goto(bs, name, errp); } aio_context_release(ctx); if (ret < 0) { error_prepend(errp, "Could not load snapshot '%s' on '%s': ", name, bdrv_get_device_or_node_name(bs)); - bdrv_next_cleanup(&it); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; } =20 -int bdrv_all_find_snapshot(const char *name, Error **errp) +int bdrv_all_find_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp) { - QEMUSnapshotInfo sn; - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; + + if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) = < 0) { + return -1; + } =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); + QEMUSnapshotInfo sn; int ret =3D 0; =20 aio_context_acquire(ctx); - if (bdrv_all_snapshots_includes_bs(bs)) { + if (devices || bdrv_all_snapshots_includes_bs(bs)) { ret =3D bdrv_snapshot_find(bs, &sn, name); } aio_context_release(ctx); if (ret < 0) { error_setg(errp, "Could not find snapshot '%s' on '%s'", name, bdrv_get_device_or_node_name(bs)); - bdrv_next_cleanup(&it); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; @@ -571,12 +641,19 @@ int bdrv_all_find_snapshot(const char *name, Error **= errp) int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, + bool has_devices, strList *devices, Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; + + if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) = < 0) { + return -1; + } =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); int ret =3D 0; =20 @@ -584,7 +661,7 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, if (bs =3D=3D vm_state_bs) { sn->vm_state_size =3D vm_state_size; ret =3D bdrv_snapshot_create(bs, sn); - } else if (bdrv_all_snapshots_includes_bs(bs)) { + } else if (devices || bdrv_all_snapshots_includes_bs(bs)) { sn->vm_state_size =3D 0; ret =3D bdrv_snapshot_create(bs, sn); } @@ -592,34 +669,43 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, if (ret < 0) { error_setg(errp, "Could not create snapshot '%s' on '%s'", sn->name, bdrv_get_device_or_node_name(bs)); - bdrv_next_cleanup(&it); return -1; } + + iterbdrvs =3D iterbdrvs->next; } =20 return 0; } =20 -BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp) +BlockDriverState *bdrv_all_find_vmstate_bs(bool has_devices, strList *devi= ces, + Error **errp) { - BlockDriverState *bs; - BdrvNextIterator it; + g_autoptr(GList) bdrvs =3D NULL; + GList *iterbdrvs; =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { + if (bdrv_all_get_snapshot_devices(has_devices, devices, &bdrvs, errp) = < 0) { + return NULL; + } + + iterbdrvs =3D bdrvs; + while (iterbdrvs) { + BlockDriverState *bs =3D iterbdrvs->data; AioContext *ctx =3D bdrv_get_aio_context(bs); - bool found; + bool found =3D false; =20 aio_context_acquire(ctx); - found =3D bdrv_all_snapshots_includes_bs(bs) && bdrv_can_snapshot(= bs); + found =3D (devices || bdrv_all_snapshots_includes_bs(bs)) && + bdrv_can_snapshot(bs); aio_context_release(ctx); =20 if (found) { - bdrv_next_cleanup(&it); - break; + return bs; } + + iterbdrvs =3D iterbdrvs->next; } - if (!bs) { - error_setg(errp, "No block device supports snapshots"); - } - return bs; + + error_setg(errp, "No block device supports snapshots"); + return NULL; } diff --git a/include/block/snapshot.h b/include/block/snapshot.h index 5cb2b696ad..2569a903f2 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -25,7 +25,7 @@ #ifndef SNAPSHOT_H #define SNAPSHOT_H =20 - +#include "qapi/qapi-builtin-types.h" =20 #define SNAPSHOT_OPT_BASE "snapshot." #define SNAPSHOT_OPT_ID "snapshot.id" @@ -77,15 +77,25 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverSta= te *bs, * These functions will properly handle dataplane (take aio_context_acquire * when appropriate for appropriate block drivers */ =20 -bool bdrv_all_can_snapshot(Error **errp); -int bdrv_all_delete_snapshot(const char *name, Error **errp); -int bdrv_all_goto_snapshot(const char *name, Error **errp); -int bdrv_all_find_snapshot(const char *name, Error **errp); +bool bdrv_all_can_snapshot(bool has_devices, strList *devices, + Error **errp); +int bdrv_all_delete_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp); +int bdrv_all_goto_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp); +int bdrv_all_find_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp); int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, + bool has_devices, + strList *devices, Error **errp); =20 -BlockDriverState *bdrv_all_find_vmstate_bs(Error **errp); +BlockDriverState *bdrv_all_find_vmstate_bs(bool has_devices, strList *devi= ces, + Error **errp); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index b85eefd682..0dbe8c1607 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2786,18 +2786,18 @@ bool save_snapshot(const char *name, Error **errp) return false; } =20 - if (!bdrv_all_can_snapshot(errp)) { + if (!bdrv_all_can_snapshot(false, NULL, errp)) { return false; } =20 /* Delete old snapshots of the same name */ if (name) { - if (bdrv_all_delete_snapshot(name, errp) < 0) { + if (bdrv_all_delete_snapshot(name, false, NULL, errp) < 0) { return false; } } =20 - bs =3D bdrv_all_find_vmstate_bs(errp); + bs =3D bdrv_all_find_vmstate_bs(false, NULL, errp); if (bs =3D=3D NULL) { return false; } @@ -2862,9 +2862,9 @@ bool save_snapshot(const char *name, Error **errp) aio_context_release(aio_context); aio_context =3D NULL; =20 - ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, errp); + ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, false, NULL, e= rrp); if (ret < 0) { - bdrv_all_delete_snapshot(sn->name, NULL); + bdrv_all_delete_snapshot(sn->name, false, NULL, NULL); goto the_end; } =20 @@ -2974,15 +2974,15 @@ bool load_snapshot(const char *name, Error **errp) AioContext *aio_context; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 - if (!bdrv_all_can_snapshot(errp)) { + if (!bdrv_all_can_snapshot(false, NULL, errp)) { return false; } - ret =3D bdrv_all_find_snapshot(name, errp); + ret =3D bdrv_all_find_snapshot(name, false, NULL, errp); if (ret < 0) { return false; } =20 - bs_vm_state =3D bdrv_all_find_vmstate_bs(errp); + bs_vm_state =3D bdrv_all_find_vmstate_bs(false, NULL, errp); if (!bs_vm_state) { return false; } @@ -3009,7 +3009,7 @@ bool load_snapshot(const char *name, Error **errp) /* Flush all IO requests so they don't interfere with the new state. = */ bdrv_drain_all_begin(); =20 - ret =3D bdrv_all_goto_snapshot(name, errp); + ret =3D bdrv_all_goto_snapshot(name, false, NULL, errp); if (ret < 0) { goto err_drain; } diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 6ff050ac3d..f795261f77 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1158,7 +1158,7 @@ void hmp_delvm(Monitor *mon, const QDict *qdict) Error *err =3D NULL; const char *name =3D qdict_get_str(qdict, "name"); =20 - bdrv_all_delete_snapshot(name, &err); + bdrv_all_delete_snapshot(name, false, NULL, &err); hmp_handle_error(mon, err); } =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 8e0050915d..67d8237077 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -148,7 +148,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, =20 *snapshot_icount =3D -1; =20 - bs =3D bdrv_all_find_vmstate_bs(NULL); + bs =3D bdrv_all_find_vmstate_bs(false, NULL, NULL); if (!bs) { goto fail; } @@ -159,7 +159,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, aio_context_release(aio_context); =20 for (i =3D 0; i < nb_sns; i++) { - if (bdrv_all_find_snapshot(sn_tab[i].name, NULL) =3D=3D 0) { + if (bdrv_all_find_snapshot(sn_tab[i].name, false, NULL, NULL) =3D= =3D 0) { if (sn_tab[i].icount !=3D -1ULL && sn_tab[i].icount <=3D icount && (!nearest || nearest->icount < sn_tab[i].icount)) { --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460383; cv=none; d=zohomail.com; s=zohoarc; b=S7hvhKSqkuigf6+bLR06mutTPm/9bNRjiraEhD98D4rJIGiDcjk8hlhRj+zx7nLdlP+H4h1r/q6mm3lggTyY5jqBEYfpwIRLvUEERMCGi8rXGWpS9y5WqkdlcSm3fXeXwZfANM5l9JNDUXIda1nhTpuulplSVgi675VXYvoQKc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460383; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WNqQ61MxKAwkshpQmFEnQMG/0nilqU1OBrOuTsNAknM=; b=Hpq7pzXTIx+fi9Iyh9GV88hAxKDr/9Gv8VMIEfzazYTAuFrFCXPsWBYAJfxCQmmmX/EN62UmA23LDYBTU3WXzdd4Xvn7YIHJxzo59vL5QzjaPLpy0j3QzrNrBj1uPqNTDzJ/aykUtLxYAeAvf9oIc/J6VGVcJy4VfMJJbpYmHnE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460383902672.5487893258196; Thu, 4 Feb 2021 09:39:43 -0800 (PST) Received: from localhost ([::1]:44056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7ibW-0003Ex-PE for importer@patchew.org; Thu, 04 Feb 2021 12:39:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hiD-00040s-FG for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35941) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hiB-0005uT-GD for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:33 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-lnhhv_N5OR2Pwyvn_HBLnw-1; Thu, 04 Feb 2021 11:42:28 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 96C0D1935780; Thu, 4 Feb 2021 16:42:27 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FEF619708; Thu, 4 Feb 2021 16:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WNqQ61MxKAwkshpQmFEnQMG/0nilqU1OBrOuTsNAknM=; b=hq8idnLoahr+AUsNdJDktn7aIPOHKs1Sbpo+fcr7VY99CSesELXtOh4B1WFFGFglpkQctZ osw+HXFifAcujhl8hRC4/iv0s4Ts1Z1/nTXn7HV/Jic6ungBrln9vuBKJt67PGaMoTMsnx EvWP9LrvKnjeGtiyIVOXIW/4yQc9EYk= X-MC-Unique: lnhhv_N5OR2Pwyvn_HBLnw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 20/27] block: allow specifying name of block device for vmstate storage Date: Thu, 4 Feb 2021 16:39:52 +0000 Message-Id: <20210204163959.377618-21-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 Currently the vmstate will be stored in the first block device that supports snapshots. Historically this would have usually been the root device, but with UEFI it might be the variable store. There needs to be a way to override the choice of block device to store the state in. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-6-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 2 +- block/snapshot.c | 26 +++++++++++++++++++++++--- include/block/snapshot.h | 3 ++- migration/savevm.c | 4 ++-- replay/replay-debugging.c | 2 +- tests/qemu-iotests/267.out | 12 ++++++------ 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index e15121be1f..9cc5d4b51e 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -902,7 +902,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdic= t) SnapshotEntry *snapshot_entry; Error *err =3D NULL; =20 - bs =3D bdrv_all_find_vmstate_bs(false, NULL, &err); + bs =3D bdrv_all_find_vmstate_bs(NULL, false, NULL, &err); if (!bs) { error_report_err(err); return; diff --git a/block/snapshot.c b/block/snapshot.c index 220173deae..0b129bee8f 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -678,7 +678,9 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, return 0; } =20 -BlockDriverState *bdrv_all_find_vmstate_bs(bool has_devices, strList *devi= ces, + +BlockDriverState *bdrv_all_find_vmstate_bs(const char *vmstate_bs, + bool has_devices, strList *devi= ces, Error **errp) { g_autoptr(GList) bdrvs =3D NULL; @@ -699,13 +701,31 @@ BlockDriverState *bdrv_all_find_vmstate_bs(bool has_d= evices, strList *devices, bdrv_can_snapshot(bs); aio_context_release(ctx); =20 - if (found) { + if (vmstate_bs) { + if (g_str_equal(vmstate_bs, + bdrv_get_node_name(bs))) { + if (found) { + return bs; + } else { + error_setg(errp, + "vmstate block device '%s' does not support= snapshots", + vmstate_bs); + return NULL; + } + } + } else if (found) { return bs; } =20 iterbdrvs =3D iterbdrvs->next; } =20 - error_setg(errp, "No block device supports snapshots"); + if (vmstate_bs) { + error_setg(errp, + "vmstate block device '%s' does not exist", vmstate_bs); + } else { + error_setg(errp, + "no block device can store vmstate for snapshot"); + } return NULL; } diff --git a/include/block/snapshot.h b/include/block/snapshot.h index 2569a903f2..8a6a37240d 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -95,7 +95,8 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, strList *devices, Error **errp); =20 -BlockDriverState *bdrv_all_find_vmstate_bs(bool has_devices, strList *devi= ces, +BlockDriverState *bdrv_all_find_vmstate_bs(const char *vmstate_bs, + bool has_devices, strList *devi= ces, Error **errp); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 0dbe8c1607..cdd201e7f8 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2797,7 +2797,7 @@ bool save_snapshot(const char *name, Error **errp) } } =20 - bs =3D bdrv_all_find_vmstate_bs(false, NULL, errp); + bs =3D bdrv_all_find_vmstate_bs(NULL, false, NULL, errp); if (bs =3D=3D NULL) { return false; } @@ -2982,7 +2982,7 @@ bool load_snapshot(const char *name, Error **errp) return false; } =20 - bs_vm_state =3D bdrv_all_find_vmstate_bs(false, NULL, errp); + bs_vm_state =3D bdrv_all_find_vmstate_bs(NULL, false, NULL, errp); if (!bs_vm_state) { return false; } diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 67d8237077..ca37cf4025 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -148,7 +148,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, =20 *snapshot_icount =3D -1; =20 - bs =3D bdrv_all_find_vmstate_bs(false, NULL, NULL); + bs =3D bdrv_all_find_vmstate_bs(NULL, false, NULL, NULL); if (!bs) { goto fail; } diff --git a/tests/qemu-iotests/267.out b/tests/qemu-iotests/267.out index 6149029b25..7176e376e1 100644 --- a/tests/qemu-iotests/267.out +++ b/tests/qemu-iotests/267.out @@ -6,11 +6,11 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D13421= 7728 Testing: QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 -Error: No block device supports snapshots +Error: no block device can store vmstate for snapshot (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 -Error: No block device supports snapshots +Error: no block device can store vmstate for snapshot (qemu) quit =20 =20 @@ -22,7 +22,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 Error: Device 'none0' is writable but does not support snapshots (qemu) quit @@ -58,7 +58,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 Error: Device 'virtio0' is writable but does not support snapshots (qemu) quit @@ -83,7 +83,7 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) savevm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) info snapshots -No block device supports snapshots +no block device can store vmstate for snapshot (qemu) loadvm snap0 Error: Device 'file' is writable but does not support snapshots (qemu) quit --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460582; cv=none; d=zohomail.com; s=zohoarc; b=D96/VkvJZT8pRyVS7EYYHfkERvxUB65E8kTSVjEJn9b46DoC5Nni93BBV1Irwixhrfxm8SenbgDCeqUHzGVTn7/MgRJYgfVLTCWUbt/zVByAPrfTCkIpUp7VejQFCb8F17D43LHma8iUoPrN+nD2U646SCCaRbhXNEZE+7p/iso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460582; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OME4PFsZTHyoOjhxy8orEH4uwZGuPN3Q5Bt20Fh1TFE=; b=Ty9daKQhtIzIh2MRrn5xDkMwYUdiYVVmMxzWtyilqlN7qDQua4QHGTe8UWlyFjV/uk2bhAEKfmKL3Bkdedk0/14KQNh/frq7Y5zDCv7BoCGjCrNOVu00vhrobP0RG7T3PUZvG8fiKzA+IfiydEo6a+sfGj7tFSbC5iOQnXWuJGs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460582343373.56257746730876; Thu, 4 Feb 2021 09:43:02 -0800 (PST) Received: from localhost ([::1]:50440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iej-00066Y-4k for importer@patchew.org; Thu, 04 Feb 2021 12:43:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hiT-00049k-RP for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hiN-0005z0-3A for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:49 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-7u3ObWRWPZWnzsAz1JGwNg-1; Thu, 04 Feb 2021 11:42:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8578D801963; Thu, 4 Feb 2021 16:42:31 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0F331A26A; Thu, 4 Feb 2021 16:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OME4PFsZTHyoOjhxy8orEH4uwZGuPN3Q5Bt20Fh1TFE=; b=EVM8SBk+hsUmxbKw93q7BoypwMmU8g7n5fsTl+tEpFAI6ScdAP9k7xx8BCvJOtDs5jqULG xBAOhplzRrmOMh2Af20DOI2RiYmYPDzCXQW3BGNtNs48mVCo7LCXskkaM7YQdDWX0+Fvo6 3hn4Ut2ceXNXdZqtnmg28cJm1wh9yrw= X-MC-Unique: 7u3ObWRWPZWnzsAz1JGwNg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 21/27] block: rename and alter bdrv_all_find_snapshot semantics Date: Thu, 4 Feb 2021 16:39:53 +0000 Message-Id: <20210204163959.377618-22-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 Currently bdrv_all_find_snapshot() will return 0 if it finds a snapshot, -1 if an error occurs, or if it fails to find a snapshot. New callers to be added want to distinguish between the error scenario and failing to find a snapshot. Rename it to bdrv_all_has_snapshot and make it return -1 on error, 0 if no snapshot is found and 1 if snapshot is found. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-7-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- block/monitor/block-hmp-cmds.c | 2 +- block/snapshot.c | 19 ++++++++++++------- include/block/snapshot.h | 6 +++--- migration/savevm.c | 7 ++++++- replay/replay-debugging.c | 6 +++++- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 9cc5d4b51e..75d7fa9510 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -954,7 +954,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdic= t) total =3D 0; for (i =3D 0; i < nb_sns; i++) { SnapshotEntry *next_sn; - if (bdrv_all_find_snapshot(sn_tab[i].name, false, NULL, NULL) =3D= =3D 0) { + if (bdrv_all_has_snapshot(sn_tab[i].name, false, NULL, NULL) =3D= =3D 1) { global_snapshots[total] =3D i; total++; QTAILQ_FOREACH(image_entry, &image_list, next) { diff --git a/block/snapshot.c b/block/snapshot.c index 0b129bee8f..e8ae9a28c1 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -603,9 +603,9 @@ int bdrv_all_goto_snapshot(const char *name, return 0; } =20 -int bdrv_all_find_snapshot(const char *name, - bool has_devices, strList *devices, - Error **errp) +int bdrv_all_has_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp) { g_autoptr(GList) bdrvs =3D NULL; GList *iterbdrvs; @@ -627,15 +627,20 @@ int bdrv_all_find_snapshot(const char *name, } aio_context_release(ctx); if (ret < 0) { - error_setg(errp, "Could not find snapshot '%s' on '%s'", - name, bdrv_get_device_or_node_name(bs)); - return -1; + if (ret =3D=3D -ENOENT) { + return 0; + } else { + error_setg_errno(errp, errno, + "Could not check snapshot '%s' on '%s'", + name, bdrv_get_device_or_node_name(bs)); + return -1; + } } =20 iterbdrvs =3D iterbdrvs->next; } =20 - return 0; + return 1; } =20 int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, diff --git a/include/block/snapshot.h b/include/block/snapshot.h index 8a6a37240d..940345692f 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -85,9 +85,9 @@ int bdrv_all_delete_snapshot(const char *name, int bdrv_all_goto_snapshot(const char *name, bool has_devices, strList *devices, Error **errp); -int bdrv_all_find_snapshot(const char *name, - bool has_devices, strList *devices, - Error **errp); +int bdrv_all_has_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp); int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BlockDriverState *vm_state_bs, uint64_t vm_state_size, diff --git a/migration/savevm.c b/migration/savevm.c index cdd201e7f8..a2a842d067 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2977,10 +2977,15 @@ bool load_snapshot(const char *name, Error **errp) if (!bdrv_all_can_snapshot(false, NULL, errp)) { return false; } - ret =3D bdrv_all_find_snapshot(name, false, NULL, errp); + ret =3D bdrv_all_has_snapshot(name, false, NULL, errp); if (ret < 0) { return false; } + if (ret =3D=3D 0) { + error_setg(errp, "Snapshot '%s' does not exist in one or more devi= ces", + name); + return false; + } =20 bs_vm_state =3D bdrv_all_find_vmstate_bs(NULL, false, NULL, errp); if (!bs_vm_state) { diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index ca37cf4025..098ef8e0f5 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -143,6 +143,7 @@ static char *replay_find_nearest_snapshot(int64_t icoun= t, QEMUSnapshotInfo *sn_tab; QEMUSnapshotInfo *nearest =3D NULL; char *ret =3D NULL; + int rv; int nb_sns, i; AioContext *aio_context; =20 @@ -159,7 +160,10 @@ static char *replay_find_nearest_snapshot(int64_t icou= nt, aio_context_release(aio_context); =20 for (i =3D 0; i < nb_sns; i++) { - if (bdrv_all_find_snapshot(sn_tab[i].name, false, NULL, NULL) =3D= =3D 0) { + rv =3D bdrv_all_has_snapshot(sn_tab[i].name, false, NULL, NULL); + if (rv < 0) + goto fail; + if (rv =3D=3D 1) { if (sn_tab[i].icount !=3D -1ULL && sn_tab[i].icount <=3D icount && (!nearest || nearest->icount < sn_tab[i].icount)) { --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460186; cv=none; d=zohomail.com; s=zohoarc; b=bbZ6+cva/7aEOkP0/+CwpgpP8znxmIDLyyUEHPwOD6NEIP2b4zM1MLdxwe/9t8mNEirhtiPBNC6tu3C8hOrCAjYnzWam8+cTRydL3UaYNzpUNMuMOZhRUx0T1MDyPvj12e//N3ZfkA9fVGUZ9pRWxzqE1Ei6AC2LWFTYIWYX9gE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460186; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JBf3eWgiLWA6nL1pLM/+sbON6jwD7Wcx8WkvDMmbEqM=; b=RoP/Wjcc5q+JDSOokcYLjo0zKpGC2Pr9DK18EHoU/mBqmxZad6d80SSpF1nHdDEGoFnsBX05FM8ASl4X2kPRf/m7p6YCbLH7Wf/Mf+h6noRVUOx/9pAfgRD89f70KRrdBpqPuC2iIvreOsjaStq4gZnwVmLiO7XTjw2aSZSPA4o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460186300229.93424050684007; Thu, 4 Feb 2021 09:36:26 -0800 (PST) Received: from localhost ([::1]:34752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iYG-0007f9-L7 for importer@patchew.org; Thu, 04 Feb 2021 12:36:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hiL-00046N-KE for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hiI-0005xg-OS for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:41 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-YfDngCv2PtuqJhmRc5iJsg-1; Thu, 04 Feb 2021 11:42:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A343E107ACC7; Thu, 4 Feb 2021 16:42:33 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFA6B1A26A; Thu, 4 Feb 2021 16:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JBf3eWgiLWA6nL1pLM/+sbON6jwD7Wcx8WkvDMmbEqM=; b=ZZK5O5Urp5vEiHUMjnXyZcpKHXotxVSAM2OkwjdxqpZWbqecrPCOAPynWdfvIbMlczY3Kr cWFRvpyhUfml8hNrR/KiWI8YmM9NZnHrCbzbNlRajckFxrbaPgaRFnLy3+eyBX5JHMz9KH heRcs2B24iTQIAWNPzMeTK7fuJdgsCM= X-MC-Unique: YfDngCv2PtuqJhmRc5iJsg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 22/27] migration: control whether snapshots are ovewritten Date: Thu, 4 Feb 2021 16:39:54 +0000 Message-Id: <20210204163959.377618-23-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 The traditional HMP "savevm" command will overwrite an existing snapshot if it already exists with the requested name. This new flag allows this to be controlled allowing for safer behaviour with a future QMP command. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-8-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/snapshot.h | 3 ++- migration/savevm.c | 19 ++++++++++++++++--- monitor/hmp-cmds.c | 2 +- replay/replay-debugging.c | 2 +- replay/replay-snapshot.c | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h index d7d210820c..d8c22d343c 100644 --- a/include/migration/snapshot.h +++ b/include/migration/snapshot.h @@ -18,11 +18,12 @@ /** * save_snapshot: Save an internal snapshot. * @name: name of internal snapshot + * @overwrite: replace existing snapshot with @name * @errp: pointer to error object * On success, return %true. * On failure, store an error through @errp and return %false. */ -bool save_snapshot(const char *name, Error **errp); +bool save_snapshot(const char *name, bool overwrite, Error **errp); =20 /** * load_snapshot: Load an internal snapshot. diff --git a/migration/savevm.c b/migration/savevm.c index a2a842d067..0ae8e4798c 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2764,7 +2764,7 @@ int qemu_load_device_state(QEMUFile *f) return 0; } =20 -bool save_snapshot(const char *name, Error **errp) +bool save_snapshot(const char *name, bool overwrite, Error **errp) { BlockDriverState *bs; QEMUSnapshotInfo sn1, *sn =3D &sn1; @@ -2792,8 +2792,21 @@ bool save_snapshot(const char *name, Error **errp) =20 /* Delete old snapshots of the same name */ if (name) { - if (bdrv_all_delete_snapshot(name, false, NULL, errp) < 0) { - return false; + if (overwrite) { + if (bdrv_all_delete_snapshot(name, false, NULL, errp) < 0) { + return false; + } + } else { + ret2 =3D bdrv_all_has_snapshot(name, false, NULL, errp); + if (ret2 < 0) { + return false; + } + if (ret2 =3D=3D 1) { + error_setg(errp, + "Snapshot '%s' already exists in one or more de= vices", + name); + return false; + } } } =20 diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index f795261f77..1fff33f14a 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1149,7 +1149,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; =20 - save_snapshot(qdict_get_try_str(qdict, "name"), &err); + save_snapshot(qdict_get_try_str(qdict, "name"), true, &err); hmp_handle_error(mon, err); } =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 098ef8e0f5..0ae6785b3b 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -327,7 +327,7 @@ void replay_gdb_attached(void) */ if (replay_mode =3D=3D REPLAY_MODE_PLAY && !replay_snapshot) { - if (!save_snapshot("start_debugging", NULL)) { + if (!save_snapshot("start_debugging", true, NULL)) { /* Can't create the snapshot. Continue conventional debugging.= */ } } diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index b289365937..31c5a8702b 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -77,7 +77,7 @@ void replay_vmstate_init(void) =20 if (replay_snapshot) { if (replay_mode =3D=3D REPLAY_MODE_RECORD) { - if (!save_snapshot(replay_snapshot, &err)) { + if (!save_snapshot(replay_snapshot, true, &err)) { error_report_err(err); error_report("Could not create snapshot for icount record"= ); exit(1); --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612459119; cv=none; d=zohomail.com; s=zohoarc; b=K9r5StEnBlUSbUvwp007XQwZpewTwrkY4DdC5DsWy27YJqkUdYW8ANetw7LEyIYZds2lvYE2BnfKp7K4/iYOUMZc+NPu5Hx8MSZXKkCAmhbgp7bqGhZNNAnAwGZM9G35dS+s/hObwqa5XWe4IyZX0HItaJJIn7wUX2TbXPfwphE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612459119; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f85xKQSJGt5c9GZGiWdx3e3lNThhCA7kdQQjDhJ/1Bg=; b=Rmkc27Jgfe8AY9WqV+JIaYVu9GRPQ4vHeBn3wmanwT9Q7DGtQ/bGYsH298w3uEgR8tn+/OelU1gafoQWM5obO3tuum+uBog8ScDip87CEiyX8qqO47W2SG65LBLxzORdUt+49VxC36wd42QW/ReN54nlKfBG4fyXDGvazRUTCfE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612459119472664.2917945655151; Thu, 4 Feb 2021 09:18:39 -0800 (PST) Received: from localhost ([::1]:48934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iH6-0005Vc-8u for importer@patchew.org; Thu, 04 Feb 2021 12:18:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hiT-00048r-44 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hiL-0005yx-A3 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-8CLFm5Q0NFiUI_nJ9dSR2A-1; Thu, 04 Feb 2021 11:42:38 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A5CE81EE61; Thu, 4 Feb 2021 16:42:37 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEB5F1A4D0; Thu, 4 Feb 2021 16:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f85xKQSJGt5c9GZGiWdx3e3lNThhCA7kdQQjDhJ/1Bg=; b=bt5RidToy395kTvA9UmA26On1oFjQrMQhtXk74JWFVVcEeUA8D4M6HVWGX2Dks+CLjBtKB sBGv5Z1DCySxMDziBbhZXwgPjGmAwDbwMfZJbfrhhNKfXqq58nV0n5vlLBlnfdIslwamso iDSYgk9/iVcA7kDjRmpwH5tECqYChpo= X-MC-Unique: 8CLFm5Q0NFiUI_nJ9dSR2A-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 23/27] migration: wire up support for snapshot device selection Date: Thu, 4 Feb 2021 16:39:55 +0000 Message-Id: <20210204163959.377618-24-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 Modify load_snapshot/save_snapshot to accept the device list and vmstate node name parameters previously added to the block layer. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-9-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/snapshot.h | 18 ++++++++++++++++-- migration/savevm.c | 30 ++++++++++++++++++------------ monitor/hmp-cmds.c | 5 +++-- replay/replay-debugging.c | 4 ++-- replay/replay-snapshot.c | 5 +++-- softmmu/vl.c | 2 +- 6 files changed, 43 insertions(+), 21 deletions(-) diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h index d8c22d343c..3bdbef435b 100644 --- a/include/migration/snapshot.h +++ b/include/migration/snapshot.h @@ -15,23 +15,37 @@ #ifndef QEMU_MIGRATION_SNAPSHOT_H #define QEMU_MIGRATION_SNAPSHOT_H =20 +#include "qapi/qapi-builtin-types.h" + /** * save_snapshot: Save an internal snapshot. * @name: name of internal snapshot * @overwrite: replace existing snapshot with @name + * @vmstate: blockdev node name to store VM state in + * @has_devices: whether to use explicit device list + * @devices: explicit device list to snapshot * @errp: pointer to error object * On success, return %true. * On failure, store an error through @errp and return %false. */ -bool save_snapshot(const char *name, bool overwrite, Error **errp); +bool save_snapshot(const char *name, bool overwrite, + const char *vmstate, + bool has_devices, strList *devices, + Error **errp); =20 /** * load_snapshot: Load an internal snapshot. * @name: name of internal snapshot + * @vmstate: blockdev node name to load VM state from + * @has_devices: whether to use explicit device list + * @devices: explicit device list to snapshot * @errp: pointer to error object * On success, return %true. * On failure, store an error through @errp and return %false. */ -bool load_snapshot(const char *name, Error **errp); +bool load_snapshot(const char *name, + const char *vmstate, + bool has_devices, strList *devices, + Error **errp); =20 #endif diff --git a/migration/savevm.c b/migration/savevm.c index 0ae8e4798c..0b27a8c55a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -43,6 +43,8 @@ #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qmp/json-writer.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-builtin-visit.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" #include "sysemu/cpus.h" @@ -2764,7 +2766,8 @@ int qemu_load_device_state(QEMUFile *f) return 0; } =20 -bool save_snapshot(const char *name, bool overwrite, Error **errp) +bool save_snapshot(const char *name, bool overwrite, const char *vmstate, + bool has_devices, strList *devices, Error **errp) { BlockDriverState *bs; QEMUSnapshotInfo sn1, *sn =3D &sn1; @@ -2786,18 +2789,19 @@ bool save_snapshot(const char *name, bool overwrite= , Error **errp) return false; } =20 - if (!bdrv_all_can_snapshot(false, NULL, errp)) { + if (!bdrv_all_can_snapshot(has_devices, devices, errp)) { return false; } =20 /* Delete old snapshots of the same name */ if (name) { if (overwrite) { - if (bdrv_all_delete_snapshot(name, false, NULL, errp) < 0) { + if (bdrv_all_delete_snapshot(name, has_devices, + devices, errp) < 0) { return false; } } else { - ret2 =3D bdrv_all_has_snapshot(name, false, NULL, errp); + ret2 =3D bdrv_all_has_snapshot(name, has_devices, devices, err= p); if (ret2 < 0) { return false; } @@ -2810,7 +2814,7 @@ bool save_snapshot(const char *name, bool overwrite, = Error **errp) } } =20 - bs =3D bdrv_all_find_vmstate_bs(NULL, false, NULL, errp); + bs =3D bdrv_all_find_vmstate_bs(vmstate, has_devices, devices, errp); if (bs =3D=3D NULL) { return false; } @@ -2875,9 +2879,10 @@ bool save_snapshot(const char *name, bool overwrite,= Error **errp) aio_context_release(aio_context); aio_context =3D NULL; =20 - ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, false, NULL, e= rrp); + ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, + has_devices, devices, errp); if (ret < 0) { - bdrv_all_delete_snapshot(sn->name, false, NULL, NULL); + bdrv_all_delete_snapshot(sn->name, has_devices, devices, NULL); goto the_end; } =20 @@ -2978,7 +2983,8 @@ void qmp_xen_load_devices_state(const char *filename,= Error **errp) migration_incoming_state_destroy(); } =20 -bool load_snapshot(const char *name, Error **errp) +bool load_snapshot(const char *name, const char *vmstate, + bool has_devices, strList *devices, Error **errp) { BlockDriverState *bs_vm_state; QEMUSnapshotInfo sn; @@ -2987,10 +2993,10 @@ bool load_snapshot(const char *name, Error **errp) AioContext *aio_context; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 - if (!bdrv_all_can_snapshot(false, NULL, errp)) { + if (!bdrv_all_can_snapshot(has_devices, devices, errp)) { return false; } - ret =3D bdrv_all_has_snapshot(name, false, NULL, errp); + ret =3D bdrv_all_has_snapshot(name, has_devices, devices, errp); if (ret < 0) { return false; } @@ -3000,7 +3006,7 @@ bool load_snapshot(const char *name, Error **errp) return false; } =20 - bs_vm_state =3D bdrv_all_find_vmstate_bs(NULL, false, NULL, errp); + bs_vm_state =3D bdrv_all_find_vmstate_bs(vmstate, has_devices, devices= , errp); if (!bs_vm_state) { return false; } @@ -3027,7 +3033,7 @@ bool load_snapshot(const char *name, Error **errp) /* Flush all IO requests so they don't interfere with the new state. = */ bdrv_drain_all_begin(); =20 - ret =3D bdrv_all_goto_snapshot(name, false, NULL, errp); + ret =3D bdrv_all_goto_snapshot(name, has_devices, devices, errp); if (ret < 0) { goto err_drain; } diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 1fff33f14a..15d4e039ac 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1139,7 +1139,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict) =20 vm_stop(RUN_STATE_RESTORE_VM); =20 - if (!load_snapshot(name, &err) && saved_vm_running) { + if (!load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running)= { vm_start(); } hmp_handle_error(mon, err); @@ -1149,7 +1149,8 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; =20 - save_snapshot(qdict_get_try_str(qdict, "name"), true, &err); + save_snapshot(qdict_get_try_str(qdict, "name"), + true, NULL, false, NULL, &err); hmp_handle_error(mon, err); } =20 diff --git a/replay/replay-debugging.c b/replay/replay-debugging.c index 0ae6785b3b..1cde50e9f3 100644 --- a/replay/replay-debugging.c +++ b/replay/replay-debugging.c @@ -196,7 +196,7 @@ static void replay_seek(int64_t icount, QEMUTimerCB cal= lback, Error **errp) if (icount < replay_get_current_icount() || replay_get_current_icount() < snapshot_icount) { vm_stop(RUN_STATE_RESTORE_VM); - load_snapshot(snapshot, errp); + load_snapshot(snapshot, NULL, false, NULL, errp); } g_free(snapshot); } @@ -327,7 +327,7 @@ void replay_gdb_attached(void) */ if (replay_mode =3D=3D REPLAY_MODE_PLAY && !replay_snapshot) { - if (!save_snapshot("start_debugging", true, NULL)) { + if (!save_snapshot("start_debugging", true, NULL, false, NULL, NUL= L)) { /* Can't create the snapshot. Continue conventional debugging.= */ } } diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c index 31c5a8702b..e8767a1937 100644 --- a/replay/replay-snapshot.c +++ b/replay/replay-snapshot.c @@ -77,13 +77,14 @@ void replay_vmstate_init(void) =20 if (replay_snapshot) { if (replay_mode =3D=3D REPLAY_MODE_RECORD) { - if (!save_snapshot(replay_snapshot, true, &err)) { + if (!save_snapshot(replay_snapshot, + true, NULL, false, NULL, &err)) { error_report_err(err); error_report("Could not create snapshot for icount record"= ); exit(1); } } else if (replay_mode =3D=3D REPLAY_MODE_PLAY) { - if (!load_snapshot(replay_snapshot, &err)) { + if (!load_snapshot(replay_snapshot, NULL, false, NULL, &err)) { error_report_err(err); error_report("Could not load snapshot for icount replay"); exit(1); diff --git a/softmmu/vl.c b/softmmu/vl.c index 8f655086b7..32b353752a 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2529,7 +2529,7 @@ void qmp_x_exit_preconfig(Error **errp) =20 if (loadvm) { Error *local_err =3D NULL; - if (!load_snapshot(loadvm, &local_err)) { + if (!load_snapshot(loadvm, NULL, false, NULL, &local_err)) { error_report_err(local_err); autostart =3D 0; exit(1); --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460671; cv=none; d=zohomail.com; s=zohoarc; b=e7YRu5pweikak0zbIx6YpIqaZIOhhkMmKqA72b7p30cqowt7D1G4LcnMoCJvoXdU5G8DwAbZ6rcXOr8k9gwK2HOJgFV0paBZlHMOX7FxuGo7587subBr7cRBabzK8NC2nsQBYtTDFxwv4hnuUh4tXr3RpgCfaVQf/UmcKJ4YGUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460671; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=S7EjN/BVvI2LI8U3n5kPOXaqjdiqQ9k1KV92LfmtmpM=; b=nUf5tdQLsOuBGav1hnupTf5IwOHVjg3wrBwp7XPVwbZvF1A89XVm4ZznKZKtQ03aBxH43TvcTXVIufnk3NvEC4WU0yxdqIrem86ldye1SBXTrP4j875R9xY44UnzSNOn/K/X5Y/VCIqsDgHLY/MCwkpJwOzsPkq09LD700GIb/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460671118670.294889296488; Thu, 4 Feb 2021 09:44:31 -0800 (PST) Received: from localhost ([::1]:52704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7igA-0007DL-04 for importer@patchew.org; Thu, 04 Feb 2021 12:44:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hiV-0004A6-O9 for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hiS-00060l-QV for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:51 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-382-4E6Un_OSOo6Cza21MguC8w-1; Thu, 04 Feb 2021 11:42:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B45080196F; Thu, 4 Feb 2021 16:42:42 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D66517A9A; Thu, 4 Feb 2021 16:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S7EjN/BVvI2LI8U3n5kPOXaqjdiqQ9k1KV92LfmtmpM=; b=dxaUkeUAVMVkIyJ1a+HR8cK7eBY681l5S9gdskem1/glMqJUxC3+JEXQ1hZlbkGViNJKpT s6+5pTdF5x2FmQ9fIsVRugdmUpn8EgvE15v684Pp4c8A9BcTsBMJ5GUT+gQlDz/lBX1ZBu eubSNzzBSz02f52eSCalUJ/R7tfecEg= X-MC-Unique: 4E6Un_OSOo6Cza21MguC8w-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 24/27] migration: introduce a delete_snapshot wrapper Date: Thu, 4 Feb 2021 16:39:56 +0000 Message-Id: <20210204163959.377618-25-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 Make snapshot deletion consistent with the snapshot save and load commands by using a wrapper around the blockdev layer. The main difference is that we get upfront validation of the passed in device list (if any). Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-10-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/snapshot.h | 13 +++++++++++++ migration/savevm.c | 14 ++++++++++++++ monitor/hmp-cmds.c | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/migration/snapshot.h b/include/migration/snapshot.h index 3bdbef435b..e72083b117 100644 --- a/include/migration/snapshot.h +++ b/include/migration/snapshot.h @@ -48,4 +48,17 @@ bool load_snapshot(const char *name, bool has_devices, strList *devices, Error **errp); =20 +/** + * delete_snapshot: Delete a snapshot. + * @name: path to snapshot + * @has_devices: whether to use explicit device list + * @devices: explicit device list to snapshot + * @errp: pointer to error object + * On success, return %true. + * On failure, store an error through @errp and return %false. + */ +bool delete_snapshot(const char *name, + bool has_devices, strList *devices, + Error **errp); + #endif diff --git a/migration/savevm.c b/migration/savevm.c index 0b27a8c55a..0c5d61ae20 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3071,6 +3071,20 @@ err_drain: return false; } =20 +bool delete_snapshot(const char *name, bool has_devices, + strList *devices, Error **errp) +{ + if (!bdrv_all_can_snapshot(has_devices, devices, errp)) { + return false; + } + + if (bdrv_all_delete_snapshot(name, has_devices, devices, errp) < 0) { + return false; + } + + return true; +} + void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) { qemu_ram_set_idstr(mr->ram_block, diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 15d4e039ac..3c88a4faef 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1159,7 +1159,7 @@ void hmp_delvm(Monitor *mon, const QDict *qdict) Error *err =3D NULL; const char *name =3D qdict_get_str(qdict, "name"); =20 - bdrv_all_delete_snapshot(name, false, NULL, &err); + delete_snapshot(name, false, NULL, &err); hmp_handle_error(mon, err); } =20 --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460378; cv=none; d=zohomail.com; s=zohoarc; b=YdBB6XndtTQ00ZurqG3issUCHLTs9lIVCv8w2uYKwqDb8qzHYPfrI+2YOAf0e5fYhgn9Qu0GzzEWbqOAEVLnPX1j9LnxV2NgPHrfDIp6N+gn98yYmuGjtSUczp+srZuNiJgyiVfcQknygCtr/afQ4ByTNla4vQN2jUol2nytvYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460378; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HXZkIG1FG7xNYVW+bw6BuJvqBE8IR/R+/E0I+C8PJlQ=; b=HiHU4hzLTpo1DrEeFA6Czw7+L5xZN78sCqRadozyADXPaTfM7u4dZc+mXSTnIV5u3O2vYF99otruaJSoGZnWIYbTBIk0+QgpdWYHKlq1f+i8chRrzO9VWgd1kqV4RyBB4YeexF/CgTgnz97vluTaGdc7/ZF1SbYi5TBkVYLC7fk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460378986306.10234024737736; Thu, 4 Feb 2021 09:39:38 -0800 (PST) Received: from localhost ([::1]:43642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7ibR-00034d-8P for importer@patchew.org; Thu, 04 Feb 2021 12:39:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hiZ-0004BE-LI for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hiV-00061p-FU for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:55 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-233-CQIx67pxMsC_7t24KASEpg-1; Thu, 04 Feb 2021 11:42:48 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58F3AC7402; Thu, 4 Feb 2021 16:42:47 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 961461A38C; Thu, 4 Feb 2021 16:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HXZkIG1FG7xNYVW+bw6BuJvqBE8IR/R+/E0I+C8PJlQ=; b=hcSbDiK7shcQZGIR77QFagqvvN3G5gZxXH3C3Me3ZsYt3y2HO2MyeF1cCIb+9YF4QHGhhm 1WoZ+H+WA93CEFrIPC0zsLJmrDhLm3468yIq9BNM5FQQheSO0NMvkjiOsbb9g9/8MVXcZc /YnPHr8LYl9FZcqWz0FhTWHn4cgDCGk= X-MC-Unique: CQIx67pxMsC_7t24KASEpg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 25/27] iotests: add support for capturing and matching QMP events Date: Thu, 4 Feb 2021 16:39:57 +0000 Message-Id: <20210204163959.377618-26-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 When using the _launch_qemu and _send_qemu_cmd functions from common.qemu, any QMP events get mixed in with the output from the commands and responses. This makes it difficult to write a test case as the ordering of events in the output is not stable. This introduces a variable 'capture_events' which can be set to a list of event names. Any events listed in this variable will not be printed, instead collected in the $QEMU_EVENTS environment variable. A new '_wait_event' function can be invoked to collect events at a fixed point in time. The function will first pull events cached in $QEMU_EVENTS variable, and if none are found, will then read more from QMP. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-11-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tests/qemu-iotests/common.qemu | 106 ++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu index ef105dfc39..0fc52d20d7 100644 --- a/tests/qemu-iotests/common.qemu +++ b/tests/qemu-iotests/common.qemu @@ -53,6 +53,15 @@ _in_fd=3D4 # If $mismatch_only is set, only non-matching responses will # be echoed. # +# If $capture_events is non-empty, then any QMP event names it lists +# will not be echoed out, but instead collected in the $QEMU_EVENTS +# variable. The _wait_event function can later be used to receive +# the cached events. +# +# If $only_capture_events is set to anything but an empty string, +# then an error will be raised if a QMP message is seen which is +# not an event listed in $capture_events. +# # If $success_or_failure is set, the meaning of the arguments is # changed as follows: # $2: A string to search for in the response; if found, this indicates @@ -78,6 +87,31 @@ _timed_wait_for() QEMU_STATUS[$h]=3D0 while IFS=3D read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]} do + if [ -n "$capture_events" ]; then + capture=3D0 + local evname + for evname in $capture_events + do + case ${resp} in + *\"event\":\ \"${evname}\"* ) capture=3D1 ;; + esac + done + if [ $capture =3D 1 ]; + then + ev=3D$(echo "${resp}" | tr -d '\r' | tr % .) + QEMU_EVENTS=3D"${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}" + if [ -n "$only_capture_events" ]; then + return + else + continue + fi + fi + fi + if [ -n "$only_capture_events" ]; then + echo "Only expected $capture_events but got ${resp}" + exit 1 + fi + if [ -z "${silent}" ] && [ -z "${mismatch_only}" ]; then echo "${resp}" | _filter_testdir | _filter_qemu \ | _filter_qemu_io | _filter_qmp | _filter_hmp @@ -172,12 +206,82 @@ _send_qemu_cmd() let count--; done if [ ${QEMU_STATUS[$h]} -ne 0 ] && [ -z "${qemu_error_no_exit}" ]; then - echo "Timeout waiting for ${1} on handle ${h}" + echo "Timeout waiting for command ${1} response on handle ${h}" exit 1 #Timeout means the test failed fi } =20 =20 +# Check event cache for a named QMP event +# +# Input parameters: +# $1: Name of the QMP event to check for +# +# Checks if the named QMP event that was previously captured +# into $QEMU_EVENTS. When matched, the QMP event will be echoed +# and the $matched variable set to 1. +# +# _wait_event is more suitable for test usage in most cases +_check_cached_events() +{ + local evname=3D${1} + + local match=3D"\"event\": \"$evname\"" + + matched=3D0 + if [ -n "$QEMU_EVENTS" ]; then + CURRENT_QEMU_EVENTS=3D$QEMU_EVENTS + QEMU_EVENTS=3D + old_IFS=3D$IFS + IFS=3D"%" + for ev in $CURRENT_QEMU_EVENTS + do + grep -q "$match" < <(echo "${ev}") + if [ $? -eq 0 ] && [ $matched =3D 0 ]; then + echo "${ev}" | _filter_testdir | _filter_qemu \ + | _filter_qemu_io | _filter_qmp | _filter_hmp + matched=3D1 + else + QEMU_EVENTS=3D"${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}" + fi + done + IFS=3D$old_IFS + fi +} + +# Wait for a named QMP event +# +# Input parameters: +# $1: QEMU handle to use +# $2: Name of the QMP event to wait for +# +# Checks if the named QMP even was previously captured +# into $QEMU_EVENTS. If none are present, then waits for the +# event to arrive on the QMP channel. When matched, the QMP +# event will be echoed +_wait_event() +{ + local h=3D${1} + local evname=3D${2} + + while true + do + _check_cached_events $evname + + if [ $matched =3D 1 ]; + then + return + fi + + only_capture_events=3D1 qemu_error_no_exit=3D1 _timed_wait_for ${h} + + if [ ${QEMU_STATUS[$h]} -ne 0 ] ; then + echo "Timeout waiting for event ${evname} on handle ${h}" + exit 1 #Timeout means the test failed + fi + done +} + # Launch a QEMU process. # # Input parameters: --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460808; cv=none; d=zohomail.com; s=zohoarc; b=NqylWK+BLb55ScGX8ICEzmIntHbtZI02SW4L3rwcc48dXv9hpcdLQ0OP7qlF9xXmA9FceDaZ3xaYehQKdfZlYEEd4VfVqyA3x/pNBezmnlMJx3FXw8bt//yRDpCy+NttKW8iN64H1bY3gFp4eZiaIUbWo4s5N632gcXHV9umk5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460808; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=33j6FfCcNYV1dyqcF5bmQgZ57R1Tc7rnfkK/2IYugOQ=; b=kYSxhM7wUKSzirVmmTJwY4+hKms2AoVr77CoCw18sG4+0jgVzGPe3NBWr2l1uV2B88HRcldSCY2MtN4/o98Fl2xjFWVCzMjrA50cVI/wZpkA4rpgVaayGQDTAr5bCgrERsEqUV/+qqv5L+7hy2xCvePTVrTzTypQFb7KBbbvPC4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460808470932.4599397112104; Thu, 4 Feb 2021 09:46:48 -0800 (PST) Received: from localhost ([::1]:58960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7iiN-0001kw-Cw for importer@patchew.org; Thu, 04 Feb 2021 12:46:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hib-0004Bd-HM for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hiX-00062A-CD for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:42:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-B-cv0IpRO1qiz3yGdfnMpw-1; Thu, 04 Feb 2021 11:42:50 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76098C7400; Thu, 4 Feb 2021 16:42:49 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3CAC19708; Thu, 4 Feb 2021 16:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=33j6FfCcNYV1dyqcF5bmQgZ57R1Tc7rnfkK/2IYugOQ=; b=YP2F0jerWca+8wpi233soli0m8ergDsLttGa0+W9cMQfwGGHUSVosPd0gLR/zc3GVhsUqs gXp3hVDri7ppMaKwDubBcd/7+WqeuzOolnDZPLQ9tiFR/gQgwZlZ1wx5sVtxTvYNB/EnoN rXkOJdC1A/e4CS96yzLm7qk325pHI2w= X-MC-Unique: B-cv0IpRO1qiz3yGdfnMpw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 26/27] iotests: fix loading of common.config from tests/ subdir Date: Thu, 4 Feb 2021 16:39:58 +0000 Message-Id: <20210204163959.377618-27-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 common.rc assumes it is being sourced from the same directory and so also tries to source common.config from the current working directory. With the ability to now have named tests in the tests/ subdir we need to check two locations for common.config. Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-12-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tests/qemu-iotests/common.rc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 297acf9b6a..77c37e8312 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -109,8 +109,14 @@ peek_file_raw() dd if=3D"$1" bs=3D1 skip=3D"$2" count=3D"$3" status=3Dnone } =20 - -if ! . ./common.config +config=3Dcommon.config +test -f $config || config=3D../common.config +if ! test -f $config +then + echo "$0: failed to find common.config" + exit 1 +fi +if ! . $config then echo "$0: failed to source common.config" exit 1 --=20 2.29.2 From nobody Sat May 18 18:27:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612460870; cv=none; d=zohomail.com; s=zohoarc; b=UW8PRpb2qu1xYe87ZzKicWVeriTm+b9wBeIEUJUpto2OYI4FF1FuaQqtiMHFhKh0jCEehPOge9l6++qLubL0UXDw0nyS1XwqwtgjFr2rAarxkcA33IbGun42RdIaT/4RnXWGX4wNkWJkasapm+sHN1qsX/yjZK27ZJlA1JGAH94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612460870; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LKnF4pRrKwqKPZxcNddLx6h5pLWcgzICdlkmoGEpkSY=; b=hd01K7RA7lW/LqTd8F5G5w1+8cEpYOF108hdCLWUBGAzhXt4BZBYnez1wDj+xjsq5/0STSDdTyao4WGsdz66ali/IKaOZilIk+hiSmxTjsCV1+v3KytkblD5MgPvcGe3ZZTWgeRPM1p6vpSz/c32kWUYzK1l4+74ltJqljqZqUs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612460870515283.03061312366594; Thu, 4 Feb 2021 09:47:50 -0800 (PST) Received: from localhost ([::1]:32994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7ijN-00035C-Eo for importer@patchew.org; Thu, 04 Feb 2021 12:47:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hih-0004E8-EZ for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25963) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7hif-00064G-2w for qemu-devel@nongnu.org; Thu, 04 Feb 2021 11:43:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-367-Ku1skO6qOCOvgik6BSMPJg-1; Thu, 04 Feb 2021 11:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E380512D; Thu, 4 Feb 2021 16:42:53 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1CAB1A38C; Thu, 4 Feb 2021 16:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612456979; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LKnF4pRrKwqKPZxcNddLx6h5pLWcgzICdlkmoGEpkSY=; b=fg3u3MWIRHu6H54bWAAG/cAmvc/ZLNvCFKLYWFTid5rNfk+dNSDAfo61ftTtbHEdeMMzvF RRrOZB+xkQ4wOJYyDk6JtLM5Bmw/4+v9IDwAGu4pwXArz/tQ2WczdO7GHmmEAE2iBO2S6W GxkotQAo8zJ57Ubqtj13Us5gQxo5YLI= X-MC-Unique: Ku1skO6qOCOvgik6BSMPJg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, andrey.gruzdev@virtuozzo.com, berrange@redhat.com, gaojinhao@huawei.com, armbru@redhat.com, mst@redhat.com, philmd@redhat.com, wainersm@redhat.com Subject: [PULL 27/27] migration: introduce snapshot-{save, load, delete} QMP commands Date: Thu, 4 Feb 2021 16:39:59 +0000 Message-Id: <20210204163959.377618-28-dgilbert@redhat.com> In-Reply-To: <20210204163959.377618-1-dgilbert@redhat.com> References: <20210204163959.377618-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Daniel P. Berrang=C3=A9 savevm, loadvm and delvm are some of the few HMP commands that have never been converted to use QMP. The reasons for the lack of conversion are that they blocked execution of the event thread, and the semantics around choice of disks were ill-defined. Despite this downside, however, libvirt and applications using libvirt have used these commands for as long as QMP has existed, via the "human-monitor-command" passthrough command. IOW, while it is clearly desirable to be able to fix the problems, they are not a blocker to all real world usage. Meanwhile there is a need for other features which involve adding new parameters to the commands. This is possible with HMP passthrough, but it provides no reliable way for apps to introspect features, so using QAPI modelling is highly desirable. This patch thus introduces new snapshot-{load,save,delete} commands to QMP that are intended to replace the old HMP counterparts. The new commands are given different names, because they will be using the new QEMU job framework and thus will have diverging behaviour from the HMP originals. It would thus be misleading to keep the same name. While this design uses the generic job framework, the current impl is still blocking. The intention that the blocking problem is fixed later. None the less applications using these new commands should assume that they are asynchronous and thus wait for the job status change event to indicate completion. In addition to using the job framework, the new commands require the caller to be explicit about all the block device nodes used in the snapshot operations, with no built-in default heuristics in use. Note that the existing "query-named-block-nodes" can be used to query what snapshots currently exist for block nodes. Acked-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210204124834.774401-13-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert dgilbert: removed tests for now, the output ordering isn't deterministic --- migration/savevm.c | 184 ++++++++++++++++++++++++++++++++++++++++++++ qapi/job.json | 9 ++- qapi/migration.json | 173 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 365 insertions(+), 1 deletion(-) diff --git a/migration/savevm.c b/migration/savevm.c index 0c5d61ae20..52e2d72e4b 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -3112,3 +3112,187 @@ bool vmstate_check_only_migratable(const VMStateDes= cription *vmsd) =20 return !(vmsd && vmsd->unmigratable); } + +typedef struct SnapshotJob { + Job common; + char *tag; + char *vmstate; + strList *devices; + Coroutine *co; + Error **errp; + bool ret; +} SnapshotJob; + +static void qmp_snapshot_job_free(SnapshotJob *s) +{ + g_free(s->tag); + g_free(s->vmstate); + qapi_free_strList(s->devices); +} + + +static void snapshot_load_job_bh(void *opaque) +{ + Job *job =3D opaque; + SnapshotJob *s =3D container_of(job, SnapshotJob, common); + int orig_vm_running; + + job_progress_set_remaining(&s->common, 1); + + orig_vm_running =3D runstate_is_running(); + vm_stop(RUN_STATE_RESTORE_VM); + + s->ret =3D load_snapshot(s->tag, s->vmstate, true, s->devices, s->errp= ); + if (s->ret && orig_vm_running) { + vm_start(); + } + + job_progress_update(&s->common, 1); + + qmp_snapshot_job_free(s); + aio_co_wake(s->co); +} + +static void snapshot_save_job_bh(void *opaque) +{ + Job *job =3D opaque; + SnapshotJob *s =3D container_of(job, SnapshotJob, common); + + job_progress_set_remaining(&s->common, 1); + s->ret =3D save_snapshot(s->tag, false, s->vmstate, + true, s->devices, s->errp); + job_progress_update(&s->common, 1); + + qmp_snapshot_job_free(s); + aio_co_wake(s->co); +} + +static void snapshot_delete_job_bh(void *opaque) +{ + Job *job =3D opaque; + SnapshotJob *s =3D container_of(job, SnapshotJob, common); + + job_progress_set_remaining(&s->common, 1); + s->ret =3D delete_snapshot(s->tag, true, s->devices, s->errp); + job_progress_update(&s->common, 1); + + qmp_snapshot_job_free(s); + aio_co_wake(s->co); +} + +static int coroutine_fn snapshot_save_job_run(Job *job, Error **errp) +{ + SnapshotJob *s =3D container_of(job, SnapshotJob, common); + s->errp =3D errp; + s->co =3D qemu_coroutine_self(); + aio_bh_schedule_oneshot(qemu_get_aio_context(), + snapshot_save_job_bh, job); + qemu_coroutine_yield(); + return s->ret ? 0 : -1; +} + +static int coroutine_fn snapshot_load_job_run(Job *job, Error **errp) +{ + SnapshotJob *s =3D container_of(job, SnapshotJob, common); + s->errp =3D errp; + s->co =3D qemu_coroutine_self(); + aio_bh_schedule_oneshot(qemu_get_aio_context(), + snapshot_load_job_bh, job); + qemu_coroutine_yield(); + return s->ret ? 0 : -1; +} + +static int coroutine_fn snapshot_delete_job_run(Job *job, Error **errp) +{ + SnapshotJob *s =3D container_of(job, SnapshotJob, common); + s->errp =3D errp; + s->co =3D qemu_coroutine_self(); + aio_bh_schedule_oneshot(qemu_get_aio_context(), + snapshot_delete_job_bh, job); + qemu_coroutine_yield(); + return s->ret ? 0 : -1; +} + + +static const JobDriver snapshot_load_job_driver =3D { + .instance_size =3D sizeof(SnapshotJob), + .job_type =3D JOB_TYPE_SNAPSHOT_LOAD, + .run =3D snapshot_load_job_run, +}; + +static const JobDriver snapshot_save_job_driver =3D { + .instance_size =3D sizeof(SnapshotJob), + .job_type =3D JOB_TYPE_SNAPSHOT_SAVE, + .run =3D snapshot_save_job_run, +}; + +static const JobDriver snapshot_delete_job_driver =3D { + .instance_size =3D sizeof(SnapshotJob), + .job_type =3D JOB_TYPE_SNAPSHOT_DELETE, + .run =3D snapshot_delete_job_run, +}; + + +void qmp_snapshot_save(const char *job_id, + const char *tag, + const char *vmstate, + strList *devices, + Error **errp) +{ + SnapshotJob *s; + + s =3D job_create(job_id, &snapshot_save_job_driver, NULL, + qemu_get_aio_context(), JOB_MANUAL_DISMISS, + NULL, NULL, errp); + if (!s) { + return; + } + + s->tag =3D g_strdup(tag); + s->vmstate =3D g_strdup(vmstate); + s->devices =3D QAPI_CLONE(strList, devices); + + job_start(&s->common); +} + +void qmp_snapshot_load(const char *job_id, + const char *tag, + const char *vmstate, + strList *devices, + Error **errp) +{ + SnapshotJob *s; + + s =3D job_create(job_id, &snapshot_load_job_driver, NULL, + qemu_get_aio_context(), JOB_MANUAL_DISMISS, + NULL, NULL, errp); + if (!s) { + return; + } + + s->tag =3D g_strdup(tag); + s->vmstate =3D g_strdup(vmstate); + s->devices =3D QAPI_CLONE(strList, devices); + + job_start(&s->common); +} + +void qmp_snapshot_delete(const char *job_id, + const char *tag, + strList *devices, + Error **errp) +{ + SnapshotJob *s; + + s =3D job_create(job_id, &snapshot_delete_job_driver, NULL, + qemu_get_aio_context(), JOB_MANUAL_DISMISS, + NULL, NULL, errp); + if (!s) { + return; + } + + s->tag =3D g_strdup(tag); + s->devices =3D QAPI_CLONE(strList, devices); + + job_start(&s->common); +} diff --git a/qapi/job.json b/qapi/job.json index 280c2f76f1..1a6ef03451 100644 --- a/qapi/job.json +++ b/qapi/job.json @@ -22,10 +22,17 @@ # # @amend: image options amend job type, see "x-blockdev-amend" (since 5.1) # +# @snapshot-load: snapshot load job type, see "snapshot-load" (since 6.0) +# +# @snapshot-save: snapshot save job type, see "snapshot-save" (since 6.0) +# +# @snapshot-delete: snapshot delete job type, see "snapshot-delete" (since= 6.0) +# # Since: 1.7 ## { 'enum': 'JobType', - 'data': ['commit', 'stream', 'mirror', 'backup', 'create', 'amend'] } + 'data': ['commit', 'stream', 'mirror', 'backup', 'create', 'amend', + 'snapshot-load', 'snapshot-save', 'snapshot-delete'] } =20 ## # @JobStatus: diff --git a/qapi/migration.json b/qapi/migration.json index 076d2d5634..ce14d78071 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1854,3 +1854,176 @@ # Since: 5.2 ## { 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' } + +## +# @snapshot-save: +# +# Save a VM snapshot +# +# @job-id: identifier for the newly created job +# @tag: name of the snapshot to create +# @vmstate: block device node name to save vmstate to +# @devices: list of block device node names to save a snapshot to +# +# Applications should not assume that the snapshot save is complete +# when this command returns. The job commands / events must be used +# to determine completion and to fetch details of any errors that arise. +# +# Note that execution of the guest CPUs may be stopped during the +# time it takes to save the snapshot. A future version of QEMU +# may ensure CPUs are executing continuously. +# +# It is strongly recommended that @devices contain all writable +# block device nodes if a consistent snapshot is required. +# +# If @tag already exists, an error will be reported +# +# Returns: nothing +# +# Example: +# +# -> { "execute": "snapshot-save", +# "data": { +# "job-id": "snapsave0", +# "tag": "my-snap", +# "vmstate": "disk0", +# "devices": ["disk0", "disk1"] +# } +# } +# <- { "return": { } } +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "created", "id": "snapsave0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "running", "id": "snapsave0"}} +# <- {"event": "STOP"} +# <- {"event": "RESUME"} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "waiting", "id": "snapsave0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "pending", "id": "snapsave0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "concluded", "id": "snapsave0"}} +# -> {"execute": "query-jobs"} +# <- {"return": [{"current-progress": 1, +# "status": "concluded", +# "total-progress": 1, +# "type": "snapshot-save", +# "id": "snapsave0"}]} +# +# Since: 6.0 +## +{ 'command': 'snapshot-save', + 'data': { 'job-id': 'str', + 'tag': 'str', + 'vmstate': 'str', + 'devices': ['str'] } } + +## +# @snapshot-load: +# +# Load a VM snapshot +# +# @job-id: identifier for the newly created job +# @tag: name of the snapshot to load. +# @vmstate: block device node name to load vmstate from +# @devices: list of block device node names to load a snapshot from +# +# Applications should not assume that the snapshot load is complete +# when this command returns. The job commands / events must be used +# to determine completion and to fetch details of any errors that arise. +# +# Note that execution of the guest CPUs will be stopped during the +# time it takes to load the snapshot. +# +# It is strongly recommended that @devices contain all writable +# block device nodes that can have changed since the original +# @snapshot-save command execution. +# +# Returns: nothing +# +# Example: +# +# -> { "execute": "snapshot-load", +# "data": { +# "job-id": "snapload0", +# "tag": "my-snap", +# "vmstate": "disk0", +# "devices": ["disk0", "disk1"] +# } +# } +# <- { "return": { } } +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "created", "id": "snapload0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "running", "id": "snapload0"}} +# <- {"event": "STOP"} +# <- {"event": "RESUME"} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "waiting", "id": "snapload0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "pending", "id": "snapload0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "concluded", "id": "snapload0"}} +# -> {"execute": "query-jobs"} +# <- {"return": [{"current-progress": 1, +# "status": "concluded", +# "total-progress": 1, +# "type": "snapshot-load", +# "id": "snapload0"}]} +# +# Since: 6.0 +## +{ 'command': 'snapshot-load', + 'data': { 'job-id': 'str', + 'tag': 'str', + 'vmstate': 'str', + 'devices': ['str'] } } + +## +# @snapshot-delete: +# +# Delete a VM snapshot +# +# @job-id: identifier for the newly created job +# @tag: name of the snapshot to delete. +# @devices: list of block device node names to delete a snapshot from +# +# Applications should not assume that the snapshot delete is complete +# when this command returns. The job commands / events must be used +# to determine completion and to fetch details of any errors that arise. +# +# Returns: nothing +# +# Example: +# +# -> { "execute": "snapshot-delete", +# "data": { +# "job-id": "snapdelete0", +# "tag": "my-snap", +# "devices": ["disk0", "disk1"] +# } +# } +# <- { "return": { } } +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "created", "id": "snapdelete0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "running", "id": "snapdelete0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "waiting", "id": "snapdelete0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "pending", "id": "snapdelete0"}} +# <- {"event": "JOB_STATUS_CHANGE", +# "data": {"status": "concluded", "id": "snapdelete0"}} +# -> {"execute": "query-jobs"} +# <- {"return": [{"current-progress": 1, +# "status": "concluded", +# "total-progress": 1, +# "type": "snapshot-delete", +# "id": "snapdelete0"}]} +# +# Since: 6.0 +## +{ 'command': 'snapshot-delete', + 'data': { 'job-id': 'str', + 'tag': 'str', + 'devices': ['str'] } } --=20 2.29.2