From nobody Mon Feb 9 03:32:01 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1768397030; cv=none; d=zohomail.com; s=zohoarc; b=Z7UZOcrDkrF+DQM5UwSrcoWRMPyLO/4pekWcWhhH0n6kQSTdDEVHr/OkuwKXZ9VjHnGyXysmCBcTQdkEavam8EkpiHtb4byvnSMjxB25eBdAcUdFnLZR22pdk+69h8kg1guU+wPO3zTXuUAwsCnJ/+aA80/A40AFyblciTdFT8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768397030; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gO7n4Urr6hm6clxfB41ChkGtIPUsT3p3qG1EnyhtOjU=; b=AnG1Eujc/RNiH/vAf8ggZCyUcoLGwEYtJ4jiEq6S/jMp5Q2yYGYVUoQvGYp7P6JWuDCSrJ7qZ1tlCybV01VhuKEzG9X9iN6W2W3Jxz94UtkR7QM5vCXStRybwqGZcYg1RGOfYWQpjveVTNa+EoDtZkmmc9g9gVnWylq/PQqgbGY= 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 1768397030720927.7501160735071; Wed, 14 Jan 2026 05:23:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vg0qM-0006Xu-9K; Wed, 14 Jan 2026 08:23:26 -0500 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 1vg0qJ-0006XK-Sf for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:23 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vg0qI-0006hQ-7O for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:23 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 42DD75C73C; Wed, 14 Jan 2026 13:23:15 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id ECD593EA63; Wed, 14 Jan 2026 13:23:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id YMWWKsGYZ2nxBwAAD6G6ig (envelope-from ); Wed, 14 Jan 2026 13:23:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768396995; h=from:from:reply-to: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=gO7n4Urr6hm6clxfB41ChkGtIPUsT3p3qG1EnyhtOjU=; b=FQQAWAyFpn8rD/fRi3VcG8o7sdb8M0E512ejfiCJOq4Pwvp57IL2f6dHWPcLdFdCNztSAw tSRTiZsnqy+oFxONDUVjwtQGFwo3qKSuvQZM1ViO2qRo3OPepL7x3rGeMiDRz1fW+sMcoY Vu+jRFhE7/0oVfu0L22H0A0tJoQZMBk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768396995; h=from:from:reply-to: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=gO7n4Urr6hm6clxfB41ChkGtIPUsT3p3qG1EnyhtOjU=; b=WUAUrpejBIJvzwEINb0I5wNfC3IvkrlvBGls2vedH4AW5+S8xhXdhXTjU3LiAHUwDCevBQ sSDse6qr3kl0KHAQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768396995; h=from:from:reply-to: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=gO7n4Urr6hm6clxfB41ChkGtIPUsT3p3qG1EnyhtOjU=; b=FQQAWAyFpn8rD/fRi3VcG8o7sdb8M0E512ejfiCJOq4Pwvp57IL2f6dHWPcLdFdCNztSAw tSRTiZsnqy+oFxONDUVjwtQGFwo3qKSuvQZM1ViO2qRo3OPepL7x3rGeMiDRz1fW+sMcoY Vu+jRFhE7/0oVfu0L22H0A0tJoQZMBk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768396995; h=from:from:reply-to: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=gO7n4Urr6hm6clxfB41ChkGtIPUsT3p3qG1EnyhtOjU=; b=WUAUrpejBIJvzwEINb0I5wNfC3IvkrlvBGls2vedH4AW5+S8xhXdhXTjU3LiAHUwDCevBQ sSDse6qr3kl0KHAQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: peterx@redhat.com, armbru@redhat.com Subject: [PATCH 1/5] migration: Use QAPI_CLONE_MEMBERS in migrate_params_test_apply Date: Wed, 14 Jan 2026 10:23:05 -0300 Message-ID: <20260114132309.5832-2-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114132309.5832-1-farosas@suse.de> References: <20260114132309.5832-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] 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 (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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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 @suse.de) X-ZM-MESSAGEID: 1768397031450158500 Content-Type: text/plain; charset="utf-8" Use QAPI_CLONE_MEMBERS instead of making an assignment. The QAPI method makes the handling of the TLS strings more intuitive because it clones them as well. Signed-off-by: Fabiano Rosas --- migration/options.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/migration/options.c b/migration/options.c index 9a5a39c886..994e1cc5ac 100644 --- a/migration/options.c +++ b/migration/options.c @@ -1264,9 +1264,9 @@ bool migrate_params_check(MigrationParameters *params= , Error **errp) static void migrate_params_test_apply(MigrationParameters *params, MigrationParameters *dest) { - *dest =3D migrate_get_current()->parameters; + MigrationState *s =3D migrate_get_current(); =20 - /* TODO use QAPI_CLONE() instead of duplicating it inline */ + QAPI_CLONE_MEMBERS(MigrationParameters, dest, &s->parameters); =20 if (params->has_throttle_trigger_threshold) { dest->throttle_trigger_threshold =3D params->throttle_trigger_thre= shold; @@ -1285,24 +1285,18 @@ static void migrate_params_test_apply(MigrationPara= meters *params, } =20 if (params->tls_creds) { + qapi_free_StrOrNull(dest->tls_creds); dest->tls_creds =3D QAPI_CLONE(StrOrNull, params->tls_creds); - } else { - /* clear the reference, it's owned by s->parameters */ - dest->tls_creds =3D NULL; } =20 if (params->tls_hostname) { + qapi_free_StrOrNull(dest->tls_hostname); dest->tls_hostname =3D QAPI_CLONE(StrOrNull, params->tls_hostname); - } else { - /* clear the reference, it's owned by s->parameters */ - dest->tls_hostname =3D NULL; } =20 if (params->tls_authz) { + qapi_free_StrOrNull(dest->tls_authz); dest->tls_authz =3D QAPI_CLONE(StrOrNull, params->tls_authz); - } else { - /* clear the reference, it's owned by s->parameters */ - dest->tls_authz =3D NULL; } =20 if (params->has_max_bandwidth) { @@ -1359,8 +1353,9 @@ static void migrate_params_test_apply(MigrationParame= ters *params, } =20 if (params->has_block_bitmap_mapping) { - dest->has_block_bitmap_mapping =3D true; - dest->block_bitmap_mapping =3D params->block_bitmap_mapping; + qapi_free_BitmapMigrationNodeAliasList(dest->block_bitmap_mapping); + dest->block_bitmap_mapping =3D QAPI_CLONE(BitmapMigrationNodeAlias= List, + params->block_bitmap_mappi= ng); } =20 if (params->has_x_vcpu_dirty_limit_period) { @@ -1384,7 +1379,8 @@ static void migrate_params_test_apply(MigrationParame= ters *params, } =20 if (params->has_cpr_exec_command) { - dest->cpr_exec_command =3D params->cpr_exec_command; + qapi_free_strList(dest->cpr_exec_command); + dest->cpr_exec_command =3D QAPI_CLONE(strList, params->cpr_exec_co= mmand); } } =20 @@ -1535,6 +1531,14 @@ void qmp_migrate_set_parameters(MigrationParameters = *params, Error **errp) migrate_params_test_apply(params, &tmp); =20 if (migrate_params_check(&tmp, errp)) { + /* + * Mark block_bitmap_mapping as present now while we have the + * params structure with the user input around. + */ + if (params->has_block_bitmap_mapping) { + migrate_get_current()->has_block_bitmap_mapping =3D true; + } + migrate_params_apply(params); migrate_post_update_params(params, errp); } --=20 2.51.0 From nobody Mon Feb 9 03:32:01 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1768397030; cv=none; d=zohomail.com; s=zohoarc; b=HjRVJFJM1FXMmJbtG6zfhZyc1i1fNWpLvWHY41yhjtXL/oD1Lf4nRN1hJA6BJ2CV0E7khUSWp1mPQnGQjEXtlmEsgIkB0Copz18ELxl0uoPZLCaVTCCZA/iJE4h/IRifgMoBJ42vdyilfNR0oYFHWIaU3jZzCtO6yObuPFqHlgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768397030; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CTiE6gXgBw/wmJ+wJbqSpBvWLRO3+hRy7nQzBPxYil4=; b=X+azteyvBNz7FGWBOsQcMtX5YRaGHc7/R+pd1dFhoufhHfN+fzv4wZTGBKastb/tghpUTjqH87M6eICqNaz+3WuwAze+ihaCPUsCyM//ZYwrGbl/He4onNx5XPYwBo2exJRQKxN8iEaPDFPpT7ADFEMaboYSzdU3HcJXG1zbkYw= 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 1768397030806629.1151388603412; Wed, 14 Jan 2026 05:23:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vg0qH-0006Ws-KQ; Wed, 14 Jan 2026 08:23:21 -0500 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 1vg0qG-0006Wh-EK for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:20 -0500 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vg0qE-0006hG-KR for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:20 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 19DD933F41; Wed, 14 Jan 2026 13:23:17 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CAF2C3EA63; Wed, 14 Jan 2026 13:23:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4FT+IcOYZ2nxBwAAD6G6ig (envelope-from ); Wed, 14 Jan 2026 13:23:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768396997; h=from:from:reply-to: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=CTiE6gXgBw/wmJ+wJbqSpBvWLRO3+hRy7nQzBPxYil4=; b=fC/6h9p68Hy0r0P95JSoVN4XPI2mAYPsisrM917hu4tMlvzE9i7UvCoUdXtYK5DICWR16H xNoLs5JGHjAyflUKifYtBIgW3M6O6kyk2x7NIMCTLrB49lXCtE3G2ldUube17PqL0nhsL5 qZzENNOsi53SoogfmOh1URVv1uYpzXo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768396997; h=from:from:reply-to: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=CTiE6gXgBw/wmJ+wJbqSpBvWLRO3+hRy7nQzBPxYil4=; b=yioBY+9z8JQBf+fWVgMwkebVM/NV6o6NwBelHearR0h5J5LN1L0dK0kGVtNcxHE0aPTA4o VZjaFlpGpuGSU6BA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768396997; h=from:from:reply-to: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=CTiE6gXgBw/wmJ+wJbqSpBvWLRO3+hRy7nQzBPxYil4=; b=fC/6h9p68Hy0r0P95JSoVN4XPI2mAYPsisrM917hu4tMlvzE9i7UvCoUdXtYK5DICWR16H xNoLs5JGHjAyflUKifYtBIgW3M6O6kyk2x7NIMCTLrB49lXCtE3G2ldUube17PqL0nhsL5 qZzENNOsi53SoogfmOh1URVv1uYpzXo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768396997; h=from:from:reply-to: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=CTiE6gXgBw/wmJ+wJbqSpBvWLRO3+hRy7nQzBPxYil4=; b=yioBY+9z8JQBf+fWVgMwkebVM/NV6o6NwBelHearR0h5J5LN1L0dK0kGVtNcxHE0aPTA4o VZjaFlpGpuGSU6BA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: peterx@redhat.com, armbru@redhat.com Subject: [PATCH 2/5] migration: Use QAPI_CLONE_MEMBERS in migrate_params_apply Date: Wed, 14 Jan 2026 10:23:06 -0300 Message-ID: <20260114132309.5832-3-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114132309.5832-1-farosas@suse.de> References: <20260114132309.5832-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid, suse.de:email, imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -2.80 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 (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=195.135.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: qemu development 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 @suse.de) X-ZM-MESSAGEID: 1768397031489158500 Content-Type: text/plain; charset="utf-8" Instead of setting parameters one by one, use the temporary object, which already contains the current migration parameters plus the new ones and was just validated by migration_params_check(). Use cloning to overwrite it. This avoids the need to alter this function every time a new parameter is added. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas Reviewed-by: Prasad Pandit --- migration/options.c | 134 ++++---------------------------------------- 1 file changed, 12 insertions(+), 122 deletions(-) diff --git a/migration/options.c b/migration/options.c index 994e1cc5ac..7a16119ff8 100644 --- a/migration/options.c +++ b/migration/options.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/main-loop.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -1384,132 +1385,21 @@ static void migrate_params_test_apply(MigrationPar= ameters *params, } } =20 +/* + * Caller must ensure all has_* fields of @params are true to ensure + * all fields get copied and the pointer members don't dangle. + */ static void migrate_params_apply(MigrationParameters *params) { MigrationState *s =3D migrate_get_current(); + MigrationParameters *cur =3D &s->parameters; =20 - /* TODO use QAPI_CLONE() instead of duplicating it inline */ + assert(bql_locked()); =20 - if (params->has_throttle_trigger_threshold) { - s->parameters.throttle_trigger_threshold =3D params->throttle_trig= ger_threshold; - } - - if (params->has_cpu_throttle_initial) { - s->parameters.cpu_throttle_initial =3D params->cpu_throttle_initia= l; - } - - if (params->has_cpu_throttle_increment) { - s->parameters.cpu_throttle_increment =3D params->cpu_throttle_incr= ement; - } - - if (params->has_cpu_throttle_tailslow) { - s->parameters.cpu_throttle_tailslow =3D params->cpu_throttle_tails= low; - } - - if (params->tls_creds) { - qapi_free_StrOrNull(s->parameters.tls_creds); - s->parameters.tls_creds =3D QAPI_CLONE(StrOrNull, params->tls_cred= s); - } - - if (params->tls_hostname) { - qapi_free_StrOrNull(s->parameters.tls_hostname); - s->parameters.tls_hostname =3D QAPI_CLONE(StrOrNull, - params->tls_hostname); - } - - if (params->tls_authz) { - qapi_free_StrOrNull(s->parameters.tls_authz); - s->parameters.tls_authz =3D QAPI_CLONE(StrOrNull, params->tls_auth= z); - } - - if (params->has_max_bandwidth) { - s->parameters.max_bandwidth =3D params->max_bandwidth; - } - - if (params->has_avail_switchover_bandwidth) { - s->parameters.avail_switchover_bandwidth =3D params->avail_switcho= ver_bandwidth; - } - - if (params->has_downtime_limit) { - s->parameters.downtime_limit =3D params->downtime_limit; - } - - if (params->has_x_checkpoint_delay) { - s->parameters.x_checkpoint_delay =3D params->x_checkpoint_delay; - } - - if (params->has_multifd_channels) { - s->parameters.multifd_channels =3D params->multifd_channels; - } - if (params->has_multifd_compression) { - s->parameters.multifd_compression =3D params->multifd_compression; - } - if (params->has_multifd_qatzip_level) { - s->parameters.multifd_qatzip_level =3D params->multifd_qatzip_leve= l; - } - if (params->has_multifd_zlib_level) { - s->parameters.multifd_zlib_level =3D params->multifd_zlib_level; - } - if (params->has_multifd_zstd_level) { - s->parameters.multifd_zstd_level =3D params->multifd_zstd_level; - } - if (params->has_xbzrle_cache_size) { - s->parameters.xbzrle_cache_size =3D params->xbzrle_cache_size; - } - if (params->has_max_postcopy_bandwidth) { - s->parameters.max_postcopy_bandwidth =3D params->max_postcopy_band= width; - } - if (params->has_max_cpu_throttle) { - s->parameters.max_cpu_throttle =3D params->max_cpu_throttle; - } - if (params->has_announce_initial) { - s->parameters.announce_initial =3D params->announce_initial; - } - if (params->has_announce_max) { - s->parameters.announce_max =3D params->announce_max; - } - if (params->has_announce_rounds) { - s->parameters.announce_rounds =3D params->announce_rounds; - } - if (params->has_announce_step) { - s->parameters.announce_step =3D params->announce_step; - } - - if (params->has_block_bitmap_mapping) { - qapi_free_BitmapMigrationNodeAliasList( - s->parameters.block_bitmap_mapping); - - s->has_block_bitmap_mapping =3D true; - s->parameters.block_bitmap_mapping =3D - QAPI_CLONE(BitmapMigrationNodeAliasList, - params->block_bitmap_mapping); - } - - if (params->has_x_vcpu_dirty_limit_period) { - s->parameters.x_vcpu_dirty_limit_period =3D - params->x_vcpu_dirty_limit_period; - } - if (params->has_vcpu_dirty_limit) { - s->parameters.vcpu_dirty_limit =3D params->vcpu_dirty_limit; - } - - if (params->has_mode) { - s->parameters.mode =3D params->mode; - } - - if (params->has_zero_page_detection) { - s->parameters.zero_page_detection =3D params->zero_page_detection; - } - - if (params->has_direct_io) { - s->parameters.direct_io =3D params->direct_io; - } - - if (params->has_cpr_exec_command) { - qapi_free_strList(s->parameters.cpr_exec_command); - s->parameters.cpr_exec_command =3D - QAPI_CLONE(strList, params->cpr_exec_command); - } + migrate_tls_opts_free(cur); + qapi_free_BitmapMigrationNodeAliasList(cur->block_bitmap_mapping); + qapi_free_strList(cur->cpr_exec_command); + QAPI_CLONE_MEMBERS(MigrationParameters, cur, params); } =20 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) @@ -1539,7 +1429,7 @@ void qmp_migrate_set_parameters(MigrationParameters *= params, Error **errp) migrate_get_current()->has_block_bitmap_mapping =3D true; } =20 - migrate_params_apply(params); + migrate_params_apply(&tmp); migrate_post_update_params(params, errp); } =20 --=20 2.51.0 From nobody Mon Feb 9 03:32:01 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1768397035; cv=none; d=zohomail.com; s=zohoarc; b=hMkDrQnwf/Q7iu3dqqj14LjA96I7RxtkCl6coh9cjvaB2Rr8yis0kpxT+GeV791MQPyGIzOOL3gjv/IDtlaH1kHPjbV47bX7zNXCgcZrxR4pT80A6H6Md3wUbSG5BkuCio+PtyV9zWCaYtlbSXFluXhumMws3NrSClYwwuMCHNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768397035; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eNQTdQp3G977GJsacAmbdN8CKP9bd2OWQw4XQhW6u44=; b=C1jSNrnJ7lQqhc0zASp4nYvhZu+HY577w6JO7G1nGo1ZLtFLS/CSlKya2oUNTmNGkdnah5jW3LITSCV+yzD2J7rIuJATYdytnUZMIi/NGRbk4ZT2cfgfLIxzhjepDYtSDFsw1QL0DmqUCf3viGWqJqRvCp27BJRCGD6Vhl6vsug= 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 1768397035208958.0887433767416; Wed, 14 Jan 2026 05:23:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vg0qk-0006uq-1j; Wed, 14 Jan 2026 08:23:51 -0500 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 1vg0qP-0006YF-Cc for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:30 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vg0qN-0006if-D8 for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:29 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 24D825C66B; Wed, 14 Jan 2026 13:23:19 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9A3FE3EA63; Wed, 14 Jan 2026 13:23:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2N7IFsWYZ2nxBwAAD6G6ig (envelope-from ); Wed, 14 Jan 2026 13:23:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768396999; h=from:from:reply-to: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=eNQTdQp3G977GJsacAmbdN8CKP9bd2OWQw4XQhW6u44=; b=DCtYpSwDdkVeOVgfNtnZBPRjQ3u7e8QVjSFCzN2s27SkzPUoWANLn6MJMney4mZgm42dwD e2RGpgxOeod7EszGbNHkafCbmrG1kNIEeUH2GUC1DmGcXExkzEOfLNqab5GNZUT/C5OXJT xtEPWfv/csNv9wj8TiVZycKr47scMbw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768396999; h=from:from:reply-to: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=eNQTdQp3G977GJsacAmbdN8CKP9bd2OWQw4XQhW6u44=; b=5wJDjlQPTocGH5Qhw+NwZrkE/lvB3Qj161oLCdkuqqikhbu/D/V5RPYXFKcmrZc7cWuVHm /Zv9p8+5aZgJqmBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=DCtYpSwD; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=5wJDjlQP DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768396999; h=from:from:reply-to: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=eNQTdQp3G977GJsacAmbdN8CKP9bd2OWQw4XQhW6u44=; b=DCtYpSwDdkVeOVgfNtnZBPRjQ3u7e8QVjSFCzN2s27SkzPUoWANLn6MJMney4mZgm42dwD e2RGpgxOeod7EszGbNHkafCbmrG1kNIEeUH2GUC1DmGcXExkzEOfLNqab5GNZUT/C5OXJT xtEPWfv/csNv9wj8TiVZycKr47scMbw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768396999; h=from:from:reply-to: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=eNQTdQp3G977GJsacAmbdN8CKP9bd2OWQw4XQhW6u44=; b=5wJDjlQPTocGH5Qhw+NwZrkE/lvB3Qj161oLCdkuqqikhbu/D/V5RPYXFKcmrZc7cWuVHm /Zv9p8+5aZgJqmBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: peterx@redhat.com, armbru@redhat.com, Michael Roth Subject: [PATCH 3/5] qapi: Implement qapi_dealloc_present_visitor Date: Wed, 14 Jan 2026 10:23:07 -0300 Message-ID: <20260114132309.5832-4-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114132309.5832-1-farosas@suse.de> References: <20260114132309.5832-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:dkim,suse.de:mid,suse.de:email]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Queue-Id: 24D825C66B X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: qemu development 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 @suse.de) X-ZM-MESSAGEID: 1768397037266158500 Content-Type: text/plain; charset="utf-8" Implement a visitor that frees the pointer members of the visited QAPI object in the same way that qapi_dealloc_visitor does, but similarly to qobject_input_visitor, takes an input QObject that will dictate which members get freed and which don't. Members not present in the input QObject will be left unchanged in the visited QAPI object. This is useful to free memory just before perfoming a visit with qobject_input_visitor on a pre-existing, non-null QAPI object. If the same QObject is passed to both visitors, the pointers overwritten by the input visitor match the ones that are freed by the dealloc visitor. Signed-off-by: Fabiano Rosas --- include/qapi/dealloc-visitor.h | 6 ++ qapi/qapi-dealloc-visitor.c | 173 ++++++++++++++++++++++++++++++++- 2 files changed, 178 insertions(+), 1 deletion(-) diff --git a/include/qapi/dealloc-visitor.h b/include/qapi/dealloc-visitor.h index c36715fdf3..96c7bf35c3 100644 --- a/include/qapi/dealloc-visitor.h +++ b/include/qapi/dealloc-visitor.h @@ -25,4 +25,10 @@ typedef struct QapiDeallocVisitor QapiDeallocVisitor; */ Visitor *qapi_dealloc_visitor_new(void); =20 +/* + * Like qapi_dealloc_visitor_new but visits a QObject and only frees + * present members. + */ +Visitor *qapi_dealloc_present_visitor_new(QObject *); + #endif diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index 57a2c904bb..90b017cc93 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -14,14 +14,146 @@ =20 #include "qemu/osdep.h" #include "qapi/dealloc-visitor.h" +#include "qemu/queue.h" +#include "qobject/qdict.h" +#include "qobject/qlist.h" #include "qobject/qnull.h" #include "qapi/visitor-impl.h" =20 +typedef struct QStackEntry { + QObject *obj; /* QDict or QList being visited */ + void *qapi; + const QListEntry *entry; /* If @obj is QList: unvisited tail */ + QSLIST_ENTRY(QStackEntry) node; +} QStackEntry; + struct QapiDeallocVisitor { Visitor visitor; + QObject *root; + QSLIST_HEAD(, QStackEntry) stack; }; =20 +static void qapi_dealloc_pop(Visitor *v, void **obj) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + QStackEntry *se =3D QSLIST_FIRST(&qdv->stack); + + assert(se && se->qapi =3D=3D obj); + QSLIST_REMOVE_HEAD(&qdv->stack, node); + g_free(se); +} + +static void qapi_dealloc_push(Visitor *v, QObject *obj, void *qapi) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + QStackEntry *se =3D g_new0(QStackEntry, 1); + + assert(obj); + se->obj =3D obj; + se->qapi =3D qapi; + + if (qobject_type(obj) =3D=3D QTYPE_QLIST) { + se->entry =3D qlist_first(qobject_to(QList, obj)); + } + + QSLIST_INSERT_HEAD(&qdv->stack, se, node); +} + +static QObject *qapi_dealloc_try_get_object(QapiDeallocVisitor *qdv, const= char *name) +{ + QStackEntry *se =3D QSLIST_FIRST(&qdv->stack); + QObject *qobj; + QObject *ret =3D NULL; + + if (!se) { + assert(qdv->root); + return qdv->root; + } + + qobj =3D se->obj; + assert(qobj); + + if (qobject_type(qobj) =3D=3D QTYPE_QDICT) { + assert(name); + ret =3D qdict_get(qobject_to(QDict, qobj), name); + } else { + assert(qobject_type(qobj) =3D=3D QTYPE_QLIST); + assert(!name); + if (se->entry) { + ret =3D qlist_entry_obj(se->entry); + } + } + + return ret; +} + +static bool qapi_dealloc_present_start_struct(Visitor *v, const char *name, + void **obj, size_t size, + Error **errp) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + QObject *qobj =3D qapi_dealloc_try_get_object(qdv, name); + + if (!qobj) { + return false; + } + assert(qobject_type(qobj) =3D=3D QTYPE_QDICT); + qapi_dealloc_push(v, qobj, obj); + return true; +} + +static void qapi_dealloc_present_end_struct(Visitor *v, void **obj) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + QStackEntry *se =3D QSLIST_FIRST(&qdv->stack); + + assert(qobject_type(se->obj) =3D=3D QTYPE_QDICT); + qapi_dealloc_pop(v, obj); + + if (obj) { + g_free(*obj); + } +} + +static bool qapi_dealloc_present_start_list(Visitor *v, const char *name, + GenericList **list, size_t siz= e, + Error **errp) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + QObject *qobj =3D qapi_dealloc_try_get_object(qdv, name); + + if (!qobj) { + return false; + } + assert(qobject_type(qobj) =3D=3D QTYPE_QLIST); + qapi_dealloc_push(v, qobj, list); + return true; +} + +static void qapi_dealloc_present_end_list(Visitor *v, void **obj) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + QStackEntry *se =3D QSLIST_FIRST(&qdv->stack); + + assert(qobject_type(se->obj) =3D=3D QTYPE_QLIST); + qapi_dealloc_pop(v, obj); +} + +static void qapi_dealloc_present_free(Visitor *v) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + + while (!QSLIST_EMPTY(&qdv->stack)) { + QStackEntry *se =3D QSLIST_FIRST(&qdv->stack); + + QSLIST_REMOVE_HEAD(&qdv->stack, node); + g_free(se); + } + qobject_unref(qdv->root); + g_free(qdv); +} + static bool qapi_dealloc_start_struct(Visitor *v, const char *name, void *= *obj, size_t unused, Error **errp) { @@ -35,6 +167,21 @@ static void qapi_dealloc_end_struct(Visitor *v, void **= obj) } } =20 +static bool qapi_dealloc_start_alternate(Visitor *v, const char *name, + GenericAlternate **obj, size_t si= ze, + Error **errp) +{ + QapiDeallocVisitor *qdv =3D container_of(v, QapiDeallocVisitor, visito= r); + QObject *qobj =3D qapi_dealloc_try_get_object(qdv, name); + + if (!qobj) { + return false; + } + assert(*obj); + (*obj)->type =3D qobject_type(qobj); + return true; +} + static void qapi_dealloc_end_alternate(Visitor *v, void **obj) { if (obj) { @@ -117,13 +264,14 @@ static void qapi_dealloc_free(Visitor *v) g_free(container_of(v, QapiDeallocVisitor, visitor)); } =20 -Visitor *qapi_dealloc_visitor_new(void) +static QapiDeallocVisitor *qapi_dealloc_visitor_new_base(void) { QapiDeallocVisitor *v; =20 v =3D g_malloc0(sizeof(*v)); =20 v->visitor.type =3D VISITOR_DEALLOC; + v->visitor.start_struct =3D qapi_dealloc_start_struct; v->visitor.end_struct =3D qapi_dealloc_end_struct; v->visitor.end_alternate =3D qapi_dealloc_end_alternate; @@ -139,5 +287,28 @@ Visitor *qapi_dealloc_visitor_new(void) v->visitor.type_null =3D qapi_dealloc_type_null; v->visitor.free =3D qapi_dealloc_free; =20 + return v; +} + +Visitor *qapi_dealloc_visitor_new(void) +{ + QapiDeallocVisitor *v =3D qapi_dealloc_visitor_new_base(); + + return &v->visitor; +} + +Visitor *qapi_dealloc_present_visitor_new(QObject *obj) +{ + QapiDeallocVisitor *v =3D qapi_dealloc_visitor_new_base(); + + v->visitor.start_alternate =3D qapi_dealloc_start_alternate; + v->visitor.start_list =3D qapi_dealloc_present_start_list; + v->visitor.end_list =3D qapi_dealloc_present_end_list; + v->visitor.start_struct =3D qapi_dealloc_present_start_struct; + v->visitor.end_struct =3D qapi_dealloc_present_end_struct; + v->visitor.free =3D qapi_dealloc_present_free; + + v->root =3D qobject_ref(obj); + return &v->visitor; } --=20 2.51.0 From nobody Mon Feb 9 03:32:01 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1768397025; cv=none; d=zohomail.com; s=zohoarc; b=hM3XsL5AOFW7n9GOOvmO8/DmCG9ujOXfLkuktjDWbpk/teLZ7ZvTdFEtWPWjrx2CZ2SAzIhryC9GhsDlD63tSR33DTckga864PFigrG6psKB3GPniEeh8AOJhc4zocOJqksnM2UVgHw3S2rFrJ+FVW3LB9Yc9RHzyf69u6oE1tY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768397025; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=mTx5PYckMY8BChMbuEeJgbhgzoj8KzCcyr85wVmv2jjQb5/AOICBYPAVolTQwrs38ZAFsBdAGFYmktgUD3WwLpK60ws1yxZ2rOclEH2UmtUvw5NKEDpBcR8BAs1z6IurxpLvAr21oguFrZ0XkaiyZFjcss9Wk2nk7EdfPc1Mxqg= 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 1768397025243298.96132239945723; Wed, 14 Jan 2026 05:23:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vg0qU-0006YJ-4R; Wed, 14 Jan 2026 08:23:34 -0500 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 1vg0qL-0006Xk-V3 for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:25 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vg0qK-0006i9-75 for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:25 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3E9863411C; Wed, 14 Jan 2026 13:23:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A24673EA63; Wed, 14 Jan 2026 13:23:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4A2uGMeYZ2nxBwAAD6G6ig (envelope-from ); Wed, 14 Jan 2026 13:23:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768397001; h=from:from:reply-to: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=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=mqi/+1M+ut4kWCYVsqPJuKH28X/nzdiXLDPbDxCOL+XUysa2kCC2mIZAioW7daIMSjB0E+ Celo07s0WgXiXp51O4Uutna+SwkG/SAwg4DpK+uY6fScyM26GVmwIdpv9KKhEfRjKOOkzX d8eWQAjy1T0EgqdybXF2T0+WGtz+Ytg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768397001; h=from:from:reply-to: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=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=Y7qwDrvTDspUAheKM0Rvt8/xkTTzmND/5Z4VKmvJhVOUz9SpOPRdFDeiwnQ+lvumdrFrFZ pKOwyf258e/loBBA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="mqi/+1M+"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Y7qwDrvT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768397001; h=from:from:reply-to: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=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=mqi/+1M+ut4kWCYVsqPJuKH28X/nzdiXLDPbDxCOL+XUysa2kCC2mIZAioW7daIMSjB0E+ Celo07s0WgXiXp51O4Uutna+SwkG/SAwg4DpK+uY6fScyM26GVmwIdpv9KKhEfRjKOOkzX d8eWQAjy1T0EgqdybXF2T0+WGtz+Ytg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768397001; h=from:from:reply-to: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=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=Y7qwDrvTDspUAheKM0Rvt8/xkTTzmND/5Z4VKmvJhVOUz9SpOPRdFDeiwnQ+lvumdrFrFZ pKOwyf258e/loBBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: peterx@redhat.com, armbru@redhat.com, Michael Roth Subject: [PATCH 4/5] qapi: Add QAPI_MERGE Date: Wed, 14 Jan 2026 10:23:08 -0300 Message-ID: <20260114132309.5832-5-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114132309.5832-1-farosas@suse.de> References: <20260114132309.5832-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Queue-Id: 3E9863411C X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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 @suse.de) X-ZM-MESSAGEID: 1768397027409158500 Content-Type: text/plain; charset="utf-8" The migration subsystem currently has code to merge two objects of the same type. It does so by checking which fields are present in a source object and overwriting the corresponding fields on the destination object. This leads to a lot of open-coded lines such as: if (src->has_foobar) { dst->foobar =3D src->foobar; } This pattern could be replaced by a copy using visitors. Implement a macro that extracts elements from a source object using an output visitor and merges it with a destination object using an input visitor. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- include/qapi/type-helpers.h | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/qapi/type-helpers.h b/include/qapi/type-helpers.h index fc8352cdec..f22d7b7139 100644 --- a/include/qapi/type-helpers.h +++ b/include/qapi/type-helpers.h @@ -10,6 +10,9 @@ */ =20 #include "qapi/qapi-types-common.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-output-visitor.h" +#include "qapi/dealloc-visitor.h" =20 HumanReadableText *human_readable_text_from_str(GString *str); =20 @@ -20,3 +23,40 @@ HumanReadableText *human_readable_text_from_str(GString = *str); * cleanup. */ char **strv_from_str_list(const strList *list); + +/* + * Merge @src over @dst by copying deep clones of the present members + * from @src to @dst. Non-present on @src are left untouched on + * @dst. Pointer members that are overwritten are also freed. + */ +#define QAPI_MERGE(type, dst_, src_) \ + ({ \ + QObject *out_ =3D NULL; \ + Visitor *v_; \ + /* read in from src */ \ + v_ =3D qobject_output_visitor_new(&out_); \ + visit_type_ ## type(v_, NULL, &src_, &error_abort); \ + visit_complete(v_, &out_); \ + visit_free(v_); \ + /* \ + * Free the memory for which the pointers will be overwritten \ + * in the next step. \ + */ \ + v_ =3D qapi_dealloc_present_visitor_new(out_); \ + visit_start_struct(v_, NULL, NULL, 0, &error_abort); \ + visit_type_ ## type ## _members(v_, dst_, &error_abort); \ + visit_end_struct(v_, NULL); \ + visit_free(v_); \ + /* \ + * Write to dst but leave existing fields intact (except for \ + * has_* which will be updated according to their presence in \ + * src). \ + */ \ + v_ =3D qobject_input_visitor_new(out_); \ + visit_start_struct(v_, NULL, NULL, 0, &error_abort); \ + visit_type_ ## type ## _members(v_, dst_, &error_abort); \ + visit_check_struct(v_, &error_abort); \ + visit_end_struct(v_, NULL); \ + visit_free(v_); \ + qobject_unref(out_); \ + }) --=20 2.51.0 From nobody Mon Feb 9 03:32:01 2026 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1768397046; cv=none; d=zohomail.com; s=zohoarc; b=OL2+9NKktc5uiATrFa+0oNV02kZpz/txblsD07Df6EpsmzqBebcBQ1NboE2Y5mT1NrZ3UuSGxLl3Z3OrCnGZ1DXMrqLglA72toZ60Vg3iGzs9YI6Oy5jYdKJ6eEIO2jB8SAgytHPN2xHyjqEf4UvcdeUgaricisnYVb3NvR25s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768397046; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bY+sOVWOMNcH5jIjpfhheng/LErx1HZkY+eTjKO6zng=; b=CE+CJfEoi6P6JcYJd+ZIAGpw6PfYU6JfAesXFptACJGTKP/C6kkajCw0IE//VWT7E8D6srJ8NgQXIwgKXcRZEZNPsENaPX9NB+DT/lggjC8O3suJWIH2TOrcnFXy5LCqXYhur9qm5puMf0NLo9yXF3gy5MoycoSHnZ1UJLvBbZE= 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 1768397046865515.7116209848903; Wed, 14 Jan 2026 05:24:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vg0qm-000712-LN; Wed, 14 Jan 2026 08:23:52 -0500 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 1vg0qV-0006aU-Od for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:43 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vg0qT-0006jN-Ug for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:35 -0500 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F0BF35C733; Wed, 14 Jan 2026 13:23:22 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AA2503EA63; Wed, 14 Jan 2026 13:23:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qCG8GsmYZ2nxBwAAD6G6ig (envelope-from ); Wed, 14 Jan 2026 13:23:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768397003; h=from:from:reply-to: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=bY+sOVWOMNcH5jIjpfhheng/LErx1HZkY+eTjKO6zng=; b=jc2sre9EPGHZrH7VmK+UGAOWZya7Joy1/eink81Pii3qIghZcv0e8yC63/e3CZU4Y08im2 VF1CTr2lYzFzzsqqsp3GA+GnH5uCMGF/8aC01MHoJoSo8aPSVVnVCUK7vuEUbiRcdtmgRm I0Gb7nU2JJpqaEYzC1bhbGEpDf4g40M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768397003; h=from:from:reply-to: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=bY+sOVWOMNcH5jIjpfhheng/LErx1HZkY+eTjKO6zng=; b=1bdhGdoS5U9oHYRFAt7SR8lbmNqR0aZmO1PGz7cidWT0gs+GsbMHFhMwPxqbgb57ea2oI+ sEsUiLsFJrxbqnCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768397002; h=from:from:reply-to: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=bY+sOVWOMNcH5jIjpfhheng/LErx1HZkY+eTjKO6zng=; b=Uv8STb15/7IbflqSRW9WKY0DJBEn2yUvXsWHSzS8zORJNqUGlWts2fF5Mduy6ytn1FWpud Ico4B7IoxJxCVcmgI7+g/+m8Q5FXEVVhaKXv6paUVNHMaTFPC88NTC/PT6p5eOScRTfbLD 8Kx5LIdhX+Z/8bLdXVUuyXNt6CqVOhY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768397002; h=from:from:reply-to: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=bY+sOVWOMNcH5jIjpfhheng/LErx1HZkY+eTjKO6zng=; b=KqmonMy/LyROJeSmqw76hAmPoEphkhZIUD245meq59J6IqoDTUf8zzR87WAbn5ts6UWI7T jdgDjKL7pPjJdvCg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: peterx@redhat.com, armbru@redhat.com Subject: [PATCH 5/5] migration/options: Use QAPI_MERGE in migrate_params_test_apply Date: Wed, 14 Jan 2026 10:23:09 -0300 Message-ID: <20260114132309.5832-6-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114132309.5832-1-farosas@suse.de> References: <20260114132309.5832-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] 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 (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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development 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 @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1768397047468158500 Content-Type: text/plain; charset="utf-8" Convert the code in migrate_params_test_apply() from an open-coded copy of every migration parameter to a copy using visitors. The current code has conditionals for each parameter's has_* field, which is exactly what the visitors do. This hides the details of QAPI from the migration code and avoids the need to update migrate_params_test_apply() every time a new migration parameter is added. Both were very confusing and while the visitor code can become a bit involved, there is no need for new contributors to ever touch it. Move the QAPI_CLONE_MEMBERS into the caller, so QAPI_CLONE can be used and there's no need to allocate memory in the migration code. Similarly, turn 'tmp' into a pointer so the proper qapi_free_ routine can be used. An extra call to migrate_mark_all_params_present() is now needed because the visitors update the has_ field for non-present fields, but we actually want them all set so migrate_params_apply() can copy all of them. Reviewed-by: Peter Xu Signed-off-by: Fabiano Rosas --- migration/options.c | 138 +++----------------------------------------- 1 file changed, 9 insertions(+), 129 deletions(-) diff --git a/migration/options.c b/migration/options.c index 7a16119ff8..b4773fecc5 100644 --- a/migration/options.c +++ b/migration/options.c @@ -20,6 +20,7 @@ #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-visit-migration.h" #include "qapi/qmp/qerror.h" +#include "qapi/type-helpers.h" #include "qobject/qnull.h" #include "system/runstate.h" #include "migration/colo.h" @@ -1262,129 +1263,6 @@ bool migrate_params_check(MigrationParameters *para= ms, Error **errp) return true; } =20 -static void migrate_params_test_apply(MigrationParameters *params, - MigrationParameters *dest) -{ - MigrationState *s =3D migrate_get_current(); - - QAPI_CLONE_MEMBERS(MigrationParameters, dest, &s->parameters); - - 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) { - qapi_free_StrOrNull(dest->tls_creds); - dest->tls_creds =3D QAPI_CLONE(StrOrNull, params->tls_creds); - } - - if (params->tls_hostname) { - qapi_free_StrOrNull(dest->tls_hostname); - dest->tls_hostname =3D QAPI_CLONE(StrOrNull, params->tls_hostname); - } - - if (params->tls_authz) { - qapi_free_StrOrNull(dest->tls_authz); - dest->tls_authz =3D QAPI_CLONE(StrOrNull, params->tls_authz); - } - - if (params->has_max_bandwidth) { - dest->max_bandwidth =3D params->max_bandwidth; - } - - if (params->has_avail_switchover_bandwidth) { - dest->avail_switchover_bandwidth =3D params->avail_switchover_band= width; - } - - 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_multifd_channels) { - dest->multifd_channels =3D params->multifd_channels; - } - if (params->has_multifd_compression) { - dest->multifd_compression =3D params->multifd_compression; - } - if (params->has_multifd_qatzip_level) { - dest->multifd_qatzip_level =3D params->multifd_qatzip_level; - } - if (params->has_multifd_zlib_level) { - dest->multifd_zlib_level =3D params->multifd_zlib_level; - } - if (params->has_multifd_zstd_level) { - dest->multifd_zstd_level =3D params->multifd_zstd_level; - } - 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) { - qapi_free_BitmapMigrationNodeAliasList(dest->block_bitmap_mapping); - dest->block_bitmap_mapping =3D QAPI_CLONE(BitmapMigrationNodeAlias= List, - params->block_bitmap_mappi= ng); - } - - 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; - } - - if (params->has_mode) { - dest->mode =3D params->mode; - } - - if (params->has_zero_page_detection) { - dest->zero_page_detection =3D params->zero_page_detection; - } - - if (params->has_direct_io) { - dest->direct_io =3D params->direct_io; - } - - if (params->has_cpr_exec_command) { - qapi_free_strList(dest->cpr_exec_command); - dest->cpr_exec_command =3D QAPI_CLONE(strList, params->cpr_exec_co= mmand); - } -} - /* * Caller must ensure all has_* fields of @params are true to ensure * all fields get copied and the pointer members don't dangle. @@ -1404,7 +1282,9 @@ static void migrate_params_apply(MigrationParameters = *params) =20 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) { - MigrationParameters tmp; + MigrationState *s =3D migrate_get_current(); + g_autoptr(MigrationParameters) tmp =3D QAPI_CLONE(MigrationParameters, + &s->parameters); =20 /* * Convert QTYPE_QNULL and NULL to the empty string (""). Even @@ -1418,9 +1298,9 @@ void qmp_migrate_set_parameters(MigrationParameters *= params, Error **errp) tls_opt_to_str(params->tls_hostname); tls_opt_to_str(params->tls_authz); =20 - migrate_params_test_apply(params, &tmp); + QAPI_MERGE(MigrationParameters, tmp, params); =20 - if (migrate_params_check(&tmp, errp)) { + if (migrate_params_check(tmp, errp)) { /* * Mark block_bitmap_mapping as present now while we have the * params structure with the user input around. @@ -1429,9 +1309,9 @@ void qmp_migrate_set_parameters(MigrationParameters *= params, Error **errp) migrate_get_current()->has_block_bitmap_mapping =3D true; } =20 - migrate_params_apply(&tmp); + /* mark all present, so they're all copied */ + migrate_mark_all_params_present(tmp); + migrate_params_apply(tmp); migrate_post_update_params(params, errp); } - - migrate_tls_opts_free(&tmp); } --=20 2.51.0