6 #include <kvm/kvm-cmd.h>
7 #include <kvm/builtin-balloon.h>
8 #include <kvm/parse-options.h>
11 static pid_t instance_pid
;
12 static const char *instance_name
;
16 static const char * const balloon_usage
[] = {
17 "kvm balloon [-n name] [-p pid] [-i amount] [-d amount]",
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"),
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
)
39 argc
= parse_options(argc
, argv
, balloon_options
, balloon_usage
,
40 PARSE_OPT_STOP_AT_NON_OPTION
);
46 int kvm_cmd_balloon(int argc
, const char **argv
, const char *prefix
)
50 parse_balloon_options(argc
, argv
);
52 if (inflate
== 0 && deflate
== 0)
55 if (instance_name
== NULL
&&
60 instance_pid
= kvm__get_pid_by_instance(instance_name
);
62 if (instance_pid
<= 0)
63 die("Failed locating instance");
66 for (i
= 0; i
< inflate
; i
++)
67 kill(instance_pid
, SIGKVMADDMEM
);
69 for (i
= 0; i
< deflate
; i
++)
70 kill(instance_pid
, SIGKVMDELMEM
);