From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775020236813.589741791463; Mon, 23 Oct 2017 09:10:20 -0700 (PDT) Received: from localhost ([::1]:39499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fIm-0006dL-U7 for importer@patchew.org; Mon, 23 Oct 2017 12:10:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fGt-0005S0-QS for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fGr-000888-VN for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41600) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fGr-00087P-PF for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9B042CE94F for ; Mon, 23 Oct 2017 16:08:08 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id E24F67DF44; Mon, 23 Oct 2017 16:08:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E9B042CE94F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:40 +0200 Message-Id: <20171023160800.20540-2-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 23 Oct 2017 16:08:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/21] migration: Fix migrate_test_apply for multifd parameters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" They were missing when introduced on the tree Signed-off-by: Juan Quintela Reviewed-by: Peter Xu --- migration/migration.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 98429dc843..fb62a639d8 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -865,6 +865,12 @@ static void migrate_params_test_apply(MigrateSetParame= ters *params, if (params->has_block_incremental) { dest->block_incremental =3D params->block_incremental; } + if (params->has_x_multifd_channels) { + dest->x_multifd_channels =3D params->x_multifd_channels; + } + if (params->has_x_multifd_page_count) { + dest->x_multifd_page_count =3D params->x_multifd_page_count; + } } =20 static void migrate_params_apply(MigrateSetParameters *params) --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775530175895.5749702412403; Mon, 23 Oct 2017 09:18:50 -0700 (PDT) Received: from localhost ([::1]:39537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fQv-0005Az-9p for importer@patchew.org; Mon, 23 Oct 2017 12:18:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fGz-0005Ug-HL for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fGt-00089p-ON for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fGt-000892-H2 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2FD15F7AC for ; Mon, 23 Oct 2017 16:08:10 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A0D878DF7; Mon, 23 Oct 2017 16:08:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A2FD15F7AC Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:41 +0200 Message-Id: <20171023160800.20540-3-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 23 Oct 2017 16:08:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/21] migratiom: Remove max_item_age parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It was not used at all since commit: 27af7d6ea5015e5ef1f7985eab94a8a218267a2b which replaced its use by the dirty sync count. Signed-off-by: Juan Quintela Reviewed-by: Peter Xu --- migration/page_cache.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/migration/page_cache.c b/migration/page_cache.c index ba984c4858..381e555ddb 100644 --- a/migration/page_cache.c +++ b/migration/page_cache.c @@ -41,7 +41,6 @@ struct PageCache { CacheItem *page_cache; unsigned int page_size; int64_t max_num_items; - uint64_t max_item_age; int64_t num_items; }; =20 @@ -69,7 +68,6 @@ PageCache *cache_init(int64_t num_pages, unsigned int pag= e_size) } cache->page_size =3D page_size; cache->num_items =3D 0; - cache->max_item_age =3D 0; cache->max_num_items =3D num_pages; =20 DPRINTF("Setting cache buckets to %" PRId64 "\n", cache->max_num_items= ); --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775025212538.6823285889146; Mon, 23 Oct 2017 09:10:25 -0700 (PDT) Received: from localhost ([::1]:39501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fIw-0006kW-K0 for importer@patchew.org; Mon, 23 Oct 2017 12:10:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fGx-0005T1-0X for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fGw-0008C9-2o for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fGv-0008BM-Sx for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4565C0587CA for ; Mon, 23 Oct 2017 16:08:12 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 031CB60BEC; Mon, 23 Oct 2017 16:08:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E4565C0587CA Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:42 +0200 Message-Id: <20171023160800.20540-4-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 23 Oct 2017 16:08:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/21] migration: Make cache size elements use the right types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/page_cache.c | 8 ++++---- migration/page_cache.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/migration/page_cache.c b/migration/page_cache.c index 381e555ddb..6b2dd77cf0 100644 --- a/migration/page_cache.c +++ b/migration/page_cache.c @@ -39,12 +39,12 @@ struct CacheItem { =20 struct PageCache { CacheItem *page_cache; - unsigned int page_size; - int64_t max_num_items; - int64_t num_items; + size_t page_size; + size_t max_num_items; + size_t num_items; }; =20 -PageCache *cache_init(int64_t num_pages, unsigned int page_size) +PageCache *cache_init(size_t num_pages, size_t page_size) { int64_t i; =20 diff --git a/migration/page_cache.h b/migration/page_cache.h index 4fadd0c501..931868b857 100644 --- a/migration/page_cache.h +++ b/migration/page_cache.h @@ -28,7 +28,7 @@ typedef struct PageCache PageCache; * @num_pages: cache maximal number of cached pages * @page_size: cache page size */ -PageCache *cache_init(int64_t num_pages, unsigned int page_size); +PageCache *cache_init(size_t num_pages, size_t page_size); =20 /** * cache_fini: free all cache resources --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775362369225.11813812140724; Mon, 23 Oct 2017 09:16:02 -0700 (PDT) Received: from localhost ([::1]:39528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fOE-0002we-Pu for importer@patchew.org; Mon, 23 Oct 2017 12:15:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fGz-0005Uq-Q6 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fGy-0008Ex-NQ for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36674) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fGy-0008E3-Ep for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9955F79704 for ; Mon, 23 Oct 2017 16:08:15 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4568960BEC; Mon, 23 Oct 2017 16:08:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9955F79704 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:43 +0200 Message-Id: <20171023160800.20540-5-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 23 Oct 2017 16:08:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/21] migration: Move xbzrle cache resize error handling to xbzrle_cache_resize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Peter Xu --- migration/migration.c | 18 +----------------- migration/ram.c | 22 ++++++++++++++++++++-- migration/ram.h | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index fb62a639d8..3feffb5e26 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1373,24 +1373,8 @@ void qmp_migrate_set_cache_size(int64_t value, Error= **errp) MigrationState *s =3D migrate_get_current(); int64_t new_size; =20 - /* Check for truncation */ - if (value !=3D (size_t)value) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "exceeding address space"); - return; - } - - /* Cache should not be larger than guest ram size */ - if (value > ram_bytes_total()) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "exceeds guest ram size "); - return; - } - - new_size =3D xbzrle_cache_resize(value); + new_size =3D xbzrle_cache_resize(value, errp); if (new_size < 0) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "is smaller than page size"); return; } =20 diff --git a/migration/ram.c b/migration/ram.c index b83f8977c5..7c3acad029 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -42,6 +42,7 @@ #include "postcopy-ram.h" #include "migration/page_cache.h" #include "qemu/error-report.h" +#include "qapi/qmp/qerror.h" #include "trace.h" #include "exec/ram_addr.h" #include "qemu/rcu_queue.h" @@ -113,13 +114,30 @@ static void XBZRLE_cache_unlock(void) * Returns the new_size or negative in case of error. * * @new_size: new cache size + * @errp: set *errp if the check failed, with reason */ -int64_t xbzrle_cache_resize(int64_t new_size) +int64_t xbzrle_cache_resize(int64_t new_size, Error **errp) { PageCache *new_cache; int64_t ret; =20 + /* Check for truncation */ + if (new_size !=3D (size_t)new_size) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "exceeding address space"); + return -1; + } + + /* Cache should not be larger than guest ram size */ + if (new_size > ram_bytes_total()) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "exceeds guest ram size"); + return -1; + } + if (new_size < TARGET_PAGE_SIZE) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "is smaller than one target page size"); return -1; } =20 @@ -132,7 +150,7 @@ int64_t xbzrle_cache_resize(int64_t new_size) new_cache =3D cache_init(new_size / TARGET_PAGE_SIZE, TARGET_PAGE_SIZE); if (!new_cache) { - error_report("Error creating cache"); + error_setg(errp, "Error creating cache"); ret =3D -1; goto out; } diff --git a/migration/ram.h b/migration/ram.h index 4a72d66503..511b3dc582 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -35,7 +35,7 @@ extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; =20 -int64_t xbzrle_cache_resize(int64_t new_size); +int64_t xbzrle_cache_resize(int64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); =20 --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775675807772.8401161801287; Mon, 23 Oct 2017 09:21:15 -0700 (PDT) Received: from localhost ([::1]:39556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fTU-0007Qs-IA for importer@patchew.org; Mon, 23 Oct 2017 12:21:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fH3-0005XW-Im for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fH1-0008Is-9I for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fH1-0008Gr-0r for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32A6D800AF for ; Mon, 23 Oct 2017 16:08:18 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEB2260BEC; Mon, 23 Oct 2017 16:08:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 32A6D800AF Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:44 +0200 Message-Id: <20171023160800.20540-6-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 23 Oct 2017 16:08:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/21] migration: Make cache_init() take an error parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Once there, take a total size instead of the size of the pages. We move the check that the new_size is bigger than one page from xbzrle_cache_resize(). Signed-off-by: Juan Quintela Reviewed-by: Peter Xu -- Fix typo spotted by Peter Xu --- migration/page_cache.c | 17 +++++++++++------ migration/page_cache.h | 7 +++---- migration/ram.c | 18 +++++------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/migration/page_cache.c b/migration/page_cache.c index 6b2dd77cf0..9a9d13d6a2 100644 --- a/migration/page_cache.c +++ b/migration/page_cache.c @@ -14,6 +14,8 @@ =20 #include "qemu/osdep.h" =20 +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" #include "qemu-common.h" #include "qemu/host-utils.h" #include "migration/page_cache.h" @@ -44,21 +46,23 @@ struct PageCache { size_t num_items; }; =20 -PageCache *cache_init(size_t num_pages, size_t page_size) +PageCache *cache_init(int64_t new_size, size_t page_size, Error **errp) { int64_t i; - + size_t num_pages =3D new_size / page_size; PageCache *cache; =20 - if (num_pages <=3D 0) { - DPRINTF("invalid number of pages\n"); + if (new_size < page_size) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "is smaller than one target page size"); return NULL; } =20 /* We prefer not to abort if there is no memory */ cache =3D g_try_malloc(sizeof(*cache)); if (!cache) { - DPRINTF("Failed to allocate cache\n"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "Failed to allocate cache"); return NULL; } /* round down to the nearest power of 2 */ @@ -76,7 +80,8 @@ PageCache *cache_init(size_t num_pages, size_t page_size) cache->page_cache =3D g_try_malloc((cache->max_num_items) * sizeof(*cache->page_cache)); if (!cache->page_cache) { - DPRINTF("Failed to allocate cache->page_cache\n"); + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "Failed to allocate page cache"); g_free(cache); return NULL; } diff --git a/migration/page_cache.h b/migration/page_cache.h index 931868b857..0cb94498a0 100644 --- a/migration/page_cache.h +++ b/migration/page_cache.h @@ -24,12 +24,11 @@ typedef struct PageCache PageCache; * * Returns new allocated cache or NULL on error * - * @cache pointer to the PageCache struct - * @num_pages: cache maximal number of cached pages + * @cache_size: cache size in bytes * @page_size: cache page size + * @errp: set *errp if the check failed, with reason */ -PageCache *cache_init(size_t num_pages, size_t page_size); - +PageCache *cache_init(int64_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 7c3acad029..47501460c8 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -135,22 +135,14 @@ int64_t xbzrle_cache_resize(int64_t new_size, Error *= *errp) return -1; } =20 - if (new_size < TARGET_PAGE_SIZE) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", - "is smaller than one target page size"); - return -1; - } - XBZRLE_cache_lock(); =20 if (XBZRLE.cache !=3D NULL) { if (pow2floor(new_size) =3D=3D migrate_xbzrle_cache_size()) { goto out_new_size; } - new_cache =3D cache_init(new_size / TARGET_PAGE_SIZE, - TARGET_PAGE_SIZE); + new_cache =3D cache_init(new_size, TARGET_PAGE_SIZE, errp); if (!new_cache) { - error_setg(errp, "Error creating cache"); ret =3D -1; goto out; } @@ -2028,6 +2020,7 @@ err: static int ram_state_init(RAMState **rsp) { *rsp =3D g_new0(RAMState, 1); + Error *local_err =3D NULL; =20 qemu_mutex_init(&(*rsp)->bitmap_mutex); qemu_mutex_init(&(*rsp)->src_page_req_mutex); @@ -2036,12 +2029,11 @@ static int ram_state_init(RAMState **rsp) if (migrate_use_xbzrle()) { XBZRLE_cache_lock(); XBZRLE.zero_target_page =3D g_malloc0(TARGET_PAGE_SIZE); - XBZRLE.cache =3D cache_init(migrate_xbzrle_cache_size() / - TARGET_PAGE_SIZE, - TARGET_PAGE_SIZE); + XBZRLE.cache =3D cache_init(migrate_xbzrle_cache_size(), + TARGET_PAGE_SIZE, &local_err); if (!XBZRLE.cache) { XBZRLE_cache_unlock(); - error_report("Error creating cache"); + error_report_err(local_err); g_free(*rsp); *rsp =3D NULL; return -1; --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775048878214.29296427711859; Mon, 23 Oct 2017 09:10:48 -0700 (PDT) Received: from localhost ([::1]:39503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fJ7-0006ri-PK for importer@patchew.org; Mon, 23 Oct 2017 12:10:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fH6-0005Y1-Pl for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fH4-0008LU-28 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fH3-0008KV-Sz for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A8A480472 for ; Mon, 23 Oct 2017 16:08:21 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 886B078DE8; Mon, 23 Oct 2017 16:08:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A8A480472 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:45 +0200 Message-Id: <20171023160800.20540-7-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 23 Oct 2017 16:08:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/21] migration: Add 'pause-before-switchover' capability X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" When 'pause-before-switchover' is enabled, the outgoing migration will pause before invalidating the block devices and serializing the device state. At this point the management layer gets the chance to clean up any device jobs or other device users before the migration completes. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 10 ++++++++++ migration/migration.h | 1 + qapi/migration.json | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 3feffb5e26..c041ec7aed 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1511,6 +1511,16 @@ bool migrate_use_multifd(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_X_MULTIFD]; } =20 +bool migrate_pause_before_switchover(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[ + MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER]; +} + int migrate_multifd_channels(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index b83cceadc4..969866303e 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -177,6 +177,7 @@ bool migrate_zero_blocks(void); =20 bool migrate_auto_converge(void); bool migrate_use_multifd(void); +bool migrate_pause_before_switchover(void); int migrate_multifd_channels(void); int migrate_multifd_page_count(void); =20 diff --git a/qapi/migration.json b/qapi/migration.json index f8b365e3f5..4960231ba2 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -341,6 +341,9 @@ # @return-path: If enabled, migration will use the return path even # for precopy. (since 2.10) # +# @pause-before-switchover: Pause outgoing migration before serialising de= vice +# state and before disabling block IO (since 2.11) +# # @x-multifd: Use more than one fd for migration (since 2.11) # # Since: 1.2 @@ -348,7 +351,7 @@ { 'enum': 'MigrationCapability', 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', 'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram', - 'block', 'return-path', 'x-multifd' ] } + 'block', 'return-path', 'pause-before-switchover', 'x-multifd' = ] } =20 ## # @MigrationCapabilityStatus: --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775363829714.2948858673121; Mon, 23 Oct 2017 09:16:03 -0700 (PDT) Received: from localhost ([::1]:39529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fOK-00031k-O4 for importer@patchew.org; Mon, 23 Oct 2017 12:15:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHD-0005cl-1Q for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fH9-0008RT-1s for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fH8-0008QC-Pg for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:26 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3C72BBD8 for ; Mon, 23 Oct 2017 16:08:25 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E6277DF44; Mon, 23 Oct 2017 16:08:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E3C72BBD8 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:46 +0200 Message-Id: <20171023160800.20540-8-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 23 Oct 2017 16:08:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/21] migration: Add 'pre-switchover' and 'device' statuses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add two statuses for use when the 'pause-before-switchover' capability is enabled. 'pre-switchover' is the state that we wait in for management to allow us to continue. 'device' is the state we enter while serialising the devices after management gives us the OK. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 6 ++++++ qapi/migration.json | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index c041ec7aed..f15372e007 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -526,6 +526,8 @@ static bool migration_is_setup_or_active(int state) case MIGRATION_STATUS_ACTIVE: case MIGRATION_STATUS_POSTCOPY_ACTIVE: case MIGRATION_STATUS_SETUP: + case MIGRATION_STATUS_PRE_SWITCHOVER: + case MIGRATION_STATUS_DEVICE: return true; =20 default: @@ -600,6 +602,8 @@ MigrationInfo *qmp_query_migrate(Error **errp) case MIGRATION_STATUS_ACTIVE: case MIGRATION_STATUS_CANCELLING: case MIGRATION_STATUS_POSTCOPY_ACTIVE: + case MIGRATION_STATUS_PRE_SWITCHOVER: + case MIGRATION_STATUS_DEVICE: /* TODO add some postcopy stats */ info->has_status =3D true; info->has_total_time =3D true; @@ -1189,6 +1193,8 @@ bool migration_is_idle(void) case MIGRATION_STATUS_ACTIVE: case MIGRATION_STATUS_POSTCOPY_ACTIVE: case MIGRATION_STATUS_COLO: + case MIGRATION_STATUS_PRE_SWITCHOVER: + case MIGRATION_STATUS_DEVICE: return false; case MIGRATION_STATUS__MAX: g_assert_not_reached(); diff --git a/qapi/migration.json b/qapi/migration.json index 4960231ba2..b56f95db64 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -96,12 +96,18 @@ # @colo: VM is in the process of fault tolerance, VM can not get into this # state unless colo capability is enabled for migration. (since 2.8) # +# @pre-switchover: Paused before device serialisation. (since 2.11) +# +# @device: During device serialisation when pause-before-switchover is ena= bled +# (since 2.11) +# # Since: 2.3 # ## { 'enum': 'MigrationStatus', 'data': [ 'none', 'setup', 'cancelling', 'cancelled', - 'active', 'postcopy-active', 'completed', 'failed', 'colo' ] } + 'active', 'postcopy-active', 'completed', 'failed', 'colo', + 'pre-switchover', 'device' ] } =20 ## # @MigrationInfo: --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775209956905.8432118878735; Mon, 23 Oct 2017 09:13:29 -0700 (PDT) Received: from localhost ([::1]:39516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fLu-0000rA-3T for importer@patchew.org; Mon, 23 Oct 2017 12:13:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHD-0005ck-1M for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHA-0008To-SO for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46500) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHA-0008Sj-J8 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C58904E906 for ; Mon, 23 Oct 2017 16:08:27 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 450C878DF4; Mon, 23 Oct 2017 16:08:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C58904E906 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:47 +0200 Message-Id: <20171023160800.20540-9-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 23 Oct 2017 16:08:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/21] migration: Wait for semaphore before completing migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Wait for a semaphore before completing the migration, if the previously added capability was enabled. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 38 ++++++++++++++++++++++++++++++++++++++ migration/migration.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index f15372e007..ef84d2c1fb 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1958,6 +1958,39 @@ fail: } =20 /** + * migration_maybe_pause: Pause if required to by + * migrate_pause_before_switchover called with the iothread locked + * Returns: 0 on success + */ +static int migration_maybe_pause(MigrationState *s, int *current_active_st= ate) +{ + if (!migrate_pause_before_switchover()) { + return 0; + } + + /* Since leaving this state is not atomic with posting the semaphore + * it's possible that someone could have issued multiple migrate_conti= nue + * and the semaphore is incorrectly positive at this point; + * the docs say it's undefined to reinit a semaphore that's already + * init'd, so use timedwait to eat up any existing posts. + */ + while (qemu_sem_timedwait(&s->pause_sem, 1) =3D=3D 0) { + /* This block intentionally left blank */ + } + + qemu_mutex_unlock_iothread(); + migrate_set_state(&s->state, *current_active_state, + MIGRATION_STATUS_PRE_SWITCHOVER); + qemu_sem_wait(&s->pause_sem); + migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, + MIGRATION_STATUS_DEVICE); + *current_active_state =3D MIGRATION_STATUS_DEVICE; + qemu_mutex_lock_iothread(); + + return s->state =3D=3D MIGRATION_STATUS_DEVICE ? 0 : -EINVAL; +} + +/** * migration_completion: Used by migration_thread when there's not much le= ft. * The caller 'breaks' the loop when this returns. * @@ -1983,6 +2016,9 @@ static void migration_completion(MigrationState *s, i= nt current_active_state, bool inactivate =3D !migrate_colo_enabled(); ret =3D vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); if (ret >=3D 0) { + ret =3D migration_maybe_pause(s, ¤t_active_state); + } + if (ret >=3D 0) { qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX); ret =3D qemu_savevm_state_complete_precopy(s->to_dst_file,= false, inactivate); @@ -2363,6 +2399,7 @@ static void migration_instance_finalize(Object *obj) =20 g_free(params->tls_hostname); g_free(params->tls_creds); + qemu_sem_destroy(&ms->pause_sem); } =20 static void migration_instance_init(Object *obj) @@ -2373,6 +2410,7 @@ static void migration_instance_init(Object *obj) ms->state =3D MIGRATION_STATUS_NONE; ms->xbzrle_cache_size =3D DEFAULT_MIGRATE_CACHE_SIZE; ms->mbps =3D -1; + qemu_sem_init(&ms->pause_sem, 0); =20 params->tls_hostname =3D g_strdup(""); params->tls_creds =3D g_strdup(""); diff --git a/migration/migration.h b/migration/migration.h index 969866303e..cd988a99b9 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -121,6 +121,9 @@ struct MigrationState /* Flag set once the migration thread called bdrv_inactivate_all */ bool block_inactive; =20 + /* Migration is paused due to pause-before-switchover */ + QemuSemaphore pause_sem; + /* The semaphore is used to notify COLO thread that failover is finish= ed */ QemuSemaphore colo_exit_sem; =20 --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775368747215.3525884130653; Mon, 23 Oct 2017 09:16:08 -0700 (PDT) Received: from localhost ([::1]:39530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fOU-0003Az-NW for importer@patchew.org; Mon, 23 Oct 2017 12:16:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHD-0005cm-Te for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHC-000053-V8 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHC-0008VT-P4 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E04404A700 for ; Mon, 23 Oct 2017 16:08:29 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28B1678DF2; Mon, 23 Oct 2017 16:08:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E04404A700 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:48 +0200 Message-Id: <20171023160800.20540-10-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 23 Oct 2017 16:08:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/21] migration: migrate-continue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" A new qmp command allows the caller to continue from a given paused state. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 11 +++++++++++ qapi/migration.json | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index ef84d2c1fb..90bfdc3a7c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1374,6 +1374,17 @@ void qmp_migrate_cancel(Error **errp) migrate_fd_cancel(migrate_get_current()); } =20 +void qmp_migrate_continue(MigrationStatus state, Error **errp) +{ + MigrationState *s =3D migrate_get_current(); + if (s->state !=3D state) { + error_setg(errp, "Migration not in expected state: %s", + MigrationStatus_str(s->state)); + return; + } + qemu_sem_post(&s->pause_sem); +} + void qmp_migrate_set_cache_size(int64_t value, Error **errp) { MigrationState *s =3D migrate_get_current(); diff --git a/qapi/migration.json b/qapi/migration.json index b56f95db64..272f191551 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -877,6 +877,23 @@ { 'command': 'migrate_cancel' } =20 ## +# @migrate-continue: +# +# Continue migration when it's in a paused state. +# +# @state: The state the migration is currently expected to be in +# +# Returns: nothing on success +# Since: 2.11 +# Example: +# +# -> { "execute": "migrate-continue" , "arguments": +# { "state": "pre-switchover" } } +# <- { "return": {} } +## +{ 'command': 'migrate-continue', 'data': {'state': 'MigrationStatus'} } + +## # @migrate_set_downtime: # # Set maximum tolerated downtime for migration. --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775193238185.31666874915584; Mon, 23 Oct 2017 09:13:13 -0700 (PDT) Received: from localhost ([::1]:39515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fLi-0000iU-9d for importer@patchew.org; Mon, 23 Oct 2017 12:13:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHG-0005eC-0O for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHF-00008X-1z for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHE-000073-SG for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AAF9C0587CC for ; Mon, 23 Oct 2017 16:08:32 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42CD760E3B; Mon, 23 Oct 2017 16:08:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0AAF9C0587CC Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:49 +0200 Message-Id: <20171023160800.20540-11-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 23 Oct 2017 16:08:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/21] migrate: HMP migate_continue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" HMP equivalent to the just added migrate-continue Unpause a migrate paused at a given state. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- hmp-commands.hx | 12 ++++++++++++ hmp.c | 13 +++++++++++++ hmp.h | 1 + 3 files changed, 26 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 1941e19932..4afd57cf5f 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -959,7 +959,19 @@ STEXI @item migrate_cancel @findex migrate_cancel Cancel the current VM migration. +ETEXI =20 + { + .name =3D "migrate_continue", + .args_type =3D "state:s", + .params =3D "state", + .help =3D "Continue migration from the given paused state", + .cmd =3D hmp_migrate_continue, + }, +STEXI +@item migrate_continue @var{state} +@findex migrate_continue +Continue migration from the paused state @var{state} ETEXI =20 { diff --git a/hmp.c b/hmp.c index ec61329ebb..41fcce6f5a 100644 --- a/hmp.c +++ b/hmp.c @@ -1495,6 +1495,19 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *q= dict) qmp_migrate_cancel(NULL); } =20 +void hmp_migrate_continue(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + const char *state =3D qdict_get_str(qdict, "state"); + int val =3D qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); + + if (val >=3D 0) { + qmp_migrate_continue(val, &err); + } + + hmp_handle_error(mon, &err); +} + void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; diff --git a/hmp.h b/hmp.h index 3605003e4c..a6f56b1f29 100644 --- a/hmp.h +++ b/hmp.h @@ -68,6 +68,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict); void hmp_delvm(Monitor *mon, const QDict *qdict); void hmp_info_snapshots(Monitor *mon, const QDict *qdict); void hmp_migrate_cancel(Monitor *mon, const QDict *qdict); +void hmp_migrate_continue(Monitor *mon, const QDict *qdict); void hmp_migrate_incoming(Monitor *mon, const QDict *qdict); void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict); void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict); --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775055812410.85545547994457; Mon, 23 Oct 2017 09:10:55 -0700 (PDT) Received: from localhost ([::1]:39509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fJQ-0007At-Bm for importer@patchew.org; Mon, 23 Oct 2017 12:10:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHI-0005gL-BP for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHH-0000BZ-9t for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHH-0000AV-47 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E54A6A7C9 for ; Mon, 23 Oct 2017 16:08:34 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F6FF78DEA; Mon, 23 Oct 2017 16:08:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4E54A6A7C9 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:50 +0200 Message-Id: <20171023160800.20540-12-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 23 Oct 2017 16:08:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/21] migration: allow cancel to unpause X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" If a migration_cancel is issued during the new paused state, kick the pause_sem to get to unpause so it can cancel. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 90bfdc3a7c..b523d8f215 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1114,6 +1114,10 @@ static void migrate_fd_cancel(MigrationState *s) if (!migration_is_setup_or_active(old_state)) { break; } + /* If the migration is paused, kick it out of the pause */ + if (old_state =3D=3D MIGRATION_STATUS_PRE_SWITCHOVER) { + qemu_sem_post(&s->pause_sem); + } migrate_set_state(&s->state, old_state, MIGRATION_STATUS_CANCELLIN= G); } while (s->state !=3D MIGRATION_STATUS_CANCELLING); =20 --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775787971376.45142739535504; Mon, 23 Oct 2017 09:23:07 -0700 (PDT) Received: from localhost ([::1]:39570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fVG-0000HH-6C for importer@patchew.org; Mon, 23 Oct 2017 12:23:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHM-0005js-E6 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHJ-0000Fd-U1 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHJ-0000EM-LD for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C890015565 for ; Mon, 23 Oct 2017 16:08:36 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52B178DF2; Mon, 23 Oct 2017 16:08:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C890015565 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:51 +0200 Message-Id: <20171023160800.20540-13-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 23 Oct 2017 16:08:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/21] migration: pause-before-switchover for postcopy X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add pause-before-switchover support for postcopy. After starting postcopy it will transition active->pre-switchover->postcopy_active Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b523d8f215..a058f8b46d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -104,6 +104,9 @@ enum mig_rp_message_type { static MigrationState *current_migration; =20 static bool migration_object_check(MigrationState *ms, Error **errp); +static int migration_maybe_pause(MigrationState *s, + int *current_active_state, + int new_state); =20 void migration_object_init(void) { @@ -1820,8 +1823,11 @@ static int postcopy_start(MigrationState *ms, bool *= old_vm_running) QEMUFile *fb; int64_t time_at_stop =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); bool restart_block =3D false; - migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_POSTCOPY_ACTIVE); + int cur_state =3D MIGRATION_STATUS_ACTIVE; + if (!migrate_pause_before_switchover()) { + migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_POSTCOPY_ACTIVE); + } =20 trace_postcopy_start(); qemu_mutex_lock_iothread(); @@ -1835,6 +1841,12 @@ static int postcopy_start(MigrationState *ms, bool *= old_vm_running) goto fail; } =20 + ret =3D migration_maybe_pause(ms, &cur_state, + MIGRATION_STATUS_POSTCOPY_ACTIVE); + if (ret < 0) { + goto fail; + } + ret =3D bdrv_inactivate_all(); if (ret < 0) { goto fail; @@ -1977,7 +1989,9 @@ fail: * migrate_pause_before_switchover called with the iothread locked * Returns: 0 on success */ -static int migration_maybe_pause(MigrationState *s, int *current_active_st= ate) +static int migration_maybe_pause(MigrationState *s, + int *current_active_state, + int new_state) { if (!migrate_pause_before_switchover()) { return 0; @@ -1998,11 +2012,11 @@ static int migration_maybe_pause(MigrationState *s,= int *current_active_state) MIGRATION_STATUS_PRE_SWITCHOVER); qemu_sem_wait(&s->pause_sem); migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, - MIGRATION_STATUS_DEVICE); - *current_active_state =3D MIGRATION_STATUS_DEVICE; + new_state); + *current_active_state =3D new_state; qemu_mutex_lock_iothread(); =20 - return s->state =3D=3D MIGRATION_STATUS_DEVICE ? 0 : -EINVAL; + return s->state =3D=3D new_state ? 0 : -EINVAL; } =20 /** @@ -2031,7 +2045,8 @@ static void migration_completion(MigrationState *s, i= nt current_active_state, bool inactivate =3D !migrate_colo_enabled(); ret =3D vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); if (ret >=3D 0) { - ret =3D migration_maybe_pause(s, ¤t_active_state); + ret =3D migration_maybe_pause(s, ¤t_active_state, + MIGRATION_STATUS_DEVICE); } if (ret >=3D 0) { qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX); --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775219286549.2515073780856; Mon, 23 Oct 2017 09:13:39 -0700 (PDT) Received: from localhost ([::1]:39517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fMA-00016M-Cl for importer@patchew.org; Mon, 23 Oct 2017 12:13:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHN-0005kh-CF for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHM-0000JE-CY for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHM-0000He-6J for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13E724A700 for ; Mon, 23 Oct 2017 16:08:39 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 274BD78DE8; Mon, 23 Oct 2017 16:08:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13E724A700 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:52 +0200 Message-Id: <20171023160800.20540-14-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 23 Oct 2017 16:08:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/21] migration: provide ram_state_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu The old ram_state_init() is not really initializing the RAMState only, but including lots of other stuff that is RAM-related. Renaming it to ram_init_all(). Instead, provide a real ram_state_init(). Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 47501460c8..13f4b3d101 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2019,13 +2019,36 @@ err: =20 static int ram_state_init(RAMState **rsp) { - *rsp =3D g_new0(RAMState, 1); - Error *local_err =3D NULL; + *rsp =3D g_try_new0(RAMState, 1); + + if (!*rsp) { + error_report("%s: Init ramstate fail", __func__); + return -1; + } =20 qemu_mutex_init(&(*rsp)->bitmap_mutex); qemu_mutex_init(&(*rsp)->src_page_req_mutex); QSIMPLEQ_INIT(&(*rsp)->src_page_requests); =20 + /* + * Count the total number of pages used by ram blocks not including any + * gaps due to alignment or unplugs. + */ + (*rsp)->migration_dirty_pages =3D ram_bytes_total() >> TARGET_PAGE_BIT= S; + + ram_state_reset(*rsp); + + return 0; +} + +static int ram_init_all(RAMState **rsp) +{ + Error *local_err =3D NULL; + + if (ram_state_init(rsp)) { + return -1; + } + if (migrate_use_xbzrle()) { XBZRLE_cache_lock(); XBZRLE.zero_target_page =3D g_malloc0(TARGET_PAGE_SIZE); @@ -2065,7 +2088,6 @@ static int ram_state_init(RAMState **rsp) =20 qemu_mutex_lock_ramlist(); rcu_read_lock(); - ram_state_reset(*rsp); =20 /* Skip setting bitmap if there is no RAM */ if (ram_bytes_total()) { @@ -2083,12 +2105,6 @@ static int ram_state_init(RAMState **rsp) } } =20 - /* - * Count the total number of pages used by ram blocks not including any - * gaps due to alignment or unplugs. - */ - (*rsp)->migration_dirty_pages =3D ram_bytes_total() >> TARGET_PAGE_BIT= S; - memory_global_dirty_log_start(); migration_bitmap_sync(*rsp); qemu_mutex_unlock_ramlist(); @@ -2120,7 +2136,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) =20 /* migration has already setup the bitmap, reuse it. */ if (!migration_in_colo_state()) { - if (ram_state_init(rsp) !=3D 0) { + if (ram_init_all(rsp) !=3D 0) { return -1; } } --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775903443345.02667385905056; Mon, 23 Oct 2017 09:25:03 -0700 (PDT) Received: from localhost ([::1]:39576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fWv-0001Us-Jz for importer@patchew.org; Mon, 23 Oct 2017 12:24:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHO-0005mb-Sw for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHN-0000Li-Ug for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59228) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHN-0000Kb-O4 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E35438048C for ; Mon, 23 Oct 2017 16:08:40 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67DB978DF2; Mon, 23 Oct 2017 16:08:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E35438048C Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:53 +0200 Message-Id: <20171023160800.20540-15-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 23 Oct 2017 16:08:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/21] migration: provide ram_state_cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu There are two Mutexes that are created but not yet destroyed for RAMState. Fix that. Since we are at it, provide helper function to clean up RAMState. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 13f4b3d101..d91e8787ae 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1576,6 +1576,15 @@ static void xbzrle_load_cleanup(void) XBZRLE.decoded_buf =3D NULL; } =20 +static void ram_state_cleanup(RAMState **rsp) +{ + migration_page_queue_free(*rsp); + qemu_mutex_destroy(&(*rsp)->bitmap_mutex); + qemu_mutex_destroy(&(*rsp)->src_page_req_mutex); + g_free(*rsp); + *rsp =3D NULL; +} + static void ram_save_cleanup(void *opaque) { RAMState **rsp =3D opaque; @@ -1605,10 +1614,8 @@ static void ram_save_cleanup(void *opaque) XBZRLE.zero_target_page =3D NULL; } XBZRLE_cache_unlock(); - migration_page_queue_free(*rsp); compress_threads_save_cleanup(); - g_free(*rsp); - *rsp =3D NULL; + ram_state_cleanup(rsp); } =20 static void ram_state_reset(RAMState *rs) --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775541168907.3883413172301; Mon, 23 Oct 2017 09:19:01 -0700 (PDT) Received: from localhost ([::1]:39539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fRH-0005RF-6w for importer@patchew.org; Mon, 23 Oct 2017 12:18:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHW-0005tS-CH for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHS-0000Qx-8l for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHS-0000Q4-0J for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2AC9A80C26 for ; Mon, 23 Oct 2017 16:08:45 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41D8278DF2; Mon, 23 Oct 2017 16:08:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2AC9A80C26 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:54 +0200 Message-Id: <20171023160800.20540-16-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 23 Oct 2017 16:08:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/21] migration: clean up xbzrle cache init/destroy X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu Let's further simplify ram_init_all() and ram_save_cleanup() by abstract all the XBZRLE related codes into their own functions. When allocating xbzrle cache, we are always very careful on -ENOMEM; which makes sense. Replacing the last g_malloc0() with g_try_malloc0(), then refactor the logic a bit. This patch should be fixing some memory leaks when some memory allocation failed for XBZRLE in the past. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 131 +++++++++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 81 insertions(+), 50 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index d91e8787ae..60f9cfe8be 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1585,23 +1585,8 @@ static void ram_state_cleanup(RAMState **rsp) *rsp =3D NULL; } =20 -static void ram_save_cleanup(void *opaque) +static void xbzrle_cleanup(void) { - RAMState **rsp =3D opaque; - RAMBlock *block; - - /* caller have hold iothread lock or is in a bh, so there is - * no writing race against this migration_bitmap - */ - memory_global_dirty_log_stop(); - - QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { - g_free(block->bmap); - block->bmap =3D NULL; - g_free(block->unsentmap); - block->unsentmap =3D NULL; - } - XBZRLE_cache_lock(); if (XBZRLE.cache) { cache_fini(XBZRLE.cache); @@ -1614,6 +1599,26 @@ static void ram_save_cleanup(void *opaque) XBZRLE.zero_target_page =3D NULL; } XBZRLE_cache_unlock(); +} + +static void ram_save_cleanup(void *opaque) +{ + RAMState **rsp =3D opaque; + RAMBlock *block; + + /* caller have hold iothread lock or is in a bh, so there is + * no writing race against this migration_bitmap + */ + memory_global_dirty_log_stop(); + + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + g_free(block->bmap); + block->bmap =3D NULL; + g_free(block->unsentmap); + block->unsentmap =3D NULL; + } + + xbzrle_cleanup(); compress_threads_save_cleanup(); ram_state_cleanup(rsp); } @@ -2024,6 +2029,63 @@ err: return ret; } =20 +/* + * For every allocation, we will try not to crash the VM if the + * allocation failed. + */ +static int xbzrle_init(void) +{ + Error *local_err =3D NULL; + + if (!migrate_use_xbzrle()) { + return 0; + } + + XBZRLE_cache_lock(); + + XBZRLE.zero_target_page =3D g_try_malloc0(TARGET_PAGE_SIZE); + if (!XBZRLE.zero_target_page) { + error_report("%s: Error allocating zero page", __func__); + goto err_out; + } + + XBZRLE.cache =3D cache_init(migrate_xbzrle_cache_size(), + TARGET_PAGE_SIZE, &local_err); + if (!XBZRLE.cache) { + error_report_err(local_err); + goto free_zero_page; + } + + XBZRLE.encoded_buf =3D g_try_malloc0(TARGET_PAGE_SIZE); + if (!XBZRLE.encoded_buf) { + error_report("%s: Error allocating encoded_buf", __func__); + goto free_cache; + } + + XBZRLE.current_buf =3D g_try_malloc(TARGET_PAGE_SIZE); + if (!XBZRLE.current_buf) { + error_report("%s: Error allocating current_buf", __func__); + goto free_encoded_buf; + } + + /* We are all good */ + XBZRLE_cache_unlock(); + return 0; + +free_encoded_buf: + g_free(XBZRLE.encoded_buf); + XBZRLE.encoded_buf =3D NULL; +free_cache: + cache_fini(XBZRLE.cache); + XBZRLE.cache =3D NULL; +free_zero_page: + g_free(XBZRLE.zero_target_page); + XBZRLE.zero_target_page =3D NULL; +err_out: + XBZRLE_cache_unlock(); + return -ENOMEM; +} + static int ram_state_init(RAMState **rsp) { *rsp =3D g_try_new0(RAMState, 1); @@ -2050,44 +2112,13 @@ static int ram_state_init(RAMState **rsp) =20 static int ram_init_all(RAMState **rsp) { - Error *local_err =3D NULL; - if (ram_state_init(rsp)) { return -1; } =20 - if (migrate_use_xbzrle()) { - XBZRLE_cache_lock(); - XBZRLE.zero_target_page =3D g_malloc0(TARGET_PAGE_SIZE); - XBZRLE.cache =3D cache_init(migrate_xbzrle_cache_size(), - TARGET_PAGE_SIZE, &local_err); - if (!XBZRLE.cache) { - XBZRLE_cache_unlock(); - error_report_err(local_err); - g_free(*rsp); - *rsp =3D NULL; - return -1; - } - XBZRLE_cache_unlock(); - - /* We prefer not to abort if there is no memory */ - XBZRLE.encoded_buf =3D g_try_malloc0(TARGET_PAGE_SIZE); - if (!XBZRLE.encoded_buf) { - error_report("Error allocating encoded_buf"); - g_free(*rsp); - *rsp =3D NULL; - return -1; - } - - XBZRLE.current_buf =3D g_try_malloc(TARGET_PAGE_SIZE); - if (!XBZRLE.current_buf) { - error_report("Error allocating current_buf"); - g_free(XBZRLE.encoded_buf); - XBZRLE.encoded_buf =3D NULL; - g_free(*rsp); - *rsp =3D NULL; - return -1; - } + if (xbzrle_init()) { + ram_state_cleanup(rsp); + return -1; } =20 /* For memory_global_dirty_log_start below. */ --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775385744966.7298542405764; Mon, 23 Oct 2017 09:16:25 -0700 (PDT) Received: from localhost ([::1]:39531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fOl-0003PF-So for importer@patchew.org; Mon, 23 Oct 2017 12:16:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHW-0005tR-CC for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHU-0000T7-H2 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37286) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHU-0000SN-Ab for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:48 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71F14C0587E6 for ; Mon, 23 Oct 2017 16:08:47 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 801EE7DF44; Mon, 23 Oct 2017 16:08:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71F14C0587E6 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:55 +0200 Message-Id: <20171023160800.20540-17-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 23 Oct 2017 16:08:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/21] migration: new ram_init_bitmaps() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu Rearrange the bitmap initialization and the first sync. Since at it, make sure the locks are taken/released in correct order (I moved RCU unlock upper - though it may not affect much). Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 60f9cfe8be..1b19a899c9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2110,30 +2110,15 @@ static int ram_state_init(RAMState **rsp) return 0; } =20 -static int ram_init_all(RAMState **rsp) +static void ram_list_init_bitmaps(void) { - if (ram_state_init(rsp)) { - return -1; - } - - if (xbzrle_init()) { - ram_state_cleanup(rsp); - return -1; - } - - /* For memory_global_dirty_log_start below. */ - qemu_mutex_lock_iothread(); - - qemu_mutex_lock_ramlist(); - rcu_read_lock(); + RAMBlock *block; + unsigned long pages; =20 /* Skip setting bitmap if there is no RAM */ if (ram_bytes_total()) { - RAMBlock *block; - QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { - unsigned long pages =3D block->max_length >> TARGET_PAGE_BITS; - + pages =3D block->max_length >> TARGET_PAGE_BITS; block->bmap =3D bitmap_new(pages); bitmap_set(block->bmap, 0, pages); if (migrate_postcopy_ram()) { @@ -2142,12 +2127,36 @@ static int ram_init_all(RAMState **rsp) } } } +} =20 +static void ram_init_bitmaps(RAMState *rs) +{ + /* For memory_global_dirty_log_start below. */ + qemu_mutex_lock_iothread(); + qemu_mutex_lock_ramlist(); + rcu_read_lock(); + + ram_list_init_bitmaps(); memory_global_dirty_log_start(); - migration_bitmap_sync(*rsp); + migration_bitmap_sync(rs); + + rcu_read_unlock(); qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_iothread(); - rcu_read_unlock(); +} + +static int ram_init_all(RAMState **rsp) +{ + if (ram_state_init(rsp)) { + return -1; + } + + if (xbzrle_init()) { + ram_state_cleanup(rsp); + return -1; + } + + ram_init_bitmaps(*rsp); =20 return 0; } --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775525707986.1578154681583; Mon, 23 Oct 2017 09:18:45 -0700 (PDT) Received: from localhost ([::1]:39538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fR4-0005Hf-PH for importer@patchew.org; Mon, 23 Oct 2017 12:18:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHY-0005ul-KS for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHX-0000WV-4e for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47910) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHW-0000VG-Rq for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D283CCAA67; Mon, 23 Oct 2017 16:08:49 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id C88997DF4E; Mon, 23 Oct 2017 16:08:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D283CCAA67 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:56 +0200 Message-Id: <20171023160800.20540-18-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 23 Oct 2017 16:08:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 17/21] migration: postcopy_place_page factoring out X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com, Alexey Perevalov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alexey Perevalov Need to mark copied pages as closer as possible to the place where it tracks down. That will be necessary in futher patch. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Alexey Perevalov Signed-off-by: Juan Quintela --- migration/postcopy-ram.c | 13 +++++++------ migration/postcopy-ram.h | 4 ++-- migration/ram.c | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 0de68e8b25..d3073b93b5 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -646,9 +646,10 @@ int postcopy_ram_enable_notify(MigrationIncomingState = *mis) * returns 0 on success */ int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m, - size_t pagesize) + RAMBlock *rb) { struct uffdio_copy copy_struct; + size_t pagesize =3D qemu_ram_pagesize(rb); =20 copy_struct.dst =3D (uint64_t)(uintptr_t)host; copy_struct.src =3D (uint64_t)(uintptr_t)from; @@ -677,11 +678,11 @@ int postcopy_place_page(MigrationIncomingState *mis, = void *host, void *from, * returns 0 on success */ int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, - size_t pagesize) + RAMBlock *rb) { trace_postcopy_place_page_zero(host); =20 - if (pagesize =3D=3D getpagesize()) { + if (qemu_ram_pagesize(rb) =3D=3D getpagesize()) { struct uffdio_zeropage zero_struct; zero_struct.range.start =3D (uint64_t)(uintptr_t)host; zero_struct.range.len =3D getpagesize(); @@ -711,7 +712,7 @@ int postcopy_place_page_zero(MigrationIncomingState *mi= s, void *host, memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_si= ze); } return postcopy_place_page(mis, host, mis->postcopy_tmp_zero_page, - pagesize); + rb); } =20 return 0; @@ -774,14 +775,14 @@ int postcopy_ram_enable_notify(MigrationIncomingState= *mis) } =20 int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m, - size_t pagesize) + RAMBlock *rb) { assert(0); return -1; } =20 int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, - size_t pagesize) + RAMBlock *rb) { assert(0); return -1; diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 587a8b86a7..77ea0fd264 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -72,14 +72,14 @@ void postcopy_discard_send_finish(MigrationState *ms, * returns 0 on success */ int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m, - size_t pagesize); + RAMBlock *rb); =20 /* * Place a zero page at (host) atomically * returns 0 on success */ int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, - size_t pagesize); + RAMBlock *rb); =20 /* The current postcopy state is read/set by postcopy_state_get/set * which update it atomically. diff --git a/migration/ram.c b/migration/ram.c index 1b19a899c9..bd4fc5ceb4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2753,10 +2753,10 @@ static int ram_load_postcopy(QEMUFile *f) =20 if (all_zero) { ret =3D postcopy_place_page_zero(mis, place_dest, - block->page_size); + block); } else { ret =3D postcopy_place_page(mis, place_dest, - place_source, block->page_size); + place_source, block); } } if (!ret) { --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775993570639.6674399822285; Mon, 23 Oct 2017 09:26:33 -0700 (PDT) Received: from localhost ([::1]:39593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fYc-0002gf-CA for importer@patchew.org; Mon, 23 Oct 2017 12:26:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHc-0005wh-BO for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHa-0000Zp-3d for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHZ-0000Ye-Rv for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1BF461D22; Mon, 23 Oct 2017 16:08:52 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 349A078DF4; Mon, 23 Oct 2017 16:08:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1BF461D22 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:57 +0200 Message-Id: <20171023160800.20540-19-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 23 Oct 2017 16:08:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 18/21] migration: introduce qemu_ufd_copy_ioctl helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com, Alexey Perevalov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alexey Perevalov Just for placing auxilary operations inside helper, auxilary operations like: track received pages, notify about copying operation in futher patches. Reviewed-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Signed-off-by: Alexey Perevalov Signed-off-by: Juan Quintela --- migration/postcopy-ram.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index d3073b93b5..8bf6432567 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -641,6 +641,25 @@ int postcopy_ram_enable_notify(MigrationIncomingState = *mis) return 0; } =20 +static int qemu_ufd_copy_ioctl(int userfault_fd, void *host_addr, + void *from_addr, uint64_t pagesize) +{ + if (from_addr) { + struct uffdio_copy copy_struct; + copy_struct.dst =3D (uint64_t)(uintptr_t)host_addr; + copy_struct.src =3D (uint64_t)(uintptr_t)from_addr; + copy_struct.len =3D pagesize; + copy_struct.mode =3D 0; + return ioctl(userfault_fd, UFFDIO_COPY, ©_struct); + } else { + struct uffdio_zeropage zero_struct; + zero_struct.range.start =3D (uint64_t)(uintptr_t)host_addr; + zero_struct.range.len =3D pagesize; + zero_struct.mode =3D 0; + return ioctl(userfault_fd, UFFDIO_ZEROPAGE, &zero_struct); + } +} + /* * Place a host page (from) at (host) atomically * returns 0 on success @@ -648,20 +667,14 @@ int postcopy_ram_enable_notify(MigrationIncomingState= *mis) int postcopy_place_page(MigrationIncomingState *mis, void *host, void *fro= m, RAMBlock *rb) { - struct uffdio_copy copy_struct; size_t pagesize =3D qemu_ram_pagesize(rb); =20 - copy_struct.dst =3D (uint64_t)(uintptr_t)host; - copy_struct.src =3D (uint64_t)(uintptr_t)from; - copy_struct.len =3D pagesize; - copy_struct.mode =3D 0; - /* copy also acks to the kernel waking the stalled thread up * TODO: We can inhibit that ack and only do it if it was requested * which would be slightly cheaper, but we'd have to be careful * of the order of updating our page state. */ - if (ioctl(mis->userfault_fd, UFFDIO_COPY, ©_struct)) { + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, from, pagesize)) { int e =3D errno; error_report("%s: %s copy host: %p from: %p (size: %zd)", __func__, strerror(e), host, from, pagesize); @@ -683,12 +696,7 @@ int postcopy_place_page_zero(MigrationIncomingState *m= is, void *host, trace_postcopy_place_page_zero(host); =20 if (qemu_ram_pagesize(rb) =3D=3D getpagesize()) { - struct uffdio_zeropage zero_struct; - zero_struct.range.start =3D (uint64_t)(uintptr_t)host; - zero_struct.range.len =3D getpagesize(); - zero_struct.mode =3D 0; - - if (ioctl(mis->userfault_fd, UFFDIO_ZEROPAGE, &zero_struct)) { + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, getpagesize= ())) { int e =3D errno; error_report("%s: %s zero host: %p", __func__, strerror(e), host); --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775555703760.8000213144345; Mon, 23 Oct 2017 09:19:15 -0700 (PDT) Received: from localhost ([::1]:39540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fRV-0005eY-SY for importer@patchew.org; Mon, 23 Oct 2017 12:19:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHg-0005zg-Br for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHc-0000cW-Mh for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHc-0000bS-Da for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 868407EA8E; Mon, 23 Oct 2017 16:08:55 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5320878DF7; Mon, 23 Oct 2017 16:08:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 868407EA8E Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:58 +0200 Message-Id: <20171023160800.20540-20-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 23 Oct 2017 16:08:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 19/21] migration: add bitmap for received page X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com, Alexey Perevalov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alexey Perevalov This patch adds ability to track down already received pages, it's necessary for calculation vCPU block time in postcopy migration feature, and for recovery after postcopy migration failure. Also it's necessary to solve shared memory issue in postcopy livemigration. Information about received pages will be transferred to the software virtual bridge (e.g. OVS-VSWITCHD), to avoid fallocate (unmap) for already received pages. fallocate syscall is required for remmaped shared memory, due to remmaping itself blocks ioctl(UFFDIO_COPY, ioctl in this case will end with EEXIT error (struct page is exists after remmap). Bitmap is placed into RAMBlock as another postcopy/precopy related bitmaps. Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Signed-off-by: Alexey Perevalov Signed-off-by: Juan Quintela --- include/exec/ram_addr.h | 10 ++++++++++ migration/postcopy-ram.c | 17 ++++++++++++----- migration/ram.c | 40 ++++++++++++++++++++++++++++++++++++++++ migration/ram.h | 5 +++++ 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index d017639f7e..6cbc02aa0f 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -47,6 +47,8 @@ struct RAMBlock { * of the postcopy phase */ unsigned long *unsentmap; + /* bitmap of already received pages in postcopy */ + unsigned long *receivedmap; }; =20 static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset) @@ -60,6 +62,14 @@ static inline void *ramblock_ptr(RAMBlock *block, ram_ad= dr_t offset) return (char *)block->host + offset; } =20 +static inline unsigned long int ramblock_recv_bitmap_offset(void *host_add= r, + RAMBlock *rb) +{ + uint64_t host_addr_offset =3D + (uint64_t)(uintptr_t)(host_addr - (void *)rb->host); + return host_addr_offset >> TARGET_PAGE_BITS; +} + long qemu_getrampagesize(void); unsigned long last_ram_page(void); RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 8bf6432567..bec6c2c66b 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -642,22 +642,28 @@ int postcopy_ram_enable_notify(MigrationIncomingState= *mis) } =20 static int qemu_ufd_copy_ioctl(int userfault_fd, void *host_addr, - void *from_addr, uint64_t pagesize) + void *from_addr, uint64_t pagesize, RAMBloc= k *rb) { + int ret; if (from_addr) { struct uffdio_copy copy_struct; copy_struct.dst =3D (uint64_t)(uintptr_t)host_addr; copy_struct.src =3D (uint64_t)(uintptr_t)from_addr; copy_struct.len =3D pagesize; copy_struct.mode =3D 0; - return ioctl(userfault_fd, UFFDIO_COPY, ©_struct); + ret =3D ioctl(userfault_fd, UFFDIO_COPY, ©_struct); } else { struct uffdio_zeropage zero_struct; zero_struct.range.start =3D (uint64_t)(uintptr_t)host_addr; zero_struct.range.len =3D pagesize; zero_struct.mode =3D 0; - return ioctl(userfault_fd, UFFDIO_ZEROPAGE, &zero_struct); + ret =3D ioctl(userfault_fd, UFFDIO_ZEROPAGE, &zero_struct); } + if (!ret) { + ramblock_recv_bitmap_set_range(rb, host_addr, + pagesize / qemu_target_page_size()); + } + return ret; } =20 /* @@ -674,7 +680,7 @@ int postcopy_place_page(MigrationIncomingState *mis, vo= id *host, void *from, * which would be slightly cheaper, but we'd have to be careful * of the order of updating our page state. */ - if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, from, pagesize)) { + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, from, pagesize, rb)) { int e =3D errno; error_report("%s: %s copy host: %p from: %p (size: %zd)", __func__, strerror(e), host, from, pagesize); @@ -696,7 +702,8 @@ int postcopy_place_page_zero(MigrationIncomingState *mi= s, void *host, trace_postcopy_place_page_zero(host); =20 if (qemu_ram_pagesize(rb) =3D=3D getpagesize()) { - if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, getpagesize= ())) { + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, getpagesize= (), + rb)) { int e =3D errno; error_report("%s: %s zero host: %p", __func__, strerror(e), host); diff --git a/migration/ram.c b/migration/ram.c index bd4fc5ceb4..7f6327f708 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -45,6 +45,7 @@ #include "qapi/qmp/qerror.h" #include "trace.h" #include "exec/ram_addr.h" +#include "exec/target_page.h" #include "qemu/rcu_queue.h" #include "migration/colo.h" #include "migration/block.h" @@ -158,6 +159,35 @@ out: return ret; } =20 +static void ramblock_recv_map_init(void) +{ + RAMBlock *rb; + + RAMBLOCK_FOREACH(rb) { + assert(!rb->receivedmap); + rb->receivedmap =3D bitmap_new(rb->max_length >> qemu_target_page_= bits()); + } +} + +int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr) +{ + return test_bit(ramblock_recv_bitmap_offset(host_addr, rb), + rb->receivedmap); +} + +void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr) +{ + set_bit_atomic(ramblock_recv_bitmap_offset(host_addr, rb), rb->receive= dmap); +} + +void ramblock_recv_bitmap_set_range(RAMBlock *rb, void *host_addr, + size_t nr) +{ + bitmap_set_atomic(rb->receivedmap, + ramblock_recv_bitmap_offset(host_addr, rb), + nr); +} + /* * An outstanding page request, on the source, having been received * and queued @@ -2021,6 +2051,8 @@ int ram_discard_range(const char *rbname, uint64_t st= art, size_t length) goto err; } =20 + bitmap_clear(rb->receivedmap, start >> qemu_target_page_bits(), + length >> qemu_target_page_bits()); ret =3D ram_block_discard_range(rb, start, length); =20 err: @@ -2607,13 +2639,20 @@ static int ram_load_setup(QEMUFile *f, void *opaque) { xbzrle_load_setup(); compress_threads_load_setup(); + ramblock_recv_map_init(); return 0; } =20 static int ram_load_cleanup(void *opaque) { + RAMBlock *rb; xbzrle_load_cleanup(); compress_threads_load_cleanup(); + + RAMBLOCK_FOREACH(rb) { + g_free(rb->receivedmap); + rb->receivedmap =3D NULL; + } return 0; } =20 @@ -2828,6 +2867,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) ret =3D -EINVAL; break; } + ramblock_recv_bitmap_set(block, host); trace_ram_load_loop(block->idstr, (uint64_t)addr, flags, host); } =20 diff --git a/migration/ram.h b/migration/ram.h index 511b3dc582..f9f7eef894 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -57,4 +57,9 @@ int ram_discard_range(const char *block_name, uint64_t st= art, size_t length); int ram_postcopy_incoming_init(MigrationIncomingState *mis); =20 void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); + +int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr); +void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr); +void ramblock_recv_bitmap_set_range(RAMBlock *rb, void *host_addr, size_t = nr); + #endif --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775690002845.9032355872855; Mon, 23 Oct 2017 09:21:30 -0700 (PDT) Received: from localhost ([::1]:39558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fTY-0007UG-EV for importer@patchew.org; Mon, 23 Oct 2017 12:21:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHg-0005zi-Ch for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHe-0000ea-Ly for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45148) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHe-0000dd-Fe for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:08:58 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96750BBD8 for ; Mon, 23 Oct 2017 16:08:57 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAF9A78DF4; Mon, 23 Oct 2017 16:08:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96750BBD8 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:07:59 +0200 Message-Id: <20171023160800.20540-21-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 23 Oct 2017 16:08:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 20/21] qapi: Fix grammar in x-multifd-page-count descriptions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reported-by: Eric Blake Signed-off-by: Juan Quintela --- qapi/migration.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 272f191551..6ae866e1aa 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -480,7 +480,7 @@ # number of sockets used for migration. The # default value is 2 (since 2.11) # -# @x-multifd-page-count: Number of pages sent together to a thread +# @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # # Since: 2.4 @@ -551,7 +551,7 @@ # number of sockets used for migration. The # default value is 2 (since 2.11) # -# @x-multifd-page-count: Number of pages sent together to a thread +# @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # # Since: 2.4 @@ -647,7 +647,7 @@ # number of sockets used for migration. # The default value is 2 (since 2.11) # -# @x-multifd-page-count: Number of pages sent together to a thread +# @x-multifd-page-count: Number of pages sent together to a thread. # The default value is 16 (since 2.11) # # Since: 2.4 --=20 2.13.6 From nobody Thu May 2 03:30:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508775788145151.21383878910444; Mon, 23 Oct 2017 09:23:08 -0700 (PDT) Received: from localhost ([::1]:39571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fVJ-0000Jq-2k for importer@patchew.org; Mon, 23 Oct 2017 12:23:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6fHh-00060x-Ku for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6fHg-0000ga-H5 for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38284) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e6fHg-0000fd-8M for qemu-devel@nongnu.org; Mon, 23 Oct 2017 12:09:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C06B5D9EA for ; Mon, 23 Oct 2017 16:08:59 +0000 (UTC) Received: from secure.mitica (ovpn-116-236.ams2.redhat.com [10.36.116.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBFC360E3B; Mon, 23 Oct 2017 16:08:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6C06B5D9EA Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 23 Oct 2017 18:08:00 +0200 Message-Id: <20171023160800.20540-22-quintela@redhat.com> In-Reply-To: <20171023160800.20540-1-quintela@redhat.com> References: <20171023160800.20540-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 23 Oct 2017 16:08:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 21/21] migration: Improve migration thread error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We now report errors also when we finish migration, not only on info migrate. We plan to use this error from several places, and we want the first error to happen to win, so we add an mutex to order it. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 19 ++++++++++++++++--- migration/migration.h | 7 ++++++- migration/tls.c | 1 - 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index a058f8b46d..62761d5705 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1084,19 +1084,30 @@ static void migrate_fd_cleanup(void *opaque) MIGRATION_STATUS_CANCELLED); } =20 + if (s->error) { + /* It is used on info migrate. We can't free it */ + error_report_err(error_copy(s->error)); + } notifier_list_notify(&migration_state_notifiers, s); block_cleanup_parameters(s); } =20 +void migrate_set_error(MigrationState *s, const Error *error) +{ + qemu_mutex_lock(&s->error_mutex); + if (!s->error) { + s->error =3D error_copy(error); + } + qemu_mutex_unlock(&s->error_mutex); +} + void migrate_fd_error(MigrationState *s, const Error *error) { trace_migrate_fd_error(error_get_pretty(error)); assert(s->to_dst_file =3D=3D NULL); migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); - if (!s->error) { - s->error =3D error_copy(error); - } + migrate_set_error(s, error); notifier_list_notify(&migration_state_notifiers, s); block_cleanup_parameters(s); } @@ -2427,6 +2438,7 @@ static void migration_instance_finalize(Object *obj) MigrationState *ms =3D MIGRATION_OBJ(obj); MigrationParameters *params =3D &ms->parameters; =20 + qemu_mutex_destroy(&ms->error_mutex); g_free(params->tls_hostname); g_free(params->tls_creds); qemu_sem_destroy(&ms->pause_sem); @@ -2441,6 +2453,7 @@ static void migration_instance_init(Object *obj) ms->xbzrle_cache_size =3D DEFAULT_MIGRATE_CACHE_SIZE; ms->mbps =3D -1; qemu_sem_init(&ms->pause_sem, 0); + qemu_mutex_init(&ms->error_mutex); =20 params->tls_hostname =3D g_strdup(""); params->tls_creds =3D g_strdup(""); diff --git a/migration/migration.h b/migration/migration.h index cd988a99b9..8ccdd7a577 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -132,8 +132,12 @@ struct MigrationState int64_t colo_checkpoint_time; QEMUTimer *colo_delay_timer; =20 - /* The last error that occurred */ + /* The first error that has occurred. + We used the mutex to be able to return the 1st error message */ Error *error; + /* mutex to protect errp */ + QemuMutex error_mutex; + /* Do we have to clean up -b/-i from old migrate parameters */ /* This feature is deprecated and will be removed */ bool must_remove_block_options; @@ -162,6 +166,7 @@ bool migration_has_all_channels(void); =20 uint64_t migrate_max_downtime(void); =20 +void migrate_set_error(MigrationState *s, const Error *error); void migrate_fd_error(MigrationState *s, const Error *error); =20 void migrate_fd_connect(MigrationState *s); diff --git a/migration/tls.c b/migration/tls.c index 596e8790bd..026a008667 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -119,7 +119,6 @@ static void migration_tls_outgoing_handshake(QIOTask *t= ask, if (qio_task_propagate_error(task, &err)) { trace_migration_tls_outgoing_handshake_error(error_get_pretty(err)= ); migrate_fd_error(s, err); - error_free(err); } else { trace_migration_tls_outgoing_handshake_complete(); migration_channel_connect(s, ioc, NULL); --=20 2.13.6