From nobody Tue Jun 18 16:58:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693931068; cv=none; d=zohomail.com; s=zohoarc; b=CfbOcj0sInvS8mVO5Eh5oBi7WBd1nKW2u98g94tsSs32Kez0XY6fL+QfZcjokrsa3EmIMqndc6qyj64yhobTK3cWSOc2/ekuIAKDbk0fKxtSFRxg100lQDZzSQjlHDtPZikG5ZPLGV7dyxHSBhgX9och7sURbbis+jJWycT5x9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693931068; 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=itPguxkiBWkiGfVju4cdVWS3JiDjTmliW6gC+4lTFqw=; b=Oi/n9BDSCTKL0nNxfCYUY7l0q8FEwhmzhdl4Y8Go/p62yejzwCNzEgnUeH8Q1zJBJaE9E4maJn5qpWsy6Du1DIu9M7iSitl4gfCxKi8CjyRHyGuvHYOubh6KHXsl3rE/8vT0wzOzsgSqhcnKJugZbWoNJ4T9kDnOBD2ZeQF3lIc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693931068678163.90763047312282; Tue, 5 Sep 2023 09:24:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdYq8-00056Q-Rn; Tue, 05 Sep 2023 12:23:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYq7-00055U-Ll for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:23:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYq5-00064x-1n for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:23:43 -0400 Received: from mail-ua1-f71.google.com (mail-ua1-f71.google.com [209.85.222.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-391-ZobFSsZLOPu0MWvKLB6lOA-1; Tue, 05 Sep 2023 12:23:38 -0400 Received: by mail-ua1-f71.google.com with SMTP id a1e0cc1a2514c-7a4ff742b97so225506241.0 for ; Tue, 05 Sep 2023 09:23:38 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id u16-20020a0cf1d0000000b0063d281e22f1sm4581675qvl.17.2023.09.05.09.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 09:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693931020; 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=itPguxkiBWkiGfVju4cdVWS3JiDjTmliW6gC+4lTFqw=; b=aQnwchQte8livT8wmf8AfziYqLy/pFPS7AgR/XVXXIP8e6KoB7whCQ5BXApdGD4HY1cD+W Qh9kYfvIFzs2Km2Kr6iXCj4kSIIC66MM6LZbLcI1XSwZG7TQSpiT2U3f4DGf94LcvVolsX bze9aThN4LJFhw9RQpe8e2SEZmdUkIA= X-MC-Unique: ZobFSsZLOPu0MWvKLB6lOA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693931018; x=1694535818; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=itPguxkiBWkiGfVju4cdVWS3JiDjTmliW6gC+4lTFqw=; b=Cz53tFiBSW9CeeP20KQcdN3Vk0ZYbdy4zwBTI99EdIsCvIrkZCg/2rB2+SPasy1qtZ C6nj0g+6hmQX6osQDdTE/CykaK04xp+vAJsjfrvHZRcxLvEwNkKqr86Tmq5ASlJZypMj CU00jl4mpATty1fHq0Huo3D382r23jHGGXmjmh8DRw4dT+h8yIb2/d5FU0GQE/oKthYS K+pfOOIa7KpnbS6r7kLAxCVOqLUjwSpowhnAfW8x7lKuvia/F3wxrpV/qzYApr8m46So 3ITspwu38RhG7z8Dvy1MY3Cp4CCnqohNN7jGDDkN4JH/lyKaNUe+W458a9SGT3Xzhdtm /Yyg== X-Gm-Message-State: AOJu0YzgAJnag7BYJuVfjayHMkn+OKKJ6+TbhGP24Gc7PHEl9wcWIpBu ST9+klYXEP2j4lDidfybwxFhO/2mJ3Ad+rTYj40ybYJ+yKG0yckzdduPGKF3NEjwZotiurYg0pX rcctJposkWgVbRANtt+xMyviJ8bfYvq5F9+jC9gOFd+3N1dd5Pr4yXU/KG6snBEFYx+Q7CMxI X-Received: by 2002:a1f:2797:0:b0:48f:d0ca:b4a3 with SMTP id n145-20020a1f2797000000b0048fd0cab4a3mr9192567vkn.1.1693931018166; Tue, 05 Sep 2023 09:23:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYZ7n7eWKUVCz/Sm83ZqVShL46tKGWkgJ6ujNd3FftjXcwMm0VCX1nHV6RzkhOtftvjaJ/bQ== X-Received: by 2002:a1f:2797:0:b0:48f:d0ca:b4a3 with SMTP id n145-20020a1f2797000000b0048fd0cab4a3mr9192542vkn.1.1693931017818; Tue, 05 Sep 2023 09:23:37 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , peterx@redhat.com, Fabiano Rosas , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Markus Armbruster , qemu-stable@nongnu.org Subject: [PATCH v3 1/4] migration/qmp: Fix crash on setting tls-authz with null Date: Tue, 5 Sep 2023 12:23:32 -0400 Message-ID: <20230905162335.235619-2-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230905162335.235619-1-peterx@redhat.com> References: <20230905162335.235619-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693931069409100008 QEMU will crash if anyone tries to set tls-authz (which is a type StrOrNull) with 'null' value. Fix it in the easy way by converting it to qstring just like the other two tls parameters. Cc: qemu-stable@nongnu.org # v4.0+ Fixes: d2f1d29b95 ("migration: add support for a "tls-authz" migration para= meter") Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/options.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/migration/options.c b/migration/options.c index 1d1e1321b0..6bbfd4853d 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1408,20 +1408,25 @@ void qmp_migrate_set_parameters(MigrateSetParameter= s *params, Error **errp) { MigrationParameters tmp; =20 - /* TODO Rewrite "" to null instead */ + /* TODO Rewrite "" to null instead for all three tls_* parameters */ if (params->tls_creds && params->tls_creds->type =3D=3D QTYPE_QNULL) { qobject_unref(params->tls_creds->u.n); params->tls_creds->type =3D QTYPE_QSTRING; params->tls_creds->u.s =3D strdup(""); } - /* TODO Rewrite "" to null instead */ if (params->tls_hostname && params->tls_hostname->type =3D=3D QTYPE_QNULL) { qobject_unref(params->tls_hostname->u.n); params->tls_hostname->type =3D QTYPE_QSTRING; params->tls_hostname->u.s =3D strdup(""); } + if (params->tls_authz + && params->tls_authz->type =3D=3D QTYPE_QNULL) { + qobject_unref(params->tls_authz->u.n); + params->tls_authz->type =3D QTYPE_QSTRING; + params->tls_authz->u.s =3D strdup(""); + } =20 migrate_params_test_apply(params, &tmp); =20 --=20 2.41.0 From nobody Tue Jun 18 16:58:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693931063; cv=none; d=zohomail.com; s=zohoarc; b=hq/59oR/2FI3mzceFFuQW/Wy2sYDYOEq9eK2JvPtbYasGHayPCpDYZMBBPMCpBjX1G4Z9APJlQwBpjSSgRxXxJ/eUHN41gMjgt+XZqbP9AjuQtxmS5ObMrLcEdfsP4KJAu2gjLuoAhm5SFUza2aFCwc+s3ToLi2e13n8TXl62/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693931063; 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=6lR+hCOuaFaVDCurD30WyUh0YxgEa01KD4gK5yHl/+c=; b=ESc30DVNiATh2KAIrlwxoDfRdT4Xpkpj0XV2cvNTRhR84EDDAqLeqss5NVXKC5TSS8bn51NaIQg3mFHzqIybpqhXXrgSnKI1ZY6GW+7UgEMjvp0NSCx0Fe5blbnp7Z1B1yNDj16GflXrzdjoK5ONr4S4uzL9VeaA+D2JH+f7W+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693931063788755.3609368495787; Tue, 5 Sep 2023 09:24:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdYqC-00058V-1k; Tue, 05 Sep 2023 12:23:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYqB-000588-5M for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:23:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYq8-00065z-WA for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:23:46 -0400 Received: from mail-vs1-f72.google.com (mail-vs1-f72.google.com [209.85.217.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-xiyYTeBtMWCAl9Rh5FMJ2A-1; Tue, 05 Sep 2023 12:23:40 -0400 Received: by mail-vs1-f72.google.com with SMTP id ada2fe7eead31-44eb5726e2eso79344137.1 for ; Tue, 05 Sep 2023 09:23:40 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id u16-20020a0cf1d0000000b0063d281e22f1sm4581675qvl.17.2023.09.05.09.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 09:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693931024; 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=6lR+hCOuaFaVDCurD30WyUh0YxgEa01KD4gK5yHl/+c=; b=KOtfbBBWfaQf8V2cUMerCIPWZKl9Z8Bbpno5Ux/aEVZPdM5IGTK7qSHhabHnycL8Z2dPY7 mO06T8mDGroZZJ1HDhq2qOjXeXbgAd9M5RzER0jFCP32kbcRxhYI9I1T0inY4TuL8QrCZb NG+N7imVndKktgO1PqHfW50dpbDSkak= X-MC-Unique: xiyYTeBtMWCAl9Rh5FMJ2A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693931019; x=1694535819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6lR+hCOuaFaVDCurD30WyUh0YxgEa01KD4gK5yHl/+c=; b=GJRfnHA/LSik2xn+SqsrHt1qvMJtXsFuXwoWJfe/KhLdNPS2/7sUhR37HAwLvA//qy wr3BaVhadYFkQ//BHkFFJ97G4bgA2VnbZY2P7WtHrKLglxpby53COOg237+hKF8ChrAT ImSWCX77bvr1+CH42q7NDJTbJR2N9HKyD7E8PRzTh7tBZfVL3pRUKx/jlaMde2ji62gl n/1f3JfzxVG6RCUTXs1aWFBEWgxwpOdb21qXoWrLgMap0Xx8uv3zFrivI9qgmzVAsZQ+ QMIaT4367wutogdeLObkgn+7OCjMoGpiVMONtQBlAW9Iv/aR9O7KbThKWWwQcaoFxxek 8uFw== X-Gm-Message-State: AOJu0YxT5LXwINOP1PXDf8pTu3zQsLowpxDSuzB4/I57cT7YnYGY0a+u YApHIDTGzjx8SbcO9Kt9kwsx2MaKfMrpkZEA+fOc0eFVstExfVShtYo+B2VsKz7jrFse3Rx40px lmBchfaedEPuLZtwkxu4URR8SFYhXHQLPiPkrXe8pH/LFTiCnvSaTvMno2RorK3MvMlZ7SaRF X-Received: by 2002:a67:fb4c:0:b0:44d:37a4:8991 with SMTP id e12-20020a67fb4c000000b0044d37a48991mr9005818vsr.1.1693931019425; Tue, 05 Sep 2023 09:23:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElqV7PxhkcnWo1QrDgH5omkO/qAeEuOgI7c3+ZI8Mx+NpZx4qyhgaxwHvSGNiJLMd0AdpkhQ== X-Received: by 2002:a67:fb4c:0:b0:44d:37a4:8991 with SMTP id e12-20020a67fb4c000000b0044d37a48991mr9005793vsr.1.1693931019016; Tue, 05 Sep 2023 09:23:39 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , peterx@redhat.com, Fabiano Rosas , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Markus Armbruster Subject: [PATCH v3 2/4] tests/migration-test: Add a test for null parameter setups Date: Tue, 5 Sep 2023 12:23:33 -0400 Message-ID: <20230905162335.235619-3-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230905162335.235619-1-peterx@redhat.com> References: <20230905162335.235619-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693931065617100001 Add a test for StrOrNull parameters (tls-*). Reviewed-by: Fabiano Rosas Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- tests/qtest/migration-test.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 62d3f37021..ff86838ec3 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1471,6 +1471,27 @@ static void test_postcopy_preempt_all(void) =20 #endif =20 +/* + * We have a few parameters that allows null as input, test them to make + * sure they won't crash (where some used to). + */ +static void test_null_parameters(void) +{ + static const char *allow_null_params[] =3D { + "tls-authz", "tls-hostname", "tls-creds" + }; + QTestState *vm =3D qtest_init(""); + int i; + + for (i =3D 0; i < ARRAY_SIZE(allow_null_params); i++) { + qtest_qmp_assert_success(vm, "{ 'execute': 'migrate-set-parameters= '," + "'arguments': { %s: null } }", + allow_null_params[i]); + } + + qtest_quit(vm); +} + static void test_baddest(void) { MigrateStart args =3D { @@ -2827,6 +2848,7 @@ int main(int argc, char **argv) } } =20 + qtest_add_func("/migration/null_parameters", test_null_parameters); qtest_add_func("/migration/bad_dest", test_baddest); qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plai= n); qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbz= rle); --=20 2.41.0 From nobody Tue Jun 18 16:58:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693931081; cv=none; d=zohomail.com; s=zohoarc; b=M84YjI7Es55JpwJfL6jkjum40YIneWEBjL6IEKw3vbW+bApfqwt1qOCIwmEVUeYh+nIN6D5WT7x557hstZ9aLcsMjryzeiVVsuEauWkLEkDbPuHbLCG2Bpvzh/IKdkK7XVP0d1+y+EZMcI7UfVQzm7Ir4N6FoHToPVcByXwBZjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693931081; 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=cWT2Wd72y8c45b1p337YG5hrJzJxWo9jLgOa/JW8rkA=; b=EU6mnheWWurs1Ur66NQlPNQ6Vsz8EE1STkXrfbSPk6+UJevEsQNZVJemDrxHeIUhOICvry8JAcG3unIXSyS1S0u/fl4R6tDSkS3TMDya1p8FOyF982nemUR6qP1eS6mXF/Sxc5PQuF8Ghh3m5TaLLkGW5oG4vZ2qqkV/trcApF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693931081263263.7896011505352; Tue, 5 Sep 2023 09:24:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdYqg-0005tG-0s; Tue, 05 Sep 2023 12:24:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYqY-0005lX-P4 for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:24:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYqR-00068S-Kb for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:24:07 -0400 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-bgkcP2ccP8Sqrm3nwNtlPw-1; Tue, 05 Sep 2023 12:23:46 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-65174aca002so4395906d6.1 for ; Tue, 05 Sep 2023 09:23:42 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id u16-20020a0cf1d0000000b0063d281e22f1sm4581675qvl.17.2023.09.05.09.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 09:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693931039; 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=cWT2Wd72y8c45b1p337YG5hrJzJxWo9jLgOa/JW8rkA=; b=I2f/toil+CQOx4JubBUAiYhj9MVuXgjWRM55nbFoG4Z41eUGHgqEjG+kAl88iANkPPFU0D 9rKiBWWt1338aM9P8d+Ho9sTfhb1vbzIHKCvrv5WUSvVEAx5NEkoLAMvQ2+/BQQ3xhxtEu 1ZSXCmoWte3fWSnsTKzJ7CEfXpeZSpA= X-MC-Unique: bgkcP2ccP8Sqrm3nwNtlPw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693931021; x=1694535821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cWT2Wd72y8c45b1p337YG5hrJzJxWo9jLgOa/JW8rkA=; b=el1iWDQHTFQBEyS0jrmIWqFiGIWl+WeFd3cj0lqoG2exUTJ3Ihp5qnJ6Es3+hB+cZs vcD6eMTJVc7hIZrFE9tZ0wdWwVd+UB+1HMT+DaOR1vfvTPKbtM6jnwy3Xr6JqM3RTFw9 5YjrORkMDKN5cvFPgngEfO0ACZRQfz9Qjy+F82ogm8EcI19KK3eCscIDB7y2kqNd42tG gIxx4UuQcTtBJZ/n6sfoXxJAjN5p/O8RrWyLfgZce7SqRsa9oOmHHAEnwlSczXmBGD2Q BI+S515UTcBa9TPvIwO2apQLfHZM7kfUfJxqBgmkFHd+3cBxoqvGzOja0bzSCwURcfsY O/TA== X-Gm-Message-State: AOJu0YyClvvDkkyUooAra5JqIlNDq+WwVWI1hvAdsCsO8vmfj7UxWk9N ZJSu9qmzTA65x10dGf5X99XK+3QDvTeinjTNUokovfYMlzMWdaO0mp8av8b1gJABRHJl2LfvfGu o7eaHTY9S7ahndwtiAbsfVhQxtpNgiHpMxMOW39viMFGlSYEe+Ng597IuU4KjKR5BiQ2gvAIE X-Received: by 2002:a05:6214:1249:b0:651:5f21:92aa with SMTP id r9-20020a056214124900b006515f2192aamr15244682qvv.5.1693931020858; Tue, 05 Sep 2023 09:23:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnUh6ocepma100acmmHGDd+860NDeqR9n1U4MAyCEa8je7OzHwGQRkeOBGbjzDT80uUUFesA== X-Received: by 2002:a05:6214:1249:b0:651:5f21:92aa with SMTP id r9-20020a056214124900b006515f2192aamr15244640qvv.5.1693931020220; Tue, 05 Sep 2023 09:23:40 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , peterx@redhat.com, Fabiano Rosas , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Markus Armbruster Subject: [PATCH v3 3/4] migration/qapi: Replace @MigrateSetParameters with @MigrationParameters Date: Tue, 5 Sep 2023 12:23:34 -0400 Message-ID: <20230905162335.235619-4-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230905162335.235619-1-peterx@redhat.com> References: <20230905162335.235619-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693931083122100003 Quotting from Markus in his replies: migrate-set-parameters sets migration parameters, and query-migrate-parameters gets them. Unsurprisingly, the former's argument type MigrateSetParameters is quite close to the latter's return type MigrationParameters. The differences are subtle: 1. Since migrate-set-parameters supports setting selected parameters, its arguments must all be optional (so you can omit the ones you don't want to change). query-migrate-parameters results are also all optional, but almost all of them are in fact always present. 2. For parameters @tls_creds, @tls_hostname, @tls_authz, migrate-set-parameters interprets special value "" as "reset to default". Works, because "" is semantically invalid. Not a general solution, because a semantically invalid value need not exist. Markus added a general solution in commit 01fa559826 ("migration: Use JSON null instead of "" to reset parameter to default"). This involved changing the type from 'str' to 'StrOrNull'. 3. When parameter @block-bitmap-mapping has not been set, query-migrate-parameters does not return it (absent optional member). Clean (but undocumented). When parameters @tls_creds, @tls_hostname, @tls_authz have not been set, it returns the semantically invalid value "". Not so clean (and just as undocumented). Here to deduplicate the two objects: keep @MigrationParameters as the name of object to use in both places, drop @MigrateSetParameters, at the meantime switch types of @tls* fields from "str" to "StrOrNull" types. I found that the TLS code wasn't so much relying on tls_* fields being non-NULL at all. Actually on the other way round: if we set tls_authz to an empty string (NOTE: currently, migrate_init() missed initializing tls_authz; also touched it up in this patch), we can already fail one of the migration-test (tls/x509/default-host), as qauthz_is_allowed_by_id() will assume tls_authz set even if tls_auths is an empty string. It means we're actually relying on tls_* fields being NULL even if it's the empty string. Let's just make it a rule to return NULL for empty string on these fields internally. For that, when converting a StrOrNull into a char* (where we introduced a helper here in this patch) we'll also make the empty string to be NULL, to make it always work. And it doesn't show any issue either when applying that logic to both tls_creds and tls_hostname. With above, we can safely change both migration_tls_client_create() and migrate_tls() to not check the empty string too finally.. not needed anymore. Also, we can drop the hackish conversions in qmp_migrate_set_parameters() where we want to make sure it's a QSTRING; it's not needed now. This greatly deduplicates the code not only in qapi/migration.json, but also in the generic migration code. Markus helped greatly with this patch. Besides a better commit message (where I just "stole" from the reply), debugged and resolved a double free, but also provided the StrOrNull property implementation to be used in MigrationState object when switching tls_* fields to StrOrNull. Co-developed-by: Markus Armbruster Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Peter Xu --- qapi/migration.json | 191 +--------------------------- include/hw/qdev-properties.h | 3 + migration/options.h | 3 + hw/core/qdev-properties.c | 40 ++++++ migration/migration-hmp-cmds.c | 20 +-- migration/options.c | 220 ++++++++++----------------------- migration/tls.c | 3 +- 7 files changed, 125 insertions(+), 355 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 8843e74b59..45d69787ae 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -851,189 +851,6 @@ { 'name': 'x-vcpu-dirty-limit-period', 'features': ['unstable']= }, 'vcpu-dirty-limit'] } =20 -## -# @MigrateSetParameters: -# -# @announce-initial: Initial delay (in milliseconds) before sending -# the first announce (Since 4.0) -# -# @announce-max: Maximum delay (in milliseconds) between packets in -# the announcement (Since 4.0) -# -# @announce-rounds: Number of self-announce packets sent after -# migration (Since 4.0) -# -# @announce-step: Increase in delay (in milliseconds) between -# subsequent packets in the announcement (Since 4.0) -# -# @compress-level: compression level -# -# @compress-threads: compression thread count -# -# @compress-wait-thread: Controls behavior when all compression -# threads are currently busy. If true (default), wait for a free -# compression thread to become available; otherwise, send the page -# uncompressed. (Since 3.1) -# -# @decompress-threads: decompression thread count -# -# @throttle-trigger-threshold: The ratio of bytes_dirty_period and -# bytes_xfer_period to trigger throttling. It is expressed as -# percentage. The default value is 50. (Since 5.0) -# -# @cpu-throttle-initial: Initial percentage of time guest cpus are -# throttled when migration auto-converge is activated. The -# default value is 20. (Since 2.7) -# -# @cpu-throttle-increment: throttle percentage increase each time -# auto-converge detects that migration is not making progress. -# The default value is 10. (Since 2.7) -# -# @cpu-throttle-tailslow: Make CPU throttling slower at tail stage At -# the tail stage of throttling, the Guest is very sensitive to CPU -# percentage while the @cpu-throttle -increment is excessive -# usually at tail stage. If this parameter is true, we will -# compute the ideal CPU percentage used by the Guest, which may -# exactly make the dirty rate match the dirty rate threshold. -# Then we will choose a smaller throttle increment between the one -# specified by @cpu-throttle-increment and the one generated by -# ideal CPU percentage. Therefore, it is compatible to -# traditional throttling, meanwhile the throttle increment won't -# be excessive at tail stage. The default value is false. (Since -# 5.1) -# -# @tls-creds: ID of the 'tls-creds' object that provides credentials -# for establishing a TLS connection over the migration data -# channel. On the outgoing side of the migration, the credentials -# must be for a 'client' endpoint, while for the incoming side the -# credentials must be for a 'server' endpoint. Setting this to a -# non-empty string enables TLS for all migrations. An empty -# string means that QEMU will use plain text mode for migration, -# rather than TLS (Since 2.9) Previously (since 2.7), this was -# reported by omitting tls-creds instead. -# -# @tls-hostname: hostname of the target host for the migration. This -# is required when using x509 based TLS credentials and the -# migration URI does not already include a hostname. For example -# if using fd: or exec: based migration, the hostname must be -# provided so that the server's x509 certificate identity can be -# validated. (Since 2.7) An empty string means that QEMU will use -# the hostname associated with the migration URI, if any. (Since -# 2.9) Previously (since 2.7), this was reported by omitting -# tls-hostname instead. -# -# @max-bandwidth: to set maximum speed for migration. maximum speed -# in bytes per second. (Since 2.8) -# -# @downtime-limit: set maximum tolerated downtime for migration. -# maximum downtime in milliseconds (Since 2.8) -# -# @x-checkpoint-delay: the delay time between two COLO checkpoints. -# (Since 2.8) -# -# @block-incremental: Affects how much storage is migrated when the -# block migration capability is enabled. When false, the entire -# storage backing chain is migrated into a flattened image at the -# destination; when true, only the active qcow2 layer is migrated -# and the destination must already have access to the same backing -# chain as was used on the source. (since 2.10) -# -# @multifd-channels: Number of channels used to migrate data in -# parallel. This is the same number that the number of sockets -# used for migration. The default value is 2 (since 4.0) -# -# @xbzrle-cache-size: cache size to be used by XBZRLE migration. It -# needs to be a multiple of the target page size and a power of 2 -# (Since 2.11) -# -# @max-postcopy-bandwidth: Background transfer bandwidth during -# postcopy. Defaults to 0 (unlimited). In bytes per second. -# (Since 3.0) -# -# @max-cpu-throttle: maximum cpu throttle percentage. The default -# value is 99. (Since 3.1) -# -# @multifd-compression: Which compression method to use. Defaults to -# none. (Since 5.0) -# -# @multifd-zlib-level: Set the compression level to be used in live -# migration, the compression level is an integer between 0 and 9, -# where 0 means no compression, 1 means the best compression -# speed, and 9 means best compression ratio which will consume -# more CPU. Defaults to 1. (Since 5.0) -# -# @multifd-zstd-level: Set the compression level to be used in live -# migration, the compression level is an integer between 0 and 20, -# where 0 means no compression, 1 means the best compression -# speed, and 20 means best compression ratio which will consume -# more CPU. Defaults to 1. (Since 5.0) -# -# @block-bitmap-mapping: Maps block nodes and bitmaps on them to -# aliases for the purpose of dirty bitmap migration. Such aliases -# may for example be the corresponding names on the opposite site. -# The mapping must be one-to-one, but not necessarily complete: On -# the source, unmapped bitmaps and all bitmaps on unmapped nodes -# will be ignored. On the destination, encountering an unmapped -# alias in the incoming migration stream will result in a report, -# and all further bitmap migration data will then be discarded. -# Note that the destination does not know about bitmaps it does -# not receive, so there is no limitation or requirement regarding -# the number of bitmaps received, or how they are named, or on -# which nodes they are placed. By default (when this parameter -# has never been set), bitmap names are mapped to themselves. -# Nodes are mapped to their block device name if there is one, and -# to their node name otherwise. (Since 5.2) -# -# @x-vcpu-dirty-limit-period: Periodic time (in milliseconds) of dirty -# limit during live migration. Should be in the range 1 to 1000ms. -# Defaults to 1000ms. (Since 8.1) -# -# @vcpu-dirty-limit: Dirtyrate limit (MB/s) during live migration. -# Defaults to 1. (Since 8.1) -# -# Features: -# -# @unstable: Members @x-checkpoint-delay and @x-vcpu-dirty-limit-period -# are experimental. -# -# TODO: either fuse back into MigrationParameters, or make -# MigrationParameters members mandatory -# -# Since: 2.4 -## -{ 'struct': 'MigrateSetParameters', - 'data': { '*announce-initial': 'size', - '*announce-max': 'size', - '*announce-rounds': 'size', - '*announce-step': 'size', - '*compress-level': 'uint8', - '*compress-threads': 'uint8', - '*compress-wait-thread': 'bool', - '*decompress-threads': 'uint8', - '*throttle-trigger-threshold': 'uint8', - '*cpu-throttle-initial': 'uint8', - '*cpu-throttle-increment': 'uint8', - '*cpu-throttle-tailslow': 'bool', - '*tls-creds': 'StrOrNull', - '*tls-hostname': 'StrOrNull', - '*tls-authz': 'StrOrNull', - '*max-bandwidth': 'size', - '*downtime-limit': 'uint64', - '*x-checkpoint-delay': { 'type': 'uint32', - 'features': [ 'unstable' ] }, - '*block-incremental': 'bool', - '*multifd-channels': 'uint8', - '*xbzrle-cache-size': 'size', - '*max-postcopy-bandwidth': 'size', - '*max-cpu-throttle': 'uint8', - '*multifd-compression': 'MultiFDCompression', - '*multifd-zlib-level': 'uint8', - '*multifd-zstd-level': 'uint8', - '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ], - '*x-vcpu-dirty-limit-period': { 'type': 'uint64', - 'features': [ 'unstable' ] }, - '*vcpu-dirty-limit': 'uint64'} } - ## # @migrate-set-parameters: # @@ -1048,7 +865,7 @@ # <- { "return": {} } ## { 'command': 'migrate-set-parameters', 'boxed': true, - 'data': 'MigrateSetParameters' } + 'data': 'MigrationParameters' } =20 ## # @MigrationParameters: @@ -1214,9 +1031,9 @@ '*cpu-throttle-initial': 'uint8', '*cpu-throttle-increment': 'uint8', '*cpu-throttle-tailslow': 'bool', - '*tls-creds': 'str', - '*tls-hostname': 'str', - '*tls-authz': 'str', + '*tls-creds': 'StrOrNull', + '*tls-hostname': 'StrOrNull', + '*tls-authz': 'StrOrNull', '*max-bandwidth': 'size', '*downtime-limit': 'uint64', '*x-checkpoint-delay': { 'type': 'uint32', diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index e1df08876c..3ae83d8390 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -59,6 +59,7 @@ extern const PropertyInfo qdev_prop_uint64_checkmask; extern const PropertyInfo qdev_prop_int64; extern const PropertyInfo qdev_prop_size; extern const PropertyInfo qdev_prop_string; +extern const PropertyInfo qdev_prop_str_or_null; extern const PropertyInfo qdev_prop_on_off_auto; extern const PropertyInfo qdev_prop_size32; extern const PropertyInfo qdev_prop_arraylen; @@ -171,6 +172,8 @@ extern const PropertyInfo qdev_prop_link; DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t) #define DEFINE_PROP_STRING(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) +#define DEFINE_PROP_STR_OR_NULL(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_str_or_null, StrOrNull *) #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_SIZE32(_n, _s, _f, _d) \ diff --git a/migration/options.h b/migration/options.h index 045e2a41a2..124a5d450f 100644 --- a/migration/options.h +++ b/migration/options.h @@ -56,6 +56,7 @@ bool migrate_zero_copy_send(void); =20 bool migrate_multifd_flush_after_each_section(void); bool migrate_postcopy(void); +/* Check whether TLS is enabled for migration */ bool migrate_tls(void); =20 /* capabilities helpers */ @@ -90,6 +91,8 @@ const char *migrate_tls_authz(void); const char *migrate_tls_creds(void); const char *migrate_tls_hostname(void); uint64_t migrate_xbzrle_cache_size(void); +StrOrNull *StrOrNull_from_str(const char *str); +const char *str_from_StrOrNull(StrOrNull *obj); =20 /* parameters setters */ =20 diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 357b8761b5..b4bbb52ae9 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -2,6 +2,7 @@ #include "hw/qdev-properties.h" #include "qapi/error.h" #include "qapi/qapi-types-misc.h" +#include "qapi/qapi-visit-misc.h" #include "qapi/qmp/qerror.h" #include "qemu/ctype.h" #include "qemu/error-report.h" @@ -490,6 +491,45 @@ const PropertyInfo qdev_prop_string =3D { .set =3D set_string, }; =20 +/* --- StrOrNull --- */ + +static void release_str_or_null(Object *obj, const char *name, void *opaqu= e) +{ + Property *prop =3D opaque; + + qapi_free_StrOrNull(*(StrOrNull **)object_field_prop_ptr(obj, prop)); +} + +static void get_str_or_null(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Property *prop =3D opaque; + StrOrNull **ptr =3D object_field_prop_ptr(obj, prop); + + visit_type_StrOrNull(v, name, ptr, errp); +} + +static void set_str_or_null(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Property *prop =3D opaque; + StrOrNull **ptr =3D object_field_prop_ptr(obj, prop); + StrOrNull *son; + + if (!visit_type_StrOrNull(v, name, &son, errp)) { + return; + } + qapi_free_StrOrNull(*ptr); + *ptr =3D son; +} + +const PropertyInfo qdev_prop_str_or_null =3D { + .name =3D "StrOrNull", + .release =3D release_str_or_null, + .get =3D get_str_or_null, + .set =3D set_str_or_null, +}; + /* --- on/off/auto --- */ =20 const PropertyInfo qdev_prop_on_off_auto =3D { diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index c115ef2d23..88a8ccb475 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -257,6 +257,7 @@ void hmp_info_migrate_capabilities(Monitor *mon, const = QDict *qdict) void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) { MigrationParameters *params; + const char *str; =20 params =3D qmp_query_migrate_parameters(NULL); =20 @@ -309,14 +310,18 @@ void hmp_info_migrate_parameters(Monitor *mon, const = QDict *qdict) monitor_printf(mon, "%s: %u\n", MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), params->max_cpu_throttle); - assert(params->tls_creds); + str =3D str_from_StrOrNull(params->tls_creds); monitor_printf(mon, "%s: '%s'\n", MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), - params->tls_creds); - assert(params->tls_hostname); + str ? str : ""); + str =3D str_from_StrOrNull(params->tls_hostname); monitor_printf(mon, "%s: '%s'\n", MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), - params->tls_hostname); + str ? str : ""); + str =3D str_from_StrOrNull(params->tls_authz); + monitor_printf(mon, "%s: '%s'\n", + MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), + str ? str : ""); assert(params->has_max_bandwidth); monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), @@ -345,9 +350,6 @@ void hmp_info_migrate_parameters(Monitor *mon, const QD= ict *qdict) monitor_printf(mon, "%s: %" PRIu64 "\n", MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWI= DTH), params->max_postcopy_bandwidth); - monitor_printf(mon, "%s: '%s'\n", - MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), - params->tls_authz); =20 if (params->has_block_bitmap_mapping) { const BitmapMigrationNodeAliasList *bmnal; @@ -497,7 +499,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDic= t *qdict) const char *param =3D qdict_get_str(qdict, "parameter"); const char *valuestr =3D qdict_get_str(qdict, "value"); Visitor *v =3D string_input_visitor_new(valuestr); - MigrateSetParameters *p =3D g_new0(MigrateSetParameters, 1); + MigrationParameters *p =3D g_new0(MigrationParameters, 1); uint64_t valuebw =3D 0; uint64_t cache_size; Error *err =3D NULL; @@ -657,7 +659,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDic= t *qdict) qmp_migrate_set_parameters(p, &err); =20 cleanup: - qapi_free_MigrateSetParameters(p); + qapi_free_MigrationParameters(p); visit_free(v); hmp_handle_error(mon, err); } diff --git a/migration/options.c b/migration/options.c index 6bbfd4853d..12e392f68c 100644 --- a/migration/options.c +++ b/migration/options.c @@ -164,9 +164,12 @@ Property migration_properties[] =3D { DEFINE_PROP_SIZE("announce-step", MigrationState, parameters.announce_step, DEFAULT_MIGRATE_ANNOUNCE_STEP), - DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), - DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_host= name), - DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), + DEFINE_PROP_STR_OR_NULL("tls-creds", MigrationState, + parameters.tls_creds), + DEFINE_PROP_STR_OR_NULL("tls-hostname", MigrationState, + parameters.tls_hostname), + DEFINE_PROP_STR_OR_NULL("tls-authz", MigrationState, + parameters.tls_authz), DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState, parameters.x_vcpu_dirty_limit_period, DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD), @@ -201,6 +204,38 @@ Property migration_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +/* + * NOTE: here we have a trick when converting the empty string (""): we + * need to make sure the empty string ("") will be converted to NULL, as + * some TLS code may rely on that to detect whether something is enabled + * (e.g., the tls_authz field). + */ +const char *str_from_StrOrNull(StrOrNull *obj) +{ + if (!obj || obj->type =3D=3D QTYPE_QNULL) { + return NULL; + } else if (obj->type =3D=3D QTYPE_QSTRING) { + if (obj->u.s[0] =3D=3D '\0') { + return NULL; + } else { + return obj->u.s; + } + } else { + abort(); + } +} + +StrOrNull *StrOrNull_from_str(const char *str) +{ + StrOrNull *obj =3D g_new0(StrOrNull, 1); + + assert(str); + obj->type =3D QTYPE_QSTRING; + obj->u.s =3D g_strdup(str); + + return obj; +} + bool migrate_auto_converge(void) { MigrationState *s =3D migrate_get_current(); @@ -378,9 +413,11 @@ bool migrate_postcopy(void) =20 bool migrate_tls(void) { - MigrationState *s =3D migrate_get_current(); - - return s->parameters.tls_creds && *s->parameters.tls_creds; + /* + * The whole TLS feature relies on a non-empty tls-creds set first. + * It's disabled otherwise. + */ + return migrate_tls_creds(); } =20 typedef enum WriteTrackingSupport { @@ -827,21 +864,21 @@ const char *migrate_tls_authz(void) { MigrationState *s =3D migrate_get_current(); =20 - return s->parameters.tls_authz; + return str_from_StrOrNull(s->parameters.tls_authz); } =20 const char *migrate_tls_creds(void) { MigrationState *s =3D migrate_get_current(); =20 - return s->parameters.tls_creds; + return str_from_StrOrNull(s->parameters.tls_creds); } =20 const char *migrate_tls_hostname(void) { MigrationState *s =3D migrate_get_current(); =20 - return s->parameters.tls_hostname; + return str_from_StrOrNull(s->parameters.tls_hostname); } =20 uint64_t migrate_xbzrle_cache_size(void) @@ -911,10 +948,9 @@ MigrationParameters *qmp_query_migrate_parameters(Erro= r **errp) params->cpu_throttle_increment =3D s->parameters.cpu_throttle_incremen= t; params->has_cpu_throttle_tailslow =3D true; params->cpu_throttle_tailslow =3D s->parameters.cpu_throttle_tailslow; - params->tls_creds =3D g_strdup(s->parameters.tls_creds); - params->tls_hostname =3D g_strdup(s->parameters.tls_hostname); - params->tls_authz =3D g_strdup(s->parameters.tls_authz ? - s->parameters.tls_authz : ""); + params->tls_creds =3D QAPI_CLONE(StrOrNull, s->parameters.tls_creds); + params->tls_hostname =3D QAPI_CLONE(StrOrNull, s->parameters.tls_hostn= ame); + params->tls_authz =3D QAPI_CLONE(StrOrNull, s->parameters.tls_authz); params->has_max_bandwidth =3D true; params->max_bandwidth =3D s->parameters.max_bandwidth; params->has_downtime_limit =3D true; @@ -963,8 +999,9 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) =20 void migrate_params_init(MigrationParameters *params) { - params->tls_hostname =3D g_strdup(""); - params->tls_creds =3D g_strdup(""); + params->tls_hostname =3D StrOrNull_from_str(""); + params->tls_creds =3D StrOrNull_from_str(""); + params->tls_authz =3D StrOrNull_from_str(""); =20 /* Set has_* up only for parameter checks */ params->has_compress_level =3D true; @@ -1145,7 +1182,7 @@ bool migrate_params_check(MigrationParameters *params= , Error **errp) #ifdef CONFIG_LINUX if (migrate_zero_copy_send() && ((params->has_multifd_compression && params->multifd_compression) = || - (params->tls_creds && *params->tls_creds))) { + migrate_tls())) { error_setg(errp, "Zero copy only available for non-compressed non-TLS mu= ltifd migration"); return false; @@ -1172,113 +1209,7 @@ bool migrate_params_check(MigrationParameters *para= ms, Error **errp) return true; } =20 -static void migrate_params_test_apply(MigrateSetParameters *params, - MigrationParameters *dest) -{ - *dest =3D migrate_get_current()->parameters; - - /* TODO use QAPI_CLONE() instead of duplicating it inline */ - - if (params->has_compress_level) { - dest->compress_level =3D params->compress_level; - } - - if (params->has_compress_threads) { - dest->compress_threads =3D params->compress_threads; - } - - if (params->has_compress_wait_thread) { - dest->compress_wait_thread =3D params->compress_wait_thread; - } - - if (params->has_decompress_threads) { - dest->decompress_threads =3D params->decompress_threads; - } - - if (params->has_throttle_trigger_threshold) { - dest->throttle_trigger_threshold =3D params->throttle_trigger_thre= shold; - } - - if (params->has_cpu_throttle_initial) { - dest->cpu_throttle_initial =3D params->cpu_throttle_initial; - } - - if (params->has_cpu_throttle_increment) { - dest->cpu_throttle_increment =3D params->cpu_throttle_increment; - } - - if (params->has_cpu_throttle_tailslow) { - dest->cpu_throttle_tailslow =3D params->cpu_throttle_tailslow; - } - - if (params->tls_creds) { - assert(params->tls_creds->type =3D=3D QTYPE_QSTRING); - dest->tls_creds =3D params->tls_creds->u.s; - } - - if (params->tls_hostname) { - assert(params->tls_hostname->type =3D=3D QTYPE_QSTRING); - dest->tls_hostname =3D params->tls_hostname->u.s; - } - - if (params->has_max_bandwidth) { - dest->max_bandwidth =3D params->max_bandwidth; - } - - if (params->has_downtime_limit) { - dest->downtime_limit =3D params->downtime_limit; - } - - if (params->has_x_checkpoint_delay) { - dest->x_checkpoint_delay =3D params->x_checkpoint_delay; - } - - if (params->has_block_incremental) { - dest->block_incremental =3D params->block_incremental; - } - if (params->has_multifd_channels) { - dest->multifd_channels =3D params->multifd_channels; - } - if (params->has_multifd_compression) { - dest->multifd_compression =3D params->multifd_compression; - } - if (params->has_xbzrle_cache_size) { - dest->xbzrle_cache_size =3D params->xbzrle_cache_size; - } - if (params->has_max_postcopy_bandwidth) { - dest->max_postcopy_bandwidth =3D params->max_postcopy_bandwidth; - } - if (params->has_max_cpu_throttle) { - dest->max_cpu_throttle =3D params->max_cpu_throttle; - } - if (params->has_announce_initial) { - dest->announce_initial =3D params->announce_initial; - } - if (params->has_announce_max) { - dest->announce_max =3D params->announce_max; - } - if (params->has_announce_rounds) { - dest->announce_rounds =3D params->announce_rounds; - } - if (params->has_announce_step) { - dest->announce_step =3D params->announce_step; - } - - if (params->has_block_bitmap_mapping) { - dest->has_block_bitmap_mapping =3D true; - dest->block_bitmap_mapping =3D params->block_bitmap_mapping; - } - - if (params->has_x_vcpu_dirty_limit_period) { - dest->x_vcpu_dirty_limit_period =3D - params->x_vcpu_dirty_limit_period; - } - if (params->has_vcpu_dirty_limit) { - dest->vcpu_dirty_limit =3D params->vcpu_dirty_limit; - } -} - -static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) +static void migrate_params_apply(MigrationParameters *params, Error **errp) { MigrationState *s =3D migrate_get_current(); =20 @@ -1317,21 +1248,18 @@ static void migrate_params_apply(MigrateSetParamete= rs *params, Error **errp) } =20 if (params->tls_creds) { - g_free(s->parameters.tls_creds); - assert(params->tls_creds->type =3D=3D QTYPE_QSTRING); - s->parameters.tls_creds =3D g_strdup(params->tls_creds->u.s); + qapi_free_StrOrNull(s->parameters.tls_creds); + s->parameters.tls_creds =3D QAPI_CLONE(StrOrNull, params->tls_cred= s); } =20 if (params->tls_hostname) { - g_free(s->parameters.tls_hostname); - assert(params->tls_hostname->type =3D=3D QTYPE_QSTRING); - s->parameters.tls_hostname =3D g_strdup(params->tls_hostname->u.s); + qapi_free_StrOrNull(s->parameters.tls_hostname); + s->parameters.tls_hostname =3D QAPI_CLONE(StrOrNull, params->tls_h= ostname); } =20 if (params->tls_authz) { - g_free(s->parameters.tls_authz); - assert(params->tls_authz->type =3D=3D QTYPE_QSTRING); - s->parameters.tls_authz =3D g_strdup(params->tls_authz->u.s); + qapi_free_StrOrNull(s->parameters.tls_authz); + s->parameters.tls_authz =3D QAPI_CLONE(StrOrNull, params->tls_auth= z); } =20 if (params->has_max_bandwidth) { @@ -1404,33 +1332,9 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) } } =20 -void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) +void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) { - MigrationParameters tmp; - - /* TODO Rewrite "" to null instead for all three tls_* parameters */ - if (params->tls_creds - && params->tls_creds->type =3D=3D QTYPE_QNULL) { - qobject_unref(params->tls_creds->u.n); - params->tls_creds->type =3D QTYPE_QSTRING; - params->tls_creds->u.s =3D strdup(""); - } - if (params->tls_hostname - && params->tls_hostname->type =3D=3D QTYPE_QNULL) { - qobject_unref(params->tls_hostname->u.n); - params->tls_hostname->type =3D QTYPE_QSTRING; - params->tls_hostname->u.s =3D strdup(""); - } - if (params->tls_authz - && params->tls_authz->type =3D=3D QTYPE_QNULL) { - qobject_unref(params->tls_authz->u.n); - params->tls_authz->type =3D QTYPE_QSTRING; - params->tls_authz->u.s =3D strdup(""); - } - - migrate_params_test_apply(params, &tmp); - - if (!migrate_params_check(&tmp, errp)) { + if (!migrate_params_check(params, errp)) { /* Invalid parameter */ return; } diff --git a/migration/tls.c b/migration/tls.c index fa03d9136c..c2ed4ff557 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -126,7 +126,8 @@ QIOChannelTLS *migration_tls_client_create(QIOChannel *= ioc, } =20 const char *tls_hostname =3D migrate_tls_hostname(); - if (tls_hostname && *tls_hostname) { + /* If tls_hostname, then it must be non-empty string already */ + if (tls_hostname) { hostname =3D tls_hostname; } =20 --=20 2.41.0 From nobody Tue Jun 18 16:58:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169393106871376.4833453403163; Tue, 5 Sep 2023 09:24:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdYqG-0005C0-86; Tue, 05 Sep 2023 12:23:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYqE-0005BP-K7 for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:23:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdYqA-00066B-JE for qemu-devel@nongnu.org; Tue, 05 Sep 2023 12:23:49 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-wzQkGgSUNDGsihf808mT3Q-1; Tue, 05 Sep 2023 12:23:43 -0400 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-64726969c8bso3986416d6.0 for ; Tue, 05 Sep 2023 09:23:42 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id u16-20020a0cf1d0000000b0063d281e22f1sm4581675qvl.17.2023.09.05.09.23.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 09:23:40 -0700 (PDT) X-MC-Unique: wzQkGgSUNDGsihf808mT3Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693931022; x=1694535822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B17zXPGoK4sB4OfBqgrVVRRtVE/q5bKYAQr0v4BLlzI=; b=cthLzBECaPJNOvaGakjrsjxvn0JD1LyLgkDSr9Tci1Ozl6AsGOOk5ifmZvf4FoyYeP yOXUPk3e6g3c98cWhQC0bDzBky6mUlWBj7bTMFUkWXvql3EPiqs+z3kt5zaLoBR8PXlI 87F9dcVuJOFLovdzr+EIhWlueqbv3aITWEehdpDFy1AMigzq0LVe1s15NT7FrfBHYnKL TwxOsYEn7q2nMSBjt0+WmG1NFD0G5aIZNtfv3oRd28WtzLbDPNOtroXXnlHC4oo2doyh /vxrrc8Wxb3xMQO+XvK1IoXJuvG8vXmenF/FVDwEFm6iHtPhVnwn3d9ijL9KA7xAeOv6 IC6A== X-Gm-Message-State: AOJu0Ywcs4oyGsZYYMlMiK8E8WICAtDVCgeg2I7LdZZhJNwHAbUQtyDM lEBS2mvPl2NUVwXlnWF1P6BBjjmAFs4dblfV7iC/MSIJZIhNSguCyZdLlCO/cJrJiBwPsvmt01Z tKbFghgwyqdD2GlcBG3Vpy04zDxRp4t1J6YRexYfUEg+Co4Cb9dQTrENF/rnbSboPG2Ch/Rkr X-Received: by 2002:a05:6214:f69:b0:649:5f43:245f with SMTP id iy9-20020a0562140f6900b006495f43245fmr15200518qvb.6.1693931021663; Tue, 05 Sep 2023 09:23:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbu3Z5UW/xOhHf8E6nNHjNvOXKQIOvqlNHvDo2pReZUliF5jzkIESluh9v8zaSliQGfzvWDw== X-Received: by 2002:a05:6214:f69:b0:649:5f43:245f with SMTP id iy9-20020a0562140f6900b006495f43245fmr15200487qvb.6.1693931021113; Tue, 05 Sep 2023 09:23:41 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , peterx@redhat.com, Fabiano Rosas , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Markus Armbruster Subject: [PATCH v3 4/4] migration/qapi: Drop @MigrationParameter enum Date: Tue, 5 Sep 2023 12:23:35 -0400 Message-ID: <20230905162335.235619-5-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230905162335.235619-1-peterx@redhat.com> References: <20230905162335.235619-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1693931069847100012 Drop the enum in qapi because it is never used in QMP APIs. Instead making it an internal definition for QEMU so that we can decouple it from QAPI, and also we can deduplicate the QAPI documentations. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 Suggested-by: Markus Armbruster --- qapi/migration.json | 179 --------------------------------- migration/options.h | 47 +++++++++ migration/migration-hmp-cmds.c | 3 +- migration/options.c | 51 ++++++++++ 4 files changed, 100 insertions(+), 180 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 45d69787ae..eeb1878c4f 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -672,185 +672,6 @@ 'bitmaps': [ 'BitmapMigrationBitmapAlias' ] } } =20 -## -# @MigrationParameter: -# -# Migration parameters enumeration -# -# @announce-initial: Initial delay (in milliseconds) before sending -# the first announce (Since 4.0) -# -# @announce-max: Maximum delay (in milliseconds) between packets in -# the announcement (Since 4.0) -# -# @announce-rounds: Number of self-announce packets sent after -# migration (Since 4.0) -# -# @announce-step: Increase in delay (in milliseconds) between -# subsequent packets in the announcement (Since 4.0) -# -# @compress-level: Set the compression level to be used in live -# migration, the compression level is an integer between 0 and 9, -# where 0 means no compression, 1 means the best compression -# speed, and 9 means best compression ratio which will consume -# more CPU. -# -# @compress-threads: Set compression thread count to be used in live -# migration, the compression thread count is an integer between 1 -# and 255. -# -# @compress-wait-thread: Controls behavior when all compression -# threads are currently busy. If true (default), wait for a free -# compression thread to become available; otherwise, send the page -# uncompressed. (Since 3.1) -# -# @decompress-threads: Set decompression thread count to be used in -# live migration, the decompression thread count is an integer -# between 1 and 255. Usually, decompression is at least 4 times as -# fast as compression, so set the decompress-threads to the number -# about 1/4 of compress-threads is adequate. -# -# @throttle-trigger-threshold: The ratio of bytes_dirty_period and -# bytes_xfer_period to trigger throttling. It is expressed as -# percentage. The default value is 50. (Since 5.0) -# -# @cpu-throttle-initial: Initial percentage of time guest cpus are -# throttled when migration auto-converge is activated. The -# default value is 20. (Since 2.7) -# -# @cpu-throttle-increment: throttle percentage increase each time -# auto-converge detects that migration is not making progress. -# The default value is 10. (Since 2.7) -# -# @cpu-throttle-tailslow: Make CPU throttling slower at tail stage At -# the tail stage of throttling, the Guest is very sensitive to CPU -# percentage while the @cpu-throttle -increment is excessive -# usually at tail stage. If this parameter is true, we will -# compute the ideal CPU percentage used by the Guest, which may -# exactly make the dirty rate match the dirty rate threshold. -# Then we will choose a smaller throttle increment between the one -# specified by @cpu-throttle-increment and the one generated by -# ideal CPU percentage. Therefore, it is compatible to -# traditional throttling, meanwhile the throttle increment won't -# be excessive at tail stage. The default value is false. (Since -# 5.1) -# -# @tls-creds: ID of the 'tls-creds' object that provides credentials -# for establishing a TLS connection over the migration data -# channel. On the outgoing side of the migration, the credentials -# must be for a 'client' endpoint, while for the incoming side the -# credentials must be for a 'server' endpoint. Setting this will -# enable TLS for all migrations. The default is unset, resulting -# in unsecured migration at the QEMU level. (Since 2.7) -# -# @tls-hostname: hostname of the target host for the migration. This -# is required when using x509 based TLS credentials and the -# migration URI does not already include a hostname. For example -# if using fd: or exec: based migration, the hostname must be -# provided so that the server's x509 certificate identity can be -# validated. (Since 2.7) -# -# @tls-authz: ID of the 'authz' object subclass that provides access -# control checking of the TLS x509 certificate distinguished name. -# This object is only resolved at time of use, so can be deleted -# and recreated on the fly while the migration server is active. -# If missing, it will default to denying access (Since 4.0) -# -# @max-bandwidth: to set maximum speed for migration. maximum speed -# in bytes per second. (Since 2.8) -# -# @downtime-limit: set maximum tolerated downtime for migration. -# maximum downtime in milliseconds (Since 2.8) -# -# @x-checkpoint-delay: The delay time (in ms) between two COLO -# checkpoints in periodic mode. (Since 2.8) -# -# @block-incremental: Affects how much storage is migrated when the -# block migration capability is enabled. When false, the entire -# storage backing chain is migrated into a flattened image at the -# destination; when true, only the active qcow2 layer is migrated -# and the destination must already have access to the same backing -# chain as was used on the source. (since 2.10) -# -# @multifd-channels: Number of channels used to migrate data in -# parallel. This is the same number that the number of sockets -# used for migration. The default value is 2 (since 4.0) -# -# @xbzrle-cache-size: cache size to be used by XBZRLE migration. It -# needs to be a multiple of the target page size and a power of 2 -# (Since 2.11) -# -# @max-postcopy-bandwidth: Background transfer bandwidth during -# postcopy. Defaults to 0 (unlimited). In bytes per second. -# (Since 3.0) -# -# @max-cpu-throttle: maximum cpu throttle percentage. Defaults to 99. -# (Since 3.1) -# -# @multifd-compression: Which compression method to use. Defaults to -# none. (Since 5.0) -# -# @multifd-zlib-level: Set the compression level to be used in live -# migration, the compression level is an integer between 0 and 9, -# where 0 means no compression, 1 means the best compression -# speed, and 9 means best compression ratio which will consume -# more CPU. Defaults to 1. (Since 5.0) -# -# @multifd-zstd-level: Set the compression level to be used in live -# migration, the compression level is an integer between 0 and 20, -# where 0 means no compression, 1 means the best compression -# speed, and 20 means best compression ratio which will consume -# more CPU. Defaults to 1. (Since 5.0) -# -# @block-bitmap-mapping: Maps block nodes and bitmaps on them to -# aliases for the purpose of dirty bitmap migration. Such aliases -# may for example be the corresponding names on the opposite site. -# The mapping must be one-to-one, but not necessarily complete: On -# the source, unmapped bitmaps and all bitmaps on unmapped nodes -# will be ignored. On the destination, encountering an unmapped -# alias in the incoming migration stream will result in a report, -# and all further bitmap migration data will then be discarded. -# Note that the destination does not know about bitmaps it does -# not receive, so there is no limitation or requirement regarding -# the number of bitmaps received, or how they are named, or on -# which nodes they are placed. By default (when this parameter -# has never been set), bitmap names are mapped to themselves. -# Nodes are mapped to their block device name if there is one, and -# to their node name otherwise. (Since 5.2) -# -# @x-vcpu-dirty-limit-period: Periodic time (in milliseconds) of dirty -# limit during live migration. Should be in the range 1 to 1000ms. -# Defaults to 1000ms. (Since 8.1) -# -# @vcpu-dirty-limit: Dirtyrate limit (MB/s) during live migration. -# Defaults to 1. (Since 8.1) -# -# Features: -# -# @unstable: Members @x-checkpoint-delay and @x-vcpu-dirty-limit-period -# are experimental. -# -# Since: 2.4 -## -{ 'enum': 'MigrationParameter', - 'data': ['announce-initial', 'announce-max', - 'announce-rounds', 'announce-step', - 'compress-level', 'compress-threads', 'decompress-threads', - 'compress-wait-thread', 'throttle-trigger-threshold', - 'cpu-throttle-initial', 'cpu-throttle-increment', - 'cpu-throttle-tailslow', - 'tls-creds', 'tls-hostname', 'tls-authz', 'max-bandwidth', - 'downtime-limit', - { 'name': 'x-checkpoint-delay', 'features': [ 'unstable' ] }, - 'block-incremental', - 'multifd-channels', - 'xbzrle-cache-size', 'max-postcopy-bandwidth', - 'max-cpu-throttle', 'multifd-compression', - 'multifd-zlib-level', 'multifd-zstd-level', - 'block-bitmap-mapping', - { 'name': 'x-vcpu-dirty-limit-period', 'features': ['unstable']= }, - 'vcpu-dirty-limit'] } - ## # @migrate-set-parameters: # diff --git a/migration/options.h b/migration/options.h index 124a5d450f..4591545c62 100644 --- a/migration/options.h +++ b/migration/options.h @@ -66,6 +66,53 @@ bool migrate_cap_set(int cap, bool value, Error **errp); =20 /* parameters */ =20 +typedef enum { + MIGRATION_PARAMETER_ANNOUNCE_INITIAL, + MIGRATION_PARAMETER_ANNOUNCE_MAX, + MIGRATION_PARAMETER_ANNOUNCE_ROUNDS, + MIGRATION_PARAMETER_ANNOUNCE_STEP, + MIGRATION_PARAMETER_COMPRESS_LEVEL, + MIGRATION_PARAMETER_COMPRESS_THREADS, + MIGRATION_PARAMETER_DECOMPRESS_THREADS, + MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD, + MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD, + MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL, + MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT, + MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW, + MIGRATION_PARAMETER_TLS_CREDS, + MIGRATION_PARAMETER_TLS_HOSTNAME, + MIGRATION_PARAMETER_TLS_AUTHZ, + MIGRATION_PARAMETER_MAX_BANDWIDTH, + MIGRATION_PARAMETER_DOWNTIME_LIMIT, + MIGRATION_PARAMETER_X_CHECKPOINT_DELAY, + MIGRATION_PARAMETER_BLOCK_INCREMENTAL, + MIGRATION_PARAMETER_MULTIFD_CHANNELS, + MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE, + MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH, + MIGRATION_PARAMETER_MAX_CPU_THROTTLE, + MIGRATION_PARAMETER_MULTIFD_COMPRESSION, + MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL, + MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL, + MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING, + MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD, + MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT, + MIGRATION_PARAMETER__MAX, +} MigrationParameter; + +extern const char *MigrationParameter_string[MIGRATION_PARAMETER__MAX]; +#define MigrationParameter_str(p) MigrationParameter_string[p] + +/** + * @MigrationParameter_from_str(): Parse string into a MigrationParameter + * + * @param: input string + * @errp: error message if failed to parse the string + * + * Returns MigrationParameter enum (>=3D0) if succeed, or negative otherwi= se + * which will always setup @errp. + */ +int MigrationParameter_from_str(const char *param, Error **errp); + const BitmapMigrationNodeAliasList *migrate_block_bitmap_mapping(void); bool migrate_has_block_bitmap_mapping(void); =20 diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 88a8ccb475..0a35a87b7e 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -31,6 +31,7 @@ #include "ui/qemu-spice.h" #include "sysemu/sysemu.h" #include "migration.h" +#include "migration/options.h" =20 static void migration_global_dump(Monitor *mon) { @@ -505,7 +506,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDic= t *qdict) Error *err =3D NULL; int val, ret; =20 - val =3D qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); + val =3D MigrationParameter_from_str(param, &err); if (val < 0) { goto cleanup; } diff --git a/migration/options.c b/migration/options.c index 12e392f68c..c9b90d932d 100644 --- a/migration/options.c +++ b/migration/options.c @@ -84,6 +84,57 @@ #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD 1000 /* millisecond= s */ #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1 /* MB/s */ =20 +const char *MigrationParameter_string[MIGRATION_PARAMETER__MAX] =3D { + [MIGRATION_PARAMETER_ANNOUNCE_INITIAL] =3D "announce-initial", + [MIGRATION_PARAMETER_ANNOUNCE_MAX] =3D "announce-max", + [MIGRATION_PARAMETER_ANNOUNCE_ROUNDS] =3D "announce-rounds", + [MIGRATION_PARAMETER_ANNOUNCE_STEP] =3D "announce-step", + [MIGRATION_PARAMETER_COMPRESS_LEVEL] =3D "compress-level", + [MIGRATION_PARAMETER_COMPRESS_THREADS] =3D "compress-threads", + [MIGRATION_PARAMETER_DECOMPRESS_THREADS] =3D "decompress-threads", + [MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD] =3D "compress-wait-thread", + [MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD] =3D "throttle-trigger= -threshold", + [MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL] =3D "cpu-throttle-initial", + [MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT] =3D "cpu-throttle-increme= nt", + [MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW] =3D "cpu-throttle-tailslow= ", + [MIGRATION_PARAMETER_TLS_CREDS] =3D "tls-creds", + [MIGRATION_PARAMETER_TLS_HOSTNAME] =3D "tls-hostname", + [MIGRATION_PARAMETER_TLS_AUTHZ] =3D "tls-authz", + [MIGRATION_PARAMETER_MAX_BANDWIDTH] =3D "max-bandwidth", + [MIGRATION_PARAMETER_DOWNTIME_LIMIT] =3D "downtime-limit", + [MIGRATION_PARAMETER_X_CHECKPOINT_DELAY] =3D "x-checkpoint-delay", + [MIGRATION_PARAMETER_BLOCK_INCREMENTAL] =3D "block-incremental", + [MIGRATION_PARAMETER_MULTIFD_CHANNELS] =3D "multifd-channels", + [MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE] =3D "xbzrle-cache-size", + [MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH] =3D "max-postcopy-bandwid= th", + [MIGRATION_PARAMETER_MAX_CPU_THROTTLE] =3D "max-cpu-throttle", + [MIGRATION_PARAMETER_MULTIFD_COMPRESSION] =3D "multifd-compression", + [MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL] =3D "multifd-zlib-level", + [MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL] =3D "multifd-zstd-level", + [MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING] =3D "block-bitmap-mapping", + [MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD] =3D "x-vcpu-dirty-limi= t-period", + [MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT] =3D "vcpu-dirty-limit", +}; + +int MigrationParameter_from_str(const char *param, Error **errp) +{ + int i; + + if (!param) { + error_setg(errp, "Missing parameter value"); + return -1; + } + + for (i =3D 0; i < MIGRATION_PARAMETER__MAX; i++) { + if (!strcmp(param, MigrationParameter_string[i])) { + return i; + } + } + + error_setg(errp, "Invalid parameter value: %s", param); + return -1; +} + Property migration_properties[] =3D { DEFINE_PROP_BOOL("store-global-state", MigrationState, store_global_state, true), --=20 2.41.0