From nobody Thu Jan 8 13:18:32 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=1766784080; cv=none; d=zohomail.com; s=zohoarc; b=CrEi8i6d1K+ZhmoIx1C3zG1CmLEJLl5+qMSZNL64qWM7D3z4PGuo1/sTOc63MRg6r+8cqct0bAzF5yB3ZpCGcdac+yULx9q6y6w5D+z7H3HOZ+tTz5aCVO4TBh3H/wyC5DrKwYddw31B1x4JrDS9uGR9x79m9t3bGK4nob+KHHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766784080; 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=7EjOJVRn+KNW3Hro0z0DceSzxWOMd1iQUeK8vxjomCk=; b=Q5p0olNIceiOySNGLba1tW85ctK+ZBS8cvkv8bzTPBvMtU+FW2yhMVt2mSNpBxsU3dqWc9vhJ6huGhla394Q9A7gTpzebwcWssM1Vr/GhrbWLI7J9xW6Oed4SqjwpnLwuNSCtJ2sP0E8GgoCrgFH1YH4NJ/hJLqLisqlSy6UGow= 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 1766784080831557.3508559199042; Fri, 26 Dec 2025 13:21:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vZFEJ-0001Qh-0x; Fri, 26 Dec 2025 16:20:11 -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 1vZFEH-0001QE-Ff for qemu-devel@nongnu.org; Fri, 26 Dec 2025 16:20:09 -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 1vZFEF-00042s-5W for qemu-devel@nongnu.org; Fri, 26 Dec 2025 16:20:09 -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 2725D336A8; Fri, 26 Dec 2025 21:19:57 +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 CF65E3EA63; Fri, 26 Dec 2025 21:19:55 +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 ANiBI/v7TmnwJwAAD6G6ig (envelope-from ); Fri, 26 Dec 2025 21:19:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1766783997; 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=7EjOJVRn+KNW3Hro0z0DceSzxWOMd1iQUeK8vxjomCk=; b=w25SP+2nOZyMHsKD47XbFNPraeNf8guPbC8u125Yc/xQWsOs2/VmCRSpoPwDBYEBPTnNoc DMuBq29KHhj2cm15h9esmM6S2fEoUEu0hKvUdXkTrMFuNImpCFMUdZdUweP0J23iKy+oxr Hr3Ogt06fk/RxedhzuGAwnIHUb/1QVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1766783997; 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=7EjOJVRn+KNW3Hro0z0DceSzxWOMd1iQUeK8vxjomCk=; b=OD1xqjTLDhIUALKyciGW2L2sJ1zauzUtn10NQVlZ+GH4JgTjWIDkvWUNYXlAFP6ThcwtpR 882T+Br4lvqrEsDA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1766783997; 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=7EjOJVRn+KNW3Hro0z0DceSzxWOMd1iQUeK8vxjomCk=; b=w25SP+2nOZyMHsKD47XbFNPraeNf8guPbC8u125Yc/xQWsOs2/VmCRSpoPwDBYEBPTnNoc DMuBq29KHhj2cm15h9esmM6S2fEoUEu0hKvUdXkTrMFuNImpCFMUdZdUweP0J23iKy+oxr Hr3Ogt06fk/RxedhzuGAwnIHUb/1QVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1766783997; 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=7EjOJVRn+KNW3Hro0z0DceSzxWOMd1iQUeK8vxjomCk=; b=OD1xqjTLDhIUALKyciGW2L2sJ1zauzUtn10NQVlZ+GH4JgTjWIDkvWUNYXlAFP6ThcwtpR 882T+Br4lvqrEsDA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Li Zhijian Subject: [RFC PATCH 14/25] migration: Remove QEMUFile from channel.c Date: Fri, 26 Dec 2025 18:19:16 -0300 Message-ID: <20251226211930.27565-15-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251226211930.27565-1-farosas@suse.de> References: <20251226211930.27565-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)[-0.988]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_THREE(0.00)[3]; RCVD_TLS_ALL(0.00)[] 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1766784082623158500 Content-Type: text/plain; charset="utf-8" Make channel.c deal only with QIOChannel objects. Move any handling of QEMUFile into migration.c. To achieve this in a clean way: 1) Define a migration_outgoing_setup, analogous to migration_incoming_setup, responsible for creating the QEMUFile from the QIOChannel. 2) Increase the scope of migration_incoming_setup to create not only the main channel, but all the others as well. That is currently being done at migration_ioc_process, so move the code. 3) Adjust RDMA code to pass in the QIOChannel and remove some of the usage of QEMUFile. Signed-off-by: Fabiano Rosas --- migration/channel.c | 21 ++++++----- migration/migration.c | 88 ++++++++++++++++++++++--------------------- migration/migration.h | 6 ++- migration/multifd.c | 7 ++-- migration/multifd.h | 2 +- migration/rdma.c | 28 ++++---------- 6 files changed, 73 insertions(+), 79 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index 7243b99108..af6c2cc76e 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -14,7 +14,6 @@ #include "channel.h" #include "tls.h" #include "migration.h" -#include "qemu-file.h" #include "trace.h" #include "qapi/error.h" #include "io/channel-tls.h" @@ -34,6 +33,7 @@ void migration_channel_process_incoming(QIOChannel *ioc) { MigrationIncomingState *mis =3D migration_incoming_get_current(); Error *local_err =3D NULL; + uint8_t ch; =20 trace_migration_set_incoming_channel( ioc, object_get_typename(OBJECT(ioc))); @@ -42,9 +42,16 @@ void migration_channel_process_incoming(QIOChannel *ioc) migration_tls_channel_process_incoming(ioc, &local_err); } else { migration_ioc_register_yank(ioc); - migration_ioc_process_incoming(ioc, &local_err); - } + ch =3D migration_ioc_process_incoming(ioc, &local_err); + if (!ch) { + goto out; + } =20 + if (migration_incoming_setup(ioc, ch, &local_err)) { + migration_incoming_process(); + } + } +out: if (local_err) { error_report_err(local_err); migrate_set_state(&mis->state, mis->state, MIGRATION_STATUS_FAILED= ); @@ -75,14 +82,8 @@ void migration_channel_connect(MigrationState *s, QIOCha= nnel *ioc) return; } =20 - QEMUFile *f =3D qemu_file_new_output(ioc); - migration_ioc_register_yank(ioc); - - qemu_mutex_lock(&s->qemu_file_lock); - s->to_dst_file =3D f; - qemu_mutex_unlock(&s->qemu_file_lock); - + migration_outgoing_setup(ioc); migration_connect(s); } =20 diff --git a/migration/migration.c b/migration/migration.c index 5c6c76f110..677581b5a5 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -92,7 +92,7 @@ enum mig_rp_message_type { }; =20 /* Migration channel types */ -enum { CH_MAIN, CH_MULTIFD, CH_POSTCOPY }; +enum { CH_NONE, CH_MAIN, CH_MULTIFD, CH_POSTCOPY }; =20 /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add @@ -934,17 +934,48 @@ out: migrate_incoming_unref_outgoing_state(); } =20 -/** - * migration_incoming_setup: Setup incoming migration - * @f: file for main migration channel - */ -static void migration_incoming_setup(QEMUFile *f) +static bool migration_has_main_and_multifd_channels(void); + +bool migration_incoming_setup(QIOChannel *ioc, uint8_t channel, Error **er= rp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); + QEMUFile *f; =20 - assert(!mis->from_src_file); - mis->from_src_file =3D f; - qemu_file_set_blocking(f, false, &error_abort); + switch (channel) { + case CH_MAIN: + f =3D qemu_file_new_input(ioc); + assert(!mis->from_src_file); + mis->from_src_file =3D f; + qemu_file_set_blocking(f, false, &error_abort); + break; + + case CH_MULTIFD: + if (!multifd_recv_new_channel(ioc, errp)) { + return false; + } + break; + + case CH_POSTCOPY: + assert(!mis->postcopy_qemufile_dst); + f =3D qemu_file_new_input(ioc); + postcopy_preempt_new_channel(mis, f); + return false; + + default: + g_assert_not_reached(); + } + + return migration_has_main_and_multifd_channels(); +} + +void migration_outgoing_setup(QIOChannel *ioc) +{ + MigrationState *s =3D migrate_get_current(); + QEMUFile *f =3D qemu_file_new_output(ioc); + + qemu_mutex_lock(&s->qemu_file_lock); + s->to_dst_file =3D f; + qemu_mutex_unlock(&s->qemu_file_lock); } =20 /* Returns true if recovered from a paused migration, otherwise false */ @@ -990,12 +1021,6 @@ void migration_incoming_process(void) qemu_coroutine_enter(co); } =20 -void migration_fd_process_incoming(QEMUFile *f) -{ - migration_incoming_setup(f); - migration_incoming_process(); -} - static bool migration_has_main_and_multifd_channels(void) { MigrationIncomingState *mis =3D migration_incoming_get_current(); @@ -1012,12 +1037,10 @@ static bool migration_has_main_and_multifd_channels= (void) return true; } =20 -void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) +uint8_t migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); - Error *local_err =3D NULL; - QEMUFile *f; - uint8_t channel; + uint8_t channel =3D CH_NONE; uint32_t channel_magic =3D 0; int ret =3D 0; =20 @@ -1036,7 +1059,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) ret =3D migration_channel_read_peek(ioc, (void *)&channel_magi= c, sizeof(channel_magic), errp); if (ret !=3D 0) { - return; + goto out; } =20 channel_magic =3D be32_to_cpu(channel_magic); @@ -1051,7 +1074,6 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) channel =3D CH_MAIN; } else { error_setg(errp, "unknown channel magic: %u", channel_magi= c); - return; } } else if (mis->from_src_file && migrate_multifd()) { /* @@ -1063,33 +1085,13 @@ void migration_ioc_process_incoming(QIOChannel *ioc= , Error **errp) channel =3D CH_MAIN; } else { error_setg(errp, "non-peekable channel used without multifd"); - return; } } else { assert(migrate_postcopy_preempt()); channel =3D CH_POSTCOPY; } - - if (channel =3D=3D CH_MAIN) { - f =3D qemu_file_new_input(ioc); - migration_incoming_setup(f); - } else if (channel =3D=3D CH_MULTIFD) { - /* Multiple connections */ - multifd_recv_new_channel(ioc, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - } else if (channel =3D=3D CH_POSTCOPY) { - assert(!mis->postcopy_qemufile_dst); - f =3D qemu_file_new_input(ioc); - postcopy_preempt_new_channel(mis, f); - return; - } - - if (migration_has_main_and_multifd_channels()) { - migration_incoming_process(); - } +out: + return channel; } =20 /** diff --git a/migration/migration.h b/migration/migration.h index f340cd518d..d2b82cf54f 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -526,8 +526,10 @@ struct MigrationState { void migrate_set_state(MigrationStatus *state, MigrationStatus old_state, MigrationStatus new_state); =20 -void migration_fd_process_incoming(QEMUFile *f); -void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp); +void migration_outgoing_setup(QIOChannel *ioc); +bool migration_incoming_setup(QIOChannel *ioc, uint8_t channel, Error **er= rp); + +uint8_t migration_ioc_process_incoming(QIOChannel *ioc, Error **errp); void migration_incoming_process(void); =20 bool migration_has_all_channels(void); diff --git a/migration/multifd.c b/migration/multifd.c index 3fb1a07ba9..c6639dbab5 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1521,7 +1521,7 @@ bool multifd_recv_all_channels_created(void) * Try to receive all multifd channels to get ready for the migration. * Sets @errp when failing to receive the current channel. */ -void multifd_recv_new_channel(QIOChannel *ioc, Error **errp) +bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) { MultiFDRecvParams *p; Error *local_err =3D NULL; @@ -1536,7 +1536,7 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) "failed to receive packet" " via multifd channel %d: ", qatomic_read(&multifd_recv_state->coun= t)); - return; + return false; } trace_multifd_recv_new_channel(id); } else { @@ -1549,7 +1549,7 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) id); multifd_recv_terminate_threads(error_copy(local_err)); error_propagate(errp, local_err); - return; + return false; } p->c =3D ioc; object_ref(OBJECT(ioc)); @@ -1558,4 +1558,5 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); qatomic_inc(&multifd_recv_state->count); + return true; } diff --git a/migration/multifd.h b/migration/multifd.h index 9b6d81e7ed..89a395aef2 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -42,7 +42,7 @@ int multifd_recv_setup(Error **errp); void multifd_recv_cleanup(void); void multifd_recv_shutdown(void); bool multifd_recv_all_channels_created(void); -void multifd_recv_new_channel(QIOChannel *ioc, Error **errp); +bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp); void multifd_recv_sync_main(void); int multifd_send_sync_main(MultiFDSyncReq req); bool multifd_queue_page(RAMBlock *block, ram_addr_t offset); diff --git a/migration/rdma.c b/migration/rdma.c index 596a1aba0b..7bee871e2b 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -384,7 +384,6 @@ struct QIOChannelRDMA { QIOChannel parent; RDMAContext *rdmain; RDMAContext *rdmaout; - QEMUFile *file; bool blocking; /* XXX we don't actually honour this yet */ }; =20 @@ -3836,32 +3835,20 @@ static void qio_channel_rdma_register_types(void) =20 type_init(qio_channel_rdma_register_types); =20 -static QEMUFile *rdma_new_input(RDMAContext *rdma) +static QIOChannel *rdma_new_ioc(RDMAContext *rdma) { QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(object_new(TYPE_QIO_CHANNEL_= RDMA)); =20 - rioc->file =3D qemu_file_new_input(QIO_CHANNEL(rioc)); - rioc->rdmain =3D rdma; - rioc->rdmaout =3D rdma->return_path; - - return rioc->file; -} - -static QEMUFile *rdma_new_output(RDMAContext *rdma) -{ - QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(object_new(TYPE_QIO_CHANNEL_= RDMA)); - - rioc->file =3D qemu_file_new_output(QIO_CHANNEL(rioc)); rioc->rdmaout =3D rdma; rioc->rdmain =3D rdma->return_path; =20 - return rioc->file; + return QIO_CHANNEL(rioc); } =20 static void rdma_accept_incoming_migration(void *opaque) { RDMAContext *rdma =3D opaque; - QEMUFile *f; + QIOChannel *ioc; =20 trace_qemu_rdma_accept_incoming_migration(); if (qemu_rdma_accept(rdma) < 0) { @@ -3875,15 +3862,16 @@ static void rdma_accept_incoming_migration(void *op= aque) return; } =20 - f =3D rdma_new_input(rdma); - if (f =3D=3D NULL) { + ioc =3D rdma_new_ioc(rdma); + if (!ioc) { error_report("RDMA ERROR: could not open RDMA for input"); qemu_rdma_cleanup(rdma); return; } =20 rdma->migration_started_on_destination =3D 1; - migration_fd_process_incoming(f); + migration_incoming_setup(ioc, 0, NULL); + migration_incoming_process(); } =20 void rdma_start_incoming_migration(InetSocketAddress *host_port, @@ -3995,8 +3983,8 @@ void rdma_start_outgoing_migration(void *opaque, =20 trace_rdma_start_outgoing_migration_after_rdma_connect(); =20 - s->to_dst_file =3D rdma_new_output(rdma); s->rdma_migration =3D true; + migration_outgoing_setup(rdma_new_ioc(rdma)); migration_connect(s); return; return_path_err: --=20 2.51.0