Skip to contentSkip to conversation

Fix argument check of xm reboot command (3)

PATCH In review Masaki Kanno 2 participants 4 messages Jul 6, 2006 – Jul 28, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix argument check of xm reboot command (3)

Hi,

I tested unlikely operations about the xm reboot/shutdown command. As a result, I found the following problems.

Problem 1: Can reboot/shutdown Domain-0 by mistake.

  # xm list
  Name                              ID Mem(MiB) VCPUs State  Time(s)
  Domain-0                           0     1024     2 r-----    31.0
  # xm reboot 0
  Error: Can't specify Domain-0
  # xm reboot 00
  # 
  Broadcast message from root (console) (Thu Jul  6 23:50:09 2006):

The system is going down for reboot NOW!

Problem 2: Can not reboot/shutdown domain of domain name '0'.

  # xm list
  Name                              ID Mem(MiB) VCPUs State  Time(s)
  0                                  1      256     1 -b----     3.5
  Domain-0                           0     1024     2 r-----    29.8
  # xm reboot 0
  Error: Can't specify Domain-0

I fixed these problems with this patch.

Best regards,
Kan

tools/python/xen/xm/shutdown.py +30 -11
diff -r 8e55c5c11475 tools/python/xen/xm/shutdown.py
@@ -22,8 +22,6 @@ from xen.xend.XendClient import server
 from xen.xend.XendClient import server
 from xen.xend import sxp
 from xen.xm.opts import *
-
-DOM0_ID = '0'
 
 gopts = Opts(use="""[options] [DOM]
 
@@ -51,14 +49,6 @@ gopts.opt('reboot', short='R',
           use='Shutdown and reboot.')
 
 def shutdown(opts, doms, mode, wait):
-    if doms == None: doms = server.xend.domains(0)
-    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
-    for x in [dom0_name, DOM0_ID]:
-        if x in doms:
-            if opts.vals.all:
-                doms.remove(x)
-            else:
-                opts.err("Can't specify Domain-0")
     for d in doms:
         server.xend.domain.shutdown(d, mode)
     if wait:
@@ -86,13 +76,42 @@ def shutdown_mode(opts):
         return 'poweroff'
 
 def main_all(opts, args):
+    doms = server.xend.domains(0)
+    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
+    
+    doms.remove(dom0_name)
+    
     mode = shutdown_mode(opts)  
-    shutdown(opts, None, mode, opts.vals.wait)
+    shutdown(opts, doms, mode, opts.vals.wait)
 
 def main_dom(opts, args):
     if len(args) == 0: opts.err('No domain parameter given')
     if len(args) >  1: opts.err('No multiple domain parameters allowed')
     dom = args[0]
+    
+    doms = server.xend.domains(0)
+    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
+    
+    # We confirm whether the domain of the specified domain name exists.
+    dom_exist = 0
+    for d in doms:
+        if d == dom:
+            if d == dom0_name: opts.err("Can't specify Domain-0")
+            dom_exist = 1
+            break
+    
+    # If the domain of the specified domain name doesn't exist,
+    # we assume that domain ID was specified. 
+    if not dom_exist:
+        # If character strings are all '0',
+        # we assume that Domain-0 was specified.
+        all_zero = 1
+        for s in dom:
+            if s != '0':
+                all_zero = 0
+                break
+        if all_zero: opts.err("Can't specify Domain-0")
+    
     mode = shutdown_mode(opts)  
     shutdown(opts, [ dom ], mode, opts.vals.wait)
     

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

#1 lore raw
Quoted 5 lines · Masaki Kanno

tested unlikely operations about the xm reboot/shutdown command.
As a result, I found the following problems.

Problem 1: Can reboot/shutdown Domain-0 by mistake. Problem 2: Can not reboot/shutdown domain of domain name '0'.

Wouldn't this be better checked in xend after it has converted domain name to domid, and an appropriate error string returned to the RPC caller? Putting the checking in xm seems a bit unnatural and means that other callers do not benefit.

-- Keir

#2 lore raw

Hi Keir,

Thanks for your comment and advice.
I will remake and resend this patch.

Best regards,
Kan

Quoted 21 lines · Masaki Kanno
Quoted 6 lines

tested unlikely operations about the xm reboot/shutdown command.
As a result, I found the following problems.

Problem 1: Can reboot/shutdown Domain-0 by mistake. Problem 2: Can not reboot/shutdown domain of domain name '0'.

Wouldn't this be better checked in xend after it has converted domain name to domid, and an appropriate error string returned to the RPC caller? Putting the checking in xm seems a bit unnatural and means that other callers do not benefit.

-- Keir

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

#3 lore raw
In reply to Keir Fraser

Hi,

I made a patch again.

Best regards,
Kan

Quoted 14 lines · Masaki Kanno
Quoted 6 lines

tested unlikely operations about the xm reboot/shutdown command.
As a result, I found the following problems.

Problem 1: Can reboot/shutdown Domain-0 by mistake. Problem 2: Can not reboot/shutdown domain of domain name '0'.

Wouldn't this be better checked in xend after it has converted domain name to domid, and an appropriate error string returned to the RPC caller? Putting the checking in xm seems a bit unnatural and means that other callers do not benefit.

Quoted 7 lines

-- Keir

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

tools/python/xen/xend/XendDomainInfo.py +2 -0
diff -r 5848356af8da tools/python/xen/xend/XendDomainInfo.py
@@ -943,6 +943,8 @@ class XendDomainInfo:
     def shutdown(self, reason):
         if not reason in shutdown_reasons.values():
             raise XendError('Invalid reason: %s' % reason)
+        if self.domid == 0:
+            raise XendError("Can't specify Domain-0")
         self.storeDom("control/shutdown", reason)
 
 
tools/python/xen/xm/shutdown.py +4 -11
diff -r 5848356af8da tools/python/xen/xm/shutdown.py
@@ -22,8 +22,6 @@ from xen.xend.XendClient import server
 from xen.xend.XendClient import server
 from xen.xend import sxp
 from xen.xm.opts import *
-
-DOM0_ID = '0'
 
 gopts = Opts(use="""[options] [DOM]
 
@@ -51,14 +49,6 @@ gopts.opt('reboot', short='R',
           use='Shutdown and reboot.')
 
 def shutdown(opts, doms, mode, wait):
-    if doms == None: doms = server.xend.domains(0)
-    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
-    for x in [dom0_name, DOM0_ID]:
-        if x in doms:
-            if opts.vals.all:
-                doms.remove(x)
-            else:
-                opts.err("Can't specify Domain-0")
     for d in doms:
         server.xend.domain.shutdown(d, mode)
     if wait:
@@ -86,8 +76,11 @@ def shutdown_mode(opts):
         return 'poweroff'
 
 def main_all(opts, args):
+    doms = server.xend.domains(0)
+    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
+    doms.remove(dom0_name)
     mode = shutdown_mode(opts)  
-    shutdown(opts, None, mode, opts.vals.wait)
+    shutdown(opts, doms, mode, opts.vals.wait)
 
 def main_dom(opts, args):
     if len(args) == 0: opts.err('No domain parameter given')

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