On 01/26/2012 04:24 PM, Orit Wasserman wrote: > Add migration state to store XBRLE params (enablement and cache size). > In the outgoing migration check to see if the page is cached and > changed than send compressed page by using save_xbrle_page function. > In the incoming migration check to see if RAM_SAVE_FLAG_XBRLE is set > and decompress the page (by using load_xbrle function). > > +/* XBZRLE (Xor Based Zero Length Encoding */ > +typedef struct XBZRLEHeader { > + uint8_t xh_flags; > + uint16_t xh_len; > + uint32_t xh_cksum; > +} XBZRLEHeader;
__attribute__((packed)) > + > +/* RAM Migration State */ > +typedef struct ArchMigrationState { > + int use_xbzrle; > + int64_t xbzrle_cache_size; > +} ArchMigrationState; > + > +static ArchMigrationState arch_mig_state; Strange name. > > +#define ENCODING_FLAG_XBZRLE 0x1 > + > +static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data, > + ram_addr_t current_addr, RAMBlock *block, > + ram_addr_t offset, int cont) > +{ ... > + /* Send XBZRLE based compressed page */ > + save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE); > + qemu_put_buffer(f, (uint8_t *) &hdr, sizeof(hdr)); Or better, encode the members separately so they get proper endian encoding. > + qemu_put_buffer(f, encoded_buf, encoded_len); > + bytes_sent = encoded_len + sizeof(hdr); > + > +done: > + g_free(encoded_buf); > + return bytes_sent; > +} > + > static RAMBlock *last_block; > static ram_addr_t last_offset; > > > > +/* > + page = zrun > + | zrun nzrun > + | zrun nzrun page This is no longer accurate. > + > + zrun = length > + > + nzrun = length byte... > + > + length = uleb128 encoded integer > + */ > +int encode_page(uint8_t *old_buf, uint8_t *new_buf, int slen, uint8_t *dst, > + int dlen) > +{ ... > +} > + > +int decode_page(uint8_t *src, int slen, uint8_t *dst, int dlen) > +{ > + int i = 0, d = 0; > + uint32_t count = 0; > + > + while (i < slen - 1) { > + /* zrun */ > + i += uleb128_decode_small(src + i, &count); > + d += count; > + > + /* overflow */ > + if (d > dlen) { > + return -1; assert instead? > + } > + > + /* completed decoding */ > + if (i == slen) { > + return d + 1; > + } > + > + /* nzrun */ > + i += uleb128_decode_small(src + i, &count); > + /* overflow */ > + if (d + count > dlen) { > + return -1; > + } > + memcpy(dst + d, src + i, count); > + d += count; > + i += count; > + } > + memset() for the tail? > + return d + 1; > +} -- error compiling committee.c: too many arguments to function