[libvirt] [PATCH 1/3 v3] utilities for supporting midonet virtualports
Laine Stump
laine at laine.org
Tue Mar 17 15:45:26 UTC 2015
On 02/23/2015 03:54 PM, Antoni Segura Puimedon wrote:
> Adds the port type definitions and methods that will be used to bind
> interfaces to the Midonet virtual ports.
>
> virtnetdevmidonet.c adds the way to bind and unbind the ports by
> calling into the Midonet Host Agent control command line (installed
> with the midolman package).
>
> Signed-off-by: Antoni Segura Puimedon <toni+libvirt at midokura.com>
> ---
> configure.ac | 4 ++
> po/POTFILES.in | 1 +
> src/Makefile.am | 1 +
> src/libvirt_private.syms | 5 +++
> src/util/virnetdevmidonet.c | 97 ++++++++++++++++++++++++++++++++++++++++
> src/util/virnetdevmidonet.h | 37 +++++++++++++++
> src/util/virnetdevvportprofile.c | 3 +-
> src/util/virnetdevvportprofile.h | 3 +-
> 8 files changed, 149 insertions(+), 2 deletions(-)
> create mode 100644 src/util/virnetdevmidonet.c
> create mode 100644 src/util/virnetdevmidonet.h
ACK with a couple very minor formatting changes.
>
> diff --git a/configure.ac b/configure.ac
> index b3e99e7..ddffbb2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -425,6 +425,8 @@ AC_PATH_PROG([MODPROBE], [modprobe], [modprobe],
> [/sbin:/usr/sbin:/usr/local/sbin:$PATH])
> AC_PATH_PROG([RMMOD], [rmmod], [rmmod],
> [/sbin:/usr/sbin:/usr/local/sbin:$PATH])
> +AC_PATH_PROG([MMCTL], [mm-ctl], [mm-ctl],
> + [/sbin:/usr/sbin:/usr/local/sbin:$PATH])
> AC_PATH_PROG([OVSVSCTL], [ovs-vsctl], [ovs-vsctl],
> [/sbin:/usr/sbin:/usr/local/sbin:$PATH])
> AC_PATH_PROG([SCRUB], [scrub], [scrub],
> @@ -440,6 +442,8 @@ AC_DEFINE_UNQUOTED([RADVD],["$RADVD"],
> [Location or name of the radvd program])
> AC_DEFINE_UNQUOTED([TC],["$TC"],
> [Location or name of the tc program (see iproute2)])
> +AC_DEFINE_UNQUOTED([MMCTL],["$MMCTL"],
> + [Location or name of the mm-ctl program])
> AC_DEFINE_UNQUOTED([OVSVSCTL],["$OVSVSCTL"],
> [Location or name of the ovs-vsctl program])
>
> diff --git a/po/POTFILES.in b/po/POTFILES.in
> index 3064037..cdfc839 100644
> --- a/po/POTFILES.in
> +++ b/po/POTFILES.in
> @@ -195,6 +195,7 @@ src/util/virnetdev.c
> src/util/virnetdevbandwidth.c
> src/util/virnetdevbridge.c
> src/util/virnetdevmacvlan.c
> +src/util/virnetdevmidonet.c
> src/util/virnetdevopenvswitch.c
> src/util/virnetdevtap.c
> src/util/virnetdevveth.c
> diff --git a/src/Makefile.am b/src/Makefile.am
> index b41c6d4..23d3f93 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -129,6 +129,7 @@ UTIL_SOURCES = \
> util/virnetdevbandwidth.h util/virnetdevbandwidth.c \
> util/virnetdevbridge.h util/virnetdevbridge.c \
> util/virnetdevmacvlan.c util/virnetdevmacvlan.h \
> + util/virnetdevmidonet.h util/virnetdevmidonet.c \
> util/virnetdevopenvswitch.h util/virnetdevopenvswitch.c \
> util/virnetdevtap.h util/virnetdevtap.c \
> util/virnetdevveth.h util/virnetdevveth.c \
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 46a1613..0938cdc 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1738,6 +1738,11 @@ virNetDevMacVLanRestartWithVPortProfile;
> virNetDevMacVLanVPortProfileRegisterCallback;
>
>
> +# util/virnetdevmidonet.h
> +virNetDevMidonetBindPort;
> +virNetDevMidonetUnbindPort;
> +
> +
> # util/virnetdevopenvswitch.h
> virNetDevOpenvswitchAddPort;
> virNetDevOpenvswitchGetMigrateData;
> diff --git a/src/util/virnetdevmidonet.c b/src/util/virnetdevmidonet.c
> new file mode 100644
> index 0000000..57fb636
> --- /dev/null
> +++ b/src/util/virnetdevmidonet.c
> @@ -0,0 +1,97 @@
> +/*
> + * Copyright (C) 2015 Midokura, Sarl.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library. If not, see
> + * <http://www.gnu.org/licenses/>.
> + *
> + * Authors:
> + * Antoni Segura Puimedon <toni at midokura.com>
> + */
> +
> +#include <config.h>
> +
> +#include "virnetdevmidonet.h"
> +#include "vircommand.h"
> +#include "viralloc.h"
> +#include "virerror.h"
> +#include "viruuid.h"
> +
> +#define VIR_FROM_THIS VIR_FROM_NONE
> +
> +/**
> + * virNetDevMidonetBindPort:
> + * @ifname: the network interface name
> + * @virtualport: the midonet specific fields
> + *
> + * Bind an interface to a Midonet virtual port
> + *
> + * Returns 0 in case of success or -1 in case of failure.
> + */
> +int virNetDevMidonetBindPort(const char *ifname,
> + virNetDevVPortProfilePtr virtualport)
^^ here (and in the next function), put return type on separate line and
realigned args.
> +{
> + int ret = -1;
> + virCommandPtr cmd = NULL;
> + char virtportuuid[VIR_UUID_STRING_BUFLEN];
> +
> + virUUIDFormat(virtualport->interfaceID, virtportuuid);
> +
> + cmd = virCommandNew(MMCTL);
> +
> + virCommandAddArgList(cmd, "--bind-port", virtportuuid, ifname, NULL);
> +
> + if (virCommandRun(cmd, NULL) < 0) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("Unable to bind port %s to the virtual port %s"),
> + ifname, virtportuuid);
> + goto cleanup;
> + }
> +
> + ret = 0;
> + cleanup:
> + virCommandFree(cmd);
> + return ret;
> +}
> +
> +/**
> + * virNetDevMidonetUnbindPort:
> + * @virtualport: the midonet specific fields
> + *
> + * Unbinds a virtual port from the host
> + *
> + * Returns 0 in case of success or -1 in case of failure.
> + */
> +int virNetDevMidonetUnbindPort(virNetDevVPortProfilePtr virtualport)
> +{
> + int ret = -1;
> + virCommandPtr cmd = NULL;
> + char virtportuuid[VIR_UUID_STRING_BUFLEN];
> +
> + virUUIDFormat(virtualport->interfaceID, virtportuuid);
> +
> + cmd = virCommandNew(MMCTL);
> + virCommandAddArgList(cmd, "--unbind-port", virtportuuid, NULL);
> +
> + if (virCommandRun(cmd, NULL) < 0) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("Unable to unbind the virtual port %s from Midonet"),
> + virtportuuid);
> + goto cleanup;
> + }
> +
> + ret = 0;
> + cleanup:
> + virCommandFree(cmd);
> + return ret;
> +}
> diff --git a/src/util/virnetdevmidonet.h b/src/util/virnetdevmidonet.h
> new file mode 100644
> index 0000000..6724d34
> --- /dev/null
> +++ b/src/util/virnetdevmidonet.h
> @@ -0,0 +1,37 @@
> +/*
> + * Copyright (C) 2015 Midokura Sarl.
> +
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library. If not, see
> + * <http://www.gnu.org/licenses/>.
> + *
> + * Authors:
> + * Antoni Segura Puimedon <toni at midokura.com>
> + */
> +
> +#ifndef __VIR_NETDEV_MIDONET_H__
> +# define __VIR_NETDEV_MIDONET_H__
> +
> +# include "internal.h"
> +# include "virnetdevvportprofile.h"
> +
> +
> +int virNetDevMidonetBindPort(const char *ifname,
> + virNetDevVPortProfilePtr virtualport)
> + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
> +
> +int virNetDevMidonetUnbindPort(virNetDevVPortProfilePtr virtualport)
> + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
> +
> +#endif /* __VIR_NETDEV_MIDONET_H__ */
> +
> diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
> index 6ee20d3..09acb52 100644
> --- a/src/util/virnetdevvportprofile.c
> +++ b/src/util/virnetdevvportprofile.c
> @@ -33,7 +33,8 @@ VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST,
> "none",
> "802.1Qbg",
> "802.1Qbh",
> - "openvswitch")
> + "openvswitch",
> + "midonet")
>
> VIR_ENUM_IMPL(virNetDevVPortProfileOp, VIR_NETDEV_VPORT_PROFILE_OP_LAST,
> "create",
> diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprofile.h
> index ad063c5..dc3e643 100644
> --- a/src/util/virnetdevvportprofile.h
> +++ b/src/util/virnetdevvportprofile.h
> @@ -35,6 +35,7 @@ enum virNetDevVPortProfile {
> VIR_NETDEV_VPORT_PROFILE_8021QBG,
> VIR_NETDEV_VPORT_PROFILE_8021QBH,
> VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH,
> + VIR_NETDEV_VPORT_PROFILE_MIDONET,
>
> VIR_NETDEV_VPORT_PROFILE_LAST,
> };
> @@ -73,7 +74,7 @@ struct _virNetDevVPortProfile {
> /* this is a null-terminated character string */
> char profileID[LIBVIRT_IFLA_VF_PORT_PROFILE_MAX];
>
> - /* this member is used when virtPortType == openvswitch */
> + /* this member is used when virtPortType == openvswitch|midonet */
> unsigned char interfaceID[VIR_UUID_BUFLEN];
> bool interfaceID_specified;
> /* NB - if virtPortType == NONE, any/all of the items could be used */
More information about the libvir-list
mailing list