|
@@ -22,14 +22,13 @@
|
|
|
* THE SOFTWARE.
|
|
|
*/
|
|
|
#include "qemu-common.h"
|
|
|
-#ifndef QEMU_IMG
|
|
|
#include "qemu-timer.h"
|
|
|
-#include "exec-all.h"
|
|
|
-#endif
|
|
|
#include "block_int.h"
|
|
|
#include <assert.h>
|
|
|
#include <winioctl.h>
|
|
|
|
|
|
+//#define WIN32_AIO
|
|
|
+
|
|
|
#define FTYPE_FILE 0
|
|
|
#define FTYPE_CD 1
|
|
|
#define FTYPE_HARDDISK 2
|
|
@@ -100,10 +99,10 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
|
|
} else {
|
|
|
create_flags = OPEN_EXISTING;
|
|
|
}
|
|
|
-#ifdef QEMU_IMG
|
|
|
- overlapped = FILE_ATTRIBUTE_NORMAL;
|
|
|
-#else
|
|
|
+#ifdef WIN32_AIO
|
|
|
overlapped = FILE_FLAG_OVERLAPPED;
|
|
|
+#else
|
|
|
+ overlapped = FILE_ATTRIBUTE_NORMAL;
|
|
|
#endif
|
|
|
if (flags & BDRV_O_DIRECT)
|
|
|
overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
|
|
@@ -133,10 +132,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
|
|
|
ov.OffsetHigh = offset >> 32;
|
|
|
ret = ReadFile(s->hfile, buf, count, &ret_count, &ov);
|
|
|
if (!ret) {
|
|
|
+#ifdef WIN32_AIO
|
|
|
ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
|
|
|
if (!ret)
|
|
|
return -EIO;
|
|
|
else
|
|
|
+#endif
|
|
|
return ret_count;
|
|
|
}
|
|
|
return ret_count;
|
|
@@ -155,17 +156,18 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
|
|
|
ov.OffsetHigh = offset >> 32;
|
|
|
ret = WriteFile(s->hfile, buf, count, &ret_count, &ov);
|
|
|
if (!ret) {
|
|
|
+#ifdef WIN32_AIO
|
|
|
ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
|
|
|
if (!ret)
|
|
|
return -EIO;
|
|
|
else
|
|
|
+#endif
|
|
|
return ret_count;
|
|
|
}
|
|
|
return ret_count;
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-#ifndef QEMU_IMG
|
|
|
+#ifdef WIN32_AIO
|
|
|
static void raw_aio_cb(void *opaque)
|
|
|
{
|
|
|
RawAIOCB *acb = opaque;
|
|
@@ -181,7 +183,6 @@ static void raw_aio_cb(void *opaque)
|
|
|
acb->common.cb(acb->common.opaque, 0);
|
|
|
}
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
static RawAIOCB *raw_aio_setup(BlockDriverState *bs,
|
|
|
int64_t sector_num, uint8_t *buf, int nb_sectors,
|
|
@@ -204,9 +205,7 @@ static RawAIOCB *raw_aio_setup(BlockDriverState *bs,
|
|
|
acb->ov.OffsetHigh = offset >> 32;
|
|
|
acb->ov.hEvent = acb->hEvent;
|
|
|
acb->count = nb_sectors * 512;
|
|
|
-#ifndef QEMU_IMG
|
|
|
qemu_add_wait_object(acb->ov.hEvent, raw_aio_cb, acb);
|
|
|
-#endif
|
|
|
return acb;
|
|
|
}
|
|
|
|
|
@@ -226,9 +225,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs,
|
|
|
qemu_aio_release(acb);
|
|
|
return NULL;
|
|
|
}
|
|
|
-#ifdef QEMU_IMG
|
|
|
qemu_aio_release(acb);
|
|
|
-#endif
|
|
|
return (BlockDriverAIOCB *)acb;
|
|
|
}
|
|
|
|
|
@@ -248,15 +245,12 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs,
|
|
|
qemu_aio_release(acb);
|
|
|
return NULL;
|
|
|
}
|
|
|
-#ifdef QEMU_IMG
|
|
|
qemu_aio_release(acb);
|
|
|
-#endif
|
|
|
return (BlockDriverAIOCB *)acb;
|
|
|
}
|
|
|
|
|
|
static void raw_aio_cancel(BlockDriverAIOCB *blockacb)
|
|
|
{
|
|
|
-#ifndef QEMU_IMG
|
|
|
RawAIOCB *acb = (RawAIOCB *)blockacb;
|
|
|
BlockDriverState *bs = acb->common.bs;
|
|
|
BDRVRawState *s = bs->opaque;
|
|
@@ -265,9 +259,8 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb)
|
|
|
/* XXX: if more than one async I/O it is not correct */
|
|
|
CancelIo(s->hfile);
|
|
|
qemu_aio_release(acb);
|
|
|
-#endif
|
|
|
}
|
|
|
-#endif /* #if 0 */
|
|
|
+#endif /* #if WIN32_AIO */
|
|
|
|
|
|
static void raw_flush(BlockDriverState *bs)
|
|
|
{
|
|
@@ -356,9 +349,7 @@ void qemu_aio_flush(void)
|
|
|
|
|
|
void qemu_aio_wait(void)
|
|
|
{
|
|
|
-#ifndef QEMU_IMG
|
|
|
qemu_bh_poll();
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
BlockDriver bdrv_raw = {
|
|
@@ -372,7 +363,7 @@ BlockDriver bdrv_raw = {
|
|
|
raw_create,
|
|
|
raw_flush,
|
|
|
|
|
|
-#if 0
|
|
|
+#ifdef WIN32_AIO
|
|
|
.bdrv_aio_read = raw_aio_read,
|
|
|
.bdrv_aio_write = raw_aio_write,
|
|
|
.bdrv_aio_cancel = raw_aio_cancel,
|
|
@@ -458,10 +449,10 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
|
|
}
|
|
|
create_flags = OPEN_EXISTING;
|
|
|
|
|
|
-#ifdef QEMU_IMG
|
|
|
- overlapped = FILE_ATTRIBUTE_NORMAL;
|
|
|
-#else
|
|
|
+#ifdef WIN32_AIO
|
|
|
overlapped = FILE_FLAG_OVERLAPPED;
|
|
|
+#else
|
|
|
+ overlapped = FILE_ATTRIBUTE_NORMAL;
|
|
|
#endif
|
|
|
if (flags & BDRV_O_DIRECT)
|
|
|
overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
|
|
@@ -524,7 +515,7 @@ BlockDriver bdrv_host_device = {
|
|
|
NULL,
|
|
|
raw_flush,
|
|
|
|
|
|
-#if 0
|
|
|
+#ifdef WIN32_AIO
|
|
|
.bdrv_aio_read = raw_aio_read,
|
|
|
.bdrv_aio_write = raw_aio_write,
|
|
|
.bdrv_aio_cancel = raw_aio_cancel,
|