* [PATCH v4 0/2] save qemu-file incoming non-blocking fds
@ 2025-09-10 19:31 Vladimir Sementsov-Ogievskiy
2025-09-10 19:31 ` [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again Vladimir Sementsov-Ogievskiy
2025-09-10 19:31 ` [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds Vladimir Sementsov-Ogievskiy
0 siblings, 2 replies; 7+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-09-10 19:31 UTC (permalink / raw)
To: berrange; +Cc: peterx, farosas, steven.sistare, vsementsov, qemu-devel
Hi all!
That's a new version for
[PATCH v3] migration/qemu-file: don't make incoming fds blocking again
Supersedes: <20250910143156.1053779-1-vsementsov@yandex-team.ru>
, adding small changes suggested by Peter.
Also, I've added here documentation patch from
[PATCH 00/10] io: deal with blocking/non-blocking fds
, because I have to change it anyway after this new flag.
Vladimir Sementsov-Ogievskiy (2):
migration/qemu-file: don't make incoming fds blocking again
io/channel: document how qio_channel_readv_full() handles fds
include/io/channel.h | 18 ++++++++++++++++++
io/channel-socket.c | 13 +++++++++----
migration/qemu-file.c | 3 ++-
3 files changed, 29 insertions(+), 5 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again
2025-09-10 19:31 [PATCH v4 0/2] save qemu-file incoming non-blocking fds Vladimir Sementsov-Ogievskiy
@ 2025-09-10 19:31 ` Vladimir Sementsov-Ogievskiy
2025-09-10 19:42 ` Peter Xu
2025-09-12 16:47 ` Daniel P. Berrangé
2025-09-10 19:31 ` [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds Vladimir Sementsov-Ogievskiy
1 sibling, 2 replies; 7+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-09-10 19:31 UTC (permalink / raw)
To: berrange; +Cc: peterx, farosas, steven.sistare, vsementsov, qemu-devel
In migration we want to pass fd "as is", not changing its
blocking status.
The only current user of these fds is CPR state (through VMSTATE_FD),
which of-course doesn't want to modify fds on target when source is
still running and use these fds.
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
include/io/channel.h | 1 +
io/channel-socket.c | 13 +++++++++----
migration/qemu-file.c | 3 ++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/include/io/channel.h b/include/io/channel.h
index 234e5db70d..12266256a8 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -36,6 +36,7 @@ OBJECT_DECLARE_TYPE(QIOChannel, QIOChannelClass,
#define QIO_CHANNEL_READ_FLAG_MSG_PEEK 0x1
#define QIO_CHANNEL_READ_FLAG_RELAXED_EOF 0x2
+#define QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING 0x4
typedef enum QIOChannelFeature QIOChannelFeature;
diff --git a/io/channel-socket.c b/io/channel-socket.c
index 3b7ca924ff..21f8f2e0c5 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -464,7 +464,8 @@ static void qio_channel_socket_finalize(Object *obj)
#ifndef WIN32
static void qio_channel_socket_copy_fds(struct msghdr *msg,
- int **fds, size_t *nfds)
+ int **fds, size_t *nfds,
+ bool preserve_blocking)
{
struct cmsghdr *cmsg;
@@ -497,8 +498,10 @@ static void qio_channel_socket_copy_fds(struct msghdr *msg,
continue;
}
- /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
- qemu_socket_set_block(fd);
+ if (!preserve_blocking) {
+ /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
+ qemu_socket_set_block(fd);
+ }
#ifndef MSG_CMSG_CLOEXEC
qemu_set_cloexec(fd);
@@ -556,7 +559,9 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc,
}
if (fds && nfds) {
- qio_channel_socket_copy_fds(&msg, fds, nfds);
+ qio_channel_socket_copy_fds(
+ &msg, fds, nfds,
+ flags & QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING);
}
return ret;
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index b6ac190034..d5c6e7ec61 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -340,7 +340,8 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMUFile *f)
do {
struct iovec iov = { f->buf + pending, IO_BUF_SIZE - pending };
- len = qio_channel_readv_full(f->ioc, &iov, 1, pfds, pnfd, 0,
+ len = qio_channel_readv_full(f->ioc, &iov, 1, pfds, pnfd,
+ QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING,
&local_error);
if (len == QIO_CHANNEL_ERR_BLOCK) {
if (qemu_in_coroutine()) {
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds
2025-09-10 19:31 [PATCH v4 0/2] save qemu-file incoming non-blocking fds Vladimir Sementsov-Ogievskiy
2025-09-10 19:31 ` [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again Vladimir Sementsov-Ogievskiy
@ 2025-09-10 19:31 ` Vladimir Sementsov-Ogievskiy
2025-09-10 19:56 ` Peter Xu
2025-09-12 16:48 ` Daniel P. Berrangé
1 sibling, 2 replies; 7+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-09-10 19:31 UTC (permalink / raw)
To: berrange; +Cc: peterx, farosas, steven.sistare, vsementsov, qemu-devel
The only realization, which may have incoming fds is
qio_channel_socket_readv() (in io/channel-socket.c).
qio_channel_socket_readv() do call (through
qio_channel_socket_copy_fds()) qemu_socket_set_block() and
qemu_set_cloexec() for each fd.
Also, qio_channel_socket_copy_fds() is called at the end of
qio_channel_socket_readv(), on success path.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
include/io/channel.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/io/channel.h b/include/io/channel.h
index 12266256a8..c7f64506f7 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -118,6 +118,15 @@ struct QIOChannelClass {
size_t nfds,
int flags,
Error **errp);
+
+ /*
+ * The io_readv handler must guarantee that all
+ * incoming fds are set BLOCKING (unless
+ * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag is set) and
+ * CLOEXEC (if available).
+ * @fds and @nfds are set only on success path, and untouched
+ * in case of errors.
+ */
ssize_t (*io_readv)(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
@@ -125,6 +134,7 @@ struct QIOChannelClass {
size_t *nfds,
int flags,
Error **errp);
+
int (*io_close)(QIOChannel *ioc,
Error **errp);
GSource * (*io_create_watch)(QIOChannel *ioc,
@@ -235,6 +245,13 @@ void qio_channel_set_name(QIOChannel *ioc,
* was allocated. It is the callers responsibility
* to call close() on each file descriptor and to
* call g_free() on the array pointer in @fds.
+ * @fds allocated and set (and @nfds is set too)
+ * _only_ on success path. These parameters are
+ * untouched in case of errors.
+ * qio_channel_readv_full() guarantees that all
+ * incoming fds are set BLOCKING (unless
+ * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag
+ * is set) and CLOEXEC (if available).
*
* It is an error to pass a non-NULL @fds parameter
* unless qio_channel_has_feature() returns a true
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again
2025-09-10 19:31 ` [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again Vladimir Sementsov-Ogievskiy
@ 2025-09-10 19:42 ` Peter Xu
2025-09-12 16:47 ` Daniel P. Berrangé
1 sibling, 0 replies; 7+ messages in thread
From: Peter Xu @ 2025-09-10 19:42 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy
Cc: berrange, farosas, steven.sistare, qemu-devel
On Wed, Sep 10, 2025 at 10:31:11PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> In migration we want to pass fd "as is", not changing its
> blocking status.
>
> The only current user of these fds is CPR state (through VMSTATE_FD),
> which of-course doesn't want to modify fds on target when source is
> still running and use these fds.
>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Thanks,
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds
2025-09-10 19:31 ` [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds Vladimir Sementsov-Ogievskiy
@ 2025-09-10 19:56 ` Peter Xu
2025-09-12 16:48 ` Daniel P. Berrangé
1 sibling, 0 replies; 7+ messages in thread
From: Peter Xu @ 2025-09-10 19:56 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy
Cc: berrange, farosas, steven.sistare, qemu-devel
On Wed, Sep 10, 2025 at 10:31:12PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> The only realization, which may have incoming fds is
> qio_channel_socket_readv() (in io/channel-socket.c).
> qio_channel_socket_readv() do call (through
> qio_channel_socket_copy_fds()) qemu_socket_set_block() and
> qemu_set_cloexec() for each fd.
>
> Also, qio_channel_socket_copy_fds() is called at the end of
> qio_channel_socket_readv(), on success path.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Maybe I'd just keep the io_readv() one, but drop the extra documents in
qio_channel_readv_full(), because that is almost a duplicate.
Meanwhile, we also have other higher level API that has the @fds
(qio_channel_readv_full_all_eof(), for example) that are not documented,
OTOH..
Totally no strong feelings.
Acked-by: Peter Xu <peterx@redhat.com>
> ---
> include/io/channel.h | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/include/io/channel.h b/include/io/channel.h
> index 12266256a8..c7f64506f7 100644
> --- a/include/io/channel.h
> +++ b/include/io/channel.h
> @@ -118,6 +118,15 @@ struct QIOChannelClass {
> size_t nfds,
> int flags,
> Error **errp);
> +
> + /*
> + * The io_readv handler must guarantee that all
> + * incoming fds are set BLOCKING (unless
> + * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag is set) and
> + * CLOEXEC (if available).
> + * @fds and @nfds are set only on success path, and untouched
> + * in case of errors.
> + */
> ssize_t (*io_readv)(QIOChannel *ioc,
> const struct iovec *iov,
> size_t niov,
> @@ -125,6 +134,7 @@ struct QIOChannelClass {
> size_t *nfds,
> int flags,
> Error **errp);
> +
> int (*io_close)(QIOChannel *ioc,
> Error **errp);
> GSource * (*io_create_watch)(QIOChannel *ioc,
> @@ -235,6 +245,13 @@ void qio_channel_set_name(QIOChannel *ioc,
> * was allocated. It is the callers responsibility
> * to call close() on each file descriptor and to
> * call g_free() on the array pointer in @fds.
> + * @fds allocated and set (and @nfds is set too)
> + * _only_ on success path. These parameters are
> + * untouched in case of errors.
> + * qio_channel_readv_full() guarantees that all
> + * incoming fds are set BLOCKING (unless
> + * QIO_CHANNEL_READ_FLAG_FD_PRESERVE_BLOCKING flag
> + * is set) and CLOEXEC (if available).
> *
> * It is an error to pass a non-NULL @fds parameter
> * unless qio_channel_has_feature() returns a true
> --
> 2.48.1
>
--
Peter Xu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again
2025-09-10 19:31 ` [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again Vladimir Sementsov-Ogievskiy
2025-09-10 19:42 ` Peter Xu
@ 2025-09-12 16:47 ` Daniel P. Berrangé
1 sibling, 0 replies; 7+ messages in thread
From: Daniel P. Berrangé @ 2025-09-12 16:47 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy; +Cc: peterx, farosas, steven.sistare, qemu-devel
On Wed, Sep 10, 2025 at 10:31:11PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> In migration we want to pass fd "as is", not changing its
> blocking status.
>
> The only current user of these fds is CPR state (through VMSTATE_FD),
> which of-course doesn't want to modify fds on target when source is
> still running and use these fds.
>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> include/io/channel.h | 1 +
> io/channel-socket.c | 13 +++++++++----
> migration/qemu-file.c | 3 ++-
> 3 files changed, 12 insertions(+), 5 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds
2025-09-10 19:31 ` [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds Vladimir Sementsov-Ogievskiy
2025-09-10 19:56 ` Peter Xu
@ 2025-09-12 16:48 ` Daniel P. Berrangé
1 sibling, 0 replies; 7+ messages in thread
From: Daniel P. Berrangé @ 2025-09-12 16:48 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy; +Cc: peterx, farosas, steven.sistare, qemu-devel
On Wed, Sep 10, 2025 at 10:31:12PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> The only realization, which may have incoming fds is
> qio_channel_socket_readv() (in io/channel-socket.c).
> qio_channel_socket_readv() do call (through
> qio_channel_socket_copy_fds()) qemu_socket_set_block() and
> qemu_set_cloexec() for each fd.
>
> Also, qio_channel_socket_copy_fds() is called at the end of
> qio_channel_socket_readv(), on success path.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> include/io/channel.h | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-09-12 16:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-10 19:31 [PATCH v4 0/2] save qemu-file incoming non-blocking fds Vladimir Sementsov-Ogievskiy
2025-09-10 19:31 ` [PATCH v4 1/2] migration/qemu-file: don't make incoming fds blocking again Vladimir Sementsov-Ogievskiy
2025-09-10 19:42 ` Peter Xu
2025-09-12 16:47 ` Daniel P. Berrangé
2025-09-10 19:31 ` [PATCH v4 2/2] io/channel: document how qio_channel_readv_full() handles fds Vladimir Sementsov-Ogievskiy
2025-09-10 19:56 ` Peter Xu
2025-09-12 16:48 ` Daniel P. Berrangé
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).