Re: [PATCH 1/3] libxl: support openvswitch interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/16/18 11:26 PM, Jim Fehlig wrote:
> It is currently possible to use <interface>s of type openvswitch
> with the libxl driver in a non-standard way, e.g.
> 
>   <interface type='bridge'>
>     <source bridge='ovsbr0'/>
>     <mac address='00:16:3e:7a:35:ce'/>
>     <script path='vif-openvswitch'/>
>   </interface>
> 
> This patch adds support for openvswitch <interface>s specified
> in typical libvirt config
> 
>   <interface type='bridge'>
>     <source bridge='ovsbr0'/>
>     <mac address='00:16:3e:7a:35:ce'/>
>     <virtualport type='openvswitch'/>
>   </interface>
> 
> VLAN tags and trunking are also supported using the extended
> syntax for specifying an openvswitch bridge in libxl
> 
>    BRIDGE_NAME[.VLAN][:TRUNK:TRUNK]
> 
> See Xen's networking wiki for more details on openvswitch support
> 
> https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch
> 
> Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
> ---
>  src/libxl/libxl_conf.c | 47 ++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
> index e2bfa2f5c3..39c969e482 100644
> --- a/src/libxl/libxl_conf.c
> +++ b/src/libxl/libxl_conf.c
> @@ -51,6 +51,7 @@
>  #include "cpu/cpu.h"
>  #include "xen_common.h"
>  #include "xen_xl.h"
> +#include "virnetdevvportprofile.h"
>  
>  
>  #define VIR_FROM_THIS VIR_FROM_LIBXL
> @@ -1190,6 +1191,11 @@ libxlMakeNic(virDomainDefPtr def,
>      virNetworkPtr network = NULL;
>      virConnectPtr conn = NULL;
>      virNetDevBandwidthPtr actual_bw;
> +    virNetDevVPortProfilePtr port_profile;
> +    virNetDevVlanPtr virt_vlan;
> +    virBuffer buf = VIR_BUFFER_INITIALIZER;
> +    size_t i;
> +    const char *script = NULL;
>      int ret = -1;
>  
>      /* TODO: Where is mtu stored?
> @@ -1247,14 +1253,50 @@ libxlMakeNic(virDomainDefPtr def,
>      if (VIR_STRDUP(x_nic->ifname, l_nic->ifname) < 0)
>          goto cleanup;
>  
> +    port_profile = virDomainNetGetActualVirtPortProfile(l_nic);
> +    virt_vlan = virDomainNetGetActualVlan(l_nic);
> +    script = l_nic->script;
>      switch (actual_type) {
>          case VIR_DOMAIN_NET_TYPE_BRIDGE:
> +            virBufferAsprintf(&buf, "%s", virDomainNetGetActualBridgeName(l_nic));

Or virBufferAddStr() or virBufferAdd(,,-1);

> +            /*
> +             * A bit of special handling if vif will be connected to an
> +             * openvswitch bridge
> +             */
> +            if (port_profile &&
> +                port_profile->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
> +                /*
> +                 * If a custom script is not specified for openvswitch, use
> +                 * Xen's vif-openvswitch script
> +                 */
> +                if (!script)
> +                    script = "vif-openvswitch";
> +                /*
> +                 * libxl_device_nic->bridge supports an extended format for
> +                 * specifying VLAN tags and trunks when using openvswitch
> +                 *
> +                 * BRIDGE_NAME[.VLAN][:TRUNK:TRUNK]
> +                 *
> +                 * See Xen's networking wiki for more details
> +                 * https://wiki.xenproject.org/wiki/Xen_Networking#Open_vSwitch
> +                 */
> +                if (virt_vlan && virt_vlan->nTags > 0) {
> +                    if (virt_vlan->trunk) {
> +                        for (i = 0; i < virt_vlan->nTags; i++)
> +                            virBufferAsprintf(&buf, ":%d", virt_vlan->tag[i]);
> +                    } else {
> +                        virBufferAsprintf(&buf, ".%d", virt_vlan->tag[0]);
> +                    }
> +                }
> +            }
> +            if (virBufferCheckError(&buf) < 0)
> +                goto cleanup;
>              if (VIR_STRDUP(x_nic->bridge,
> -                           virDomainNetGetActualBridgeName(l_nic)) < 0)
> +                           virBufferCurrentContent(&buf)) < 0)
>                  goto cleanup;
>              ATTRIBUTE_FALLTHROUGH;
>          case VIR_DOMAIN_NET_TYPE_ETHERNET:
> -            if (VIR_STRDUP(x_nic->script, l_nic->script) < 0)
> +            if (VIR_STRDUP(x_nic->script, script) < 0)
>                  goto cleanup;
>              if (l_nic->guestIP.nips > 0) {
>                  x_nic->ip = xenMakeIPList(&l_nic->guestIP);
> @@ -1351,6 +1393,7 @@ libxlMakeNic(virDomainDefPtr def,
>      ret = 0;
>  
>   cleanup:
> +    virBufferFreeAndReset(&buf);
>      virObjectUnref(network);
>      virObjectUnref(conn);
>  
> 


Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux