Received: from eggs.gnu.org ([2001:4830:134:3::10]:51939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wno0A-0004JK-1W for qemu-devel@nongnu.org; Fri, 23 May 2014 07:51:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wnnzz-00022o-UW for qemu-devel@nongnu.org; Fri, 23 May 2014 07:51:05 -0400 Received: from mail-we0-x234.google.com ([2a00:1450:400c:c03::234]:51445) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wnnzz-00022W-NH for qemu-devel@nongnu.org; Fri, 23 May 2014 07:50:55 -0400 Received: by mail-we0-f180.google.com with SMTP id t61so4736926wes.25 for ; Fri, 23 May 2014 04:50:54 -0700 (PDT) Date: Fri, 23 May 2014 13:50:51 +0200 From: Stefan Hajnoczi Message-ID: <20140523115051.GB1260@stefanha-thinkpad.redhat.com> References: <1400137368-8945-1-git-send-email-famz@redhat.com> <1400137368-8945-3-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1400137368-8945-3-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v4 2/2] vmdk: Optimize cluster allocation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi On Thu, May 15, 2014 at 03:02:48PM +0800, Fam Zheng wrote: > @@ -397,6 +397,7 @@ static int vmdk_add_extent(BlockDriverState *bs, > { > VmdkExtent *extent; > BDRVVmdkState *s = bs->opaque; > + int64_t ret; > > if (cluster_sectors > 0x200000) { > /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */ > @@ -428,6 +429,12 @@ static int vmdk_add_extent(BlockDriverState *bs, > extent->l2_size = l2_size; > extent->cluster_sectors = flat ? sectors : cluster_sectors; > > + ret = bdrv_getlength(extent->file); > + if (ret < 0) { > + return ret; We need to clean up here. extent isn't initialized fully and s->num_extents needs to be decremented. > + } > + extent->next_cluster_sector = DIV_ROUND_UP(ret, BDRV_SECTOR_SIZE); Should this be rounded up to clusters instead of just 512-byte sectors? Otherwise the next allocated cluster might not be aligned. > + > if (s->num_extents > 1) { > extent->end_sector = (*(extent - 1)).end_sector + extent->sectors; > } else { > @@ -954,57 +961,96 @@ static int vmdk_refresh_limits(BlockDriverState *bs) > return 0; > } > > +/** > + * get_whole_cluster > + * > + * Copy backing file's cluster that covers @sector_num, otherwise write zero, > + * to the cluster at @cluster_sector_num. > + * > + * If @skip_start < @skip_end, the relative range [@skip_start, @skip_end) is > + * not copied or written, and leave it for call to write user data in the > + * request. skip_start/skip_end are in sectors, please include the unit in the argument name.