[libvirt] Serial connection between guests

Marcelo Ricardo Leitner mleitner at redhat.com
Tue Jul 14 11:25:27 UTC 2015


Hi,

On Tue, Jul 14, 2015 at 09:52:12AM +0200, Martin Kletzander wrote:
> 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

I'd like to avoid that as much as possible. (though I failed to connect
the serial interfaces through libvirt with any of the configs, tcp,
unix, etc..) perhaps due to the console thing you mentioned below.

> 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

That's what I was doing in the end. It also allows me to change the
connection on the fly if needed, but I have to keep an eye on socat. I
was thinking if we could have something more automatic for it.

Like, if I have domA and domB connected through a serial link using
socat, and I reboot the hypervisor, I wanted the socat to come back
automatically. Same if it dies..

Maybe it could be handled like Ethernet network is. You add a cable, and
on cable specs you define which dom/port is connected to that end.  I
tried to think on an UI that would allow this but all my ideas are
confusing.

> 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.

That's probably what kept it from working here for a long time hehe took
me a while to notice that.

> 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.

Thanks,
Marcelo

> 
> 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





More information about the libvir-list mailing list