This command stops a running instance. Syntax: kvm stop [instance name] Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> --- tools/kvm/Documentation/kvm-stop.txt | 16 ++++++++++++++++ tools/kvm/Makefile | 1 + tools/kvm/builtin-run.c | 6 ++++++ tools/kvm/builtin-stop.c | 32 ++++++++++++++++++++++++++++++++ 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, 65 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/Documentation/kvm-stop.txt create mode 100644 tools/kvm/builtin-stop.c create mode 100644 tools/kvm/include/kvm/builtin-stop.h 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 2e04265..7a76255 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -261,6 +261,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; @@ -489,6 +494,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-stop.c b/tools/kvm/builtin-stop.c new file mode 100644 index 0000000..7dd2015 --- /dev/null +++ b/tools/kvm/builtin-stop.c @@ -0,0 +1,32 @@ +#include <kvm/util.h> +#include <kvm/kvm-cmd.h> +#include <kvm/builtin-stop.h> +#include <kvm/kvm.h> + +#include <stdio.h> +#include <string.h> +#include <signal.h> + +static void do_stop(const char *name, int pid) +{ + kill(pid, SIGKVMSTOP); +} + +int kvm_cmd_stop(int argc, const char **argv, const char *prefix) +{ + int pid; + + if (argc != 1) + die("Usage: kvm stop [instance name]\n"); + + if (strcmp(argv[0], "all") == 0) { + kvm__enumerate_instances(do_stop); + return 0; + } + + pid = kvm__get_pid_by_instance(argv[0]); + if (pid < 0) + die("Failed locating instance name"); + + 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 }, -- 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