ia64/xen-unstable

changeset 12782:fd28a1b139de

[QEMU] Error reporting in IDE device model.

Following on from my patch to make blktap report I/O errors back to
guest OS, 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.

From: Daniel Berrange <berrange@redhat.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Mon Dec 04 09:29:26 2006 +0000 (2006-12-04)
parents d8befb109c39
children 38ad5643aafe
files tools/ioemu/hw/ide.c
line diff
     1.1 --- a/tools/ioemu/hw/ide.c	Mon Dec 04 09:21:10 2006 +0000
     1.2 +++ b/tools/ioemu/hw/ide.c	Mon Dec 04 09:29:26 2006 +0000
     1.3 @@ -680,7 +680,7 @@ static void ide_set_sector(IDEState *s, 
     1.4  static void ide_sector_read(IDEState *s)
     1.5  {
     1.6      int64_t sector_num;
     1.7 -    int ret, n;
     1.8 +    int n;
     1.9  
    1.10      s->status = READY_STAT | SEEK_STAT;
    1.11      s->error = 0; /* not needed by IDE spec, but needed by Windows */
    1.12 @@ -695,7 +695,11 @@ static void ide_sector_read(IDEState *s)
    1.13  #endif
    1.14          if (n > s->req_nb_sectors)
    1.15              n = s->req_nb_sectors;
    1.16 -        ret = bdrv_read(s->bs, sector_num, s->io_buffer, n);
    1.17 +        if (bdrv_read(s->bs, sector_num, s->io_buffer, n) != 0) {
    1.18 +            ide_abort_command(s);
    1.19 +            ide_set_irq(s);
    1.20 +            return;
    1.21 +        }
    1.22          ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read);
    1.23          ide_set_irq(s);
    1.24          ide_set_sector(s, sector_num + n);
    1.25 @@ -721,7 +725,11 @@ static int ide_read_dma_cb(IDEState *s,
    1.26              if (n > MAX_MULT_SECTORS)
    1.27                  n = MAX_MULT_SECTORS;
    1.28              sector_num = ide_get_sector(s);
    1.29 -            bdrv_read(s->bs, sector_num, s->io_buffer, n);
    1.30 +            if (bdrv_read(s->bs, sector_num, s->io_buffer, n) != 0) {
    1.31 +                ide_abort_command(s);
    1.32 +                ide_set_irq(s);
    1.33 +                return 0;
    1.34 +            }
    1.35              s->io_buffer_index = 0;
    1.36              s->io_buffer_size = n * 512;
    1.37              len = s->io_buffer_size;
    1.38 @@ -767,7 +775,7 @@ static void ide_sector_write_timer_cb(vo
    1.39  static void ide_sector_write(IDEState *s)
    1.40  {
    1.41      int64_t sector_num;
    1.42 -    int ret, n, n1;
    1.43 +    int n, n1;
    1.44  
    1.45      s->status = READY_STAT | SEEK_STAT;
    1.46      sector_num = ide_get_sector(s);
    1.47 @@ -777,7 +785,11 @@ static void ide_sector_write(IDEState *s
    1.48      n = s->nsector;
    1.49      if (n > s->req_nb_sectors)
    1.50          n = s->req_nb_sectors;
    1.51 -    ret = bdrv_write(s->bs, sector_num, s->io_buffer, n);
    1.52 +    if (bdrv_write(s->bs, sector_num, s->io_buffer, n) != 0) {
    1.53 +        ide_abort_command(s);
    1.54 +        ide_set_irq(s);
    1.55 +        return;
    1.56 +    }
    1.57      s->nsector -= n;
    1.58      if (s->nsector == 0) {
    1.59          /* no more sector to write */
    1.60 @@ -823,8 +835,13 @@ static int ide_write_dma_cb(IDEState *s,
    1.61          if (len == 0) {
    1.62              n = s->io_buffer_size >> 9;
    1.63              sector_num = ide_get_sector(s);
    1.64 -            bdrv_write(s->bs, sector_num, s->io_buffer, 
    1.65 -                       s->io_buffer_size >> 9);
    1.66 +            if (bdrv_write(s->bs, sector_num, s->io_buffer, 
    1.67 +                	   s->io_buffer_size >> 9) != 0) {
    1.68 +                ide_abort_command(s);
    1.69 +                ide_set_irq(s);
    1.70 +                return 0;
    1.71 +            }
    1.72 +
    1.73              sector_num += n;
    1.74              ide_set_sector(s, sector_num);
    1.75              s->nsector -= n;