From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyuxQ-0000eT-2F for qemu-devel@nongnu.org; Mon, 15 Jul 2013 22:25:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UyuxP-0005tc-86 for qemu-devel@nongnu.org; Mon, 15 Jul 2013 22:25:40 -0400 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]:55380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyuxO-0005tC-TX for qemu-devel@nongnu.org; Mon, 15 Jul 2013 22:25:39 -0400 Received: by mail-wg0-f52.google.com with SMTP id b12so112180wgh.7 for ; Mon, 15 Jul 2013 19:25:38 -0700 (PDT) Date: Tue, 16 Jul 2013 10:25:28 +0800 From: Stefan Hajnoczi Message-ID: <20130716022528.GC32278@stefanha-thinkpad.redhat.com> References: <1373355014-14846-1-git-send-email-qiaonuohan@cn.fujitsu.com> <1373355014-14846-7-git-send-email-qiaonuohan@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1373355014-14846-7-git-send-email-qiaonuohan@cn.fujitsu.com> Subject: Re: [Qemu-devel] [PATCH v5 6/9] dump: Add API to write dump_bitmap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qiao Nuohan Cc: qemu-devel@nongnu.org, lcapitulino@redhat.com, zhangxh@cn.fujitsu.com, anderson@redhat.com, kumagai-atsushi@mxc.nes.nec.co.jp, afaerber@suse.de On Tue, Jul 09, 2013 at 03:30:11PM +0800, Qiao Nuohan wrote: > +/* set dump_bitmap sequencely */ > +static int set_dump_bitmap(int64_t last_pfn, int64_t pfn, uint32_t value, > + void *buf, DumpState *s) > +{ > + off_t old_offset, new_offset; > + off_t offset_bitmap1, offset_bitmap2; > + uint32_t byte, bit; > + > + /* should not set the previous place */ > + if (last_pfn > pfn) { > + return -1; > + } > + > + /* > + * if the block needed to be set is not same as the one cached in buf, flush > + * the cached buf to vmcore firstly > + */ > + old_offset = BUFSIZE_BITMAP * (last_pfn / PFN_BUFBITMAP); > + new_offset = BUFSIZE_BITMAP * (pfn / PFN_BUFBITMAP); > + > + while (old_offset < new_offset) { > + /* calculate the offset and write dump_bitmap */ > + offset_bitmap1 = s->offset_dump_bitmap + old_offset; > + if (write_buffer(s->fd, s->flag_flatten, offset_bitmap1, buf, > + BUFSIZE_BITMAP) < 0) { > + return -1; > + } > + > + /* dump level 1 is chosen, so 1st and 2nd bitmap are same */ > + offset_bitmap2 = s->offset_dump_bitmap + s->len_dump_bitmap / 2 + > + old_offset; > + if (write_buffer(s->fd, s->flag_flatten, offset_bitmap2, buf, > + BUFSIZE_BITMAP) < 0) { > + return -1; > + } Can you reuse sync_dump_bitmap() here instead of duplicating this code?