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

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



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1204733806 0
# Node ID 4e8b15a29df003bbaac373fca8cb758d1b512a9e
# Parent  243fd1b2e296047ddcd3273e778af43d31024172
ioemu: Expandable storage backends should defeat block-device range checks.
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
xen-unstable changeset:   17133:5e6e1fce3300a0f32a4bba789c17e5194a31c0a9
xen-unstable date:        Wed Feb 27 13:21:36 2008 +0000

ioemu: Fix segfault when creating qcow-backed vbds.
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
xen-unstable changeset:   17177:d0daf11fb35dab676e5e4ef9b1c02da649e4f9af
xen-unstable date:        Mon Mar 03 13:54:05 2008 +0000
---
 tools/ioemu/block-qcow.c  |    2 +-
 tools/ioemu/block-qcow2.c |    2 +-
 tools/ioemu/block-vmdk.c  |    2 +-
 tools/ioemu/block.c       |   14 ++++++++++----
 tools/ioemu/block_int.h   |    1 +
 tools/ioemu/vl.h          |    2 ++
 6 files changed, 16 insertions(+), 7 deletions(-)

diff -r 243fd1b2e296 -r 4e8b15a29df0 tools/ioemu/block-qcow.c
--- a/tools/ioemu/block-qcow.c  Wed Mar 05 16:15:34 2008 +0000
+++ b/tools/ioemu/block-qcow.c  Wed Mar 05 16:16:46 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 243fd1b2e296 -r 4e8b15a29df0 tools/ioemu/block-qcow2.c
--- a/tools/ioemu/block-qcow2.c Wed Mar 05 16:15:34 2008 +0000
+++ b/tools/ioemu/block-qcow2.c Wed Mar 05 16:16:46 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 243fd1b2e296 -r 4e8b15a29df0 tools/ioemu/block-vmdk.c
--- a/tools/ioemu/block-vmdk.c  Wed Mar 05 16:15:34 2008 +0000
+++ b/tools/ioemu/block-vmdk.c  Wed Mar 05 16:16:46 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 243fd1b2e296 -r 4e8b15a29df0 tools/ioemu/block.c
--- a/tools/ioemu/block.c       Wed Mar 05 16:15:34 2008 +0000
+++ b/tools/ioemu/block.c       Wed Mar 05 16:16:46 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)
@@ -346,6 +349,9 @@ int bdrv_open2(BlockDriverState *bs, con
     bs->read_only = 0;
     bs->is_temporary = 0;
     bs->encrypted = 0;
+
+    if (flags & BDRV_O_EXTENDABLE)
+       bs->extendable = 1;
 
     if (flags & BDRV_O_SNAPSHOT) {
         BlockDriverState *bs1;
diff -r 243fd1b2e296 -r 4e8b15a29df0 tools/ioemu/block_int.h
--- a/tools/ioemu/block_int.h   Wed Mar 05 16:15:34 2008 +0000
+++ b/tools/ioemu/block_int.h   Wed Mar 05 16:16:46 2008 +0000
@@ -87,6 +87,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 243fd1b2e296 -r 4e8b15a29df0 tools/ioemu/vl.h
--- a/tools/ioemu/vl.h  Wed Mar 05 16:15:34 2008 +0000
+++ b/tools/ioemu/vl.h  Wed Mar 05 16:16:46 2008 +0000
@@ -611,6 +611,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®.