This patch seperates 'kvm pause' into 'kvm pause' and 'kvm resume', 'kvm pause' no longer acts as a switch between running and paused state but instead just switches the instance into paused and reume is handled by the new 'kvm resume'. Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> --- tools/kvm/Documentation/kvm-pause.txt | 4 ++-- tools/kvm/Documentation/kvm-resume.txt | 16 ++++++++++++++++ tools/kvm/Makefile | 1 + tools/kvm/builtin-pause.c | 2 +- tools/kvm/builtin-resume.c | 32 ++++++++++++++++++++++++++++++++ tools/kvm/builtin-run.c | 7 +++++-- tools/kvm/command-list.txt | 1 + tools/kvm/include/kvm/builtin-resume.h | 6 ++++++ tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/kvm-cmd.c | 2 ++ 10 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 tools/kvm/Documentation/kvm-resume.txt create mode 100644 tools/kvm/builtin-resume.c create mode 100644 tools/kvm/include/kvm/builtin-resume.h diff --git a/tools/kvm/Documentation/kvm-pause.txt b/tools/kvm/Documentation/kvm-pause.txt index 773824f..770bcfe 100644 --- a/tools/kvm/Documentation/kvm-pause.txt +++ b/tools/kvm/Documentation/kvm-pause.txt @@ -3,7 +3,7 @@ kvm-pause(1) NAME ---- -kvm-pause - Pause/resume the virtual machine +kvm-pause - Pause the virtual machine SYNOPSIS -------- @@ -12,5 +12,5 @@ SYNOPSIS DESCRIPTION ----------- -The command pauses and resumes a virtual machine. +The command pauses a virtual machine. For a list of running instances see 'kvm list'. diff --git a/tools/kvm/Documentation/kvm-resume.txt b/tools/kvm/Documentation/kvm-resume.txt new file mode 100644 index 0000000..918648e --- /dev/null +++ b/tools/kvm/Documentation/kvm-resume.txt @@ -0,0 +1,16 @@ +kvm-resume(1) +================ + +NAME +---- +kvm-resume - Resume the virtual machine + +SYNOPSIS +-------- +[verse] +'kvm resume [instance]' + +DESCRIPTION +----------- +The command resumes a virtual machine. +For a list of running instances see 'kvm list'. diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 21d6189..0a218d7 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -25,6 +25,7 @@ OBJS += builtin-debug.o OBJS += builtin-help.o OBJS += builtin-list.o OBJS += builtin-pause.o +OBJS += builtin-resume.o OBJS += builtin-run.o OBJS += builtin-version.o OBJS += cpuid.o diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c index 0c0010d..827b3b4 100644 --- a/tools/kvm/builtin-pause.c +++ b/tools/kvm/builtin-pause.c @@ -17,7 +17,7 @@ int kvm_cmd_pause(int argc, const char **argv, const char *prefix) int pid; if (argc != 1) - die("Usage: kvm debug [instance name]\n"); + die("Usage: kvm pause [instance name]\n"); if (strcmp(argv[0], "all") == 0) { kvm__enumerate_instances(do_pause); diff --git a/tools/kvm/builtin-resume.c b/tools/kvm/builtin-resume.c new file mode 100644 index 0000000..4a85918 --- /dev/null +++ b/tools/kvm/builtin-resume.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <string.h> +#include <signal.h> + +#include <kvm/util.h> +#include <kvm/kvm-cmd.h> +#include <kvm/builtin-resume.h> +#include <kvm/kvm.h> + +static void do_resume(const char *name, int pid) +{ + kill(pid, SIGKVMRESUME); +} + +int kvm_cmd_resume(int argc, const char **argv, const char *prefix) +{ + int pid; + + if (argc != 1) + die("Usage: kvm resume [instance name]\n"); + + if (strcmp(argv[0], "all") == 0) { + kvm__enumerate_instances(do_resume); + return 0; + } + + pid = kvm__get_pid_by_instance(argv[0]); + if (pid < 0) + die("Failed locating instance name"); + + return kill(pid, SIGKVMRESUME); +} diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 2e04265..3a6551a 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -222,10 +222,12 @@ static int is_paused; static void handle_sigusr2(int sig) { - if (is_paused) + if (sig == SIGKVMRESUME && is_paused) kvm__continue(); - else + else if (sig == SIGUSR2 && !is_paused) kvm__pause(); + else + return; is_paused = !is_paused; pr_info("Guest %s\n", is_paused ? "paused" : "resumed"); @@ -489,6 +491,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) signal(SIGQUIT, handle_sigquit); signal(SIGUSR1, handle_sigusr1); signal(SIGUSR2, handle_sigusr2); + signal(SIGKVMRESUME, handle_sigusr2); nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); diff --git a/tools/kvm/command-list.txt b/tools/kvm/command-list.txt index 037a8ea..e7ed012 100644 --- a/tools/kvm/command-list.txt +++ b/tools/kvm/command-list.txt @@ -4,6 +4,7 @@ # kvm-run mainporcelain common kvm-pause common +kvm-resume common kvm-version common kvm-list common kvm-debug common diff --git a/tools/kvm/include/kvm/builtin-resume.h b/tools/kvm/include/kvm/builtin-resume.h new file mode 100644 index 0000000..4a64747 --- /dev/null +++ b/tools/kvm/include/kvm/builtin-resume.h @@ -0,0 +1,6 @@ +#ifndef KVM__RESUME_H +#define KVM__RESUME_H + +int kvm_cmd_resume(int argc, const char **argv, const char *prefix); + +#endif diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 5f3cbbf..1cb727b 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -20,6 +20,7 @@ #define SIGKVMPAUSE (SIGRTMIN + 1) #define SIGKVMADDMEM (SIGRTMIN + 2) #define SIGKVMDELMEM (SIGRTMIN + 3) +#define SIGKVMRESUME (SIGRTMIN + 5) struct kvm { int sys_fd; /* For system ioctls(), i.e. /dev/kvm */ diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c index a954a61..12eb3fb 100644 --- a/tools/kvm/kvm-cmd.c +++ b/tools/kvm/kvm-cmd.c @@ -7,6 +7,7 @@ /* user defined header files */ #include "kvm/builtin-debug.h" #include "kvm/builtin-pause.h" +#include "kvm/builtin-resume.h" #include "kvm/builtin-balloon.h" #include "kvm/builtin-list.h" #include "kvm/builtin-version.h" @@ -16,6 +17,7 @@ struct cmd_struct kvm_commands[] = { { "pause", kvm_cmd_pause, NULL, 0 }, + { "resume", kvm_cmd_resume, NULL, 0 }, { "debug", kvm_cmd_debug, NULL, 0 }, { "balloon", kvm_cmd_balloon, NULL, 0 }, { "list", kvm_cmd_list, NULL, 0 }, -- 1.7.6 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html