From adec43af85cae377807a569f283321b65272ad7e Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 18 Apr 2012 12:31:24 +0200 Subject: [PATCH] dom0/qvm-prefs: validate memory parameters (#497) --- dom0/qvm-tools/qvm-prefs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/dom0/qvm-tools/qvm-prefs b/dom0/qvm-tools/qvm-prefs index 6b4f1d8c..75463e22 100755 --- a/dom0/qvm-tools/qvm-prefs +++ b/dom0/qvm-tools/qvm-prefs @@ -88,14 +88,38 @@ def set_memory(vms, vm, args): print >> sys.stderr, "Missing memory argument!" exit (1) - vm.memory = int(args[0]) + new_memory = int(args[0]) + + if new_memory <= 0: + print >>sys.stderr, "Memory size must be positive" + return False + + if new_memory > vm.maxmem: + print >>sys.stderr, "Memory size must be less or equal to maxmem" + return False + + vm.memory = new_memory def set_maxmem(vms, vm, args): if len (args) != 1: print >> sys.stderr, "Missing maxmem argument!" exit (1) - vm.maxmem = int(args[0]) + new_maxmem = int(args[0]) + + if new_maxmem <= 0: + print >>sys.stderr, "Memory size must be positive" + return False + + qubes_host = QubesHost() + if new_maxmem > qubes_host.memory_total/1024: + print >> sys.stderr, "This host has only {0} MB of RAM".format(qubes_host.memory_total/1024) + return False + + if new_maxmem < vm.memory: + print >> sys.stderr, "WARNING: new maxmem smaller than memory property - VM will be able to use only 'maxmem' memory amount". + + vm.maxmem = new_maxmem def set_mac(vms, vm, args): if len (args) != 1: