From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:51806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLxMD-0007JP-BP for qemu-devel@nongnu.org; Mon, 16 May 2011 08:57:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QLxMC-0006wr-F9 for qemu-devel@nongnu.org; Mon, 16 May 2011 08:57:09 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:45411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLxMC-0006vT-7z for qemu-devel@nongnu.org; Mon, 16 May 2011 08:57:08 -0400 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p4GCut5t030963 for ; Mon, 16 May 2011 12:56:55 GMT Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4GCutKW2285630 for ; Mon, 16 May 2011 13:56:55 +0100 Received: from d06av10.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4GCutjQ018341 for ; Mon, 16 May 2011 06:56:55 -0600 From: Stefan Hajnoczi Date: Mon, 16 May 2011 13:56:53 +0100 Message-Id: <1305550613-3567-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] qed: support for growing images List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , 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 --- block/qed.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-) diff --git a/block/qed.c b/block/qed.c index c8c5930..bfb49d9 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1233,7 +1233,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.4.4