All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Kagan <rvkagan@yandex-team.ru>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	"Daniel P. Berrange" <berrange@redhat.com>,
	"open list:Block layer core" <qemu-block@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	QEMU <qemu-devel@nongnu.org>,
	Raphael Norwitz <raphael.norwitz@nutanix.com>,
	Hanna Reitz <hreitz@redhat.com>,
	yc-core@yandex-team.ru, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 04/10] chardev/char-fe: don't allow EAGAIN from blocking read
Date: Fri, 12 Nov 2021 22:04:54 +0300	[thread overview]
Message-ID: <YY661s3JqoL6GQMZ@rvkaganb.lan> (raw)
In-Reply-To: <CAJ+F1CKmAR9K6_HRr66+rTxzBVUTbw+GNJ22tByuLyx+CHYfVw@mail.gmail.com>

On Fri, Nov 12, 2021 at 12:24:06PM +0400, Marc-André Lureau wrote:
> Hi
> 
> On Thu, Nov 11, 2021 at 7:44 PM Roman Kagan <rvkagan@yandex-team.ru> wrote:
> 
> > As its name suggests, ChardevClass.chr_sync_read is supposed to do a
> > blocking read.  The only implementation of it, tcp_chr_sync_read, does
> > set the underlying io channel to the blocking mode indeed.
> >
> > Therefore a failure return with EAGAIN is not expected from this call.
> >
> > So do not retry it in qemu_chr_fe_read_all; instead place an assertion
> > that it doesn't fail with EAGAIN.
> >
> 
> The code was introduced in :
> commit 7b0bfdf52d694c9a3a96505aa42ce3f8d63acd35
> Author: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>
> Date:   Tue May 27 15:03:48 2014 +0300
> 
>     Add chardev API qemu_chr_fe_read_all

Right, but at that point chr_sync_read wasn't made to block.  It
happened later in

commit bcdeb9be566ded2eb35233aaccf38742a21e5daa
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date:   Thu Jul 6 19:03:53 2017 +0200

    chardev: block during sync read
    
    A sync read should block until all requested data is
    available (instead of retrying in qemu_chr_fe_read_all). Change the
    channel to blocking during sync_read.

> > @@ -68,13 +68,10 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t
> > *buf, int len)
> >      }
> >
> >      while (offset < len) {
> > -    retry:
> >          res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset,
> >                                                    len - offset);
> > -        if (res == -1 && errno == EAGAIN) {
> > -            g_usleep(100);
> > -            goto retry;
> > -        }
> > +        /* ->chr_sync_read should block */
> > +        assert(!(res < 0 && errno == EAGAIN));
> >
> >
> While I agree with the rationale to clean this code a bit, I am not so sure
> about replacing it with an assert(). In the past, when we did such things
> we had unexpected regressions :)

Valid point, qemu may be run against some OS where a blocking call may
sporadically return -EAGAIN, and it would be hard to reliably catch this
with testing.

> A slightly better approach perhaps is g_warn_if_fail(), although it's not
> very popular in qemu.

I think the first thing to decide is whether -EAGAIN from a blocking
call isn't broken enough, and justifies (unlimited) retries.  I'm
tempted to just remove any special handling of -EAGAIN and treat it as
any other error, leaving up to the caller to handle (most probably to
fail the call and initiate a recovery, if possible).

Does this make sense?

Thanks,
Roman.


  reply	other threads:[~2021-11-12 19:05 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 15:33 [PATCH 00/10] vhost: stick to -errno error return convention Roman Kagan
2021-11-11 15:33 ` [PATCH 01/10] vhost-user-blk: reconnect on any error during realize Roman Kagan
2021-11-11 17:52   ` Kevin Wolf
2021-11-12  7:39     ` Roman Kagan
2021-11-12 11:37       ` Kevin Wolf
2021-11-12 19:59         ` Roman Kagan
2021-11-29 22:15           ` Raphael Norwitz
2021-11-29 22:17   ` Raphael Norwitz
2021-11-11 15:33 ` [PATCH 02/10] chardev/char-socket: tcp_chr_recv: don't clobber errno Roman Kagan
2021-11-12  8:27   ` Marc-André Lureau
2021-11-11 15:33 ` [PATCH 03/10] chardev/char-socket: tcp_chr_sync_read: " Roman Kagan
2021-11-12  8:28   ` Marc-André Lureau
2021-11-11 15:33 ` [PATCH 04/10] chardev/char-fe: don't allow EAGAIN from blocking read Roman Kagan
2021-11-12  8:24   ` Marc-André Lureau
2021-11-12 19:04     ` Roman Kagan [this message]
2021-11-11 15:33 ` [PATCH 05/10] vhost-backend: avoid overflow on memslots_limit Roman Kagan
2021-11-11 17:59   ` Philippe Mathieu-Daudé
2021-11-12  7:46     ` Roman Kagan
2021-11-12  9:56       ` Daniel P. Berrangé
2021-11-12 11:10         ` Roman Kagan
2021-11-11 15:33 ` [PATCH 06/10] vhost-backend: stick to -errno error return convention Roman Kagan
2021-11-11 18:00   ` Philippe Mathieu-Daudé
2021-11-11 15:33 ` [PATCH 07/10] vhost-vdpa: " Roman Kagan
2021-11-11 15:33 ` [PATCH 08/10] vhost-user: " Roman Kagan
2021-11-11 15:33 ` [PATCH 09/10] vhost: " Roman Kagan
2021-11-11 15:33 ` [PATCH 10/10] vhost-user-blk: propagate error return from generic vhost Roman Kagan
2021-11-29 22:37   ` Raphael Norwitz
2021-11-11 20:14 ` [PATCH 00/10] vhost: stick to -errno error return convention Michael S. Tsirkin
2021-11-12  8:04   ` Roman Kagan
2021-11-28 21:47 ` Michael S. Tsirkin
2021-11-29 21:44   ` Roman Kagan
2022-01-06  9:57 ` Michael S. Tsirkin

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=YY661s3JqoL6GQMZ@rvkaganb.lan \
    --to=rvkagan@yandex-team.ru \
    --cc=berrange@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    --cc=yc-core@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.