From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:59663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYXBu-00066D-Tf for qemu-devel@nongnu.org; Mon, 20 Jun 2011 01:38:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QYXBt-0000Og-Vk for qemu-devel@nongnu.org; Mon, 20 Jun 2011 01:38:30 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:35599) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYXBt-0000OP-QZ for qemu-devel@nongnu.org; Mon, 20 Jun 2011 01:38:29 -0400 Received: by pzk30 with SMTP id 30so3521232pzk.4 for ; Sun, 19 Jun 2011 22:38:28 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Fam Zheng Date: Mon, 20 Jun 2011 13:37:48 +0800 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 12/12] Add disk_size field to BlockDriverState structure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , qemu-devel@nongnu.org, Christoph Hellwig Is there any difference between bdrv_getlength and bdrv_get_allocated_file_size for bs-file? If not, I can simplify it by reusing it in two raw devices. On Sun, Jun 19, 2011 at 2:35 AM, Stefan Hajnoczi wrote= : > On Sat, Jun 4, 2011 at 1:44 AM, Fam Zheng wrote: >> The `qemu-img info` results for mono flat image are no longer >> accurate, as the "disk size" was the length of bs->file, which is not >> the case for multi file images (such as vmdk images with multiple >> files). >> The new field disk_size in BlockDriverState can be used by block >> driver to tell the exact disk size of block image (only valid if the >> field is set to non-zero). >> >> Signed-off-by: Fam Zheng >> --- >> =C2=A0block/vmdk.c | =C2=A0 =C2=A01 + >> =C2=A0block_int.h =C2=A0| =C2=A0 =C2=A01 + >> =C2=A0qemu-img.c =C2=A0 | =C2=A0 =C2=A06 +++++- >> =C2=A03 files changed, 7 insertions(+), 1 deletions(-) > > Instead of introducing a variable please add a new BlockDriver > .bdrv_get_allocated_file_size() function pointer and move > get_allocated_file_size() from qemu-img.c into block/raw-posix.c and > block/raw-win32.c. > > qemu-img.c should call bdrv_get_allocated_file_size() and > bdrv_get_allocated_file_size() could look like this: > > int bdrv_get_allocated_file_size(BlockDriverState *bs, int64_t *size) > { > =C2=A0 =C2=A0BlockDriver *drv =3D bs->drv; > > =C2=A0 =C2=A0if (!drv) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENOMEDIUM; > =C2=A0 =C2=A0} > > =C2=A0 =C2=A0if (drv->bdrv_get_allocated_file_size) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0return drv->bdrv_get_allocated_file_size(bs, s= ize); > =C2=A0 =C2=A0} > > =C2=A0 =C2=A0if (bs->file) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0return bdrv_get_allocated_file_size(bs->file, = size); > =C2=A0 =C2=A0} > =C2=A0 =C2=A0return -ENOTSUP; > } > >> @@ -607,6 +607,7 @@ static int vmdk_open_desc_file(BlockDriverState >> *bs, int flags) >> =C2=A0 =C2=A0 extent =3D s->extents; >> =C2=A0 =C2=A0 vmdk_parse_extents(buf, s->extents, bs->file->filename); >> =C2=A0 =C2=A0 bs->total_sectors =3D extent->sectors; >> + =C2=A0 =C2=A0bs->disk_size =3D bdrv_getlength(bs->file) + bdrv_getleng= th(extent->file); > > This should call bdrv_get_allocated_file_size() so add together the > actually allocated amount, not what bdrv_getlength() returns. > > Stefan > --=20 Best regards! Fam Zheng