summaryrefslogtreecommitdiffstats
path: root/qemu/migration/xbzrle.c
diff options
context:
space:
mode:
authorRajithaY <rajithax.yerrumsetty@intel.com>2017-04-25 03:31:15 -0700
committerRajitha Yerrumchetty <rajithax.yerrumsetty@intel.com>2017-05-22 06:48:08 +0000
commitbb756eebdac6fd24e8919e2c43f7d2c8c4091f59 (patch)
treeca11e03542edf2d8f631efeca5e1626d211107e3 /qemu/migration/xbzrle.c
parenta14b48d18a9ed03ec191cf16b162206998a895ce (diff)
Adding qemu as a submodule of KVMFORNFV
This Patch includes the changes to add qemu as a submodule to kvmfornfv repo and make use of the updated latest qemu for the execution of all testcase Change-Id: I1280af507a857675c7f81d30c95255635667bdd7 Signed-off-by:RajithaY<rajithax.yerrumsetty@intel.com>
Diffstat (limited to 'qemu/migration/xbzrle.c')
-rw-r--r--qemu/migration/xbzrle.c176
1 files changed, 0 insertions, 176 deletions
diff --git a/qemu/migration/xbzrle.c b/qemu/migration/xbzrle.c
deleted file mode 100644
index c85833925..000000000
--- a/qemu/migration/xbzrle.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Xor Based Zero Run Length Encoding
- *
- * Copyright 2013 Red Hat, Inc. and/or its affiliates
- *
- * Authors:
- * Orit Wasserman <owasserm@redhat.com>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-#include "qemu/osdep.h"
-#include "qemu/cutils.h"
-#include "include/migration/migration.h"
-
-/*
- page = zrun nzrun
- | zrun nzrun page
-
- zrun = length
-
- nzrun = length byte...
-
- length = uleb128 encoded integer
- */
-int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
- uint8_t *dst, int dlen)
-{
- uint32_t zrun_len = 0, nzrun_len = 0;
- int d = 0, i = 0;
- long res;
- uint8_t *nzrun_start = NULL;
-
- g_assert(!(((uintptr_t)old_buf | (uintptr_t)new_buf | slen) %
- sizeof(long)));
-
- while (i < slen) {
- /* overflow */
- if (d + 2 > dlen) {
- return -1;
- }
-
- /* not aligned to sizeof(long) */
- res = (slen - i) % sizeof(long);
- while (res && old_buf[i] == new_buf[i]) {
- zrun_len++;
- i++;
- res--;
- }
-
- /* word at a time for speed */
- if (!res) {
- while (i < slen &&
- (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) {
- i += sizeof(long);
- zrun_len += sizeof(long);
- }
-
- /* go over the rest */
- while (i < slen && old_buf[i] == new_buf[i]) {
- zrun_len++;
- i++;
- }
- }
-
- /* buffer unchanged */
- if (zrun_len == slen) {
- return 0;
- }
-
- /* skip last zero run */
- if (i == slen) {
- return d;
- }
-
- d += uleb128_encode_small(dst + d, zrun_len);
-
- zrun_len = 0;
- nzrun_start = new_buf + i;
-
- /* overflow */
- if (d + 2 > dlen) {
- return -1;
- }
- /* not aligned to sizeof(long) */
- res = (slen - i) % sizeof(long);
- while (res && old_buf[i] != new_buf[i]) {
- i++;
- nzrun_len++;
- res--;
- }
-
- /* word at a time for speed, use of 32-bit long okay */
- if (!res) {
- /* truncation to 32-bit long okay */
- unsigned long mask = (unsigned long)0x0101010101010101ULL;
- while (i < slen) {
- unsigned long xor;
- xor = *(unsigned long *)(old_buf + i)
- ^ *(unsigned long *)(new_buf + i);
- if ((xor - mask) & ~xor & (mask << 7)) {
- /* found the end of an nzrun within the current long */
- while (old_buf[i] != new_buf[i]) {
- nzrun_len++;
- i++;
- }
- break;
- } else {
- i += sizeof(long);
- nzrun_len += sizeof(long);
- }
- }
- }
-
- d += uleb128_encode_small(dst + d, nzrun_len);
- /* overflow */
- if (d + nzrun_len > dlen) {
- return -1;
- }
- memcpy(dst + d, nzrun_start, nzrun_len);
- d += nzrun_len;
- nzrun_len = 0;
- }
-
- return d;
-}
-
-int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen)
-{
- int i = 0, d = 0;
- int ret;
- uint32_t count = 0;
-
- while (i < slen) {
-
- /* zrun */
- if ((slen - i) < 2) {
- return -1;
- }
-
- ret = uleb128_decode_small(src + i, &count);
- if (ret < 0 || (i && !count)) {
- return -1;
- }
- i += ret;
- d += count;
-
- /* overflow */
- if (d > dlen) {
- return -1;
- }
-
- /* nzrun */
- if ((slen - i) < 2) {
- return -1;
- }
-
- ret = uleb128_decode_small(src + i, &count);
- if (ret < 0 || !count) {
- return -1;
- }
- i += ret;
-
- /* overflow */
- if (d + count > dlen || i + count > slen) {
- return -1;
- }
-
- memcpy(dst + d, src + i, count);
- d += count;
- i += count;
- }
-
- return d;
-}