summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorChenLiang <chenliang88@huawei.com>2014-11-24 19:55:48 +0800
committerAmit Shah <amit.shah@redhat.com>2015-01-15 17:49:43 +0530
commit1b826f277814dd9496fe3cc71cbe6ab7b203cadf (patch)
tree1af121a84c8ee16d2afaa18d840b69538f2a38ab
parent27af7d6ea5015e5ef1f7985eab94a8a218267a2b (diff)
downloadfocaccia-qemu-1b826f277814dd9496fe3cc71cbe6ab7b203cadf.tar.gz
focaccia-qemu-1b826f277814dd9496fe3cc71cbe6ab7b203cadf.zip
xbzrle: rebuild the cache_is_cached function
Rebuild the cache_is_cached function by cache_get_by_addr. And
drops the asserts because the caller is also asserting the same
thing.

Signed-off-by: ChenLiang <chenliang88@huawei.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r--page_cache.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/page_cache.c b/page_cache.c
index aa681923c6..cf8878d1d7 100644
--- a/page_cache.c
+++ b/page_cache.c
@@ -125,24 +125,6 @@ static size_t cache_get_cache_pos(const PageCache *cache,
     return pos;
 }
 
-bool cache_is_cached(const PageCache *cache, uint64_t addr,
-                     uint64_t current_age)
-{
-    size_t pos;
-
-    g_assert(cache);
-    g_assert(cache->page_cache);
-
-    pos = cache_get_cache_pos(cache, addr);
-
-    if (cache->page_cache[pos].it_addr == addr) {
-        /* update the it_age when the cache hit */
-        cache->page_cache[pos].it_age = current_age;
-        return true;
-    }
-    return false;
-}
-
 static CacheItem *cache_get_by_addr(const PageCache *cache, uint64_t addr)
 {
     size_t pos;
@@ -160,14 +142,26 @@ uint8_t *get_cached_data(const PageCache *cache, uint64_t addr)
     return cache_get_by_addr(cache, addr)->it_data;
 }
 
+bool cache_is_cached(const PageCache *cache, uint64_t addr,
+                     uint64_t current_age)
+{
+    CacheItem *it;
+
+    it = cache_get_by_addr(cache, addr);
+
+    if (it->it_addr == addr) {
+        /* update the it_age when the cache hit */
+        it->it_age = current_age;
+        return true;
+    }
+    return false;
+}
+
 int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata,
                  uint64_t current_age)
 {
 
-    CacheItem *it = NULL;
-
-    g_assert(cache);
-    g_assert(cache->page_cache);
+    CacheItem *it;
 
     /* actual update of entry */
     it = cache_get_by_addr(cache, addr);