From: Keir Fraser Date: Mon, 31 Mar 2008 09:35:35 +0000 (+0100) Subject: ioemu: actually check for errors in bdrv_flush et al X-Git-Tag: 3.3.0-rc1~246^2~16 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=28f2b557689f8310bebdff15b37f079bc3fb5d0a;p=xen.git ioemu: actually check for errors in bdrv_flush et al bdrv_flush is declared to return void, but this is wrong because it means that the implementations have nowhere to report their errors. Indeed, the implementations generally ignore errors. This patch corrects this by making it return int (implicitly, either 0 or -errno, as for other similar functions). All of the implementations and callers are adjusted too. Signed-off-by: Ian Jackson --- diff --git a/tools/ioemu/block-qcow.c b/tools/ioemu/block-qcow.c index e59b600f1d..d7dacc75be 100644 --- a/tools/ioemu/block-qcow.c +++ b/tools/ioemu/block-qcow.c @@ -934,10 +934,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/tools/ioemu/block-qcow2.c b/tools/ioemu/block-qcow2.c index ec64448a34..606716bdc1 100644 --- a/tools/ioemu/block-qcow2.c +++ b/tools/ioemu/block-qcow2.c @@ -1235,10 +1235,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/tools/ioemu/block-raw.c b/tools/ioemu/block-raw.c index 7584aa38a0..cbc049f64e 100644 --- a/tools/ioemu/block-raw.c +++ b/tools/ioemu/block-raw.c @@ -615,10 +615,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/tools/ioemu/block-vmdk.c b/tools/ioemu/block-vmdk.c index 0558977abc..a8b8a35153 100644 --- a/tools/ioemu/block-vmdk.c +++ b/tools/ioemu/block-vmdk.c @@ -734,10 +734,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/tools/ioemu/block.c b/tools/ioemu/block.c index 3e25ccb544..8a730bd754 100644 --- a/tools/ioemu/block.c +++ b/tools/ioemu/block.c @@ -889,12 +889,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; } void bdrv_info(void) @@ -1232,8 +1234,9 @@ static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb) static BlockDriverAIOCB *bdrv_aio_flush_em(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque) { - bdrv_flush(bs); - cb(opaque, 0); + int ret; + ret = bdrv_flush(bs); + cb(opaque, ret); return NULL; } diff --git a/tools/ioemu/block_int.h b/tools/ioemu/block_int.h index 6190d1c08e..8c0318e795 100644 --- a/tools/ioemu/block_int.h +++ b/tools/ioemu/block_int.h @@ -36,7 +36,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/tools/ioemu/hw/ide.c b/tools/ioemu/hw/ide.c index 0db6f2a6b3..cfe3e8a5b2 100644 --- a/tools/ioemu/hw/ide.c +++ b/tools/ioemu/hw/ide.c @@ -1786,6 +1786,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); diff --git a/tools/ioemu/hw/scsi-disk.c b/tools/ioemu/hw/scsi-disk.c index 9de1fe83a5..2ad204ba26 100644 --- a/tools/ioemu/hw/scsi-disk.c +++ b/tools/ioemu/hw/scsi-disk.c @@ -291,6 +291,7 @@ int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun) uint8_t command; uint8_t *outbuf; SCSIRequest *r; + int ret; command = buf[0]; r = scsi_find_request(s, tag); @@ -496,7 +497,12 @@ int32_t scsi_send_command(SCSIDevice *s, uint32_t tag, uint8_t *buf, int lun) break; case 0x35: DPRINTF("Syncronise 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: { diff --git a/tools/ioemu/vl.h b/tools/ioemu/vl.h index 79531bf783..c6b7368658 100644 --- a/tools/ioemu/vl.h +++ b/tools/ioemu/vl.h @@ -664,7 +664,7 @@ void qemu_aio_wait(void); void qemu_aio_wait_end(void); /* 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