# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1206956135 -3600
# Node ID d8fc3b73fb76147d391f6664f31b0ec626beadd3
# Parent 6736c28a0d35cf4d25e2e93a98c1443e809f2c50
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 <ian.jackson@xxxxxxxxxxxxx>
---
tools/ioemu/block-qcow.c | 8 ++++----
tools/ioemu/block-qcow2.c | 8 ++++----
tools/ioemu/block-raw.c | 10 ++++++----
tools/ioemu/block-vmdk.c | 8 ++++----
tools/ioemu/block.c | 19 +++++++++++--------
tools/ioemu/block_int.h | 2 +-
tools/ioemu/hw/ide.c | 1 +
tools/ioemu/hw/scsi-disk.c | 8 +++++++-
tools/ioemu/vl.h | 2 +-
9 files changed, 39 insertions(+), 27 deletions(-)
diff -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/block-qcow.c
--- a/tools/ioemu/block-qcow.c Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/block-qcow.c Mon Mar 31 10:35:35 2008 +0100
@@ -934,10 +934,10 @@ static int qcow_write_compressed(BlockDr
return 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)
diff -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/block-qcow2.c
--- a/tools/ioemu/block-qcow2.c Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/block-qcow2.c Mon Mar 31 10:35:35 2008 +0100
@@ -1235,10 +1235,10 @@ static int qcow_write_compressed(BlockDr
return 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)
diff -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/block-raw.c
--- a/tools/ioemu/block-raw.c Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/block-raw.c Mon Mar 31 10:35:35 2008 +0100
@@ -615,10 +615,12 @@ static int raw_create(const char *filena
return 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 = {
diff -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/block-vmdk.c
--- a/tools/ioemu/block-vmdk.c Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/block-vmdk.c Mon Mar 31 10:35:35 2008 +0100
@@ -734,10 +734,10 @@ static void vmdk_close(BlockDriverState
vmdk_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 = {
diff -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/block.c
--- a/tools/ioemu/block.c Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/block.c Mon Mar 31 10:35:35 2008 +0100
@@ -889,12 +889,14 @@ const char *bdrv_get_device_name(BlockDr
return 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;
}
diff -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/block_int.h
--- a/tools/ioemu/block_int.h Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/block_int.h Mon Mar 31 10:35:35 2008 +0100
@@ -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 -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/hw/ide.c
--- a/tools/ioemu/hw/ide.c Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/hw/ide.c Mon Mar 31 10:35:35 2008 +0100
@@ -1786,6 +1786,7 @@ static void ide_ioport_write(void *opaqu
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 -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/hw/scsi-disk.c
--- a/tools/ioemu/hw/scsi-disk.c Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/hw/scsi-disk.c Mon Mar 31 10:35:35 2008 +0100
@@ -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:
{
diff -r 6736c28a0d35 -r d8fc3b73fb76 tools/ioemu/vl.h
--- a/tools/ioemu/vl.h Fri Mar 28 17:58:36 2008 +0000
+++ b/tools/ioemu/vl.h Mon Mar 31 10:35:35 2008 +0100
@@ -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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|