kvm tools: Add 'kvm stop'
PATCH 1/1 kvm tools: Add 'kvm stop'
This command stops a running instance.
Syntax:
kvm stop [instance name]
Signed-off-by Sasha Levin <[email protected]>
--- 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
tools/kvm/Documentation/kvm-stop.txt new file +16 -0
@@ -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'.
tools/kvm/Makefile +1 -0
@@ -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
tools/kvm/builtin-run.c +6 -0
@@ -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);
tools/kvm/builtin-stop.c new file +32 -0
@@ -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 ); +}
tools/kvm/command-list.txt +1 -0
@@ -8,3 +8,4 @@ kvm-version common kvm-list common kvm-debug common kvm-balloon common +kvm-stop common
tools/kvm/include/kvm/builtin-stop.h new file +6 -0
@@ -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
tools/kvm/include/kvm/kvm.h +1 -0
@@ -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 */
tools/kvm/kvm-cmd.c +2 -0
@@ -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 },
Signature · 1 line
1.7.6