ia64/xen-unstable

changeset 17351:d8fc3b73fb76

ioemu: actually check for errors in bdrv_flush et al

bdrv_flush is declared to return void, but this is wrong because it
means that the implementations have nowhere to report their errors.
Indeed, the implementations generally ignore errors.

This patch corrects this by making it return int (implicitly, either 0
or -errno, as for other similar functions). All of the
implementations and callers are adjusted too.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 31 10:35:35 2008 +0100 (2008-03-31)
parents 6736c28a0d35
children 5dfdf95db75c
files tools/ioemu/block-qcow.c tools/ioemu/block-qcow2.c tools/ioemu/block-raw.c tools/ioemu/block-vmdk.c tools/ioemu/block.c tools/ioemu/block_int.h tools/ioemu/hw/ide.c tools/ioemu/hw/scsi-disk.c tools/ioemu/vl.h
line diff
     1.1 --- a/tools/ioemu/block-qcow.c	Fri Mar 28 17:58:36 2008 +0000
     1.2 +++ b/tools/ioemu/block-qcow.c	Mon Mar 31 10:35:35 2008 +0100
     1.3 @@ -934,10 +934,10 @@ static int qcow_write_compressed(BlockDr
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -static void qcow_flush(BlockDriverState *bs)
     1.8 +static int qcow_flush(BlockDriverState *bs)
     1.9  {
    1.10      BDRVQcowState *s = bs->opaque;
    1.11 -    bdrv_flush(s->hd);
    1.12 +    return bdrv_flush(s->hd);
    1.13  }
    1.14  
    1.15  static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     2.1 --- a/tools/ioemu/block-qcow2.c	Fri Mar 28 17:58:36 2008 +0000
     2.2 +++ b/tools/ioemu/block-qcow2.c	Mon Mar 31 10:35:35 2008 +0100
     2.3 @@ -1235,10 +1235,10 @@ static int qcow_write_compressed(BlockDr
     2.4      return 0;
     2.5  }
     2.6  
     2.7 -static void qcow_flush(BlockDriverState *bs)
     2.8 +static int qcow_flush(BlockDriverState *bs)
     2.9  {
    2.10      BDRVQcowState *s = bs->opaque;
    2.11 -    bdrv_flush(s->hd);
    2.12 +    return bdrv_flush(s->hd);
    2.13  }
    2.14  
    2.15  static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     3.1 --- a/tools/ioemu/block-raw.c	Fri Mar 28 17:58:36 2008 +0000
     3.2 +++ b/tools/ioemu/block-raw.c	Mon Mar 31 10:35:35 2008 +0100
     3.3 @@ -615,10 +615,12 @@ static int raw_create(const char *filena
     3.4      return 0;
     3.5  }
     3.6  
     3.7 -static void raw_flush(BlockDriverState *bs)
     3.8 +static int raw_flush(BlockDriverState *bs)
     3.9  {
    3.10      BDRVRawState *s = bs->opaque;
    3.11 -    fsync(s->fd);
    3.12 +    if (fsync(s->fd))
    3.13 +        return errno;
    3.14 +    return 0;
    3.15  }
    3.16  
    3.17  BlockDriver bdrv_raw = {
     4.1 --- a/tools/ioemu/block-vmdk.c	Fri Mar 28 17:58:36 2008 +0000
     4.2 +++ b/tools/ioemu/block-vmdk.c	Mon Mar 31 10:35:35 2008 +0100
     4.3 @@ -734,10 +734,10 @@ static void vmdk_close(BlockDriverState 
     4.4      vmdk_parent_close(s->hd);
     4.5  }
     4.6  
     4.7 -static void vmdk_flush(BlockDriverState *bs)
     4.8 +static int vmdk_flush(BlockDriverState *bs)
     4.9  {
    4.10      BDRVVmdkState *s = bs->opaque;
    4.11 -    bdrv_flush(s->hd);
    4.12 +    return bdrv_flush(s->hd);
    4.13  }
    4.14  
    4.15  BlockDriver bdrv_vmdk = {
     5.1 --- a/tools/ioemu/block.c	Fri Mar 28 17:58:36 2008 +0000
     5.2 +++ b/tools/ioemu/block.c	Mon Mar 31 10:35:35 2008 +0100
     5.3 @@ -889,12 +889,14 @@ const char *bdrv_get_device_name(BlockDr
     5.4      return bs->device_name;
     5.5  }
     5.6  
     5.7 -void bdrv_flush(BlockDriverState *bs)
     5.8 +int bdrv_flush(BlockDriverState *bs)
     5.9  {
    5.10 -    if (bs->drv->bdrv_flush)
    5.11 -        bs->drv->bdrv_flush(bs);
    5.12 -    if (bs->backing_hd)
    5.13 -        bdrv_flush(bs->backing_hd);
    5.14 +    int ret = 0;
    5.15 +    if (bs->drv->bdrv_flush) 
    5.16 +        ret = bs->drv->bdrv_flush(bs);
    5.17 +    if (!ret && bs->backing_hd)
    5.18 +        ret = bdrv_flush(bs->backing_hd);
    5.19 +    return ret;
    5.20  }
    5.21  
    5.22  void bdrv_info(void)
    5.23 @@ -1232,8 +1234,9 @@ static void bdrv_aio_cancel_em(BlockDriv
    5.24  static BlockDriverAIOCB *bdrv_aio_flush_em(BlockDriverState *bs,
    5.25          BlockDriverCompletionFunc *cb, void *opaque)
    5.26  {
    5.27 -    bdrv_flush(bs);
    5.28 -    cb(opaque, 0);
    5.29 +    int ret;
    5.30 +    ret = bdrv_flush(bs);
    5.31 +    cb(opaque, ret);
    5.32      return NULL;
    5.33  }
    5.34  
     6.1 --- a/tools/ioemu/block_int.h	Fri Mar 28 17:58:36 2008 +0000
     6.2 +++ b/tools/ioemu/block_int.h	Mon Mar 31 10:35:35 2008 +0100
     6.3 @@ -36,7 +36,7 @@ struct BlockDriver {
     6.4      void (*bdrv_close)(BlockDriverState *bs);
     6.5      int (*bdrv_create)(const char *filename, int64_t total_sectors, 
     6.6                         const char *backing_file, int flags);
     6.7 -    void (*bdrv_flush)(BlockDriverState *bs);
     6.8 +    int (*bdrv_flush)(BlockDriverState *bs);
     6.9      int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
    6.10                               int nb_sectors, int *pnum);
    6.11      int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     7.1 --- a/tools/ioemu/hw/ide.c	Fri Mar 28 17:58:36 2008 +0000
     7.2 +++ b/tools/ioemu/hw/ide.c	Mon Mar 31 10:35:35 2008 +0100
     7.3 @@ -1786,6 +1786,7 @@ static void ide_ioport_write(void *opaqu
     7.4      IDEState *s;
     7.5      int unit, n;
     7.6      int lba48 = 0;
     7.7 +    int ret;
     7.8  
     7.9  #ifdef DEBUG_IDE
    7.10      printf("IDE: write addr=0x%x val=0x%02x\n", addr, val);
     8.1 --- a/tools/ioemu/hw/scsi-disk.c	Fri Mar 28 17:58:36 2008 +0000
     8.2 +++ b/tools/ioemu/hw/scsi-disk.c	Mon Mar 31 10:35:35 2008 +0100
     8.3 @@ -291,6 +291,7 @@ int32_t scsi_send_command(SCSIDevice *s,
     8.4      uint8_t command;
     8.5      uint8_t *outbuf;
     8.6      SCSIRequest *r;
     8.7 +    int ret;
     8.8  
     8.9      command = buf[0];
    8.10      r = scsi_find_request(s, tag);
    8.11 @@ -496,7 +497,12 @@ int32_t scsi_send_command(SCSIDevice *s,
    8.12          break;
    8.13      case 0x35:
    8.14          DPRINTF("Syncronise cache (sector %d, count %d)\n", lba, len);
    8.15 -        bdrv_flush(s->bdrv);
    8.16 +        ret = bdrv_flush(s->bdrv);
    8.17 +        if (ret) {
    8.18 +            DPRINTF("IO error on bdrv_flush\n");
    8.19 +            scsi_command_complete(r, SENSE_HARDWARE_ERROR);
    8.20 +            return 0;
    8.21 +        }
    8.22          break;
    8.23      case 0x43:
    8.24          {
     9.1 --- a/tools/ioemu/vl.h	Fri Mar 28 17:58:36 2008 +0000
     9.2 +++ b/tools/ioemu/vl.h	Mon Mar 31 10:35:35 2008 +0100
     9.3 @@ -664,7 +664,7 @@ void qemu_aio_wait(void);
     9.4  void qemu_aio_wait_end(void);
     9.5  
     9.6  /* Ensure contents are flushed to disk.  */
     9.7 -void bdrv_flush(BlockDriverState *bs);
     9.8 +int bdrv_flush(BlockDriverState *bs);
     9.9  
    9.10  #define BDRV_TYPE_HD     0
    9.11  #define BDRV_TYPE_CDROM  1