mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-08-25 23:47:13 +00:00
kvm tools: add kvm_ipc__send() and kvm_ipc__send_msg()
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>
This commit is contained in:
committed by
Will Deacon
parent
a9aae6c580
commit
50dc18ae65
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user