Received: from eggs.gnu.org ([208.118.235.92]:44805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uemi8-0005Lm-EJ for qemu-devel@nongnu.org; Tue, 21 May 2013 09:34:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uemi3-0005Rc-9B for qemu-devel@nongnu.org; Tue, 21 May 2013 09:34:40 -0400 Received: from mail-we0-x229.google.com ([2a00:1450:400c:c03::229]:34476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uemi3-0005RU-1g for qemu-devel@nongnu.org; Tue, 21 May 2013 09:34:35 -0400 Received: by mail-we0-f169.google.com with SMTP id q55so388200wes.28 for ; Tue, 21 May 2013 06:34:34 -0700 (PDT) Date: Tue, 21 May 2013 15:34:28 +0200 From: Stefan Hajnoczi Message-ID: <20130521133428.GA6631@stefanha-thinkpad.muc.redhat.com> References: <1368628476-19622-1-git-send-email-stefanha@redhat.com> <1368628476-19622-3-git-send-email-stefanha@redhat.com> <519A095D.4070808@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <519A095D.4070808@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 2/8] block: add basic backup support to block driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, xiawenc@linux.vnet.ibm.com, imain@redhat.com, Stefan Hajnoczi , dietmar@proxmox.com On Mon, May 20, 2013 at 01:30:37PM +0200, Paolo Bonzini wrote: > Il 15/05/2013 16:34, Stefan Hajnoczi ha scritto: > > + wait_for_overlapping_requests(job, start, end); > > + cow_request_begin(&cow_request, job, start, end); > > + > > + for (; start < end; start++) { > > + if (hbitmap_get(job->bitmap, start)) { > > + DPRINTF("brdv_co_backup_cow skip C%" PRId64 "\n", start); > > + continue; /* already copied */ > > + } > > + > > + /* immediately set bitmap (avoid coroutine race) */ > > + hbitmap_set(job->bitmap, start, 1); > > + > > HBitmap already has code for finding the next set bit, but you're not > using it. > > If you reverse the direction of the bitmap, you can use an HBitmapIter here: > > > > > + start = 0; > > + end = DIV_ROUND_UP(bdrv_getlength(bs) / BDRV_SECTOR_SIZE, > > + BACKUP_BLOCKS_PER_CLUSTER); > > + > > + job->bitmap = hbitmap_alloc(end, 0); > > + > > + before_write = bdrv_add_before_write_cb(bs, backup_before_write); > > + > > + DPRINTF("backup_run start %s %" PRId64 " %" PRId64 "\n", > > + bdrv_get_device_name(bs), start, end); > > + > > + for (; start < end; start++) { > > ... instead of iterating through each item manually. /** * hbitmap_iter_init: [...] * position of the iterator is also okay. However, concurrent resetting of * bits can lead to unexpected behavior if the iterator has not yet reached * those bits. */ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap *hb, uint64_t first); This worries me. We would initialize the bitmap to all 1s. Backing up a cluster resets the bit. But the documentation says it is not safe to reset bits while iterating? Stefan