diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 4360ce2..aabc30f 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -152,6 +152,12 @@ def recreate(info, priv): assert not info['dying'] + # Validate domain maxmem value not to be higher than dom0 physical memory + if priv: + total_mem = int(xc.physinfo()['total_memory']) + if info['maxmem_kb'] > total_mem: + info['maxmem_kb'] = total_mem + xeninfo = XendConfig.XendConfig(dominfo = info) xeninfo['is_control_domain'] = priv xeninfo['is_a_template'] = False @@ -1490,6 +1496,14 @@ class XendDomainInfo: """Set the maximum memory limit of this domain @param limit: In MiB. """ + # Get total memory and convert to MiB + if self.info['is_control_domain']: + total_mem = int(xc.physinfo()['total_memory'] / 1024) + + if limit <= 0 or limit > total_mem: + raise XendError('Invalid memory size, only positive values ' + 'up to %s MiB are valid' % total_mem) + log.debug("Setting memory maximum of domain %s (%s) to %d MiB.", self.info['name_label'], str(self.domid), limit)