From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LqZYv-0002q5-CJ for qemu-devel@nongnu.org; Sun, 05 Apr 2009 17:07:29 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LqZYu-0002pj-A1 for qemu-devel@nongnu.org; Sun, 05 Apr 2009 17:07:28 -0400 Received: from [199.232.76.173] (port=59388 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LqZYt-0002pY-R9 for qemu-devel@nongnu.org; Sun, 05 Apr 2009 17:07:27 -0400 Received: from savannah.gnu.org ([199.232.41.3]:45042 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LqZYt-0006Bo-Dw for qemu-devel@nongnu.org; Sun, 05 Apr 2009 17:07:27 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LqZYs-00007p-Pf for qemu-devel@nongnu.org; Sun, 05 Apr 2009 21:07:26 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LqZYs-00007j-G7 for qemu-devel@nongnu.org; Sun, 05 Apr 2009 21:07:26 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Sun, 05 Apr 2009 21:07:26 +0000 Subject: [Qemu-devel] [7005] Fix savevm after BDRV_FILE size enforcement Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7005 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7005 Author: aliguori Date: 2009-04-05 21:07:26 +0000 (Sun, 05 Apr 2009) Log Message: ----------- 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 Modified Paths: -------------- branches/stable_0_10/block-qcow2.c branches/stable_0_10/block.c branches/stable_0_10/block.h branches/stable_0_10/block_int.h branches/stable_0_10/savevm.c Modified: branches/stable_0_10/block-qcow2.c =================================================================== --- branches/stable_0_10/block-qcow2.c 2009-04-05 20:08:59 UTC (rev 7004) +++ branches/stable_0_10/block-qcow2.c 2009-04-05 21:07:26 UTC (rev 7005) @@ -2601,6 +2601,31 @@ #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 = { "qcow2", sizeof(BDRVQcowState), @@ -2626,4 +2651,7 @@ .bdrv_snapshot_delete = qcow_snapshot_delete, .bdrv_snapshot_list = qcow_snapshot_list, .bdrv_get_info = qcow_get_info, + + .bdrv_put_buffer = qcow_put_buffer, + .bdrv_get_buffer = qcow_get_buffer, }; Modified: branches/stable_0_10/block.c =================================================================== --- branches/stable_0_10/block.c 2009-04-05 20:08:59 UTC (rev 7004) +++ branches/stable_0_10/block.c 2009-04-05 21:07:26 UTC (rev 7005) @@ -1181,6 +1181,26 @@ 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 */ Modified: branches/stable_0_10/block.h =================================================================== --- branches/stable_0_10/block.h 2009-04-05 20:08:59 UTC (rev 7004) +++ branches/stable_0_10/block.h 2009-04-05 21:07:26 UTC (rev 7005) @@ -169,4 +169,9 @@ 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 Modified: branches/stable_0_10/block_int.h =================================================================== --- branches/stable_0_10/block_int.h 2009-04-05 20:08:59 UTC (rev 7004) +++ branches/stable_0_10/block_int.h 2009-04-05 21:07:26 UTC (rev 7005) @@ -76,6 +76,11 @@ 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); Modified: branches/stable_0_10/savevm.c =================================================================== --- branches/stable_0_10/savevm.c 2009-04-05 20:08:59 UTC (rev 7004) +++ branches/stable_0_10/savevm.c 2009-04-05 21:07:26 UTC (rev 7005) @@ -306,18 +306,18 @@ 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) @@ -337,9 +337,9 @@ 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,