aboutsummaryrefslogtreecommitdiff
path: root/migration/page_cache.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-10-25 15:24:08 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-10-25 15:24:08 +0100
commit4e1b31dba8f66e337fbaf0166b7b8c440be78529 (patch)
treeb51eb1c88a22b232193e54bb3bb083c023340aef /migration/page_cache.c
parent328f6f79e9916deb6e5649499f7439b0262f6f9e (diff)
parent87db1a7d89677e3dbc8b3763e417b9376009bdbb (diff)
Merge remote-tracking branch 'remotes/juanquintela/tags/migration/20171023' into staging
migration/next for 20171023 # gpg: Signature made Mon 23 Oct 2017 17:05:14 BST # gpg: using RSA key 0xF487EF185872D723 # gpg: Good signature from "Juan Quintela <quintela@redhat.com>" # gpg: aka "Juan Quintela <quintela@trasno.org>" # Primary key fingerprint: 1899 FF8E DEBF 58CC EE03 4B82 F487 EF18 5872 D723 * remotes/juanquintela/tags/migration/20171023: (21 commits) migration: Improve migration thread error handling qapi: Fix grammar in x-multifd-page-count descriptions migration: add bitmap for received page migration: introduce qemu_ufd_copy_ioctl helper migration: postcopy_place_page factoring out migration: new ram_init_bitmaps() migration: clean up xbzrle cache init/destroy migration: provide ram_state_cleanup migration: provide ram_state_init() migration: pause-before-switchover for postcopy migration: allow cancel to unpause migrate: HMP migate_continue migration: migrate-continue migration: Wait for semaphore before completing migration migration: Add 'pre-switchover' and 'device' statuses migration: Add 'pause-before-switchover' capability migration: Make cache_init() take an error parameter migration: Move xbzrle cache resize error handling to xbzrle_cache_resize migration: Make cache size elements use the right types migratiom: Remove max_item_age parameter ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'migration/page_cache.c')
-rw-r--r--migration/page_cache.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/migration/page_cache.c b/migration/page_cache.c
index ba984c4858..9a9d13d6a2 100644
--- a/migration/page_cache.c
+++ b/migration/page_cache.c
@@ -14,6 +14,8 @@
#include "qemu/osdep.h"
+#include "qapi/qmp/qerror.h"
+#include "qapi/error.h"
#include "qemu-common.h"
#include "qemu/host-utils.h"
#include "migration/page_cache.h"
@@ -39,27 +41,28 @@ struct CacheItem {
struct PageCache {
CacheItem *page_cache;
- unsigned int page_size;
- int64_t max_num_items;
- uint64_t max_item_age;
- int64_t num_items;
+ size_t page_size;
+ size_t max_num_items;
+ size_t num_items;
};
-PageCache *cache_init(int64_t num_pages, unsigned int page_size)
+PageCache *cache_init(int64_t new_size, size_t page_size, Error **errp)
{
int64_t i;
-
+ size_t num_pages = new_size / page_size;
PageCache *cache;
- if (num_pages <= 0) {
- DPRINTF("invalid number of pages\n");
+ if (new_size < page_size) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
+ "is smaller than one target page size");
return NULL;
}
/* We prefer not to abort if there is no memory */
cache = g_try_malloc(sizeof(*cache));
if (!cache) {
- DPRINTF("Failed to allocate cache\n");
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
+ "Failed to allocate cache");
return NULL;
}
/* round down to the nearest power of 2 */
@@ -69,7 +72,6 @@ PageCache *cache_init(int64_t num_pages, unsigned int page_size)
}
cache->page_size = page_size;
cache->num_items = 0;
- cache->max_item_age = 0;
cache->max_num_items = num_pages;
DPRINTF("Setting cache buckets to %" PRId64 "\n", cache->max_num_items);
@@ -78,7 +80,8 @@ PageCache *cache_init(int64_t num_pages, unsigned int page_size)
cache->page_cache = g_try_malloc((cache->max_num_items) *
sizeof(*cache->page_cache));
if (!cache->page_cache) {
- DPRINTF("Failed to allocate cache->page_cache\n");
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
+ "Failed to allocate page cache");
g_free(cache);
return NULL;
}