qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Fam Zheng <famcool@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [Qemu-devel] [PATCH 12/12] Add disk_size field to BlockDriverState structure
Date: Sat, 18 Jun 2011 19:35:44 +0100	[thread overview]
Message-ID: <BANLkTincii_Bn4kCRGk2JyA4BQ+hrkGaOg@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=GKQo724CK2ULgjych2OP3hr6cyQ@mail.gmail.com>

On Sat, Jun 4, 2011 at 1:44 AM, Fam Zheng <famcool@gmail.com> 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 <famcool@gmail.com>
> ---
>  block/vmdk.c |    1 +
>  block_int.h  |    1 +
>  qemu-img.c   |    6 +++++-
>  3 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)
{
    BlockDriver *drv = bs->drv;

    if (!drv) {
        return -ENOMEDIUM;
    }

    if (drv->bdrv_get_allocated_file_size) {
        return drv->bdrv_get_allocated_file_size(bs, size);
    }

    if (bs->file) {
        return bdrv_get_allocated_file_size(bs->file, size);
    }
    return -ENOTSUP;
}

> @@ -607,6 +607,7 @@ static int vmdk_open_desc_file(BlockDriverState
> *bs, int flags)
>     extent = s->extents;
>     vmdk_parse_extents(buf, s->extents, bs->file->filename);
>     bs->total_sectors = extent->sectors;
> +    bs->disk_size = bdrv_getlength(bs->file) + bdrv_getlength(extent->file);

This should call bdrv_get_allocated_file_size() so add together the
actually allocated amount, not what bdrv_getlength() returns.

Stefan

  reply	other threads:[~2011-06-18 18:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-04  0:44 [Qemu-devel] [PATCH 12/12] Add disk_size field to BlockDriverState structure Fam Zheng
2011-06-18 18:35 ` Stefan Hajnoczi [this message]
2011-06-20  5:37   ` Fam Zheng
2011-06-20  6:08     ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTincii_Bn4kCRGk2JyA4BQ+hrkGaOg@mail.gmail.com \
    --to=stefanha@gmail.com \
    --cc=famcool@gmail.com \
    --cc=hch@lst.de \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).