qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] handle_aiocb_rw() can't distinguish between an error and 0 bytes transferred
@ 2015-09-25 23:35 Guangmu Zhu
  2015-09-26  1:54 ` Guangmu Zhu
  0 siblings, 1 reply; 4+ messages in thread
From: Guangmu Zhu @ 2015-09-25 23:35 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

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

The handle_aiocb_rw() can't distinguish between an error and 0 bytes transferred.


diff --git a/block/raw-win32.c b/block/raw-win32.c
index 68f2338..569dda2 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -60,11 +60,13 @@ typedef struct BDRVRawState {
  * Returns the number of bytes handles or -errno in case of an error. Short
  * reads are only returned if the end of the file is reached.
  */
-static size_t handle_aiocb_rw(RawWin32AIOData *aiocb)
+static size_t handle_aiocb_rw(RawWin32AIOData *aiocb, BOOL *err)
 {
     size_t offset = 0;
     int i;
 
+    *err = FALSE;
+
     for (i = 0; i < aiocb->aio_niov; i++) {
         OVERLAPPED ov;
         DWORD ret, ret_count, len;
@@ -81,7 +83,8 @@ static size_t handle_aiocb_rw(RawWin32AIOData *aiocb)
                            len, &ret_count, &ov);
         }
         if (!ret) {
-            ret_count = 0;
+            *err = TRUE;
+            break;
         }
         if (ret_count != len) {
             offset += ret_count;
@@ -98,30 +101,39 @@ static int aio_worker(void *arg)
     RawWin32AIOData *aiocb = arg;
     ssize_t ret = 0;
     size_t count;
+    BOOL err = FALSE;
 
     switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) {
     case QEMU_AIO_READ:
-        count = handle_aiocb_rw(aiocb);
-        if (count < aiocb->aio_nbytes) {
-            /* A short read means that we have reached EOF. Pad the buffer
-             * with zeros for bytes after EOF. */
-            iov_memset(aiocb->aio_iov, aiocb->aio_niov, count,
-                      0, aiocb->aio_nbytes - count);
-
-            count = aiocb->aio_nbytes;
-        }
-        if (count == aiocb->aio_nbytes) {
-            ret = 0;
-        } else {
+        count = handle_aiocb_rw(aiocb, &err);
+        if (err) {
             ret = -EINVAL;
+        } else {
+            if (count < aiocb->aio_nbytes) {
+                /* A short read means that we have reached EOF. Pad the buffer
+                 * with zeros for bytes after EOF. */
+                iov_memset(aiocb->aio_iov, aiocb->aio_niov, count,
+                          0, aiocb->aio_nbytes - count);
+
+                count = aiocb->aio_nbytes;
+            }
+            if (count == aiocb->aio_nbytes) {
+                ret = 0;
+            } else {
+                ret = -EINVAL;
+            }
         }
         break;
     case QEMU_AIO_WRITE:
-        count = handle_aiocb_rw(aiocb);
-        if (count == aiocb->aio_nbytes) {
-            count = 0;
+        count = handle_aiocb_rw(aiocb, &err);
+        if (err) {
+            ret = -EINVAL;
         } else {
-            count = -EINVAL;
+            if (count == aiocb->aio_nbytes) {
+                count = 0;
+            } else {
+                count = -EINVAL;
+            }
         }
         break;
     case QEMU_AIO_FLUSH:

[-- Attachment #2: Type: text/html, Size: 5852 bytes --]

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

end of thread, other threads:[~2015-09-30  1:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-25 23:35 [Qemu-devel] [PATCH] handle_aiocb_rw() can't distinguish between an error and 0 bytes transferred Guangmu Zhu
2015-09-26  1:54 ` Guangmu Zhu
2015-09-29 12:00   ` Kevin Wolf
2015-09-30  1:42     ` [Qemu-devel] [PATCH] handle_aiocb_rw() can't distinguish betweenan " Guangmu Zhu

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