]> xenbits.xensource.com Git - qemu-xen-4.1-testing.git/commitdiff
make bdrv_flush pay attention to errors
authorIan Jackson <iwj@mariner.uk.xensource.com>
Wed, 20 Feb 2008 15:54:23 +0000 (15:54 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 12 May 2008 11:16:23 +0000 (12:16 +0100)
block-qcow.c
block-qcow2.c
block-raw-posix.c
block-raw-win32.c
block-vmdk.c
block.c
block.h
block_int.h
hw/ide.c
hw/scsi-disk.c

index cb207b2fbc8778a03c7213e3754b390a4ddfe6c0..59f1c66c56e9aee4b918a37bea135b8b8ededaa0 100644 (file)
@@ -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)
index 577210b21acb6248443c88c1ad24141f83dcf3a9..9bad090c4555de95b0cc35a29e399d83ad8db5b6 100644 (file)
@@ -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)
index 28aaf02a62dad4e8e713e566da162351a042a368..45d0a932c813e7988b7559e90d8e5823b62f05e3 100644 (file)
@@ -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 = {
index 43d3f6c4c216d6eb2f7286bbc74acc96d35decd7..b86c66e9f2df8b5191b07d7a7fa35700a3db6374 100644 (file)
@@ -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)
index b6ec89e8fb137621c0a03085f9002f2f61bc85bc..4cacc6a6ab771bda794bee42ee1af4abc0c05aba 100644 (file)
@@ -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 07309541f319c3c4399bfededc3053904ed6640d..fc32a60c6e2ee41688a94a336360cc7451d8269a 100644 (file)
--- 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 b73050556abe3761c68e852d9bf425ba8e977de9..861a65b18036d51330ef77b4e4cb355fc16f91af 100644 (file)
--- 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
index 137000e14075fb2b1b2d55739a8a83a27c510e22..796ce294ff9732eeef0d8dfb55096901ec5875c8 100644 (file)
@@ -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);
index 370a412414740d60378cd020c274c887b73b933b..56a1cda92e55cc99be4878f290903922239c7275 100644 (file)
--- 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;
index 44462d43519f0858f21663c4dab309f3925b798b..30cc9069a12b00d78990007ac2f06d86313e8d37 100644 (file)
@@ -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:
         {