diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-05 19:10:55 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-05 19:10:55 +0000 |
commit | 178e08a58f40dd5aef2ce774fe0850f5d0e56918 (patch) | |
tree | 4884054a59eaaad4b5df2f47403cee9a81e8e2db | |
parent | 8185d2c9a20975114ebb59b0f46b615cbb83c730 (diff) |
Fix savevm after BDRV_FILE size enforcement
We now enforce that you cannot write beyond the end of a non-growable file.
qcow2 files are not growable but we rely on them being growable to do
savevm/loadvm. Temporarily allow them to be growable by introducing a new
API specifically for savevm read/write operations.
Reported-by: malc
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6994 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r-- | block-qcow2.c | 28 | ||||
-rw-r--r-- | block.c | 20 | ||||
-rw-r--r-- | block.h | 5 | ||||
-rw-r--r-- | block_int.h | 5 | ||||
-rw-r--r-- | savevm.c | 12 |
5 files changed, 64 insertions, 6 deletions
diff --git a/block-qcow2.c b/block-qcow2.c index d99811d3ff..6eba524a2b 100644 --- a/block-qcow2.c +++ b/block-qcow2.c @@ -2721,6 +2721,31 @@ static void dump_refcounts(BlockDriverState *bs) #endif #endif +static int qcow_put_buffer(BlockDriverState *bs, const uint8_t *buf, + int64_t pos, int size) +{ + int growable = bs->growable; + + bs->growable = 1; + bdrv_pwrite(bs, pos, buf, size); + bs->growable = growable; + + return size; +} + +static int qcow_get_buffer(BlockDriverState *bs, uint8_t *buf, + int64_t pos, int size) +{ + int growable = bs->growable; + int ret; + + bs->growable = 1; + ret = bdrv_pread(bs, pos, buf, size); + bs->growable = growable; + + return ret; +} + BlockDriver bdrv_qcow2 = { .format_name = "qcow2", .instance_size = sizeof(BDRVQcowState), @@ -2745,5 +2770,8 @@ BlockDriver bdrv_qcow2 = { .bdrv_snapshot_list = qcow_snapshot_list, .bdrv_get_info = qcow_get_info, + .bdrv_put_buffer = qcow_put_buffer, + .bdrv_get_buffer = qcow_get_buffer, + .bdrv_create2 = qcow_create2, }; @@ -1146,6 +1146,26 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return drv->bdrv_get_info(bs, bdi); } +int bdrv_put_buffer(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) +{ + BlockDriver *drv = bs->drv; + if (!drv) + return -ENOMEDIUM; + if (!drv->bdrv_put_buffer) + return -ENOTSUP; + return drv->bdrv_put_buffer(bs, buf, pos, size); +} + +int bdrv_get_buffer(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size) +{ + BlockDriver *drv = bs->drv; + if (!drv) + return -ENOMEDIUM; + if (!drv->bdrv_get_buffer) + return -ENOTSUP; + return drv->bdrv_get_buffer(bs, buf, pos, size); +} + /**************************************************************/ /* handling of snapshots */ @@ -178,4 +178,9 @@ void path_combine(char *dest, int dest_size, const char *base_path, const char *filename); +int bdrv_put_buffer(BlockDriverState *bs, const uint8_t *buf, + int64_t pos, int size); + +int bdrv_get_buffer(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size); + #endif diff --git a/block_int.h b/block_int.h index af6dff6bd6..dc4335982c 100644 --- a/block_int.h +++ b/block_int.h @@ -78,6 +78,11 @@ struct BlockDriver { QEMUSnapshotInfo **psn_info); int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); + int (*bdrv_put_buffer)(BlockDriverState *bs, const uint8_t *buf, + int64_t pos, int size); + int (*bdrv_get_buffer)(BlockDriverState *bs, uint8_t *buf, + int64_t pos, int size); + /* removable device specific */ int (*bdrv_is_inserted)(BlockDriverState *bs); int (*bdrv_media_changed)(BlockDriverState *bs); @@ -310,18 +310,18 @@ typedef struct QEMUFileBdrv int64_t base_offset; } QEMUFileBdrv; -static int bdrv_put_buffer(void *opaque, const uint8_t *buf, +static int block_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) { QEMUFileBdrv *s = opaque; - bdrv_pwrite(s->bs, s->base_offset + pos, buf, size); + bdrv_put_buffer(s->bs, buf, s->base_offset + pos, size); return size; } -static int bdrv_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) +static int block_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) { QEMUFileBdrv *s = opaque; - return bdrv_pread(s->bs, s->base_offset + pos, buf, size); + return bdrv_get_buffer(s->bs, buf, s->base_offset + pos, size); } static int bdrv_fclose(void *opaque) @@ -341,9 +341,9 @@ static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int64_t offset, int is_wr s->base_offset = offset; if (is_writable) - return qemu_fopen_ops(s, bdrv_put_buffer, NULL, bdrv_fclose, NULL); + return qemu_fopen_ops(s, block_put_buffer, NULL, bdrv_fclose, NULL); - return qemu_fopen_ops(s, NULL, bdrv_get_buffer, bdrv_fclose, NULL); + return qemu_fopen_ops(s, NULL, block_get_buffer, bdrv_fclose, NULL); } QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, |