[{"id":3629526,"web_url":"http://patchwork.ozlabs.org/comment/3629526/","msgid":"<aVLfYlEwDu3rL3wj@x1.local>","list_archive_url":null,"date":"2025-12-29T20:06:58","subject":"Re: [RFC PATCH 22/25] migration/channel: Merge both sides of the\n connection initiation code","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/people/67717/","name":"Peter Xu","email":"peterx@redhat.com"},"content":"On Fri, Dec 26, 2025 at 06:19:24PM -0300, Fabiano Rosas wrote:\n> Now that everything is in channel.c, it's easier to browse this code\n> if it's all in the same place. It's also easier to grasp what the\n> connection flow is if both sides of the connection are close together.\n> \n> Signed-off-by: Fabiano Rosas <farosas@suse.de>\n> ---\n>  migration/channel.c | 86 +++++++++++++++++++++++----------------------\n>  migration/channel.h | 14 ++++++--\n>  2 files changed, 56 insertions(+), 44 deletions(-)\n> \n> diff --git a/migration/channel.c b/migration/channel.c\n> index 042e01b224..ba9aa1c58b 100644\n> --- a/migration/channel.c\n> +++ b/migration/channel.c\n> @@ -31,10 +31,11 @@\n>  #include \"trace.h\"\n>  #include \"yank_functions.h\"\n>  \n> -bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n> +bool migration_connect(MigrationAddress *addr, bool out, Error **errp)\n>  {\n>      g_autoptr(QIOChannel) ioc = NULL;\n>      SocketAddress *saddr;\n> +    ERRP_GUARD();\n>  \n>      switch (addr->transport) {\n>      case MIGRATION_ADDRESS_TYPE_SOCKET:\n> @@ -44,15 +45,24 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n>          case SOCKET_ADDRESS_TYPE_INET:\n>          case SOCKET_ADDRESS_TYPE_UNIX:\n>          case SOCKET_ADDRESS_TYPE_VSOCK:\n> -            socket_connect_outgoing(saddr, errp);\n> -            /*\n> -             * async: after the socket is connected, calls\n> -             * migration_channel_connect_outgoing() directly.\n> -             */\n> -            return true;\n> +            if (out) {\n\nPersonally I wouldn't suggest we merge the outgoing / incoming with\nmigration_connect() then split paths once more in this exact function.\n\nI got this conclusion when I started to count how many \"if (out)\" are\nthere..  When there're too much, it may imply we need to think more..\n\nThis also answers part of my confusion when reading the previous patch - if\nthat was only paving way for this one, IMHO it may not be as worthwhile,\nand I would tend to avoid both.\n\nThoughts?\n\n> +                socket_connect_outgoing(saddr, errp);\n> +                /*\n> +                 * async: after the socket is connected, calls\n> +                 * migration_channel_connect_outgoing() directly.\n> +                 */\n> +                return true;\n> +            } else {\n> +                socket_connect_incoming(saddr, errp);\n> +            }\n> +\n>              break;\n>          case SOCKET_ADDRESS_TYPE_FD:\n> -            ioc = fd_connect_outgoing(saddr->u.fd.str, errp);\n> +            if (out) {\n> +                ioc = fd_connect_outgoing(saddr->u.fd.str, errp);\n> +            } else {\n> +                fd_connect_incoming(saddr->u.fd.str, errp);\n> +            }\n>              break;\n>          default:\n>              g_assert_not_reached();\n> @@ -62,16 +72,28 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n>  \n>  #ifdef CONFIG_RDMA\n>      case MIGRATION_ADDRESS_TYPE_RDMA:\n> -        ioc = rdma_connect_outgoing(&addr->u.rdma, errp);\n> +        if (out) {\n> +            ioc = rdma_connect_outgoing(&addr->u.rdma, errp);\n> +        } else {\n> +            rdma_connect_incoming(&addr->u.rdma, errp);\n> +        }\n>          break;\n>  #endif\n>  \n>      case MIGRATION_ADDRESS_TYPE_EXEC:\n> -        ioc = exec_connect_outgoing(addr->u.exec.args, errp);\n> +        if (out) {\n> +            ioc = exec_connect_outgoing(addr->u.exec.args, errp);\n> +        } else {\n> +            exec_connect_incoming(addr->u.exec.args, errp);\n> +        }\n>          break;\n>  \n>      case MIGRATION_ADDRESS_TYPE_FILE:\n> -        ioc = file_connect_outgoing(&addr->u.file, errp);\n> +        if (out) {\n> +            ioc = file_connect_outgoing(&addr->u.file, errp);\n> +        } else {\n> +            file_connect_incoming(&addr->u.file, errp);\n> +        }\n>          break;\n>  \n>      default:\n> @@ -79,42 +101,22 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n>          break;\n>      }\n>  \n> -    if (!ioc) {\n> -        return false;\n> -    }\n> -\n> -    migration_channel_connect_outgoing(ioc);\n> -    return true;\n> -}\n> -\n> -void migration_connect_incoming(MigrationAddress *addr, Error **errp)\n> -{\n> -    if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {\n> -        SocketAddress *saddr = &addr->u.socket;\n> -        if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||\n> -            saddr->type == SOCKET_ADDRESS_TYPE_UNIX ||\n> -            saddr->type == SOCKET_ADDRESS_TYPE_VSOCK) {\n> -            socket_connect_incoming(saddr, errp);\n> -        } else if (saddr->type == SOCKET_ADDRESS_TYPE_FD) {\n> -            fd_connect_incoming(saddr->u.fd.str, errp);\n> +    if (out) {\n> +        if (!ioc) {\n> +            return false;\n>          }\n> -#ifdef CONFIG_RDMA\n> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_RDMA) {\n> -        rdma_connect_incoming(&addr->u.rdma, errp);\n> -#endif\n> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_EXEC) {\n> -        exec_connect_incoming(addr->u.exec.args, errp);\n> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_FILE) {\n> -        file_connect_incoming(&addr->u.file, errp);\n> -    } else {\n> -        error_setg(errp, \"unknown migration protocol\");\n> +\n> +        migration_channel_connect_outgoing(ioc);\n> +        return true;\n>      }\n>  \n>      /*\n> -     * async: the above routines all wait for the incoming connection\n> -     * and call back to migration_channel_process_incoming() to start\n> -     * the migration.\n> +     * async: on the incoming side all of the transport routines above\n> +     * wait for the incoming connection and call back to\n> +     * migration_channel_process_incoming() to start the migration.\n>       */\n> +\n> +    return !*errp;\n>  }\n>  \n>  bool migration_has_main_and_multifd_channels(void)\n> diff --git a/migration/channel.h b/migration/channel.h\n> index 8cf16bfda9..86934fee38 100644\n> --- a/migration/channel.h\n> +++ b/migration/channel.h\n> @@ -39,6 +39,16 @@ int migration_channel_read_peek(QIOChannel *ioc,\n>  bool migration_has_main_and_multifd_channels(void);\n>  bool migration_has_all_channels(void);\n>  \n> -bool migration_connect_outgoing(MigrationAddress *addr, Error **errp);\n> -void migration_connect_incoming(MigrationAddress *addr, Error **errp);\n> +bool migration_connect(MigrationAddress *addr, bool out, Error **errp);\n> +static inline bool migration_connect_outgoing(MigrationAddress *addr,\n> +                                              Error **errp)\n> +{\n> +    return migration_connect(addr, true, errp);\n> +}\n> +\n> +static inline bool migration_connect_incoming(MigrationAddress *addr,\n> +                                              Error **errp)\n> +{\n> +    return migration_connect(addr, false, errp);\n> +}\n>  #endif\n> -- \n> 2.51.0\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=YI5f9B4A;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=RDkyuQ4E;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dg6hl3pQbz1xqZ\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 30 Dec 2025 07:07:50 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vaJWM-0006X2-Vm; Mon, 29 Dec 2025 15:07:15 -0500","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1vaJWL-0006WJ-34\n for qemu-devel@nongnu.org; Mon, 29 Dec 2025 15:07:13 -0500","from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1vaJWD-0005Vz-AN\n for qemu-devel@nongnu.org; Mon, 29 Dec 2025 15:07:12 -0500","from mail-qt1-f197.google.com (mail-qt1-f197.google.com\n [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-161-hUL8nUZKM4mkBOVrYdO-Sg-1; Mon, 29 Dec 2025 15:07:01 -0500","by mail-qt1-f197.google.com with SMTP id\n d75a77b69052e-4ee1b7293e7so350610771cf.0\n for <qemu-devel@nongnu.org>; Mon, 29 Dec 2025 12:07:01 -0800 (PST)","from x1.local ([142.188.210.156]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-88d973a7f17sm231205506d6.22.2025.12.29.12.06.59\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 29 Dec 2025 12:06:59 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1767038823;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=VjWFcz2K4hTWWfN6iCFtTpnqV/f47YvrCvXLgeHCg8E=;\n b=YI5f9B4Aqal6j60n82GMxPw5wRJkLck8L4gD9kg1iERp2R0kT3QtkVmhv+tZ9ROjz1mXLL\n 1URi3pdhmHarUScAQ1JBX+yekp02fl2rYgipXVIGkIxZNdOpic64XJyIdaWyCmq15ROeE4\n 2I+WjsTD9LMqm9ewKTUR0nNGSU3Lw7I=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1767038820; x=1767643620; darn=nongnu.org;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;\n bh=VjWFcz2K4hTWWfN6iCFtTpnqV/f47YvrCvXLgeHCg8E=;\n b=RDkyuQ4EALyEbxhka4nvj93Mye4dgg3Hlmc2k2b+Lkg+LHJzCyOcB230KgzXVIKjuc\n 00FWRlOKlK/Hzp60yOGgGtNw+tKC4m9vg8Pu65/gYySupVbZct9K/zLTUw1Mji4XhbOn\n RrEPLVtBs3xISRHaM+IPJA+BXAd8hzlR+Uv/8odovmH0Ssy9YMvfa8XdU4umaCRjsLIz\n PyIF5/AWbeqSFoUkuwb1Kmw1BXaewHWMJSLDJp11qePHuIU7wNdemUNJpNJHKlBWnFbE\n VuJpBBXMKj55OIpoQf4erxj7EgIQG3xAtZM7K2gDysg4ewmkxInt8RQclGQJcCwUgZBJ\n MfdQ=="],"X-MC-Unique":"hUL8nUZKM4mkBOVrYdO-Sg-1","X-Mimecast-MFC-AGG-ID":"hUL8nUZKM4mkBOVrYdO-Sg_1767038820","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1767038820; x=1767643620;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=VjWFcz2K4hTWWfN6iCFtTpnqV/f47YvrCvXLgeHCg8E=;\n b=s3hrceFSUqFssODa/Jy1vdzSI3XcZn+ltlCWoE/oh4Cq63e4Tukky8uvD1QWgwJ+Tc\n OyW3g1oZbt5HYWZ81UlhMQPXzu3sXf3//3uUaOpMGaFF9RXsR81eoeDicx3YDl13JsYf\n 5WQWn+tqX1uiSgEhM5tr4iXcoE+oa+f7CPNFmlIKYNMl/91goEjHgKGnqhMViFYVbumb\n SvctqDgLSb1tKSnbUmg1LDF0UOLpnwLGil4oRLKVd2H4g/kKuTgs1U92OIf8cSbpPPle\n WPpXWXKxv9+2X/tHgcp5Z9l8jZA/y5tzHnuFTRogz7hZHs/2XicC6lGEo68MdcstUSar\n Sw6Q==","X-Gm-Message-State":"AOJu0Yzb3ucrwV4ttTadKqVy9mEpTQL7AzfrCH+iwt8Uze1V8279mHbG\n 0/YO7lIHkyqdTKSvGkG9fmjVT32Qsab9gwfNTClLqWn9fVtAijnS4FliLUNB/93th9LsYisYD1z\n BzOf7TO3vNOTT/tcm5+7RoMmUmVARv/nLq8M3RKJ0kxSbc/tI46cO+r/I","X-Gm-Gg":"AY/fxX5cg7oH0HOYUXR9+Xycyohw4GqRMueGtgHC8UIN02z2g8Is24hkpZL+w8r4kg+\n Ik2epQiRfv89Z6ncNO0am/rwlSbGfDQ1lV5Sahr4GuZzcgDoiJ2+arZIKolqLzDPUelVbMSFYdm\n 6J3ph7dL6yqvhQo5nBtFD0OxnhloMHQhlSZ0ffDyLrqqt2I6bTIElSKxa60G5QLCM1NEPOBzAUS\n jw5DWm6wwoP5rjiVDjiDBkNEtkHQBcFAdfi/EYoFettpINO/wF0fESKRNCkBOdXtR8mOipeOWl2\n dZtmWGgVb1JIjtm8zG5shSKM07bezS9JhAi0F60fjWf4sDzNKVTXjEm7h4xT9iB9sUn7vgfmqod\n XnKc=","X-Received":["by 2002:a05:622a:4813:b0:4f0:23b6:c285 with SMTP id\n d75a77b69052e-4f4abd80b13mr447928461cf.41.1767038820424;\n Mon, 29 Dec 2025 12:07:00 -0800 (PST)","by 2002:a05:622a:4813:b0:4f0:23b6:c285 with SMTP id\n d75a77b69052e-4f4abd80b13mr447927981cf.41.1767038819883;\n Mon, 29 Dec 2025 12:06:59 -0800 (PST)"],"X-Google-Smtp-Source":"\n AGHT+IFaHZzMkqlxMmgJt8f0XNHz6eeDEBFYrZmzZsLnl8PAYV/R0ZsV6RomoXEzVAVEy2A48ApJAA==","Date":"Mon, 29 Dec 2025 15:06:58 -0500","From":"Peter Xu <peterx@redhat.com>","To":"Fabiano Rosas <farosas@suse.de>","Cc":"qemu-devel@nongnu.org","Subject":"Re: [RFC PATCH 22/25] migration/channel: Merge both sides of the\n connection initiation code","Message-ID":"<aVLfYlEwDu3rL3wj@x1.local>","References":"<20251226211930.27565-1-farosas@suse.de>\n <20251226211930.27565-23-farosas@suse.de>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20251226211930.27565-23-farosas@suse.de>","Received-SPF":"pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com;\n 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,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-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-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}},{"id":3629535,"web_url":"http://patchwork.ozlabs.org/comment/3629535/","msgid":"<875x9p7zxv.fsf@suse.de>","list_archive_url":null,"date":"2025-12-29T21:14:52","subject":"Re: [RFC PATCH 22/25] migration/channel: Merge both sides of the\n connection initiation code","submitter":{"id":85343,"url":"http://patchwork.ozlabs.org/api/people/85343/","name":"Fabiano Rosas","email":"farosas@suse.de"},"content":"Peter Xu <peterx@redhat.com> writes:\n\n> On Fri, Dec 26, 2025 at 06:19:24PM -0300, Fabiano Rosas wrote:\n>> Now that everything is in channel.c, it's easier to browse this code\n>> if it's all in the same place. It's also easier to grasp what the\n>> connection flow is if both sides of the connection are close together.\n>> \n>> Signed-off-by: Fabiano Rosas <farosas@suse.de>\n>> ---\n>>  migration/channel.c | 86 +++++++++++++++++++++++----------------------\n>>  migration/channel.h | 14 ++++++--\n>>  2 files changed, 56 insertions(+), 44 deletions(-)\n>> \n>> diff --git a/migration/channel.c b/migration/channel.c\n>> index 042e01b224..ba9aa1c58b 100644\n>> --- a/migration/channel.c\n>> +++ b/migration/channel.c\n>> @@ -31,10 +31,11 @@\n>>  #include \"trace.h\"\n>>  #include \"yank_functions.h\"\n>>  \n>> -bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n>> +bool migration_connect(MigrationAddress *addr, bool out, Error **errp)\n>>  {\n>>      g_autoptr(QIOChannel) ioc = NULL;\n>>      SocketAddress *saddr;\n>> +    ERRP_GUARD();\n>>  \n>>      switch (addr->transport) {\n>>      case MIGRATION_ADDRESS_TYPE_SOCKET:\n>> @@ -44,15 +45,24 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n>>          case SOCKET_ADDRESS_TYPE_INET:\n>>          case SOCKET_ADDRESS_TYPE_UNIX:\n>>          case SOCKET_ADDRESS_TYPE_VSOCK:\n>> -            socket_connect_outgoing(saddr, errp);\n>> -            /*\n>> -             * async: after the socket is connected, calls\n>> -             * migration_channel_connect_outgoing() directly.\n>> -             */\n>> -            return true;\n>> +            if (out) {\n>\n> Personally I wouldn't suggest we merge the outgoing / incoming with\n> migration_connect() then split paths once more in this exact function.\n>\n> I got this conclusion when I started to count how many \"if (out)\" are\n> there..  When there're too much, it may imply we need to think more..\n>\n\nWell, compared to before, there 50% less \"if (addr->transport == ...)\",\nthis is top level programming! =D\n\nThis part of the series is highly subjective, if there's a patch you\ndon't like it we can drop it, let's not dwell on it.. Just read my words\nbelow on the previous patch, which I think you may be mistaken about.\n\n> This also answers part of my confusion when reading the previous patch - if\n> that was only paving way for this one, IMHO it may not be as worthwhile,\n> and I would tend to avoid both.\n>\n\nPatch 21 is just a cleanup after patch 19 moves the call to\nmigration_channel_connect_outgoing from being inside the transport\nroutines to this top level here at migration_connect(), which moves the\nplaces where MigrationState is used as well. So it removes unused\npassing of MigrationState along with the SocketConnectionData.\n\n> Thoughts?\n>\n>> +                socket_connect_outgoing(saddr, errp);\n>> +                /*\n>> +                 * async: after the socket is connected, calls\n>> +                 * migration_channel_connect_outgoing() directly.\n>> +                 */\n>> +                return true;\n>> +            } else {\n>> +                socket_connect_incoming(saddr, errp);\n>> +            }\n>> +\n>>              break;\n>>          case SOCKET_ADDRESS_TYPE_FD:\n>> -            ioc = fd_connect_outgoing(saddr->u.fd.str, errp);\n>> +            if (out) {\n>> +                ioc = fd_connect_outgoing(saddr->u.fd.str, errp);\n>> +            } else {\n>> +                fd_connect_incoming(saddr->u.fd.str, errp);\n>> +            }\n>>              break;\n>>          default:\n>>              g_assert_not_reached();\n>> @@ -62,16 +72,28 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n>>  \n>>  #ifdef CONFIG_RDMA\n>>      case MIGRATION_ADDRESS_TYPE_RDMA:\n>> -        ioc = rdma_connect_outgoing(&addr->u.rdma, errp);\n>> +        if (out) {\n>> +            ioc = rdma_connect_outgoing(&addr->u.rdma, errp);\n>> +        } else {\n>> +            rdma_connect_incoming(&addr->u.rdma, errp);\n>> +        }\n>>          break;\n>>  #endif\n>>  \n>>      case MIGRATION_ADDRESS_TYPE_EXEC:\n>> -        ioc = exec_connect_outgoing(addr->u.exec.args, errp);\n>> +        if (out) {\n>> +            ioc = exec_connect_outgoing(addr->u.exec.args, errp);\n>> +        } else {\n>> +            exec_connect_incoming(addr->u.exec.args, errp);\n>> +        }\n>>          break;\n>>  \n>>      case MIGRATION_ADDRESS_TYPE_FILE:\n>> -        ioc = file_connect_outgoing(&addr->u.file, errp);\n>> +        if (out) {\n>> +            ioc = file_connect_outgoing(&addr->u.file, errp);\n>> +        } else {\n>> +            file_connect_incoming(&addr->u.file, errp);\n>> +        }\n>>          break;\n>>  \n>>      default:\n>> @@ -79,42 +101,22 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n>>          break;\n>>      }\n>>  \n>> -    if (!ioc) {\n>> -        return false;\n>> -    }\n>> -\n>> -    migration_channel_connect_outgoing(ioc);\n>> -    return true;\n>> -}\n>> -\n>> -void migration_connect_incoming(MigrationAddress *addr, Error **errp)\n>> -{\n>> -    if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {\n>> -        SocketAddress *saddr = &addr->u.socket;\n>> -        if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||\n>> -            saddr->type == SOCKET_ADDRESS_TYPE_UNIX ||\n>> -            saddr->type == SOCKET_ADDRESS_TYPE_VSOCK) {\n>> -            socket_connect_incoming(saddr, errp);\n>> -        } else if (saddr->type == SOCKET_ADDRESS_TYPE_FD) {\n>> -            fd_connect_incoming(saddr->u.fd.str, errp);\n>> +    if (out) {\n>> +        if (!ioc) {\n>> +            return false;\n>>          }\n>> -#ifdef CONFIG_RDMA\n>> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_RDMA) {\n>> -        rdma_connect_incoming(&addr->u.rdma, errp);\n>> -#endif\n>> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_EXEC) {\n>> -        exec_connect_incoming(addr->u.exec.args, errp);\n>> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_FILE) {\n>> -        file_connect_incoming(&addr->u.file, errp);\n>> -    } else {\n>> -        error_setg(errp, \"unknown migration protocol\");\n>> +\n>> +        migration_channel_connect_outgoing(ioc);\n>> +        return true;\n>>      }\n>>  \n>>      /*\n>> -     * async: the above routines all wait for the incoming connection\n>> -     * and call back to migration_channel_process_incoming() to start\n>> -     * the migration.\n>> +     * async: on the incoming side all of the transport routines above\n>> +     * wait for the incoming connection and call back to\n>> +     * migration_channel_process_incoming() to start the migration.\n>>       */\n>> +\n>> +    return !*errp;\n>>  }\n>>  \n>>  bool migration_has_main_and_multifd_channels(void)\n>> diff --git a/migration/channel.h b/migration/channel.h\n>> index 8cf16bfda9..86934fee38 100644\n>> --- a/migration/channel.h\n>> +++ b/migration/channel.h\n>> @@ -39,6 +39,16 @@ int migration_channel_read_peek(QIOChannel *ioc,\n>>  bool migration_has_main_and_multifd_channels(void);\n>>  bool migration_has_all_channels(void);\n>>  \n>> -bool migration_connect_outgoing(MigrationAddress *addr, Error **errp);\n>> -void migration_connect_incoming(MigrationAddress *addr, Error **errp);\n>> +bool migration_connect(MigrationAddress *addr, bool out, Error **errp);\n>> +static inline bool migration_connect_outgoing(MigrationAddress *addr,\n>> +                                              Error **errp)\n>> +{\n>> +    return migration_connect(addr, true, errp);\n>> +}\n>> +\n>> +static inline bool migration_connect_incoming(MigrationAddress *addr,\n>> +                                              Error **errp)\n>> +{\n>> +    return migration_connect(addr, false, errp);\n>> +}\n>>  #endif\n>> -- \n>> 2.51.0\n>>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256\n header.s=susede2_rsa header.b=RYNPsOdu;\n\tdkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=XC4yGGwF;\n\tdkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de\n header.a=rsa-sha256 header.s=susede2_rsa header.b=q6QP+dRA;\n\tdkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=ODi4GEoT;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)","smtp-out2.suse.de;\n dkim=pass header.d=suse.de header.s=susede2_rsa header.b=q6QP+dRA;\n dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ODi4GEoT"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dg8Bk1D4Tz1xqZ\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 30 Dec 2025 08:15:26 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vaKa0-0001mq-Gp; Mon, 29 Dec 2025 16:15:04 -0500","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <farosas@suse.de>) id 1vaKZz-0001mJ-Jo\n for qemu-devel@nongnu.org; Mon, 29 Dec 2025 16:15:03 -0500","from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <farosas@suse.de>) id 1vaKZx-00089J-Fk\n for qemu-devel@nongnu.org; Mon, 29 Dec 2025 16:15:03 -0500","from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org\n [IPv6:2a07:de40:b281:104:10:150:64:97])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by smtp-out2.suse.de (Postfix) with ESMTPS id 2BE9D5BCD9;\n Mon, 29 Dec 2025 21:14:56 +0000 (UTC)","from imap1.dmz-prg2.suse.org (localhost [127.0.0.1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9CA0F137C3;\n Mon, 29 Dec 2025 21:14:55 +0000 (UTC)","from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167])\n by imap1.dmz-prg2.suse.org with ESMTPSA id NuhGF0/vUmmhZAAAD6G6ig\n (envelope-from <farosas@suse.de>); Mon, 29 Dec 2025 21:14:55 +0000"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1767042897;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=tKsyT7tbp7WuqZuoaJlBJ8qywR2mV3VRst23hULT+2E=;\n b=RYNPsOduMAtUQVt5pU+BVqO+XY7bl89mXD8Gg7W6QBuX99pG5bODxbXzy1vDaerTmKElKA\n MfliDt/Q1uodRDv2H8PgOcT/moxHptHpt7uvht8lPAyVNyKFF7x9buL+n/xsjlHO8V1f2D\n sdE9KoVZnV8Bs+vlQjVfr0Bcwpuy51k=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1767042897;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=tKsyT7tbp7WuqZuoaJlBJ8qywR2mV3VRst23hULT+2E=;\n b=XC4yGGwFlnWSuuvSm8eki9oqG9eO7leLD7L4d4w871RxnEGWg6ZendASVKpXW8qEytDTju\n jz7sbcZlkXgiXnBg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_rsa;\n t=1767042896;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=tKsyT7tbp7WuqZuoaJlBJ8qywR2mV3VRst23hULT+2E=;\n b=q6QP+dRAHIk0nXXBtqf8WCq+NbTB8iSr3VnPp32adgmo16CK5Md3fZ9Kam6x9pibiVyYn4\n 7krYdY/GmVkM/b6+PyRn+TxxMLRqNdQg2wkga7DSlcINB9xAIkvxjuu37grEYraj6TrgPB\n T9VblWXqV57XGhQFmc1IRDLqj1s7wqU=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de;\n s=susede2_ed25519; t=1767042896;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=tKsyT7tbp7WuqZuoaJlBJ8qywR2mV3VRst23hULT+2E=;\n b=ODi4GEoT1Hjxf0lrSJF+Fn3c42RF3cDC4AU7sD7T8+NwaDBklgKgHcnXBQ+FGXwaZzJwFO\n fYGdXWSN2OMfgbAA=="],"From":"Fabiano Rosas <farosas@suse.de>","To":"Peter Xu <peterx@redhat.com>","Cc":"qemu-devel@nongnu.org","Subject":"Re: [RFC PATCH 22/25] migration/channel: Merge both sides of the\n connection initiation code","In-Reply-To":"<aVLfYlEwDu3rL3wj@x1.local>","References":"<20251226211930.27565-1-farosas@suse.de>\n <20251226211930.27565-23-farosas@suse.de> <aVLfYlEwDu3rL3wj@x1.local>","Date":"Mon, 29 Dec 2025 18:14:52 -0300","Message-ID":"<875x9p7zxv.fsf@suse.de>","MIME-Version":"1.0","Content-Type":"text/plain","X-Spam-Score":"-4.51","X-Rspamd-Queue-Id":"2BE9D5BCD9","X-Spamd-Result":"default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%];\n NEURAL_HAM_LONG(-1.00)[-1.000];\n R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain];\n MX_GOOD(-0.01)[];\n DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519];\n URIBL_BLOCKED(0.00)[suse.de:mid,suse.de:dkim,suse.de:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo];\n RCPT_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[];\n FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[];\n MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[];\n RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+];\n DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received];\n RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[];\n SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n MID_RHS_MATCH_FROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[];\n DWL_DNSWL_BLOCKED(0.00)[suse.de:dkim]; MISSING_XM_UA(0.00)[];\n DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid, suse.de:dkim, suse.de:email,\n imap1.dmz-prg2.suse.org:rdns, imap1.dmz-prg2.suse.org:helo]","X-Rspamd-Server":"rspamd1.dmz-prg2.suse.org","X-Rspamd-Action":"no action","Received-SPF":"pass client-ip=2a07:de40:b251:101:10:150:64:2;\n 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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,\n 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-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}},{"id":3629543,"web_url":"http://patchwork.ozlabs.org/comment/3629543/","msgid":"<aVL7I6tmd5wb22-n@x1.local>","list_archive_url":null,"date":"2025-12-29T22:05:23","subject":"Re: [RFC PATCH 22/25] migration/channel: Merge both sides of the\n connection initiation code","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/people/67717/","name":"Peter Xu","email":"peterx@redhat.com"},"content":"On Mon, Dec 29, 2025 at 06:14:52PM -0300, Fabiano Rosas wrote:\n> Peter Xu <peterx@redhat.com> writes:\n> \n> > On Fri, Dec 26, 2025 at 06:19:24PM -0300, Fabiano Rosas wrote:\n> >> Now that everything is in channel.c, it's easier to browse this code\n> >> if it's all in the same place. It's also easier to grasp what the\n> >> connection flow is if both sides of the connection are close together.\n> >> \n> >> Signed-off-by: Fabiano Rosas <farosas@suse.de>\n> >> ---\n> >>  migration/channel.c | 86 +++++++++++++++++++++++----------------------\n> >>  migration/channel.h | 14 ++++++--\n> >>  2 files changed, 56 insertions(+), 44 deletions(-)\n> >> \n> >> diff --git a/migration/channel.c b/migration/channel.c\n> >> index 042e01b224..ba9aa1c58b 100644\n> >> --- a/migration/channel.c\n> >> +++ b/migration/channel.c\n> >> @@ -31,10 +31,11 @@\n> >>  #include \"trace.h\"\n> >>  #include \"yank_functions.h\"\n> >>  \n> >> -bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n> >> +bool migration_connect(MigrationAddress *addr, bool out, Error **errp)\n> >>  {\n> >>      g_autoptr(QIOChannel) ioc = NULL;\n> >>      SocketAddress *saddr;\n> >> +    ERRP_GUARD();\n> >>  \n> >>      switch (addr->transport) {\n> >>      case MIGRATION_ADDRESS_TYPE_SOCKET:\n> >> @@ -44,15 +45,24 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n> >>          case SOCKET_ADDRESS_TYPE_INET:\n> >>          case SOCKET_ADDRESS_TYPE_UNIX:\n> >>          case SOCKET_ADDRESS_TYPE_VSOCK:\n> >> -            socket_connect_outgoing(saddr, errp);\n> >> -            /*\n> >> -             * async: after the socket is connected, calls\n> >> -             * migration_channel_connect_outgoing() directly.\n> >> -             */\n> >> -            return true;\n> >> +            if (out) {\n> >\n> > Personally I wouldn't suggest we merge the outgoing / incoming with\n> > migration_connect() then split paths once more in this exact function.\n> >\n> > I got this conclusion when I started to count how many \"if (out)\" are\n> > there..  When there're too much, it may imply we need to think more..\n> >\n> \n> Well, compared to before, there 50% less \"if (addr->transport == ...)\",\n> this is top level programming! =D\n\nYep, though that'll be the only part got deduplicated.\n\nReading migration_connect() will definitely break my flow of thoughts when\nhitting so many \"if (out)\", and I'll be a bit puzzled on how the code runs.\n\nI'm not sure if I'm the only one, though.\n\nIf we really want, we can introduce a MigrationAddressOps, providing one\nops for each type of MigrationAddress, differently on both sides:\n\n/* Return true if success; when false errp will be set */\nbool (*MigrationAddressOp)(MigrationAddress *addr, QIOChannel **channel, Error **errp)\n\nThen define:\n\nMigrationAddressOps[MIGRATION_ADDRESS_TYPE__MAX] addr_ops_outgoing = { ... };\nMigrationAddressOps[MIGRATION_ADDRESS_TYPE__MAX] addr_ops_incoming = { ... };\n\nAnd use them..  but it may also be an overkill when we only have incoming /\noutgoing anyway..  So IMHO the existing code (after you refactored many of\nthe rest!) looks still pretty decent to me.\n\n> \n> This part of the series is highly subjective, if there's a patch you\n> don't like it we can drop it, let's not dwell on it.. Just read my words\n> below on the previous patch, which I think you may be mistaken about.\n\nThanks, yes I was indeed mistaken and overlooked something. :)\n\n> \n> > This also answers part of my confusion when reading the previous patch - if\n> > that was only paving way for this one, IMHO it may not be as worthwhile,\n> > and I would tend to avoid both.\n> >\n> \n> Patch 21 is just a cleanup after patch 19 moves the call to\n> migration_channel_connect_outgoing from being inside the transport\n> routines to this top level here at migration_connect(), which moves the\n> places where MigrationState is used as well. So it removes unused\n> passing of MigrationState along with the SocketConnectionData.\n\nNow after I read it again, I agree with those removal of *s where they're\nnot used, like for:\n\n  fd_connect_outgoing()\n  exec_connect_outgoing()\n  file_connect_outgoing()\n\nI think socket_connect_outgoing() should also be fine, but maybe better to\nhave a pre-requisite patch removing SocketConnectData?\n\nFor most of the rest, IMHO we don't get much benefit from removing *s from\nthe parameters, especially inside qmp_migrate()..\n\nSo IMHO you were right in the commit log there, that we should justify\nevery use of migrate_get_current() to deserve fetching from a global, and\nwe should avoid using it in new code whenever possible.  IMHO we should\nstick with that.\n\nImagine the old days we debug when *s can become null, and the more we\nreference the global, the harder we fight those things (taking one refcount\nfrom the very top caller would work for all the sub-callers OTOH, when we\njustify one place thread-safe and justify all the rest).  More referencing\nglobals normally will just make things harder for us.  This rule applies to\nall the globals.. not only *s.\n\n> \n> > Thoughts?\n> >\n> >> +                socket_connect_outgoing(saddr, errp);\n> >> +                /*\n> >> +                 * async: after the socket is connected, calls\n> >> +                 * migration_channel_connect_outgoing() directly.\n> >> +                 */\n> >> +                return true;\n> >> +            } else {\n> >> +                socket_connect_incoming(saddr, errp);\n> >> +            }\n> >> +\n> >>              break;\n> >>          case SOCKET_ADDRESS_TYPE_FD:\n> >> -            ioc = fd_connect_outgoing(saddr->u.fd.str, errp);\n> >> +            if (out) {\n> >> +                ioc = fd_connect_outgoing(saddr->u.fd.str, errp);\n> >> +            } else {\n> >> +                fd_connect_incoming(saddr->u.fd.str, errp);\n> >> +            }\n> >>              break;\n> >>          default:\n> >>              g_assert_not_reached();\n> >> @@ -62,16 +72,28 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n> >>  \n> >>  #ifdef CONFIG_RDMA\n> >>      case MIGRATION_ADDRESS_TYPE_RDMA:\n> >> -        ioc = rdma_connect_outgoing(&addr->u.rdma, errp);\n> >> +        if (out) {\n> >> +            ioc = rdma_connect_outgoing(&addr->u.rdma, errp);\n> >> +        } else {\n> >> +            rdma_connect_incoming(&addr->u.rdma, errp);\n> >> +        }\n> >>          break;\n> >>  #endif\n> >>  \n> >>      case MIGRATION_ADDRESS_TYPE_EXEC:\n> >> -        ioc = exec_connect_outgoing(addr->u.exec.args, errp);\n> >> +        if (out) {\n> >> +            ioc = exec_connect_outgoing(addr->u.exec.args, errp);\n> >> +        } else {\n> >> +            exec_connect_incoming(addr->u.exec.args, errp);\n> >> +        }\n> >>          break;\n> >>  \n> >>      case MIGRATION_ADDRESS_TYPE_FILE:\n> >> -        ioc = file_connect_outgoing(&addr->u.file, errp);\n> >> +        if (out) {\n> >> +            ioc = file_connect_outgoing(&addr->u.file, errp);\n> >> +        } else {\n> >> +            file_connect_incoming(&addr->u.file, errp);\n> >> +        }\n> >>          break;\n> >>  \n> >>      default:\n> >> @@ -79,42 +101,22 @@ bool migration_connect_outgoing(MigrationAddress *addr, Error **errp)\n> >>          break;\n> >>      }\n> >>  \n> >> -    if (!ioc) {\n> >> -        return false;\n> >> -    }\n> >> -\n> >> -    migration_channel_connect_outgoing(ioc);\n> >> -    return true;\n> >> -}\n> >> -\n> >> -void migration_connect_incoming(MigrationAddress *addr, Error **errp)\n> >> -{\n> >> -    if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {\n> >> -        SocketAddress *saddr = &addr->u.socket;\n> >> -        if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||\n> >> -            saddr->type == SOCKET_ADDRESS_TYPE_UNIX ||\n> >> -            saddr->type == SOCKET_ADDRESS_TYPE_VSOCK) {\n> >> -            socket_connect_incoming(saddr, errp);\n> >> -        } else if (saddr->type == SOCKET_ADDRESS_TYPE_FD) {\n> >> -            fd_connect_incoming(saddr->u.fd.str, errp);\n> >> +    if (out) {\n> >> +        if (!ioc) {\n> >> +            return false;\n> >>          }\n> >> -#ifdef CONFIG_RDMA\n> >> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_RDMA) {\n> >> -        rdma_connect_incoming(&addr->u.rdma, errp);\n> >> -#endif\n> >> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_EXEC) {\n> >> -        exec_connect_incoming(addr->u.exec.args, errp);\n> >> -    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_FILE) {\n> >> -        file_connect_incoming(&addr->u.file, errp);\n> >> -    } else {\n> >> -        error_setg(errp, \"unknown migration protocol\");\n> >> +\n> >> +        migration_channel_connect_outgoing(ioc);\n> >> +        return true;\n> >>      }\n> >>  \n> >>      /*\n> >> -     * async: the above routines all wait for the incoming connection\n> >> -     * and call back to migration_channel_process_incoming() to start\n> >> -     * the migration.\n> >> +     * async: on the incoming side all of the transport routines above\n> >> +     * wait for the incoming connection and call back to\n> >> +     * migration_channel_process_incoming() to start the migration.\n> >>       */\n> >> +\n> >> +    return !*errp;\n> >>  }\n> >>  \n> >>  bool migration_has_main_and_multifd_channels(void)\n> >> diff --git a/migration/channel.h b/migration/channel.h\n> >> index 8cf16bfda9..86934fee38 100644\n> >> --- a/migration/channel.h\n> >> +++ b/migration/channel.h\n> >> @@ -39,6 +39,16 @@ int migration_channel_read_peek(QIOChannel *ioc,\n> >>  bool migration_has_main_and_multifd_channels(void);\n> >>  bool migration_has_all_channels(void);\n> >>  \n> >> -bool migration_connect_outgoing(MigrationAddress *addr, Error **errp);\n> >> -void migration_connect_incoming(MigrationAddress *addr, Error **errp);\n> >> +bool migration_connect(MigrationAddress *addr, bool out, Error **errp);\n> >> +static inline bool migration_connect_outgoing(MigrationAddress *addr,\n> >> +                                              Error **errp)\n> >> +{\n> >> +    return migration_connect(addr, true, errp);\n> >> +}\n> >> +\n> >> +static inline bool migration_connect_incoming(MigrationAddress *addr,\n> >> +                                              Error **errp)\n> >> +{\n> >> +    return migration_connect(addr, false, errp);\n> >> +}\n> >>  #endif\n> >> -- \n> >> 2.51.0\n> >> \n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=IhyE6Cpu;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=k4b4h99H;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dg9KP4l9cz1xqH\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 30 Dec 2025 09:06:16 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vaLMu-0006g1-8g; Mon, 29 Dec 2025 17:05:36 -0500","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1vaLMq-0006fh-Jj\n for qemu-devel@nongnu.org; Mon, 29 Dec 2025 17:05:32 -0500","from us-smtp-delivery-124.mimecast.com ([170.10.133.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1vaLMn-00019F-K7\n for qemu-devel@nongnu.org; Mon, 29 Dec 2025 17:05:32 -0500","from mail-qv1-f69.google.com (mail-qv1-f69.google.com\n [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-568-fodDtkG5OM2_yE1p9SevQw-1; Mon, 29 Dec 2025 17:05:26 -0500","by mail-qv1-f69.google.com with SMTP id\n 6a1803df08f44-88a3356a310so266392636d6.3\n for <qemu-devel@nongnu.org>; Mon, 29 Dec 2025 14:05:26 -0800 (PST)","from x1.local ([142.188.210.156]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8901d0dcd77sm42232306d6.42.2025.12.29.14.05.24\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 29 Dec 2025 14:05:24 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1767045928;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=ZTyIja2FsXRC/Ha96gf+PdtNHPQlehUzLHkaYyOJv+c=;\n b=IhyE6Cpu8tThUQhIXSjCHtDlfuAaTgXwA/rDzdXBHbBgFiA+JSkT1FvYO4iPUcT0//BjJQ\n s5iLinFhn/CQsbqpHK8kB9aEG2IegfegYel5vqxjVrl+/c5RCQMzbRMKLJydSbGMC+HrJQ\n XsyIkh0D5if+cjxnXKQyfxcxytJx8lI=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1767045925; x=1767650725; darn=nongnu.org;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;\n bh=ZTyIja2FsXRC/Ha96gf+PdtNHPQlehUzLHkaYyOJv+c=;\n b=k4b4h99HDkuhVm7RHxh1n/4zGHtLwgZtGSa3COj1z2a7O9G0StGXDvQDiZRr3Ts9nv\n V6NQKZ3YiIEeSXtMgbcRmiLysV1OUUg+c7zh3uRhD1UYmVQKe76sev2qfg9m/hWCwCDt\n t5+bd6g/nCmrwdPrClGxTKL6ea/ngypJVGbem9gI67rsq+RINEKx/zACRVPn7nWNpK6p\n /QM72x6balbcOIkKCFWVIMvy+G2Aiql+xRnW2koyNwBBl17QhtktZwXWl0qXeyztyLgM\n jOExPH2rsHG/zBsyPJUBCeH3xE5wVvDs2Qxtc/boH2dhEx1PfI9iA8NODGFpbTxOMEss\n XeCg=="],"X-MC-Unique":"fodDtkG5OM2_yE1p9SevQw-1","X-Mimecast-MFC-AGG-ID":"fodDtkG5OM2_yE1p9SevQw_1767045925","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1767045925; x=1767650725;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=ZTyIja2FsXRC/Ha96gf+PdtNHPQlehUzLHkaYyOJv+c=;\n b=qeyYHeC8LWEh8Gms2uXUe2QIZg+dl0Zr3Gd1SGRzoFoK/rnlEPmVH0bExv6R6VxkZo\n YgpSVm2MdfsuWvBOWFRzgNtQcrCDJkHqaEYV3xviJL9COsp6TKo+sj2l0xVsg9IrLPUj\n 5AAityHTZ2S7etFN6MUYquLETiabAclvBJZ/SyYTGdrpATVMEFxDBVHGpIBBuQVEcnyr\n 7OBL+a5nCgmQcA66RI+x3wnf3e3oE2XPsShDBRaiEhcsoX6ieiyfyl16BLDRbq+mTYi8\n VFTdwtmdwIehsKzqEnOcKfibg/boV6QwCuqILn71u/cSq/H7dC7/jNYZupp3ADei1jEx\n /Gng==","X-Gm-Message-State":"AOJu0Yx3JCzubyYKnvVOlXgtIczUQLzm/8HTohezum0DqzcnkisivZ7l\n O6/KUY7g7Zd0zR1WoUuB859cmI9tb4oaW+nxGuAybSW7QXGxNus+onyAM1W/SvRs7VErUKpPtvG\n yyEH2DBwbgirqT7JQ8FCxu8lC2eo6FA1oDkn3mmldhONEluzhhbOzytYa","X-Gm-Gg":"AY/fxX7VqSApA0731ayixFDWhv3XMqJaydTVSe7Kk+r369vxremGvSqiwdDFLXB9I36\n 42BpltzklRwjqha7qy7YpuKsrzJhKahv0KoiTR29JQkwoPnEPwD2EpdLIOplY6n+MDPUZpcm+Si\n iRjoJLNEL3kOB0QwSMEKMIUe1wOVyGya2f9EdNfEZQ8IYrTwkt3HAPTSdjhxnOilV6bGCSDexCp\n yI7IUHJMsAYkcbBRLCKwemgq499rKo5cw0gxnI+Bcj95OvSaqtVuA3tqitZ6u/dKfVT0tbSJ63v\n amSsMyz4p1v4Y1QpYgh+WIv8SCfsT2LyIIkldSG3IA+ZDbpv+zV+OShrvZ2yPmDLoiZevGiLvhZ\n 8vj0=","X-Received":["by 2002:a0c:ea42:0:b0:880:3ce2:65ad with SMTP id\n 6a1803df08f44-88d845357dbmr341769666d6.41.1767045925392;\n Mon, 29 Dec 2025 14:05:25 -0800 (PST)","by 2002:a0c:ea42:0:b0:880:3ce2:65ad with SMTP id\n 6a1803df08f44-88d845357dbmr341769466d6.41.1767045924894;\n Mon, 29 Dec 2025 14:05:24 -0800 (PST)"],"X-Google-Smtp-Source":"\n AGHT+IEMV7msRm0pkuq10g55tlrIeyjzMyg4gYOaM4q04eEGS0GpT0cyWcPRmHMf2tKpHcnIPD69fg==","Date":"Mon, 29 Dec 2025 17:05:23 -0500","From":"Peter Xu <peterx@redhat.com>","To":"Fabiano Rosas <farosas@suse.de>","Cc":"qemu-devel@nongnu.org","Subject":"Re: [RFC PATCH 22/25] migration/channel: Merge both sides of the\n connection initiation code","Message-ID":"<aVL7I6tmd5wb22-n@x1.local>","References":"<20251226211930.27565-1-farosas@suse.de>\n <20251226211930.27565-23-farosas@suse.de>\n <aVLfYlEwDu3rL3wj@x1.local> <875x9p7zxv.fsf@suse.de>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<875x9p7zxv.fsf@suse.de>","Received-SPF":"pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com;\n 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,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-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-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]