qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v6] block:add-cow file format
Date: Thu, 5 Jan 2012 13:46:08 -0200	[thread overview]
Message-ID: <20120105154607.GA6894@amt.cnet> (raw)
In-Reply-To: <1325151419-26228-1-git-send-email-wdongxu@linux.vnet.ibm.com>

On Thu, Dec 29, 2011 at 05:36:59PM +0800, Dong Xu Wang wrote:
> From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> 
> Introduce a new file format: add-cow. The usage can be found in add-cow.txt of
> this patch.
> 
> CC: Kevin Wolf <kwolf@redhat.com>
> CC: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> ---
> After applying this patch, qemu might can not compile, need apply this patch first:
> http://lists.gnu.org/archive/html/qemu-devel/2011-12/msg02527.html
> 
>  Makefile.objs          |    1 +
>  block.c                |    2 +-
>  block.h                |    1 +
>  block/add-cow.c        |  429 ++++++++++++++++++++++++++++++++++++++++++++++++
>  block_int.h            |    1 +
>  docs/specs/add-cow.txt |   72 ++++++++
>  6 files changed, 505 insertions(+), 1 deletions(-)
>  create mode 100644 block/add-cow.c
>  create mode 100644 docs/specs/add-cow.txt
> 


> +    s->bitmap_size = ((bs->total_sectors + 7) >> 3);
> +    s->bitmap = qemu_blockalign(bs, s->bitmap_size);
> +
> +    ret = bdrv_pread(bs->file, sizeof(header), s->bitmap,
> +            s->bitmap_size);
> +    if (ret != s->bitmap_size) {
> +        goto fail;
> +    }

As noted previously, it is not acceptable to read the entire bitmap in
memory since it might be very large. A cache, which limits the in-memory
size of the bitmap, must be created. In the qcow2-cache.c file you can 
find an example (thats for qcow2 metadata cache). You can divide the
bitmap in chunks of say, 4k, and have:

int is_bit_set(int64_t bitnum, BlockDriverState *bs)
{
    int64_t bitmap_entry = bitnum >> bits_per_entry;

    if (!is_in_bitmap_cache(bs, bitmap_entry))
        read_from_disk(bs, bitmap_entry);

    return lookup_bitmap_cache(bs, bitnum);
}

And then limit the cache to a few megabytes.

Also when setting a bit you must update cache and write
to disk.

> +
> +    if (s->image_file[0] == '\0') {
> +        ret = -ENOENT;
> +        goto fail;
> +    }
> +
> +    ret = bdrv_file_open(&backing_bs, bs->backing_file, 0);
> +    if (ret < 0) {
> +        return ret;
> +    }
> +    bdrv_delete(backing_bs);
> +
> +    s->image_hd = bdrv_new("");
> +
> +    if (path_has_protocol(s->image_file)) {
> +        pstrcpy(image_filename, sizeof(image_filename),
> +                s->image_file);
> +    } else {
> +        path_combine(image_filename, sizeof(image_filename),
> +                     bs->filename, s->image_file);
> +    }
> +
> +    image_drv = bdrv_find_format("raw");
> +    ret = bdrv_open(s->image_hd, image_filename, flags, image_drv);
> +    if (ret < 0) {
> +        bdrv_delete(s->image_hd);
> +        s->image_hd = NULL;
> +        goto fail;
> +    }

Please make sure it is possible to create a snapshot with the
snapshot_blkdev command, of a raw image. It is necessary for live block
copy, as described here:

http://patchwork.ozlabs.org/patch/134257/

Also please update that document, later, with raw examples.

Thanks

  parent reply	other threads:[~2012-01-05 15:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-29  9:36 [Qemu-devel] [PATCH v6] block:add-cow file format Dong Xu Wang
2011-12-30 14:09 ` Stefan Hajnoczi
2011-12-31  9:17   ` Dong Xu Wang
2012-01-01 16:56     ` Stefan Hajnoczi
2012-01-05 15:46 ` Marcelo Tosatti [this message]
2012-01-06  8:22   ` Stefan Hajnoczi
2012-01-09  5:18     ` Dong Xu Wang

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=20120105154607.GA6894@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=wdongxu@linux.vnet.ibm.com \
    /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).