From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsVfu-00068T-EB for qemu-devel@nongnu.org; Thu, 05 Jun 2014 07:17:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsVfl-0000D6-D7 for qemu-devel@nongnu.org; Thu, 05 Jun 2014 07:17:38 -0400 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:48250) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsVfl-0000CY-28 for qemu-devel@nongnu.org; Thu, 05 Jun 2014 07:17:29 -0400 Received: by mail-wi0-f173.google.com with SMTP id bs8so10243788wib.6 for ; Thu, 05 Jun 2014 04:17:28 -0700 (PDT) Date: Thu, 5 Jun 2014 13:17:24 +0200 From: Stefan Hajnoczi Message-ID: <20140605111724.GI27366@stefanha-thinkpad.redhat.com> References: <1401939756-11150-1-git-send-email-famz@redhat.com> <1401939756-11150-2-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1401939756-11150-2-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/3] mirror: Go through ready -> complete process for 0 len image List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , jcody@redhat.com, qemu-devel@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini On Thu, Jun 05, 2014 at 11:42:34AM +0800, Fam Zheng wrote: > diff --git a/block/mirror.c b/block/mirror.c > index 94c8661..2bef5f3 100644 > --- a/block/mirror.c > +++ b/block/mirror.c > @@ -324,9 +324,18 @@ static void coroutine_fn mirror_run(void *opaque) > } > > s->common.len = bdrv_getlength(bs); > - if (s->common.len <= 0) { > + if (s->common.len < 0) { > ret = s->common.len; > goto immediate_exit; > + } else if (s->common.len == 0) { > + /* Report BLOCK_JOB_READY and wait for complete. */ > + block_job_ready(&s->common); > + s->synced = true; > + while (!block_job_is_cancelled(&s->common) && !s->should_complete) { > + block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, SLICE_TIME); Please take a look at block_job_resume() and how it's used when cancelling or completing block jobs. There is no need to sleep, instead we can yield until we get resumed.