From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNvhE-0002io-Dj for qemu-devel@nongnu.org; Tue, 17 Feb 2015 22:53:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNvhB-0003zv-5B for qemu-devel@nongnu.org; Tue, 17 Feb 2015 22:53:08 -0500 Received: from mail-ig0-x236.google.com ([2607:f8b0:4001:c05::236]:35491) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNvhA-0003zk-Vu for qemu-devel@nongnu.org; Tue, 17 Feb 2015 22:53:05 -0500 Received: by mail-ig0-f182.google.com with SMTP id h15so34334307igd.3 for ; Tue, 17 Feb 2015 19:53:03 -0800 (PST) Date: Wed, 18 Feb 2015 11:52:55 +0800 From: Liu Yuan Message-ID: <20150218035255.GA6415@ubuntu-trusty> References: <87pp9f1b61.fsf@blackfin.pond.sub.org> <1423799142-21893-1-git-send-email-namei.unix@gmail.com> <20150216115604.GI4079@noname.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150216115604.GI4079@noname.str.redhat.com> Subject: Re: [Qemu-devel] [PATCH] sheepdog: fix confused return values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: sheepdog@lists.wpkg.org, qemu-devel@nongnu.org, armbru@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 > > > > 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 > > Signed-off-by: Liu Yuan > > --- > > 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