From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV0qM-0007mr-JX for qemu-devel@nongnu.org; Wed, 24 Apr 2013 10:38:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UV0qH-0007bq-Uc for qemu-devel@nongnu.org; Wed, 24 Apr 2013 10:38:46 -0400 Received: from mail-ea0-x22d.google.com ([2a00:1450:4013:c01::22d]:49450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV0qH-0007ba-OH for qemu-devel@nongnu.org; Wed, 24 Apr 2013 10:38:41 -0400 Received: by mail-ea0-f173.google.com with SMTP id m14so801162eaj.32 for ; Wed, 24 Apr 2013 07:38:40 -0700 (PDT) Date: Wed, 24 Apr 2013 16:38:37 +0200 From: Stefan Hajnoczi Message-ID: <20130424143837.GE24635@stefanha-thinkpad.redhat.com> References: <80ad906f450a3279d16c047af973d3ce75bc7b51.1366726446.git.jcody@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <80ad906f450a3279d16c047af973d3ce75bc7b51.1366726446.git.jcody@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 4/5] block: add read-only support to VHDX image format. 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 Tue, Apr 23, 2013 at 10:24:23AM -0400, Jeff Cody wrote: > +static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num, > + int nb_sectors, vhdx_sector_info *sinfo) > +{ > + uint32_t block_offset; > + > + sinfo->bat_idx = sector_num >> s->sectors_per_block_bits; > + /* effectively a modulo - this gives us the offset into the block > + * (in sector sizes) for our sector number */ > + block_offset = sector_num - (sinfo->bat_idx << s->sectors_per_block_bits); > + /* the chunk ratio gives us the interleaving of the sector > + * bitmaps, so we need to advance our page block index by the > + * sector bitmaps entry number */ > + sinfo->bat_idx += sinfo->bat_idx >> s->chunk_ratio_bits; > + > + /* the number of sectors we can read/write in this cycle */ > + sinfo->sectors_avail = s->sectors_per_block - block_offset; > + > + sinfo->bytes_left = sinfo->sectors_avail << s->logical_sector_size_bits; > + > + if (sinfo->sectors_avail > nb_sectors) { > + sinfo->sectors_avail = nb_sectors; > + } > + > + sinfo->bytes_avail = sinfo->sectors_avail << s->logical_sector_size_bits; > + > + sinfo->file_offset = s->bat[sinfo->bat_idx] >> VHDX_BAT_FILE_OFF_BITS; If my calculation is correct, a 2 TB image would result in 16 MB of BAT entries for payload blocks. The BAT entries for sector bitmap blocks would be smaller. On a slow disk the startup time with many VHDX files could be be several seconds though since we need to read all this data into memory. Perhaps something to consider for the future but not critical right now.