]> xenbits.xensource.com Git - mini-os.git/commitdiff
Save/Restore Support: Moved shutdown thread to shutdown.c
authorBruno Alvisio <bruno.alvisio@gmail.com>
Mon, 11 Dec 2017 15:22:31 +0000 (07:22 -0800)
committerWei Liu <wei.liu2@citrix.com>
Wed, 21 Mar 2018 09:16:49 +0000 (09:16 +0000)
The shutdown thread present in kernel.c was removed and now the thread in
shutdown.c is created instead.

Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
arch/x86/setup.c
include/kernel.h
kernel.c

index 3dd86f9627b7ae7db3a0e051595291a7f53c168f..31fa2c64511c4e47cb6ff5ca08ee4fe698b6dcdb 100644 (file)
@@ -201,7 +201,7 @@ arch_init(void *par)
        memcpy(&start_info, par, sizeof(start_info));
 #endif
 
-       start_kernel();
+       start_kernel((start_info_t *)par);
 }
 
 void arch_pre_suspend(void)
index 161d757103e92fb8ec4a90d1713af6cacb2e8f79..742abf5fcd45353acef842b822ffb36331f699e5 100644 (file)
@@ -4,7 +4,7 @@
 #define MAX_CMDLINE_SIZE 1024
 extern char cmdline[MAX_CMDLINE_SIZE];
 
-void start_kernel(void);
+void start_kernel(void* par);
 void pre_suspend(void);
 void post_suspend(int canceled);
 void do_exit(void) __attribute__((noreturn));
index 90c865a2f460bfa9cdb2d743e0f75c0e09ab9dbd..1cd40e8b552a3f44c6e2899d8c7885733d5236a1 100644 (file)
--- a/kernel.c
+++ b/kernel.c
@@ -42,6 +42,9 @@
 #include <mini-os/blkfront.h>
 #include <mini-os/fbfront.h>
 #include <mini-os/pcifront.h>
+#ifdef CONFIG_XENBUS
+#include <mini-os/shutdown.h>
+#endif
 #include <mini-os/xmalloc.h>
 #include <fcntl.h>
 #include <xen/features.h>
@@ -66,48 +69,6 @@ void setup_xen_features(void)
     }
 }
 
-#ifdef CONFIG_XENBUS
-/* This should be overridden by the application we are linked against. */
-__attribute__((weak)) void app_shutdown(unsigned reason)
-{
-    struct sched_shutdown sched_shutdown = { .reason = reason };
-    printk("Shutdown requested: %d\n", reason);
-    HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
-}
-
-static void shutdown_thread(void *p)
-{
-    const char *path = "control/shutdown";
-    const char *token = path;
-    xenbus_event_queue events = NULL;
-    char *shutdown = NULL, *err;
-    unsigned int shutdown_reason;
-    xenbus_watch_path_token(XBT_NIL, path, token, &events);
-    while ((err = xenbus_read(XBT_NIL, path, &shutdown)) != NULL || !strcmp(shutdown, ""))
-    {
-        free(err);
-        free(shutdown);
-        shutdown = NULL;
-        xenbus_wait_for_watch(&events);
-    }
-    err = xenbus_unwatch_path_token(XBT_NIL, path, token);
-    free(err);
-    err = xenbus_write(XBT_NIL, path, "");
-    free(err);
-    printk("Shutting down (%s)\n", shutdown);
-
-    if (!strcmp(shutdown, "poweroff"))
-        shutdown_reason = SHUTDOWN_poweroff;
-    else if (!strcmp(shutdown, "reboot"))
-        shutdown_reason = SHUTDOWN_reboot;
-    else
-        /* Unknown */
-        shutdown_reason = SHUTDOWN_crash;
-    app_shutdown(shutdown_reason);
-    free(shutdown);
-}
-#endif
-
 
 /* This should be overridden by the application we are linked against. */
 __attribute__((weak)) int app_main(void *p)
@@ -116,7 +77,7 @@ __attribute__((weak)) int app_main(void *p)
     return 0;
 }
 
-void start_kernel(void)
+void start_kernel(void* par)
 {
     /* Set up events. */
     init_events();
@@ -145,7 +106,8 @@ void start_kernel(void)
     init_xenbus();
 
 #ifdef CONFIG_XENBUS
-    create_thread("shutdown", shutdown_thread, NULL);
+    /* Init shutdown thread */
+    init_shutdown((start_info_t *)par);
 #endif
 
     /* Call (possibly overridden) app_main() */