* [PATCH] QEMU report I/O errors to guest via IDE status registers
@ 2006-12-03 23:28 Daniel P. Berrange
0 siblings, 0 replies; only message in thread
From: Daniel P. Berrange @ 2006-12-03 23:28 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 1704 bytes --]
Following on from my patch to make blktap report I/O errors back to guest
OS[1], a similar problem exists in the QEMU codebase. The IDE driver never
reports I/O errors during read/write operations back to the guest OS.
Instead all I/O operations are reported as succesfull. If, for example,
the host FS holding the disk image fills up, then writes may fail due to
lack of space. Since the guest OS never sees these failures, it assumes
all is well & will continue writing. Eventually this can lead to severe
& unrecoverable filesystem corruption.
The attached patch fixes QEMU ide driver such that any failure of a read
or write operation sets the appropriate IDE status/error registers. Having
read the ATA-6 spec I think the most compliant behaviour is to set the
status register to 'READY_STAT | ERR_STAT', and the error register to
ABRT_ERR. There is already a convenience function ide_abort_command() in
the QEMU codebase which does just this, so the attached patch simply calls
that function.
With this patch the guest OS sees the I/O failure & the kernel logs
IDE errors and then retries the operation. This at least ensures that
the guest can be shutdown the out of space issue in the host corrected
and the guest restarted, without any serious filesystem damage having
occurred.
Regards,
Dan.
[1] http://lists.xensource.com/archives/html/xen-devel/2006-12/msg00029.html
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
[-- Attachment #2: xen-qemu-ide-error-handling-2.patch --]
[-- Type: text/plain, Size: 2633 bytes --]
diff -ru xen-3.0.3_0-src.orig/tools/ioemu/hw/ide.c xen-3.0.3_0-src/tools/ioemu/hw/ide.c
--- xen-3.0.3_0-src.orig/tools/ioemu/hw/ide.c 2006-10-15 08:22:03.000000000 -0400
+++ xen-3.0.3_0-src/tools/ioemu/hw/ide.c 2006-12-01 16:46:59.000000000 -0500
@@ -680,7 +680,7 @@
static void ide_sector_read(IDEState *s)
{
int64_t sector_num;
- int ret, n;
+ int n;
s->status = READY_STAT | SEEK_STAT;
s->error = 0; /* not needed by IDE spec, but needed by Windows */
@@ -695,7 +695,11 @@
#endif
if (n > s->req_nb_sectors)
n = s->req_nb_sectors;
- ret = bdrv_read(s->bs, sector_num, s->io_buffer, n);
+ if (bdrv_read(s->bs, sector_num, s->io_buffer, n) != 0) {
+ ide_abort_command(s);
+ ide_set_irq(s);
+ return;
+ }
ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read);
ide_set_irq(s);
ide_set_sector(s, sector_num + n);
@@ -721,7 +725,11 @@
if (n > MAX_MULT_SECTORS)
n = MAX_MULT_SECTORS;
sector_num = ide_get_sector(s);
- bdrv_read(s->bs, sector_num, s->io_buffer, n);
+ if (bdrv_read(s->bs, sector_num, s->io_buffer, n) != 0) {
+ ide_abort_command(s);
+ ide_set_irq(s);
+ return 0;
+ }
s->io_buffer_index = 0;
s->io_buffer_size = n * 512;
len = s->io_buffer_size;
@@ -767,7 +775,7 @@
static void ide_sector_write(IDEState *s)
{
int64_t sector_num;
- int ret, n, n1;
+ int n, n1;
s->status = READY_STAT | SEEK_STAT;
sector_num = ide_get_sector(s);
@@ -777,7 +785,11 @@
n = s->nsector;
if (n > s->req_nb_sectors)
n = s->req_nb_sectors;
- ret = bdrv_write(s->bs, sector_num, s->io_buffer, n);
+ if (bdrv_write(s->bs, sector_num, s->io_buffer, n) != 0) {
+ ide_abort_command(s);
+ ide_set_irq(s);
+ return;
+ }
s->nsector -= n;
if (s->nsector == 0) {
/* no more sector to write */
@@ -823,8 +835,13 @@
if (len == 0) {
n = s->io_buffer_size >> 9;
sector_num = ide_get_sector(s);
- bdrv_write(s->bs, sector_num, s->io_buffer,
- s->io_buffer_size >> 9);
+ if (bdrv_write(s->bs, sector_num, s->io_buffer,
+ s->io_buffer_size >> 9) != 0) {
+ ide_abort_command(s);
+ ide_set_irq(s);
+ return 0;
+ }
+
sector_num += n;
ide_set_sector(s, sector_num);
s->nsector -= n;
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-12-03 23:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-03 23:28 [PATCH] QEMU report I/O errors to guest via IDE status registers Daniel P. Berrange
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.