Skip to contentSkip to conversation

tweak XendDomainInfo to allow architectures to subclass

PATCH In review Hollis Blanchard 2 participants 4 messages Sep 20, 2006 – Sep 25, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tweak XendDomainInfo to allow architectures to subclass

# HG changeset patch
# User Hollis Blanchard <[email protected]>
# 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).

tools/python/xen/xend/XendDomainInfo.py +20 -6
diff -r f7d90f962967 -r b46d3d47063a tools/python/xen/xend/XendDomainInfo.py
@@ -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.
#1 lore raw

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.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
Quoted 100 lines · Hollis Blanchard

# HG changeset patch
# User Hollis Blanchard <[email protected]>
# 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

diff -r f7d90f962967 -r b46d3d47063a tools/python/xen/xend/XendDomainInfo.py

tools/python/xen/xend/XendDomainInfo.py +20 -6
@@ -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
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 5 lines · Hollis Blanchard

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

#3 lore raw
Quoted 5 lines · Alastair Tse

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).

tools/python/xen/xend/XendDomainInfo.py +19 -6
diff -r 3499b3271e5f tools/python/xen/xend/XendDomainInfo.py
@@ -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.
Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center