]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/kvm/builtin-resume.c
backlight: tosa: fix checkpatch error and warning
[karo-tx-linux.git] / tools / kvm / builtin-resume.c
1 #include <kvm/util.h>
2 #include <kvm/kvm-cmd.h>
3 #include <kvm/builtin-resume.h>
4 #include <kvm/builtin-list.h>
5 #include <kvm/kvm.h>
6 #include <kvm/parse-options.h>
7 #include <kvm/kvm-ipc.h>
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <signal.h>
12
13 static bool all;
14 static const char *instance_name;
15
16 static const char * const resume_usage[] = {
17         "lkvm resume [--all] [-n name]",
18         NULL
19 };
20
21 static const struct option resume_options[] = {
22         OPT_GROUP("General options:"),
23         OPT_BOOLEAN('a', "all", &all, "Resume all instances"),
24         OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
25         OPT_END()
26 };
27
28 static void parse_resume_options(int argc, const char **argv)
29 {
30         while (argc != 0) {
31                 argc = parse_options(argc, argv, resume_options, resume_usage,
32                                 PARSE_OPT_STOP_AT_NON_OPTION);
33                 if (argc != 0)
34                         kvm_resume_help();
35         }
36 }
37
38 void kvm_resume_help(void)
39 {
40         usage_with_options(resume_usage, resume_options);
41 }
42
43 static int do_resume(const char *name, int sock)
44 {
45         int r;
46         int vmstate;
47
48         vmstate = get_vmstate(sock);
49         if (vmstate < 0)
50                 return vmstate;
51         if (vmstate == KVM_VMSTATE_RUNNING) {
52                 printf("Guest %s is still running.\n", name);
53                 return 0;
54         }
55
56         r = kvm_ipc__send(sock, KVM_IPC_RESUME);
57         if (r)
58                 return r;
59
60         printf("Guest %s resumed\n", name);
61
62         return 0;
63 }
64
65 int kvm_cmd_resume(int argc, const char **argv, const char *prefix)
66 {
67         int instance;
68         int r;
69
70         parse_resume_options(argc, argv);
71
72         if (all)
73                 return kvm__enumerate_instances(do_resume);
74
75         if (instance_name == NULL)
76                 kvm_resume_help();
77
78         instance = kvm__get_sock_by_instance(instance_name);
79
80         if (instance <= 0)
81                 die("Failed locating instance");
82
83         r = do_resume(instance_name, instance);
84
85         close(instance);
86
87         return r;
88 }