From: "Guangmu Zhu" <guangmuzhu@gmail.com>
To: "Kevin Wolf" <kwolf@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH] handle_aiocb_rw() can't distinguish between an error and 0 bytes transferred
Date: Sat, 26 Sep 2015 07:35:36 +0800 [thread overview]
Message-ID: <tencent_19E2352B6E37669F402564FA@qq.com> (raw)
[-- 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 --]
next reply other threads:[~2015-09-25 23:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-25 23:35 Guangmu Zhu [this message]
2015-09-26 1:54 ` [Qemu-devel] [PATCH] handle_aiocb_rw() can't distinguish between an error and 0 bytes transferred 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
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=tencent_19E2352B6E37669F402564FA@qq.com \
--to=guangmuzhu@gmail.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.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).