[libvirt] [libvirt PATCH] Port-profile ID support using IFLA_VF_PORT_PROFILE netlink msg

Stefan Berger stefanb at us.ibm.com
Sat May 8 19:12:06 UTC 2010


libvir-list-bounces at redhat.com wrote on 05/08/2010 03:05:29 AM:


> From: Scott Feldman <scofeldm at cisco.com>
> 
> This fleshes out the port profile ID proof-of-concept patch posted 
earlier
> by David Allan, referenced here:
> 
>   https://www.redhat.com/archives/libvir-list/2010-March/msg01401.html
> 
> It uses the new IFLA_VF_PORT_PROFILE netlink msg to set/unset the port-
> profile for the virtual switch port backing the VM device.  The new 
netlink
> msg is being discussed on the netdev kernel mailing list here:
> 
>   http://marc.info/?l=linux-netdev&m=127312092712543&w=2
>   http://marc.info/?l=linux-netdev&m=127312093412556&w=2
> 
> IFLA_VF_PORT_PROFILE is sent using RTM_SETLINK, and retrieved using
> RTM_GETLINK.  IFLA_VF_PORT_PROFILE is sent using netlink multicast send
> with RTNLGRP_LINK so the receiver of the msg can be in user-space or
> kernel-space.
> 
> The device XML is:
> 
>     <interface type='direct'>
>         <source dev='eth2' mode='private' profileid='dc_test'/>
>         <mac address='00:16:3e:1a:b3:4b'/>
>     </interface>
> 
> The port-profile ID msg is sent to source dev.

Great. Now we have two competing implementations where the underlying 
technology is supposed
to be VEPA in both but the parameters to set it up are vastly different -- 
if you compare
against Vivek's post yesterfa. Above you are providing a profile id in 
form of a string. 
Is that string above just a dummy example or a real-world parameter that 
can actually be passed?
Vivek posted a message yesterday showing now 4 different parameters... are 
these somehow encoded
in the profileid in your case or you simply don't need them? I see you are 
getting the host UUID
vid dmidecode, so there are still3 parameters left. Anyway, I let you guys 
figure that out.

I suppose in your case we would use the external daemon to derive eth0 
from eth0.100 where the
macvtap would be connected on along with the vlan id in eth0.100. So the 
functions I posted
yesterday may need to go into that code then.



> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 5fa8c0a..aff6f28 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -1479,6 +1479,11 @@ qemudPhysIfaceConnect(virConnectPtr conn,
>          net->model && STREQ(net->model, "virtio"))
>          vnet_hdr = 1;
> 
> +    if (!STREQ(net->data.direct.profileid, ""))
> +        setPortProfileId(net->data.direct.linkdev,
> +                         net->data.direct.profileid,
> +                         net->mac);
> +

Since setting up a port profile seems to be a step tightly connected
to opening the macvtap I'd push this into the openMactapTap function.


>      rc = openMacvtapTap(net->ifname, net->mac, linkdev, brmode,
>                          &res_ifname, vnet_hdr);
>      if (rc >= 0) {
> @@ -1501,6 +1506,8 @@ qemudPhysIfaceConnect(virConnectPtr conn,
>                  close(rc);
>                  rc = -1;
>                  delMacvtap(net->ifname);
> +                if (!STREQ(net->data.direct.profileid, ""))
> +                    unsetPortProfileId(net->data.direct.linkdev);
>              }

Same here, push it into the delMacvtap function.


>          }
>      }
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index bb1079e..6ea37d4 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -3586,8 +3586,11 @@ static void qemudShutdownVMDaemon(struct 
> qemud_driver *driver,
>      for (i = 0; i < def->nnets; i++) {
>          virDomainNetDefPtr net = def->nets[i];
>          if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
> -            if (net->ifname)
> +            if (net->ifname) {
>                  delMacvtap(net->ifname);
> +                if (!STREQ(net->data.direct.profileid, ""))
> +                    unsetPortProfileId(net->data.direct.linkdev);
> +            }

Same.

>          }
>      }
>  #endif
> @@ -8147,8 +8150,11 @@ qemudDomainDetachNetDevice(struct qemud_driver 
*driver,
> 
>  #if WITH_MACVTAP
>      if (detach->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
> -        if (detach->ifname)
> +        if (detach->ifname) {
>              delMacvtap(detach->ifname);
> +            if (!STREQ(detach->data.direct.profileid, ""))
> +                unsetPortProfileId(detach->data.direct.linkdev);
> +        }

Same.



> +
> +int setPortProfileId(const char *linkdev,
> +                     const char *profileid,
> +                     unsigned char *macaddress)
> +{
> +    int rc = 0;
> +    struct ifla_vf_port_profile ivp;
> +    char host_uuid[IFLA_VF_UUID_MAX] = "\0";
> +
> +    if (!profileid)
> +        return -EINVAL;
> +
> +    memset(&ivp, 0, sizeof(struct ifla_vf_port_profile));
> +    ivp.vf = -1;
> +    strncpy((char *)ivp.port_profile, profileid, 
sizeof(ivp.port_profile));

use the libvirt function to copy string

> +    ivp.port_profile[sizeof(ivp.port_profile)-1] = '\0';
> +    memcpy(ivp.mac, macaddress, sizeof(ivp.mac));
> +    get_host_uuid(host_uuid, IFLA_VF_UUID_MAX);


check for error


> +    if (strlen(host_uuid)) {
> +        strncpy((char *)ivp.host_uuid, host_uuid, 
sizeof(ivp.host_uuid));

use libvirt function to copy string

> +        ivp.port_profile[sizeof(ivp.port_profile)-1] = '\0';
> +    }
> +
> +    if(!(rc = sendPortProfileMulticastMsg(linkdev, &ivp))) {
> +       rc = ifaceUp(linkdev);
> +       if (rc != 0) {
> +           virReportSystemError(errno,
> +                               ("cannot 'up' interface %s"),
> +                               linkdev);
> +           // Should we error out of here ?
> +           //rc = -1;
> +       }
> +    }
> +
> +    return rc;
> +}
> 
>  /**
>   * openMacvtapTap:
> diff --git a/src/util/macvtap.h b/src/util/macvtap.h
> index 5d4ea5e..7f58a13 100644
> --- a/src/util/macvtap.h
> +++ b/src/util/macvtap.h
> @@ -37,6 +37,12 @@ int openMacvtapTap(const char *ifname,
> 
>  void delMacvtap(const char *ifname);
> 
> +int setPortProfileId(const char *linkdev,
> +                     const char *profileid,
> +                     unsigned char *macaddress);
> +
> +int unsetPortProfileId(const char *linkdev);
> +

Remove after pushing the function into open* and del* functions.

Regards,
   Stefan


>  # endif /* WITH_MACVTAP */
> 
>  # define MACVTAP_MODE_PRIVATE_STR  "private"
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100508/733550b4/attachment-0001.htm>


More information about the libvir-list mailing list