From: Kevin Wolf <kwolf@redhat.com>
To: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 3/9] block: add image streaming block job
Date: Wed, 14 Dec 2011 14:59:03 +0100 [thread overview]
Message-ID: <4EE8ABA7.4030303@redhat.com> (raw)
In-Reply-To: <1323784351-25531-4-git-send-email-stefanha@linux.vnet.ibm.com>
Am 13.12.2011 14:52, schrieb Stefan Hajnoczi:
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
> Makefile.objs | 1 +
> block/stream.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> block_int.h | 3 +
> trace-events | 4 ++
> 4 files changed, 129 insertions(+), 0 deletions(-)
> create mode 100644 block/stream.c
>
> diff --git a/Makefile.objs b/Makefile.objs
> index d737d81..025cc08 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -34,6 +34,7 @@ block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow
> block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
> block-nested-y += qed-check.o
> block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
> +block-nested-y += stream.o
> block-nested-$(CONFIG_WIN32) += raw-win32.o
> block-nested-$(CONFIG_POSIX) += raw-posix.o
> block-nested-$(CONFIG_LIBISCSI) += iscsi.o
> diff --git a/block/stream.c b/block/stream.c
> new file mode 100644
> index 0000000..7d362ab
> --- /dev/null
> +++ b/block/stream.c
> @@ -0,0 +1,121 @@
> +/*
> + * Image streaming
> + *
> + * Copyright IBM, Corp. 2011
> + *
> + * Authors:
> + * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#include "trace.h"
> +#include "block_int.h"
> +
> +enum {
> + /*
> + * Size of data buffer for populating the image file. This should be large
> + * enough to process multiple clusters in a single call, so that populating
> + * contiguous regions of the image is efficient.
> + */
> + STREAM_BUFFER_SIZE = 512 * 1024, /* in bytes */
> +};
> +
> +typedef struct StreamBlockJob {
> + BlockJob common;
> + BlockDriverState *base;
> +} StreamBlockJob;
> +
> +static int coroutine_fn stream_populate(BlockDriverState *bs,
> + int64_t sector_num, int nb_sectors,
> + void *buf)
> +{
> + struct iovec iov = {
> + .iov_base = buf,
> + .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
> + };
> + QEMUIOVector qiov;
> +
> + qemu_iovec_init_external(&qiov, &iov, 1);
> +
> + /* Copy-on-read the unallocated clusters */
> + return bdrv_co_readv(bs, sector_num, nb_sectors, &qiov);
> +}
> +
> +static void coroutine_fn stream_run(void *opaque)
> +{
> + StreamBlockJob *s = opaque;
> + BlockDriverState *bs = s->common.bs;
> + int64_t sector_num, end;
> + int ret = 0;
> + int n;
> + void *buf;
> +
> + buf = qemu_blockalign(bs, STREAM_BUFFER_SIZE);
> + s->common.len = bdrv_getlength(bs);
> + bdrv_get_geometry(bs, (uint64_t *)&end);
> +
> + bdrv_enable_zero_detection(bs);
I still don't agree with this all-or-nothing switch. The default that
you want to have is zero detection on COR, but no additional overhead
for guest-initiated writes.
> + bdrv_enable_copy_on_read(bs);
> +
> + for (sector_num = 0; sector_num < end; sector_num += n) {
> + if (block_job_is_cancelled(&s->common)) {
> + break;
> + }
> +
> + /* TODO rate-limit */
> + /* Note that even when no rate limit is applied we need to yield with
> + * no pending I/O here so that qemu_aio_flush() is able to return.
> + */
> + co_sleep_ns(rt_clock, 0);
> +
> + ret = bdrv_co_is_allocated(bs, sector_num,
> + STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
> + trace_stream_one_iteration(s, sector_num, n, ret);
> + if (ret == 0) {
> + ret = stream_populate(bs, sector_num, n, buf);
> + }
> + if (ret < 0) {
> + break;
> + }
> +
> + /* Publish progress */
> + s->common.offset += n * BDRV_SECTOR_SIZE;
> + }
> +
> + bdrv_disable_copy_on_read(bs);
> + bdrv_disable_zero_detection(bs);
> +
> + if (sector_num == end && ret == 0) {
> + bdrv_change_backing_file(bs, NULL, NULL);
Need to check the return value.
Kevin
next prev parent reply other threads:[~2011-12-14 13:56 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-13 13:52 [Qemu-devel] [PATCH v3 0/9] block: generic image streaming Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 1/9] coroutine: add co_sleep_ns() coroutine sleep function Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 2/9] block: add BlockJob interface for long-running operations Stefan Hajnoczi
2011-12-14 13:51 ` Kevin Wolf
2011-12-15 8:50 ` Stefan Hajnoczi
2011-12-15 10:40 ` Marcelo Tosatti
2011-12-16 8:09 ` Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 3/9] block: add image streaming block job Stefan Hajnoczi
2011-12-13 14:14 ` Marcelo Tosatti
2011-12-13 15:18 ` Stefan Hajnoczi
2011-12-14 13:59 ` Kevin Wolf [this message]
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 4/9] block: rate-limit streaming operations Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 5/9] qmp: add block_stream command Stefan Hajnoczi
2012-01-04 12:59 ` Luiz Capitulino
2012-01-04 13:11 ` Luiz Capitulino
2012-01-05 13:48 ` Stefan Hajnoczi
2012-01-05 14:16 ` [Qemu-devel] QMP: Supporting off tree APIs Luiz Capitulino
2012-01-05 15:35 ` [Qemu-devel] [libvirt] " Eric Blake
2012-01-05 15:56 ` Anthony Liguori
2012-01-05 20:26 ` Luiz Capitulino
2012-01-06 11:06 ` Stefan Hajnoczi
2012-01-06 12:45 ` Luiz Capitulino
2012-01-06 15:08 ` Anthony Liguori
2012-01-06 19:42 ` Luiz Capitulino
2012-01-10 19:18 ` Anthony Liguori
2012-01-10 20:55 ` Luiz Capitulino
2012-01-10 21:02 ` Anthony Liguori
2012-01-11 1:41 ` Luiz Capitulino
2012-01-05 14:20 ` [Qemu-devel] [PATCH v3 5/9] qmp: add block_stream command Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 6/9] qmp: add block_job_set_speed command Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 7/9] qmp: add block_job_cancel command Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 8/9] qmp: add query-block-jobs Stefan Hajnoczi
2011-12-14 14:54 ` Kevin Wolf
2011-12-15 8:27 ` Stefan Hajnoczi
2011-12-15 10:34 ` Kevin Wolf
2011-12-15 11:30 ` Luiz Capitulino
2011-12-15 12:00 ` Stefan Hajnoczi
2011-12-15 12:09 ` Luiz Capitulino
2011-12-15 12:37 ` Kevin Wolf
2011-12-15 12:51 ` Stefan Hajnoczi
2012-01-04 13:17 ` Luiz Capitulino
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 9/9] test: add image streaming test cases Stefan Hajnoczi
2011-12-13 14:12 ` [Qemu-devel] [PATCH v3 0/9] block: generic image streaming Yibin Shen
2011-12-13 15:18 ` Stefan Hajnoczi
2011-12-14 1:42 ` Yibin Shen
2011-12-14 10:50 ` 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=4EE8ABA7.4030303@redhat.com \
--to=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.