WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 1/2] Make shutdown use strings instead of codes

To: "List: Xen Developers" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 1/2] Make shutdown use strings instead of codes
From: Dan Smith <danms@xxxxxxxxxx>
Date: Fri, 05 Aug 2005 11:53:26 -0700
Delivery-date: Fri, 05 Aug 2005 18:52:20 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux)
This patch changes the shutdown driver and xend to use strings instead
of codes for signaling a shutdown request.

Also, we fix the return code for the shutdown notifier, so other
notifiers will get to run ;)

Signed-off-by: Dan Smith <danms@xxxxxxxxxx>

diff -r 5a33233a608e -r a94ff69a51a3 
linux-2.6-xen-sparse/arch/xen/kernel/reboot.c
--- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c     Fri Aug  5 09:53:04 2005
+++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c     Fri Aug  5 16:04:24 2005
@@ -247,19 +247,31 @@
 {
     static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
 
-    int type = -1;
-
-    if (!xenbus_scanf("control", "shutdown", "%i", &type)) {
-        printk("Unable to read code in control/shutdown\n");
+    char *str;
+    unsigned int len;
+
+    str = (char *)xenbus_read("control", "shutdown", &len);
+
+    if (! len) {
         return;
-    };
+    }
 
     xenbus_printf("control", "shutdown", "%i", SHUTDOWN_INVALID);
 
-    if ((type == SHUTDOWN_POWEROFF) ||
-        (type == SHUTDOWN_REBOOT)   ||
-        (type == SHUTDOWN_SUSPEND)) {
-        shutting_down = type;
+    if (strncmp(str, "poweroff", len) == 0) {
+        shutting_down = SHUTDOWN_POWEROFF;
+    } else if (strncmp(str, "reboot", len) == 0) {
+        shutting_down = SHUTDOWN_REBOOT;
+    } else if (strncmp(str, "suspend", len) == 0) {
+        shutting_down = SHUTDOWN_SUSPEND;
+    } else {
+        printk("Ignoring shutdown request: %s\n", str);
+        shutting_down = SHUTDOWN_INVALID;
+    }
+
+    kfree(str);
+
+    if (shutting_down != SHUTDOWN_INVALID) {
         schedule_work(&shutdown_work);
     }
 
@@ -271,7 +283,7 @@
     char sysrq_key = '\0';
     
     if (!xenbus_scanf("control", "sysrq", "%c", &sysrq_key)) {
-        printk("Unable to read sysrq code in control/sysrq\n");
+        printk(KERN_ERR "Unable to read sysrq code in control/sysrq\n");
         return;
     }
 
@@ -319,16 +331,16 @@
     up(&xenbus_lock);
 
     if (err1) {
-        printk("Failed to set shutdown watcher\n");
+        printk(KERN_ERR "Failed to set shutdown watcher\n");
     }
     
 #ifdef CONFIG_MAGIC_SYSRQ
     if (err2) {
-        printk("Failed to set sysrq watcher\n");
-    }
-#endif
-
-    return NOTIFY_STOP;
+        printk(KERN_ERR "Failed to set sysrq watcher\n");
+    }
+#endif
+
+    return NOTIFY_DONE;
 }
 
 static int __init setup_shutdown_event(void)
diff -r 5a33233a608e -r a94ff69a51a3 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Fri Aug  5 09:53:04 2005
+++ b/tools/python/xen/xend/XendDomainInfo.py   Fri Aug  5 16:04:24 2005
@@ -50,14 +50,6 @@
     DOMAIN_REBOOT  : "reboot",
     DOMAIN_SUSPEND : "suspend",
     DOMAIN_CRASH   : "crash",
-    }
-
-"""Map shutdown reasons to codes
-"""
-shutdown_codes = {
-    'poweroff' : DOMAIN_POWEROFF,
-    'reboot'   : DOMAIN_REBOOT,
-    'suspend'  : DOMAIN_SUSPEND,
     }
 
 RESTART_ALWAYS   = 'always'
@@ -939,11 +931,10 @@
             self.channel.writeRequest(msg)
 
     def shutdown(self, reason):
-        reasonid = shutdown_codes.get(reason)
-        if reasonid == None:
+        if not reason in shutdown_reasons.values():
             raise XendError('invalid reason:' + reason)
         db = self.db.addChild("/control");
-        db['shutdown'] = '%i' % reasonid;
+        db['shutdown'] = reason;
         db.saveDB(save=True);
         if not reason in ['suspend']:
             self.shutdown_pending = {'start':time.time(), 'reason':reason}
-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms@xxxxxxxxxx
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>