]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: carefully send and handle balloon ipc
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 20 Dec 2011 09:08:54 +0000 (17:08 +0800)
committerPekka Enberg <penberg@kernel.org>
Wed, 21 Dec 2011 20:28:09 +0000 (22:28 +0200)
Remove struct balloon_cmd and use kvm_ipc__send_msg().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-balloon.c
tools/kvm/virtio/balloon.c

index 3f3056e55513e76e9db26e08f1023baeb2baec35..5bd2291648a891aa90618f2be2a8e1818ea58db0 100644 (file)
@@ -13,12 +13,6 @@ static const char *instance_name;
 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
@@ -50,9 +44,9 @@ static void parse_balloon_options(int argc, const char **argv)
 
 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);
 
@@ -67,17 +61,15 @@ int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
        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);
 
index 556f0ec5d302daafa1f4d11336b32a5af99a2fed..bd984b721dab2ab3ff73d6db4a13b30e83ef4e1e 100644 (file)
@@ -154,8 +154,12 @@ static void virtio_bln__print_stats(int fd, u32 type, u32 len, u8 *msg)
 
 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) {