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

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

index 855cc8994e874c80c291cdde787d0ae695d5165e..ffd72e80ba16d3b2928ecc3b2c789609fdd85a08 100644 (file)
 
 #include <linux/virtio_balloon.h>
 
-struct stat_cmd {
-       u32 type;
-       u32 len;
-};
-
 static bool mem;
 static bool all;
 static const char *instance_name;
@@ -52,7 +47,6 @@ void kvm_stat_help(void)
 
 static int do_memstat(const char *name, int sock)
 {
-       struct stat_cmd cmd = {KVM_IPC_STAT, 0};
        struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
        fd_set fdset;
        struct timeval t = { .tv_sec = 1 };
@@ -61,7 +55,7 @@ static int do_memstat(const char *name, int sock)
 
        FD_ZERO(&fdset);
        FD_SET(sock, &fdset);
-       r = write(sock, &cmd, sizeof(cmd));
+       r = kvm_ipc__send(sock, KVM_IPC_STAT);
        if (r < 0)
                return r;
 
index bd984b721dab2ab3ff73d6db4a13b30e83ef4e1e..09044d0eb0e9b5432eeaf987f24e784699dc8412 100644 (file)
@@ -144,6 +144,9 @@ static void virtio_bln__print_stats(int fd, u32 type, u32 len, u8 *msg)
 {
        int r;
 
+       if (WARN_ON(type != KVM_IPC_STAT || len))
+               return;
+
        if (virtio_bln__collect_stats() < 0)
                return;