Skip to content

Commit

Permalink
kvm tools: Check the state before pause/resume
Browse files Browse the repository at this point in the history
Let the user know what happened

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
  • Loading branch information
Lai Jiangshan authored and wildea01 committed Jun 1, 2015
1 parent 0a56c42 commit 08ffc82
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin-list.c
Expand Up @@ -51,7 +51,7 @@ static pid_t get_pid(int sock)
return pid;
}

static int get_vmstate(int sock)
int get_vmstate(int sock)
{
int vmstate;
int r;
Expand Down
10 changes: 10 additions & 0 deletions builtin-pause.c
@@ -1,6 +1,7 @@
#include <kvm/util.h>
#include <kvm/kvm-cmd.h>
#include <kvm/builtin-pause.h>
#include <kvm/builtin-list.h>
#include <kvm/kvm.h>
#include <kvm/parse-options.h>
#include <kvm/kvm-ipc.h>
Expand Down Expand Up @@ -42,6 +43,15 @@ void kvm_pause_help(void)
static int do_pause(const char *name, int sock)
{
int r;
int vmstate;

vmstate = get_vmstate(sock);
if (vmstate < 0)
return vmstate;
if (vmstate == KVM_VMSTATE_PAUSED) {
printf("Guest %s is already paused.\n", name);
return 0;
}

r = kvm_ipc__send(sock, KVM_IPC_PAUSE);
if (r)
Expand Down
10 changes: 10 additions & 0 deletions builtin-resume.c
@@ -1,6 +1,7 @@
#include <kvm/util.h>
#include <kvm/kvm-cmd.h>
#include <kvm/builtin-resume.h>
#include <kvm/builtin-list.h>
#include <kvm/kvm.h>
#include <kvm/parse-options.h>
#include <kvm/kvm-ipc.h>
Expand Down Expand Up @@ -42,6 +43,15 @@ void kvm_resume_help(void)
static int do_resume(const char *name, int sock)
{
int r;
int vmstate;

vmstate = get_vmstate(sock);
if (vmstate < 0)
return vmstate;
if (vmstate == KVM_VMSTATE_RUNNING) {
printf("Guest %s is still running.\n", name);
return 0;
}

r = kvm_ipc__send(sock, KVM_IPC_RESUME);
if (r)
Expand Down
1 change: 1 addition & 0 deletions include/kvm/builtin-list.h
Expand Up @@ -5,5 +5,6 @@

int kvm_cmd_list(int argc, const char **argv, const char *prefix);
void kvm_list_help(void) NORETURN;
int get_vmstate(int sock);

#endif

0 comments on commit 08ffc82

Please sign in to comment.