diff mbox

[2/2] Add check for cache size smaller than page size

Message ID 1389109808-19681-2-git-send-email-owasserm@redhat.com
State New
Headers show

Commit Message

Orit Wasserman Jan. 7, 2014, 3:50 p.m. UTC
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 arch_init.c |  4 ++++
 migration.c | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

1.8.3.1

Comments

Juan Quintela Jan. 14, 2014, 3:25 p.m. UTC | #1
Orit Wasserman <owasserm@redhat.com> wrote:
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>
diff mbox

Patch

diff --git a/arch_init.c b/arch_init.c
index 5c55c68..e52c9ba 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -176,6 +176,10 @@  static struct {
 
 int64_t xbzrle_cache_resize(int64_t new_size)
 {
+    if (new_size < TARGET_PAGE_SIZE) {
+        return -1;
+    }
+
     if (XBZRLE.cache != NULL) {
         return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) *
             TARGET_PAGE_SIZE;
diff --git a/migration.c b/migration.c
index 2b1ab20..f28aa1d 100644
--- a/migration.c
+++ b/migration.c
@@ -455,6 +455,7 @@  void qmp_migrate_cancel(Error **errp)
 void qmp_migrate_set_cache_size(int64_t value, Error **errp)
 {
     MigrationState *s = migrate_get_current();
+    int64_t new_size; 
 
     /* Check for truncation */
     if (value != (size_t)value) {
@@ -463,8 +464,14 @@  void qmp_migrate_set_cache_size(int64_t value, Error **errp)
         return;
     }
 
-    s->xbzrle_cache_size = xbzrle_cache_resize(value);
+    new_size = xbzrle_cache_resize(value);
+    if (new_size < 0) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
+                  "is smaller than page size");
+        return;
+    }
+
+    s->xbzrle_cache_size = new_size;
 }
 
 int64_t qmp_query_migrate_cache_size(Error **errp)
--