From: JAEHOON KIM <jhkim@linux.ibm.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Steven Sistare <steven.sistare@oracle.com>,
qemu-devel@nongnu.org, jjherne@linux.ibm.com, peterx@redhat.com,
farosas@suse.de
Subject: Re: [PATCH v1] migration: Wait for cpr.sock file to appear before connecting
Date: Mon, 9 Jun 2025 10:32:13 -0500 [thread overview]
Message-ID: <8d8b48eb-32d1-4263-bb19-14179b82ee9a@linux.ibm.com> (raw)
In-Reply-To: <aEb2aaOpn4aahXcM@redhat.com>
On 6/9/2025 9:57 AM, Daniel P. Berrangé wrote:
> On Mon, Jun 09, 2025 at 09:54:02AM -0500, JAEHOON KIM wrote:
>> On 6/9/2025 8:50 AM, Daniel P. Berrangé wrote:
>>> On Mon, Jun 09, 2025 at 09:39:48AM -0400, Steven Sistare wrote:
>>>> On 6/9/2025 9:20 AM, Daniel P. Berrangé wrote:
>>>>> On Mon, Jun 09, 2025 at 09:12:27AM -0400, Steven Sistare wrote:
>>>>>> On 6/9/2025 4:06 AM, Daniel P. Berrangé wrote:
>>>>>>> On Fri, Jun 06, 2025 at 03:37:56PM -0400, Steven Sistare wrote:
>>>>>>>> The easiest solution, with no interface changes, is adding wait_for_socket() in qtest,
>>>>>>>> with this addition from Daniel:
>>>>>>>>
>>>>>>>> "With the busy wait you risk looping forever if the child (target) QEMU
>>>>>>>> already exited for some reason without ever creating the socket. You
>>>>>>>> can mitigate this by using 'kill($PID, 0)' in the loop and looking
>>>>>>>> for -ERSCH, but this only works if you know the pid involved."
>>>>>>>>
>>>>>>>> Daniel also suggested:
>>>>>>>> "For the tests, passing a pre-opened UNIX socket FD could work"
>>>>>>>>
>>>>>>>> Note we can not use any of the standard chardev options to specify such a socket,
>>>>>>>> because the cpr socket is created before chardevs are created.
>>>>>>>>
>>>>>>>> Perhaps we could specify the fd in an extension of the MigrationChannel MigrationAddress.
>>>>>>>> { 'union': 'MigrationAddress',
>>>>>>>> 'base': { 'transport' : 'MigrationAddressType'},
>>>>>>>> 'discriminator': 'transport',
>>>>>>>> 'data': {
>>>>>>>> 'socket': 'SocketAddress',
>>>>>>>> 'exec': 'MigrationExecCommand',
>>>>>>>> 'rdma': 'InetSocketAddress',
>>>>>>>> 'file': 'FileMigrationArgs',
>>>>>>>> 'fd': 'FdMigrationArgs' } } <-- add this
>>>>>>>>
>>>>>>>> That would be useful for all clients, but this is asking a lot from you,
>>>>>>>> when you are just trying to fix the tests.
>>>>>>> Note, 'SocketAddress' already has an option for declaring a FD that
>>>>>>> represents a socket.
>>>>>> Yes, but if I understand, you proposed passing an fd that represents a
>>>>>> pre-listened socket, which requires target qemu to accept() first. The
>>>>>> existing FdSocketAddress is ready to read. We could add a boolean to enable
>>>>>> the new behavior.
>>>>> It can do both actually - it depends on what APIs the QEMU uses the
>>>>> SocketAddress with.
>>>>>
>>>>> If it is used with qio_channel_socket_connect* the FD must be an
>>>>> active peer connection.
>>>>>
>>>>> If it is used with qio_channel_socket_listen*/qio_net_listener* the
>>>>> FD must be listener socket.
>>>> Fair enough. cpr currently listens here, and we could add a case for the FD:
>>>>
>>>> QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp)
>>>> {
>>>> MigrationAddress *addr = channel->addr;
>>>>
>>>> if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET &&
>>>> addr->u.socket.type == SOCKET_ADDRESS_TYPE_UNIX) {
>>>> ...
>>>> g_autoptr(QIONetListener) listener = qio_net_listener_new();
>>>>
>>>> Or to use my socketpair() suggestion, that function would also need changes,
>>>> calling qio_channel_socket_connect.
>>>>
>>>> Which do you think is better for clients -- socketpair or pre-listened?
>>> Please just use the existing SocketAddress functionality, as that's used
>>> throughout QEMU - a special case with socketpair for migration is not
>>> desirable.
>>>
>>> The SocketAddress stuff is what libvirt's used for many years now to
>>> address the race condition with QMP listeners.
>> Dear Daniel and Steve,
>>
>> Thank you both for your valuable insights.
>>
>> To clarify regarding the socket handling approach:
>> If I do not use socketpair() and instead pass a pre-listened FD to the target, which then calls accept(),
>> it seems this could mitigate some race condition. However, isn't there still a risk that the old QEMU might try to
>> connect before the target QEMU calls accept(), thereby resulting in the same race condition?
> No, that's fine. The kernel will queue all incoming connections
> until accept() is called. So essentially the source QEMU connect()
> will get blocked until dst QEMU accept()s, which is exactly the
> semantics we want.
>
> With regards,
> Daniel
Thank you for the clarification.
If, as you said, the kernel queues incoming connections until accept()
is called, then the race condition should not occur.
I'll take this approach into consideration.
- Jaehoon Kim.
prev parent reply other threads:[~2025-06-09 15:32 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 23:08 [PATCH v1] migration: Wait for cpr.sock file to appear before connecting Jaehoon Kim
2025-06-06 13:40 ` Fabiano Rosas
2025-06-06 14:48 ` JAEHOON KIM
2025-06-06 15:47 ` Daniel P. Berrangé
2025-06-06 13:53 ` Daniel P. Berrangé
2025-06-06 14:14 ` Steven Sistare
2025-06-06 15:06 ` JAEHOON KIM
2025-06-06 15:12 ` Steven Sistare
2025-06-06 15:37 ` JAEHOON KIM
2025-06-06 15:43 ` Daniel P. Berrangé
2025-06-06 15:50 ` Steven Sistare
2025-06-06 16:06 ` Daniel P. Berrangé
2025-06-06 17:04 ` Steven Sistare
2025-06-06 18:06 ` JAEHOON KIM
2025-06-06 19:37 ` Steven Sistare
2025-06-08 22:01 ` JAEHOON KIM
2025-06-09 8:06 ` Daniel P. Berrangé
2025-06-09 13:12 ` Steven Sistare
2025-06-09 13:20 ` Daniel P. Berrangé
2025-06-09 13:39 ` Steven Sistare
2025-06-09 13:48 ` JAEHOON KIM
2025-06-09 13:50 ` Daniel P. Berrangé
2025-06-09 14:54 ` JAEHOON KIM
2025-06-09 14:57 ` Daniel P. Berrangé
2025-06-09 15:32 ` JAEHOON KIM [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8d8b48eb-32d1-4263-bb19-14179b82ee9a@linux.ibm.com \
--to=jhkim@linux.ibm.com \
--cc=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=jjherne@linux.ibm.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=steven.sistare@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).