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 01/11] xen: do not respond to unknown xenstore contro

To: Stefano Stabellini <Stefano.Stabellini@xxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 01/11] xen: do not respond to unknown xenstore control requests
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Tue, 15 Feb 2011 14:13:15 +0000
Cc: Jeremy Fitzhardinge <jeremy@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx, Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Tue, 15 Feb 2011 06:15:11 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1297779181.21980.3722.camel@xxxxxxxxxxxxxxxxxxxxxx>
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/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1297779181.21980.3722.camel@xxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
The PV xenbus control/shutdown node is written by the toolstack as a
request to the guest to perform a particular action (shutdown, reboot,
suspend etc). The guest is expected to acknowledge that it will
complete a request by clearing the control node.

Previously it would acknowledge any request, even if it did not know
what to do with it. Specifically in the case where CONFIG_PM_SLEEP is
not enabled the kernel would acknowledge a suspend request even though
it was not actually going to do anything.

Instead make the kernel only acknowledge requests if it is actually
going to do something with it. This will improve the toolstack's
ability to diagnose and deal with failures.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 drivers/xen/manage.c |   49 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index 2417727..6f866e2 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -172,12 +172,39 @@ out:
 }
 #endif /* CONFIG_PM_SLEEP */
 
+struct shutdown_handler {
+       const char *command;
+       void (*cb)(void);
+};
+
+static void do_poweroff(void)
+{
+       shutting_down = SHUTDOWN_POWEROFF;
+       orderly_poweroff(false);
+}
+
+static void do_reboot(void)
+{
+       shutting_down = SHUTDOWN_POWEROFF; /* ? */
+       ctrl_alt_del();
+}
+
 static void shutdown_handler(struct xenbus_watch *watch,
                             const char **vec, unsigned int len)
 {
        char *str;
        struct xenbus_transaction xbt;
        int err;
+       static struct shutdown_handler handlers[] = {
+               { "poweroff",   do_poweroff },
+               { "halt",       do_poweroff },
+               { "reboot",     do_reboot   },
+#ifdef CONFIG_PM_SLEEP
+               { "suspend",    do_suspend  },
+#endif
+               {NULL, NULL},
+       };
+       static struct shutdown_handler *handler;
 
        if (shutting_down != SHUTDOWN_INVALID)
                return;
@@ -194,7 +221,14 @@ static void shutdown_handler(struct xenbus_watch *watch,
                return;
        }
 
-       xenbus_write(xbt, "control", "shutdown", "");
+       for (handler = &handlers[0]; handler->command; handler++) {
+               if (strcmp(str, handler->command) == 0)
+                       break;
+       }
+
+       /* Only acknowledge commands which we are prepared to handle. */
+       if (handler->cb)
+               xenbus_write(xbt, "control", "shutdown", "");
 
        err = xenbus_transaction_end(xbt, 0);
        if (err == -EAGAIN) {
@@ -202,17 +236,8 @@ static void shutdown_handler(struct xenbus_watch *watch,
                goto again;
        }
 
-       if (strcmp(str, "poweroff") == 0 ||
-           strcmp(str, "halt") == 0) {
-               shutting_down = SHUTDOWN_POWEROFF;
-               orderly_poweroff(false);
-       } else if (strcmp(str, "reboot") == 0) {
-               shutting_down = SHUTDOWN_POWEROFF; /* ? */
-               ctrl_alt_del();
-#ifdef CONFIG_PM_SLEEP
-       } else if (strcmp(str, "suspend") == 0) {
-               do_suspend();
-#endif
+       if (handler->cb) {
+               handler->cb();
        } else {
                printk(KERN_INFO "Ignoring shutdown request: %s\n", str);
                shutting_down = SHUTDOWN_INVALID;
-- 
1.5.6.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>