Skip to contentSkip to conversation

sheepdog: fix confused return values

PATCH Applied Liu Yuan 2 participants 3 messages Feb 18, 2015 – Feb 27, 2015 Block layer

lore
Share & tools
lore

Liu Yuan

author
#0 lore raw

PATCH v2 1/1 sheepdog: fix confused return values

From: Liu Yuan <[email protected]>

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.

---
v2:
- use socket_error() instead of errno

 block/sheepdog.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
block/sheepdog.c +11 -0
index be3176f..e4b30ba 100644
@@ -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)
 {
Signature · 1 line
1.9.1
author
#1 lore raw
Quoted 76 lines · Liu Yuan

From: Liu Yuan <[email protected]>

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.

---
v2:
- use socket_error() instead of errno

 block/sheepdog.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
block/sheepdog.c +11 -0
index be3176f..e4b30ba 100644
@@ -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)
 {
Signature · 1 line
1.9.1

Ping...

#2 lore raw
In reply to Liu Yuan
Quoted 13 lines · Liu Yuan

From: Liu Yuan <[email protected]>

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.

Quoted 6 lines

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