From patchwork Thu May 19 12:33:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 96360 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 044D7B6F81 for ; Thu, 19 May 2011 22:34:16 +1000 (EST) Received: from localhost ([::1]:34643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QN2Qf-0007tH-4q for incoming@patchwork.ozlabs.org; Thu, 19 May 2011 08:34:13 -0400 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 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4JCV1EH008610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 19 May 2011 08:31:01 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4JCUleR009371; Thu, 19 May 2011 08:31:00 -0400 From: Kevin Wolf To: anthony@codemonkey.ws 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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 11/18] qed: support for growing images X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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)