From: Liu Yuan <namei.unix@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: sheepdog@lists.wpkg.org, qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH] sheepdog: fix confused return values
Date: Wed, 18 Feb 2015 11:52:55 +0800 [thread overview]
Message-ID: <20150218035255.GA6415@ubuntu-trusty> (raw)
In-Reply-To: <20150216115604.GI4079@noname.str.redhat.com>
On Mon, Feb 16, 2015 at 12:56:04PM +0100, Kevin Wolf wrote:
> Am 13.02.2015 um 04:45 hat Liu Yuan geschrieben:
> > From: Liu Yuan <liuyuan@cmss.chinamobile.com>
> >
> > These functions mix up -1 and -errno in return values and would might cause
> > trouble error handling in the call chain.
> >
> > This patch let them return -errno and add some comments.
> >
> > Reported-by: Markus Armbruster <armbru@redhat.com>
> > Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
> > ---
> > block/sheepdog.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/block/sheepdog.c b/block/sheepdog.c
> > index be3176f..c28658c 100644
> > --- a/block/sheepdog.c
> > +++ b/block/sheepdog.c
> > @@ -527,6 +527,7 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
> > return acb;
> > }
> >
> > +/* Return -EIO in case of error, file descriptor on success */
> > static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
> > {
> > int fd;
> > @@ -546,11 +547,14 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
> >
> > if (fd >= 0) {
> > qemu_set_nonblock(fd);
> > + } else {
> > + fd = -EIO;
> > }
> >
> > return fd;
> > }
> >
> > +/* Return 0 on success and -errno in case of error */
> > static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
> > unsigned int *wlen)
> > {
> > @@ -559,11 +563,13 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
> > ret = qemu_co_send(sockfd, hdr, sizeof(*hdr));
> > if (ret != sizeof(*hdr)) {
> > error_report("failed to send a req, %s", strerror(errno));
> > + ret = -errno;
>
> qemu_co_sendv_recvv() uses socket_error() internally to access the
> return code. This is defined as errno on POSIX, but as WSAGetLastError()
> on Windows.
>
> You should probably either use socket_error() here, or change
> qemu_co_sendv_recvv() to return a negative error code instead of -1.
>
> > return ret;
> > }
> >
> > ret = qemu_co_send(sockfd, data, *wlen);
> > if (ret != *wlen) {
> > + ret = -errno;
> > error_report("failed to send a req, %s", strerror(errno));
> > }
>
> The same here.
>
Hi, Kevin, thanks for your tips. I'll post v2 against your comments.
Yuan
next prev parent reply other threads:[~2015-02-18 3:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-12 14:01 [Qemu-devel] Several sheepdog functions mix up -1 and -errno in return values Markus Armbruster
2015-02-13 3:45 ` [Qemu-devel] [PATCH] sheepdog: fix confused " Liu Yuan
2015-02-13 3:49 ` Liu Yuan
2015-02-16 11:56 ` Kevin Wolf
2015-02-18 3:52 ` Liu Yuan [this message]
2015-02-18 8:35 ` Markus Armbruster
2015-02-25 1:39 ` Liu Yuan
2015-02-25 9:35 ` Markus Armbruster
2015-02-26 3:54 ` Liu Yuan
2015-02-26 7:50 ` Markus Armbruster
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=20150218035255.GA6415@ubuntu-trusty \
--to=namei.unix@gmail.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sheepdog@lists.wpkg.org \
/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).