Perform emulated IDE flushes asynchronously.
PATCH 1/1 Perform emulated IDE flushes asynchronously.
Presently, a guest may be blocked while bdrv_flush completes if it uses the IDE FLUSH_CACHE command. With this patch, it may continue executing while the cache completes.
This avoids a problem detected in a Xen installation where Windows does a flush and blocks for long enough that it loses a substantial amount of wall clock time - enough for it to fail.
This patch introduces a new bdrv_aio_flush method and implementations in the relevant drivers, and uses it for the IDE flush cache operation.
Ian.
Quoted 1 line
From
59b4a4d1c2ab84c560576861e2a817bdfdd686fdMon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Fri, 28 Mar 2008 16:54:09 +0000
Subject: [PATCH] Perform emulated IDE flushes asynchronously.
We arrange for the WIN_FLUSH_CACHE and WIN_FLUSH_CACHE_EXT commands to use a new bdrv_aio_flush facility.
If there is an error, the ATA-7 spec says that we are supposed to know which is the first block whose flush failed and leave that in the block offset registers. However since we are using f(data)sync that's not possible for us. There is sadly no way for us to report the error which won't encourage the guest to try to understand what went wrong and then do the flush again expecting the remaining blocks to be written (as specified by ATA-7).
So if the asynchronous flush fails, we kill the disk by detaching ->bs. This makes it vanish: we don't generate any more interrupts, leave status set to busy, and ignore future commands (and discard any in-flight IO). Alan Cox reports that this will probably induce the best available behaviour in guests (retry for a while and then give up). Fine-grained error reporting is available if the guest turns off the write cache.
--- block-qcow.c | 8 +++++++ block-qcow2.c | 8 +++++++ block-raw-posix.c | 16 +++++++++++++++ block.c | 39 ++++++++++++++++++++++++++++++++++++++ block.h | 2 + block_int.h | 2 + hw/ide.c | 54 +++++++++++++++++++++++++++++++++++++++++++++------- 7 files changed, 121 insertions(+), 8 deletions(-)
block-qcow.c +8 -0
@@ -725,6 +725,13 @@ static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)qemu_aio_release (acb); } +static BlockDriverAIOCB *qcow_aio_flush (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque) +{ +BDRVQcowState *s = bs->opaque; +return bdrv_aio_flush (s->hd, cb, opaque); +} +static void qcow_close (BlockDriverState *bs) {BDRVQcowState *s = bs->opaque;
@@ -913,6 +920,7 @@ BlockDriver bdrv_qcow = { .bdrv_aio_read = qcow_aio_read, .bdrv_aio_write = qcow_aio_write, .bdrv_aio_cancel = qcow_aio_cancel, + .bdrv_aio_flush = qcow_aio_flush, .aiocb_size = sizeof(QCowAIOCB), .bdrv_write_compressed = qcow_write_compressed, .bdrv_get_info = qcow_get_info,
block-qcow2.c +8 -0
@@ -1007,6 +1007,13 @@ static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)qemu_aio_release (acb); } +static BlockDriverAIOCB *qcow_aio_flush (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque) +{ +BDRVQcowState *s = bs->opaque; +return bdrv_aio_flush (s->hd, cb, opaque); +} +static void qcow_close (BlockDriverState *bs) {BDRVQcowState *s = bs->opaque;
@@ -2241,6 +2248,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_aio_read = qcow_aio_read, .bdrv_aio_write = qcow_aio_write, .bdrv_aio_cancel = qcow_aio_cancel, + .bdrv_aio_flush = qcow_aio_flush, .aiocb_size = sizeof(QCowAIOCB), .bdrv_write_compressed = qcow_write_compressed,
block-raw-posix.c +16 -0
@@ -762,6 +762,21 @@ static int fd_open(BlockDriverState *bs) {return 0 ; } + +static BlockDriverAIOCB *raw_aio_flush (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque) +{ +RawAIOCB *acb; + + acb =raw_aio_setup (bs,0 ,NULL ,0 , cb, opaque); +if (!acb) +return NULL ; +if (aio_fsync (O_SYNC , &acb->aiocb) <0 ) { +qemu_aio_release (acb); +return NULL ; + } +return &acb->common; +}#endif #if defined(__linux__)
@@ -913,6 +928,7 @@ BlockDriver bdrv_host_device = { .bdrv_aio_read = raw_aio_read, .bdrv_aio_write = raw_aio_write, .bdrv_aio_cancel = raw_aio_cancel, + .bdrv_aio_flush = raw_aio_flush, .aiocb_size = sizeof(RawAIOCB), .bdrv_pread = raw_pread, .bdrv_pwrite = raw_pwrite,
block.c +39 -0
@@ -50,6 +50,8 @@ static BlockDriverAIOCB *bdrv_aio_read_em(BlockDriverState *bs,static BlockDriverAIOCB *bdrv_aio_write_em (BlockDriverState *bs,int64_t sector_num,const uint8_t *buf,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque); +static BlockDriverAIOCB *bdrv_aio_flush_em (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque);static void bdrv_aio_cancel_em (BlockDriverAIOCB *acb);static int bdrv_read_em (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors);
@@ -137,6 +139,8 @@ static void bdrv_register(BlockDriver *bdrv) bdrv->bdrv_read = bdrv_read_em; bdrv->bdrv_write = bdrv_write_em; } +if (!bdrv->bdrv_aio_flush) + bdrv->bdrv_aio_flush = bdrv_aio_flush_em; bdrv->next = first_drv; first_drv = bdrv; }
@@ -1156,6 +1160,17 @@ void bdrv_aio_cancel(BlockDriverAIOCB *acb) drv->bdrv_aio_cancel (acb); } +BlockDriverAIOCB *bdrv_aio_flush (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque) +{ +BlockDriver *drv = bs->drv; + +if (!drv) +return NULL ; + +return drv->bdrv_aio_flush (bs, cb, opaque); +} +/**************************************************************/ /* async block device emulation */
@@ -1181,6 +1196,15 @@ static BlockDriverAIOCB *bdrv_aio_write_em(BlockDriverState *bs,return NULL ; } +static BlockDriverAIOCB *bdrv_aio_flush_em (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque) +{ +int ret; + ret =bdrv_flush (bs); +cb (opaque, ret); +return NULL ; +} +static void bdrv_aio_cancel_em (BlockDriverAIOCB *acb) { }
@@ -1224,6 +1248,21 @@ static BlockDriverAIOCB *bdrv_aio_write_em(BlockDriverState *bs,return &acb->common; } +static BlockDriverAIOCB *bdrv_aio_flush_em (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque) +{ +BlockDriverAIOCBSync *acb; +int ret; + + acb =qemu_aio_get (bs, cb, opaque); +if (!acb->bh) + acb->bh =qemu_bh_new (bdrv_aio_bh_cb, acb); + ret =bdrv_flush (bs); + acb->ret = ret; +qemu_bh_schedule (acb->bh); +return &acb->common; +} +static void bdrv_aio_cancel_em (BlockDriverAIOCB *blockacb) {BlockDriverAIOCBSync *acb = (BlockDriverAIOCBSync *)blockacb;
block.h +2 -0
@@ -86,6 +86,8 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,BlockDriverAIOCB *bdrv_aio_write (BlockDriverState *bs,int64_t sector_num,const uint8_t *buf,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque); +BlockDriverAIOCB *bdrv_aio_flush (BlockDriverState *bs, +BlockDriverCompletionFunc *cb,void *opaque);void bdrv_aio_cancel (BlockDriverAIOCB *acb);void qemu_aio_init (void );
block_int.h +2 -0
@@ -55,6 +55,8 @@ struct BlockDriver { int64_t sector_num, const uint8_t *buf, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque);void (*bdrv_aio_cancel)(BlockDriverAIOCB *acb); + BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque);int aiocb_size;const char *protocol_name;
hw/ide.c +46 -8
102 lines not on this page · raw message
Signature · 1 line
1.4.4.4