From: Eric Blake <eblake@redhat.com>
To: "xinhua.Cao" <caoxinhua@huawei.com>,
pbonzini@redhat.com, marcandre.lureau@redhat.com,
anton.nefedov@virtuozzo.com, vsementsov@virtuozzo.com
Cc: weidong.huang@huawei.com, weifuqiang@huawei.com,
king.wang@huawei.com, arei.gonglei@huawei.com,
liuyongan@huawei.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu-char: reset errno before qemu char write or read action
Date: Mon, 2 Jul 2018 06:57:46 -0500 [thread overview]
Message-ID: <bc41d8c5-f8cc-90ab-f6fe-064ff071116e@redhat.com> (raw)
In-Reply-To: <20180702004910.13216-1-caoxinhua@huawei.com>
On 07/01/2018 07:49 PM, xinhua.Cao wrote:
> In the tcp_chr_write function, we checked errno,
> but errno was not reset before a read or write operation.
> Therefore, this check of errno's actions is often
> incorrect after EAGAIN has occurred.
> We reset errno before reading and writing to
> ensure the correctness of errno's judgment
>
> Signed-off-by: xinhua.Cao <caoxinhua@huawei.com>
> ---
> chardev/char-fe.c | 1 +
> chardev/char.c | 2 ++
> 2 files changed, 3 insertions(+)
>
> diff --git a/chardev/char-fe.c b/chardev/char-fe.c
> index b1f228e..d96ca6f 100644
> --- a/chardev/char-fe.c
> +++ b/chardev/char-fe.c
> @@ -69,6 +69,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
>
> while (offset < len) {
> retry:
> + errno = 0;
> res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset,
> len - offset);
> if (res == -1 && errno == EAGAIN) {
NACK. read() is guaranteed to have set errno if res is -1, and we don't
check errno unless we first checked that res was -1. Thus, the EAGAIN
check is not confused by a stale errno value.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-07-02 11:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-02 0:49 [Qemu-devel] [PATCH] qemu-char: reset errno before qemu char write or read action xinhua.Cao
2018-07-02 1:42 ` Philippe Mathieu-Daudé
2018-07-02 8:46 ` Paolo Bonzini
2018-07-04 4:12 ` xinhua.Cao
2018-07-02 11:57 ` Eric Blake [this message]
2018-07-02 15:01 ` Stefan Hajnoczi
2018-07-04 2:10 ` xinhua.Cao
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=bc41d8c5-f8cc-90ab-f6fe-064ff071116e@redhat.com \
--to=eblake@redhat.com \
--cc=anton.nefedov@virtuozzo.com \
--cc=arei.gonglei@huawei.com \
--cc=caoxinhua@huawei.com \
--cc=king.wang@huawei.com \
--cc=liuyongan@huawei.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
--cc=weidong.huang@huawei.com \
--cc=weifuqiang@huawei.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).