[libvirt] [PATCH 4/5] macvtap support for libvirt -- helper code

This part adds the helper code to setup and tear down macvtap devices using direct communication with the device driver via netlink sockets. Signed-off-by: Stefan Berger <stefanb@us.ibm.com>

On Thu, Feb 04, 2010 at 08:02:54AM -0500, Stefan Berger wrote:
This part adds the helper code to setup and tear down macvtap devices using direct communication with the device driver via netlink sockets.
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
Index: libvirt-macvtap/src/util/macvtap.h =================================================================== --- /dev/null +++ libvirt-macvtap/src/util/macvtap.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2010 IBM Corporation + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: + * Stefan Berger <stefanb@us.ibm.com> + */ + +#ifndef __UTIL_MACVTAP_H__ +#define __UTIL_MACVTAP_H__ + +#include <config.h> + +#if defined(WITH_MACVTAP) + +#include "internal.h" + +int openMacvtapTap(virConnectPtr conn, + const char *ifname, + const unsigned char *macaddress, + const char *linkdev, + const char *mode, + char **res_ifname);
'mode' should be just an int rather than char *
+ +int delMacvtapByMACAddress(virConnectPtr conn, + const unsigned char *macaddress, + int *hasBusyDev); + +#endif /* WITH_MACVTAP */ + +#define MACVTAP_MODE_PRIVATE_STR "private" +#define MACVTAP_MODE_VEPA_STR "vepa" +#define MACVTAP_MODE_BRIDGE_STR "bridge"
These strings are redundant if the XML parser takes care of the string -> int conversion at parsing time.
+ +static uint32_t +modeFromString(const char *mode_str) +{ + if (!mode_str) + return 0; + if (STREQ(mode_str, MACVTAP_MODE_PRIVATE_STR)) + return MACVLAN_MODE_PRIVATE; + if (STREQ(mode_str, MACVTAP_MODE_VEPA_STR)) + return MACVLAN_MODE_VEPA; + if (STREQ(mode_str, MACVTAP_MODE_BRIDGE_STR)) + return MACVLAN_MODE_BRIDGE; + return 0; +}
This method can be removed, since it is just duplicating the functionality of the code generated by the VIR_ENUM_DECL declaration in the XML parsing code you have.
+create_name: + retries = 5; + for (c = 0; c < 255; c++) {
This that an abslute limit on number of MACVTAP devices, or can we raise this somewhat higher ? We recently had to remove a similarly low hardcoded limit in number of plain TAP devices. If we cna make this 1024 or more, that'd be great
+ snprintf(ifname, sizeof(ifname), MACVTAP_NAME_PATTERN, c); + if (getIfIndex(NULL, ifname, &ifindex) == ENODEV) { + rc = link_add(conn, type, macaddress, 6, ifname, linkdev, + mode, &do_retry); + if (rc == 0) + break; + + if (do_retry && --retries) + continue; + return -1; + } + } + cr_ifname = ifname; + } + + rc = ifUp(cr_ifname, 1); + if (rc != 0) { + virReportSystemError(conn, errno, + _("cannot 'up' interface %s"), cr_ifname); + rc = -1; + goto link_del_exit; + } + + rc = openTap(conn, cr_ifname, 10); + + if (rc > 0) + *res_ifname = strdup(cr_ifname); + else + goto link_del_exit; + + return rc; + +link_del_exit: + link_del(conn, type, ifname); + + return rc; +}
Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

"Daniel P. Berrange" <berrange@redhat.com> wrote on 02/08/2010 12:03:53 PM:
This method can be removed, since it is just duplicating the functionality of the code generated by the VIR_ENUM_DECL declaration in the XML parsing code you have.
I will probably have to have a translation function to convert the integers to the enums understood by the driver.
+create_name: + retries = 5; + for (c = 0; c < 255; c++) {
This that an abslute limit on number of MACVTAP devices, or can we raise this somewhat higher ? We recently had to remove a similarly low hardcoded limit in number of plain TAP devices. If we cna make this 1024 or more, that'd be great
I don't think there is such a limit. I will raise the number to 1024 or higher. Thanks and regards, Stefan
participants (2)
-
Daniel P. Berrange
-
Stefan Berger