From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V41Gb-0003o5-Hz for qemu-devel@nongnu.org; Tue, 30 Jul 2013 00:10:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V41GV-00023Z-ES for qemu-devel@nongnu.org; Tue, 30 Jul 2013 00:10:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2731) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V41GV-00023L-2m for qemu-devel@nongnu.org; Tue, 30 Jul 2013 00:10:27 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6U4AP08029783 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 30 Jul 2013 00:10:26 -0400 Date: Tue, 30 Jul 2013 12:10:14 +0800 From: Fam Zheng Message-ID: <20130730041014.GC31918@T430s.nay.redhat.com> References: <7afd1d43841f39d8445a6c9800d562e9cbea37f0.1374687002.git.jcody@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7afd1d43841f39d8445a6c9800d562e9cbea37f0.1374687002.git.jcody@redhat.com> Subject: Re: [Qemu-devel] [PATCH 9/9] block: vhdx write support Reply-To: famz@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jeff Cody Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Wed, 07/24 13:54, Jeff Cody wrote: > This adds support for writing to VHDX image files, using coroutines. > Writes into the BAT table goes through the VHDX log. Currently, BAT > table writes occur when expanding a dynamic VHDX file, and allocating a > new BAT entry. > > Signed-off-by: Jeff Cody > --- > block/vhdx.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 147 insertions(+), 2 deletions(-) > > diff --git a/block/vhdx.c b/block/vhdx.c > index a8dd6d7..791c6dc 100644 > --- a/block/vhdx.c > +++ b/block/vhdx.c > @@ -831,7 +831,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags) > vhdx_update_headers(bs, s, false, NULL); > } > > - /* TODO: differencing files, write */ > + /* TODO: differencing files */ > > return 0; > fail: > @@ -963,7 +963,45 @@ exit: > return ret; > } > > +/* > + * Allocate a new payload block at the end of the file. > + * > + * Allocation will happen at 1MB alignment inside the file > + * > + * Returns the file offset start of the new payload block > + */ > +static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s, > + uint64_t *new_offset) > +{ > + *new_offset = bdrv_getlength(bs->file); > > + /* per the spec, the address for a block is in units of 1MB */ > + if (*new_offset % (1024*1024)) { > + *new_offset = ((*new_offset >> 20) + 1) << 20; /* round up to 1MB */ You can use ROUND_UP() macro here: *new_offset = ROUND_UP(*new_offset, 1 << 20); Fam