Fix xm commands for inactive domains
PATCH 1/1 Fix xm commands for inactive domains
The commands 'mem-set' 'mem-max' and 'vcpu-set' are all broken when used against an inactive domain. The backend implementation of these commands typically updates the in-memory config held by XenD, and does a hypercall or xenstore write to update the live guest. Obviously the latter part fails with inactive guests. The changes are also not persisted to disk.
The attached patch ensures that the hypercalls/xenstore writes are not tried for inactive guests. It will also write out the changes to disk so config changes to inactive guests are preserved across XenD restarts.
Normally memory_dynamic_min/max and online_vcpus are picked up from the running domain state. This doesn't apply for inactive guests, so when changing config for inactive guests, we also update those 3 parameters to match the new settings.
So, at the end of all this, I can do:
1. Define an inactive domain...
# xm new demo
# xm list demo
Name ID Mem VCPUs State Time(s)
demo 410 1 0.0
# xm list --long demo | grep mem
(memory 410)
(maxmem 800)
(shadow_memory 0)
(memory_dynamic_min 410)
(memory_dynamic_max 800)2. Change its memory config...
# xm mem-set demo 500
# xm mem-max demo 1000
# xm list --long demo | grep mem
(memory 500)
(maxmem 1000)
(shadow_memory 0)
(memory_dynamic_min 500)
(memory_dynamic_max 1000)
# xm list demo
Name ID Mem VCPUs State Time(s)
demo 500 1 0.03. Change its cpu config...
# xm vcpu-set demo 8
# xm list --long demo | grep vcpu
(vcpus 8)
(online_vcpus 8)
# xm list demo
Name ID Mem VCPUs State Time(s)
demo 500 8 0.04. Start it with new settings...
# xm start demo # xm list demo Name ID Mem VCPUs State Time(s) demo 22 500 8 -b---- 0.7
NB, the patch is structured so there is no functional change for active guests, to minimise risk of regression in this 3.0.4 freeze. I think this is really important to get working in 3.0.4 since inactive domain support is of pretty limited usefullness as it currently stands. Hopefully in 3.0.5 the XenAPI will make it possible to change all aspects of an inactive guest config.
Regards,
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
tools/python/xen/xend/XendDomainInfo.py +43 -12
@@ -606,8 +606,34 @@ class XendDomainInfo: raise XendError('Invalid memory size') self.info['memory_static_min'] = target - self.storeVm("memory", target) - self.storeDom("memory/target", target << 10) + if self.domid >= 0: + self.storeVm("memory", target) + self.storeDom("memory/target", target << 10) + else: + self.info['memory_dynamic_min'] = target + xen.xend.XendDomain.instance().managed_config_save(self) + + def setMemoryMaximum(self, limit): + """Set the maximum memory limit of this domain + @param limit: In MiB. + """ + log.debug("Setting memory maximum of domain %s (%d) to %d MiB.", + self.info['name_label'], self.domid, limit) + + if limit <= 0: + raise XendError('Invalid memory size') + + self.info['memory_static_max'] = limit + if self.domid >= 0: + maxmem = int(limit) * 1024 + try: + return xc.domain_setmaxmem(self.domid, maxmem) + except Exception, ex: + raise XendError(str(ex)) + else: + self.info['memory_dynamic_max'] = limit + xen.xend.XendDomain.instance().managed_config_save(self) + def getVCPUInfo(self): try:
@@ -876,18 +902,23 @@ class XendDomainInfo: def setVCpuCount(self, vcpus): self.info['vcpu_avail'] = (1 << vcpus) - 1 - self.storeVm('vcpu_avail', self.info['vcpu_avail']) - # update dom differently depending on whether we are adjusting - # vcpu number up or down, otherwise _vcpuDomDetails does not - # disable the vcpus - if self.info['vcpus_number'] > vcpus: - # decreasing - self._writeDom(self._vcpuDomDetails()) - self.info['vcpus_number'] = vcpus + if self.domid >= 0: + self.storeVm('vcpu_avail', self.info['vcpu_avail']) + # update dom differently depending on whether we are adjusting + # vcpu number up or down, otherwise _vcpuDomDetails does not + # disable the vcpus + if self.info['vcpus_number'] > vcpus: + # decreasing + self._writeDom(self._vcpuDomDetails()) + self.info['vcpus_number'] = vcpus + else: + # same or increasing + self.info['vcpus_number'] = vcpus + self._writeDom(self._vcpuDomDetails()) else: - # same or increasing self.info['vcpus_number'] = vcpus - self._writeDom(self._vcpuDomDetails()) + self.info['online_vcpus'] = vcpus + xen.xend.XendDomain.instance().managed_config_save(self) def getLabel(self): return security.get_security_info(self.info, 'label')
tools/python/xen/xend/XendDomain.py +1 -5
@@ -1337,11 +1337,7 @@ class XendDomain: dominfo = self.domain_lookup_nr(domid) if not dominfo: raise XendInvalidDomain(str(domid)) - maxmem = int(mem) * 1024 - try: - return xc.domain_setmaxmem(dominfo.getDomid(), maxmem) - except Exception, ex: - raise XendError(str(ex)) + dominfo.setMemoryMaximum(mem) def domain_ioport_range_enable(self, domid, first, last): """Enable access to a range of IO ports for a domain
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 62 lines · Daniel P. Berrange
The commands 'mem-set' 'mem-max' and 'vcpu-set' are all broken when used against an inactive domain. The backend implementation of these commands typically updates the in-memory config held by XenD, and does a hypercall or xenstore write to update the live guest. Obviously the latter part fails with inactive guests. The changes are also not persisted to disk.
The attached patch ensures that the hypercalls/xenstore writes are not tried for inactive guests. It will also write out the changes to disk so config changes to inactive guests are preserved across XenD restarts.
Normally memory_dynamic_min/max and
online_vcpusare picked up from the running domain state. This doesn't apply for inactive guests, so when changing config for inactive guests, we also update those 3 parameters to match the new settings.So, at the end of all this, I can do:
1. Define an inactive domain...
# xm new demo # xm list demo Name ID Mem VCPUs State Time(s) demo 410 1 0.0 # xm list --long demo | grep mem (memory 410) (maxmem 800) (shadow_memory 0) (memory_dynamic_min 410) (memory_dynamic_max 800)2. Change its memory config...
# xm mem-set demo 500 # xm mem-max demo 1000 # xm list --long demo | grep mem (memory 500) (maxmem 1000) (shadow_memory 0) (memory_dynamic_min 500) (memory_dynamic_max 1000) # xm list demo Name ID Mem VCPUs State Time(s) demo 500 1 0.03. Change its cpu config...
# xm vcpu-set demo 8 # xm list --long demo | grep vcpu (vcpus 8) (online_vcpus 8) # xm list demo Name ID Mem VCPUs State Time(s) demo 500 8 0.04. Start it with new settings...
# xm start demo # xm list demo Name ID Mem VCPUs State Time(s) demo 22 500 8 -b---- 0.7
Quoted 8 lines
NB, the patch is structured so there is no functional change for active guests, to minimise risk of regression in this 3.0.4 freeze. I think this is really important to get working in 3.0.4 since inactive domain support is of pretty limited usefullness as it currently stands. Hopefully in 3.0.5 the XenAPI will make it possible to change all aspects of an inactive guest config.
Signed-off-by Daniel P. Berrange <[email protected]>
There was one final problem I've just also fixed - for some reason the SEXPR api to change max memory was calling into XenDomain instead of XenDomainInfo directly. This meant it needed a domid - which doesn't exist in inactive domain case. So this updated version of the patch also fixed SrvDomain.py to call the XenDomainInfo object it already has directly - this matches the style of the rest of the method in SrvDomain.py
The attached patch contains my original patch + this SrvDomain.py fix. Now, not only does 'xm' work correctly, but libvirt can manage inactive domains & their config settings too.
Regards,
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
tools/python/xen/xend/server/SrvDomain.py +3 -6
@@ -160,12 +160,9 @@ class SrvDomain(SrvDir): return val def op_maxmem_set(self, _, req): - fn = FormFn(self.xd.domain_maxmem_set, - [['dom', 'int'], - ['memory', 'int']]) - val = fn(req.args, {'dom': self.dom.domid}) - return val - + return self.call(self.dom.setMemoryMaximum, + [['memory', 'int']], + req) def call(self, fn, args, req): return FormFn(fn, args)(req.args)
tools/python/xen/xend/XendDomainInfo.py +43 -12
69 lines not on this page · raw message
tools/python/xen/xend/XendDomain.py +1 -5
@@ -1337,11 +1337,7 @@ class XendDomain: dominfo = self.domain_lookup_nr(domid) if not dominfo: raise XendInvalidDomain(str(domid)) - maxmem = int(mem) * 1024 - try: - return xc.domain_setmaxmem(dominfo.getDomid(), maxmem) - except Exception, ex: - raise XendError(str(ex)) + dominfo.setMemoryMaximum(mem) def domain_ioport_range_enable(self, domid, first, last): """Enable access to a range of IO ports for a domain
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Ewan Mellor
AppliedQuoted 79 lines · Daniel P. Berrange
Quoted 62 lines · Daniel P. Berrange
The commands 'mem-set' 'mem-max' and 'vcpu-set' are all broken when used against an inactive domain. The backend implementation of these commands typically updates the in-memory config held by XenD, and does a hypercall or xenstore write to update the live guest. Obviously the latter part fails with inactive guests. The changes are also not persisted to disk.
The attached patch ensures that the hypercalls/xenstore writes are not tried for inactive guests. It will also write out the changes to disk so config changes to inactive guests are preserved across XenD restarts.
Normally memory_dynamic_min/max and
online_vcpusare picked up from the running domain state. This doesn't apply for inactive guests, so when changing config for inactive guests, we also update those 3 parameters to match the new settings.So, at the end of all this, I can do:
1. Define an inactive domain...
# xm new demo # xm list demo Name ID Mem VCPUs State Time(s) demo 410 1 0.0 # xm list --long demo | grep mem (memory 410) (maxmem 800) (shadow_memory 0) (memory_dynamic_min 410) (memory_dynamic_max 800)2. Change its memory config...
# xm mem-set demo 500 # xm mem-max demo 1000 # xm list --long demo | grep mem (memory 500) (maxmem 1000) (shadow_memory 0) (memory_dynamic_min 500) (memory_dynamic_max 1000) # xm list demo Name ID Mem VCPUs State Time(s) demo 500 1 0.03. Change its cpu config...
# xm vcpu-set demo 8 # xm list --long demo | grep vcpu (vcpus 8) (online_vcpus 8) # xm list demo Name ID Mem VCPUs State Time(s) demo 500 8 0.04. Start it with new settings...
# xm start demo # xm list demo Name ID Mem VCPUs State Time(s) demo 22 500 8 -b---- 0.7Quoted 8 lines
NB, the patch is structured so there is no functional change for active guests, to minimise risk of regression in this 3.0.4 freeze. I think this is really important to get working in 3.0.4 since inactive domain support is of pretty limited usefullness as it currently stands. Hopefully in 3.0.5 the XenAPI will make it possible to change all aspects of an inactive guest config.
Signed-off-by Daniel P. Berrange <[email protected]>There was one final problem I've just also fixed - for some reason the SEXPR api to change max memory was calling into XenDomain instead of XenDomainInfo directly. This meant it needed a domid - which doesn't exist in inactive domain case. So this updated version of the patch also fixed
SrvDomain.pyto call the XenDomainInfo object it already has directly - this matches the style of the rest of the method inSrvDomain.py
Quoted 5 lines
The attached patch contains my original patch + this
SrvDomain.pyfix. Now, not only does 'xm' work correctly, but libvirt can manage inactive domains & their config settings too.Signed-off-by Daniel P. Berrange <[email protected]>
Applied, thanks Daniel. Nice stuff.
Ewan.