From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:47338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaU7k-0006s0-Fw for qemu-devel@nongnu.org; Tue, 13 Dec 2011 10:18:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaU7j-0004WR-52 for qemu-devel@nongnu.org; Tue, 13 Dec 2011 10:18:32 -0500 Received: from mail-fx0-f45.google.com ([209.85.161.45]:38064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaU7i-0004K7-VU for qemu-devel@nongnu.org; Tue, 13 Dec 2011 10:18:31 -0500 Received: by mail-fx0-f45.google.com with SMTP id o26so256025faa.4 for ; Tue, 13 Dec 2011 07:18:30 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20111213141437.GA2387@amt.cnet> References: <1323784351-25531-1-git-send-email-stefanha@linux.vnet.ibm.com> <1323784351-25531-4-git-send-email-stefanha@linux.vnet.ibm.com> <20111213141437.GA2387@amt.cnet> Date: Tue, 13 Dec 2011 15:18:30 +0000 Message-ID: From: Stefan Hajnoczi Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 3/9] block: add image streaming block job List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcelo Tosatti Cc: Kevin Wolf , Luiz Capitulino , Stefan Hajnoczi , qemu-devel@nongnu.org On Tue, Dec 13, 2011 at 2:14 PM, Marcelo Tosatti wrot= e: > On Tue, Dec 13, 2011 at 01:52:25PM +0000, Stefan Hajnoczi wrote: >> Signed-off-by: Stefan Hajnoczi >> --- >> =A0Makefile.objs =A0| =A0 =A01 + >> =A0block/stream.c | =A0121 +++++++++++++++++++++++++++++++++++++++++++++= +++++++++++ >> =A0block_int.h =A0 =A0| =A0 =A03 + >> =A0trace-events =A0 | =A0 =A04 ++ >> =A04 files changed, 129 insertions(+), 0 deletions(-) >> =A0create 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 +=3D qcow2.o qcow2-refcount.o qcow2-clu= ster.o qcow2-snapshot.o qcow >> =A0block-nested-y +=3D qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-= cluster.o >> =A0block-nested-y +=3D qed-check.o >> =A0block-nested-y +=3D parallels.o nbd.o blkdebug.o sheepdog.o blkverify= .o >> +block-nested-y +=3D stream.o >> =A0block-nested-$(CONFIG_WIN32) +=3D raw-win32.o >> =A0block-nested-$(CONFIG_POSIX) +=3D raw-posix.o >> =A0block-nested-$(CONFIG_LIBISCSI) +=3D 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: >> + * =A0Stefan Hajnoczi =A0 >> + * >> + * 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 { >> + =A0 =A0/* >> + =A0 =A0 * Size of data buffer for populating the image file. =A0This s= hould be large >> + =A0 =A0 * enough to process multiple clusters in a single call, so tha= t populating >> + =A0 =A0 * contiguous regions of the image is efficient. >> + =A0 =A0 */ >> + =A0 =A0STREAM_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ >> +}; >> + >> +typedef struct StreamBlockJob { >> + =A0 =A0BlockJob common; >> + =A0 =A0BlockDriverState *base; >> +} StreamBlockJob; >> + >> +static int coroutine_fn stream_populate(BlockDriverState *bs, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0int64_t sector_num, int nb_sectors, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0void *buf) >> +{ >> + =A0 =A0struct iovec iov =3D { >> + =A0 =A0 =A0 =A0.iov_base =3D buf, >> + =A0 =A0 =A0 =A0.iov_len =A0=3D nb_sectors * BDRV_SECTOR_SIZE, >> + =A0 =A0}; >> + =A0 =A0QEMUIOVector qiov; >> + >> + =A0 =A0qemu_iovec_init_external(&qiov, &iov, 1); >> + >> + =A0 =A0/* Copy-on-read the unallocated clusters */ >> + =A0 =A0return bdrv_co_readv(bs, sector_num, nb_sectors, &qiov); >> +} >> + >> +static void coroutine_fn stream_run(void *opaque) >> +{ >> + =A0 =A0StreamBlockJob *s =3D opaque; >> + =A0 =A0BlockDriverState *bs =3D s->common.bs; >> + =A0 =A0int64_t sector_num, end; >> + =A0 =A0int ret =3D 0; >> + =A0 =A0int n; >> + =A0 =A0void *buf; >> + >> + =A0 =A0buf =3D qemu_blockalign(bs, STREAM_BUFFER_SIZE); >> + =A0 =A0s->common.len =3D bdrv_getlength(bs); >> + =A0 =A0bdrv_get_geometry(bs, (uint64_t *)&end); >> + >> + =A0 =A0bdrv_enable_zero_detection(bs); >> + =A0 =A0bdrv_enable_copy_on_read(bs); >> + >> + =A0 =A0for (sector_num =3D 0; sector_num < end; sector_num +=3D n) { >> + =A0 =A0 =A0 =A0if (block_job_is_cancelled(&s->common)) { >> + =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 =A0} >> + >> + =A0 =A0 =A0 =A0/* TODO rate-limit */ >> + =A0 =A0 =A0 =A0/* Note that even when no rate limit is applied we need= to yield with >> + =A0 =A0 =A0 =A0 * no pending I/O here so that qemu_aio_flush() is able= to return. >> + =A0 =A0 =A0 =A0 */ >> + =A0 =A0 =A0 =A0co_sleep_ns(rt_clock, 0); >> + >> + =A0 =A0 =A0 =A0ret =3D bdrv_co_is_allocated(bs, sector_num, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ST= REAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); >> + =A0 =A0 =A0 =A0trace_stream_one_iteration(s, sector_num, n, ret); >> + =A0 =A0 =A0 =A0if (ret =3D=3D 0) { >> + =A0 =A0 =A0 =A0 =A0 =A0ret =3D stream_populate(bs, sector_num, n, buf)= ; >> + =A0 =A0 =A0 =A0} >> + =A0 =A0 =A0 =A0if (ret < 0) { >> + =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 =A0} >> + >> + =A0 =A0 =A0 =A0/* Publish progress */ >> + =A0 =A0 =A0 =A0s->common.offset +=3D n * BDRV_SECTOR_SIZE; >> + =A0 =A0} >> + >> + =A0 =A0bdrv_disable_copy_on_read(bs); >> + =A0 =A0bdrv_disable_zero_detection(bs); >> + >> + =A0 =A0if (sector_num =3D=3D end && ret =3D=3D 0) { >> + =A0 =A0 =A0 =A0bdrv_change_backing_file(bs, NULL, NULL); >> + =A0 =A0} > > In fact there is no need for a new command to switch backing file, > it can be done here for the shared base case also. Agreed. Stefan