ia64/xen-unstable

changeset 17140:5e6e1fce3300

ioemu: Expandable storage backends should defeat block-device range checks.
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Feb 27 13:21:36 2008 +0000 (2008-02-27)
parents bfd87849ccda
children 45a24393a594
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/vl.h
line diff
     1.1 --- a/tools/ioemu/block-qcow.c	Wed Feb 27 13:19:42 2008 +0000
     1.2 +++ b/tools/ioemu/block-qcow.c	Wed Feb 27 13:21:36 2008 +0000
     1.3 @@ -95,7 +95,7 @@ static int qcow_open(BlockDriverState *b
     1.4      int len, i, shift, ret;
     1.5      QCowHeader header;
     1.6  
     1.7 -    ret = bdrv_file_open(&s->hd, filename, flags);
     1.8 +    ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE);
     1.9      if (ret < 0)
    1.10          return ret;
    1.11      if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != sizeof(header))
     2.1 --- a/tools/ioemu/block-qcow2.c	Wed Feb 27 13:19:42 2008 +0000
     2.2 +++ b/tools/ioemu/block-qcow2.c	Wed Feb 27 13:21:36 2008 +0000
     2.3 @@ -191,7 +191,7 @@ static int qcow_open(BlockDriverState *b
     2.4      int len, i, shift, ret;
     2.5      QCowHeader header;
     2.6  
     2.7 -    ret = bdrv_file_open(&s->hd, filename, flags);
     2.8 +    ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE);
     2.9      if (ret < 0)
    2.10          return ret;
    2.11      if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != sizeof(header))
     3.1 --- a/tools/ioemu/block-raw.c	Wed Feb 27 13:19:42 2008 +0000
     3.2 +++ b/tools/ioemu/block-raw.c	Wed Feb 27 13:21:36 2008 +0000
     3.3 @@ -1489,5 +1489,7 @@ BlockDriver bdrv_host_device = {
     3.4      .bdrv_pread = raw_pread,
     3.5      .bdrv_pwrite = raw_pwrite,
     3.6      .bdrv_getlength = raw_getlength,
     3.7 +
     3.8 +    .bdrv_flags = BLOCK_DRIVER_FLAG_EXTENDABLE
     3.9  };
    3.10  #endif /* _WIN32 */
     4.1 --- a/tools/ioemu/block-vmdk.c	Wed Feb 27 13:19:42 2008 +0000
     4.2 +++ b/tools/ioemu/block-vmdk.c	Wed Feb 27 13:21:36 2008 +0000
     4.3 @@ -352,7 +352,7 @@ static int vmdk_open(BlockDriverState *b
     4.4      uint32_t magic;
     4.5      int l1_size, i, ret;
     4.6  
     4.7 -    ret = bdrv_file_open(&s->hd, filename, flags);
     4.8 +    ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE);
     4.9      if (ret < 0)
    4.10          return ret;
    4.11      if (bdrv_pread(s->hd, 0, &magic, sizeof(magic)) != sizeof(magic))
     5.1 --- a/tools/ioemu/block.c	Wed Feb 27 13:19:42 2008 +0000
     5.2 +++ b/tools/ioemu/block.c	Wed Feb 27 13:21:36 2008 +0000
     5.3 @@ -123,20 +123,23 @@ void path_combine(char *dest, int dest_s
     5.4  static int bdrv_rw_badreq_sectors(BlockDriverState *bs,
     5.5  				int64_t sector_num, int nb_sectors)
     5.6  {
     5.7 -    return
     5.8 +    return (
     5.9  	nb_sectors < 0 ||
    5.10  	nb_sectors > bs->total_sectors ||
    5.11 -	sector_num > bs->total_sectors - nb_sectors;
    5.12 +	sector_num > bs->total_sectors - nb_sectors
    5.13 +	) && !bs->extendable;
    5.14  }
    5.15  
    5.16  static int bdrv_rw_badreq_bytes(BlockDriverState *bs,
    5.17  				  int64_t offset, int count)
    5.18  {
    5.19      int64_t size = bs->total_sectors << SECTOR_BITS;
    5.20 -    return
    5.21 +    return (
    5.22  	count < 0 ||
    5.23  	count > size ||
    5.24 -	offset > size - count;
    5.25 +	offset > size - count
    5.26 +	) && !bs->extendable;
    5.27 +    
    5.28  }
    5.29  
    5.30  void bdrv_register(BlockDriver *bdrv)
    5.31 @@ -347,6 +350,12 @@ int bdrv_open2(BlockDriverState *bs, con
    5.32      bs->is_temporary = 0;
    5.33      bs->encrypted = 0;
    5.34  
    5.35 +    if (flags & BDRV_O_EXTENDABLE) {
    5.36 +	if (!(drv->bdrv_flags & BLOCK_DRIVER_FLAG_EXTENDABLE))
    5.37 +	    return -ENOSYS;
    5.38 +	bs->extendable = 1;
    5.39 +    }
    5.40 +
    5.41      if (flags & BDRV_O_SNAPSHOT) {
    5.42          BlockDriverState *bs1;
    5.43          int64_t total_size;
     6.1 --- a/tools/ioemu/block_int.h	Wed Feb 27 13:19:42 2008 +0000
     6.2 +++ b/tools/ioemu/block_int.h	Wed Feb 27 13:21:36 2008 +0000
     6.3 @@ -24,6 +24,8 @@
     6.4  #ifndef BLOCK_INT_H
     6.5  #define BLOCK_INT_H
     6.6  
     6.7 +#define BLOCK_DRIVER_FLAG_EXTENDABLE  0x0001u
     6.8 +
     6.9  struct BlockDriver {
    6.10      const char *format_name;
    6.11      int instance_size;
    6.12 @@ -76,6 +78,7 @@ struct BlockDriver {
    6.13      int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
    6.14      int (*bdrv_set_locked)(BlockDriverState *bs, int locked);
    6.15      
    6.16 +    unsigned bdrv_flags;
    6.17      BlockDriverAIOCB *free_aiocb;
    6.18      struct BlockDriver *next;
    6.19  };
    6.20 @@ -87,6 +90,7 @@ struct BlockDriverState {
    6.21      int removable; /* if true, the media can be removed */
    6.22      int locked;    /* if true, the media cannot temporarily be ejected */
    6.23      int encrypted; /* if true, the media is encrypted */
    6.24 +    int extendable;/* if true, we may write out of original range */
    6.25      /* event callback when inserting/removing */
    6.26      void (*change_cb)(void *opaque);
    6.27      void *change_opaque;
     7.1 --- a/tools/ioemu/vl.h	Wed Feb 27 13:19:42 2008 +0000
     7.2 +++ b/tools/ioemu/vl.h	Wed Feb 27 13:21:36 2008 +0000
     7.3 @@ -614,6 +614,8 @@ typedef struct QEMUSnapshotInfo {
     7.4                                       use a disk image format on top of
     7.5                                       it (default for
     7.6                                       bdrv_file_open()) */
     7.7 +#define BDRV_O_EXTENDABLE  0x0080 /* allow writes out of original size range;
     7.8 +				     only effective for some drivers */
     7.9  
    7.10  void bdrv_init(void);
    7.11  BlockDriver *bdrv_find_format(const char *format_name);