[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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@xxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.