From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeOIl-0004wL-Hd for qemu-devel@nongnu.org; Mon, 20 May 2013 07:30:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UeOIg-0003cZ-Or for qemu-devel@nongnu.org; Mon, 20 May 2013 07:30:51 -0400 Received: from mail-yh0-x22a.google.com ([2607:f8b0:4002:c01::22a]:49771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeOIg-0003cT-Hs for qemu-devel@nongnu.org; Mon, 20 May 2013 07:30:46 -0400 Received: by mail-yh0-f42.google.com with SMTP id t59so1578166yho.1 for ; Mon, 20 May 2013 04:30:46 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <519A095D.4070808@redhat.com> Date: Mon, 20 May 2013 13:30:37 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1368628476-19622-1-git-send-email-stefanha@redhat.com> <1368628476-19622-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1368628476-19622-3-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: Stefan Hajnoczi Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, dietmar@proxmox.com, imain@redhat.com, xiawenc@linux.vnet.ibm.com 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. Paolo > + if (block_job_is_cancelled(&job->common)) { > + break; > + } > + > + /* we need to yield so that qemu_aio_flush() returns. > + * (without, VM does not reboot) > + */ > + if (job->common.speed) { > + uint64_t delay_ns = ratelimit_calculate_delay( > + &job->limit, job->sectors_read); > + job->sectors_read = 0; > + block_job_sleep_ns(&job->common, rt_clock, delay_ns); > + } else { > + block_job_sleep_ns(&job->common, rt_clock, 0); > + } > + > + if (block_job_is_cancelled(&job->common)) { > + break; > + } > + > + DPRINTF("backup_run loop C%" PRId64 "\n", start); > + > + ret = backup_do_cow(bs, start * BACKUP_BLOCKS_PER_CLUSTER, 1); > + if (ret < 0) { > + break; > + } > + > + /* Publish progress */ > + job->common.offset += BACKUP_CLUSTER_SIZE; > + }