From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhVBQ-000467-Hn for qemu-devel@nongnu.org; Mon, 05 May 2014 22:32:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhVBK-0005t6-EC for qemu-devel@nongnu.org; Mon, 05 May 2014 22:32:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65336) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhVBK-0005sw-5b for qemu-devel@nongnu.org; Mon, 05 May 2014 22:32:34 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s462WXWO020472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 5 May 2014 22:32:33 -0400 From: Fam Zheng Date: Tue, 6 May 2014 10:32:44 +0800 Message-Id: <1399343564-17687-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v2] vmdk: Optimize cluster allocation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi On mounted NFS filesystem, ftruncate is much much slower than doing a zero write. Changing this significantly speeds up cluster allocation. Comparing by converting a cirros image (296M) to VMDK on an NFS mount point, over 1Gbe LAN: $ time qemu-img convert cirros-0.3.1.img /mnt/a.raw -O vmdk Before: real 0m26.464s user 0m0.133s sys 0m0.527s After: real 0m2.120s user 0m0.080s sys 0m0.197s Signed-off-by: Fam Zheng --- V2: Fix cluster_offset check. (Kevin) Signed-off-by: Fam Zheng --- block/vmdk.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 06a1f9f..98d2d56 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1037,6 +1037,7 @@ static int get_cluster_offset(BlockDriverState *bs, int min_index, i, j; uint32_t min_count, *l2_table; bool zeroed = false; + int64_t ret; if (m_data) { m_data->valid = 0; @@ -1110,12 +1111,20 @@ static int get_cluster_offset(BlockDriverState *bs, } /* Avoid the L2 tables update for the images that have snapshots. */ - *cluster_offset = bdrv_getlength(extent->file); + ret = bdrv_getlength(extent->file); + if (ret < 0 || + ret & ((extent->cluster_sectors << BDRV_SECTOR_BITS) - 1)) { + return VMDK_ERROR; + } + *cluster_offset = ret; if (!extent->compressed) { - bdrv_truncate( - extent->file, - *cluster_offset + (extent->cluster_sectors << 9) - ); + ret = bdrv_write_zeroes(extent->file, + *cluster_offset >> BDRV_SECTOR_BITS, + extent->cluster_sectors, + 0); + if (ret) { + return VMDK_ERROR; + } } *cluster_offset >>= 9; -- 1.9.2