Skip to content

Commit de7056a

Browse files
ebblakekevmw
authored andcommitted
file-win32: Switch to byte-based callbacks
We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based callbacks in the file-win32 driver. Note that the driver was already using byte-based calls for performing actual I/O, so this just gets rid of a round trip of scaling; however, as I don't know if Windows is tolerant of non-sector AIO operations, I went with the conservative approach of modifying .bdrv_refresh_limits to override the block layer defaults back to the pre-patch value of 512. Signed-off-by: Eric Blake <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent e31f686 commit de7056a

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

block/file-win32.c

+29-18
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ static void raw_probe_alignment(BlockDriverState *bs, Error **errp)
251251
&dg.Geometry.BytesPerSector,
252252
&freeClusters, &totalClusters);
253253
bs->bl.request_alignment = dg.Geometry.BytesPerSector;
254+
return;
254255
}
256+
257+
/* XXX Does Windows support AIO on less than 512-byte alignment? */
258+
bs->bl.request_alignment = 512;
255259
}
256260

257261
static void raw_parse_flags(int flags, bool use_aio, int *access_flags,
@@ -410,32 +414,32 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
410414
return ret;
411415
}
412416

413-
static BlockAIOCB *raw_aio_readv(BlockDriverState *bs,
414-
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
415-
BlockCompletionFunc *cb, void *opaque)
417+
static BlockAIOCB *raw_aio_preadv(BlockDriverState *bs,
418+
uint64_t offset, uint64_t bytes,
419+
QEMUIOVector *qiov, int flags,
420+
BlockCompletionFunc *cb, void *opaque)
416421
{
417422
BDRVRawState *s = bs->opaque;
418423
if (s->aio) {
419-
return win32_aio_submit(bs, s->aio, s->hfile, sector_num, qiov,
420-
nb_sectors, cb, opaque, QEMU_AIO_READ);
424+
return win32_aio_submit(bs, s->aio, s->hfile, offset, bytes, qiov,
425+
cb, opaque, QEMU_AIO_READ);
421426
} else {
422-
return paio_submit(bs, s->hfile, sector_num << BDRV_SECTOR_BITS, qiov,
423-
nb_sectors << BDRV_SECTOR_BITS,
427+
return paio_submit(bs, s->hfile, offset, qiov, bytes,
424428
cb, opaque, QEMU_AIO_READ);
425429
}
426430
}
427431

428-
static BlockAIOCB *raw_aio_writev(BlockDriverState *bs,
429-
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
430-
BlockCompletionFunc *cb, void *opaque)
432+
static BlockAIOCB *raw_aio_pwritev(BlockDriverState *bs,
433+
uint64_t offset, uint64_t bytes,
434+
QEMUIOVector *qiov, int flags,
435+
BlockCompletionFunc *cb, void *opaque)
431436
{
432437
BDRVRawState *s = bs->opaque;
433438
if (s->aio) {
434-
return win32_aio_submit(bs, s->aio, s->hfile, sector_num, qiov,
435-
nb_sectors, cb, opaque, QEMU_AIO_WRITE);
439+
return win32_aio_submit(bs, s->aio, s->hfile, offset, bytes, qiov,
440+
cb, opaque, QEMU_AIO_WRITE);
436441
} else {
437-
return paio_submit(bs, s->hfile, sector_num << BDRV_SECTOR_BITS, qiov,
438-
nb_sectors << BDRV_SECTOR_BITS,
442+
return paio_submit(bs, s->hfile, offset, qiov, bytes,
439443
cb, opaque, QEMU_AIO_WRITE);
440444
}
441445
}
@@ -632,8 +636,8 @@ BlockDriver bdrv_file = {
632636
.bdrv_co_create_opts = raw_co_create_opts,
633637
.bdrv_has_zero_init = bdrv_has_zero_init_1,
634638

635-
.bdrv_aio_readv = raw_aio_readv,
636-
.bdrv_aio_writev = raw_aio_writev,
639+
.bdrv_aio_preadv = raw_aio_preadv,
640+
.bdrv_aio_pwritev = raw_aio_pwritev,
637641
.bdrv_aio_flush = raw_aio_flush,
638642

639643
.bdrv_truncate = raw_truncate,
@@ -708,6 +712,12 @@ static void hdev_parse_filename(const char *filename, QDict *options,
708712
bdrv_parse_filename_strip_prefix(filename, "host_device:", options);
709713
}
710714

715+
static void hdev_refresh_limits(BlockDriverState *bs, Error **errp)
716+
{
717+
/* XXX Does Windows support AIO on less than 512-byte alignment? */
718+
bs->bl.request_alignment = 512;
719+
}
720+
711721
static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
712722
Error **errp)
713723
{
@@ -793,9 +803,10 @@ static BlockDriver bdrv_host_device = {
793803
.bdrv_probe_device = hdev_probe_device,
794804
.bdrv_file_open = hdev_open,
795805
.bdrv_close = raw_close,
806+
.bdrv_refresh_limits = hdev_refresh_limits,
796807

797-
.bdrv_aio_readv = raw_aio_readv,
798-
.bdrv_aio_writev = raw_aio_writev,
808+
.bdrv_aio_preadv = raw_aio_preadv,
809+
.bdrv_aio_pwritev = raw_aio_pwritev,
799810
.bdrv_aio_flush = raw_aio_flush,
800811

801812
.bdrv_detach_aio_context = raw_detach_aio_context,

block/win32-aio.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,14 @@ static const AIOCBInfo win32_aiocb_info = {
112112

113113
BlockAIOCB *win32_aio_submit(BlockDriverState *bs,
114114
QEMUWin32AIOState *aio, HANDLE hfile,
115-
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
115+
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov,
116116
BlockCompletionFunc *cb, void *opaque, int type)
117117
{
118118
struct QEMUWin32AIOCB *waiocb;
119-
uint64_t offset = sector_num * 512;
120119
DWORD rc;
121120

122121
waiocb = qemu_aio_get(&win32_aiocb_info, bs, cb, opaque);
123-
waiocb->nbytes = nb_sectors * 512;
122+
waiocb->nbytes = bytes;
124123
waiocb->qiov = qiov;
125124
waiocb->is_read = (type == QEMU_AIO_READ);
126125

include/block/raw-aio.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void win32_aio_cleanup(QEMUWin32AIOState *aio);
5757
int win32_aio_attach(QEMUWin32AIOState *aio, HANDLE hfile);
5858
BlockAIOCB *win32_aio_submit(BlockDriverState *bs,
5959
QEMUWin32AIOState *aio, HANDLE hfile,
60-
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
60+
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov,
6161
BlockCompletionFunc *cb, void *opaque, int type);
6262
void win32_aio_detach_aio_context(QEMUWin32AIOState *aio,
6363
AioContext *old_context);

0 commit comments

Comments
 (0)