From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asrbR-0001mk-QE for qemu-devel@nongnu.org; Wed, 20 Apr 2016 08:51:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asrbQ-0003aH-Qc for qemu-devel@nongnu.org; Wed, 20 Apr 2016 08:51:33 -0400 Date: Wed, 20 Apr 2016 14:51:25 +0200 From: Kevin Wolf Message-ID: <20160420125125.GK6517@noname.str.redhat.com> References: <1461106788-14285-1-git-send-email-mreitz@redhat.com> <1461106788-14285-3-git-send-email-mreitz@redhat.com> <20160420121341.GH6517@noname.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160420121341.GH6517@noname.str.redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH for-2.6 2/2] block/mirror: Refresh stale bitmap iterator cache List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Fam Zheng , qemu-devel@nongnu.org, qemu-block@nongnu.org Am 20.04.2016 um 14:13 hat Kevin Wolf geschrieben: > Am 20.04.2016 um 00:59 hat Max Reitz geschrieben: > > If the drive's dirty bitmap is dirtied while the mirror operation is > > running, the cache of the iterator used by the mirror code may become > > stale and not contain all dirty bits. > > > > This only becomes an issue if we are looking for contiguously dirty > > chunks on the drive. In that case, we can easily detect the discrepancy > > and just refresh the iterator if one occurs. > > > > Signed-off-by: Max Reitz > > --- > > block/mirror.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/block/mirror.c b/block/mirror.c > > index 2714a77..9df1fae 100644 > > --- a/block/mirror.c > > +++ b/block/mirror.c > > @@ -334,6 +334,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) > > } > > > > hbitmap_next = hbitmap_iter_next(&s->hbi); > > + if (hbitmap_next > next_sector || hbitmap_next < 0) { > > + /* The bitmap iterator's cache is stale, refresh it */ > > + bdrv_set_dirty_iter(&s->hbi, next_sector); > > + hbitmap_next = hbitmap_iter_next(&s->hbi); > > + } > > assert(hbitmap_next == next_sector); > > The iterator doesn't seem to be used afterwards anyway, so why not just > use next_sector and stop using the iterator when we already know what > result we want to get? And of course I read that code completely wrong because in reality &s->hbi isn't local. Seems to be the right way to do things then. Kevin