]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: add kvm_ipc__send() and kvm_ipc__send_msg()
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 20 Dec 2011 09:08:51 +0000 (17:08 +0800)
committerPekka Enberg <penberg@kernel.org>
Wed, 21 Dec 2011 20:28:08 +0000 (22:28 +0200)
Current code write the sock manually. There is nothing constrains the format of
the written data is expect. Use kvm_ipc__send() and kvm_ipc__send_msg() for
such constraint.

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 c6f4582decdb08cd17accb43c8057d1c3c67b8b1..5916c40c21b86e58e0621d2943f7374ae4b7e093 100644 (file)
@@ -17,4 +17,7 @@ int kvm_ipc__register_handler(u32 type, void (*cb)(int fd, u32 type, u32 len, u8
 int kvm_ipc__start(int sock);
 int kvm_ipc__stop(void);
 
+int kvm_ipc__send(int fd, u32 type);
+int kvm_ipc__send_msg(int fd, u32 type, u32 len, u8 *msg);
+
 #endif
index a875e7dcf580964ea56fd2eaf8dc678026e94eb3..2036b918f8663f732ed46898ba750e765829afab 100644 (file)
@@ -33,6 +33,29 @@ int kvm_ipc__register_handler(u32 type, void (*cb)(int fd, u32 type, u32 len, u8
        return 0;
 }
 
+int kvm_ipc__send(int fd, u32 type)
+{
+       struct kvm_ipc_head head = {.type = type, .len = 0,};
+
+       if (write_in_full(fd, &head, sizeof(head)) != sizeof(head))
+               return -1;
+
+       return 0;
+}
+
+int kvm_ipc__send_msg(int fd, u32 type, u32 len, u8 *msg)
+{
+       struct kvm_ipc_head head = {.type = type, .len = len,};
+
+       if (write_in_full(fd, &head, sizeof(head)) != sizeof(head))
+               return -1;
+
+       if (write_in_full(fd, msg, len) != len)
+               return -1;
+
+       return 0;
+}
+
 static int kvm_ipc__handle(int fd, u32 type, u32 len, u8 *data)
 {
        void (*cb)(int fd, u32 type, u32 len, u8 *msg);