From: Stefan Hajnoczi Date: Mon, 16 May 2011 12:56:53 +0000 (+0100) Subject: qed: support for growing images X-Git-Tag: TizenStudio_2.0_p2.3~2726 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9bf0073bf9765a616628a1b8d95246115a5f7a9a;p=sdk%2Femulator%2Fqemu.git qed: support for growing images The .bdrv_truncate() operation resizes images and growing is easy to implement in QED. Simply check that the new size is valid and then update the image_size header field to reflect the new size. Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- diff --git a/block/qed.c b/block/qed.c index d8d6ea2..da0bf31 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1333,7 +1333,27 @@ static BlockDriverAIOCB *bdrv_qed_aio_flush(BlockDriverState *bs, static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset) { - return -ENOTSUP; + BDRVQEDState *s = bs->opaque; + uint64_t old_image_size; + int ret; + + if (!qed_is_image_size_valid(offset, s->header.cluster_size, + s->header.table_size)) { + return -EINVAL; + } + + /* Shrinking is currently not supported */ + if ((uint64_t)offset < s->header.image_size) { + return -ENOTSUP; + } + + old_image_size = s->header.image_size; + s->header.image_size = offset; + ret = qed_write_header_sync(s); + if (ret < 0) { + s->header.image_size = old_image_size; + } + return ret; } static int64_t bdrv_qed_getlength(BlockDriverState *bs)