static u64 inflate;
static u64 deflate;
-struct balloon_cmd {
- u32 type;
- u32 len;
- int amount;
-};
-
static const char * const balloon_usage[] = {
"lkvm balloon [-n name] [-p pid] [-i amount] [-d amount]",
NULL
int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
{
- struct balloon_cmd cmd;
int instance;
int r;
+ int amount;
parse_balloon_options(argc, argv);
if (instance <= 0)
die("Failed locating instance");
- cmd.type = KVM_IPC_BALLOON;
- cmd.len = sizeof(cmd.amount);
-
if (inflate)
- cmd.amount = inflate;
+ amount = inflate;
else if (deflate)
- cmd.amount = -deflate;
+ amount = -deflate;
else
kvm_balloon_help();
- r = write(instance, &cmd, sizeof(cmd));
+ r = kvm_ipc__send_msg(instance, KVM_IPC_BALLOON,
+ sizeof(amount), (u8 *)&amount);
close(instance);
static void handle_mem(int fd, u32 type, u32 len, u8 *msg)
{
- int mem = *(int *)msg;
+ int mem;
+ if (WARN_ON(type != KVM_IPC_BALLOON || len != sizeof(int)))
+ return;
+
+ mem = *(int *)msg;
if (mem > 0) {
bdev.config.num_pages += 256 * mem;
} else if (mem < 0) {