qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] sheepdog: fix confused return values
@ 2015-02-18  3:57 Liu Yuan
  2015-02-27  2:13 ` Liu Yuan
  2015-02-27 11:29 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: Liu Yuan @ 2015-02-18  3:57 UTC (permalink / raw)
  To: sheepdog; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi, Markus Armbruster

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.

Cc: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
---
v2:
 - use socket_error() instead of errno

 block/sheepdog.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index be3176f..e4b30ba 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 = -socket_error();
         return ret;
     }
 
     ret = qemu_co_send(sockfd, data, *wlen);
     if (ret != *wlen) {
+        ret = -socket_error();
         error_report("failed to send a req, %s", strerror(errno));
     }
 
@@ -638,6 +644,11 @@ out:
     srco->finished = true;
 }
 
+/*
+ * Send the request to the sheep in a synchronous manner.
+ *
+ * Return 0 on success, -errno in case of error.
+ */
 static int do_req(int sockfd, AioContext *aio_context, SheepdogReq *hdr,
                   void *data, unsigned int *wlen, unsigned int *rlen)
 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] sheepdog: fix confused return values
  2015-02-18  3:57 [Qemu-devel] [PATCH v2] sheepdog: fix confused return values Liu Yuan
@ 2015-02-27  2:13 ` Liu Yuan
  2015-02-27 11:29 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Liu Yuan @ 2015-02-27  2:13 UTC (permalink / raw)
  To: sheepdog; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi, Markus Armbruster

On Wed, Feb 18, 2015 at 11:57:55AM +0800, Liu Yuan wrote:
> 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.
> 
> Cc: qemu-devel@nongnu.org
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
> ---
> v2:
>  - use socket_error() instead of errno
> 
>  block/sheepdog.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index be3176f..e4b30ba 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 = -socket_error();
>          return ret;
>      }
>  
>      ret = qemu_co_send(sockfd, data, *wlen);
>      if (ret != *wlen) {
> +        ret = -socket_error();
>          error_report("failed to send a req, %s", strerror(errno));
>      }
>  
> @@ -638,6 +644,11 @@ out:
>      srco->finished = true;
>  }
>  
> +/*
> + * Send the request to the sheep in a synchronous manner.
> + *
> + * Return 0 on success, -errno in case of error.
> + */
>  static int do_req(int sockfd, AioContext *aio_context, SheepdogReq *hdr,
>                    void *data, unsigned int *wlen, unsigned int *rlen)
>  {
> -- 
> 1.9.1
> 

Ping...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] sheepdog: fix confused return values
  2015-02-18  3:57 [Qemu-devel] [PATCH v2] sheepdog: fix confused return values Liu Yuan
  2015-02-27  2:13 ` Liu Yuan
@ 2015-02-27 11:29 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2015-02-27 11:29 UTC (permalink / raw)
  To: Liu Yuan
  Cc: Kevin Wolf, sheepdog, qemu-devel, Stefan Hajnoczi,
	Markus Armbruster

[-- Attachment #1: Type: text/plain, Size: 802 bytes --]

On Wed, Feb 18, 2015 at 11:57:55AM +0800, Liu Yuan wrote:
> 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.
> 
> Cc: qemu-devel@nongnu.org
> Cc: Markus Armbruster <armbru@redhat.com>
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
> ---
> v2:
>  - use socket_error() instead of errno
> 
>  block/sheepdog.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-27 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-18  3:57 [Qemu-devel] [PATCH v2] sheepdog: fix confused return values Liu Yuan
2015-02-27  2:13 ` Liu Yuan
2015-02-27 11:29 ` Stefan Hajnoczi

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).