[libvirt] Serial connection between guests

Martin Kletzander mkletzan at redhat.com
Tue Jul 14 07:52:12 UTC 2015


On Fri, Jul 10, 2015 at 04:28:46PM -0300, Marcelo Ricardo Leitner wrote:
>Hi,
>
>(I'm not subscribed to the list, please keep me on Cc)
>
>I'm attempting to get a serial link between two guests, same hypervisor.
>The only practical way I could find is to add a serial port using a pty
>to a guest and then manually connecting to the serial (console in my
>case) of the other guest using socat in the hypervisor.
>
>Then it made me think.. we could have this implemented at libvirt level.
>We could have a serial port on which we choose pty, udp, tcp, etc, and
>also a serial port from another guest, so that libvirt would handle
>socat start/stop automatically as both guests come up/down. Maybe
>libvirt could even do something smarter than that, maybe it can avoid
>socat somehow.
>

You can have one domain with serial port that will listen on some
interface (unix socket, ip and port, whatever) and then have the
second one connect to it.  That could be done for example like this:

XML snippet of device for domain A:
  <serial type='file'>
    <source mode='bind' path='/tmp/tahi.sock'/>
    <target port='1'/>
  </serial>

XML snippet of device for domain B:
  <serial type='file'>
    <source mode='connect' path='/tmp/tahi.sock'/>
    <target port='1'/>
  </serial>

This way you need to make sure domain A is started when you are
starting domain B, so it can connect to the socket that was created by
domain A.  If you don't want to depend on the order of domains being
started, you can use for example socat for that:

XML snippet of device for domain A:
  <serial type='file'>
    <source mode='bind' path='/tmp/tahi-domA.sock'/>
    <target port='1'/>
  </serial>

XML snippet of device for domain B:
  <serial type='file'>
    <source mode='bind' path='/tmp/tahi-domB.sock'/>
    <target port='1'/>
  </serial>

And then run socat as:
  socat unix:/tmp/tahi-domA.sock unix:/tmp/tahi-domB.sock

For more details on how this works and what you can use, see the
documentation [1].  Beware that if it's the only serial port n the
guest, it will become a console, so you might want to add it instead
of modifying an existing one.

Also, the examples are done without any security labels in mind.  If
you use SELinux, for example, you'll probably need to adjust the
<seclabel/> for the sockets, see the docs [2] for details.


Martin

[1] https://libvirt.org/formatdomain.html#elementCharChannel
[2] https://libvirt.org/formatdomain.html#seclabel

>What do you think? My usage is for virtualizing TAHI:
>http://networktest.sourceforge.net/usage.html
>I need 2 ethernet links plus a serial one, which TAHI can't break while
>running the tests.
>
>I didn't think this regarding multi-platform & all.. just sharing the
>idea/need.
>
>Thanks,
>Marcelo
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150714/6af7de7e/attachment-0001.sig>


More information about the libvir-list mailing list