]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: add kvm_ipc__receive()
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 20 Dec 2011 09:08:50 +0000 (17:08 +0800)
committerPekka Enberg <penberg@kernel.org>
Wed, 21 Dec 2011 20:28:08 +0000 (22:28 +0200)
Rename struct kvm_ipc_msg to struct kvm_ipc_head.
Change current kvm_ipc__new_data() to kvm_ipc__receive().
Don't allocate memory for the msg head.

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

index c5562856476711d944c98eac0ac304ab61607cd5..c6f4582decdb08cd17accb43c8057d1c3c67b8b1 100644 (file)
@@ -3,12 +3,6 @@
 
 #include <linux/types.h>
 
-struct kvm_ipc_msg {
-       u32 type;
-       u32 len;
-       u8 data[];
-};
-
 enum {
        KVM_IPC_BALLOON = 1,
        KVM_IPC_DEBUG   = 2,
index be534f818dac658b6ba513b371a784bc144ff77b..a875e7dcf580964ea56fd2eaf8dc678026e94eb3 100644 (file)
@@ -9,6 +9,11 @@
 #include <sys/socket.h>
 #include <sys/eventfd.h>
 
+struct kvm_ipc_head {
+       u32 type;
+       u32 len;
+};
+
 #define KVM_IPC_MAX_MSGS 16
 
 static void (*msgs[KVM_IPC_MAX_MSGS])(int fd, u32 type, u32 len, u8 *msg);
@@ -74,28 +79,25 @@ static void kvm_ipc__close_conn(int fd)
        close(fd);
 }
 
-static void kvm_ipc__new_data(int fd)
+static void kvm_ipc__receive(int fd)
 {
-       struct kvm_ipc_msg *msg;
+       struct kvm_ipc_head head;
+       u8 *msg = NULL;
        u32 n;
 
-       msg = malloc(sizeof(*msg));
-       if (msg == NULL)
-               goto done;
-
-       n = read(fd, msg, sizeof(*msg));
-       if (n != sizeof(*msg))
+       n = read(fd, &head, sizeof(head));
+       if (n != sizeof(head))
                goto done;
 
-       msg = realloc(msg, sizeof(*msg) + msg->len);
+       msg = malloc(head.len);
        if (msg == NULL)
                goto done;
 
-       n = read_in_full(fd, msg->data, msg->len);
-       if (n != msg->len)
+       n = read_in_full(fd, msg, head.len);
+       if (n != head.len)
                goto done;
 
-       kvm_ipc__handle(fd, msg->type, msg->len, msg->data);
+       kvm_ipc__handle(fd, head.type, head.len, msg);
 
 done:
        free(msg);
@@ -118,11 +120,11 @@ static void *kvm_ipc__thread(void *param)
                                int client;
 
                                client = kvm_ipc__new_conn(fd);
-                               kvm_ipc__new_data(client);
+                               kvm_ipc__receive(client);
                        } else if (event.events && (EPOLLERR | EPOLLRDHUP | EPOLLHUP)) {
                                kvm_ipc__close_conn(fd);
                        } else {
-                               kvm_ipc__new_data(fd);
+                               kvm_ipc__receive(fd);
                        }
                }
        }