Skip to contentSkip to conversation

Fix stale-state issue with 'xm dom{id,name}'

PATCH Superseded Dan Smith 1 participant 1 message Sep 28, 2005

lore
Share & tools
lore

Dan Smith

author
#0 lore raw

PATCH 1/1 Fix stale-state issue with 'xm dom{id,name}'

This patch prevents 'xm dom{id,name}' from returning stale information after a domain has exited.

Xend already called XendDomainInfo.update() before returning information, but did not check to see if the result indicated that the domain had disappeared. So, it updated the domain (which just bails if the domain is gone) and then returned info from its internal data structures. This means that if you run "xm destroy foo", you can then run "xm domid" or "xm domname" many times, getting stale info.

Instead of modifying Xend's state in a "random place", we just make sure to throw an error if we know the state is invalid.

This patch causes xm-test 01_shutdown_basic_pos to pass now. Xm-test uses domid and domname in many places to determine if a domain is running or not (as, I would imagine, other higher-level tools might). Having this information consistent with the actual state is a good thing.

tools/python/xen/xend/XendDomainInfo.py +3 -1
diff -r ca78d9668fdb tools/python/xen/xend/XendDomainInfo.py
@@ -693,7 +693,7 @@
         if not info:
             info = dom_get(self.domid)
             if not info:
-                return
+                return False
             
         self.info.update(info)
         self.validateInfo()
@@ -701,6 +701,8 @@
 
         log.debug("XendDomainInfo.update done on domain %d: %s", self.domid,
                   self.info)
+
+        return True
 
 
     ## private:
tools/python/xen/xend/server/SrvDomain.py +5 -1
diff -r ca78d9668fdb tools/python/xen/xend/server/SrvDomain.py
@@ -21,6 +21,8 @@
 from xen.xend import XendDomain
 from xen.xend import PrettyPrint
 from xen.xend.Args import FormFn
+from xen.xend.XendError import XendError
+from xen.xend.XendLogging import log
 
 from xen.web.SrvDir import SrvDir
 
@@ -221,7 +223,9 @@
         #
         # if op and op[0] in ['vifs', 'vif', 'vbds', 'vbd', 'mem_target_set']:
         #    return self.perform(req)
-        self.dom.update()
+        if not self.dom.update():
+            raise XendError("Domain %s no longer exists" % self.dom.getName())
+
         if self.use_sxp(req):
             req.setHeader("Content-Type", sxp.mime_type)
             sxp.show(self.dom.sxpr(), out=req)
tools/python/xen/xm/main.py +13 -3
diff -r ca78d9668fdb tools/python/xen/xm/main.py
@@ -32,6 +32,7 @@
 warnings.filterwarnings('ignore', category=FutureWarning)
 from xen.xend import PrettyPrint
 from xen.xend import sxp
+from xen.xend.XendClient import XendError
 from xen.xm.opts import *
 shorthelp = """Usage: xm <subcommand> [args]
     Control, list, and manipulate Xen guest instances
@@ -385,14 +386,24 @@
     name = args[0]
 
     from xen.xend.XendClient import server
-    dom = server.xend_domain(name)
+    try:
+        dom = server.xend_domain(name)
+    except XendError, e:
+        err("Unable to get info for domain %s" % name)
+        sys.exit(1)
+        
     print sxp.child_value(dom, 'domid')
     
 def xm_domname(args):
     name = args[0]
 
     from xen.xend.XendClient import server
-    dom = server.xend_domain(name)
+    try:
+        dom = server.xend_domain(name)
+    except XendError, e:
+        err("Unable to get info for domain %s" % name)
+        sys.exit(1)
+        
     print sxp.child_value(dom, 'name')
 
 def xm_sched_bvt(args):
@@ -687,7 +698,6 @@
     args = argv[2:]
     if cmd:
         try:
-            from xen.xend.XendClient import XendError
             rc = cmd(args)
             if rc:
                 usage()
Signature · 4 lines
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: [email protected]

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel