From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:39650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlIKK-0004gC-V3 for qemu-devel@nongnu.org; Thu, 12 Jan 2012 05:56:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlIKJ-0007zg-QJ for qemu-devel@nongnu.org; Thu, 12 Jan 2012 05:56:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58728) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlIKJ-0007zU-Je for qemu-devel@nongnu.org; Thu, 12 Jan 2012 05:56:11 -0500 Message-ID: <4F0EBD12.7080702@redhat.com> Date: Thu, 12 Jan 2012 11:59:30 +0100 From: Kevin Wolf MIME-Version: 1.0 References: <1325858501-25741-1-git-send-email-stefanha@linux.vnet.ibm.com> <1325858501-25741-5-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1325858501-25741-5-git-send-email-stefanha@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4 04/15] block: add image streaming block job List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Marcelo Tosatti , qemu-devel@nongnu.org, Luiz Capitulino Am 06.01.2012 15:01, schrieb Stefan Hajnoczi: > Signed-off-by: Stefan Hajnoczi > --- > Makefile.objs | 1 + > block/stream.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > block_int.h | 3 + > trace-events | 4 ++ > 4 files changed, 127 insertions(+), 0 deletions(-) > create mode 100644 block/stream.c > > diff --git a/Makefile.objs b/Makefile.objs > index 64d84de..fde3769 100644 > --- a/Makefile.objs > +++ b/Makefile.objs > @@ -35,6 +35,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..8ff98cf > --- /dev/null > +++ b/block/stream.c > @@ -0,0 +1,119 @@ > +/* > + * Image streaming > + * > + * Copyright IBM, Corp. 2011 > + * > + * Authors: > + * Stefan Hajnoczi > + * > + * 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); No error check? > + bdrv_get_geometry(bs, (uint64_t *)&end); Why call bdrv_getlength() twice? end = s->common.len >> BDRV_SECTOR_BITS should be the same. Kevin