Reputation: 687
I want to exchange "complex" data (hierarchical structs) between the guest and the host in a KVM+Qemu setup.
My idea was to use the virtio serial driver to do so. A guest application would use the normal I/O functions such as open(2), close(2), read(2) and write(2) to send the "buffer" (=the struct I want to send) to the virtio serial back-end. The back-end driver would run inside Qemu and receive the pointer to the struct through the in-qemu host API described here: http://www.linux-kvm.org/page/Virtio-serial_API
My question now may be relatively trivial, but I was looking around all over Google and couldn't find anything: How do I "hook into qemu" such that I can use the virtio serial host API?
I understand that I have to provide an init function like void my_init(void) { virtio_serial_port_qdev_register(&myinfo); }
and register it with qemu using device_init(&my_init)
. However, I do not understand how I link my module with qemu? Do I have to add my source files to the qemu code base and makefiles and recompile qemu? Or can I compile it separately and use some magic qemu command line option to load it? Or something completely different?
(Note: I know that I could optionally serialize my data, send it to a socket on the host, and de-serialize it there, but I wanted to avoid the serialization overhead. If there is a way to use a shared memory region instead of a socket with an out-of-the-box virtIO serial device, this could be an option, too).
Thank you all for your help! Christoph
Upvotes: 4
Views: 6168
Reputation: 312
you can start vm using
qemu-system-x86_64 -m 1024 -name mac -hda ~/Documents/ubuntu -device virtio-serial -chardev socket,path=/tmp/foo,server,nowait,id=foo -device virtconsole,name=jobsfoo,chardev=foo,name=org.fedoraproject.console.foo
and transfer data by using socat /tmp/foo (host)
socat /tmp/hvc0 (guest)
or you can use socket program on host and simple file i/o on guest
Upvotes: 2
Reputation: 1930
on the host side a serial port can be attached to a pipe or socket using the "-chardev" option. If you specify for example "-chardev socket,path=/tmp/foo.sock,server,nowait,id=foo", you can connect a virtio-serial port to that socket with "-device virtserialport,chardev=foo". You do not need to modify QEMU (or I don't understand what you want to do).
Upvotes: 1