actually check for errors in bdrv_flush et al
PATCH 1/1 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 <[email protected]>
tools/ioemu/block-qcow.c +4 -4
@@ -934,10 +934,10 @@ static int qcow_write_compressed(BlockDrreturn 0 ; } -static void qcow_flush (BlockDriverState *bs) -{ -BDRVQcowState *s = bs->opaque; -bdrv_flush (s->hd); +static int qcow_flush (BlockDriverState *bs) +{ +BDRVQcowState *s = bs->opaque; +return bdrv_flush (s->hd); }static int qcow_get_info (BlockDriverState *bs,BlockDriverInfo *bdi)
tools/ioemu/block-qcow2.c +4 -4
@@ -1235,10 +1235,10 @@ static int qcow_write_compressed(BlockDrreturn 0 ; } -static void qcow_flush (BlockDriverState *bs) -{ -BDRVQcowState *s = bs->opaque; -bdrv_flush (s->hd); +static int qcow_flush (BlockDriverState *bs) +{ +BDRVQcowState *s = bs->opaque; +return bdrv_flush (s->hd); }static int qcow_get_info (BlockDriverState *bs,BlockDriverInfo *bdi)
tools/ioemu/block-raw.c +6 -4
@@ -615,10 +615,12 @@ static int raw_create(const char *filenareturn 0 ; } -static void raw_flush (BlockDriverState *bs) -{ -BDRVRawState *s = bs->opaque; -fsync (s->fd); +static int raw_flush (BlockDriverState *bs) +{ +BDRVRawState *s = bs->opaque; +if (fsync (s->fd)) +return errno; +return 0 ; }BlockDriver bdrv_raw = {
tools/ioemu/block-vmdk.c +4 -4
@@ -734,10 +734,10 @@ static void vmdk_close(BlockDriverStatevmdk_parent_close (s->hd); } -static void vmdk_flush (BlockDriverState *bs) -{ -BDRVVmdkState *s = bs->opaque; -bdrv_flush (s->hd); +static int vmdk_flush (BlockDriverState *bs) +{ +BDRVVmdkState *s = bs->opaque; +return bdrv_flush (s->hd); }BlockDriver bdrv_vmdk = {
tools/ioemu/block.c +11 -8
@@ -889,12 +889,14 @@ const char *bdrv_get_device_name(BlockDrreturn bs->device_name; } -void bdrv_flush (BlockDriverState *bs) -{ -if (bs->drv->bdrv_flush) - bs->drv->bdrv_flush (bs); -if (bs->backing_hd) -bdrv_flush (bs->backing_hd); +int bdrv_flush (BlockDriverState *bs) +{ +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 BlockDriverAIOCB *bdrv_aio_flush_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 ; }
tools/ioemu/block_int.h +1 -1
@@ -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);
tools/ioemu/hw/ide.c +1 -0
@@ -1786,6 +1786,7 @@ static void ide_ioport_write(void *opaquIDEState *s;int unit, n;int lba48 =0 ; +int ret;#ifdef DEBUG_IDE printf ("IDE: write addr=0x%x val=0x%02x\n" , addr, val);
tools/ioemu/hw/scsi-disk.c +7 -1
@@ -291,6 +291,7 @@ int32_t scsi_send_command(SCSIDevice *s,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,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 : {
tools/ioemu/vl.h +1 -1
@@ -664,7 +664,7 @@ void qemu_aio_wait_end(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
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel