From: Ian Jackson <ian.jackson@eu.citrix.com>
To: qemu-devel@nongnu.org
Cc: ian.jackson@eu.citrix.com
Subject: [Qemu-devel] [PATCH 1/3] make bdrv_flush pay attention to errors
Date: Mon, 1 Sep 2008 18:07:36 +0100 [thread overview]
Message-ID: <f1d87cbb33d2f525ef867d7de5b2f07896bd1786.1220371069.git.Ian.Jackson@eu.citrix.com> (raw)
In-Reply-To: <18621.25198.92678.705526@mariner.uk.xensource.com>
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 <Ian.Jackson@eu.citrix.com>
---
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
next prev parent reply other threads:[~2008-09-02 15:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-02 15:57 [Qemu-devel] [REPOST] [PATCH 0/3] IDE write cache Ian Jackson
2008-09-01 17:07 ` Ian Jackson [this message]
2008-09-01 17:18 ` [Qemu-devel] [PATCH 2/3] Perform emulated IDE flushes asynchronously Ian Jackson
2008-09-02 14:51 ` [Qemu-devel] [PATCH 3/3] make write cacheing controllable by guest Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f1d87cbb33d2f525ef867d7de5b2f07896bd1786.1220371069.git.Ian.Jackson@eu.citrix.com \
--to=ian.jackson@eu.citrix.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).