From patchwork Mon Aug 14 22:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1821155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fp6NzbJM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPpkM4x72z1yfZ for ; Tue, 15 Aug 2023 08:20:26 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVfuw-0003Co-7d; Mon, 14 Aug 2023 18:20:06 -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 1qVful-0003BH-Jl for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:55 -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 1qVfuk-0005k2-3t for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692051593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qu5ivLazFUczHSfNwhNGz9an3pNXKi1yqEOz8vB4qLg=; b=fp6NzbJMDAChdiOpnzalpAleiw7dOyFptHBOlkJ0wyD5WyM5lDhwMaz+dGSKddIRITK+dv cwQhCARHhib5VnQp06imV23tPDL+vF2uYwfZUiiirteKL8wB5XhxnJzg6WjlM4V4eWYGJC o4Zeneqokz7DhqTM3SV7sxSxtRHTNfE= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-OE2vJyz3MEKyF1h3RZYcew-1; Mon, 14 Aug 2023 18:19:51 -0400 X-MC-Unique: OE2vJyz3MEKyF1h3RZYcew-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-76cb292df12so172453485a.0 for ; Mon, 14 Aug 2023 15:19:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692051591; x=1692656391; 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=qu5ivLazFUczHSfNwhNGz9an3pNXKi1yqEOz8vB4qLg=; b=I2saY6nK7+9URxe90Tq9i5o472L4vEDPCiYUxtuVDbqZIgBN30xAckrx2TbU7twgdk X0UuWAtxwl7/XKixYiRlzLpeHQe8W3k5i9kB1QmL8aTmqU9ZRld3oH/Cy0kfs/9Vw6b6 cOLqzPl1x1prWcnK+nO1zqPDydwIfoIp0a0yoSgFG/6NpJBVR+4c9sy6LXPUfEQr9tm/ AGH5ZZhkkf3Lr4cCBNhYQt8Bp1uYGbDL0ujPcqqqajasFOGgfS+x3x7otIgD1aCCTRhM eWkzQoNpoWT+E5FmWu2JbvwFofs4LDBkSi5UPSUiPMEFU79e+B5fNlKSPHDJPkUXtgiV ttLA== X-Gm-Message-State: AOJu0Yx65haCteBp3cndgTK7GJOqZJDB4Lf4qlK/jRc7F53HUrPu4xiz aBR1SCKSn3Ip1HK6iCHn307fNZjdVZML9fDhhwGlb2W9PlOFnbpUOq37OEEeblmqrdgbc2uls50 87A/McwNeaSffpAmf1WPSjQEIEjlgWmnXpxo8rRRvVz2z4sYwYa4oSZZv8kLfeNv/1uu5jyrI X-Received: by 2002:a05:620a:45a5:b0:76c:a9eb:90bf with SMTP id bp37-20020a05620a45a500b0076ca9eb90bfmr14784502qkb.3.1692051590916; Mon, 14 Aug 2023 15:19:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQoEGJcwdLnun/r4m4RVHgk6wafTVEo5mvU9H/B3jJ1Kl9KBd8IyfN7OqBSn9cO+dfAYJfkA== X-Received: by 2002:a05:620a:45a5:b0:76c:a9eb:90bf with SMTP id bp37-20020a05620a45a500b0076ca9eb90bfmr14784476qkb.3.1692051590523; Mon, 14 Aug 2023 15:19:50 -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 s22-20020a05620a16b600b0076ca401d8c7sm3324978qkj.111.2023.08.14.15.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 15:19:50 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Markus Armbruster , Leonardo Bras Soares Passos , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , Fabiano Rosas , peterx@redhat.com, Juan Quintela , qemu-stable@nongnu.org Subject: [PATCH for-8.2 1/4] migration/qmp: Fix crash on setting tls-authz with null Date: Mon, 14 Aug 2023 18:19:44 -0400 Message-ID: <20230814221947.353093-2-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230814221947.353093-1-peterx@redhat.com> References: <20230814221947.353093-1-peterx@redhat.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 parameter") Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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(MigrateSetParameters *params, Error **errp) { MigrationParameters tmp; - /* TODO Rewrite "" to null instead */ + /* TODO Rewrite "" to null instead for all three tls_* parameters */ if (params->tls_creds && params->tls_creds->type == QTYPE_QNULL) { qobject_unref(params->tls_creds->u.n); params->tls_creds->type = QTYPE_QSTRING; params->tls_creds->u.s = strdup(""); } - /* TODO Rewrite "" to null instead */ if (params->tls_hostname && params->tls_hostname->type == QTYPE_QNULL) { qobject_unref(params->tls_hostname->u.n); params->tls_hostname->type = QTYPE_QSTRING; params->tls_hostname->u.s = strdup(""); } + if (params->tls_authz + && params->tls_authz->type == QTYPE_QNULL) { + qobject_unref(params->tls_authz->u.n); + params->tls_authz->type = QTYPE_QSTRING; + params->tls_authz->u.s = strdup(""); + } migrate_params_test_apply(params, &tmp); From patchwork Mon Aug 14 22:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1821159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ajt0q6Oq; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPpln6Kjzz1yfZ for ; Tue, 15 Aug 2023 08:21:41 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVfvJ-0003Ol-Bl; Mon, 14 Aug 2023 18:20:29 -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 1qVfum-0003BQ-Iw for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:56 -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 1qVfuk-0005k9-D5 for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692051593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9sRU6XGp/MSmvILBmcGtp0+DyLq8JV+/t6bA0F+AKyo=; b=Ajt0q6Oq1DfwZwFN/e50zgi8F28syyIjNI6EU6ba1jxwCTsU4D+hNfGdfeZg0Q1FxJwPZS AlmQgzES6GKlNTc6l5MyekwtQvTxgjbfWys1wgof5j58YjmoiV+GPWLMjja2El7cUGpl8S X3Mw07RPtT/9RU39asv8EsUPo5bBKKw= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-396-Z98wOUTZOGS7Uae40MEKog-1; Mon, 14 Aug 2023 18:19:52 -0400 X-MC-Unique: Z98wOUTZOGS7Uae40MEKog-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-76cc6815f23so119307685a.1 for ; Mon, 14 Aug 2023 15:19:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692051592; x=1692656392; 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=9sRU6XGp/MSmvILBmcGtp0+DyLq8JV+/t6bA0F+AKyo=; b=VCx6bKO+XfhGxeDqpZ9PRd4VUaEY0N4QxDoE2DuOweUGXllta60ljJlUSA5lc+bGIs TNhUAOLFXqfqTsoBTOyRiAf5bs02cIRxs+XOHBERMM8+gnyT8DVtB9Le+2hHlz2s8STC WKCoM82J3Nnqjg/uWh8SLErKaLIMUQpLm5zjtQtougqZyUsp85xbZGuA271ebi09LacI q7qZOIlZlMDhEI/uZjb3hs2CH9oddSAeCP3fsE1Fkm1qzYLHwEn4MPG78t/Lnpq5IaWB ohgahPADCTLPpMSDU8PH1bxaz4qlMlsnAa3OIBAn/gsJuSSkjpMdl3tZ8C2tP9aD7WaE wuZw== X-Gm-Message-State: AOJu0YxELrSh5W17G32j5wxwovhBOSbNt7RgXkWtcWtrd6j8HLJjBci8 JEOc9mgVWQOrfDbU48SmjRLvGafW1//wZ8xthuCv+AAPpsIuxy/a9LMBBlOlGq22zwRyFY+5ZaU W4Cgz5RJPsvXT/rjua9xeHUB0K8qXkrZsimZeNhhG2Hqb5UMUBhXfj6YyYBGtQ2art03KDbSC X-Received: by 2002:a05:620a:468b:b0:76c:a3bb:f8c0 with SMTP id bq11-20020a05620a468b00b0076ca3bbf8c0mr14775294qkb.0.1692051591840; Mon, 14 Aug 2023 15:19:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFb+BiLiGnyNcq45xP+OcbVw3yZ2/NCPIqbDiOpvPmvvtdA6uBtXiAmpO+bqLG3X/U6YnSQIA== X-Received: by 2002:a05:620a:468b:b0:76c:a3bb:f8c0 with SMTP id bq11-20020a05620a468b00b0076ca3bbf8c0mr14775273qkb.0.1692051591493; Mon, 14 Aug 2023 15:19:51 -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 s22-20020a05620a16b600b0076ca401d8c7sm3324978qkj.111.2023.08.14.15.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 15:19:51 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Markus Armbruster , Leonardo Bras Soares Passos , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , Fabiano Rosas , peterx@redhat.com, Juan Quintela Subject: [PATCH for-8.2 2/4] tests/migration-test: Add a test for null parameter setups Date: Mon, 14 Aug 2023 18:19:45 -0400 Message-ID: <20230814221947.353093-3-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230814221947.353093-1-peterx@redhat.com> References: <20230814221947.353093-1-peterx@redhat.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a test for StrOrNull parameters (tls-*). Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- tests/qtest/migration-test.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 62d3f37021..12e72580a6 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -1471,6 +1471,29 @@ static void test_postcopy_preempt_all(void) #endif +/* + * 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) +{ + const char *null_params[] = { + "tls-authz", "tls-hostname", "tls-creds"}; + QTestState *vm = qtest_init(""); + QDict *response; + int i; + + for (i = 0; i < sizeof(null_params) / sizeof(const char *); i++) { + response = qtest_qmp(vm, "{ 'execute': 'migrate-set-parameters'," + "'arguments': { %s: null } }", + null_params[i]); + /* Succeed or fail; as long as not crashing */ + qobject_unref(response); + } + + qtest_quit(vm); +} + static void test_baddest(void) { MigrateStart args = { @@ -2827,6 +2850,7 @@ int main(int argc, char **argv) } } + 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_plain); qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle); From patchwork Mon Aug 14 22:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1821158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HoZT4gNM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPpll09J0z1yfZ for ; Tue, 15 Aug 2023 08:21:38 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVfvK-0003S1-4C; Mon, 14 Aug 2023 18:20:30 -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 1qVfuo-0003Bt-KS for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:58 -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 1qVful-0005kO-QF for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692051595; 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=nOmDDwiqX7/2CN1wshjObAob2rHWWjlzdpdy7eZZMZ8=; b=HoZT4gNMc+5bQFsvi0yKU6NzvC9O5ZkVIhQha7Xf7CJISWbIQNlUkIgcp8tS6PEAK7WgU4 kch5rIZnLgCSqdt/JQCBJg2xcWBLKiQIvCenMdgHSpiOBEMLvElEci6aPXwGh0PBWTD98R u0lMWUc6+6vpn9wJkDaNV/zZdowKIC8= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-8KrEKbnUMJea32sxe9muPA-1; Mon, 14 Aug 2023 18:19:53 -0400 X-MC-Unique: 8KrEKbnUMJea32sxe9muPA-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4059b5c3dd0so15030801cf.0 for ; Mon, 14 Aug 2023 15:19:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692051593; x=1692656393; 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=nOmDDwiqX7/2CN1wshjObAob2rHWWjlzdpdy7eZZMZ8=; b=FfFKdfawUrBxdy93P7WhLlbawL7hSK/TSJIASl1amBGxBoothawnrDCr5gkCop/3j9 GgmBdR+4wpyxLjarNImiqyx5rZ2D2/13IKKVy03Fs0MrBMgc4SsWOhAyUDJHRhyhn+df BAsq7Wp9kTL7tnbRjbuxvo38LVKuRwtDaTmrY6ELAAhCdpTBPqtxUcWE0pOiNLxSOAUx Ad6J2HrVi0cnUVIlNiO7YI8CLEaST6tIlTOUamykMcfIw8JZRNFgm8VLnGv9xKxbU3Wy jLEX0l34mrVd5E/bf+SxnWWebjSGoIPy8K47N8y+cFcRgMbB6OxPJVEwer3V0oWcFfIG rJBg== X-Gm-Message-State: AOJu0YzTcUUPci3wMvgpg3VMFndjmBfM9zRirFQHfkzjlIjJ4frL5SHX 0XVMUmSVUJwooM+61n4rywR7hifQS+KeYY9LZsamjPZQi0UMiOVhudR1uYTxq+pBSHJ4HYG65v8 2fNgl7RE0+wn9CBONAou9uIo5h6oSdipDl835CDDXwP1GEbwnjC8x8r3QF1nqdIH7wpqpH+7e X-Received: by 2002:a05:6214:508d:b0:635:e528:521a with SMTP id kk13-20020a056214508d00b00635e528521amr16116507qvb.5.1692051592973; Mon, 14 Aug 2023 15:19:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/evOGKsIYZbCwGebdqpSgKuFa8SlvZ5wszzaIdqBF0rtLyBBjgRlHG8ooiEQ8Ll1xaPx9QQ== X-Received: by 2002:a05:6214:508d:b0:635:e528:521a with SMTP id kk13-20020a056214508d00b00635e528521amr16116468qvb.5.1692051592418; Mon, 14 Aug 2023 15:19:52 -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 s22-20020a05620a16b600b0076ca401d8c7sm3324978qkj.111.2023.08.14.15.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 15:19:52 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Markus Armbruster , Leonardo Bras Soares Passos , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , Fabiano Rosas , peterx@redhat.com, Juan Quintela Subject: [PATCH for-8.2 3/4] migration/qapi: Replace @MigrateSetParameters with @MigrationParameters Date: Mon, 14 Aug 2023 18:19:46 -0400 Message-ID: <20230814221947.353093-4-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230814221947.353093-1-peterx@redhat.com> References: <20230814221947.353093-1-peterx@redhat.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These two structs are mostly identical besides some fields (quote from Daniel P. Berrangé in his reply): 1c1 < { 'struct': 'MigrationParameters', --- > { 'struct': 'MigrateSetParameters', 14,16c14,16 < '*tls-creds': 'str', < '*tls-hostname': 'str', < '*tls-authz': 'str', --- > '*tls-creds': 'StrOrNull', > '*tls-hostname': 'StrOrNull', > '*tls-authz': 'StrOrNull', Here the difference is @MigrateSetParameters object would allow 'null' values for any tls-* fields passed in. Markus used to describe why it happened to be StrOrNull, and also his concern on having a pure "str" type to be problematic as the reset indicator in the commit 01fa559826 ("migration: Use JSON null instead of "" to reset parameter to default"). There, "null" is introduced for the tls fields even though being treated as "" (empty string) internally to match the code. Here to deduplicate the two objects, logically it'll be safe only if we use "StrOrNull" to replace "str" type, not vice versa. However we may face difficulty using StrOrNull as part of MigrationState.parameters [1] when replacing existing @MigrationParameters to use StrOrNull. With the fact that nobody seems to be using "null" for tls-* fields (see the long standing qemu crash bug on tls-authz when "null" was passed in), let's use "str" to represent both objects. This greatly deduplicates the code not only in qapi/migration.json, but also in the generic migration code on handling transitions between StrOrNull <-> str types. [1] https://lore.kernel.org/all/ZNKfoqM0V6pcvrz%2F@x1n/ Signed-off-by: Peter Xu --- qapi/migration.json | 185 +-------------------------------- migration/migration-hmp-cmds.c | 16 +-- migration/options.c | 145 ++------------------------ 3 files changed, 12 insertions(+), 334 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 8843e74b59..0416da65b5 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -851,189 +851,6 @@ { 'name': 'x-vcpu-dirty-limit-period', 'features': ['unstable'] }, 'vcpu-dirty-limit'] } -## -# @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' } ## # @MigrationParameters: diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index c115ef2d23..a64672f640 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -497,7 +497,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) const char *param = qdict_get_str(qdict, "parameter"); const char *valuestr = qdict_get_str(qdict, "value"); Visitor *v = string_input_visitor_new(valuestr); - MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); + MigrationParameters *p = g_new0(MigrationParameters, 1); uint64_t valuebw = 0; uint64_t cache_size; Error *err = NULL; @@ -546,19 +546,13 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) visit_type_uint8(v, param, &p->max_cpu_throttle, &err); break; case MIGRATION_PARAMETER_TLS_CREDS: - p->tls_creds = g_new0(StrOrNull, 1); - p->tls_creds->type = QTYPE_QSTRING; - visit_type_str(v, param, &p->tls_creds->u.s, &err); + visit_type_str(v, param, &p->tls_creds, &err); break; case MIGRATION_PARAMETER_TLS_HOSTNAME: - p->tls_hostname = g_new0(StrOrNull, 1); - p->tls_hostname->type = QTYPE_QSTRING; - visit_type_str(v, param, &p->tls_hostname->u.s, &err); + visit_type_str(v, param, &p->tls_hostname, &err); break; case MIGRATION_PARAMETER_TLS_AUTHZ: - p->tls_authz = g_new0(StrOrNull, 1); - p->tls_authz->type = QTYPE_QSTRING; - visit_type_str(v, param, &p->tls_authz->u.s, &err); + visit_type_str(v, param, &p->tls_authz, &err); break; case MIGRATION_PARAMETER_MAX_BANDWIDTH: p->has_max_bandwidth = true; @@ -657,7 +651,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) qmp_migrate_set_parameters(p, &err); 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..7967c572fc 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1172,113 +1172,7 @@ bool migrate_params_check(MigrationParameters *params, Error **errp) return true; } -static void migrate_params_test_apply(MigrateSetParameters *params, - MigrationParameters *dest) -{ - *dest = migrate_get_current()->parameters; - - /* TODO use QAPI_CLONE() instead of duplicating it inline */ - - if (params->has_compress_level) { - dest->compress_level = params->compress_level; - } - - if (params->has_compress_threads) { - dest->compress_threads = params->compress_threads; - } - - if (params->has_compress_wait_thread) { - dest->compress_wait_thread = params->compress_wait_thread; - } - - if (params->has_decompress_threads) { - dest->decompress_threads = params->decompress_threads; - } - - if (params->has_throttle_trigger_threshold) { - dest->throttle_trigger_threshold = params->throttle_trigger_threshold; - } - - if (params->has_cpu_throttle_initial) { - dest->cpu_throttle_initial = params->cpu_throttle_initial; - } - - if (params->has_cpu_throttle_increment) { - dest->cpu_throttle_increment = params->cpu_throttle_increment; - } - - if (params->has_cpu_throttle_tailslow) { - dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow; - } - - if (params->tls_creds) { - assert(params->tls_creds->type == QTYPE_QSTRING); - dest->tls_creds = params->tls_creds->u.s; - } - - if (params->tls_hostname) { - assert(params->tls_hostname->type == QTYPE_QSTRING); - dest->tls_hostname = params->tls_hostname->u.s; - } - - if (params->has_max_bandwidth) { - dest->max_bandwidth = params->max_bandwidth; - } - - if (params->has_downtime_limit) { - dest->downtime_limit = params->downtime_limit; - } - - if (params->has_x_checkpoint_delay) { - dest->x_checkpoint_delay = params->x_checkpoint_delay; - } - - if (params->has_block_incremental) { - dest->block_incremental = params->block_incremental; - } - if (params->has_multifd_channels) { - dest->multifd_channels = params->multifd_channels; - } - if (params->has_multifd_compression) { - dest->multifd_compression = params->multifd_compression; - } - if (params->has_xbzrle_cache_size) { - dest->xbzrle_cache_size = params->xbzrle_cache_size; - } - if (params->has_max_postcopy_bandwidth) { - dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth; - } - if (params->has_max_cpu_throttle) { - dest->max_cpu_throttle = params->max_cpu_throttle; - } - if (params->has_announce_initial) { - dest->announce_initial = params->announce_initial; - } - if (params->has_announce_max) { - dest->announce_max = params->announce_max; - } - if (params->has_announce_rounds) { - dest->announce_rounds = params->announce_rounds; - } - if (params->has_announce_step) { - dest->announce_step = params->announce_step; - } - - if (params->has_block_bitmap_mapping) { - dest->has_block_bitmap_mapping = true; - dest->block_bitmap_mapping = params->block_bitmap_mapping; - } - - if (params->has_x_vcpu_dirty_limit_period) { - dest->x_vcpu_dirty_limit_period = - params->x_vcpu_dirty_limit_period; - } - if (params->has_vcpu_dirty_limit) { - dest->vcpu_dirty_limit = params->vcpu_dirty_limit; - } -} - -static void migrate_params_apply(MigrateSetParameters *params, Error **errp) +static void migrate_params_apply(MigrationParameters *params, Error **errp) { MigrationState *s = migrate_get_current(); @@ -1318,20 +1212,17 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) if (params->tls_creds) { g_free(s->parameters.tls_creds); - assert(params->tls_creds->type == QTYPE_QSTRING); - s->parameters.tls_creds = g_strdup(params->tls_creds->u.s); + s->parameters.tls_creds = g_strdup(params->tls_creds); } if (params->tls_hostname) { g_free(s->parameters.tls_hostname); - assert(params->tls_hostname->type == QTYPE_QSTRING); - s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s); + s->parameters.tls_hostname = g_strdup(params->tls_hostname); } if (params->tls_authz) { g_free(s->parameters.tls_authz); - assert(params->tls_authz->type == QTYPE_QSTRING); - s->parameters.tls_authz = g_strdup(params->tls_authz->u.s); + s->parameters.tls_authz = g_strdup(params->tls_authz); } if (params->has_max_bandwidth) { @@ -1404,33 +1295,9 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) } } -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 == QTYPE_QNULL) { - qobject_unref(params->tls_creds->u.n); - params->tls_creds->type = QTYPE_QSTRING; - params->tls_creds->u.s = strdup(""); - } - if (params->tls_hostname - && params->tls_hostname->type == QTYPE_QNULL) { - qobject_unref(params->tls_hostname->u.n); - params->tls_hostname->type = QTYPE_QSTRING; - params->tls_hostname->u.s = strdup(""); - } - if (params->tls_authz - && params->tls_authz->type == QTYPE_QNULL) { - qobject_unref(params->tls_authz->u.n); - params->tls_authz->type = QTYPE_QSTRING; - params->tls_authz->u.s = strdup(""); - } - - migrate_params_test_apply(params, &tmp); - - if (!migrate_params_check(&tmp, errp)) { + if (!migrate_params_check(params, errp)) { /* Invalid parameter */ return; } From patchwork Mon Aug 14 22:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1821156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fVqp3b11; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPpkc2r1Fz1yfZ for ; Tue, 15 Aug 2023 08:20:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVfuw-0003DI-Ty; Mon, 14 Aug 2023 18:20:06 -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 1qVfuo-0003C0-S9 for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:58 -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 1qVfum-0005kZ-IB for qemu-devel@nongnu.org; Mon, 14 Aug 2023 18:19:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692051595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8G1TmcSOvXkWNcdrRbm/jqwVssiwOnxMS0EgMMXgNUY=; b=fVqp3b11+1jHUkNz8898yzI6Sagjr14hU9TnDED3yR6miXAWhnXaJx68A1IduB9iT5iqfB DTQGyANnTeFXNYc3XHoUDHQSLi3XmlzIJzf8RtQZrzOyUsjLuk3UgZEZYzeoLd2/6P80iG PGBZBkfuDnOEAWDr+pZe+CP4nAziXrw= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-y9jkMBJTPqGdqQrASL7jgA-1; Mon, 14 Aug 2023 18:19:54 -0400 X-MC-Unique: y9jkMBJTPqGdqQrASL7jgA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76ca3baaec8so133291785a.1 for ; Mon, 14 Aug 2023 15:19:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692051594; x=1692656394; 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=8G1TmcSOvXkWNcdrRbm/jqwVssiwOnxMS0EgMMXgNUY=; b=E71E3EyNZix1ndONhIMeR7pLpC2Df7qORYlGeaAscacKiC0xo/pczL+Dw2tl489uOi j/EZdr1mj02WfYmSI18rGyq7i9rHyKz3GiyH+Xpjz3QJoRYrrW+7ZiABGMlUuOAjNPwf cps5Z0nQasf1Bq9S+UMpoCLEo83uFMQu1Xo9JJZCo6UZthdAJWXMNxLdHmAdS3ymvyB6 qeJH2sj2NNFAQSnX/nPs1Pf3lpnab4Qw4Kbw3EQ8g8Kf5MkyG3GPmi6ph8zdRAvoVwdi GkDmfG9o1EjdIBmQ6MAFlyakZytq6B5qIQj2rxdZwEtLnbMKYgkK50QlSjwlQDtUzqHD 60tA== X-Gm-Message-State: AOJu0YzGrqyK6iFMFZ9Iq8AQzz1QYew476E6x/m/9VWpCiADDF6Fc/Kb Smv8mnM/s9mPuNzLE+CCbWCr1ZNP/wAoYD9AlyaJ+1oC0jyQL2GpE0jxFeVxvCuSlU/Rktrnj1y ZGZGXt6stYLc2gnJp7Chwpg6z4ziidost9aRI7pDBVSwGB2a5QkHtQioqn3rvw5Eg9NILbPZ6 X-Received: by 2002:a05:620a:4706:b0:76d:3475:2e0d with SMTP id bs6-20020a05620a470600b0076d34752e0dmr14909976qkb.3.1692051593707; Mon, 14 Aug 2023 15:19:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYfNcZQuBRNIMq8IvHjGKDHqBqMjverKkfSN/spJaNg7Ytwk5rwUCtY8mb2kSq4/hgaoK8QQ== X-Received: by 2002:a05:620a:4706:b0:76d:3475:2e0d with SMTP id bs6-20020a05620a470600b0076d34752e0dmr14909943qkb.3.1692051593235; Mon, 14 Aug 2023 15:19:53 -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 s22-20020a05620a16b600b0076ca401d8c7sm3324978qkj.111.2023.08.14.15.19.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 15:19:53 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Markus Armbruster , Leonardo Bras Soares Passos , =?utf-8?q?Daniel_P_=2E_B?= =?utf-8?q?errang=C3=A9?= , Fabiano Rosas , peterx@redhat.com, Juan Quintela Subject: [PATCH for-8.2 4/4] migration/qapi: Drop @MigrationParameter enum Date: Mon, 14 Aug 2023 18:19:47 -0400 Message-ID: <20230814221947.353093-5-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230814221947.353093-1-peterx@redhat.com> References: <20230814221947.353093-1-peterx@redhat.com> MIME-Version: 1.0 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. One of the important things is we can deduplicate the documentations on the various migration parameters. Signed-off-by: Peter Xu --- 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 0416da65b5..4846b2a98e 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -672,185 +672,6 @@ 'bitmaps': [ 'BitmapMigrationBitmapAlias' ] } } -## -# @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 045e2a41a2..b1b3a26604 100644 --- a/migration/options.h +++ b/migration/options.h @@ -65,6 +65,53 @@ bool migrate_cap_set(int cap, bool value, Error **errp); /* parameters */ +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 (>=0) if succeed, or negative otherwise + * 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); diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index a64672f640..68c68079c2 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" static void migration_global_dump(Monitor *mon) { @@ -503,7 +504,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) Error *err = NULL; int val, ret; - val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); + val = MigrationParameter_from_str(param, &err); if (val < 0) { goto cleanup; } diff --git a/migration/options.c b/migration/options.c index 7967c572fc..0e661bc251 100644 --- a/migration/options.c +++ b/migration/options.c @@ -84,6 +84,57 @@ #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD 1000 /* milliseconds */ #define DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT 1 /* MB/s */ +const char *MigrationParameter_string[MIGRATION_PARAMETER__MAX] = { + [MIGRATION_PARAMETER_ANNOUNCE_INITIAL] = "announce-initial", + [MIGRATION_PARAMETER_ANNOUNCE_MAX] = "announce-max", + [MIGRATION_PARAMETER_ANNOUNCE_ROUNDS] = "announce-rounds", + [MIGRATION_PARAMETER_ANNOUNCE_STEP] = "announce-step", + [MIGRATION_PARAMETER_COMPRESS_LEVEL] = "compress-level", + [MIGRATION_PARAMETER_COMPRESS_THREADS] = "compress-threads", + [MIGRATION_PARAMETER_DECOMPRESS_THREADS] = "decompress-threads", + [MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD] = "compress-wait-thread", + [MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD] = "throttle-trigger-threshold", + [MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL] = "cpu-throttle-initial", + [MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT] = "cpu-throttle-increment", + [MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW] = "cpu-throttle-tailslow", + [MIGRATION_PARAMETER_TLS_CREDS] = "tls-creds", + [MIGRATION_PARAMETER_TLS_HOSTNAME] = "tls-hostname", + [MIGRATION_PARAMETER_TLS_AUTHZ] = "tls-authz", + [MIGRATION_PARAMETER_MAX_BANDWIDTH] = "max-bandwidth", + [MIGRATION_PARAMETER_DOWNTIME_LIMIT] = "downtime-limit", + [MIGRATION_PARAMETER_X_CHECKPOINT_DELAY] = "x-checkpoint-delay", + [MIGRATION_PARAMETER_BLOCK_INCREMENTAL] = "block-incremental", + [MIGRATION_PARAMETER_MULTIFD_CHANNELS] = "multifd-channels", + [MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE] = "xbzrle-cache-size", + [MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH] = "max-postcopy-bandwidth", + [MIGRATION_PARAMETER_MAX_CPU_THROTTLE] = "max-cpu-throttle", + [MIGRATION_PARAMETER_MULTIFD_COMPRESSION] = "multifd-compression", + [MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL] = "multifd-zlib-level", + [MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL] = "multifd-zstd-level", + [MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING] = "block-bitmap-mapping", + [MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD] = "x-vcpu-dirty-limit-period", + [MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT] = "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 = 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[] = { DEFINE_PROP_BOOL("store-global-state", MigrationState, store_global_state, true),