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?