qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/3] make bdrv_flush pay attention to errors


From: Ian Jackson
Subject: [Qemu-devel] [PATCH 1/3] make bdrv_flush pay attention to errors
Date: Mon, 1 Sep 2008 18:07:36 +0100

We change bdrv_flush, and all of its implementations in the block
backends, to return int rather than void.  This enables the IDE and
SCSI controllers to report errors from FLUSH CACHE commands.

Cherry picked from qemu-xen adc804735154e1945e2d104ced2b40d6fc4dc07c.
Conflicts:
        block.h
        hw/ide.c

Signed-off-by: Ian Jackson <address@hidden>
---
 block-qcow.c      |    4 ++--
 block-qcow2.c     |    4 ++--
 block-raw-posix.c |    6 ++++--
 block-raw-win32.c |    8 ++++++--
 block-vmdk.c      |    4 ++--
 block.c           |   12 +++++++-----
 block.h           |    2 +-
 block_int.h       |    2 +-
 hw/ide.c          |    7 +++++--
 hw/scsi-disk.c    |    8 +++++++-
 10 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/block-qcow.c b/block-qcow.c
index 1fecf30..b5bfce6 100644
--- a/block-qcow.c
+++ b/block-qcow.c
@@ -868,10 +868,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 b9f1688..07c64ce 100644
--- a/block-qcow2.c
+++ b/block-qcow2.c
@@ -1600,10 +1600,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 96edab4..5fdd6e9 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -837,10 +837,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 43d3f6c..b86c66e 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 e85bd42..7f9a9a8 100644
--- a/block-vmdk.c
+++ b/block-vmdk.c
@@ -813,10 +813,10 @@ static void vmdk_close(BlockDriverState *bs)
     bdrv_delete(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 db8244c..e5aa401 100644
--- a/block.c
+++ b/block.c
@@ -875,12 +875,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;
 }
 
 /*
diff --git a/block.h b/block.h
index fa741b5..510818b 100644
--- a/block.h
+++ b/block.h
@@ -99,7 +99,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);
 int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
        int *pnum);
 
diff --git a/block_int.h b/block_int.h
index 137000e..796ce29 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 fd3a055..6b73f41 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -2014,6 +2014,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);
@@ -2276,8 +2277,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 | SEEK_STAT;
             ide_set_irq(s);
             break;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 16b3215..8c40cbf 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);
@@ -689,7 +690,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:
         {
-- 
1.4.4.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]