The discovered bit in PGCCSR register indicates if the device has been
[linux-2.6/next.git] / tools / kvm / builtin-balloon.c
blob73290635a92a9fd8a9c50a804053ed360f1bda4b
1 #include <stdio.h>
2 #include <string.h>
3 #include <signal.h>
5 #include <kvm/util.h>
6 #include <kvm/kvm-cmd.h>
7 #include <kvm/builtin-balloon.h>
8 #include <kvm/parse-options.h>
9 #include <kvm/kvm.h>
11 static pid_t instance_pid;
12 static const char *instance_name;
13 static u64 inflate;
14 static u64 deflate;
16 static const char * const balloon_usage[] = {
17 "kvm balloon [-n name] [-p pid] [-i amount] [-d amount]",
18 NULL
21 static const struct option balloon_options[] = {
22 OPT_GROUP("Instance options:"),
23 OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
24 OPT_INTEGER('p', "pid", &instance_pid, "Instance pid"),
25 OPT_GROUP("Balloon options:"),
26 OPT_U64('i', "inflate", &inflate, "Amount to inflate"),
27 OPT_U64('d', "deflate", &deflate, "Amount to deflate"),
28 OPT_END(),
31 void kvm_balloon_help(void)
33 usage_with_options(balloon_usage, balloon_options);
36 static void parse_balloon_options(int argc, const char **argv)
38 while (argc != 0) {
39 argc = parse_options(argc, argv, balloon_options, balloon_usage,
40 PARSE_OPT_STOP_AT_NON_OPTION);
41 if (argc != 0)
42 kvm_balloon_help();
46 int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
48 u64 i;
50 parse_balloon_options(argc, argv);
52 if (inflate == 0 && deflate == 0)
53 kvm_balloon_help();
55 if (instance_name == NULL &&
56 instance_pid == 0)
57 kvm_balloon_help();
59 if (instance_name)
60 instance_pid = kvm__get_pid_by_instance(instance_name);
62 if (instance_pid <= 0)
63 die("Failed locating instance");
65 if (inflate)
66 for (i = 0; i < inflate; i++)
67 kill(instance_pid, SIGKVMADDMEM);
68 else if (deflate)
69 for (i = 0; i < deflate; i++)
70 kill(instance_pid, SIGKVMDELMEM);
71 else
72 kvm_balloon_help();
74 return 0;