20 Commits

Author SHA1 Message Date
Andre Przywara d77bd4f466 Fix call to connect()
According to the manpage and the prototype the second argument to
connect(2) is a "const struct sockaddr*", so cast our protocol
specific type back to the super type.
This fixes compilation on musl-libc.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara a2583dbf82 kvm-ipc: use proper type for file descriptor
A socket (as any other file descriptor) is of type "int" to catch the
negative error cases. Fix the declaration to allow errors to be
detected.
Found and needed by clang.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Milan Kocian 22fb13f677 kvm tools: Fix dirent handling on dirent non-friendly filesystems
Some filesystems don't return valid d_type field in dirent
structure (e.g XFS). So we must handle this case properly.

Signed-off-by: Milan Kocian <milon@wq.cz>
Cc: Sasha Levin <levinsasha928@gmail.com>
[ penberg@kernel.org: cleanups ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Michael Ellerman 211370d69e kvm tools: More error handling in the ipc code
Add perror() calls to a couple of exit paths, to ease debugging.

There are also two places where we print "Failed starting IPC thread",
but one is really an epoll failure, so make that obvious.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Sasha Levin a4d8c55eb2 kvm tools: Specify names for VM internal threads
Give threads a meaningful name. This makes debugging much easier, and
everything else much prettier.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
[ penberg@kernel.org: specify vcpu names ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Sasha Levin 4346fd8f1e kvm tools: remove global kvm object
This was ugly, and now we get rid of it.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Sasha Levin 49a8afd1b9 kvm tools: use init/exit where possible
Switch to using init/exit calls instead of the repeating call blocks in builtin-run.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Sasha Levin e1063726d9 kvm tools: kvm-ipc cleanup
Move all the kvm-ipc specific code into the relevant file, and modify
the ipc callback to pass a ptr to struct kvm as well.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Sasha Levin 066c58090b kvm tools: use bitwise 'and' in kvm-ipc
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Yang Bai e21e8ff36e kvm tools: if kvm_ipc__start failed, return negative
If kvm_ipc__start failed, it returns a negative and by checking
this return value, we can ensure that it succeeds.

Signed-off-by: Yang Bai <hamo.by@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He ca08826821 kvm tools: Simply write_in_full() check semantics
write_in_full() would not return until count byes has been written or
error has occurred.

So

   if (write_in_full(fd, buf, count) < 0)
	goto err;

is enough.

And

   if (write_in_full(fd, buf, count) != count)
	goto err;

is not necessary.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Asias He fd5b45a1d3 kvm tools: Fix kvm-ipc.c build breakage
CC       kvm-ipc.o
    kvm-ipc.c: In function ???kvm_ipc__send_msg???:
    kvm-ipc.c:53:34: error: comparison between signed and unsigned integer
    expressions [-Werror=sign-compare]
    cc1: all warnings being treated as errors

Reported-by: Jean-Philippe Menil <jean-philippe.menil@univ-nantes.fr>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Asias He 8e463c6245 kvm tools: Handle multiple IPC cmd at a time
This is useful when client submiting multiple IPC cmd in one socket
connection.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Lai Jiangshan 50dc18ae65 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>
2015-06-01 16:39:50 +01:00
Lai Jiangshan a9aae6c580 kvm tools: add kvm_ipc__receive()
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>
2015-06-01 16:39:50 +01:00
Lai Jiangshan 44a56bfd32 kvm tools: cleanup kvm_ipc__handle()
Make it be a static function.
Expland to kvm_ipc_msg to its arguments.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Sasha Levin 21b3c2c0d9 kvm tools: Zero out event before calling epoll_ctl()
Zero out struct epoll_event before calling epoll_ctl(). This isn't really
required, but is done to avoid warnings.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Sasha Levin 47f72b90da kvm tools: Handle only relevant events in epoll
Handle only new incoming data for listener and stop fds, treat all other
events as error events which close the socket.

This fixes the bug where a 'kvm list' could have hanged because a close
event in the listener fd have been treated as a new connection.

Cc: Osier Yang <jyang@redhat.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin c733c80bbc kvm tools: Add method to stop ipc thread
Stop the ipc thread when shutting down the hypervisor.

This solves a bug where the .sock files weren't removed upon shutdown.

Reported-by: Osier Yang <jyang@redhat.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 4b1addaeed kvm tools: Switch to using UNIX sockets instead of signals
This patch changes the IPC method to use UNIX sockets instead of
signals.

This allows for more flexibility in moving data between processes, for example
it would allow avoid printing output in the terminal of the guest.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00