<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 19, 2015 at 4:22 PM, Laine Stump <span dir="ltr"><<a href="mailto:laine@laine.org" target="_blank">laine@laine.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 02/17/2015 09:42 PM, Antoni Segura Puimedon wrote:<br>
> Adds the port type definitions and methods that will be used to bind<br>
> interfaces to the Midonet virtual ports.<br>
><br>
> virtnetdevmidonet.c adds the way to bind and unbind the ports by<br>
> calling into the Midonet Host Agent control command line (installed<br>
> with the midolman package).<br>
<br>
</span>Thinking a bit more about the organization of the patches - I think this<br>
patch needs to be 1 (since the parser/formatter changes will use the new<br>
enum values, then the patch with schema/docs and changes to<br>
parser/formatter (i.e. conf directory) should be 2, then the one that<br>
ties it all together would be 3.<br></blockquote><div><br>Makes sense. Thanks. <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5"><br>
><br>
> Signed-off-by: Antoni Segura Puimedon <<a href="mailto:toni%2Blibvirt@midokura.com">toni+libvirt@midokura.com</a>><br>
> ---<br>
>  <a href="http://configure.ac" target="_blank">configure.ac</a>                     |  4 ++<br>
>  src/Makefile.am                  |  1 +<br>
>  src/libvirt_private.syms         |  5 +++<br>
>  src/util/virnetdevmidonet.c      | 97 ++++++++++++++++++++++++++++++++++++++++<br>
>  src/util/virnetdevmidonet.h      | 37 +++++++++++++++<br>
>  src/util/virnetdevvportprofile.c |  1 +<br>
>  src/util/virnetdevvportprofile.h |  3 +-<br>
>  7 files changed, 147 insertions(+), 1 deletion(-)<br>
>  create mode 100644 src/util/virnetdevmidonet.c<br>
>  create mode 100644 src/util/virnetdevmidonet.h<br>
><br>
> diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
> index b3e99e7..ddffbb2 100644<br>
> --- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
> +++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
> @@ -425,6 +425,8 @@ AC_PATH_PROG([MODPROBE], [modprobe], [modprobe],<br>
>       [/sbin:/usr/sbin:/usr/local/sbin:$PATH])<br>
>  AC_PATH_PROG([RMMOD], [rmmod], [rmmod],<br>
>       [/sbin:/usr/sbin:/usr/local/sbin:$PATH])<br>
> +AC_PATH_PROG([MMCTL], [mm-ctl], [mm-ctl],<br>
> +     [/sbin:/usr/sbin:/usr/local/sbin:$PATH])<br>
>  AC_PATH_PROG([OVSVSCTL], [ovs-vsctl], [ovs-vsctl],<br>
>       [/sbin:/usr/sbin:/usr/local/sbin:$PATH])<br>
>  AC_PATH_PROG([SCRUB], [scrub], [scrub],<br>
> @@ -440,6 +442,8 @@ AC_DEFINE_UNQUOTED([RADVD],["$RADVD"],<br>
>          [Location or name of the radvd program])<br>
>  AC_DEFINE_UNQUOTED([TC],["$TC"],<br>
>          [Location or name of the tc program (see iproute2)])<br>
> +AC_DEFINE_UNQUOTED([MMCTL],["$MMCTL"],<br>
> +        [Location or name of the mm-ctl program])<br>
>  AC_DEFINE_UNQUOTED([OVSVSCTL],["$OVSVSCTL"],<br>
>          [Location or name of the ovs-vsctl program])<br>
><br>
> diff --git a/src/Makefile.am b/src/Makefile.am<br>
> index b41c6d4..23d3f93 100644<br>
> --- a/src/Makefile.am<br>
> +++ b/src/Makefile.am<br>
> @@ -129,6 +129,7 @@ UTIL_SOURCES =                                                    \<br>
>               util/virnetdevbandwidth.h util/virnetdevbandwidth.c \<br>
>               util/virnetdevbridge.h util/virnetdevbridge.c   \<br>
>               util/virnetdevmacvlan.c util/virnetdevmacvlan.h \<br>
> +             util/virnetdevmidonet.h util/virnetdevmidonet.c \<br>
>               util/virnetdevopenvswitch.h util/virnetdevopenvswitch.c \<br>
>               util/virnetdevtap.h util/virnetdevtap.c         \<br>
>               util/virnetdevveth.h util/virnetdevveth.c       \<br>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms<br>
> index 46a1613..0938cdc 100644<br>
> --- a/src/libvirt_private.syms<br>
> +++ b/src/libvirt_private.syms<br>
> @@ -1738,6 +1738,11 @@ virNetDevMacVLanRestartWithVPortProfile;<br>
>  virNetDevMacVLanVPortProfileRegisterCallback;<br>
><br>
><br>
> +# util/virnetdevmidonet.h<br>
> +virNetDevMidonetBindPort;<br>
> +virNetDevMidonetUnbindPort;<br>
> +<br>
> +<br>
>  # util/virnetdevopenvswitch.h<br>
>  virNetDevOpenvswitchAddPort;<br>
>  virNetDevOpenvswitchGetMigrateData;<br>
> diff --git a/src/util/virnetdevmidonet.c b/src/util/virnetdevmidonet.c<br>
> new file mode 100644<br>
> index 0000000..57fb636<br>
> --- /dev/null<br>
> +++ b/src/util/virnetdevmidonet.c<br>
> @@ -0,0 +1,97 @@<br>
> +/*<br>
> + * Copyright (C) 2015 Midokura, Sarl.<br>
> + *<br>
> + * This library is free software; you can redistribute it and/or<br>
> + * modify it under the terms of the GNU Lesser General Public<br>
> + * License as published by the Free Software Foundation; either<br>
> + * version 2.1 of the License, or (at your option) any later version.<br>
> + *<br>
> + * This library is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
> + * Lesser General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU Lesser General Public<br>
> + * License along with this library.  If not, see<br>
> + * <<a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>>.<br>
> + *<br>
> + * Authors:<br>
> + *     Antoni Segura Puimedon <<a href="mailto:toni@midokura.com">toni@midokura.com</a>><br>
> + */<br>
> +<br>
> +#include <config.h><br>
> +<br>
> +#include "virnetdevmidonet.h"<br>
> +#include "vircommand.h"<br>
> +#include "viralloc.h"<br>
> +#include "virerror.h"<br>
> +#include "viruuid.h"<br>
> +<br>
> +#define VIR_FROM_THIS VIR_FROM_NONE<br>
> +<br>
> +/**<br>
> + * virNetDevMidonetBindPort:<br>
> + * @ifname: the network interface name<br>
> + * @virtualport: the midonet specific fields<br>
> + *<br>
> + * Bind an interface to a Midonet virtual port<br>
> + *<br>
> + * Returns 0 in case of success or -1 in case of failure.<br>
> + */<br>
> +int virNetDevMidonetBindPort(const char *ifname,<br>
> +                                virNetDevVPortProfilePtr virtualport)<br>
> +{<br>
> +    int ret = -1;<br>
> +    virCommandPtr cmd = NULL;<br>
> +    char virtportuuid[VIR_UUID_STRING_BUFLEN];<br>
> +<br>
> +    virUUIDFormat(virtualport->interfaceID, virtportuuid);<br>
> +<br>
> +    cmd = virCommandNew(MMCTL);<br>
> +<br>
> +    virCommandAddArgList(cmd, "--bind-port", virtportuuid, ifname, NULL);<br>
> +<br>
> +    if (virCommandRun(cmd, NULL) < 0) {<br>
> +        virReportError(VIR_ERR_INTERNAL_ERROR,<br>
> +                       _("Unable to bind port %s to the virtual port %s"),<br>
> +                       ifname, virtportuuid);<br>
> +        goto cleanup;<br>
> +    }<br>
> +<br>
> +    ret = 0;<br>
> + cleanup:<br>
> +    virCommandFree(cmd);<br>
> +    return ret;<br>
> +}<br>
> +<br>
> +/**<br>
> + * virNetDevMidonetUnbindPort:<br>
> + * @virtualport: the midonet specific fields<br>
> + *<br>
> + * Unbinds a virtual port from the host<br>
> + *<br>
> + * Returns 0 in case of success or -1 in case of failure.<br>
> + */<br>
> +int virNetDevMidonetUnbindPort(virNetDevVPortProfilePtr virtualport)<br>
> +{<br>
> +    int ret = -1;<br>
> +    virCommandPtr cmd = NULL;<br>
> +    char virtportuuid[VIR_UUID_STRING_BUFLEN];<br>
> +<br>
> +    virUUIDFormat(virtualport->interfaceID, virtportuuid);<br>
> +<br>
> +    cmd = virCommandNew(MMCTL);<br>
> +    virCommandAddArgList(cmd, "--unbind-port", virtportuuid, NULL);<br>
> +<br>
> +    if (virCommandRun(cmd, NULL) < 0) {<br>
> +        virReportError(VIR_ERR_INTERNAL_ERROR,<br>
> +                       _("Unable to unbind the virtual port %s from Midonet"),<br>
> +                       virtportuuid);<br>
> +        goto cleanup;<br>
> +    }<br>
> +<br>
> +    ret = 0;<br>
> + cleanup:<br>
> +    virCommandFree(cmd);<br>
> +    return ret;<br>
> +}<br>
> diff --git a/src/util/virnetdevmidonet.h b/src/util/virnetdevmidonet.h<br>
> new file mode 100644<br>
> index 0000000..b8dbeac<br>
> --- /dev/null<br>
> +++ b/src/util/virnetdevmidonet.h<br>
> @@ -0,0 +1,37 @@<br>
> +/*<br>
> + * Copyright (C) 2015 Midokura Sarl.<br>
> +<br>
> + * This library is free software; you can redistribute it and/or<br>
> + * modify it under the terms of the GNU Lesser General Public<br>
> + * License as published by the Free Software Foundation; either<br>
> + * version 2.1 of the License, or (at your option) any later version.<br>
> + *<br>
> + * This library is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
> + * Lesser General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU Lesser General Public<br>
> + * License along with this library.  If not, see<br>
> + * <<a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>>.<br>
> + *<br>
> + * Authors:<br>
> + *     Antoni Segura Puimedon <<a href="mailto:toni@midokura.com">toni@midokura.com</a><br>
> + */<br>
> +<br>
> +#ifndef __VIR_NETDEV_MIDONET_H__<br>
> +# define __VIR_NETDEV_MIDONET_H__<br>
> +<br>
> +# include "internal.h"<br>
> +# include "virnetdevvportprofile.h"<br>
> +<br>
> +<br>
> +int virNetDevMidonetBindPort(const char *ifname,<br>
> +                             virNetDevVPortProfilePtr virtualport)<br>
> +    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;<br>
> +<br>
> +int virNetDevMidonetUnbindPort(virNetDevVPortProfilePtr virtualport)<br>
> +    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;<br>
> +<br>
> +#endif /* __VIR_NETDEV_MIDONET_H__ */<br>
> +<br>
> diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c<br>
> index 6ee20d3..921c6aa 100644<br>
> --- a/src/util/virnetdevvportprofile.c<br>
> +++ b/src/util/virnetdevvportprofile.c<br>
> @@ -33,6 +33,7 @@ VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST,<br>
>                "none",<br>
>                "802.1Qbg",<br>
>                "802.1Qbh",<br>
> +              "midonet",<br>
>                "openvswitch")<br>
<br>
</div></div>I'm curious why you added the new enum in the middle rather than at the<br>
end. Was it to reduce the number of lines in the diff?</blockquote><div><br>No. Something sillier than that. I just went by alphabetic order :P<br>I'll add it at the end.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> We usually add<br>
new values at the end of the list. Everything *should* work when adding<br>
to the middle, but superstition causes me to anticipate bugs cause by<br>
some idiot using a hard-coded value, or storing the enum somewhere as an<br>
integer, or other assorted bad things.<br></blockquote><div><br>Understood. I'' put new enum things at the end from now on.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
<br>
><br>
>  VIR_ENUM_IMPL(virNetDevVPortProfileOp, VIR_NETDEV_VPORT_PROFILE_OP_LAST,<br>
> diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprofile.h<br>
> index ad063c5..7c00350 100644<br>
> --- a/src/util/virnetdevvportprofile.h<br>
> +++ b/src/util/virnetdevvportprofile.h<br>
> @@ -34,6 +34,7 @@ enum virNetDevVPortProfile {<br>
>      VIR_NETDEV_VPORT_PROFILE_NONE,<br>
>      VIR_NETDEV_VPORT_PROFILE_8021QBG,<br>
>      VIR_NETDEV_VPORT_PROFILE_8021QBH,<br>
> +    VIR_NETDEV_VPORT_PROFILE_MIDONET,<br>
>      VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH,<br>
><br>
>      VIR_NETDEV_VPORT_PROFILE_LAST,<br>
> @@ -73,7 +74,7 @@ struct _virNetDevVPortProfile {<br>
>      /* this is a null-terminated character string */<br>
>      char          profileID[LIBVIRT_IFLA_VF_PORT_PROFILE_MAX];<br>
><br>
> -    /* this member is used when virtPortType == openvswitch */<br>
> +    /* this member is used when virtPortType == openvswitch|midonet */<br>
>      unsigned char interfaceID[VIR_UUID_BUFLEN];<br>
>      bool          interfaceID_specified;<br>
>      /* NB - if virtPortType == NONE, any/all of the items could be used */<br>
<br>
</div></div></blockquote></div><br></div></div>