From patchwork Thu Dec 19 02:27:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 303143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 58E6A2C007B for ; Thu, 19 Dec 2013 13:30:58 +1100 (EST) Received: from localhost ([::1]:41681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtTO2-0004cR-UW for incoming@patchwork.ozlabs.org; Wed, 18 Dec 2013 21:30:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtTNF-0004Ki-IG for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:30:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtTN7-0007mK-AG for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:30:05 -0500 Received: from [222.73.24.84] (port=35860 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtTN6-0007lt-Ut for qemu-devel@nongnu.org; Wed, 18 Dec 2013 21:29:57 -0500 X-IronPort-AV: E=Sophos;i="4.95,511,1384272000"; d="scan'208";a="9287750" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 19 Dec 2013 10:26:11 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id rBJ2TfI6004922; Thu, 19 Dec 2013 10:29:42 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com ([10.167.226.102]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013121910290983-563811 ; Thu, 19 Dec 2013 10:29:09 +0800 From: Hu Tao To: qemu-devel@nongnu.org Date: Thu, 19 Dec 2013 10:27:41 +0800 Message-Id: <4f5c56d2ebd81d5ae3333b4894eb785ab98cf2db.1387419339.git.hutao@cn.fujitsu.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/12/19 10:29:09, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/12/19 10:29:13, Serialize complete at 2013/12/19 10:29:13 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Kevin Wolf , Fam Zheng , Peter Lieven , hutao@cn.fujitsu.com Subject: [Qemu-devel] [RFC PATCH v3 6/6] qcow2: Add full image preallocation option 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 This adds a preallocation=full mode to qcow2 image creation, which creates a non-sparse image file. Signed-off-by: Hu Tao --- block/qcow2.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 487a595..3c41d4a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1386,7 +1386,7 @@ static int qcow2_change_backing_file(BlockDriverState *bs, return qcow2_update_header(bs); } -static int preallocate(BlockDriverState *bs) +static int preallocate(BlockDriverState *bs, enum prealloc_mode mode) { uint64_t nb_sectors; uint64_t offset; @@ -1395,9 +1395,19 @@ static int preallocate(BlockDriverState *bs) int ret; QCowL2Meta *meta; + assert(mode != PREALLOC_OFF); + nb_sectors = bdrv_getlength(bs) >> 9; offset = 0; + if (mode == PREALLOC_FULL) { + ret = bdrv_preallocate(bs->file, 0, bdrv_getlength(bs)); + if (ret < 0) { + return ret; + } + } + + /* allocate metadata */ while (nb_sectors) { num = MIN(nb_sectors, INT_MAX >> 9); ret = qcow2_alloc_cluster_offset(bs, offset, 0, num, &num, @@ -1577,11 +1587,11 @@ static int qcow2_create2(const char *filename, int64_t total_size, } } - /* And if we're supposed to preallocate metadata, do that now */ + /* And if we're supposed to preallocate data, do that now */ if (prealloc) { BDRVQcowState *s = bs->opaque; qemu_co_mutex_lock(&s->lock); - ret = preallocate(bs); + ret = preallocate(bs, prealloc); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { error_setg_errno(errp, -ret, "Could not preallocate metadata"); @@ -1638,6 +1648,8 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options, prealloc = PREALLOC_OFF; } else if (!strcmp(options->value.s, "metadata")) { prealloc = PREALLOC_METADATA; + } else if (!strcmp(options->value.s, "full")) { + prealloc = PREALLOC_FULL; } else { error_setg(errp, "Invalid preallocation mode: '%s'", options->value.s); @@ -2229,7 +2241,7 @@ static QEMUOptionParameter qcow2_create_options[] = { { .name = BLOCK_OPT_PREALLOC, .type = OPT_STRING, - .help = "Preallocation mode (allowed values: off, metadata)" + .help = "Preallocation mode (allowed values: off, metadata, full)" }, { .name = BLOCK_OPT_LAZY_REFCOUNTS,