From: Ian Jackson Date: Wed, 20 Feb 2008 15:54:23 +0000 (+0000) Subject: make bdrv_flush pay attention to errors X-Git-Tag: xen-3.3.0-rc1~247 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=adc804735154e1945e2d104ced2b40d6fc4dc07c;p=qemu-xen-3.4-testing.git make bdrv_flush pay attention to errors --- diff --git a/block-qcow.c b/block-qcow.c index cb207b2f..59f1c66c 100644 --- a/block-qcow.c +++ b/block-qcow.c @@ -883,10 +883,10 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static void qcow_flush(BlockDriverState *bs) +static int qcow_flush(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; - bdrv_flush(s->hd); + return bdrv_flush(s->hd); } static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) diff --git a/block-qcow2.c b/block-qcow2.c index 577210b2..9bad090c 100644 --- a/block-qcow2.c +++ b/block-qcow2.c @@ -1228,10 +1228,10 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, return 0; } -static void qcow_flush(BlockDriverState *bs) +static int qcow_flush(BlockDriverState *bs) { BDRVQcowState *s = bs->opaque; - bdrv_flush(s->hd); + return bdrv_flush(s->hd); } static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) diff --git a/block-raw-posix.c b/block-raw-posix.c index 28aaf02a..45d0a932 100644 --- a/block-raw-posix.c +++ b/block-raw-posix.c @@ -539,10 +539,12 @@ static int raw_create(const char *filename, int64_t total_size, return 0; } -static void raw_flush(BlockDriverState *bs) +static int raw_flush(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; - fsync(s->fd); + if (fsync(s->fd)) + return errno; + return 0; } BlockDriver bdrv_raw = { diff --git a/block-raw-win32.c b/block-raw-win32.c index 43d3f6c4..b86c66e9 100644 --- a/block-raw-win32.c +++ b/block-raw-win32.c @@ -269,10 +269,14 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb) } #endif /* #if 0 */ -static void raw_flush(BlockDriverState *bs) +static int raw_flush(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; - FlushFileBuffers(s->hfile); + int ret; + ret = FlushFileBuffers(s->hfile); + if (ret) + return -EIO; + return 0; } static void raw_close(BlockDriverState *bs) diff --git a/block-vmdk.c b/block-vmdk.c index b6ec89e8..4cacc6a6 100644 --- a/block-vmdk.c +++ b/block-vmdk.c @@ -815,10 +815,10 @@ static void vmdk_close(BlockDriverState *bs) vmdk_parent_close(s->hd); } -static void vmdk_flush(BlockDriverState *bs) +static int vmdk_flush(BlockDriverState *bs) { BDRVVmdkState *s = bs->opaque; - bdrv_flush(s->hd); + return bdrv_flush(s->hd); } BlockDriver bdrv_vmdk = { diff --git a/block.c b/block.c index 07309541..fc32a60c 100644 --- a/block.c +++ b/block.c @@ -869,12 +869,14 @@ const char *bdrv_get_device_name(BlockDriverState *bs) return bs->device_name; } -void bdrv_flush(BlockDriverState *bs) +int bdrv_flush(BlockDriverState *bs) { - if (bs->drv->bdrv_flush) - bs->drv->bdrv_flush(bs); - if (bs->backing_hd) - bdrv_flush(bs->backing_hd); + int ret = 0; + if (bs->drv->bdrv_flush) + ret = bs->drv->bdrv_flush(bs); + if (!ret && bs->backing_hd) + ret = bdrv_flush(bs->backing_hd); + return ret; } #ifndef QEMU_IMG diff --git a/block.h b/block.h index b7305055..861a65b1 100644 --- a/block.h +++ b/block.h @@ -98,7 +98,7 @@ void qemu_aio_wait_end(void); int qemu_key_check(BlockDriverState *bs, const char *name); /* Ensure contents are flushed to disk. */ -void bdrv_flush(BlockDriverState *bs); +int bdrv_flush(BlockDriverState *bs); #define BDRV_TYPE_HD 0 #define BDRV_TYPE_CDROM 1 diff --git a/block_int.h b/block_int.h index 137000e1..796ce294 100644 --- a/block_int.h +++ b/block_int.h @@ -42,7 +42,7 @@ struct BlockDriver { void (*bdrv_close)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, int64_t total_sectors, const char *backing_file, int flags); - void (*bdrv_flush)(BlockDriverState *bs); + int (*bdrv_flush)(BlockDriverState *bs); int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); int (*bdrv_set_key)(BlockDriverState *bs, const char *key); diff --git a/hw/ide.c b/hw/ide.c index 370a4124..56a1cda9 100644 --- a/hw/ide.c +++ b/hw/ide.c @@ -1895,6 +1895,7 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) IDEState *s; int unit, n; int lba48 = 0; + int ret; #ifdef DEBUG_IDE printf("IDE: write addr=0x%x val=0x%02x\n", addr, val); @@ -2140,8 +2141,10 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) break; case WIN_FLUSH_CACHE: case WIN_FLUSH_CACHE_EXT: - if (s->bs) - bdrv_flush(s->bs); + if (s->bs) { + ret = bdrv_flush(s->bs); + if (ret) goto abort_cmd; + } s->status = READY_STAT; ide_set_irq(s); break; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 44462d43..30cc9069 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -293,6 +293,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, uint8_t command; uint8_t *outbuf; SCSIRequest *r; + int ret; command = buf[0]; r = scsi_find_request(s, tag); @@ -620,7 +621,12 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, break; case 0x35: DPRINTF("Synchronise cache (sector %d, count %d)\n", lba, len); - bdrv_flush(s->bdrv); + ret = bdrv_flush(s->bdrv); + if (ret) { + DPRINTF("IO error on bdrv_flush\n"); + scsi_command_complete(r, SENSE_HARDWARE_ERROR); + return 0; + } break; case 0x43: {