Commit-ID: fbc3ef6796d3fc6e73177bcce0acb82f900ed61e Gitweb: http://git.kernel.org/tip/fbc3ef6796d3fc6e73177bcce0acb82f900ed61e Author: Sasha Levin <levinsasha928@xxxxxxxxx> AuthorDate: Fri, 5 Aug 2011 18:21:10 +0300 Committer: Pekka Enberg <penberg@xxxxxxxxxx> CommitDate: Sun, 7 Aug 2011 21:01:22 +0300 kvm tools: Add 'kvm stop' This command stops a running instance. Syntax: kvm stop [instance name] Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx> --- tools/kvm/Documentation/kvm-stop.txt | 16 ++++++++++++++++ tools/kvm/Makefile | 1 + tools/kvm/builtin-run.c | 6 ++++++ tools/kvm/{builtin-pause.c => builtin-stop.c} | 22 +++++++++++----------- tools/kvm/command-list.txt | 1 + tools/kvm/include/kvm/builtin-stop.h | 6 ++++++ tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/kvm-cmd.c | 2 ++ 8 files changed, 44 insertions(+), 11 deletions(-) diff --git a/tools/kvm/Documentation/kvm-stop.txt b/tools/kvm/Documentation/kvm-stop.txt new file mode 100644 index 0000000..5267081 --- /dev/null +++ b/tools/kvm/Documentation/kvm-stop.txt @@ -0,0 +1,16 @@ +kvm-stop(1) +================ + +NAME +---- +kvm-stop - Stop a running instance + +SYNOPSIS +-------- +[verse] +'kvm stop [instance]' + +DESCRIPTION +----------- +The command stops a running instance. +For a list of running instances see 'kvm list'. diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 21d6189..b52f503 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -26,6 +26,7 @@ OBJS += builtin-help.o OBJS += builtin-list.o OBJS += builtin-pause.o OBJS += builtin-run.o +OBJS += builtin-stop.o OBJS += builtin-version.o OBJS += cpuid.o OBJS += disk/core.o diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 67ab43e..c8539cc 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -274,6 +274,11 @@ static void handle_sigalrm(int sig) virtio_console__inject_interrupt(kvm); } +static void handle_sigstop(int sig) +{ + kvm_cpu__reboot(); +} + static void *kvm_cpu_thread(void *arg) { current_kvm_cpu = arg; @@ -502,6 +507,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(SIGKVMSTOP, handle_sigstop); nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-stop.c similarity index 53% copy from tools/kvm/builtin-pause.c copy to tools/kvm/builtin-stop.c index 0c0010d..7dd2015 100644 --- a/tools/kvm/builtin-pause.c +++ b/tools/kvm/builtin-stop.c @@ -1,26 +1,26 @@ -#include <stdio.h> -#include <string.h> -#include <signal.h> - #include <kvm/util.h> #include <kvm/kvm-cmd.h> -#include <kvm/builtin-pause.h> +#include <kvm/builtin-stop.h> #include <kvm/kvm.h> -static void do_pause(const char *name, int pid) +#include <stdio.h> +#include <string.h> +#include <signal.h> + +static void do_stop(const char *name, int pid) { - kill(pid, SIGUSR2); + kill(pid, SIGKVMSTOP); } -int kvm_cmd_pause(int argc, const char **argv, const char *prefix) +int kvm_cmd_stop(int argc, const char **argv, const char *prefix) { int pid; if (argc != 1) - die("Usage: kvm debug [instance name]\n"); + die("Usage: kvm stop [instance name]\n"); if (strcmp(argv[0], "all") == 0) { - kvm__enumerate_instances(do_pause); + kvm__enumerate_instances(do_stop); return 0; } @@ -28,5 +28,5 @@ int kvm_cmd_pause(int argc, const char **argv, const char *prefix) if (pid < 0) die("Failed locating instance name"); - return kill(pid, SIGUSR2); + return kill(pid, SIGKVMSTOP); } diff --git a/tools/kvm/command-list.txt b/tools/kvm/command-list.txt index 037a8ea..fd809a8 100644 --- a/tools/kvm/command-list.txt +++ b/tools/kvm/command-list.txt @@ -8,3 +8,4 @@ kvm-version common kvm-list common kvm-debug common kvm-balloon common +kvm-stop common diff --git a/tools/kvm/include/kvm/builtin-stop.h b/tools/kvm/include/kvm/builtin-stop.h new file mode 100644 index 0000000..317d34d --- /dev/null +++ b/tools/kvm/include/kvm/builtin-stop.h @@ -0,0 +1,6 @@ +#ifndef KVM__STOP_H +#define KVM__STOP_H + +int kvm_cmd_stop(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..722b24b 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 SIGKVMSTOP (SIGRTMIN + 4) 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..d85cb0a 100644 --- a/tools/kvm/kvm-cmd.c +++ b/tools/kvm/kvm-cmd.c @@ -10,6 +10,7 @@ #include "kvm/builtin-balloon.h" #include "kvm/builtin-list.h" #include "kvm/builtin-version.h" +#include "kvm/builtin-stop.h" #include "kvm/builtin-help.h" #include "kvm/kvm-cmd.h" #include "kvm/builtin-run.h" @@ -20,6 +21,7 @@ struct cmd_struct kvm_commands[] = { { "balloon", kvm_cmd_balloon, NULL, 0 }, { "list", kvm_cmd_list, NULL, 0 }, { "version", kvm_cmd_version, NULL, 0 }, + { "stop", kvm_cmd_stop, NULL, 0 }, { "help", kvm_cmd_help, NULL, 0 }, { "run", kvm_cmd_run, kvm_run_help, 0 }, { NULL, NULL, NULL, 0 }, -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html
![]() |