From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:50309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QN2Nc-0002XR-NP for qemu-devel@nongnu.org; Thu, 19 May 2011 08:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QN2Nb-0003vl-D0 for qemu-devel@nongnu.org; Thu, 19 May 2011 08:31:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44161) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QN2Nb-0003vM-3k for qemu-devel@nongnu.org; Thu, 19 May 2011 08:31:03 -0400 From: Kevin Wolf Date: Thu, 19 May 2011 14:33:25 +0200 Message-Id: <1305808412-16994-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1305808412-16994-1-git-send-email-kwolf@redhat.com> References: <1305808412-16994-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 11/18] qed: support for growing images List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Stefan Hajnoczi 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 --- block/qed.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-) 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) -- 1.7.2.3