From: Peter Xu <peterx@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: berrange@redhat.com, qemu-devel@nongnu.org,
qemu-block@nongnu.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH 02/10] char-socket: rework tcp_chr_recv()
Date: Mon, 8 Sep 2025 17:53:19 -0400 [thread overview]
Message-ID: <aL9QT9T2QTCA_tks@x1.local> (raw)
In-Reply-To: <20250903094411.1029449-3-vsementsov@yandex-team.ru>
On Wed, Sep 03, 2025 at 12:44:02PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> First, qio_channel_readv_full() already guarantees BLOCKING and
> CLOEXEC states for incoming descriptors, no reason call extra
> ioctls.
>
> Second, current implementation calls _set_block() and _set_cloexec()
> again on old descriptors on failure path - we fix this too.
>
> Finally, handling errors exactly after qio_channel_readv_full() call
> looks more readable.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> chardev/char-socket.c | 37 +++++++++++++------------------------
> 1 file changed, 13 insertions(+), 24 deletions(-)
>
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index 1e8313915b..5b9b19ba8b 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -293,6 +293,18 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len)
> 0, &err);
> }
>
> + if (ret == QIO_CHANNEL_ERR_BLOCK) {
> + errno = EAGAIN;
> + return -1;
> + } else if (ret == -1) {
> + trace_chr_socket_recv_err(chr, chr->label, error_get_pretty(err));
> + error_free(err);
> + errno = EIO;
> + return -1;
> + }
> +
> + assert(ret >= 0);
> +
> if (msgfds_num) {
> /* close and clean read_msgfds */
> for (i = 0; i < s->read_msgfds_num; i++) {
> @@ -307,30 +319,7 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len)
> s->read_msgfds_num = msgfds_num;
> }
>
> - for (i = 0; i < s->read_msgfds_num; i++) {
> - int fd = s->read_msgfds[i];
> - if (fd < 0) {
> - continue;
> - }
> -
> - /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
> - qemu_socket_set_block(fd);
> -
> -#ifndef MSG_CMSG_CLOEXEC
> - qemu_set_cloexec(fd);
> -#endif
> - }
> -
> - if (ret == QIO_CHANNEL_ERR_BLOCK) {
> - errno = EAGAIN;
> - ret = -1;
> - } else if (ret == -1) {
> - trace_chr_socket_recv_err(chr, chr->label, error_get_pretty(err));
> - error_free(err);
> - errno = EIO;
> - } else if (ret == 0) {
> - trace_chr_socket_recv_eof(chr, chr->label);
> - }
> + trace_chr_socket_recv_eof(chr, chr->label);
This tracepoint may still need to be put into a ret==0 check.
Looks reasonable other than that..
>
> return ret;
> }
> --
> 2.48.1
>
--
Peter Xu
next prev parent reply other threads:[~2025-09-08 21:54 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 9:44 [PATCH 00/10] io: deal with blocking/non-blocking fds Vladimir Sementsov-Ogievskiy
2025-09-03 9:44 ` [PATCH 01/10] io/channel: document how qio_channel_readv_full() handles fds Vladimir Sementsov-Ogievskiy
2025-09-09 8:34 ` Daniel P. Berrangé
2025-09-03 9:44 ` [PATCH 02/10] char-socket: rework tcp_chr_recv() Vladimir Sementsov-Ogievskiy
2025-09-08 21:53 ` Peter Xu [this message]
2025-09-09 7:49 ` Vladimir Sementsov-Ogievskiy
2025-09-09 8:38 ` Daniel P. Berrangé
2025-09-09 8:46 ` Vladimir Sementsov-Ogievskiy
2025-09-03 9:44 ` [PATCH 03/10] util: add qemu_set_blocking() function Vladimir Sementsov-Ogievskiy
2025-09-08 22:02 ` Peter Xu
2025-09-09 7:51 ` Vladimir Sementsov-Ogievskiy
2025-09-09 8:59 ` Daniel P. Berrangé
2025-09-03 9:44 ` [PATCH 04/10] util: drop qemu_socket_set_nonblock() Vladimir Sementsov-Ogievskiy
2025-09-08 22:16 ` Peter Xu
2025-09-09 8:19 ` Vladimir Sementsov-Ogievskiy
2025-09-10 9:41 ` Daniel P. Berrangé
2025-09-10 10:32 ` Vladimir Sementsov-Ogievskiy
2025-09-10 9:44 ` Daniel P. Berrangé
2025-09-10 10:33 ` Vladimir Sementsov-Ogievskiy
2025-09-10 15:30 ` Vladimir Sementsov-Ogievskiy
2025-09-10 17:55 ` Vladimir Sementsov-Ogievskiy
2025-09-10 18:15 ` Daniel P. Berrangé
2025-09-10 18:52 ` Vladimir Sementsov-Ogievskiy
2025-09-12 14:51 ` Daniel P. Berrangé
2025-09-03 9:44 ` [PATCH 05/10] util: drop qemu_socket_try_set_nonblock() Vladimir Sementsov-Ogievskiy
2025-09-09 0:09 ` Peter Xu
2025-09-03 9:44 ` [PATCH 06/10] util: drop qemu_socket_set_block() Vladimir Sementsov-Ogievskiy
2025-09-03 9:44 ` [PATCH 07/10] use qemu_set_blocking instead of g_unix_set_fd_nonblocking Vladimir Sementsov-Ogievskiy
2025-09-09 9:00 ` Daniel P. Berrangé
2025-09-09 9:11 ` Vladimir Sementsov-Ogievskiy
2025-09-09 9:15 ` Daniel P. Berrangé
2025-09-09 9:50 ` Vladimir Sementsov-Ogievskiy
2025-09-10 9:32 ` Daniel P. Berrangé
2025-09-09 14:24 ` Stefan Hajnoczi
2025-09-03 9:44 ` [PATCH 08/10] oslib-posix: add qemu_fds_set_blocking() helper Vladimir Sementsov-Ogievskiy
2025-09-03 9:48 ` Vladimir Sementsov-Ogievskiy
2025-09-10 9:52 ` Daniel P. Berrangé
2025-09-10 10:42 ` Vladimir Sementsov-Ogievskiy
2025-09-03 9:44 ` [PATCH 09/10] qio_channel_readv_full(): move setting fd blocking to callers Vladimir Sementsov-Ogievskiy
2025-09-03 9:44 ` [PATCH 10/10] migration/qemu-file: don't make incoming fds blocking again Vladimir Sementsov-Ogievskiy
2025-09-03 9:47 ` Vladimir Sementsov-Ogievskiy
2025-09-04 14:35 ` [PATCH 00/10] io: deal with blocking/non-blocking fds Lei Yang
2025-09-09 8:12 ` Vladimir Sementsov-Ogievskiy
2025-09-09 14:25 ` Stefan Hajnoczi
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=aL9QT9T2QTCA_tks@x1.local \
--to=peterx@redhat.com \
--cc=berrange@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/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).