From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579783713; cv=none; d=zohomail.com; s=zohoarc; b=cgd12FuHoNN6Ye3QqCy+rkTaoY8dBNrmWGJ0u5KEzRim5dzzEaW8lMfF6g3t+7uvEdXIqgYtwiyjdEeTBaIVZLhH4Cj4Qn7VFerjjX6uvuudiEMtQ2vzbW29IW7seus85c3ioaQoUyhesHjPS+ZemXmVANz7kC2JIPmDZSzU7hw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579783713; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3bpc7h+vgWmBBF1bWkDQbQnMseD5ZrIS6bw9UBUOoPs=; b=PT9eCqr+ICA5zB93F7URbuKGPU7B58YpjJW6yNofW3jKfb+QqFvd0Xk5MiC09/W4utWADAX4lMMxgnmLlJDnkXTTcrTdy7L/IEi8WV9JXZqf0j76fUXk/fJ44rVZ1FeBcnB7EqmNJh6y1XaHQb5c4Qf3e0znjIkF2TeGDYkY7Js= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579783713042496.0768959626363; Thu, 23 Jan 2020 04:48:33 -0800 (PST) Received: from localhost ([::1]:56512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iubuR-0003ez-8k for importer@patchew.org; Thu, 23 Jan 2020 07:48:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39838) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8E-0001CT-1m for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8C-0004aN-FW for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:41 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:48000 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8C-0004Zf-C8 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-GKa-jK5cMguJIZKNaJnpMg-1; Thu, 23 Jan 2020 06:58:38 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 990528010C5 for ; Thu, 23 Jan 2020 11:58:37 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 500C619C69; Thu, 23 Jan 2020 11:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3bpc7h+vgWmBBF1bWkDQbQnMseD5ZrIS6bw9UBUOoPs=; b=LJeMlE+Wu7LAQksiNXPzdeFxZrMgORLyHawhZQEaBzd7T/pbmBZ5MQz3Te/D+CDakPUjtI OqAmJtDjnPi7i1WVguSwX87nQZVDMBwA9YSzhtDyCI50MVK3DGkVNoAZDJ95UH0/hEbz0c rZCUM3yYpMbSfXm5xRRn+J9TlVEleoQ= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 01/21] migration-test: Use g_free() instead of free() Date: Thu, 23 Jan 2020 12:58:11 +0100 Message-Id: <20200123115831.36842-2-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: GKa-jK5cMguJIZKNaJnpMg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth --- tests/qtest/migration-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 26e2e77289..b6a74a05ce 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1291,7 +1291,7 @@ static void test_multifd_tcp(void) wait_for_serial("dest_serial"); wait_for_migration_complete(from); test_migrate_end(from, to, true); - free(uri); + g_free(uri); } =20 int main(int argc, char **argv) --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579783874; cv=none; d=zohomail.com; s=zohoarc; b=kpcHT8dJi4lKOb9gxhb7u8nugUaOs0ord6VKBVqhGutyKJE3H1bdbYA1jtv75cpj5kPm8V2YW3SAK7XlnsUijU5GsFSeNia2PA/L59exrCRaatnFZPDjUVxg+H/zbs+UXyYi7RH0ISmD3PK6OWZa+Xi2CEBnA45AKq4fAOFef00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579783874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0XLEsLYuEFTegFIRqqZZE8oFcNpiNrP2fq/YbTYyWmM=; b=JrNRtIHWK7bvMePA94uuI4wu7zruLNzwWLw/PwjQLzMNjGHfwgl5HSGzXd+l1nu4oKwCQQ/DgnrYZagqLx3UOBnwQlQeVgZTiZzw41IpdCm5vZspk91wu4N/3gaKyhJWGti1fT9JxSrlMTbWa7djmOFqyasyK5Q7tCXbONpsOJ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157978387451975.67209627829959; Thu, 23 Jan 2020 04:51:14 -0800 (PST) Received: from localhost ([::1]:56548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iubx2-0006vo-N0 for importer@patchew.org; Thu, 23 Jan 2020 07:51:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39864) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8G-0001Fe-4O for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8E-0004c8-Vv for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:43 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23041 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8E-0004bz-Qs for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:42 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-193-j3IGRVP7OZO3OH9N1gPBQg-1; Thu, 23 Jan 2020 06:58:41 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34F80800D5A for ; Thu, 23 Jan 2020 11:58:40 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBC2119C69; Thu, 23 Jan 2020 11:58:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0XLEsLYuEFTegFIRqqZZE8oFcNpiNrP2fq/YbTYyWmM=; b=Ecdi067Svzn2rWgtsozuUyX8RlzBa1lXVaDpFNCK5KlnxcXGTsiJaplLgOkM04GleaKzE+ gbmAnhTYNhsrk+HgtlZe+iJBW3F0KMBGnFgUaaB+N0lokuG5HEhdv9MMWzidpNL+X6FNU7 oh/pQRemeZSDC4Dh2XNNYz7GBDHwwmU= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 02/21] multifd: Make sure that we don't do any IO after an error Date: Thu, 23 Jan 2020 12:58:12 +0100 Message-Id: <20200123115831.36842-3-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: j3IGRVP7OZO3OH9N1gPBQg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index d2208b5534..f95d656c26 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3445,7 +3445,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) { RAMState **temp =3D opaque; RAMState *rs =3D *temp; - int ret; + int ret =3D 0; int i; int64_t t0; int done =3D 0; @@ -3524,12 +3524,14 @@ static int ram_save_iterate(QEMUFile *f, void *opaq= ue) ram_control_after_iterate(f, RAM_CONTROL_ROUND); =20 out: - multifd_send_sync_main(rs); - qemu_put_be64(f, RAM_SAVE_FLAG_EOS); - qemu_fflush(f); - ram_counters.transferred +=3D 8; + if (ret >=3D 0) { + multifd_send_sync_main(rs); + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + qemu_fflush(f); + ram_counters.transferred +=3D 8; =20 - ret =3D qemu_file_get_error(f); + ret =3D qemu_file_get_error(f); + } if (ret < 0) { return ret; } @@ -3581,9 +3583,11 @@ static int ram_save_complete(QEMUFile *f, void *opaq= ue) ram_control_after_iterate(f, RAM_CONTROL_FINISH); } =20 - multifd_send_sync_main(rs); - qemu_put_be64(f, RAM_SAVE_FLAG_EOS); - qemu_fflush(f); + if (ret >=3D 0) { + multifd_send_sync_main(rs); + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + qemu_fflush(f); + } =20 return ret; } --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579783894; cv=none; d=zohomail.com; s=zohoarc; b=MusmNoavr9YPPfKC7Q8NRbSbBO5sYW/V3PvnhniV1EC6DQYLNEJPLSJe2hoVS+mL4lEAfZBGfHmQkMz9KwTy8CMt4K2iJTb4YkkhGJCULrx+0Fd1gbZdIP1NR3nQrmKzwV0hkFLdkhwHrg4H+Hh8A46mH1U6xwO//MWk2p+NRrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579783894; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NT34jybCSxqqhb9E0i6CiN4hh1ID9VIMQpr6EXCYNx4=; b=Db1+DMmpzqIlR+bEJ/wi/hZRpCh0PTE27NB5aBw7VAvtWSKlxqQUdfn9D9uI3gvg9OKBmTV22Lrtdl9XGazSW9OPOaZ/1ILEBU2CEms/vfsjOr99l96RPIYYA5Aes+H+AjsMUei5AvJo9IGolvkIn666NwEe66KkPUkrU9llccM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579783894061896.8503657542631; Thu, 23 Jan 2020 04:51:34 -0800 (PST) Received: from localhost ([::1]:56552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iubxM-0007OY-93 for importer@patchew.org; Thu, 23 Jan 2020 07:51:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39885) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8I-0001Jz-Pp for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8H-0004dv-M8 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:46 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42922 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8H-0004do-J8 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:45 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-151-39Zj0z7WOx6Viq4BWOrjXg-1; Thu, 23 Jan 2020 06:58:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB8C0107ACC5 for ; Thu, 23 Jan 2020 11:58:42 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89EE019C69; Thu, 23 Jan 2020 11:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NT34jybCSxqqhb9E0i6CiN4hh1ID9VIMQpr6EXCYNx4=; b=EpM4l9rXICprVoPs1xTzHU2+vNhKlmEmnDal/Pvw3YjJERaR3MYnsqjW5OfzZlFGScneQN NgNAA8fBvkLzBGseYfRDnR/o9TKKFvjY0VlFPwYHGBAfml4dxPQFcM1pwLtVO3uii8/kb4 qsDBG/xx3sPcWzzQnMK46v9zDnFagMQ= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 03/21] qemu-file: Don't do IO after shutdown Date: Thu, 23 Jan 2020 12:58:13 +0100 Message-Id: <20200123115831.36842-4-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 39Zj0z7WOx6Viq4BWOrjXg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Be sure that we are not doing neither read/write after shutdown of the QEMUFile. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- Set error in case that there is none (dave) --- migration/qemu-file.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 26fb25ddc1..bbb2b63927 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -53,6 +53,8 @@ struct QEMUFile { =20 int last_error; Error *last_error_obj; + /* has the file has been shutdown */ + bool shutdown; }; =20 /* @@ -61,10 +63,18 @@ struct QEMUFile { */ int qemu_file_shutdown(QEMUFile *f) { + int ret; + + f->shutdown =3D true; if (!f->ops->shut_down) { return -ENOSYS; } - return f->ops->shut_down(f->opaque, true, true, NULL); + ret =3D f->ops->shut_down(f->opaque, true, true, NULL); + + if (!f->last_error) { + qemu_file_set_error(f, -EIO); + } + return ret; } =20 /* @@ -214,6 +224,9 @@ void qemu_fflush(QEMUFile *f) return; } =20 + if (f->shutdown) { + return; + } if (f->iovcnt > 0) { expect =3D iov_size(f->iov, f->iovcnt); ret =3D f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, f->pos, @@ -328,6 +341,10 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) f->buf_index =3D 0; f->buf_size =3D pending; =20 + if (f->shutdown) { + return 0; + } + len =3D f->ops->get_buffer(f->opaque, f->buf + pending, f->pos, IO_BUF_SIZE - pending, &local_error); if (len > 0) { @@ -642,6 +659,9 @@ int64_t qemu_ftell(QEMUFile *f) =20 int qemu_file_rate_limit(QEMUFile *f) { + if (f->shutdown) { + return 1; + } if (qemu_file_get_error(f)) { return 1; } --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579783058; cv=none; d=zohomail.com; s=zohoarc; b=kpZHVOBbxd6xNMGw2tZLQBtTuIB8PvhDw+uKheBQ5754Se5DJr3ZUo2616Hx+AazBEA0cok4lRdXLwoqXwkTCCA1nCK3WdZqepCZgoQCYZiWNzUodgMWUjsyV3EN/GdAsdbUy3ffmvGmrpNm6UvhKyT0w5caUyhjv4hXW10jq8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579783058; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iwZEYBBew8lo3lmUNJWPGzVep9D+rbOYQ2y34LZoLwU=; b=bsKPzIgyLovkrfU7+7IkerVVUfg/wMdlKArvJLrXLAtVgKbo+IDglL2Uou3z3JswyREQsuopFLSTXDDd93wa2yAhcL0qzua992ydml+J97dI8twyTekIzHBilhGMlDS9c2gEMda1vMqJAMpKT5ZpYzXpBIHE7Jy3Ku8zFvaycOs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579783058167554.3321061574161; Thu, 23 Jan 2020 04:37:38 -0800 (PST) Received: from localhost ([::1]:56318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iubjs-0006uQ-9U for importer@patchew.org; Thu, 23 Jan 2020 07:37:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39903) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8M-0001PE-8P for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8K-0004fW-Vi for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:50 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28456 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8K-0004fN-SF for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-402-DkoFpFiLPVS2z_mbH79HAw-1; Thu, 23 Jan 2020 06:58:46 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66941477 for ; Thu, 23 Jan 2020 11:58:45 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A20219C69; Thu, 23 Jan 2020 11:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iwZEYBBew8lo3lmUNJWPGzVep9D+rbOYQ2y34LZoLwU=; b=K1tokhBWxs+Tn8YYxN+4fb9QVFPRYi3yZY5MFHGz7cJ3RCeHBD7av9SzwhVH/ggZ0jfUIt muNK/CuctMj+8J9Tg30XbPc4YcDh3GHeAVT7DiTXUvLdHGM5/AOM4W/thbr0eanfLsNZXs cHg/GOhC5/pPdM1Asw0td1muMffv7aw= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 04/21] migration-test: Make sure that multifd and cancel works Date: Thu, 23 Jan 2020 12:58:14 +0100 Message-Id: <20200123115831.36842-5-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: DkoFpFiLPVS2z_mbH79HAw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Test that this sequerce works: - launch source - launch target - start migration - cancel migration - relaunch target - do migration again Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- - Wait for 1st trhead to move to cancelled before launching second migration - Add 'to2' parameter to diferentiate 1st and second target. - Use g_free() instead of free() --- tests/qtest/migration-test.c | 112 ++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index b6a74a05ce..cf27ebbc9d 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -424,6 +424,14 @@ static void migrate_recover(QTestState *who, const cha= r *uri) qobject_unref(rsp); } =20 +static void migrate_cancel(QTestState *who) +{ + QDict *rsp; + + rsp =3D wait_command(who, "{ 'execute': 'migrate_cancel' }"); + qobject_unref(rsp); +} + static void migrate_set_capability(QTestState *who, const char *capability, bool value) { @@ -456,6 +464,8 @@ static void migrate_postcopy_start(QTestState *from, QT= estState *to) typedef struct { bool hide_stderr; bool use_shmem; + /* only launch the target process */ + bool only_target; char *opts_source; char *opts_target; } MigrateStart; @@ -571,7 +581,9 @@ static int test_migrate_start(QTestState **from, QTestS= tate **to, arch_source, shmem_opts, args->opts_sourc= e, ignore_stderr); g_free(arch_source); - *from =3D qtest_init(cmd_source); + if (!args->only_target) { + *from =3D qtest_init(cmd_source); + } g_free(cmd_source); =20 cmd_target =3D g_strdup_printf("-accel kvm -accel tcg%s%s " @@ -1294,6 +1306,103 @@ static void test_multifd_tcp(void) g_free(uri); } =20 +/* + * This test does: + * source target + * migrate_incoming + * migrate + * migrate_cancel + * launch another target + * migrate + * + * And see that it works + */ + +static void test_multifd_tcp_cancel(void) +{ + MigrateStart *args =3D migrate_start_new(); + QTestState *from, *to, *to2; + QDict *rsp; + char *uri; + + args->hide_stderr =3D true; + + if (test_migrate_start(&from, &to, "defer", args)) { + return; + } + + /* + * We want to pick a speed slow enough that the test completes + * quickly, but that it doesn't complete precopy even on a slow + * machine, so also set the downtime. + */ + /* 1 ms should make it not converge*/ + migrate_set_parameter_int(from, "downtime-limit", 1); + /* 300MB/s */ + migrate_set_parameter_int(from, "max-bandwidth", 30000000); + + migrate_set_parameter_int(from, "multifd-channels", 16); + migrate_set_parameter_int(to, "multifd-channels", 16); + + migrate_set_capability(from, "multifd", "true"); + migrate_set_capability(to, "multifd", "true"); + + /* Start incoming migration from the 1st socket */ + rsp =3D wait_command(to, "{ 'execute': 'migrate-incoming'," + " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}"); + qobject_unref(rsp); + + /* Wait for the first serial output from the source */ + wait_for_serial("src_serial"); + + uri =3D migrate_get_socket_address(to, "socket-address"); + + migrate_qmp(from, uri, "{}"); + + wait_for_migration_pass(from); + + migrate_cancel(from); + + args =3D migrate_start_new(); + args->only_target =3D true; + + if (test_migrate_start(&from, &to2, "defer", args)) { + return; + } + + migrate_set_parameter_int(to2, "multifd-channels", 16); + + migrate_set_capability(to2, "multifd", "true"); + + /* Start incoming migration from the 1st socket */ + rsp =3D wait_command(to2, "{ 'execute': 'migrate-incoming'," + " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}"= ); + qobject_unref(rsp); + + uri =3D migrate_get_socket_address(to2, "socket-address"); + + wait_for_migration_status(from, "cancelled", NULL); + + /* 300ms it should converge */ + migrate_set_parameter_int(from, "downtime-limit", 300); + /* 1GB/s */ + migrate_set_parameter_int(from, "max-bandwidth", 1000000000); + + migrate_qmp(from, uri, "{}"); + + wait_for_migration_pass(from); + + if (!got_stop) { + qtest_qmp_eventwait(from, "STOP"); + } + qtest_qmp_eventwait(to2, "RESUME"); + + wait_for_serial("dest_serial"); + wait_for_migration_complete(from); + test_migrate_end(from, to2, true); + g_free(uri); +} + int main(int argc, char **argv) { char template[] =3D "/tmp/migration-test-XXXXXX"; @@ -1359,6 +1468,7 @@ int main(int argc, char **argv) =20 qtest_add_func("/migration/auto_converge", test_migrate_auto_converge); qtest_add_func("/migration/multifd/tcp", test_multifd_tcp); + qtest_add_func("/migration/multifd/tcp/cancel", test_multifd_tcp_cance= l); =20 ret =3D g_test_run(); =20 --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579785874; cv=none; d=zohomail.com; s=zohoarc; b=ZLwurbv5LgdfZ2ToO9HsJy3M2AC+ER3ZlkCbZFPtSrGCaVp3S9RWW2+37sxnFjgR53sTm/AkYg9G7X6/t4y8iFi2s4UKs9n8JHiyY4QEVasKxz8M0V3UnwS5cyn1D/QsYXKh1t+uCkkqNfMKoP30dyTFh8PsdBbJTKcKa5JjkYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579785874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=++FvK0c0O8G0FXeU4NNIduuz4jqnbR+m4cIilJeA5Vw=; b=XvBNNdZIP52QlbuaTkSfN9hEOVIY7IXpZnAKXVwawC6HoLMMdRkIQXlRonU0KrXU0JJFsJFHD4FkZr+1QbixWEoBYV25JITf3DWPg+DRghQBZaRdzXYNVIn8AswWHrQL1DFrFpaUV18+KTk1lcCX0okFaSyuuuUTjNAFj0VBpFA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579785874503666.8419990922811; Thu, 23 Jan 2020 05:24:34 -0800 (PST) Received: from localhost ([::1]:56986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucTI-0007NL-Qa for importer@patchew.org; Thu, 23 Jan 2020 08:24:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39933) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8Q-0001V7-3L for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8O-0004hk-Qx for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:53 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:45677 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8O-0004ha-OP for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:52 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-271-FKfEMo5-M6O5iKQ-YjiltA-1; Thu, 23 Jan 2020 06:58:49 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E55E477 for ; Thu, 23 Jan 2020 11:58:48 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBD7419C69; Thu, 23 Jan 2020 11:58:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=++FvK0c0O8G0FXeU4NNIduuz4jqnbR+m4cIilJeA5Vw=; b=Vgl6g2L+Tl2FADo7aMU9uR2KKchiBzY4k0VllhbpZKogG+Z8UWG5qWxOtswQ5gc2xnlLyW rr7Wh90txxuvERnI3DsAQAQWAMH3uBecyz1RGWFW4EAcpQ6m/QdJhVQv9j3dEQcqK/Q9b4 xkDy1mpddc/HxH0YTDsqyJfsn9vKutI= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 05/21] migration: Create migration_is_running() Date: Thu, 23 Jan 2020 12:58:15 +0100 Message-Id: <20200123115831.36842-6-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: FKfEMo5-M6O5iKQ-YjiltA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function returns if we are in the middle of a migration. It is like migration_is_setup_or_active() with CANCELLING and COLO. Adapt all calers that are needed. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 29 ++++++++++++++++++++++++----- migration/migration.h | 1 + migration/savevm.c | 4 +--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 990bff00c0..1fb0aab44d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -829,6 +829,27 @@ bool migration_is_setup_or_active(int state) } } =20 +bool migration_is_running(int state) +{ + switch (state) { + case MIGRATION_STATUS_ACTIVE: + case MIGRATION_STATUS_POSTCOPY_ACTIVE: + case MIGRATION_STATUS_POSTCOPY_PAUSED: + case MIGRATION_STATUS_POSTCOPY_RECOVER: + case MIGRATION_STATUS_SETUP: + case MIGRATION_STATUS_PRE_SWITCHOVER: + case MIGRATION_STATUS_DEVICE: + case MIGRATION_STATUS_WAIT_UNPLUG: + case MIGRATION_STATUS_CANCELLING: + case MIGRATION_STATUS_COLO: + return true; + + default: + return false; + + } +} + static void populate_time_info(MigrationInfo *info, MigrationState *s) { info->has_status =3D true; @@ -1077,7 +1098,7 @@ void qmp_migrate_set_capabilities(MigrationCapability= StatusList *params, MigrationCapabilityStatusList *cap; bool cap_list[MIGRATION_CAPABILITY__MAX]; =20 - if (migration_is_setup_or_active(s->state)) { + if (migration_is_running(s->state)) { error_setg(errp, QERR_MIGRATION_ACTIVE); return; } @@ -1590,7 +1611,7 @@ static void migrate_fd_cancel(MigrationState *s) =20 do { old_state =3D s->state; - if (!migration_is_setup_or_active(old_state)) { + if (!migration_is_running(old_state)) { break; } /* If the migration is paused, kick it out of the pause */ @@ -1888,9 +1909,7 @@ static bool migrate_prepare(MigrationState *s, bool b= lk, bool blk_inc, return true; } =20 - if (migration_is_setup_or_active(s->state) || - s->state =3D=3D MIGRATION_STATUS_CANCELLING || - s->state =3D=3D MIGRATION_STATUS_COLO) { + if (migration_is_running(s->state)) { error_setg(errp, QERR_MIGRATION_ACTIVE); return false; } diff --git a/migration/migration.h b/migration/migration.h index aa9ff6f27b..44b1d56929 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -279,6 +279,7 @@ void migrate_fd_error(MigrationState *s, const Error *e= rror); void migrate_fd_connect(MigrationState *s, Error *error_in); =20 bool migration_is_setup_or_active(int state); +bool migration_is_running(int state); =20 void migrate_init(MigrationState *s); bool migration_is_blocked(Error **errp); diff --git a/migration/savevm.c b/migration/savevm.c index adfdca26ac..f19cb9ec7a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1531,9 +1531,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **err= p) MigrationState *ms =3D migrate_get_current(); MigrationStatus status; =20 - if (migration_is_setup_or_active(ms->state) || - ms->state =3D=3D MIGRATION_STATUS_CANCELLING || - ms->state =3D=3D MIGRATION_STATUS_COLO) { + if (migration_is_running(ms->state)) { error_setg(errp, QERR_MIGRATION_ACTIVE); return -EINVAL; } --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579786039; cv=none; d=zohomail.com; s=zohoarc; b=PgXPTVZ4rLYYCA9ZFeH4zJtT3VTaj/bMhvaSjweep/X3vnFLtNIc36Hg97Odr/i1Oa2Obx3kgXDfb27BxriRG+7B/C2IIHpJ/J+yQF65z2ncf82UzgsZJqID56vYchskdoyoAC0foXV/arSqMgk3j+G2yz03i+stpB/c6w6uoO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579786039; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rf2VEYyJOJZjJVikxnQmH9H9nlhYVMDgThLcvQrR3pM=; b=cgi8w/C3Z14qlxdHc8yjqWCP6ZPjYfPY7GiqCXJzHu/TdOuHFp5PFAgvix5l575IdH+OnQC49lMZrm/vOgcBIaYLh3+mEqfm8t1b0meatIvrp6CSEE+cMdjuF+hTTdfNKN8Hhpuj8GjPSaWR8SQcY4aVdbeumYTEJl2MG+geGvI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579786039688271.8355250645184; Thu, 23 Jan 2020 05:27:19 -0800 (PST) Received: from localhost ([::1]:57026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucVx-0002be-UV for importer@patchew.org; Thu, 23 Jan 2020 08:27:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39950) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8R-0001Wa-0j for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8P-0004iN-LA for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:32861 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8P-0004i8-HW for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-212-5EfQOpmqNTisB8v3MDeHGg-1; Thu, 23 Jan 2020 06:58:51 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B351F800D4C for ; Thu, 23 Jan 2020 11:58:50 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 663B019C69; Thu, 23 Jan 2020 11:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rf2VEYyJOJZjJVikxnQmH9H9nlhYVMDgThLcvQrR3pM=; b=MQEa+DtCGfa1Vds12zd9VntSqCe72UhLx7nhxa/jIP3Y1XpJv2AMBB4+o9GKDEmm99FSiE NItbfutyEdVdl9y9jlW+nyVbarVMftjgBxtiLoyVpOiyw/WS0yCXGlMvo7u9xaz3uNl5eL pht+S4plFiq7mR3h0wBQVIwWY/zL4Q0= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 06/21] migration: Don't send data if we have stopped Date: Thu, 23 Jan 2020 12:58:16 +0100 Message-Id: <20200123115831.36842-7-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 5EfQOpmqNTisB8v3MDeHGg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If we do a cancel, we got out without one error, but we can't do the rest of the output as in a normal situation. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index f95d656c26..3fd7fdffcf 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3524,7 +3524,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) ram_control_after_iterate(f, RAM_CONTROL_ROUND); =20 out: - if (ret >=3D 0) { + if (ret >=3D 0 + && migration_is_setup_or_active(migrate_get_current()->state)) { multifd_send_sync_main(rs); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); qemu_fflush(f); --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579783411; cv=none; d=zohomail.com; s=zohoarc; b=KJ8xd5JfqdZv+7Cy2RIGApHSb6HCM1BYm/MAu0piZ/CymWVqoZuT3v7S5YBFBqnOPu6Wi+HknjG2BkCELeZlXbwqZCeJwfugO8LB/QfVo6oEyxTdB6O8O+BPvzu7SN9v09XwqZNnQoURujtgFDZ5xOFEpPEosLmDnv5vjbC5vk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579783411; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3T1xZffyRw6zdagUvCqbkWto7+4QUJmQJMLUOjf9YKQ=; b=V75kxwBWhj1FXQ5w/MYTYsKuVl4cvcjzrG6vL9QSVrEqJ3XVZZOOui/9rcvjWoK5pt7eDAqqR35bDTcJXy0e53zmjHewebPmK+29LmignYjxTIbuLSU6t/ljdqj71Hlx/wvsnoZh+mKAZ3h4VEfiN6ffEN5vptW+xGCq+/oLwyo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579783411062925.0532125025738; Thu, 23 Jan 2020 04:43:31 -0800 (PST) Received: from localhost ([::1]:56408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iubpZ-0006O9-4J for importer@patchew.org; Thu, 23 Jan 2020 07:43:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39991) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8V-0001fr-MV for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8U-0004mk-HM for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:59 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:60376 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8U-0004mS-Do for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:58:58 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-wMtmairBM9mA6CtjlSV5UA-1; Thu, 23 Jan 2020 06:58:56 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C3572DB62 for ; Thu, 23 Jan 2020 11:58:55 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 149E119C70; Thu, 23 Jan 2020 11:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3T1xZffyRw6zdagUvCqbkWto7+4QUJmQJMLUOjf9YKQ=; b=OP4bTeMUq7IOlKYfSJ0TRuKHVtorhaHBmoexp9k2G9PLweXXtE0TiZfdB/uWHoVUHBKJpd arJdhmTSZZz7kSel01TGVHPT3I4/G4yW82izcdzGRVjJK/tMTDNL0tuQ9NsZfYhjS4l9vl mVeTsbRM7llXS9weOQx8jnJWFJj3HOs= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 07/21] migration: Make multifd_save_setup() get an Error parameter Date: Thu, 23 Jan 2020 12:58:17 +0100 Message-Id: <20200123115831.36842-8-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: wMtmairBM9mA6CtjlSV5UA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- We can't trust that error_in is not NULL. Create a local_error. --- migration/migration.c | 4 +++- migration/ram.c | 2 +- migration/ram.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 1fb0aab44d..7140d1e040 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3367,6 +3367,7 @@ static void *migration_thread(void *opaque) =20 void migrate_fd_connect(MigrationState *s, Error *error_in) { + Error *local_err =3D NULL; int64_t rate_limit; bool resume =3D s->state =3D=3D MIGRATION_STATUS_POSTCOPY_PAUSED; =20 @@ -3415,7 +3416,8 @@ void migrate_fd_connect(MigrationState *s, Error *err= or_in) return; } =20 - if (multifd_save_setup() !=3D 0) { + if (multifd_save_setup(&local_err) !=3D 0) { + error_report_err(local_err); migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); migrate_fd_cleanup(s); diff --git a/migration/ram.c b/migration/ram.c index 3fd7fdffcf..d537264ba5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1243,7 +1243,7 @@ static void multifd_new_send_channel_async(QIOTask *t= ask, gpointer opaque) } } =20 -int multifd_save_setup(void) +int multifd_save_setup(Error **errp) { int thread_count; uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); diff --git a/migration/ram.h b/migration/ram.h index bd0eee79b6..da22a417ea 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -41,7 +41,7 @@ int xbzrle_cache_resize(int64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); =20 -int multifd_save_setup(void); +int multifd_save_setup(Error **errp); void multifd_save_cleanup(void); int multifd_load_setup(void); int multifd_load_cleanup(Error **errp); --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579786215; cv=none; d=zohomail.com; s=zohoarc; b=SxqqpwtLIq+3ceEU4/ztNv5HAvHw7XV6M/JTsxWmRerfEXOZdiwPFHImsuzofW8LFu0Whd0u7vD3Mkgp5eYnlV+3Af3xEuzbeYHkxWaxvkkKWG8dAshZskN/y5h/XW7c1PKMyQX/ANwRFhGZcjOxZkWW5Igps78lO6kt0y+tq7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579786215; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qBOh6K2fzmI5EXbRTV+Sn6uqbXLRBp4QsUu5JfUEW/M=; b=SvEhqKebGf8szFm2T9rsrIGzUGBYakbF3nrljVHKBUaVgpw1a7UFHYvg5mboRSSyun1zdcmJtASMWmS0/Zc6fWtfA8symBA14pxMbUOO7py5UwtZRYV9r9vFjGzfik2kNzJQZL12dHiFwMaWX+/RJvRAxpRvRSbmxE7va1sbhgc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157978621598052.2317927272469; Thu, 23 Jan 2020 05:30:15 -0800 (PST) Received: from localhost ([::1]:57052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucYo-0006Pl-Eq for importer@patchew.org; Thu, 23 Jan 2020 08:30:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40082) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8b-0001oE-AM for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8Z-0004qU-U5 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:05 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:29146 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8Z-0004q4-Q4 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-PmIMtUZYODCoSLaYNh1LtA-1; Thu, 23 Jan 2020 06:59:01 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD70F18A6EC3 for ; Thu, 23 Jan 2020 11:59:00 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27B9028D14; Thu, 23 Jan 2020 11:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBOh6K2fzmI5EXbRTV+Sn6uqbXLRBp4QsUu5JfUEW/M=; b=NVZdHFLTIxVxGq2Khmc4al4cZdvAhzvrVYc/tZIsfHJYB055P18dmP/9bD5XAj5zc75PCe gfpkwwDEIXN4u7we2RtO88x/9nqxXzB0jphZQR5oln5X/7e1YE6kP1aTBBXddKu0raXGV7 IuytIlgS3EImG6Kj7z+Hs8fpxPBvh1k= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 08/21] migration: Make multifd_load_setup() get an Error parameter Date: Thu, 23 Jan 2020 12:58:18 +0100 Message-Id: <20200123115831.36842-9-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: PmIMtUZYODCoSLaYNh1LtA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We need to change the full chain to pass the Error parameter. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- Always use a local_err, and in case of error propagate/print it as needed. --- migration/migration.c | 35 +++++++++++++++++++++++++++++------ migration/migration.h | 2 +- migration/ram.c | 2 +- migration/ram.h | 2 +- migration/rdma.c | 2 +- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 7140d1e040..ef17b9f3f2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -518,13 +518,23 @@ fail: exit(EXIT_FAILURE); } =20 -static void migration_incoming_setup(QEMUFile *f) +/** + * @migration_incoming_setup: Setup incoming migration + * + * Returns 0 for no error or 1 for error + * + * @f: file for main migration channel + * @errp: where to put errors + */ +static int migration_incoming_setup(QEMUFile *f, Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); + Error *local_err =3D NULL; =20 - if (multifd_load_setup() !=3D 0) { + if (multifd_load_setup(&local_err) !=3D 0) { /* We haven't been able to create multifd threads nothing better to do */ + error_report_err(local_err); exit(EXIT_FAILURE); } =20 @@ -532,6 +542,7 @@ static void migration_incoming_setup(QEMUFile *f) mis->from_src_file =3D f; } qemu_file_set_blocking(f, false); + return 0; } =20 void migration_incoming_process(void) @@ -572,19 +583,27 @@ static bool postcopy_try_recover(QEMUFile *f) return false; } =20 -void migration_fd_process_incoming(QEMUFile *f) +void migration_fd_process_incoming(QEMUFile *f, Error **errp) { + Error *local_err =3D NULL; + if (postcopy_try_recover(f)) { return; } =20 - migration_incoming_setup(f); + if (migration_incoming_setup(f, &local_err)) { + if (local_err) { + error_propagate(errp, local_err); + } + return; + } migration_incoming_process(); } =20 void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); + Error *local_err =3D NULL; bool start_migration; =20 if (!mis->from_src_file) { @@ -596,7 +615,12 @@ void migration_ioc_process_incoming(QIOChannel *ioc, E= rror **errp) return; } =20 - migration_incoming_setup(f); + if (migration_incoming_setup(f, &local_err)) { + if (local_err) { + error_propagate(errp, local_err); + } + return; + } =20 /* * Common migration only needs one channel, so we can start @@ -604,7 +628,6 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp) */ start_migration =3D !migrate_use_multifd(); } else { - Error *local_err =3D NULL; /* Multiple connections */ assert(migrate_use_multifd()); start_migration =3D multifd_recv_new_channel(ioc, &local_err); diff --git a/migration/migration.h b/migration/migration.h index 44b1d56929..8473ddfc88 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -265,7 +265,7 @@ struct MigrationState =20 void migrate_set_state(int *state, int old_state, int new_state); =20 -void migration_fd_process_incoming(QEMUFile *f); +void migration_fd_process_incoming(QEMUFile *f, Error **errp); void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp); void migration_incoming_process(void); =20 diff --git a/migration/ram.c b/migration/ram.c index d537264ba5..125c6d0f60 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1463,7 +1463,7 @@ static void *multifd_recv_thread(void *opaque) return NULL; } =20 -int multifd_load_setup(void) +int multifd_load_setup(Error **errp) { int thread_count; uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); diff --git a/migration/ram.h b/migration/ram.h index da22a417ea..42be471d52 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -43,7 +43,7 @@ uint64_t ram_bytes_total(void); =20 int multifd_save_setup(Error **errp); void multifd_save_cleanup(void); -int multifd_load_setup(void); +int multifd_load_setup(Error **errp); int multifd_load_cleanup(Error **errp); bool multifd_recv_all_channels_created(void); bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp); diff --git a/migration/rdma.c b/migration/rdma.c index e241dcb992..2379b8345b 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -4004,7 +4004,7 @@ static void rdma_accept_incoming_migration(void *opaq= ue) } =20 rdma->migration_started_on_destination =3D 1; - migration_fd_process_incoming(f); + migration_fd_process_incoming(f, errp); } =20 void rdma_start_incoming_migration(const char *host_port, Error **errp) --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579784939; cv=none; d=zohomail.com; s=zohoarc; b=ctJKE1oqi4Ttz/nlNOKn76HPN1BTH/JYXzePhSnAHmU1+q05EZHkPl6cs2aS/PDUaZTndmVNLWtcp9O68P1meoc68HyICgX9Xz1FgyxdgwWQwiO48dn52eH8ZoNJ25OOO283O46YzOSIxjT44qXumV1PAXcUYEyr8IulH0V0cuc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579784939; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OMkXTWrXl1nIHDu6Pwtz6k1RxcJSxrnoNOMJSzgEYLI=; b=JUAlfA5NJRnyC2xctTKxO/zwDj555ygS9tiowy1u4VujSNxMj5Z6xgo7BTqUwevXpC1itNd6TcVGCzWYHr1w+dER9nRDvGFDhIFHvLHz6tuKftRlTS392dSQYUW4pb1gCYiQxw4dNhbmRYYCDjbX1HKsWbUDHviV0Zvvvda9+Pc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579784938997894.3284382995224; Thu, 23 Jan 2020 05:08:58 -0800 (PST) Received: from localhost ([::1]:56784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucED-0004Lv-8I for importer@patchew.org; Thu, 23 Jan 2020 08:08:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40149) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8i-0001uL-4I for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8g-0004uP-4t for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:12 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55884 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8f-0004tG-V8 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:10 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-422-rv6vBLUOMwu9DO3ctyYALw-1; Thu, 23 Jan 2020 06:59:06 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 610EE18A6ECF for ; Thu, 23 Jan 2020 11:59:05 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DEE219C69; Thu, 23 Jan 2020 11:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OMkXTWrXl1nIHDu6Pwtz6k1RxcJSxrnoNOMJSzgEYLI=; b=QVRb5x5OjN04KbV9aa7q5XpfVi2NCX+6cFAW2+zjYXXQ2ftOlkQ4mDI8V7uALI1n4lrLaH zLnnNYL9TOOSM7xnqDZPJop5aAxB5whq2d9GXrOZGAmUexRPQNbZG0gTgB3M4FfVpjLEdj GR9g99sJNIzH2wuHnoVlFLEQuowlIIo= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 09/21] migration: Add multifd-compress parameter Date: Thu, 23 Jan 2020 12:58:19 +0100 Message-Id: <20200123115831.36842-10-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: rv6vBLUOMwu9DO3ctyYALw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Markus Armbruster Reviewed-by: Dr. David Alan Gilbert --- Rename it to NONE Fix typos (dave) We don't need to chek values returned by visit_type_MultifdCompress (markus) Fix yet more typos (wei) --- hw/core/qdev-properties.c | 13 +++++++++++++ include/hw/qdev-properties.h | 3 +++ migration/migration.c | 13 +++++++++++++ monitor/hmp-cmds.c | 13 +++++++++++++ qapi/migration.json | 30 +++++++++++++++++++++++++++--- tests/qtest/migration-test.c | 14 ++++++++++---- 6 files changed, 79 insertions(+), 7 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 6ca7697599..ff6a752b19 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -8,6 +8,7 @@ #include "qapi/qmp/qerror.h" #include "qemu/ctype.h" #include "qemu/error-report.h" +#include "qapi/qapi-types-migration.h" #include "hw/block/block.h" #include "net/hub.h" #include "qapi/visitor.h" @@ -641,6 +642,18 @@ const PropertyInfo qdev_prop_fdc_drive_type =3D { .set_default_value =3D set_default_value_enum, }; =20 +/* --- MultifdCompress --- */ + +const PropertyInfo qdev_prop_multifd_compress =3D { + .name =3D "MultifdCompress", + .description =3D "multifd_compress values, " + "none", + .enum_table =3D &MultifdCompress_lookup, + .get =3D get_enum, + .set =3D set_enum, + .set_default_value =3D set_default_value_enum, +}; + /* --- pci address --- */ =20 /* diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index a90a9cec80..72f21a74c6 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -20,6 +20,7 @@ extern const PropertyInfo qdev_prop_chr; extern const PropertyInfo qdev_prop_tpm; extern const PropertyInfo qdev_prop_macaddr; extern const PropertyInfo qdev_prop_on_off_auto; +extern const PropertyInfo qdev_prop_multifd_compress; extern const PropertyInfo qdev_prop_losttickpolicy; extern const PropertyInfo qdev_prop_blockdev_on_error; extern const PropertyInfo qdev_prop_bios_chs_trans; @@ -184,6 +185,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width; DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto) +#define DEFINE_PROP_MULTIFD_COMPRESS(_n, _s, _f, _d) \ + DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_multifd_compress, Multifd= Compress) #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ LostTickPolicy) diff --git a/migration/migration.c b/migration/migration.c index ef17b9f3f2..ecb56afd50 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -87,6 +87,7 @@ /* The delay time (in ms) between two COLO checkpoints */ #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY (200 * 100) #define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2 +#define DEFAULT_MIGRATE_MULTIFD_COMPRESS MULTIFD_COMPRESS_NONE =20 /* Background transfer rate for postcopy, 0 means unlimited, note * that page requests can still exceed this limit. @@ -797,6 +798,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->block_incremental =3D s->parameters.block_incremental; params->has_multifd_channels =3D true; params->multifd_channels =3D s->parameters.multifd_channels; + params->has_multifd_compress =3D true; + params->multifd_compress =3D s->parameters.multifd_compress; params->has_xbzrle_cache_size =3D true; params->xbzrle_cache_size =3D s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth =3D true; @@ -1314,6 +1317,9 @@ static void migrate_params_test_apply(MigrateSetParam= eters *params, if (params->has_multifd_channels) { dest->multifd_channels =3D params->multifd_channels; } + if (params->has_multifd_compress) { + dest->multifd_compress =3D params->multifd_compress; + } if (params->has_xbzrle_cache_size) { dest->xbzrle_cache_size =3D params->xbzrle_cache_size; } @@ -1410,6 +1416,9 @@ static void migrate_params_apply(MigrateSetParameters= *params, Error **errp) if (params->has_multifd_channels) { s->parameters.multifd_channels =3D params->multifd_channels; } + if (params->has_multifd_compress) { + s->parameters.multifd_compress =3D params->multifd_compress; + } if (params->has_xbzrle_cache_size) { s->parameters.xbzrle_cache_size =3D params->xbzrle_cache_size; xbzrle_cache_resize(params->xbzrle_cache_size, errp); @@ -3514,6 +3523,9 @@ static Property migration_properties[] =3D { DEFINE_PROP_UINT8("multifd-channels", MigrationState, parameters.multifd_channels, DEFAULT_MIGRATE_MULTIFD_CHANNELS), + DEFINE_PROP_MULTIFD_COMPRESS("multifd-compress", MigrationState, + parameters.multifd_compress, + DEFAULT_MIGRATE_MULTIFD_COMPRESS), DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE), @@ -3604,6 +3616,7 @@ static void migration_instance_init(Object *obj) params->has_x_checkpoint_delay =3D true; params->has_block_incremental =3D true; params->has_multifd_channels =3D true; + params->has_multifd_compress =3D true; params->has_xbzrle_cache_size =3D true; params->has_max_postcopy_bandwidth =3D true; params->has_max_cpu_throttle =3D true; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index d0e0af893a..ba75a609a7 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -39,6 +39,7 @@ #include "qapi/qapi-commands-tpm.h" #include "qapi/qapi-commands-ui.h" #include "qapi/qapi-visit-net.h" +#include "qapi/qapi-visit-migration.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/string-input-visitor.h" @@ -447,6 +448,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QD= ict *qdict) monitor_printf(mon, "%s: %u\n", MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), params->multifd_channels); + monitor_printf(mon, "%s: %s\n", + MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESS), + MultifdCompress_str(params->multifd_compress)); monitor_printf(mon, "%s: %" PRIu64 "\n", MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), params->xbzrle_cache_size); @@ -1738,6 +1742,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) MigrateSetParameters *p =3D g_new0(MigrateSetParameters, 1); uint64_t valuebw =3D 0; uint64_t cache_size; + MultifdCompress compress_type; Error *err =3D NULL; int val, ret; =20 @@ -1823,6 +1828,14 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p->has_multifd_channels =3D true; visit_type_int(v, param, &p->multifd_channels, &err); break; + case MIGRATION_PARAMETER_MULTIFD_COMPRESS: + p->has_multifd_compress =3D true; + visit_type_MultifdCompress(v, param, &compress_type, &err); + if (err) { + break; + } + p->multifd_compress =3D compress_type; + break; case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: p->has_xbzrle_cache_size =3D true; visit_type_size(v, param, &cache_size, &err); diff --git a/qapi/migration.json b/qapi/migration.json index b7348d0c8b..c2891e6ebf 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -488,6 +488,19 @@ ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabil= ityStatus']} =20 +## +# @MultifdCompress: +# +# An enumeration of multifd compression. +# +# @none: no compression. +# +# Since: 4.1 +# +## +{ 'enum': 'MultifdCompress', + 'data': [ 'none' ] } + ## # @MigrationParameter: # @@ -586,6 +599,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # Defaults to 99. (Since 3.1) # +# @multifd-compress: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## { 'enum': 'MigrationParameter', @@ -598,7 +614,7 @@ 'downtime-limit', 'x-checkpoint-delay', 'block-incremental', 'multifd-channels', 'xbzrle-cache-size', 'max-postcopy-bandwidth', - 'max-cpu-throttle' ] } + 'max-cpu-throttle', 'multifd-compress' ] } =20 ## # @MigrateSetParameters: @@ -688,6 +704,9 @@ # @max-cpu-throttle: maximum cpu throttle percentage. # The default value is 99. (Since 3.1) # +# @multifd-compress: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## # TODO either fuse back into MigrationParameters, or make @@ -713,7 +732,8 @@ '*multifd-channels': 'int', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'int' } } + '*max-cpu-throttle': 'int', + '*multifd-compress': 'MultifdCompress' } } =20 ## # @migrate-set-parameters: @@ -823,6 +843,9 @@ # Defaults to 99. # (Since 3.1) # +# @multifd-compress: Which compression method to use. +# Defaults to none. (Since 5.0) +# # Since: 2.4 ## { 'struct': 'MigrationParameters', @@ -846,7 +869,8 @@ '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle':'uint8'} } + '*max-cpu-throttle': 'uint8', + '*multifd-compress': 'MultifdCompress' } } =20 ## # @query-migrate-parameters: diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index cf27ebbc9d..3d5d2aba8c 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -378,7 +378,6 @@ static void migrate_check_parameter_str(QTestState *who= , const char *parameter, g_free(result); } =20 -__attribute__((unused)) static void migrate_set_parameter_str(QTestState *who, const char *paramet= er, const char *value) { @@ -1251,7 +1250,7 @@ static void test_migrate_auto_converge(void) test_migrate_end(from, to, true); } =20 -static void test_multifd_tcp(void) +static void test_multifd_tcp(const char *method) { MigrateStart *args =3D migrate_start_new(); QTestState *from, *to; @@ -1275,6 +1274,9 @@ static void test_multifd_tcp(void) migrate_set_parameter_int(from, "multifd-channels", 16); migrate_set_parameter_int(to, "multifd-channels", 16); =20 + migrate_set_parameter_str(from, "multifd-compress", method); + migrate_set_parameter_str(to, "multifd-compress", method); + migrate_set_capability(from, "multifd", "true"); migrate_set_capability(to, "multifd", "true"); =20 @@ -1306,6 +1308,11 @@ static void test_multifd_tcp(void) g_free(uri); } =20 +static void test_multifd_tcp_none(void) +{ + test_multifd_tcp("none"); +} + /* * This test does: * source target @@ -1317,7 +1324,6 @@ static void test_multifd_tcp(void) * * And see that it works */ - static void test_multifd_tcp_cancel(void) { MigrateStart *args =3D migrate_start_new(); @@ -1467,7 +1473,7 @@ int main(int argc, char **argv) test_validate_uuid_dst_not_set); =20 qtest_add_func("/migration/auto_converge", test_migrate_auto_converge); - qtest_add_func("/migration/multifd/tcp", test_multifd_tcp); + qtest_add_func("/migration/multifd/tcp/none", test_multifd_tcp_none); qtest_add_func("/migration/multifd/tcp/cancel", test_multifd_tcp_cance= l); =20 ret =3D g_test_run(); --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579784292; cv=none; d=zohomail.com; s=zohoarc; b=c+nzcDGwQTEbox8R9oDwKtknYsHkx/ckmdI9WYs2GggppELRcMjzs/w0bVFC6/CFamrfQuRw7f+/DOiuwS+CA6RF3oNvhUEtl5FA6I/DyaKOSHTEblwhvLDkDCVjJ8jSof07c6QTR31EYl64XB7m/l7sNuknHvHMHHkWDKsRvKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579784292; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m0tPyfIG/1DzNomXMeY5FZxQSCY8+/0Clp5G5kbILOg=; b=XxiwLpSGYTzuyhtbfRMdjmpSwgPf/pSv4X/OMwD98g8bpe0c6XOhE8mx8WLyJbMMrZyeK0zmpwXhzxW2yMR/XIYJ/PBTuVM6nivWckWj/OcDOsBC24BNrdwNxPrLNy/XIY4xZSuxlnKRO6Y+IMlPoLl5osdqZm3z/k6z2k+WzXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579784292604791.2673750803954; Thu, 23 Jan 2020 04:58:12 -0800 (PST) Received: from localhost ([::1]:56636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuc3m-00083j-SW for importer@patchew.org; Thu, 23 Jan 2020 07:58:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40196) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8k-0001w6-3v for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8i-0004vq-6d for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:13 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:53785 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8i-0004ut-2e for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:12 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-qSjN7BcNNMOPUrAAfUjalQ-1; Thu, 23 Jan 2020 06:59:09 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69E5D800D41 for ; Thu, 23 Jan 2020 11:59:08 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB9EB28989; Thu, 23 Jan 2020 11:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m0tPyfIG/1DzNomXMeY5FZxQSCY8+/0Clp5G5kbILOg=; b=NhkxjIEYpvSC1okBjIrts2CpVyKCLWXyGC8UqmuEjM/KZ9mOQg+0Jrm7yQQxtl7PtYigN/ qYubFgoazHU2c62oOXI4PvzbnO7wwqGTERBGc6IHG+ZwXcV6N7rxC/7mUE/AvW6ViXyAR7 sYzgMEhZ8pbFvB6IZYGdUdYQCNiCSPs= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 10/21] ram_addr: Split RAMBlock definition Date: Thu, 23 Jan 2020 12:58:20 +0100 Message-Id: <20200123115831.36842-11-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: qSjN7BcNNMOPUrAAfUjalQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We need some of the fields without having to poison everything else. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- MAINTAINERS | 1 + include/exec/ram_addr.h | 40 +------------------------- include/exec/ramblock.h | 64 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 39 deletions(-) create mode 100644 include/exec/ramblock.h diff --git a/MAINTAINERS b/MAINTAINERS index 2c768ed3d8..3732f746b3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1965,6 +1965,7 @@ F: ioport.c F: include/exec/memop.h F: include/exec/memory.h F: include/exec/ram_addr.h +F: include/exec/ramblock.h F: memory.c F: include/exec/memory-internal.h F: exec.c diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 5adebb0bc7..5e59a3d8d7 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -24,45 +24,7 @@ #include "hw/xen/xen.h" #include "sysemu/tcg.h" #include "exec/ramlist.h" - -struct RAMBlock { - struct rcu_head rcu; - struct MemoryRegion *mr; - uint8_t *host; - uint8_t *colo_cache; /* For colo, VM's ram cache */ - ram_addr_t offset; - ram_addr_t used_length; - ram_addr_t max_length; - void (*resized)(const char*, uint64_t length, void *host); - uint32_t flags; - /* Protected by iothread lock. */ - char idstr[256]; - /* RCU-enabled, writes protected by the ramlist lock */ - QLIST_ENTRY(RAMBlock) next; - QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers; - int fd; - size_t page_size; - /* dirty bitmap used during migration */ - unsigned long *bmap; - /* bitmap of already received pages in postcopy */ - unsigned long *receivedmap; - - /* - * bitmap to track already cleared dirty bitmap. When the bit is - * set, it means the corresponding memory chunk needs a log-clear. - * Set this up to non-NULL to enable the capability to postpone - * and split clearing of dirty bitmap on the remote node (e.g., - * KVM). The bitmap will be set only when doing global sync. - * - * NOTE: this bitmap is different comparing to the other bitmaps - * in that one bit can represent multiple guest pages (which is - * decided by the `clear_bmap_shift' variable below). On - * destination side, this should always be NULL, and the variable - * `clear_bmap_shift' is meaningless. - */ - unsigned long *clear_bmap; - uint8_t clear_bmap_shift; -}; +#include "exec/ramblock.h" =20 /** * clear_bmap_size: calculate clear bitmap size diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h new file mode 100644 index 0000000000..07d50864d8 --- /dev/null +++ b/include/exec/ramblock.h @@ -0,0 +1,64 @@ +/* + * Declarations for cpu physical memory functions + * + * Copyright 2011 Red Hat, Inc. and/or its affiliates + * + * Authors: + * Avi Kivity + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + * + */ + +/* + * This header is for use by exec.c and memory.c ONLY. Do not include it. + * The functions declared here will be removed soon. + */ + +#ifndef QEMU_EXEC_RAMBLOCK_H +#define QEMU_EXEC_RAMBLOCK_H + +#ifndef CONFIG_USER_ONLY +#include "cpu-common.h" + +struct RAMBlock { + struct rcu_head rcu; + struct MemoryRegion *mr; + uint8_t *host; + uint8_t *colo_cache; /* For colo, VM's ram cache */ + ram_addr_t offset; + ram_addr_t used_length; + ram_addr_t max_length; + void (*resized)(const char*, uint64_t length, void *host); + uint32_t flags; + /* Protected by iothread lock. */ + char idstr[256]; + /* RCU-enabled, writes protected by the ramlist lock */ + QLIST_ENTRY(RAMBlock) next; + QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers; + int fd; + size_t page_size; + /* dirty bitmap used during migration */ + unsigned long *bmap; + /* bitmap of already received pages in postcopy */ + unsigned long *receivedmap; + + /* + * bitmap to track already cleared dirty bitmap. When the bit is + * set, it means the corresponding memory chunk needs a log-clear. + * Set this up to non-NULL to enable the capability to postpone + * and split clearing of dirty bitmap on the remote node (e.g., + * KVM). The bitmap will be set only when doing global sync. + * + * NOTE: this bitmap is different comparing to the other bitmaps + * in that one bit can represent multiple guest pages (which is + * decided by the `clear_bmap_shift' variable below). On + * destination side, this should always be NULL, and the variable + * `clear_bmap_shift' is meaningless. + */ + unsigned long *clear_bmap; + uint8_t clear_bmap_shift; +}; +#endif +#endif --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579784388; cv=none; d=zohomail.com; s=zohoarc; b=YGMu0n/6B7yg2sjvADjgs3+Lk/w/UQqeesOZxlo7z9AfwNe5dq2vMEvIXMbWNVH7S8tXerycAtwbmUnwfmu78TeEXDielbDn9axKKPbA78VsXWNKEfgzDw8xwDGvVBWTcMHQThwhCXNrk69iKBoCbl75n9cI8dzzJomb/6cNte4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579784388; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zpZtx+nrJtr99ho6va+6XTZGIghNiNIClmqo3+ZKxi4=; b=KqKycRqUOTYuNvB/xxLs9J2wQYKLYsUrubPYBGGXP7DR36annPnhzgkGkio23r07DPAD+WHJAra55QMvfNbpnVxkSg57gRX5vt0OOZo1Y40xi8OOwcsEeRoC2hYORHq70XL1Tu5xGTjkA0qho3NN5DSn2eVwVMqf6kzLGbwch+I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579784388213425.05529837380243; Thu, 23 Jan 2020 04:59:48 -0800 (PST) Received: from localhost ([::1]:56654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuc5K-00021G-Gb for importer@patchew.org; Thu, 23 Jan 2020 07:59:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40225) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8m-0001y4-37 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8k-0004xA-5j for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:15 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:51635 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8k-0004we-0L for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:14 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-ceFHk55COheLRJPGXxWU_g-1; Thu, 23 Jan 2020 06:59:12 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A174107ACC4 for ; Thu, 23 Jan 2020 11:59:11 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFA5419C69; Thu, 23 Jan 2020 11:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zpZtx+nrJtr99ho6va+6XTZGIghNiNIClmqo3+ZKxi4=; b=gyHsxNtK8WwusxGaPojqDiKLRsU18zO+hMh9p6R0xbe9xTRgba4pAp5Br/SbY8OEjrjG1Z RGb9cNIyO+5rwCwIqlqU84zpXY2RGAo35LZKolS7JLCpvMD4AOb86D1iFZ1vR4iWsiLVZE 3+wtSKwLI4v1N0amWFAqD9NVdEy/lKI= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 11/21] multifd: multifd_send_pages only needs the qemufile Date: Thu, 23 Jan 2020 12:58:21 +0100 Message-Id: <20200123115831.36842-12-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: ceFHk55COheLRJPGXxWU_g-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 125c6d0f60..19caf5ed4d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -929,7 +929,7 @@ struct { * false. */ =20 -static int multifd_send_pages(RAMState *rs) +static int multifd_send_pages(QEMUFile *f) { int i; static int next_channel; @@ -965,7 +965,7 @@ static int multifd_send_pages(RAMState *rs) multifd_send_state->pages =3D p->pages; p->pages =3D pages; transferred =3D ((uint64_t) pages->used) * TARGET_PAGE_SIZE + p->packe= t_len; - qemu_file_update_transfer(rs->f, transferred); + qemu_file_update_transfer(f, transferred); ram_counters.multifd_bytes +=3D transferred; ram_counters.transferred +=3D transferred;; qemu_mutex_unlock(&p->mutex); @@ -993,7 +993,7 @@ static int multifd_queue_page(RAMState *rs, RAMBlock *b= lock, ram_addr_t offset) } } =20 - if (multifd_send_pages(rs) < 0) { + if (multifd_send_pages(rs->f) < 0) { return -1; } =20 @@ -1090,7 +1090,7 @@ static void multifd_send_sync_main(RAMState *rs) return; } if (multifd_send_state->pages->used) { - if (multifd_send_pages(rs) < 0) { + if (multifd_send_pages(rs->f) < 0) { error_report("%s: multifd_send_pages fail", __func__); return; } --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579785996; cv=none; d=zohomail.com; s=zohoarc; b=W+/VQwhFhUaqtp228xIT5F+2Ssb6BZ9On/KKlb+XpZwgITFCm0hJ0x2kf+sBqPuRa+peNkKsmBW4V3IlhQPJYZdY+Em7e9+lRrNf8zu4O5CHTA8QxoNDOWMbHAD2WyA6Ti8NPKD2GusQsN2eFTQhOSiVF5LObGcq8uT3Ewit5dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579785996; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OBMjeyeAZyM2/vGJZhH1BtgKby+UDT6rTZKWS6FFQ30=; b=fO/9EZpEZtDMRGN4Gj5XoONwyOw+otdvFRAH/jBPpJWil+N1LOAlU3MXQhhpjLafugx5dJ4DRumvsVbWxT2OZeOyJUMLUR0yHop+tZApPj25GxAzMIzV7PuQ85Z00vLqKeM2p19x0Stm/SnuTMnu/yNg93GAMonl64rflwcODPY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579785996480416.72641270692145; Thu, 23 Jan 2020 05:26:36 -0800 (PST) Received: from localhost ([::1]:57018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucVG-0001TM-O9 for importer@patchew.org; Thu, 23 Jan 2020 08:26:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40360) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8t-00025V-3x for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8s-000536-3r for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:23 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:26194) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8s-00052D-0J for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:22 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-ljTShN33Mdqqg0pUQ0bhIw-1; Thu, 23 Jan 2020 06:59:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22E1618A6ED2 for ; Thu, 23 Jan 2020 11:59:18 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E1C819C69; Thu, 23 Jan 2020 11:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OBMjeyeAZyM2/vGJZhH1BtgKby+UDT6rTZKWS6FFQ30=; b=aIBx+DB6xeKHA8O1Ja/pVKXDlU2fxlvQBqwcV3cyNv8l0OnYp+ObuCGFk6N2PNkQiC+joT OWlEHIrOG9qCoHwzEF/hvY9J9JrPlrzx4lPNotyTn6cmyCp9iWXqoWPgQKiCAcuPhmmQXu Y3yMrBNALHozWLs/s6QfoRd8T7stz/E= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 12/21] multifd: multifd_queue_page only needs the qemufile Date: Thu, 23 Jan 2020 12:58:22 +0100 Message-Id: <20200123115831.36842-13-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: ljTShN33Mdqqg0pUQ0bhIw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 19caf5ed4d..d4c829bc77 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -974,7 +974,7 @@ static int multifd_send_pages(QEMUFile *f) return 1; } =20 -static int multifd_queue_page(RAMState *rs, RAMBlock *block, ram_addr_t of= fset) +static int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t off= set) { MultiFDPages_t *pages =3D multifd_send_state->pages; =20 @@ -993,12 +993,12 @@ static int multifd_queue_page(RAMState *rs, RAMBlock = *block, ram_addr_t offset) } } =20 - if (multifd_send_pages(rs->f) < 0) { + if (multifd_send_pages(f) < 0) { return -1; } =20 if (pages->block !=3D block) { - return multifd_queue_page(rs, block, offset); + return multifd_queue_page(f, block, offset); } =20 return 1; @@ -2128,7 +2128,7 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss, bool last_stage) static int ram_save_multifd_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) { - if (multifd_queue_page(rs, block, offset) < 0) { + if (multifd_queue_page(rs->f, block, offset) < 0) { return -1; } ram_counters.normal++; --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579785027; cv=none; d=zohomail.com; s=zohoarc; b=gfL+/rA/js1UGnrVvmmHlxZ55qMZvQRJBpGd89BwwqXfZ+LDgVNyxVjqYBM9o14X8jWhSgbtK2lFSqd256moF9eZ26QXBu41MLUooTAjebEXGuM6F0QG9ZRKHbQ9fGAUl7Pk0hjD+COkOZlltOErJulpbfo94kKmg29RFmCczZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579785027; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gEtrEl/b8zHxSZ0DTpznmiBp8GHFsRGG0f8Y5qLnuEY=; b=FWv//LCbEp2NvU16GFRHqqaWWY7CRp+BhuqlVSGHtFyrO65PZ4ELqWYacnrXMSfp+4/i+EDCWi/3wn97TNovDnDVDuki0QSlFZPuuuO94U0xHzpCWU8z0+dkou/yaKv54OsPznuRQEE9ssmFYod2Wzci/SvvBkCdm2j7VJn+MJk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579785027671839.3601462926288; Thu, 23 Jan 2020 05:10:27 -0800 (PST) Received: from localhost ([::1]:56798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucFd-0005xX-T5 for importer@patchew.org; Thu, 23 Jan 2020 08:10:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40407) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8v-00028l-12 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8t-00054g-VP for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:24 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56158 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8t-00054O-Rc for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:23 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-396-WR10frG8NdSn4J3T_dMsaQ-1; Thu, 23 Jan 2020 06:59:21 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D50EB800D4C for ; Thu, 23 Jan 2020 11:59:20 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CF4B19C69; Thu, 23 Jan 2020 11:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gEtrEl/b8zHxSZ0DTpznmiBp8GHFsRGG0f8Y5qLnuEY=; b=SiVBriRdpB5X/OJgQdJ8qjC4CYmH7GOueQm8w4dVOtOkFEEeGwvVqxWyEa71ZDaDUf8Piz ziHX8F1OExhcEuthi8t27xTTX5RJcXRrVuWO0hmmbvk4qOfrcDMSRvrZp+PpSk5DyoeLDq vVS1ITESTf9VOcDyCTLHKfo/AxlOw+U= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 13/21] multifd: multifd_send_sync_main only needs the qemufile Date: Thu, 23 Jan 2020 12:58:23 +0100 Message-Id: <20200123115831.36842-14-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: WR10frG8NdSn4J3T_dMsaQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index d4c829bc77..2783dc60f4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1082,7 +1082,7 @@ void multifd_save_cleanup(void) multifd_send_state =3D NULL; } =20 -static void multifd_send_sync_main(RAMState *rs) +static void multifd_send_sync_main(QEMUFile *f) { int i; =20 @@ -1090,7 +1090,7 @@ static void multifd_send_sync_main(RAMState *rs) return; } if (multifd_send_state->pages->used) { - if (multifd_send_pages(rs->f) < 0) { + if (multifd_send_pages(f) < 0) { error_report("%s: multifd_send_pages fail", __func__); return; } @@ -1111,7 +1111,7 @@ static void multifd_send_sync_main(RAMState *rs) p->packet_num =3D multifd_send_state->packet_num++; p->flags |=3D MULTIFD_FLAG_SYNC; p->pending_job++; - qemu_file_update_transfer(rs->f, p->packet_len); + qemu_file_update_transfer(f, p->packet_len); ram_counters.multifd_bytes +=3D p->packet_len; ram_counters.transferred +=3D p->packet_len; qemu_mutex_unlock(&p->mutex); @@ -3426,7 +3426,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) ram_control_before_iterate(f, RAM_CONTROL_SETUP); ram_control_after_iterate(f, RAM_CONTROL_SETUP); =20 - multifd_send_sync_main(*rsp); + multifd_send_sync_main(f); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); qemu_fflush(f); =20 @@ -3526,7 +3526,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) out: if (ret >=3D 0 && migration_is_setup_or_active(migrate_get_current()->state)) { - multifd_send_sync_main(rs); + multifd_send_sync_main(rs->f); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); qemu_fflush(f); ram_counters.transferred +=3D 8; @@ -3585,7 +3585,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) } =20 if (ret >=3D 0) { - multifd_send_sync_main(rs); + multifd_send_sync_main(rs->f); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); qemu_fflush(f); } --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579786681; cv=none; d=zohomail.com; s=zohoarc; b=EPhv825GnOuG8yO/VVPZVeU1P23zsTjga6MGvftlvbCUgUu/r839gBei8z7B9611Bq+42WjlFWIUMa6RInmCrQv8mLyCdsFoBA1xo54aDQahIpNhdn8InBGz4CHCPsV47HA3y6kdVHcgCNLr1hRhcin50YbJc4IoztC/rkQXyBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579786681; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XaY15sZsWneq0IGhoUPBI3NEwwpuSCn+u24CtPksQRw=; b=hMB/C03GHsP7gD4i9D1cZKhrIQFi9RhCCWcot/g/6QiRao7jTAhebC8eFxOyKE5gAdn3Gi4KIzAHSHWnS0AU7hT8p3x/xFSF2945ODX3q4gF50H2Iy/ul6mQwyqYL9JTflWYKZQB6ipOMaR5qpBCU0kYx8wWOeCVhS+A/y/tUc0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579786681550700.162050935781; Thu, 23 Jan 2020 05:38:01 -0800 (PST) Received: from localhost ([::1]:57139 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucgK-0005iF-2j for importer@patchew.org; Thu, 23 Jan 2020 08:38:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40430) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub8x-0002Cs-F4 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8w-000560-9z for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:27 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32306 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8w-00055w-76 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:26 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-Jtf0GKvFOIuHK4OvH41Blg-1; Thu, 23 Jan 2020 06:59:24 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7ADDE1800D48 for ; Thu, 23 Jan 2020 11:59:23 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3425D19C69; Thu, 23 Jan 2020 11:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XaY15sZsWneq0IGhoUPBI3NEwwpuSCn+u24CtPksQRw=; b=HrXF8eVNwL7VI0BvMnbIi7NiJL7H4k1sJt2dzqsscbWdYAzpqLCQ4Dc+j+DoBNX4+95IOW plLRZF2RmVu/AEIMVraDprOM3msm8R5f/t1CHWVtQFOSIgm5aZL8lxveucwRw7MVgSaIMo 1LbE5UaJyPseYBQDwiTlKJpp/ZiY4fI= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 14/21] multifd: Use qemu_target_page_size() Date: Thu, 23 Jan 2020 12:58:24 +0100 Message-Id: <20200123115831.36842-15-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: Jtf0GKvFOIuHK4OvH41Blg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We will make it cpu independent. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 2783dc60f4..14b7cbdbc9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -882,14 +882,14 @@ static int multifd_recv_unfill_packet(MultiFDRecvPara= ms *p, Error **errp) for (i =3D 0; i < p->pages->used; i++) { uint64_t offset =3D be64_to_cpu(packet->offset[i]); =20 - if (offset > (block->used_length - TARGET_PAGE_SIZE)) { + if (offset > (block->used_length - qemu_target_page_size())) { error_setg(errp, "multifd: offset too long %" PRIu64 " (max " RAM_ADDR_FMT ")", offset, block->max_length); return -1; } p->pages->iov[i].iov_base =3D block->host + offset; - p->pages->iov[i].iov_len =3D TARGET_PAGE_SIZE; + p->pages->iov[i].iov_len =3D qemu_target_page_size(); } =20 return 0; @@ -964,7 +964,8 @@ static int multifd_send_pages(QEMUFile *f) p->packet_num =3D multifd_send_state->packet_num++; multifd_send_state->pages =3D p->pages; p->pages =3D pages; - transferred =3D ((uint64_t) pages->used) * TARGET_PAGE_SIZE + p->packe= t_len; + transferred =3D ((uint64_t) pages->used) * qemu_target_page_size() + + p->packet_len; qemu_file_update_transfer(f, transferred); ram_counters.multifd_bytes +=3D transferred; ram_counters.transferred +=3D transferred;; @@ -985,7 +986,7 @@ static int multifd_queue_page(QEMUFile *f, RAMBlock *bl= ock, ram_addr_t offset) if (pages->block =3D=3D block) { pages->offset[pages->used] =3D offset; pages->iov[pages->used].iov_base =3D block->host + offset; - pages->iov[pages->used].iov_len =3D TARGET_PAGE_SIZE; + pages->iov[pages->used].iov_len =3D qemu_target_page_size(); pages->used++; =20 if (pages->used < pages->allocated) { --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579784787; cv=none; d=zohomail.com; s=zohoarc; b=eFf/tTNO7i2UPrB/1HP33RCv+MM68WG5Q3h9FAcpHN5R2bNerEKTEdB3n9JX7UCmiA6VGFloDrS7VtvDdPXhWI1eCdswG+16S3xIDLyl7foAUTcpUaqV1XRPIC1HSC7qTEitAhRLmZhznNWDiob358bCJXf1h/UzhGLdpAxNIfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579784787; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1lroIocMrNnM4MALgW/EKonh3yvsvnqzwgFLgJtyK2M=; b=i/cAC2vweW62x2AMhFRoGzFLgOaaYRX2Hq1wZtFaqwEiwD3oIr+WN6MaQPLIr4FWrvMwcClzG7DaO24YMLp96RBjgvW287J4nEP50yc5kLE+CHmDOkyd5HMlFdVUyfHQvvKSaxS+BuMhknwZlwM1iuZDC55CsLGxPs/TTB4KgZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579784787634625.8478125097382; Thu, 23 Jan 2020 05:06:27 -0800 (PST) Received: from localhost ([::1]:56750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucBl-0000vM-Ti for importer@patchew.org; Thu, 23 Jan 2020 08:06:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40473) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub90-0002Ho-EF for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub8z-00057j-AN for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:30 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:21580 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub8z-00057O-6l for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:29 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-jUTeS7peNGClaGnd_Ow7eA-1; Thu, 23 Jan 2020 06:59:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2705C800D4C for ; Thu, 23 Jan 2020 11:59:26 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id D12AB19C70; Thu, 23 Jan 2020 11:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1lroIocMrNnM4MALgW/EKonh3yvsvnqzwgFLgJtyK2M=; b=Bvj2XTfcHRZq3CnNye/NC4piy7J4PGvDZG1JQ4FrG1d4JH2RnhHbJSpL7C2UyfVdZXymPe TQ6t12Q3AhU8B2Zk21wW7CXhjYNAAiCijXKEoptLcqCOzF/IqlRGaQvS2LW6u2mi6+Dt7m pitkdt1ikQxhNQUYJpRwrS3Cou8ULhY= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 15/21] migration: Make checkpatch happy with comments Date: Thu, 23 Jan 2020 12:58:25 +0100 Message-Id: <20200123115831.36842-16-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: jUTeS7peNGClaGnd_Ow7eA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 14b7cbdbc9..c24b4cc771 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1312,10 +1312,12 @@ static void multifd_recv_terminate_threads(Error *e= rr) =20 qemu_mutex_lock(&p->mutex); p->quit =3D true; - /* We could arrive here for two reasons: - - normal quit, i.e. everything went fine, just finished - - error quit: We close the channels so the channel threads - finish the qio_channel_read_all_eof() */ + /* + * We could arrive here for two reasons: + * - normal quit, i.e. everything went fine, just finished + * - error quit: We close the channels so the channel threads + * finish the qio_channel_read_all_eof() + */ if (p->c) { qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579786973; cv=none; d=zohomail.com; s=zohoarc; b=O0g+vuVwp4ZbcTAzdDNY1cl3tyTe2mH2WHCr9Gsyjp2qFVb/3DsTV8xyxvRR9QP/AmfTh7a6PQhjtfJhqVV/p/oFAsJhSzBe7diaQOZOLxH+F+nLcsMwxk6aCewIz6QcM28hRs6S75SMdW5t19D/rWf0H/QDyYYdzIKz4AOskXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579786973; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ydN3zOxZ5Nr4uslKo8T3Yz92d59EdgixLkVO3Mx1HQ8=; b=HV4wk18zSR/SP9hgyj5wTKKST2R9hKtCzR0397uRLHHWjki/+1nlFc2i+pf6V/NW0QnyYPc0mr7hgV3xvfx9l4hcZBS6NDgyTX3z30ox6s7teeJ7F10Rufp7Fj5KoWgbz72L0yZ4RQhoZbaUsxXJY8dqx1Kp7Oa2eJN5h8OI5dI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579786973364858.9396916522613; Thu, 23 Jan 2020 05:42:53 -0800 (PST) Received: from localhost ([::1]:57210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucl1-000536-KM for importer@patchew.org; Thu, 23 Jan 2020 08:42:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40517) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub94-0002Nx-7y for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub93-0005AI-0v for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:34 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:22061 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub92-00059y-Ti for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:32 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-202-3wnmO7ENPpGL2G1jMpOddg-1; Thu, 23 Jan 2020 06:59:30 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C831C107ACC4 for ; Thu, 23 Jan 2020 11:59:28 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D62419C69; Thu, 23 Jan 2020 11:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ydN3zOxZ5Nr4uslKo8T3Yz92d59EdgixLkVO3Mx1HQ8=; b=Iufy8fkLjHui3IWfc7sl4aXOtOb3IGJ1lZybhIJbO9kWeogaILDKML84gYEQg6LovfRN+v W3xxJjF96brHwmS8ppyDQGeW0aoCjzQaccuJK6RQ4C/cJOVFPAprUK6JhlgMUbKSoBpYDS ACjhwsQBCud0OuddxiIWey9pPoOk7VE= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 16/21] migration: Add support for modules Date: Thu, 23 Jan 2020 12:58:26 +0100 Message-Id: <20200123115831.36842-17-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 3wnmO7ENPpGL2G1jMpOddg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" So we don't have to compile everything in, or have ifdefs Signed-off-by: Juan Quintela --- include/qemu/module.h | 2 ++ vl.c | 1 + 2 files changed, 3 insertions(+) diff --git a/include/qemu/module.h b/include/qemu/module.h index 65ba596e46..907cb5c0a5 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -40,6 +40,7 @@ static void __attribute__((constructor)) do_qemu_init_ ##= function(void) \ #endif =20 typedef enum { + MODULE_INIT_MIGRATION, MODULE_INIT_BLOCK, MODULE_INIT_OPTS, MODULE_INIT_QOM, @@ -56,6 +57,7 @@ typedef enum { #define xen_backend_init(function) module_init(function, \ MODULE_INIT_XEN_BACKEND) #define libqos_init(function) module_init(function, MODULE_INIT_LIBQOS) +#define migration_init(function) module_init(function, MODULE_INIT_MIGRATI= ON) =20 #define block_module_load_one(lib) module_load_one("block-", lib) #define ui_module_load_one(lib) module_load_one("ui-", lib) diff --git a/vl.c b/vl.c index 71d3e7eefb..f331a3921f 100644 --- a/vl.c +++ b/vl.c @@ -2873,6 +2873,7 @@ int main(int argc, char **argv, char **envp) qemu_init_exec_dir(argv[0]); =20 module_call_init(MODULE_INIT_QOM); + module_call_init(MODULE_INIT_MIGRATION); =20 qemu_add_opts(&qemu_drive_opts); qemu_add_drive_opts(&qemu_legacy_drive_opts); --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579785667; cv=none; d=zohomail.com; s=zohoarc; b=ZSyiXPgfCjv7E8lvnVns/KgNLWb+O5FojRdvmkCZ7RmubC/iMFcUsCgYjLAgdnF5jPlVNHyWPdmKdQF1mlua0usbE+ftGHx0L+Uzzs49IqxPS2SAaU+y1G8yPf4odb1Uye5/3z2vr9EFtKwdaYqO5tdyC4EdtbOuJKrltSKsJBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579785667; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T+leNIS9nWaI+AOENppBkAOVD/TxTXO5iS/w38ejyRg=; b=CfD4N37+t3OfnSPKGvU4CcQAoU1tBXOQdhrzZeyhN7bwiMjRue0gKzwNflQd+Rb+AtzFT8xsZY3eYZWcFoLDuNrfSfNCXYamPqh/5fjCzIe3W/ipYLs6nt5rwleOKUIOYwzWKDuaA8eplyv9oylr9a2q0IJ90Vyk+tvTLCmC7SI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579785667479247.98894296896947; Thu, 23 Jan 2020 05:21:07 -0800 (PST) Received: from localhost ([::1]:56928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucPx-0002TH-Or for importer@patchew.org; Thu, 23 Jan 2020 08:21:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40685) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub9D-0002ZE-Do for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub97-0005D7-4J for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:43 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:29711 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub96-0005Cc-Pw for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370-ARKWtLnXO5aA8TJnzIU7yA-1; Thu, 23 Jan 2020 06:59:32 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0EBFA18A6EC2 for ; Thu, 23 Jan 2020 11:59:32 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2869219C69; Thu, 23 Jan 2020 11:59:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T+leNIS9nWaI+AOENppBkAOVD/TxTXO5iS/w38ejyRg=; b=QsJJy9qfkbWjAmeJP83dYOIsDjyuY8chOhvAwtkOOM7WoqKk0uVdD9q6xtyorsBPPYHiD3 vvdpemeEBhVm9ZTOMlx0bx+jprlr1fYzOnXd0M+hDX+vY8kYzXNhMCNlxAGWQHIZChI2q4 MGwf8vOjeGkCIqKGRaF8jxdu/VgcKkg= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 17/21] multifd: Split multifd code into its own file Date: Thu, 23 Jan 2020 12:58:27 +0100 Message-Id: <20200123115831.36842-18-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: ARKWtLnXO5aA8TJnzIU7yA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/Makefile.objs | 1 + migration/migration.c | 1 + migration/multifd.c | 891 ++++++++++++++++++++++++++++++++++++ migration/multifd.h | 139 ++++++ migration/ram.c | 980 +--------------------------------------- migration/ram.h | 7 - 6 files changed, 1033 insertions(+), 986 deletions(-) create mode 100644 migration/multifd.c create mode 100644 migration/multifd.h diff --git a/migration/Makefile.objs b/migration/Makefile.objs index a4f3bafd86..d3623d5f9b 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -7,6 +7,7 @@ common-obj-y +=3D qemu-file-channel.o common-obj-y +=3D xbzrle.o postcopy-ram.o common-obj-y +=3D qjson.o common-obj-y +=3D block-dirty-bitmap.o +common-obj-y +=3D multifd.o =20 common-obj-$(CONFIG_RDMA) +=3D rdma.o =20 diff --git a/migration/migration.c b/migration/migration.c index ecb56afd50..3501bc3353 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -53,6 +53,7 @@ #include "monitor/monitor.h" #include "net/announce.h" #include "qemu/queue.h" +#include "multifd.h" =20 #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttli= ng */ =20 diff --git a/migration/multifd.c b/migration/multifd.c new file mode 100644 index 0000000000..1875bb3aaa --- /dev/null +++ b/migration/multifd.c @@ -0,0 +1,891 @@ +/* + * Multifd common code + * + * Copyright (c) 2019-2020 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/rcu.h" +#include "exec/target_page.h" +#include "sysemu/sysemu.h" +#include "exec/ramblock.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "ram.h" +#include "migration.h" +#include "socket.h" +#include "qemu-file.h" +#include "trace.h" +#include "multifd.h" + +/* Multiple fd's */ + +#define MULTIFD_MAGIC 0x11223344U +#define MULTIFD_VERSION 1 + +typedef struct { + uint32_t magic; + uint32_t version; + unsigned char uuid[16]; /* QemuUUID */ + uint8_t id; + uint8_t unused1[7]; /* Reserved for future use */ + uint64_t unused2[4]; /* Reserved for future use */ +} __attribute__((packed)) MultiFDInit_t; + +static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) +{ + MultiFDInit_t msg =3D {}; + int ret; + + msg.magic =3D cpu_to_be32(MULTIFD_MAGIC); + msg.version =3D cpu_to_be32(MULTIFD_VERSION); + msg.id =3D p->id; + memcpy(msg.uuid, &qemu_uuid.data, sizeof(msg.uuid)); + + ret =3D qio_channel_write_all(p->c, (char *)&msg, sizeof(msg), errp); + if (ret !=3D 0) { + return -1; + } + return 0; +} + +static int multifd_recv_initial_packet(QIOChannel *c, Error **errp) +{ + MultiFDInit_t msg; + int ret; + + ret =3D qio_channel_read_all(c, (char *)&msg, sizeof(msg), errp); + if (ret !=3D 0) { + return -1; + } + + msg.magic =3D be32_to_cpu(msg.magic); + msg.version =3D be32_to_cpu(msg.version); + + if (msg.magic !=3D MULTIFD_MAGIC) { + error_setg(errp, "multifd: received packet magic %x " + "expected %x", msg.magic, MULTIFD_MAGIC); + return -1; + } + + if (msg.version !=3D MULTIFD_VERSION) { + error_setg(errp, "multifd: received packet version %d " + "expected %d", msg.version, MULTIFD_VERSION); + return -1; + } + + if (memcmp(msg.uuid, &qemu_uuid, sizeof(qemu_uuid))) { + char *uuid =3D qemu_uuid_unparse_strdup(&qemu_uuid); + char *msg_uuid =3D qemu_uuid_unparse_strdup((const QemuUUID *)msg.= uuid); + + error_setg(errp, "multifd: received uuid '%s' and expected " + "uuid '%s' for channel %hhd", msg_uuid, uuid, msg.id); + g_free(uuid); + g_free(msg_uuid); + return -1; + } + + if (msg.id > migrate_multifd_channels()) { + error_setg(errp, "multifd: received channel version %d " + "expected %d", msg.version, MULTIFD_VERSION); + return -1; + } + + return msg.id; +} + +static MultiFDPages_t *multifd_pages_init(size_t size) +{ + MultiFDPages_t *pages =3D g_new0(MultiFDPages_t, 1); + + pages->allocated =3D size; + pages->iov =3D g_new0(struct iovec, size); + pages->offset =3D g_new0(ram_addr_t, size); + + return pages; +} + +static void multifd_pages_clear(MultiFDPages_t *pages) +{ + pages->used =3D 0; + pages->allocated =3D 0; + pages->packet_num =3D 0; + pages->block =3D NULL; + g_free(pages->iov); + pages->iov =3D NULL; + g_free(pages->offset); + pages->offset =3D NULL; + g_free(pages); +} + +static void multifd_send_fill_packet(MultiFDSendParams *p) +{ + MultiFDPacket_t *packet =3D p->packet; + int i; + + packet->flags =3D cpu_to_be32(p->flags); + packet->pages_alloc =3D cpu_to_be32(p->pages->allocated); + packet->pages_used =3D cpu_to_be32(p->pages->used); + packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); + packet->packet_num =3D cpu_to_be64(p->packet_num); + + if (p->pages->block) { + strncpy(packet->ramblock, p->pages->block->idstr, 256); + } + + for (i =3D 0; i < p->pages->used; i++) { + /* there are architectures where ram_addr_t is 32 bit */ + uint64_t temp =3D p->pages->offset[i]; + + packet->offset[i] =3D cpu_to_be64(temp); + } +} + +static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) +{ + MultiFDPacket_t *packet =3D p->packet; + uint32_t pages_max =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + RAMBlock *block; + int i; + + packet->magic =3D be32_to_cpu(packet->magic); + if (packet->magic !=3D MULTIFD_MAGIC) { + error_setg(errp, "multifd: received packet " + "magic %x and expected magic %x", + packet->magic, MULTIFD_MAGIC); + return -1; + } + + packet->version =3D be32_to_cpu(packet->version); + if (packet->version !=3D MULTIFD_VERSION) { + error_setg(errp, "multifd: received packet " + "version %d and expected version %d", + packet->version, MULTIFD_VERSION); + return -1; + } + + p->flags =3D be32_to_cpu(packet->flags); + + packet->pages_alloc =3D be32_to_cpu(packet->pages_alloc); + /* + * If we received a packet that is 100 times bigger than expected + * just stop migration. It is a magic number. + */ + if (packet->pages_alloc > pages_max * 100) { + error_setg(errp, "multifd: received packet " + "with size %d and expected a maximum size of %d", + packet->pages_alloc, pages_max * 100) ; + return -1; + } + /* + * We received a packet that is bigger than expected but inside + * reasonable limits (see previous comment). Just reallocate. + */ + if (packet->pages_alloc > p->pages->allocated) { + multifd_pages_clear(p->pages); + p->pages =3D multifd_pages_init(packet->pages_alloc); + } + + p->pages->used =3D be32_to_cpu(packet->pages_used); + if (p->pages->used > packet->pages_alloc) { + error_setg(errp, "multifd: received packet " + "with %d pages and expected maximum pages are %d", + p->pages->used, packet->pages_alloc) ; + return -1; + } + + p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); + p->packet_num =3D be64_to_cpu(packet->packet_num); + + if (p->pages->used =3D=3D 0) { + return 0; + } + + /* make sure that ramblock is 0 terminated */ + packet->ramblock[255] =3D 0; + block =3D qemu_ram_block_by_name(packet->ramblock); + if (!block) { + error_setg(errp, "multifd: unknown ram block %s", + packet->ramblock); + return -1; + } + + for (i =3D 0; i < p->pages->used; i++) { + uint64_t offset =3D be64_to_cpu(packet->offset[i]); + + if (offset > (block->used_length - qemu_target_page_size())) { + error_setg(errp, "multifd: offset too long %" PRIu64 + " (max " RAM_ADDR_FMT ")", + offset, block->max_length); + return -1; + } + p->pages->iov[i].iov_base =3D block->host + offset; + p->pages->iov[i].iov_len =3D qemu_target_page_size(); + } + + return 0; +} + +struct { + MultiFDSendParams *params; + /* array of pages to sent */ + MultiFDPages_t *pages; + /* global number of generated multifd packets */ + uint64_t packet_num; + /* send channels ready */ + QemuSemaphore channels_ready; + /* + * Have we already run terminate threads. There is a race when it + * happens that we got one error while we are exiting. + * We will use atomic operations. Only valid values are 0 and 1. + */ + int exiting; +} *multifd_send_state; + +/* + * How we use multifd_send_state->pages and channel->pages? + * + * We create a pages for each channel, and a main one. Each time that + * we need to send a batch of pages we interchange the ones between + * multifd_send_state and the channel that is sending it. There are + * two reasons for that: + * - to not have to do so many mallocs during migration + * - to make easier to know what to free at the end of migration + * + * This way we always know who is the owner of each "pages" struct, + * and we don't need any locking. It belongs to the migration thread + * or to the channel thread. Switching is safe because the migration + * thread is using the channel mutex when changing it, and the channel + * have to had finish with its own, otherwise pending_job can't be + * false. + */ + +static int multifd_send_pages(QEMUFile *f) +{ + int i; + static int next_channel; + MultiFDSendParams *p =3D NULL; /* make happy gcc */ + MultiFDPages_t *pages =3D multifd_send_state->pages; + uint64_t transferred; + + if (atomic_read(&multifd_send_state->exiting)) { + return -1; + } + + qemu_sem_wait(&multifd_send_state->channels_ready); + for (i =3D next_channel;; i =3D (i + 1) % migrate_multifd_channels()) { + p =3D &multifd_send_state->params[i]; + + qemu_mutex_lock(&p->mutex); + if (p->quit) { + error_report("%s: channel %d has already quit!", __func__, i); + qemu_mutex_unlock(&p->mutex); + return -1; + } + if (!p->pending_job) { + p->pending_job++; + next_channel =3D (i + 1) % migrate_multifd_channels(); + break; + } + qemu_mutex_unlock(&p->mutex); + } + assert(!p->pages->used); + assert(!p->pages->block); + + p->packet_num =3D multifd_send_state->packet_num++; + multifd_send_state->pages =3D p->pages; + p->pages =3D pages; + transferred =3D ((uint64_t) pages->used) * qemu_target_page_size() + + p->packet_len; + qemu_file_update_transfer(f, transferred); + ram_counters.multifd_bytes +=3D transferred; + ram_counters.transferred +=3D transferred;; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + + return 1; +} + +int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset) +{ + MultiFDPages_t *pages =3D multifd_send_state->pages; + + if (!pages->block) { + pages->block =3D block; + } + + if (pages->block =3D=3D block) { + pages->offset[pages->used] =3D offset; + pages->iov[pages->used].iov_base =3D block->host + offset; + pages->iov[pages->used].iov_len =3D qemu_target_page_size(); + pages->used++; + + if (pages->used < pages->allocated) { + return 1; + } + } + + if (multifd_send_pages(f) < 0) { + return -1; + } + + if (pages->block !=3D block) { + return multifd_queue_page(f, block, offset); + } + + return 1; +} + +static void multifd_send_terminate_threads(Error *err) +{ + int i; + + trace_multifd_send_terminate_threads(err !=3D NULL); + + if (err) { + MigrationState *s =3D migrate_get_current(); + migrate_set_error(s, err); + if (s->state =3D=3D MIGRATION_STATUS_SETUP || + s->state =3D=3D MIGRATION_STATUS_PRE_SWITCHOVER || + s->state =3D=3D MIGRATION_STATUS_DEVICE || + s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + migrate_set_state(&s->state, s->state, + MIGRATION_STATUS_FAILED); + } + } + + /* + * We don't want to exit each threads twice. Depending on where + * we get the error, or if there are two independent errors in two + * threads at the same time, we can end calling this function + * twice. + */ + if (atomic_xchg(&multifd_send_state->exiting, 1)) { + return; + } + + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + qemu_mutex_lock(&p->mutex); + p->quit =3D true; + qemu_sem_post(&p->sem); + qemu_mutex_unlock(&p->mutex); + } +} + +void multifd_save_cleanup(void) +{ + int i; + + if (!migrate_use_multifd()) { + return; + } + multifd_send_terminate_threads(NULL); + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + if (p->running) { + qemu_thread_join(&p->thread); + } + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + socket_send_channel_destroy(p->c); + p->c =3D NULL; + qemu_mutex_destroy(&p->mutex); + qemu_sem_destroy(&p->sem); + qemu_sem_destroy(&p->sem_sync); + g_free(p->name); + p->name =3D NULL; + multifd_pages_clear(p->pages); + p->pages =3D NULL; + p->packet_len =3D 0; + g_free(p->packet); + p->packet =3D NULL; + } + qemu_sem_destroy(&multifd_send_state->channels_ready); + g_free(multifd_send_state->params); + multifd_send_state->params =3D NULL; + multifd_pages_clear(multifd_send_state->pages); + multifd_send_state->pages =3D NULL; + g_free(multifd_send_state); + multifd_send_state =3D NULL; +} + +void multifd_send_sync_main(QEMUFile *f) +{ + int i; + + if (!migrate_use_multifd()) { + return; + } + if (multifd_send_state->pages->used) { + if (multifd_send_pages(f) < 0) { + error_report("%s: multifd_send_pages fail", __func__); + return; + } + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + trace_multifd_send_sync_main_signal(p->id); + + qemu_mutex_lock(&p->mutex); + + if (p->quit) { + error_report("%s: channel %d has already quit", __func__, i); + qemu_mutex_unlock(&p->mutex); + return; + } + + p->packet_num =3D multifd_send_state->packet_num++; + p->flags |=3D MULTIFD_FLAG_SYNC; + p->pending_job++; + qemu_file_update_transfer(f, p->packet_len); + ram_counters.multifd_bytes +=3D p->packet_len; + ram_counters.transferred +=3D p->packet_len; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + trace_multifd_send_sync_main_wait(p->id); + qemu_sem_wait(&p->sem_sync); + } + trace_multifd_send_sync_main(multifd_send_state->packet_num); +} + +static void *multifd_send_thread(void *opaque) +{ + MultiFDSendParams *p =3D opaque; + Error *local_err =3D NULL; + int ret =3D 0; + uint32_t flags =3D 0; + + trace_multifd_send_thread_start(p->id); + rcu_register_thread(); + + if (multifd_send_initial_packet(p, &local_err) < 0) { + ret =3D -1; + goto out; + } + /* initial packet */ + p->num_packets =3D 1; + + while (true) { + qemu_sem_wait(&p->sem); + + if (atomic_read(&multifd_send_state->exiting)) { + break; + } + qemu_mutex_lock(&p->mutex); + + if (p->pending_job) { + uint32_t used =3D p->pages->used; + uint64_t packet_num =3D p->packet_num; + flags =3D p->flags; + + p->next_packet_size =3D used * qemu_target_page_size(); + multifd_send_fill_packet(p); + p->flags =3D 0; + p->num_packets++; + p->num_pages +=3D used; + p->pages->used =3D 0; + p->pages->block =3D NULL; + qemu_mutex_unlock(&p->mutex); + + trace_multifd_send(p->id, packet_num, used, flags, + p->next_packet_size); + + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret !=3D 0) { + break; + } + + if (used) { + ret =3D qio_channel_writev_all(p->c, p->pages->iov, + used, &local_err); + if (ret !=3D 0) { + break; + } + } + + qemu_mutex_lock(&p->mutex); + p->pending_job--; + qemu_mutex_unlock(&p->mutex); + + if (flags & MULTIFD_FLAG_SYNC) { + qemu_sem_post(&p->sem_sync); + } + qemu_sem_post(&multifd_send_state->channels_ready); + } else if (p->quit) { + qemu_mutex_unlock(&p->mutex); + break; + } else { + qemu_mutex_unlock(&p->mutex); + /* sometimes there are spurious wakeups */ + } + } + +out: + if (local_err) { + trace_multifd_send_error(p->id); + multifd_send_terminate_threads(local_err); + } + + /* + * Error happen, I will exit, but I can't just leave, tell + * who pay attention to me. + */ + if (ret !=3D 0) { + qemu_sem_post(&p->sem_sync); + qemu_sem_post(&multifd_send_state->channels_ready); + } + + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + + rcu_unregister_thread(); + trace_multifd_send_thread_end(p->id, p->num_packets, p->num_pages); + + return NULL; +} + +static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) +{ + MultiFDSendParams *p =3D opaque; + QIOChannel *sioc =3D QIO_CHANNEL(qio_task_get_source(task)); + Error *local_err =3D NULL; + + trace_multifd_new_send_channel_async(p->id); + if (qio_task_propagate_error(task, &local_err)) { + migrate_set_error(migrate_get_current(), local_err); + multifd_save_cleanup(); + } else { + p->c =3D QIO_CHANNEL(sioc); + qio_channel_set_delay(p->c, false); + p->running =3D true; + qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, + QEMU_THREAD_JOINABLE); + } +} + +int multifd_save_setup(Error **errp) +{ + int thread_count; + uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + uint8_t i; + + if (!migrate_use_multifd()) { + return 0; + } + thread_count =3D migrate_multifd_channels(); + multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); + multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); + multifd_send_state->pages =3D multifd_pages_init(page_count); + qemu_sem_init(&multifd_send_state->channels_ready, 0); + atomic_set(&multifd_send_state->exiting, 0); + + for (i =3D 0; i < thread_count; i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem, 0); + qemu_sem_init(&p->sem_sync, 0); + p->quit =3D false; + p->pending_job =3D 0; + p->id =3D i; + p->pages =3D multifd_pages_init(page_count); + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(uint64_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); + p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); + p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); + p->name =3D g_strdup_printf("multifdsend_%d", i); + socket_send_channel_create(multifd_new_send_channel_async, p); + } + return 0; +} + +struct { + MultiFDRecvParams *params; + /* number of created threads */ + int count; + /* syncs main thread and channels */ + QemuSemaphore sem_sync; + /* global number of generated multifd packets */ + uint64_t packet_num; +} *multifd_recv_state; + +static void multifd_recv_terminate_threads(Error *err) +{ + int i; + + trace_multifd_recv_terminate_threads(err !=3D NULL); + + if (err) { + MigrationState *s =3D migrate_get_current(); + migrate_set_error(s, err); + if (s->state =3D=3D MIGRATION_STATUS_SETUP || + s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + migrate_set_state(&s->state, s->state, + MIGRATION_STATUS_FAILED); + } + } + + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_mutex_lock(&p->mutex); + p->quit =3D true; + /* + * We could arrive here for two reasons: + * - normal quit, i.e. everything went fine, just finished + * - error quit: We close the channels so the channel threads + * finish the qio_channel_read_all_eof() + */ + if (p->c) { + qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + } + qemu_mutex_unlock(&p->mutex); + } +} + +int multifd_load_cleanup(Error **errp) +{ + int i; + int ret =3D 0; + + if (!migrate_use_multifd()) { + return 0; + } + multifd_recv_terminate_threads(NULL); + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + if (p->running) { + p->quit =3D true; + /* + * multifd_recv_thread may hung at MULTIFD_FLAG_SYNC handle co= de, + * however try to wakeup it without harm in cleanup phase. + */ + qemu_sem_post(&p->sem_sync); + qemu_thread_join(&p->thread); + } + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + object_unref(OBJECT(p->c)); + p->c =3D NULL; + qemu_mutex_destroy(&p->mutex); + qemu_sem_destroy(&p->sem_sync); + g_free(p->name); + p->name =3D NULL; + multifd_pages_clear(p->pages); + p->pages =3D NULL; + p->packet_len =3D 0; + g_free(p->packet); + p->packet =3D NULL; + } + qemu_sem_destroy(&multifd_recv_state->sem_sync); + g_free(multifd_recv_state->params); + multifd_recv_state->params =3D NULL; + g_free(multifd_recv_state); + multifd_recv_state =3D NULL; + + return ret; +} + +void multifd_recv_sync_main(void) +{ + int i; + + if (!migrate_use_multifd()) { + return; + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + trace_multifd_recv_sync_main_wait(p->id); + qemu_sem_wait(&multifd_recv_state->sem_sync); + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_mutex_lock(&p->mutex); + if (multifd_recv_state->packet_num < p->packet_num) { + multifd_recv_state->packet_num =3D p->packet_num; + } + qemu_mutex_unlock(&p->mutex); + trace_multifd_recv_sync_main_signal(p->id); + qemu_sem_post(&p->sem_sync); + } + trace_multifd_recv_sync_main(multifd_recv_state->packet_num); +} + +static void *multifd_recv_thread(void *opaque) +{ + MultiFDRecvParams *p =3D opaque; + Error *local_err =3D NULL; + int ret; + + trace_multifd_recv_thread_start(p->id); + rcu_register_thread(); + + while (true) { + uint32_t used; + uint32_t flags; + + if (p->quit) { + break; + } + + ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret =3D=3D 0) { /* EOF */ + break; + } + if (ret =3D=3D -1) { /* Error */ + break; + } + + qemu_mutex_lock(&p->mutex); + ret =3D multifd_recv_unfill_packet(p, &local_err); + if (ret) { + qemu_mutex_unlock(&p->mutex); + break; + } + + used =3D p->pages->used; + flags =3D p->flags; + trace_multifd_recv(p->id, p->packet_num, used, flags, + p->next_packet_size); + p->num_packets++; + p->num_pages +=3D used; + qemu_mutex_unlock(&p->mutex); + + if (used) { + ret =3D qio_channel_readv_all(p->c, p->pages->iov, + used, &local_err); + if (ret !=3D 0) { + break; + } + } + + if (flags & MULTIFD_FLAG_SYNC) { + qemu_sem_post(&multifd_recv_state->sem_sync); + qemu_sem_wait(&p->sem_sync); + } + } + + if (local_err) { + multifd_recv_terminate_threads(local_err); + } + qemu_mutex_lock(&p->mutex); + p->running =3D false; + qemu_mutex_unlock(&p->mutex); + + rcu_unregister_thread(); + trace_multifd_recv_thread_end(p->id, p->num_packets, p->num_pages); + + return NULL; +} + +int multifd_load_setup(Error **errp) +{ + int thread_count; + uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + uint8_t i; + + if (!migrate_use_multifd()) { + return 0; + } + thread_count =3D migrate_multifd_channels(); + multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); + multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); + atomic_set(&multifd_recv_state->count, 0); + qemu_sem_init(&multifd_recv_state->sem_sync, 0); + + for (i =3D 0; i < thread_count; i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_mutex_init(&p->mutex); + qemu_sem_init(&p->sem_sync, 0); + p->quit =3D false; + p->id =3D i; + p->pages =3D multifd_pages_init(page_count); + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(uint64_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); + p->name =3D g_strdup_printf("multifdrecv_%d", i); + } + return 0; +} + +bool multifd_recv_all_channels_created(void) +{ + int thread_count =3D migrate_multifd_channels(); + + if (!migrate_use_multifd()) { + return true; + } + + return thread_count =3D=3D atomic_read(&multifd_recv_state->count); +} + +/* + * Try to receive all multifd channels to get ready for the migration. + * - Return true and do not set @errp when correctly receving all channels; + * - Return false and do not set @errp when correctly receiving the curren= t one; + * - Return false and set @errp when failing to receive the current channe= l. + */ +bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) +{ + MultiFDRecvParams *p; + Error *local_err =3D NULL; + int id; + + id =3D multifd_recv_initial_packet(ioc, &local_err); + if (id < 0) { + multifd_recv_terminate_threads(local_err); + error_propagate_prepend(errp, local_err, + "failed to receive packet" + " via multifd channel %d: ", + atomic_read(&multifd_recv_state->count)); + return false; + } + trace_multifd_recv_new_channel(id); + + p =3D &multifd_recv_state->params[id]; + if (p->c !=3D NULL) { + error_setg(&local_err, "multifd: received id '%d' already setup'", + id); + multifd_recv_terminate_threads(local_err); + error_propagate(errp, local_err); + return false; + } + p->c =3D ioc; + object_ref(OBJECT(ioc)); + /* initial packet */ + p->num_packets =3D 1; + + p->running =3D true; + qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, + QEMU_THREAD_JOINABLE); + atomic_inc(&multifd_recv_state->count); + return atomic_read(&multifd_recv_state->count) =3D=3D + migrate_multifd_channels(); +} + diff --git a/migration/multifd.h b/migration/multifd.h new file mode 100644 index 0000000000..d8b0205977 --- /dev/null +++ b/migration/multifd.h @@ -0,0 +1,139 @@ +/* + * Multifd common functions + * + * Copyright (c) 2019-2020 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_MIGRATION_MULTIFD_H +#define QEMU_MIGRATION_MULTIFD_H + +int multifd_save_setup(Error **errp); +void multifd_save_cleanup(void); +int multifd_load_setup(Error **errp); +int multifd_load_cleanup(Error **errp); +bool multifd_recv_all_channels_created(void); +bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp); +void multifd_recv_sync_main(void); +void multifd_send_sync_main(QEMUFile *f); +int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); + +#define MULTIFD_FLAG_SYNC (1 << 0) + +/* This value needs to be a multiple of qemu_target_page_size() */ +#define MULTIFD_PACKET_SIZE (512 * 1024) + +typedef struct { + uint32_t magic; + uint32_t version; + uint32_t flags; + /* maximum number of allocated pages */ + uint32_t pages_alloc; + uint32_t pages_used; + /* size of the next packet that contains pages */ + uint32_t next_packet_size; + uint64_t packet_num; + uint64_t unused[4]; /* Reserved for future use */ + char ramblock[256]; + uint64_t offset[]; +} __attribute__((packed)) MultiFDPacket_t; + +typedef struct { + /* number of used pages */ + uint32_t used; + /* number of allocated pages */ + uint32_t allocated; + /* global number of generated multifd packets */ + uint64_t packet_num; + /* offset of each page */ + ram_addr_t *offset; + /* pointer to each page */ + struct iovec *iov; + RAMBlock *block; +} MultiFDPages_t; + +typedef struct { + /* this fields are not changed once the thread is created */ + /* channel number */ + uint8_t id; + /* channel thread name */ + char *name; + /* channel thread id */ + QemuThread thread; + /* communication channel */ + QIOChannel *c; + /* sem where to wait for more work */ + QemuSemaphore sem; + /* this mutex protects the following parameters */ + QemuMutex mutex; + /* is this channel thread running */ + bool running; + /* should this thread finish */ + bool quit; + /* thread has work to do */ + int pending_job; + /* array of pages to sent */ + MultiFDPages_t *pages; + /* packet allocated len */ + uint32_t packet_len; + /* pointer to the packet */ + MultiFDPacket_t *packet; + /* multifd flags for each packet */ + uint32_t flags; + /* size of the next packet that contains pages */ + uint32_t next_packet_size; + /* global number of generated multifd packets */ + uint64_t packet_num; + /* thread local variables */ + /* packets sent through this channel */ + uint64_t num_packets; + /* pages sent through this channel */ + uint64_t num_pages; + /* syncs main thread and channels */ + QemuSemaphore sem_sync; +} MultiFDSendParams; + +typedef struct { + /* this fields are not changed once the thread is created */ + /* channel number */ + uint8_t id; + /* channel thread name */ + char *name; + /* channel thread id */ + QemuThread thread; + /* communication channel */ + QIOChannel *c; + /* this mutex protects the following parameters */ + QemuMutex mutex; + /* is this channel thread running */ + bool running; + /* should this thread finish */ + bool quit; + /* array of pages to receive */ + MultiFDPages_t *pages; + /* packet allocated len */ + uint32_t packet_len; + /* pointer to the packet */ + MultiFDPacket_t *packet; + /* multifd flags for each packet */ + uint32_t flags; + /* global number of generated multifd packets */ + uint64_t packet_num; + /* thread local variables */ + /* size of the next packet that contains pages */ + uint32_t next_packet_size; + /* packets sent through this channel */ + uint64_t num_packets; + /* pages sent through this channel */ + uint64_t num_pages; + /* syncs main thread and channels */ + QemuSemaphore sem_sync; +} MultiFDRecvParams; + +#endif + diff --git a/migration/ram.c b/migration/ram.c index c24b4cc771..ed23ed1c7c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -36,7 +36,6 @@ #include "xbzrle.h" #include "ram.h" #include "migration.h" -#include "socket.h" #include "migration/register.h" #include "migration/misc.h" #include "qemu-file.h" @@ -53,9 +52,9 @@ #include "migration/colo.h" #include "block.h" #include "sysemu/sysemu.h" -#include "qemu/uuid.h" #include "savevm.h" #include "qemu/iov.h" +#include "multifd.h" =20 /***********************************************************/ /* ram save/restore */ @@ -575,983 +574,6 @@ exit: return -1; } =20 -/* Multiple fd's */ - -#define MULTIFD_MAGIC 0x11223344U -#define MULTIFD_VERSION 1 - -#define MULTIFD_FLAG_SYNC (1 << 0) - -/* This value needs to be a multiple of qemu_target_page_size() */ -#define MULTIFD_PACKET_SIZE (512 * 1024) - -typedef struct { - uint32_t magic; - uint32_t version; - unsigned char uuid[16]; /* QemuUUID */ - uint8_t id; - uint8_t unused1[7]; /* Reserved for future use */ - uint64_t unused2[4]; /* Reserved for future use */ -} __attribute__((packed)) MultiFDInit_t; - -typedef struct { - uint32_t magic; - uint32_t version; - uint32_t flags; - /* maximum number of allocated pages */ - uint32_t pages_alloc; - uint32_t pages_used; - /* size of the next packet that contains pages */ - uint32_t next_packet_size; - uint64_t packet_num; - uint64_t unused[4]; /* Reserved for future use */ - char ramblock[256]; - uint64_t offset[]; -} __attribute__((packed)) MultiFDPacket_t; - -typedef struct { - /* number of used pages */ - uint32_t used; - /* number of allocated pages */ - uint32_t allocated; - /* global number of generated multifd packets */ - uint64_t packet_num; - /* offset of each page */ - ram_addr_t *offset; - /* pointer to each page */ - struct iovec *iov; - RAMBlock *block; -} MultiFDPages_t; - -typedef struct { - /* this fields are not changed once the thread is created */ - /* channel number */ - uint8_t id; - /* channel thread name */ - char *name; - /* channel thread id */ - QemuThread thread; - /* communication channel */ - QIOChannel *c; - /* sem where to wait for more work */ - QemuSemaphore sem; - /* this mutex protects the following parameters */ - QemuMutex mutex; - /* is this channel thread running */ - bool running; - /* should this thread finish */ - bool quit; - /* thread has work to do */ - int pending_job; - /* array of pages to sent */ - MultiFDPages_t *pages; - /* packet allocated len */ - uint32_t packet_len; - /* pointer to the packet */ - MultiFDPacket_t *packet; - /* multifd flags for each packet */ - uint32_t flags; - /* size of the next packet that contains pages */ - uint32_t next_packet_size; - /* global number of generated multifd packets */ - uint64_t packet_num; - /* thread local variables */ - /* packets sent through this channel */ - uint64_t num_packets; - /* pages sent through this channel */ - uint64_t num_pages; - /* syncs main thread and channels */ - QemuSemaphore sem_sync; -} MultiFDSendParams; - -typedef struct { - /* this fields are not changed once the thread is created */ - /* channel number */ - uint8_t id; - /* channel thread name */ - char *name; - /* channel thread id */ - QemuThread thread; - /* communication channel */ - QIOChannel *c; - /* this mutex protects the following parameters */ - QemuMutex mutex; - /* is this channel thread running */ - bool running; - /* should this thread finish */ - bool quit; - /* array of pages to receive */ - MultiFDPages_t *pages; - /* packet allocated len */ - uint32_t packet_len; - /* pointer to the packet */ - MultiFDPacket_t *packet; - /* multifd flags for each packet */ - uint32_t flags; - /* global number of generated multifd packets */ - uint64_t packet_num; - /* thread local variables */ - /* size of the next packet that contains pages */ - uint32_t next_packet_size; - /* packets sent through this channel */ - uint64_t num_packets; - /* pages sent through this channel */ - uint64_t num_pages; - /* syncs main thread and channels */ - QemuSemaphore sem_sync; -} MultiFDRecvParams; - -static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) -{ - MultiFDInit_t msg =3D {}; - int ret; - - msg.magic =3D cpu_to_be32(MULTIFD_MAGIC); - msg.version =3D cpu_to_be32(MULTIFD_VERSION); - msg.id =3D p->id; - memcpy(msg.uuid, &qemu_uuid.data, sizeof(msg.uuid)); - - ret =3D qio_channel_write_all(p->c, (char *)&msg, sizeof(msg), errp); - if (ret !=3D 0) { - return -1; - } - return 0; -} - -static int multifd_recv_initial_packet(QIOChannel *c, Error **errp) -{ - MultiFDInit_t msg; - int ret; - - ret =3D qio_channel_read_all(c, (char *)&msg, sizeof(msg), errp); - if (ret !=3D 0) { - return -1; - } - - msg.magic =3D be32_to_cpu(msg.magic); - msg.version =3D be32_to_cpu(msg.version); - - if (msg.magic !=3D MULTIFD_MAGIC) { - error_setg(errp, "multifd: received packet magic %x " - "expected %x", msg.magic, MULTIFD_MAGIC); - return -1; - } - - if (msg.version !=3D MULTIFD_VERSION) { - error_setg(errp, "multifd: received packet version %d " - "expected %d", msg.version, MULTIFD_VERSION); - return -1; - } - - if (memcmp(msg.uuid, &qemu_uuid, sizeof(qemu_uuid))) { - char *uuid =3D qemu_uuid_unparse_strdup(&qemu_uuid); - char *msg_uuid =3D qemu_uuid_unparse_strdup((const QemuUUID *)msg.= uuid); - - error_setg(errp, "multifd: received uuid '%s' and expected " - "uuid '%s' for channel %hhd", msg_uuid, uuid, msg.id); - g_free(uuid); - g_free(msg_uuid); - return -1; - } - - if (msg.id > migrate_multifd_channels()) { - error_setg(errp, "multifd: received channel version %d " - "expected %d", msg.version, MULTIFD_VERSION); - return -1; - } - - return msg.id; -} - -static MultiFDPages_t *multifd_pages_init(size_t size) -{ - MultiFDPages_t *pages =3D g_new0(MultiFDPages_t, 1); - - pages->allocated =3D size; - pages->iov =3D g_new0(struct iovec, size); - pages->offset =3D g_new0(ram_addr_t, size); - - return pages; -} - -static void multifd_pages_clear(MultiFDPages_t *pages) -{ - pages->used =3D 0; - pages->allocated =3D 0; - pages->packet_num =3D 0; - pages->block =3D NULL; - g_free(pages->iov); - pages->iov =3D NULL; - g_free(pages->offset); - pages->offset =3D NULL; - g_free(pages); -} - -static void multifd_send_fill_packet(MultiFDSendParams *p) -{ - MultiFDPacket_t *packet =3D p->packet; - int i; - - packet->flags =3D cpu_to_be32(p->flags); - packet->pages_alloc =3D cpu_to_be32(p->pages->allocated); - packet->pages_used =3D cpu_to_be32(p->pages->used); - packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); - packet->packet_num =3D cpu_to_be64(p->packet_num); - - if (p->pages->block) { - strncpy(packet->ramblock, p->pages->block->idstr, 256); - } - - for (i =3D 0; i < p->pages->used; i++) { - /* there are architectures where ram_addr_t is 32 bit */ - uint64_t temp =3D p->pages->offset[i]; - - packet->offset[i] =3D cpu_to_be64(temp); - } -} - -static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) -{ - MultiFDPacket_t *packet =3D p->packet; - uint32_t pages_max =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); - RAMBlock *block; - int i; - - packet->magic =3D be32_to_cpu(packet->magic); - if (packet->magic !=3D MULTIFD_MAGIC) { - error_setg(errp, "multifd: received packet " - "magic %x and expected magic %x", - packet->magic, MULTIFD_MAGIC); - return -1; - } - - packet->version =3D be32_to_cpu(packet->version); - if (packet->version !=3D MULTIFD_VERSION) { - error_setg(errp, "multifd: received packet " - "version %d and expected version %d", - packet->version, MULTIFD_VERSION); - return -1; - } - - p->flags =3D be32_to_cpu(packet->flags); - - packet->pages_alloc =3D be32_to_cpu(packet->pages_alloc); - /* - * If we received a packet that is 100 times bigger than expected - * just stop migration. It is a magic number. - */ - if (packet->pages_alloc > pages_max * 100) { - error_setg(errp, "multifd: received packet " - "with size %d and expected a maximum size of %d", - packet->pages_alloc, pages_max * 100) ; - return -1; - } - /* - * We received a packet that is bigger than expected but inside - * reasonable limits (see previous comment). Just reallocate. - */ - if (packet->pages_alloc > p->pages->allocated) { - multifd_pages_clear(p->pages); - p->pages =3D multifd_pages_init(packet->pages_alloc); - } - - p->pages->used =3D be32_to_cpu(packet->pages_used); - if (p->pages->used > packet->pages_alloc) { - error_setg(errp, "multifd: received packet " - "with %d pages and expected maximum pages are %d", - p->pages->used, packet->pages_alloc) ; - return -1; - } - - p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); - p->packet_num =3D be64_to_cpu(packet->packet_num); - - if (p->pages->used =3D=3D 0) { - return 0; - } - - /* make sure that ramblock is 0 terminated */ - packet->ramblock[255] =3D 0; - block =3D qemu_ram_block_by_name(packet->ramblock); - if (!block) { - error_setg(errp, "multifd: unknown ram block %s", - packet->ramblock); - return -1; - } - - for (i =3D 0; i < p->pages->used; i++) { - uint64_t offset =3D be64_to_cpu(packet->offset[i]); - - if (offset > (block->used_length - qemu_target_page_size())) { - error_setg(errp, "multifd: offset too long %" PRIu64 - " (max " RAM_ADDR_FMT ")", - offset, block->max_length); - return -1; - } - p->pages->iov[i].iov_base =3D block->host + offset; - p->pages->iov[i].iov_len =3D qemu_target_page_size(); - } - - return 0; -} - -struct { - MultiFDSendParams *params; - /* array of pages to sent */ - MultiFDPages_t *pages; - /* global number of generated multifd packets */ - uint64_t packet_num; - /* send channels ready */ - QemuSemaphore channels_ready; - /* - * Have we already run terminate threads. There is a race when it - * happens that we got one error while we are exiting. - * We will use atomic operations. Only valid values are 0 and 1. - */ - int exiting; -} *multifd_send_state; - -/* - * How we use multifd_send_state->pages and channel->pages? - * - * We create a pages for each channel, and a main one. Each time that - * we need to send a batch of pages we interchange the ones between - * multifd_send_state and the channel that is sending it. There are - * two reasons for that: - * - to not have to do so many mallocs during migration - * - to make easier to know what to free at the end of migration - * - * This way we always know who is the owner of each "pages" struct, - * and we don't need any locking. It belongs to the migration thread - * or to the channel thread. Switching is safe because the migration - * thread is using the channel mutex when changing it, and the channel - * have to had finish with its own, otherwise pending_job can't be - * false. - */ - -static int multifd_send_pages(QEMUFile *f) -{ - int i; - static int next_channel; - MultiFDSendParams *p =3D NULL; /* make happy gcc */ - MultiFDPages_t *pages =3D multifd_send_state->pages; - uint64_t transferred; - - if (atomic_read(&multifd_send_state->exiting)) { - return -1; - } - - qemu_sem_wait(&multifd_send_state->channels_ready); - for (i =3D next_channel;; i =3D (i + 1) % migrate_multifd_channels()) { - p =3D &multifd_send_state->params[i]; - - qemu_mutex_lock(&p->mutex); - if (p->quit) { - error_report("%s: channel %d has already quit!", __func__, i); - qemu_mutex_unlock(&p->mutex); - return -1; - } - if (!p->pending_job) { - p->pending_job++; - next_channel =3D (i + 1) % migrate_multifd_channels(); - break; - } - qemu_mutex_unlock(&p->mutex); - } - assert(!p->pages->used); - assert(!p->pages->block); - - p->packet_num =3D multifd_send_state->packet_num++; - multifd_send_state->pages =3D p->pages; - p->pages =3D pages; - transferred =3D ((uint64_t) pages->used) * qemu_target_page_size() - + p->packet_len; - qemu_file_update_transfer(f, transferred); - ram_counters.multifd_bytes +=3D transferred; - ram_counters.transferred +=3D transferred;; - qemu_mutex_unlock(&p->mutex); - qemu_sem_post(&p->sem); - - return 1; -} - -static int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t off= set) -{ - MultiFDPages_t *pages =3D multifd_send_state->pages; - - if (!pages->block) { - pages->block =3D block; - } - - if (pages->block =3D=3D block) { - pages->offset[pages->used] =3D offset; - pages->iov[pages->used].iov_base =3D block->host + offset; - pages->iov[pages->used].iov_len =3D qemu_target_page_size(); - pages->used++; - - if (pages->used < pages->allocated) { - return 1; - } - } - - if (multifd_send_pages(f) < 0) { - return -1; - } - - if (pages->block !=3D block) { - return multifd_queue_page(f, block, offset); - } - - return 1; -} - -static void multifd_send_terminate_threads(Error *err) -{ - int i; - - trace_multifd_send_terminate_threads(err !=3D NULL); - - if (err) { - MigrationState *s =3D migrate_get_current(); - migrate_set_error(s, err); - if (s->state =3D=3D MIGRATION_STATUS_SETUP || - s->state =3D=3D MIGRATION_STATUS_PRE_SWITCHOVER || - s->state =3D=3D MIGRATION_STATUS_DEVICE || - s->state =3D=3D MIGRATION_STATUS_ACTIVE) { - migrate_set_state(&s->state, s->state, - MIGRATION_STATUS_FAILED); - } - } - - /* - * We don't want to exit each threads twice. Depending on where - * we get the error, or if there are two independent errors in two - * threads at the same time, we can end calling this function - * twice. - */ - if (atomic_xchg(&multifd_send_state->exiting, 1)) { - return; - } - - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - qemu_mutex_lock(&p->mutex); - p->quit =3D true; - qemu_sem_post(&p->sem); - qemu_mutex_unlock(&p->mutex); - } -} - -void multifd_save_cleanup(void) -{ - int i; - - if (!migrate_use_multifd()) { - return; - } - multifd_send_terminate_threads(NULL); - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - if (p->running) { - qemu_thread_join(&p->thread); - } - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - socket_send_channel_destroy(p->c); - p->c =3D NULL; - qemu_mutex_destroy(&p->mutex); - qemu_sem_destroy(&p->sem); - qemu_sem_destroy(&p->sem_sync); - g_free(p->name); - p->name =3D NULL; - multifd_pages_clear(p->pages); - p->pages =3D NULL; - p->packet_len =3D 0; - g_free(p->packet); - p->packet =3D NULL; - } - qemu_sem_destroy(&multifd_send_state->channels_ready); - g_free(multifd_send_state->params); - multifd_send_state->params =3D NULL; - multifd_pages_clear(multifd_send_state->pages); - multifd_send_state->pages =3D NULL; - g_free(multifd_send_state); - multifd_send_state =3D NULL; -} - -static void multifd_send_sync_main(QEMUFile *f) -{ - int i; - - if (!migrate_use_multifd()) { - return; - } - if (multifd_send_state->pages->used) { - if (multifd_send_pages(f) < 0) { - error_report("%s: multifd_send_pages fail", __func__); - return; - } - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - trace_multifd_send_sync_main_signal(p->id); - - qemu_mutex_lock(&p->mutex); - - if (p->quit) { - error_report("%s: channel %d has already quit", __func__, i); - qemu_mutex_unlock(&p->mutex); - return; - } - - p->packet_num =3D multifd_send_state->packet_num++; - p->flags |=3D MULTIFD_FLAG_SYNC; - p->pending_job++; - qemu_file_update_transfer(f, p->packet_len); - ram_counters.multifd_bytes +=3D p->packet_len; - ram_counters.transferred +=3D p->packet_len; - qemu_mutex_unlock(&p->mutex); - qemu_sem_post(&p->sem); - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - trace_multifd_send_sync_main_wait(p->id); - qemu_sem_wait(&p->sem_sync); - } - trace_multifd_send_sync_main(multifd_send_state->packet_num); -} - -static void *multifd_send_thread(void *opaque) -{ - MultiFDSendParams *p =3D opaque; - Error *local_err =3D NULL; - int ret =3D 0; - uint32_t flags =3D 0; - - trace_multifd_send_thread_start(p->id); - rcu_register_thread(); - - if (multifd_send_initial_packet(p, &local_err) < 0) { - ret =3D -1; - goto out; - } - /* initial packet */ - p->num_packets =3D 1; - - while (true) { - qemu_sem_wait(&p->sem); - - if (atomic_read(&multifd_send_state->exiting)) { - break; - } - qemu_mutex_lock(&p->mutex); - - if (p->pending_job) { - uint32_t used =3D p->pages->used; - uint64_t packet_num =3D p->packet_num; - flags =3D p->flags; - - p->next_packet_size =3D used * qemu_target_page_size(); - multifd_send_fill_packet(p); - p->flags =3D 0; - p->num_packets++; - p->num_pages +=3D used; - p->pages->used =3D 0; - p->pages->block =3D NULL; - qemu_mutex_unlock(&p->mutex); - - trace_multifd_send(p->id, packet_num, used, flags, - p->next_packet_size); - - ret =3D qio_channel_write_all(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret !=3D 0) { - break; - } - - if (used) { - ret =3D qio_channel_writev_all(p->c, p->pages->iov, - used, &local_err); - if (ret !=3D 0) { - break; - } - } - - qemu_mutex_lock(&p->mutex); - p->pending_job--; - qemu_mutex_unlock(&p->mutex); - - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&p->sem_sync); - } - qemu_sem_post(&multifd_send_state->channels_ready); - } else if (p->quit) { - qemu_mutex_unlock(&p->mutex); - break; - } else { - qemu_mutex_unlock(&p->mutex); - /* sometimes there are spurious wakeups */ - } - } - -out: - if (local_err) { - trace_multifd_send_error(p->id); - multifd_send_terminate_threads(local_err); - } - - /* - * Error happen, I will exit, but I can't just leave, tell - * who pay attention to me. - */ - if (ret !=3D 0) { - qemu_sem_post(&p->sem_sync); - qemu_sem_post(&multifd_send_state->channels_ready); - } - - qemu_mutex_lock(&p->mutex); - p->running =3D false; - qemu_mutex_unlock(&p->mutex); - - rcu_unregister_thread(); - trace_multifd_send_thread_end(p->id, p->num_packets, p->num_pages); - - return NULL; -} - -static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) -{ - MultiFDSendParams *p =3D opaque; - QIOChannel *sioc =3D QIO_CHANNEL(qio_task_get_source(task)); - Error *local_err =3D NULL; - - trace_multifd_new_send_channel_async(p->id); - if (qio_task_propagate_error(task, &local_err)) { - migrate_set_error(migrate_get_current(), local_err); - multifd_save_cleanup(); - } else { - p->c =3D QIO_CHANNEL(sioc); - qio_channel_set_delay(p->c, false); - p->running =3D true; - qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE); - } -} - -int multifd_save_setup(Error **errp) -{ - int thread_count; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); - uint8_t i; - - if (!migrate_use_multifd()) { - return 0; - } - thread_count =3D migrate_multifd_channels(); - multifd_send_state =3D g_malloc0(sizeof(*multifd_send_state)); - multifd_send_state->params =3D g_new0(MultiFDSendParams, thread_count); - multifd_send_state->pages =3D multifd_pages_init(page_count); - qemu_sem_init(&multifd_send_state->channels_ready, 0); - atomic_set(&multifd_send_state->exiting, 0); - - for (i =3D 0; i < thread_count; i++) { - MultiFDSendParams *p =3D &multifd_send_state->params[i]; - - qemu_mutex_init(&p->mutex); - qemu_sem_init(&p->sem, 0); - qemu_sem_init(&p->sem_sync, 0); - p->quit =3D false; - p->pending_job =3D 0; - p->id =3D i; - p->pages =3D multifd_pages_init(page_count); - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); - p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); - p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); - p->name =3D g_strdup_printf("multifdsend_%d", i); - socket_send_channel_create(multifd_new_send_channel_async, p); - } - return 0; -} - -struct { - MultiFDRecvParams *params; - /* number of created threads */ - int count; - /* syncs main thread and channels */ - QemuSemaphore sem_sync; - /* global number of generated multifd packets */ - uint64_t packet_num; -} *multifd_recv_state; - -static void multifd_recv_terminate_threads(Error *err) -{ - int i; - - trace_multifd_recv_terminate_threads(err !=3D NULL); - - if (err) { - MigrationState *s =3D migrate_get_current(); - migrate_set_error(s, err); - if (s->state =3D=3D MIGRATION_STATUS_SETUP || - s->state =3D=3D MIGRATION_STATUS_ACTIVE) { - migrate_set_state(&s->state, s->state, - MIGRATION_STATUS_FAILED); - } - } - - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - qemu_mutex_lock(&p->mutex); - p->quit =3D true; - /* - * We could arrive here for two reasons: - * - normal quit, i.e. everything went fine, just finished - * - error quit: We close the channels so the channel threads - * finish the qio_channel_read_all_eof() - */ - if (p->c) { - qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - } - qemu_mutex_unlock(&p->mutex); - } -} - -int multifd_load_cleanup(Error **errp) -{ - int i; - int ret =3D 0; - - if (!migrate_use_multifd()) { - return 0; - } - multifd_recv_terminate_threads(NULL); - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - if (p->running) { - p->quit =3D true; - /* - * multifd_recv_thread may hung at MULTIFD_FLAG_SYNC handle co= de, - * however try to wakeup it without harm in cleanup phase. - */ - qemu_sem_post(&p->sem_sync); - qemu_thread_join(&p->thread); - } - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - object_unref(OBJECT(p->c)); - p->c =3D NULL; - qemu_mutex_destroy(&p->mutex); - qemu_sem_destroy(&p->sem_sync); - g_free(p->name); - p->name =3D NULL; - multifd_pages_clear(p->pages); - p->pages =3D NULL; - p->packet_len =3D 0; - g_free(p->packet); - p->packet =3D NULL; - } - qemu_sem_destroy(&multifd_recv_state->sem_sync); - g_free(multifd_recv_state->params); - multifd_recv_state->params =3D NULL; - g_free(multifd_recv_state); - multifd_recv_state =3D NULL; - - return ret; -} - -static void multifd_recv_sync_main(void) -{ - int i; - - if (!migrate_use_multifd()) { - return; - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - trace_multifd_recv_sync_main_wait(p->id); - qemu_sem_wait(&multifd_recv_state->sem_sync); - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - qemu_mutex_lock(&p->mutex); - if (multifd_recv_state->packet_num < p->packet_num) { - multifd_recv_state->packet_num =3D p->packet_num; - } - qemu_mutex_unlock(&p->mutex); - trace_multifd_recv_sync_main_signal(p->id); - qemu_sem_post(&p->sem_sync); - } - trace_multifd_recv_sync_main(multifd_recv_state->packet_num); -} - -static void *multifd_recv_thread(void *opaque) -{ - MultiFDRecvParams *p =3D opaque; - Error *local_err =3D NULL; - int ret; - - trace_multifd_recv_thread_start(p->id); - rcu_register_thread(); - - while (true) { - uint32_t used; - uint32_t flags; - - if (p->quit) { - break; - } - - ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret =3D=3D 0) { /* EOF */ - break; - } - if (ret =3D=3D -1) { /* Error */ - break; - } - - qemu_mutex_lock(&p->mutex); - ret =3D multifd_recv_unfill_packet(p, &local_err); - if (ret) { - qemu_mutex_unlock(&p->mutex); - break; - } - - used =3D p->pages->used; - flags =3D p->flags; - trace_multifd_recv(p->id, p->packet_num, used, flags, - p->next_packet_size); - p->num_packets++; - p->num_pages +=3D used; - qemu_mutex_unlock(&p->mutex); - - if (used) { - ret =3D qio_channel_readv_all(p->c, p->pages->iov, - used, &local_err); - if (ret !=3D 0) { - break; - } - } - - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&multifd_recv_state->sem_sync); - qemu_sem_wait(&p->sem_sync); - } - } - - if (local_err) { - multifd_recv_terminate_threads(local_err); - } - qemu_mutex_lock(&p->mutex); - p->running =3D false; - qemu_mutex_unlock(&p->mutex); - - rcu_unregister_thread(); - trace_multifd_recv_thread_end(p->id, p->num_packets, p->num_pages); - - return NULL; -} - -int multifd_load_setup(Error **errp) -{ - int thread_count; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); - uint8_t i; - - if (!migrate_use_multifd()) { - return 0; - } - thread_count =3D migrate_multifd_channels(); - multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); - multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); - atomic_set(&multifd_recv_state->count, 0); - qemu_sem_init(&multifd_recv_state->sem_sync, 0); - - for (i =3D 0; i < thread_count; i++) { - MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; - - qemu_mutex_init(&p->mutex); - qemu_sem_init(&p->sem_sync, 0); - p->quit =3D false; - p->id =3D i; - p->pages =3D multifd_pages_init(page_count); - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); - p->name =3D g_strdup_printf("multifdrecv_%d", i); - } - return 0; -} - -bool multifd_recv_all_channels_created(void) -{ - int thread_count =3D migrate_multifd_channels(); - - if (!migrate_use_multifd()) { - return true; - } - - return thread_count =3D=3D atomic_read(&multifd_recv_state->count); -} - -/* - * Try to receive all multifd channels to get ready for the migration. - * - Return true and do not set @errp when correctly receving all channels; - * - Return false and do not set @errp when correctly receiving the curren= t one; - * - Return false and set @errp when failing to receive the current channe= l. - */ -bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) -{ - MultiFDRecvParams *p; - Error *local_err =3D NULL; - int id; - - id =3D multifd_recv_initial_packet(ioc, &local_err); - if (id < 0) { - multifd_recv_terminate_threads(local_err); - error_propagate_prepend(errp, local_err, - "failed to receive packet" - " via multifd channel %d: ", - atomic_read(&multifd_recv_state->count)); - return false; - } - trace_multifd_recv_new_channel(id); - - p =3D &multifd_recv_state->params[id]; - if (p->c !=3D NULL) { - error_setg(&local_err, "multifd: received id '%d' already setup'", - id); - multifd_recv_terminate_threads(local_err); - error_propagate(errp, local_err); - return false; - } - p->c =3D ioc; - object_ref(OBJECT(ioc)); - /* initial packet */ - p->num_packets =3D 1; - - p->running =3D true; - qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); - atomic_inc(&multifd_recv_state->count); - return atomic_read(&multifd_recv_state->count) =3D=3D - migrate_multifd_channels(); -} - /** * save_page_header: write page header to wire * diff --git a/migration/ram.h b/migration/ram.h index 42be471d52..a553d40751 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -41,13 +41,6 @@ int xbzrle_cache_resize(int64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); =20 -int multifd_save_setup(Error **errp); -void multifd_save_cleanup(void); -int multifd_load_setup(Error **errp); -int multifd_load_cleanup(Error **errp); -bool multifd_recv_all_channels_created(void); -bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp); - uint64_t ram_pagesize_summary(void); int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len); void acct_update_position(QEMUFile *f, size_t size, bool zero); --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579786282; cv=none; d=zohomail.com; s=zohoarc; b=eBZaBsf/dJCrWGL714YrTO2ZDM0afyE9fMAJDHdm77Jk22jKsOdhHVaMzYVnrBi3cPYpimwOXnqrsgWZTP3U4I/JgrKhManwtdaQg6cXiCWGrVQ1LLZzxXYrqHJgHaDO+9pFnKsqMM85sGbaS8hWlxF50dwBl5xpA1Uv1f3RrUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579786282; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/tN+lBVLn3pt3o4YBhLMASpYIaxSV/yTnqvOFAdRNOs=; b=Z9QJf8Qm4f2gbGaQSSPgpiovXqr81tCR8mdsWs9/x6129KkBe/W5oaqFxLL0CXikaTs+r5MC25rUzn3NI2fIc5ZwfYrpZt2o3Y1f7ExSiQ3+HQBbTzjkJHDK3xZngIunE6QFaQm6bwAwLyVQMhL3XSHVW/1u0bF4Cjm1wcwaecU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15797862821401009.1157962969913; Thu, 23 Jan 2020 05:31:22 -0800 (PST) Received: from localhost ([::1]:57072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucZs-0007FK-4c for importer@patchew.org; Thu, 23 Jan 2020 08:31:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40608) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub9A-0002VB-K0 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub97-0005DY-OX for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:40 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37779 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub97-0005DE-Eb for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-57-Fkxcu9Y9MmG93lLHnOek3g-1; Thu, 23 Jan 2020 06:59:35 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A49F58017CC for ; Thu, 23 Jan 2020 11:59:34 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65B9419C69; Thu, 23 Jan 2020 11:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/tN+lBVLn3pt3o4YBhLMASpYIaxSV/yTnqvOFAdRNOs=; b=hoX6IDdfWL+7BBO6hGvlr1yfepZHsOJ0ScM601G4586BBfm3JYLbDF6qTNwi0JX3AvwBDv sBIPtBetexsuby0/aomQ+uocE4YiKsJTPIUY9bV/cE4SkTr+v+DL+wULZ2C/HAUeEzeEGq jaxcXrVCyP1iyPpPZ4PU9F/PD6Hemos= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 18/21] migration: Make no compression operations into its own structure Date: Thu, 23 Jan 2020 12:58:28 +0100 Message-Id: <20200123115831.36842-19-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: Fkxcu9Y9MmG93lLHnOek3g-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It will be used later. Signed-off-by: Juan Quintela --- Move setup of ->ops helper to proper place (wei) Rename s/none/nocomp/ (dave) Introduce MULTIFD_FLAG_NOCOMP right order of arguments for print --- migration/migration.c | 9 +++ migration/migration.h | 1 + migration/multifd.c | 183 ++++++++++++++++++++++++++++++++++++++++-- migration/multifd.h | 22 +++++ migration/ram.c | 1 + 5 files changed, 208 insertions(+), 8 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 3501bc3353..d25fdb3e6b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2245,6 +2245,15 @@ int migrate_multifd_channels(void) return s->parameters.multifd_channels; } =20 +int migrate_multifd_method(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.multifd_compress; +} + int migrate_use_xbzrle(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index 8473ddfc88..3b0b413a93 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -300,6 +300,7 @@ bool migrate_auto_converge(void); bool migrate_use_multifd(void); bool migrate_pause_before_switchover(void); int migrate_multifd_channels(void); +int migrate_multifd_method(void); =20 int migrate_use_xbzrle(void); int64_t migrate_xbzrle_cache_size(void); diff --git a/migration/multifd.c b/migration/multifd.c index 1875bb3aaa..353140cd25 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -38,6 +38,132 @@ typedef struct { uint64_t unused2[4]; /* Reserved for future use */ } __attribute__((packed)) MultiFDInit_t; =20 +/* Multifd without compression */ + +/** + * nocomp_send_setup: setup send side + * + * For no compression this function does nothing. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @errp: pointer to an error + */ +static int nocomp_send_setup(MultiFDSendParams *p, Error **errp) +{ + return 0; +} + +/** + * nocomp_send_cleanup: cleanup send side + * + * For no compression this function does nothing. + * + * @p: Params for the channel that we are using + */ +static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp) +{ + return; +} + +/** + * nocomp_send_prepare: prepare date to be able to send + * + * For no compression we just have to calculate the size of the + * packet. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + * @errp: pointer to an error + */ +static int nocomp_send_prepare(MultiFDSendParams *p, uint32_t used, + Error **errp) +{ + p->next_packet_size =3D used * qemu_target_page_size(); + p->flags |=3D MULTIFD_FLAG_NOCOMP; + return 0; +} + +/** + * nocomp_send_write: do the actual write of the data + * + * For no compression we just have to write the data. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + * @errp: pointer to an error + */ +static int nocomp_send_write(MultiFDSendParams *p, uint32_t used, Error **= errp) +{ + return qio_channel_writev_all(p->c, p->pages->iov, used, errp); +} + +/** + * nocomp_recv_setup: setup receive side + * + * For no compression this function does nothing. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @errp: pointer to an error + */ +static int nocomp_recv_setup(MultiFDRecvParams *p, Error **errp) +{ + return 0; +} + +/** + * nocomp_recv_cleanup: setup receive side + * + * For no compression this function does nothing. + * + * @p: Params for the channel that we are using + */ +static void nocomp_recv_cleanup(MultiFDRecvParams *p) +{ +} + +/** + * nocomp_recv_pages: read the data from the channel into actual pages + * + * For no compression we just need to read things into the correct place. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + * @errp: pointer to an error + */ +static int nocomp_recv_pages(MultiFDRecvParams *p, uint32_t used, Error **= errp) +{ + if (p->flags !=3D MULTIFD_FLAG_NOCOMP) { + error_setg(errp, "multifd %d: flags received %x flags expected %x", + p->id, p->flags, MULTIFD_FLAG_NOCOMP); + return -1; + } + return qio_channel_readv_all(p->c, p->pages->iov, used, errp); +} + +static MultiFDMethods multifd_nocomp_ops =3D { + .send_setup =3D nocomp_send_setup, + .send_cleanup =3D nocomp_send_cleanup, + .send_prepare =3D nocomp_send_prepare, + .send_write =3D nocomp_send_write, + .recv_setup =3D nocomp_recv_setup, + .recv_cleanup =3D nocomp_recv_cleanup, + .recv_pages =3D nocomp_recv_pages +}; + +static MultiFDMethods *multifd_ops[MULTIFD_COMPRESS__MAX] =3D { + [MULTIFD_COMPRESS_NONE] =3D &multifd_nocomp_ops, +}; + static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) { MultiFDInit_t msg =3D {}; @@ -246,6 +372,8 @@ struct { * We will use atomic operations. Only valid values are 0 and 1. */ int exiting; + /* multifd ops */ + MultiFDMethods *ops; } *multifd_send_state; =20 /* @@ -397,6 +525,7 @@ void multifd_save_cleanup(void) } for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; + Error *local_err =3D NULL; =20 socket_send_channel_destroy(p->c); p->c =3D NULL; @@ -410,6 +539,10 @@ void multifd_save_cleanup(void) p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; + multifd_send_state->ops->send_cleanup(p, &local_err); + if (local_err) { + migrate_set_error(migrate_get_current(), local_err); + } } qemu_sem_destroy(&multifd_send_state->channels_ready); g_free(multifd_send_state->params); @@ -494,7 +627,14 @@ static void *multifd_send_thread(void *opaque) uint64_t packet_num =3D p->packet_num; flags =3D p->flags; =20 - p->next_packet_size =3D used * qemu_target_page_size(); + if (used) { + ret =3D multifd_send_state->ops->send_prepare(p, used, + &local_err); + if (ret !=3D 0) { + qemu_mutex_unlock(&p->mutex); + break; + } + } multifd_send_fill_packet(p); p->flags =3D 0; p->num_packets++; @@ -513,8 +653,7 @@ static void *multifd_send_thread(void *opaque) } =20 if (used) { - ret =3D qio_channel_writev_all(p->c, p->pages->iov, - used, &local_err); + ret =3D multifd_send_state->ops->send_write(p, used, &loca= l_err); if (ret !=3D 0) { break; } @@ -596,6 +735,7 @@ int multifd_save_setup(Error **errp) multifd_send_state->pages =3D multifd_pages_init(page_count); qemu_sem_init(&multifd_send_state->channels_ready, 0); atomic_set(&multifd_send_state->exiting, 0); + multifd_send_state->ops =3D multifd_ops[migrate_multifd_method()]; =20 for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; @@ -615,6 +755,18 @@ int multifd_save_setup(Error **errp) p->name =3D g_strdup_printf("multifdsend_%d", i); socket_send_channel_create(multifd_new_send_channel_async, p); } + + for (i =3D 0; i < thread_count; i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + Error *local_err =3D NULL; + int ret; + + ret =3D multifd_send_state->ops->send_setup(p, &local_err); + if (ret) { + error_propagate(errp, local_err); + return ret; + } + } return 0; } =20 @@ -626,6 +778,8 @@ struct { QemuSemaphore sem_sync; /* global number of generated multifd packets */ uint64_t packet_num; + /* multifd ops */ + MultiFDMethods *ops; } *multifd_recv_state; =20 static void multifd_recv_terminate_threads(Error *err) @@ -665,7 +819,6 @@ static void multifd_recv_terminate_threads(Error *err) int multifd_load_cleanup(Error **errp) { int i; - int ret =3D 0; =20 if (!migrate_use_multifd()) { return 0; @@ -698,6 +851,7 @@ int multifd_load_cleanup(Error **errp) p->packet_len =3D 0; g_free(p->packet); p->packet =3D NULL; + multifd_recv_state->ops->recv_cleanup(p); } qemu_sem_destroy(&multifd_recv_state->sem_sync); g_free(multifd_recv_state->params); @@ -705,7 +859,7 @@ int multifd_load_cleanup(Error **errp) g_free(multifd_recv_state); multifd_recv_state =3D NULL; =20 - return ret; + return 0; } =20 void multifd_recv_sync_main(void) @@ -770,6 +924,8 @@ static void *multifd_recv_thread(void *opaque) =20 used =3D p->pages->used; flags =3D p->flags; + /* recv methods don't know how to handle the SYNC flag */ + p->flags &=3D ~MULTIFD_FLAG_SYNC; trace_multifd_recv(p->id, p->packet_num, used, flags, p->next_packet_size); p->num_packets++; @@ -777,8 +933,7 @@ static void *multifd_recv_thread(void *opaque) qemu_mutex_unlock(&p->mutex); =20 if (used) { - ret =3D qio_channel_readv_all(p->c, p->pages->iov, - used, &local_err); + ret =3D multifd_recv_state->ops->recv_pages(p, used, &local_er= r); if (ret !=3D 0) { break; } @@ -817,6 +972,7 @@ int multifd_load_setup(Error **errp) multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); atomic_set(&multifd_recv_state->count, 0); qemu_sem_init(&multifd_recv_state->sem_sync, 0); + multifd_recv_state->ops =3D multifd_ops[migrate_multifd_method()]; =20 for (i =3D 0; i < thread_count; i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; @@ -831,6 +987,18 @@ int multifd_load_setup(Error **errp) p->packet =3D g_malloc0(p->packet_len); p->name =3D g_strdup_printf("multifdrecv_%d", i); } + + for (i =3D 0; i < thread_count; i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + Error *local_err =3D NULL; + int ret; + + ret =3D multifd_recv_state->ops->recv_setup(p, &local_err); + if (ret) { + error_propagate(errp, local_err); + return ret; + } + } return 0; } =20 @@ -888,4 +1056,3 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error *= *errp) return atomic_read(&multifd_recv_state->count) =3D=3D migrate_multifd_channels(); } - diff --git a/migration/multifd.h b/migration/multifd.h index d8b0205977..8edea4fdac 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -24,6 +24,7 @@ void multifd_send_sync_main(QEMUFile *f); int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); =20 #define MULTIFD_FLAG_SYNC (1 << 0) +#define MULTIFD_FLAG_NOCOMP (1 << 1) =20 /* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024) @@ -96,6 +97,8 @@ typedef struct { uint64_t num_pages; /* syncs main thread and channels */ QemuSemaphore sem_sync; + /* used for compression methods */ + void *data; } MultiFDSendParams; =20 typedef struct { @@ -133,7 +136,26 @@ typedef struct { uint64_t num_pages; /* syncs main thread and channels */ QemuSemaphore sem_sync; + /* used for de-compression methods */ + void *data; } MultiFDRecvParams; =20 +typedef struct { + /* Setup for sending side */ + int (*send_setup)(MultiFDSendParams *p, Error **errp); + /* Cleanup for sending side */ + void (*send_cleanup)(MultiFDSendParams *p, Error **errp); + /* Prepare the send packet */ + int (*send_prepare)(MultiFDSendParams *p, uint32_t used, Error **errp); + /* Write the send packet */ + int (*send_write)(MultiFDSendParams *p, uint32_t used, Error **errp); + /* Setup for receiving side */ + int (*recv_setup)(MultiFDRecvParams *p, Error **errp); + /* Cleanup for receiving side */ + void (*recv_cleanup)(MultiFDRecvParams *p); + /* Read all pages */ + int (*recv_pages)(MultiFDRecvParams *p, uint32_t used, Error **errp); +} MultiFDMethods; + #endif =20 diff --git a/migration/ram.c b/migration/ram.c index ed23ed1c7c..73a141bb60 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -43,6 +43,7 @@ #include "page_cache.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qapi/qapi-types-migration.h" #include "qapi/qapi-events-migration.h" #include "qapi/qmp/qerror.h" #include "trace.h" --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579787523; cv=none; d=zohomail.com; s=zohoarc; b=iIQPInP+QA5wzD4UBgprOIhrs2K89crE5MdOpbI6lr8EtjOF3QR6pSY1PJaAqPOVG1q7uPlj+z3j7kuLtuPOVK9WKEKTpKSmkij0eDAMvn1NT1A5h+h2DcPNvLKCXkNY+DAY8EhRkD0rx0n0zhRBKtVXEq/SE995l7ak85XpWJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579787523; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xlE5j2wEh6KrLdX3P6i9LTpKSQ12vQbUidlG5VXRlGM=; b=CBduQYuET/dxaBeIW5ovgO9ikaAgUxy4tvsk9k4Q+p94RnjxyoQTKHrNxu4d05I61p/Z6ePPGlrb498OBolkaYPNJqfpPsG5FXIjUNBjh1E4RJiUBMt9AsHoQ0e3POr7mK4gq8Je494KbJYi65NQRh2VAGZ58YeLOpySMd/l+SY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579787523340818.5366280385184; Thu, 23 Jan 2020 05:52:03 -0800 (PST) Received: from localhost ([::1]:57362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuctt-0008EE-RS for importer@patchew.org; Thu, 23 Jan 2020 08:52:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40714) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub9F-0002bA-01 for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub9C-0005HL-6t for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:44 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43522 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub9C-0005Gy-1n for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:42 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-QAA-Nsm6MXS8m79VT9roCQ-1; Thu, 23 Jan 2020 06:59:38 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E1651005512 for ; Thu, 23 Jan 2020 11:59:37 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08EA219C69; Thu, 23 Jan 2020 11:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xlE5j2wEh6KrLdX3P6i9LTpKSQ12vQbUidlG5VXRlGM=; b=MW5y9ee9VdIq/adlC4BGOjPcUKwT2C0Rq4Q+Z8aliHTjJo3vpOgGNCVtK1N6TiXNWWEpdV WyNqverWUEjZnLPR5kI6SOsWa4hF9aPQfOFp4h5Oh3R+kw/DP/ar86FBMiFQCvg8QBzfx8 frkvHeXGSPqUzv9pON26vtAmVi1lYX8= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 19/21] migration: Add zlib compression multifd support Date: Thu, 23 Jan 2020 12:58:29 +0100 Message-Id: <20200123115831.36842-20-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: QAA-Nsm6MXS8m79VT9roCQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela --- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/multifd-zlib.c | 289 +++++++++++++++++++++++++++++++++++ migration/multifd.c | 6 + migration/multifd.h | 4 + qapi/migration.json | 2 +- tests/qtest/migration-test.c | 6 + 7 files changed, 308 insertions(+), 2 deletions(-) create mode 100644 migration/multifd-zlib.c diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index ff6a752b19..07ec75d8e3 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -647,7 +647,7 @@ const PropertyInfo qdev_prop_fdc_drive_type =3D { const PropertyInfo qdev_prop_multifd_compress =3D { .name =3D "MultifdCompress", .description =3D "multifd_compress values, " - "none", + "none/zlib", .enum_table =3D &MultifdCompress_lookup, .get =3D get_enum, .set =3D set_enum, diff --git a/migration/Makefile.objs b/migration/Makefile.objs index d3623d5f9b..0308caa5c5 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -8,6 +8,7 @@ common-obj-y +=3D xbzrle.o postcopy-ram.o common-obj-y +=3D qjson.o common-obj-y +=3D block-dirty-bitmap.o common-obj-y +=3D multifd.o +common-obj-y +=3D multifd-zlib.o =20 common-obj-$(CONFIG_RDMA) +=3D rdma.o =20 diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c new file mode 100644 index 0000000000..33d7ee6741 --- /dev/null +++ b/migration/multifd-zlib.c @@ -0,0 +1,289 @@ +/* + * Multifd zlib compression implementation + * + * Copyright (c) 2020 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include +#include "qemu/rcu.h" +#include "exec/target_page.h" +#include "qapi/error.h" +#include "migration.h" +#include "trace.h" +#include "multifd.h" + +struct zlib_data { + /* stream for compression */ + z_stream zs; + /* compressed buffer */ + uint8_t *zbuff; + /* size of compressed buffer */ + uint32_t zbuff_len; +}; + +/* Multifd zlib compression */ + +/** + * zlib_send_setup: setup send side + * + * Setup each channel with zlib compression. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @errp: pointer to an error + */ +static int zlib_send_setup(MultiFDSendParams *p, Error **errp) +{ + uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + struct zlib_data *z =3D g_malloc0(sizeof(struct zlib_data)); + z_stream *zs =3D &z->zs; + + p->data =3D z; + zs->zalloc =3D Z_NULL; + zs->zfree =3D Z_NULL; + zs->opaque =3D Z_NULL; + if (deflateInit(zs, migrate_compress_level()) !=3D Z_OK) { + g_free(z); + error_setg(errp, "multifd %d: deflate init failed", p->id); + return -1; + } + /* We will never have more than page_count pages */ + z->zbuff_len =3D page_count * qemu_target_page_size(); + z->zbuff_len *=3D 2; + z->zbuff =3D g_try_malloc(z->zbuff_len); + if (!z->zbuff) { + g_free(z); + error_setg(errp, "multifd %d: out of memory for zbuff", p->id); + return -1; + } + return 0; +} + +/** + * zlib_send_cleanup: cleanup send side + * + * Close the channel and return memory. + * + * @p: Params for the channel that we are using + */ +static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp) +{ + struct zlib_data *z =3D p->data; + + deflateEnd(&z->zs); + g_free(z->zbuff); + z->zbuff =3D NULL; + g_free(p->data); + p->data =3D NULL; +} + +/** + * zlib_send_prepare: prepare date to be able to send + * + * Create a compressed buffer with all the pages that we are going to + * send. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + */ +static int zlib_send_prepare(MultiFDSendParams *p, uint32_t used, Error **= errp) +{ + struct iovec *iov =3D p->pages->iov; + struct zlib_data *z =3D p->data; + z_stream *zs =3D &z->zs; + uint32_t out_size =3D 0; + int ret; + uint32_t i; + + for (i =3D 0; i < used; i++) { + uint32_t available =3D z->zbuff_len - out_size; + int flush =3D Z_NO_FLUSH; + + if (i =3D=3D used - 1) { + flush =3D Z_SYNC_FLUSH; + } + + zs->avail_in =3D iov[i].iov_len; + zs->next_in =3D iov[i].iov_base; + + zs->avail_out =3D available; + zs->next_out =3D z->zbuff + out_size; + + ret =3D deflate(zs, flush); + if (ret !=3D Z_OK) { + error_setg(errp, "multifd %d: deflate returned %d instead of Z= _OK", + p->id, ret); + return -1; + } + out_size +=3D available - zs->avail_out; + } + p->next_packet_size =3D out_size; + p->flags |=3D MULTIFD_FLAG_ZLIB; + + return 0; +} + +/** + * zlib_send_write: do the actual write of the data + * + * Do the actual write of the comprresed buffer. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + * @errp: pointer to an error + */ +static int zlib_send_write(MultiFDSendParams *p, uint32_t used, Error **er= rp) +{ + struct zlib_data *z =3D p->data; + + return qio_channel_write_all(p->c, (void *)z->zbuff, p->next_packet_si= ze, + errp); +} + +/** + * zlib_recv_setup: setup receive side + * + * Create the compressed channel and buffer. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @errp: pointer to an error + */ +static int zlib_recv_setup(MultiFDRecvParams *p, Error **errp) +{ + uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + struct zlib_data *z =3D g_malloc0(sizeof(struct zlib_data)); + z_stream *zs =3D &z->zs; + + p->data =3D z; + zs->zalloc =3D Z_NULL; + zs->zfree =3D Z_NULL; + zs->opaque =3D Z_NULL; + zs->avail_in =3D 0; + zs->next_in =3D Z_NULL; + if (inflateInit(zs) !=3D Z_OK) { + error_setg(errp, "multifd %d: inflate init failed", p->id); + return -1; + } + /* We will never have more than page_count pages */ + z->zbuff_len =3D page_count * qemu_target_page_size(); + /* We know compression "could" use more space */ + z->zbuff_len *=3D 2; + z->zbuff =3D g_try_malloc(z->zbuff_len); + if (!z->zbuff) { + error_setg(errp, "multifd %d: out of memory for zbuff", p->id); + return -1; + } + return 0; +} + +/** + * zlib_recv_cleanup: setup receive side + * + * For no compression this function does nothing. + * + * @p: Params for the channel that we are using + */ +static void zlib_recv_cleanup(MultiFDRecvParams *p) +{ + struct zlib_data *z =3D p->data; + + inflateEnd(&z->zs); + g_free(z->zbuff); + z->zbuff =3D NULL; + g_free(p->data); + p->data =3D NULL; +} + +/** + * zlib_recv_pages: read the data from the channel into actual pages + * + * Read the compressed buffer, and uncompress it into the actual + * pages. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + * @errp: pointer to an error + */ +static int zlib_recv_pages(MultiFDRecvParams *p, uint32_t used, Error **er= rp) +{ + uint32_t in_size =3D p->next_packet_size; + uint32_t out_size =3D 0; + uint32_t expected_size =3D used * qemu_target_page_size(); + struct zlib_data *z =3D p->data; + z_stream *zs =3D &z->zs; + int ret; + int i; + + if (p->flags !=3D MULTIFD_FLAG_ZLIB) { + error_setg(errp, "multifd %d: flags received %x flags expected %x", + p->id, MULTIFD_FLAG_ZLIB, p->flags); + return -1; + } + ret =3D qio_channel_read_all(p->c, (void *)z->zbuff, in_size, errp); + + if (ret !=3D 0) { + return ret; + } + + zs->avail_in =3D in_size; + zs->next_in =3D z->zbuff; + + for (i =3D 0; i < used; i++) { + struct iovec *iov =3D &p->pages->iov[i]; + int flush =3D Z_NO_FLUSH; + + if (i =3D=3D used - 1) { + flush =3D Z_SYNC_FLUSH; + } + + zs->avail_out =3D iov->iov_len; + zs->next_out =3D iov->iov_base; + + ret =3D inflate(zs, flush); + if (ret !=3D Z_OK) { + error_setg(errp, "multifd %d: inflate returned %d instead of Z= _OK", + p->id, ret); + return ret; + } + out_size +=3D iov->iov_len; + } + if (out_size !=3D expected_size) { + error_setg(errp, "multifd %d: packet size received %d size expecte= d %d", + p->id, out_size, expected_size); + return -1; + } + return 0; +} + +static MultiFDMethods multifd_zlib_ops =3D { + .send_setup =3D zlib_send_setup, + .send_cleanup =3D zlib_send_cleanup, + .send_prepare =3D zlib_send_prepare, + .send_write =3D zlib_send_write, + .recv_setup =3D zlib_recv_setup, + .recv_cleanup =3D zlib_recv_cleanup, + .recv_pages =3D zlib_recv_pages +}; + +static void multifd_zlib_register(void) +{ + multifd_register_ops(MULTIFD_COMPRESS_ZLIB, &multifd_zlib_ops); +} + +migration_init(multifd_zlib_register); diff --git a/migration/multifd.c b/migration/multifd.c index 353140cd25..a1fc451d49 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -164,6 +164,12 @@ static MultiFDMethods *multifd_ops[MULTIFD_COMPRESS__M= AX] =3D { [MULTIFD_COMPRESS_NONE] =3D &multifd_nocomp_ops, }; =20 +void multifd_register_ops(int method, MultiFDMethods *ops) +{ + assert(0 < method && method < MULTIFD_COMPRESS__MAX); + multifd_ops[method] =3D ops; +} + static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) { MultiFDInit_t msg =3D {}; diff --git a/migration/multifd.h b/migration/multifd.h index 8edea4fdac..85542f3222 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -23,8 +23,10 @@ void multifd_recv_sync_main(void); void multifd_send_sync_main(QEMUFile *f); int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); =20 +/* Multifd Compression flags */ #define MULTIFD_FLAG_SYNC (1 << 0) #define MULTIFD_FLAG_NOCOMP (1 << 1) +#define MULTIFD_FLAG_ZLIB (1 << 2) =20 /* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024) @@ -157,5 +159,7 @@ typedef struct { int (*recv_pages)(MultiFDRecvParams *p, uint32_t used, Error **errp); } MultiFDMethods; =20 +void multifd_register_ops(int method, MultiFDMethods *ops); + #endif =20 diff --git a/qapi/migration.json b/qapi/migration.json index c2891e6ebf..1714ea51e3 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -499,7 +499,7 @@ # ## { 'enum': 'MultifdCompress', - 'data': [ 'none' ] } + 'data': [ 'none', 'zlib' ] } =20 ## # @MigrationParameter: diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 3d5d2aba8c..985a7d4b97 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1313,6 +1313,11 @@ static void test_multifd_tcp_none(void) test_multifd_tcp("none"); } =20 +static void test_multifd_tcp_zlib(void) +{ + test_multifd_tcp("zlib"); +} + /* * This test does: * source target @@ -1475,6 +1480,7 @@ int main(int argc, char **argv) qtest_add_func("/migration/auto_converge", test_migrate_auto_converge); qtest_add_func("/migration/multifd/tcp/none", test_multifd_tcp_none); qtest_add_func("/migration/multifd/tcp/cancel", test_multifd_tcp_cance= l); + qtest_add_func("/migration/multifd/tcp/zlib", test_multifd_tcp_zlib); =20 ret =3D g_test_run(); =20 --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579785380; cv=none; d=zohomail.com; s=zohoarc; b=jfVX2Lmf1TFcA3oVLuTNyPuehRAF8vLAGKqkuV2Ai1y8BTW1tM0Zr7BrJq/Q0s1euIy/sxq6U/fDoyiGyrA8/o1DFzQPZqPdD9wlhw9B6TYZTtqsjTaog6PDd8BkDiHn4InMCOnjKI7K9x1TZ75xu9aYRuYSN0pO7Lg6O3Fm17c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579785380; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jl7rZha+anhl8HyEBbzyChMvC+XF+svndYlQbHY4vkk=; b=WVAy+r6SKqeKRBYSK/6eksoLActd49+ZoOOlMjuPlXqtdBnKfNxRcMnL2dtOjuUJt0m1cEjGjX71ru+JLabgVXQnVe7yIhy479OZRt60zdp5okgX4pWnCPIkHtDCsMyCvJY4TC6MxPvSIYvtmeJA2t4G4ftigZnUEDIPxavnoWs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579785380740252.42714100829323; Thu, 23 Jan 2020 05:16:20 -0800 (PST) Received: from localhost ([::1]:56876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucLK-0006lN-Om for importer@patchew.org; Thu, 23 Jan 2020 08:16:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40701) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub9E-0002aK-0R for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub9C-0005Hz-Qz for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:43 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:38883 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub9C-0005He-Nv for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:42 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-55-a4oQcipXMJCz4AreJZBvYA-1; Thu, 23 Jan 2020 06:59:40 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA409107ACC5 for ; Thu, 23 Jan 2020 11:59:39 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id A325D19C69; Thu, 23 Jan 2020 11:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jl7rZha+anhl8HyEBbzyChMvC+XF+svndYlQbHY4vkk=; b=f2o5Jzm903miCeycIUbmFCkbjDyriBI2R7jVjIS3LFkHU8/FUlQdcGz7j/2GJOBPCYDB9/ CLWFlFZlVLH35M0K6aPq41cCK5ARpwp2v2R1Ca/UCt7bo9fLkmT7VCHn/vBmM3kwtFVHTD DSzcc7ZU/6BlmUBN46rzOaiMvMZJR9M= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 20/21] configure: Enable test and libs for zstd Date: Thu, 23 Jan 2020 12:58:30 +0100 Message-Id: <20200123115831.36842-21-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: a4oQcipXMJCz4AreJZBvYA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- configure | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/configure b/configure index 557e4382ea..56ddfd7f8a 100755 --- a/configure +++ b/configure @@ -448,6 +448,7 @@ lzo=3D"" snappy=3D"" bzip2=3D"" lzfse=3D"" +zstd=3D"" guest_agent=3D"" guest_agent_with_vss=3D"no" guest_agent_ntddscsi=3D"no" @@ -1343,6 +1344,10 @@ for opt do ;; --disable-lzfse) lzfse=3D"no" ;; + --disable-zstd) zstd=3D"no" + ;; + --enable-zstd) zstd=3D"yes" + ;; --enable-guest-agent) guest_agent=3D"yes" ;; --disable-guest-agent) guest_agent=3D"no" @@ -1795,6 +1800,8 @@ disabled with --disable-FEATURE, default is enabled i= f available: (for reading bzip2-compressed dmg images) lzfse support of lzfse compression library (for reading lzfse-compressed dmg images) + zstd support for zstd compression library + (for migration compression) seccomp seccomp support coroutine-pool coroutine freelist (better performance) glusterfs GlusterFS backend @@ -2408,6 +2415,24 @@ EOF fi fi =20 +########################################## +# zstd check + +if test "$zstd" !=3D "no" ; then + if $pkg_config --exist libzstd ; then + zstd_cflags=3D"$($pkg_config --cflags libzstd)" + zstd_libs=3D"$($pkg_config --libs libzstd)" + LIBS=3D"$zstd_libs $LIBS" + QEMU_CFLAGS=3D"$QEMU_CFLAGS $zstd_cflags" + zstd=3D"yes" + else + if test "$zstd" =3D "yes" ; then + feature_not_found "libzstd" "Install libzstd devel" + fi + zstd=3D"no" + fi +fi + ########################################## # libseccomp check =20 @@ -6555,6 +6580,7 @@ echo "lzo support $lzo" echo "snappy support $snappy" echo "bzip2 support $bzip2" echo "lzfse support $lzfse" +echo "zstd support $zstd" echo "NUMA host support $numa" echo "libxml2 $libxml2" echo "tcmalloc support $tcmalloc" @@ -7114,6 +7140,10 @@ if test "$lzfse" =3D "yes" ; then echo "LZFSE_LIBS=3D-llzfse" >> $config_host_mak fi =20 +if test "$zstd" =3D "yes" ; then + echo "CONFIG_ZSTD=3Dy" >> $config_host_mak +fi + if test "$libiscsi" =3D "yes" ; then echo "CONFIG_LIBISCSI=3Dm" >> $config_host_mak echo "LIBISCSI_CFLAGS=3D$libiscsi_cflags" >> $config_host_mak --=20 2.24.1 From nobody Sat May 18 19:47:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579785833; cv=none; d=zohomail.com; s=zohoarc; b=lNAoJDlKZEfanWaIjfnxoWilfh3CtPPN6KOrb7G784gPQj5eMvl3EoRfO2aelgI5EHqfXaER46Tzrj5o/Z1snj53shS8BBYfnYY3rglJ4B0Nk+wCxA3mKbyby0sH9c6Q8bYS5LO9YlcCdbRx5IDaUJ44zmL/c/odgYUM3QlyCyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579785833; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jmR++/UB7tB9YHLVfmWEjAOrZHAusU9S0A7UEFOiS+s=; b=XKbzKn/+pYiH8p0IMIbGHuxggDp4x+qq9Dy1T/lJsMudHOs+1XJIe/nfpZMyCnVWMquKCx+jMbmb/I9vlslCzn1is3tgBHEDwwSg2TolvbtvoXFCsBXfEdOFrh7xaKJRC2bwxKaTdzgrtSi7XDKqzD7PSCkJAjEmLoozo05Afdw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579785833933737.6095798763376; Thu, 23 Jan 2020 05:23:53 -0800 (PST) Received: from localhost ([::1]:56982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iucSe-0006SD-E7 for importer@patchew.org; Thu, 23 Jan 2020 08:23:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40755) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iub9I-0002er-LH for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iub9G-0005KR-Ko for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:48 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:48209 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iub9F-0005Jk-Io for qemu-devel@nongnu.org; Thu, 23 Jan 2020 06:59:45 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-5y8GCWqpN1qQOTRpXvc_uA-1; Thu, 23 Jan 2020 06:59:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2AF5DB63 for ; Thu, 23 Jan 2020 11:59:42 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C2B719C69; Thu, 23 Jan 2020 11:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579780785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jmR++/UB7tB9YHLVfmWEjAOrZHAusU9S0A7UEFOiS+s=; b=OEJ9LG1AA7/JOauDVxkZPPaOWfKgEkwQqslujyqccXP+07n+Hczv6uWdWcQTZKpFfAO8D+ /3g2WysDEzf2h8ORcfRx7SQhWazpKlj5zL6hTYwnNyL33EBsKvoRrw2qnkoDVHCC//AJoi OWPBQuNtA93NKdKLO6mxfge9NXa7Tx8= From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PATCH v3 21/21] migration: Add zstd compression multifd support Date: Thu, 23 Jan 2020 12:58:31 +0100 Message-Id: <20200123115831.36842-22-quintela@redhat.com> In-Reply-To: <20200123115831.36842-1-quintela@redhat.com> References: <20200123115831.36842-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 5y8GCWqpN1qQOTRpXvc_uA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela --- hw/core/qdev-properties.c | 2 +- migration/Makefile.objs | 1 + migration/migration.c | 6 + migration/multifd-zstd.c | 304 +++++++++++++++++++++++++++++++++++ migration/multifd.h | 20 +++ migration/ram.c | 1 - qapi/migration.json | 2 +- tests/qtest/migration-test.c | 10 ++ 8 files changed, 343 insertions(+), 3 deletions(-) create mode 100644 migration/multifd-zstd.c diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 07ec75d8e3..c9c56d3123 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -647,7 +647,7 @@ const PropertyInfo qdev_prop_fdc_drive_type =3D { const PropertyInfo qdev_prop_multifd_compress =3D { .name =3D "MultifdCompress", .description =3D "multifd_compress values, " - "none/zlib", + "none/zlib/zstd", .enum_table =3D &MultifdCompress_lookup, .get =3D get_enum, .set =3D set_enum, diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 0308caa5c5..0fc619e380 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -9,6 +9,7 @@ common-obj-y +=3D qjson.o common-obj-y +=3D block-dirty-bitmap.o common-obj-y +=3D multifd.o common-obj-y +=3D multifd-zlib.o +common-obj-$(CONFIG_ZSTD) +=3D multifd-zstd.o =20 common-obj-$(CONFIG_RDMA) +=3D rdma.o =20 diff --git a/migration/migration.c b/migration/migration.c index d25fdb3e6b..f0d5ade1df 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1256,6 +1256,12 @@ static bool migrate_params_check(MigrationParameters= *params, Error **errp) "is invalid, it must be in the range of 1 to 10000 ms"); return false; } + if (params->has_multifd_compress && + params->multifd_compress =3D=3D MULTIFD_COMPRESS_ZSTD && + !multifd_compress_zstd_is_enabled()) { + error_setg(errp, "The multifd compression method zstd is compiled = out"); + return false; + } return true; } =20 diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c new file mode 100644 index 0000000000..d13c93d297 --- /dev/null +++ b/migration/multifd-zstd.c @@ -0,0 +1,304 @@ +/* + * Multifd zlib compression implementation + * + * Copyright (c) 2020 Red Hat Inc + * + * Authors: + * Juan Quintela + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include +#include "qemu/rcu.h" +#include "exec/target_page.h" +#include "qapi/error.h" +#include "migration.h" +#include "trace.h" +#include "multifd.h" + +struct zstd_data { + /* stream for compression */ + ZSTD_CStream *zcs; + /* stream for decompression */ + ZSTD_DStream *zds; + /* buffers */ + ZSTD_inBuffer in; + ZSTD_outBuffer out; + /* compressed buffer */ + uint8_t *zbuff; + /* size of compressed buffer */ + uint32_t zbuff_len; +}; + +/* Multifd zstd compression */ + +/** + * zstd_send_setup: setup send side + * + * Setup each channel with zstd compression. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @errp: pointer to an error + */ +static int zstd_send_setup(MultiFDSendParams *p, Error **errp) +{ + uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + struct zstd_data *z =3D g_new0(struct zstd_data, 1); + int res; + + p->data =3D z; + z->zcs =3D ZSTD_createCStream(); + if (!z->zcs) { + g_free(z); + error_setg(errp, "multifd %d: zstd createCStream failed", p->id); + return -1; + } + + res =3D ZSTD_initCStream(z->zcs, migrate_compress_level()); + if (ZSTD_isError(res)) { + ZSTD_freeCStream(z->zcs); + g_free(z); + error_setg(errp, "multifd %d: initCStream failed", p->id); + return -1; + } + /* We will never have more than page_count pages */ + z->zbuff_len =3D page_count * qemu_target_page_size(); + z->zbuff_len *=3D 2; + z->zbuff =3D g_try_malloc(z->zbuff_len); + if (!z->zbuff) { + ZSTD_freeCStream(z->zcs); + g_free(z); + error_setg(errp, "multifd %d: out of memory for zbuff", p->id); + return -1; + } + return 0; +} + +/** + * zstd_send_cleanup: cleanup send side + * + * Close the channel and return memory. + * + * @p: Params for the channel that we are using + */ +static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp) +{ + struct zstd_data *z =3D p->data; + + ZSTD_freeCStream(z->zcs); + z->zcs =3D NULL; + g_free(z->zbuff); + z->zbuff =3D NULL; + g_free(p->data); + p->data =3D NULL; +} + +/** + * zstd_send_prepare: prepare date to be able to send + * + * Create a compressed buffer with all the pages that we are going to + * send. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + */ +static int zstd_send_prepare(MultiFDSendParams *p, uint32_t used, Error **= errp) +{ + struct iovec *iov =3D p->pages->iov; + struct zstd_data *z =3D p->data; + int ret; + uint32_t i; + + z->out.dst =3D z->zbuff; + z->out.size =3D z->zbuff_len; + z->out.pos =3D 0; + + for (i =3D 0; i < used; i++) { + ZSTD_EndDirective flush =3D ZSTD_e_continue; + + if (i =3D=3D used - 1) { + flush =3D ZSTD_e_flush; + } + z->in.src =3D iov[i].iov_base; + z->in.size =3D iov[i].iov_len; + z->in.pos =3D 0; + + ret =3D ZSTD_compressStream2(z->zcs, &z->out, &z->in, flush); + if (ZSTD_isError(ret)) { + error_setg(errp, "multifd %d: compressStream error %s", + p->id, ZSTD_getErrorName(ret)); + return -1; + } + } + p->next_packet_size =3D z->out.pos; + p->flags |=3D MULTIFD_FLAG_ZSTD; + + return 0; +} + +/** + * zstd_send_write: do the actual write of the data + * + * Do the actual write of the comprresed buffer. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + * @errp: pointer to an error + */ +static int zstd_send_write(MultiFDSendParams *p, uint32_t used, Error **er= rp) +{ + struct zstd_data *z =3D p->data; + + return qio_channel_write_all(p->c, (void *)z->zbuff, p->next_packet_si= ze, + errp); +} + +/** + * zstd_recv_setup: setup receive side + * + * Create the compressed channel and buffer. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @errp: pointer to an error + */ +static int zstd_recv_setup(MultiFDRecvParams *p, Error **errp) +{ + uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + struct zstd_data *z =3D g_new0(struct zstd_data, 1); + int res; + + p->data =3D z; + z->zds =3D ZSTD_createDStream(); + if (!z->zds) { + g_free(z); + error_setg(errp, "multifd %d: zstd createDStream failed", p->id); + return -1; + } + + res =3D ZSTD_initDStream(z->zds); + if (ZSTD_isError(res)) { + ZSTD_freeDStream(z->zds); + g_free(z); + error_setg(errp, "multifd %d: initDStream failed", p->id); + return -1; + } + + /* We will never have more than page_count pages */ + z->zbuff_len =3D page_count * qemu_target_page_size(); + /* We know compression "could" use more space */ + z->zbuff_len *=3D 2; + z->zbuff =3D g_try_malloc(z->zbuff_len); + if (!z->zbuff) { + ZSTD_freeDStream(z->zds); + g_free(z); + error_setg(errp, "multifd %d: out of memory for zbuff", p->id); + return -1; + } + return 0; +} + +/** + * zstd_recv_cleanup: setup receive side + * + * For no compression this function does nothing. + * + * @p: Params for the channel that we are using + */ +static void zstd_recv_cleanup(MultiFDRecvParams *p) +{ + struct zstd_data *z =3D p->data; + + ZSTD_freeDStream(z->zds); + z->zds =3D NULL; + g_free(z->zbuff); + z->zbuff =3D NULL; + g_free(p->data); + p->data =3D NULL; +} + +/** + * zstd_recv_pages: read the data from the channel into actual pages + * + * Read the compressed buffer, and uncompress it into the actual + * pages. + * + * Returns 0 for success or -1 for error + * + * @p: Params for the channel that we are using + * @used: number of pages used + * @errp: pointer to an error + */ +static int zstd_recv_pages(MultiFDRecvParams *p, uint32_t used, Error **er= rp) +{ + uint32_t in_size =3D p->next_packet_size; + uint32_t out_size =3D 0; + uint32_t expected_size =3D used * qemu_target_page_size(); + struct zstd_data *z =3D p->data; + int ret; + int i; + + if (p->flags !=3D MULTIFD_FLAG_ZSTD) { + error_setg(errp, "multifd %d: flags received %x flags expected %x", + p->id, p->flags, MULTIFD_FLAG_ZSTD); + return -1; + } + ret =3D qio_channel_read_all(p->c, (void *)z->zbuff, in_size, errp); + + if (ret !=3D 0) { + return ret; + } + + z->in.src =3D z->zbuff; + z->in.size =3D in_size; + z->in.pos =3D 0; + + for (i =3D 0; i < used; i++) { + struct iovec *iov =3D &p->pages->iov[i]; + + z->out.dst =3D iov->iov_base; + z->out.size =3D iov->iov_len; + z->out.pos =3D 0; + + ret =3D ZSTD_decompressStream(z->zds, &z->out, &z->in); + if (ZSTD_isError(ret)) { + error_setg(errp, "multifd %d: decompressStream returned %s", + p->id, ZSTD_getErrorName(ret)); + return ret; + } + out_size +=3D iov->iov_len; + } + if (out_size !=3D expected_size) { + error_setg(errp, "multifd %d: packet size received %d size expecte= d %d", + p->id, out_size, expected_size); + return -1; + } + return 0; +} + +static MultiFDMethods multifd_zstd_ops =3D { + .send_setup =3D zstd_send_setup, + .send_cleanup =3D zstd_send_cleanup, + .send_prepare =3D zstd_send_prepare, + .send_write =3D zstd_send_write, + .recv_setup =3D zstd_recv_setup, + .recv_cleanup =3D zstd_recv_cleanup, + .recv_pages =3D zstd_recv_pages +}; + +static void multifd_zstd_register(void) +{ + multifd_register_ops(MULTIFD_COMPRESS_ZSTD, &multifd_zstd_ops); +} + +migration_init(multifd_zstd_register); diff --git a/migration/multifd.h b/migration/multifd.h index 85542f3222..7ec55a4534 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -27,6 +27,7 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_= addr_t offset); #define MULTIFD_FLAG_SYNC (1 << 0) #define MULTIFD_FLAG_NOCOMP (1 << 1) #define MULTIFD_FLAG_ZLIB (1 << 2) +#define MULTIFD_FLAG_ZSTD (1 << 3) =20 /* This value needs to be a multiple of qemu_target_page_size() */ #define MULTIFD_PACKET_SIZE (512 * 1024) @@ -161,5 +162,24 @@ typedef struct { =20 void multifd_register_ops(int method, MultiFDMethods *ops); =20 + +/* + * This is gross, but we don't want to have ifdefs in migration.h + * And we need to know if ZSTD is compiled in to be able to know + * if we can setup multifd_compress with that parameter. + * + * As far as I can see there is no way to convince qapi that the value + * of multifd_compress is none/zlib if zstd is compiled out, or + * none/zlib/zstd when zstd is compiled in. + */ + +static inline bool multifd_compress_zstd_is_enabled(void) +{ +#ifdef CONFIG_ZSTD + return true; +#else + return false; +#endif +} #endif =20 diff --git a/migration/ram.c b/migration/ram.c index 73a141bb60..0ef68798d2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -28,7 +28,6 @@ =20 #include "qemu/osdep.h" #include "cpu.h" -#include #include "qemu/cutils.h" #include "qemu/bitops.h" #include "qemu/bitmap.h" diff --git a/qapi/migration.json b/qapi/migration.json index 1714ea51e3..65db85970e 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -499,7 +499,7 @@ # ## { 'enum': 'MultifdCompress', - 'data': [ 'none', 'zlib' ] } + 'data': [ 'none', 'zlib', 'zstd' ] } =20 ## # @MigrationParameter: diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 985a7d4b97..99eee5d891 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1318,6 +1318,13 @@ static void test_multifd_tcp_zlib(void) test_multifd_tcp("zlib"); } =20 +#ifdef CONFIG_ZSTD +static void test_multifd_tcp_zstd(void) +{ + test_multifd_tcp("zstd"); +} +#endif + /* * This test does: * source target @@ -1481,6 +1488,9 @@ int main(int argc, char **argv) qtest_add_func("/migration/multifd/tcp/none", test_multifd_tcp_none); qtest_add_func("/migration/multifd/tcp/cancel", test_multifd_tcp_cance= l); qtest_add_func("/migration/multifd/tcp/zlib", test_multifd_tcp_zlib); +#ifdef CONFIG_ZSTD + qtest_add_func("/migration/multifd/tcp/zstd", test_multifd_tcp_zstd); +#endif =20 ret =3D g_test_run(); =20 --=20 2.24.1