new file mode 100644
@@ -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'.
@@ -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
@@ -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);
new file mode 100644
@@ -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);
+}
@@ -8,3 +8,4 @@ kvm-version common
kvm-list common
kvm-debug common
kvm-balloon common
+kvm-stop common
new file mode 100644
@@ -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
@@ -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 */
@@ -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 },
This command stops a running instance. Syntax: kvm stop [instance name] Signed-off-by: Sasha Levin <levinsasha928@gmail.com> --- 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