Hollis Blanchard
2006-Sep-20 19:23 UTC
[Xen-devel] [PATCH] [XEND] tweak XendDomainInfo to allow architectures to subclass
# HG changeset patch # User Hollis Blanchard <hollisb@us.ibm.com> # Date 1158780212 18000 # Node ID b46d3d47063ac51343847ec22321276b72a5e591 # Parent f7d90f962967a5a94fce0c04f8fcac449f36344f [XEND] tweak XendDomainInfo to allow architectures to subclass. - create findDomainClass(), analogous to findImageHandlerClass() in image.py. - move initial memory allocation into an allocMem() method (for subclasses to override). Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> diff -r f7d90f962967 -r b46d3d47063a tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Wed Sep 20 14:20:52 2006 -0500 +++ b/tools/python/xen/xend/XendDomainInfo.py Wed Sep 20 14:23:32 2006 -0500 @@ -35,6 +35,7 @@ from xen.util import asserts from xen.util import asserts from xen.util.blkif import blkdev_uname_to_file from xen.util import security +import arch import balloon import image import sxp @@ -189,7 +190,7 @@ def create(config): log.debug("XendDomainInfo.create(%s)", config) - vm = XendDomainInfo(parseConfig(config)) + vm = findDomainClass()(parseConfig(config)) try: vm.construct() vm.initDomain() @@ -239,13 +240,13 @@ def recreate(xeninfo, priv): ''Uuid in store does not match uuid for existing domain %d: '' ''%s != %s'' % (domid, uuid2_str, xeninfo[''uuid''])) - vm = XendDomainInfo(xeninfo, domid, dompath, True, priv) + vm = findDomainClass()(xeninfo, domid, dompath, True, priv) except Exception, exn: if priv: log.warn(str(exn)) - vm = XendDomainInfo(xeninfo, domid, dompath, True, priv) + vm = findDomainClass()(xeninfo, domid, dompath, True, priv) vm.recreateDom() vm.removeVm() vm.storeVmDetails() @@ -264,7 +265,7 @@ def restore(config): log.debug("XendDomainInfo.restore(%s)", config) - vm = XendDomainInfo(parseConfig(config), None, None, False, False, True) + vm = findDomainClass()(parseConfig(config), None, None, False, False, True) try: vm.construct() vm.storeVmDetails() @@ -1329,8 +1330,7 @@ class XendDomainInfo: self.info[''shadow_memory''] = shadow_cur # initial memory reservation - xc.domain_memory_increase_reservation(self.domid, reservation, 0, - 0) + self.allocMem(reservation) self.createChannels() @@ -1351,6 +1351,9 @@ class XendDomainInfo: except RuntimeError, exn: raise VmError(str(exn)) + + def allocMem(self, reservation): + xc.domain_memory_increase_reservation(self.domid, reservation, 0, 0) ## public: @@ -1761,6 +1764,17 @@ class XendDomainInfo: def infoIsSet(self, name): return name in self.info and self.info[name] is not None +domainTypes = { + "ia64": XendDomainInfo, + "x86": XendDomainInfo, +} + +def findDomainClass(): + type = arch.type + try: + return domainTypes[type] + except KeyError: + raise VmError("Unsupported architecture: " + type) #=========================================================================== # Register device controllers and their device config types. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hollis Blanchard
2006-Sep-22 20:02 UTC
Re: [Xen-devel] [PATCH] [XEND] tweak XendDomainInfo to allow architectures to subclass
Hi, thanks for checking in the earlier patch, Alistair. Do you have any comments on this one? It looks like the "import arch" statement isn''t needed, at least, since there''s a (stranger) import statement for it later. -- Hollis Blanchard IBM Linux Technology Center On Wed, 2006-09-20 at 14:23 -0500, Hollis Blanchard wrote:> # HG changeset patch > # User Hollis Blanchard <hollisb@us.ibm.com> > # Date 1158780212 18000 > # Node ID b46d3d47063ac51343847ec22321276b72a5e591 > # Parent f7d90f962967a5a94fce0c04f8fcac449f36344f > [XEND] tweak XendDomainInfo to allow architectures to subclass. > - create findDomainClass(), analogous to findImageHandlerClass() in image.py. > - move initial memory allocation into an allocMem() method (for subclasses to > override)..hg/patches/xenddomaininfo-refactor > > Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> > > diff -r f7d90f962967 -r b46d3d47063a tools/python/xen/xend/XendDomainInfo.py > --- a/tools/python/xen/xend/XendDomainInfo.py Wed Sep 20 14:20:52 2006 -0500 > +++ b/tools/python/xen/xend/XendDomainInfo.py Wed Sep 20 14:23:32 2006 -0500 > @@ -35,6 +35,7 @@ from xen.util import asserts > from xen.util import asserts > from xen.util.blkif import blkdev_uname_to_file > from xen.util import security > +import arch > import balloon > import image > import sxp > @@ -189,7 +190,7 @@ def create(config): > > log.debug("XendDomainInfo.create(%s)", config) > > - vm = XendDomainInfo(parseConfig(config)) > + vm = findDomainClass()(parseConfig(config)) > try: > vm.construct() > vm.initDomain() > @@ -239,13 +240,13 @@ def recreate(xeninfo, priv): > ''Uuid in store does not match uuid for existing domain %d: '' > ''%s != %s'' % (domid, uuid2_str, xeninfo[''uuid''])) > > - vm = XendDomainInfo(xeninfo, domid, dompath, True, priv) > + vm = findDomainClass()(xeninfo, domid, dompath, True, priv) > > except Exception, exn: > if priv: > log.warn(str(exn)) > > - vm = XendDomainInfo(xeninfo, domid, dompath, True, priv) > + vm = findDomainClass()(xeninfo, domid, dompath, True, priv) > vm.recreateDom() > vm.removeVm() > vm.storeVmDetails() > @@ -264,7 +265,7 @@ def restore(config): > > log.debug("XendDomainInfo.restore(%s)", config) > > - vm = XendDomainInfo(parseConfig(config), None, None, False, False, True) > + vm = findDomainClass()(parseConfig(config), None, None, False, False, True) > try: > vm.construct() > vm.storeVmDetails() > @@ -1329,8 +1330,7 @@ class XendDomainInfo: > self.info[''shadow_memory''] = shadow_cur > > # initial memory reservation > - xc.domain_memory_increase_reservation(self.domid, reservation, 0, > - 0) > + self.allocMem(reservation) > > self.createChannels() > > @@ -1351,6 +1351,9 @@ class XendDomainInfo: > > except RuntimeError, exn: > raise VmError(str(exn)) > + > + def allocMem(self, reservation): > + xc.domain_memory_increase_reservation(self.domid, reservation, 0, 0) > > > ## public: > @@ -1761,6 +1764,17 @@ class XendDomainInfo: > def infoIsSet(self, name): > return name in self.info and self.info[name] is not None > > +domainTypes = { > + "ia64": XendDomainInfo, > + "x86": XendDomainInfo, > +} > + > +def findDomainClass(): > + type = arch.type > + try: > + return domainTypes[type] > + except KeyError: > + raise VmError("Unsupported architecture: " + type) > > #===========================================================================> # Register device controllers and their device config types. > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Alastair Tse
2006-Sep-23 09:29 UTC
Re: [Xen-devel] [PATCH] [XEND] tweak XendDomainInfo to allow architectures to subclass
On 22 Sep 2006, at 21:02, Hollis Blanchard wrote:> Hi, thanks for checking in the earlier patch, Alistair. Do you have > any > comments on this one? > > It looks like the "import arch" statement isn''t needed, at least, > since > there''s a (stranger) import statement for it later.Stranger because it is an absolute import rather than a relative one, which is a good thing. :) The patch looks OK and the impact is pretty low since the impact is only contained within XendDomainInfo.py. domainTypes should probably be renamed to _domainTypes just to make it explicit it is not to be accessed outside of this module. Also, type is a built-in python function, better to rename that to something else, just in case. Cheers, Alastair _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Hollis Blanchard
2006-Sep-25 13:53 UTC
Re: [Xen-devel] [PATCH] [XEND] tweak XendDomainInfo to allow architectures to subclass
On Sat, 2006-09-23 at 10:29 +0100, Alastair Tse wrote:> The patch looks OK and the impact is pretty low since the impact is > only contained within XendDomainInfo.py. domainTypes should probably > be renamed to _domainTypes just to make it explicit it is not to be > accessed outside of this module. Also, type is a built-in python > function, better to rename that to something else, just in case.Sounds good; here is the update. [XEND] tweak XendDomainInfo to allow architectures to subclass. - create findDomainClass(), analogous to findImageHandlerClass() in image.py. - move initial memory allocation into an allocMem() method (for subclasses to override). Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> diff -r 3499b3271e5f tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Fri Sep 22 17:46:32 2006 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Mon Sep 25 08:52:14 2006 -0500 @@ -189,7 +189,7 @@ def create(config): log.debug("XendDomainInfo.create(%s)", config) - vm = XendDomainInfo(parseConfig(config)) + vm = findDomainClass()(parseConfig(config)) try: vm.construct() vm.initDomain() @@ -239,13 +239,13 @@ def recreate(xeninfo, priv): ''Uuid in store does not match uuid for existing domain %d: '' ''%s != %s'' % (domid, uuid2_str, xeninfo[''uuid''])) - vm = XendDomainInfo(xeninfo, domid, dompath, True, priv) + vm = findDomainClass()(xeninfo, domid, dompath, True, priv) except Exception, exn: if priv: log.warn(str(exn)) - vm = XendDomainInfo(xeninfo, domid, dompath, True, priv) + vm = findDomainClass()(xeninfo, domid, dompath, True, priv) vm.recreateDom() vm.removeVm() vm.storeVmDetails() @@ -264,7 +264,7 @@ def restore(config): log.debug("XendDomainInfo.restore(%s)", config) - vm = XendDomainInfo(parseConfig(config), None, None, False, False, True) + vm = findDomainClass()(parseConfig(config), None, None, False, False, True) try: vm.construct() vm.storeVmDetails() @@ -1339,8 +1339,7 @@ class XendDomainInfo: self.info[''shadow_memory''] = shadow_cur # initial memory reservation - xc.domain_memory_increase_reservation(self.domid, reservation, 0, - 0) + self.allocMem(reservation) self.createChannels() @@ -1361,6 +1360,9 @@ class XendDomainInfo: except RuntimeError, exn: raise VmError(str(exn)) + + def allocMem(self, reservation): + xc.domain_memory_increase_reservation(self.domid, reservation, 0, 0) ## public: @@ -1771,6 +1773,17 @@ class XendDomainInfo: def infoIsSet(self, name): return name in self.info and self.info[name] is not None +_domainTypes = { + "ia64": XendDomainInfo, + "x86": XendDomainInfo, +} + +def findDomainClass(): + archname = arch.type + try: + return _domainTypes[archname] + except KeyError: + raise VmError("Unsupported architecture: " + archname) #=========================================================================== # Register device controllers and their device config types. -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel