Skip to contentSkip to conversation

kvm tools: Split 'kvm pause' and add 'kvm resume'

PATCH RESEND New Sasha Levin 1 participant 1 message Aug 7, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 kvm tools: Split 'kvm pause' and add 'kvm resume'

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'.

---
 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
tools/kvm/Documentation/kvm-pause.txt +2 -2
index 773824f..770bcfe 100644
@@ -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'.
tools/kvm/Documentation/kvm-resume.txt new file +16 -0
new file mode 100644
index 0000000..918648e
@@ -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'.
tools/kvm/Makefile +1 -0
index 8d45ebf..672027d 100644
@@ -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-stop.o
 OBJS	+= builtin-version.o
tools/kvm/builtin-pause.c +1 -1
index 0c0010d..827b3b4 100644
@@ -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);
tools/kvm/builtin-resume.c new file +32 -0
new file mode 100644
index 0000000..4a85918
@@ -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);
+}
tools/kvm/builtin-run.c +5 -2
index c8539cc..364b538 100644
@@ -235,10 +235,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");
@@ -508,6 +510,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 	signal(SIGUSR1, handle_sigusr1);
 	signal(SIGUSR2, handle_sigusr2);
 	signal(SIGKVMSTOP, handle_sigstop);
+	signal(SIGKVMRESUME, handle_sigusr2);
 
 	nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
tools/kvm/command-list.txt +1 -0
index fd809a8..6a49d0a 100644
@@ -4,6 +4,7 @@
 #
 kvm-run				mainporcelain common
 kvm-pause			common
+kvm-resume			common
 kvm-version			common
 kvm-list			common
 kvm-debug			common
tools/kvm/include/kvm/builtin-resume.h new file +6 -0
new file mode 100644
index 0000000..4a64747
@@ -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
tools/kvm/include/kvm/kvm.h +1 -0
index 722b24b..4f12d11 100644
@@ -21,6 +21,7 @@
 #define SIGKVMADDMEM		(SIGRTMIN + 2)
 #define SIGKVMDELMEM		(SIGRTMIN + 3)
 #define SIGKVMSTOP		(SIGRTMIN + 4)
+#define SIGKVMRESUME		(SIGRTMIN + 5)
 
 struct kvm {
 	int			sys_fd;		/* For system ioctls(), i.e. /dev/kvm */
tools/kvm/kvm-cmd.c +2 -0
index d85cb0a..63a2dbf 100644
@@ -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"
@@ -17,6 +18,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 },
Signature · 1 line
1.7.6