Skip to content

clownix/cloonix_vsock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Software to help using VirtioVsock

Provides a distant bash between virtual guest and host going
through the virtio-vsock host/guest communications device.

Also does distant non-interractive commands.
Also provides regular file copy to or from distant server.
Also forwards the x11 graphical applications.


To install:

make
make install  (to be done as root)

The service vsock_srv.service is created disabled in the machine:
systemctl list-unit-files |grep vsock
vsock_srv.service                                                disabled
if you want the service to start with next boot of your machine, do:
systemctl enable vsock_srv.service


Then the server command line is:
vsock_srv <vsock_port>

And the client command line is:
vsock_cli <vsock_cid> <vsock_port>

The vsock_cid is 2 (harcoded) for the host and you can use from 3 upwards
for the guests.


On the host, module vhost_vsock is necessary, it creates
/dev/vhost-vsock, this file is opened rw by qemu and as I launch
qemu without privileges, I chmod 0666 this file before launching
qemu. The virtual guest launched with qemu must have the following
line in its start command (case where guest cid is chosen to be 4):

  -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=4

sudo modprobe vhost_vsock
sudo chmod 0666 /dev/vhost-vsock
sudo vsock_srv 777
qemu... -device vhost-vsock-pci,...guest-cid=4 ...



Errors I have had during tries:

  "failed to open vhost device: Unknown error -2"
  happens when /dev/vhost_vsock does not exist (module not inserted)

  "failed to open vhost device: Unknown error -13"
  happens when the qemu software cannot read/write /dev/vhost_vsock



Once inside the guest virtual machine:

vsock_cli 2 777


And you get a pseudo-console as root on the host machine.


In case of unexpected events with this software, do:
sudo cat /var/log/user.log

For bug reports use github or mail clownix at clownix.net.


#--------------------------------------------------------------------
This tool can be tested with unix or ip sockets before using it
on the real host/guest env.

Here are the possible commands for the server for unix or ip:

vsock_srv -i <inet_port>
vsock_srv -u <unix_sock_path>

#--------------------------------------------------------------------
Here are the possible commands for the client for unix or ip:

vsock_cli -i <ip> <port>
vsock_cli -i <ip> <port> -cmd "<cmd + params>"
vsock_cli -i <ip> <port> -snd <loc_src> <rem_dst_dir>
vsock_cli -i <ip> <port> -rcv <rem_src> <loc_dst_dir>

vsock_cli -u <unix_sock>
vsock_cli -u <unix_sock> -cmd "<cmd + params>"
vsock_cli -u <unix_sock> -snd <loc_src> <rem_dst_dir>
vsock_cli -u <unix_sock> -rcv <rem_src> <loc_dst_dir>

#--------------------------------------------------------------------
Basic Examples:

vsock_srv 7777
vsock_cli 2 7777

vsock_srv -u /tmp/whatever
vsock_cli -u /tmp/whatever

vsock_srv -i 127.0.0.1 7777
vsock_cli -i 127.0.0.1 7777

#--------------------------------------------------------------------

If you want an automated systemd start of vsock_srv, you can use the
bash file install_vsock.sh to help.

#--------------------------------------------------------------------
NOTES ON LIBVIRT WITH VSOCK:
http://cloonix.fr:/libvirt_vsock/libvirt_vsock.tar.gz
is a working cloonix demo of vsock inside a nested guest running
on virsh.

For the special line to add to qemu, here is the way chosen in the demo:
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>nested</name>
  <qemu:commandline>
    <qemu:arg value='-device'/>
    <qemu:arg value='vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3'/>
  </qemu:commandline>

The /etc/libvirt/qemu.conf must be modified to add "/dev/vhost-vsock"
to the cgroup_device_acl, because qemu has to open it.
#--------------------------------------------------------------------