[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] ioemu: Expandable storage backends should defeat block-device range checks.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1204118496 0
# Node ID 5e6e1fce3300a0f32a4bba789c17e5194a31c0a9
# Parent  bfd87849ccda6db8bd7b336b5230237683af96ee
ioemu: Expandable storage backends should defeat block-device range checks.
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/ioemu/block-qcow.c  |    2 +-
 tools/ioemu/block-qcow2.c |    2 +-
 tools/ioemu/block-raw.c   |    2 ++
 tools/ioemu/block-vmdk.c  |    2 +-
 tools/ioemu/block.c       |   17 +++++++++++++----
 tools/ioemu/block_int.h   |    4 ++++
 tools/ioemu/vl.h          |    2 ++
 7 files changed, 24 insertions(+), 7 deletions(-)

diff -r bfd87849ccda -r 5e6e1fce3300 tools/ioemu/block-qcow.c
--- a/tools/ioemu/block-qcow.c  Wed Feb 27 13:19:42 2008 +0000
+++ b/tools/ioemu/block-qcow.c  Wed Feb 27 13:21:36 2008 +0000
@@ -95,7 +95,7 @@ static int qcow_open(BlockDriverState *b
     int len, i, shift, ret;
     QCowHeader header;
 
-    ret = bdrv_file_open(&s->hd, filename, flags);
+    ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE);
     if (ret < 0)
         return ret;
     if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != sizeof(header))
diff -r bfd87849ccda -r 5e6e1fce3300 tools/ioemu/block-qcow2.c
--- a/tools/ioemu/block-qcow2.c Wed Feb 27 13:19:42 2008 +0000
+++ b/tools/ioemu/block-qcow2.c Wed Feb 27 13:21:36 2008 +0000
@@ -191,7 +191,7 @@ static int qcow_open(BlockDriverState *b
     int len, i, shift, ret;
     QCowHeader header;
 
-    ret = bdrv_file_open(&s->hd, filename, flags);
+    ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE);
     if (ret < 0)
         return ret;
     if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != sizeof(header))
diff -r bfd87849ccda -r 5e6e1fce3300 tools/ioemu/block-raw.c
--- a/tools/ioemu/block-raw.c   Wed Feb 27 13:19:42 2008 +0000
+++ b/tools/ioemu/block-raw.c   Wed Feb 27 13:21:36 2008 +0000
@@ -1489,5 +1489,7 @@ BlockDriver bdrv_host_device = {
     .bdrv_pread = raw_pread,
     .bdrv_pwrite = raw_pwrite,
     .bdrv_getlength = raw_getlength,
+
+    .bdrv_flags = BLOCK_DRIVER_FLAG_EXTENDABLE
 };
 #endif /* _WIN32 */
diff -r bfd87849ccda -r 5e6e1fce3300 tools/ioemu/block-vmdk.c
--- a/tools/ioemu/block-vmdk.c  Wed Feb 27 13:19:42 2008 +0000
+++ b/tools/ioemu/block-vmdk.c  Wed Feb 27 13:21:36 2008 +0000
@@ -352,7 +352,7 @@ static int vmdk_open(BlockDriverState *b
     uint32_t magic;
     int l1_size, i, ret;
 
-    ret = bdrv_file_open(&s->hd, filename, flags);
+    ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE);
     if (ret < 0)
         return ret;
     if (bdrv_pread(s->hd, 0, &magic, sizeof(magic)) != sizeof(magic))
diff -r bfd87849ccda -r 5e6e1fce3300 tools/ioemu/block.c
--- a/tools/ioemu/block.c       Wed Feb 27 13:19:42 2008 +0000
+++ b/tools/ioemu/block.c       Wed Feb 27 13:21:36 2008 +0000
@@ -123,20 +123,23 @@ static int bdrv_rw_badreq_sectors(BlockD
 static int bdrv_rw_badreq_sectors(BlockDriverState *bs,
                                int64_t sector_num, int nb_sectors)
 {
-    return
+    return (
        nb_sectors < 0 ||
        nb_sectors > bs->total_sectors ||
-       sector_num > bs->total_sectors - nb_sectors;
+       sector_num > bs->total_sectors - nb_sectors
+       ) && !bs->extendable;
 }
 
 static int bdrv_rw_badreq_bytes(BlockDriverState *bs,
                                  int64_t offset, int count)
 {
     int64_t size = bs->total_sectors << SECTOR_BITS;
-    return
+    return (
        count < 0 ||
        count > size ||
-       offset > size - count;
+       offset > size - count
+       ) && !bs->extendable;
+    
 }
 
 void bdrv_register(BlockDriver *bdrv)
@@ -347,6 +350,12 @@ int bdrv_open2(BlockDriverState *bs, con
     bs->is_temporary = 0;
     bs->encrypted = 0;
 
+    if (flags & BDRV_O_EXTENDABLE) {
+       if (!(drv->bdrv_flags & BLOCK_DRIVER_FLAG_EXTENDABLE))
+           return -ENOSYS;
+       bs->extendable = 1;
+    }
+
     if (flags & BDRV_O_SNAPSHOT) {
         BlockDriverState *bs1;
         int64_t total_size;
diff -r bfd87849ccda -r 5e6e1fce3300 tools/ioemu/block_int.h
--- a/tools/ioemu/block_int.h   Wed Feb 27 13:19:42 2008 +0000
+++ b/tools/ioemu/block_int.h   Wed Feb 27 13:21:36 2008 +0000
@@ -23,6 +23,8 @@
  */
 #ifndef BLOCK_INT_H
 #define BLOCK_INT_H
+
+#define BLOCK_DRIVER_FLAG_EXTENDABLE  0x0001u
 
 struct BlockDriver {
     const char *format_name;
@@ -76,6 +78,7 @@ struct BlockDriver {
     int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
     int (*bdrv_set_locked)(BlockDriverState *bs, int locked);
     
+    unsigned bdrv_flags;
     BlockDriverAIOCB *free_aiocb;
     struct BlockDriver *next;
 };
@@ -87,6 +90,7 @@ struct BlockDriverState {
     int removable; /* if true, the media can be removed */
     int locked;    /* if true, the media cannot temporarily be ejected */
     int encrypted; /* if true, the media is encrypted */
+    int extendable;/* if true, we may write out of original range */
     /* event callback when inserting/removing */
     void (*change_cb)(void *opaque);
     void *change_opaque;
diff -r bfd87849ccda -r 5e6e1fce3300 tools/ioemu/vl.h
--- a/tools/ioemu/vl.h  Wed Feb 27 13:19:42 2008 +0000
+++ b/tools/ioemu/vl.h  Wed Feb 27 13:21:36 2008 +0000
@@ -614,6 +614,8 @@ typedef struct QEMUSnapshotInfo {
                                      use a disk image format on top of
                                      it (default for
                                      bdrv_file_open()) */
+#define BDRV_O_EXTENDABLE  0x0080 /* allow writes out of original size range;
+                                    only effective for some drivers */
 
 void bdrv_init(void);
 BlockDriver *bdrv_find_format(const char *format_name);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.