From 9000800ce91a60f48adf0b4567b671d29acb2ab0 Mon Sep 17 00:00:00 2001 From: Jean Guyader Date: Wed, 10 Dec 2008 17:38:22 +0000 Subject: [PATCH] suspend-signal from the product patch queue. --- i386-dm/helper2.c | 5 ++++- qemu-xen.h | 2 ++ vl.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/i386-dm/helper2.c b/i386-dm/helper2.c index d383e383..9ffefc55 100644 --- a/i386-dm/helper2.c +++ b/i386-dm/helper2.c @@ -571,7 +571,7 @@ int main_loop(void) qemu_set_fd_handler(xenstore_fd(), xenstore_process_event, NULL, NULL); while (1) { - while (!(vm_running && xen_pause_requested)) + while (!(vm_running && (xen_pause_requested || suspend_requested))) /* Wait up to 10 msec. */ main_loop_wait(10); @@ -587,6 +587,9 @@ int main_loop(void) do_savevm(qemu_file); free(qemu_file); + if (suspend_requested) + return 0; + xenstore_record_dm_state("paused"); /* Wait to be allowed to continue */ diff --git a/qemu-xen.h b/qemu-xen.h index f751a4a8..99b9cd52 100644 --- a/qemu-xen.h +++ b/qemu-xen.h @@ -14,6 +14,8 @@ void qemu_invalidate_map_cache(void); #define mapcache_lock() ((void)0) #define mapcache_unlock() ((void)0) +extern int suspend_requested; + /* helper2.c */ extern long time_offset; void timeoffset_get(void); diff --git a/vl.c b/vl.c index 18da2d32..3a5dc71f 100644 --- a/vl.c +++ b/vl.c @@ -6470,6 +6470,15 @@ void do_loadvm(const char *name) #endif /* !CONFIG_DM */ +void suspend(int sig) +{ + fprintf(stderr, "suspend sig handler called with requested=%d!\n", + suspend_requested); + if (sig != SIGUSR1) + fprintf(stderr, "suspend signal dismatch, get sig=%d!\n", sig); + suspend_requested = 1; +} + void do_delvm(const char *name) { BlockDriverState *bs, *bs1; @@ -7005,6 +7014,7 @@ static QEMUResetEntry *first_reset_entry; static int reset_requested; static int shutdown_requested; static int powerdown_requested; +int suspend_requested = 0; int qemu_shutdown_requested(void) { @@ -9012,6 +9022,26 @@ int main(int argc, char **argv) dom0_driver_init(dom0_input); xenstore_dm_finished_startup(); +#ifndef CONFIG_STUBDOM + /* register signal for the suspend request when save */ + { + struct sigaction act; + sigset_t set; + act.sa_handler = suspend; + act.sa_flags = SA_RESTART; + sigemptyset(&act.sa_mask); + + sigaction(SIGUSR1, &act, NULL); + + /* control panel mask some signals when spawn qemu, need unmask here*/ + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + sigaddset(&set, SIGTERM); + if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) + fprintf(stderr, "unblock signal fail, possible issue for HVM save!\n"); + + } +#endif main_loop(); quit_timers(); -- 2.39.5