mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-04 21:47:16 +03:00
Remove macvtap dependency on domain configuration
Files under src/util must not depend on src/conf Solve the macvtap problem by moving the definition of macvtap modes from domain_conf.h into macvtap.h * src/util/macvtap.c, src/util/macvtap.h: Add enum for macvtap modes * src/conf/domain_conf.c, src/conf/domain_conf.h: Remove enum for macvtap modes
This commit is contained in:
parent
73b9246df9
commit
caf808c790
@ -447,12 +447,6 @@ VIR_ENUM_IMPL(virDomainSeclabel, VIR_DOMAIN_SECLABEL_LAST,
|
||||
"dynamic",
|
||||
"static")
|
||||
|
||||
VIR_ENUM_IMPL(virDomainNetdevMacvtap, VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
|
||||
"vepa",
|
||||
"private",
|
||||
"bridge",
|
||||
"passthrough")
|
||||
|
||||
VIR_ENUM_IMPL(virVirtualPort, VIR_VIRTUALPORT_TYPE_LAST,
|
||||
"none",
|
||||
"802.1Qbg",
|
||||
@ -2974,14 +2968,14 @@ virDomainNetDefParseXML(virCapsPtr caps,
|
||||
|
||||
if (mode != NULL) {
|
||||
int m;
|
||||
if ((m = virDomainNetdevMacvtapTypeFromString(mode)) < 0) {
|
||||
if ((m = virMacvtapModeTypeFromString(mode)) < 0) {
|
||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unkown mode has been specified"));
|
||||
goto error;
|
||||
}
|
||||
def->data.direct.mode = m;
|
||||
} else
|
||||
def->data.direct.mode = VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA;
|
||||
def->data.direct.mode = VIR_MACVTAP_MODE_VEPA;
|
||||
|
||||
if (virtPortParsed)
|
||||
def->data.direct.virtPortProfile = virtPort;
|
||||
@ -8634,7 +8628,7 @@ virDomainNetDefFormat(virBufferPtr buf,
|
||||
virBufferEscapeString(buf, " <source dev='%s'",
|
||||
def->data.direct.linkdev);
|
||||
virBufferAsprintf(buf, " mode='%s'",
|
||||
virDomainNetdevMacvtapTypeToString(def->data.direct.mode));
|
||||
virMacvtapModeTypeToString(def->data.direct.mode));
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
virVirtualPortProfileFormat(buf, &def->data.direct.virtPortProfile,
|
||||
" ");
|
||||
|
@ -348,17 +348,6 @@ enum virDomainNetVirtioTxModeType {
|
||||
VIR_DOMAIN_NET_VIRTIO_TX_MODE_LAST,
|
||||
};
|
||||
|
||||
/* the mode type for macvtap devices */
|
||||
enum virDomainNetdevMacvtapType {
|
||||
VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA,
|
||||
VIR_DOMAIN_NETDEV_MACVTAP_MODE_PRIVATE,
|
||||
VIR_DOMAIN_NETDEV_MACVTAP_MODE_BRIDGE,
|
||||
VIR_DOMAIN_NETDEV_MACVTAP_MODE_PASSTHRU,
|
||||
|
||||
VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
|
||||
};
|
||||
|
||||
|
||||
/* Stores the virtual network interface configuration */
|
||||
typedef struct _virDomainNetDef virDomainNetDef;
|
||||
typedef virDomainNetDef *virDomainNetDefPtr;
|
||||
@ -396,7 +385,7 @@ struct _virDomainNetDef {
|
||||
} internal;
|
||||
struct {
|
||||
char *linkdev;
|
||||
int mode;
|
||||
int mode; /* enum virMacvtapMode from util/macvtap.h */
|
||||
virVirtualPortProfileParams virtPortProfile;
|
||||
} direct;
|
||||
} data;
|
||||
@ -1615,8 +1604,6 @@ int virDomainStateReasonFromString(virDomainState state, const char *reason);
|
||||
VIR_ENUM_DECL(virDomainSeclabel)
|
||||
VIR_ENUM_DECL(virDomainClockOffset)
|
||||
|
||||
VIR_ENUM_DECL(virDomainNetdevMacvtap)
|
||||
|
||||
VIR_ENUM_DECL(virDomainTimerName)
|
||||
VIR_ENUM_DECL(virDomainTimerTrack)
|
||||
VIR_ENUM_DECL(virDomainTimerTickpolicy)
|
||||
|
@ -55,12 +55,17 @@
|
||||
#include "util.h"
|
||||
#include "macvtap.h"
|
||||
|
||||
VIR_ENUM_IMPL(virMacvtapMode, VIR_MACVTAP_MODE_LAST,
|
||||
"vepa",
|
||||
"private",
|
||||
"bridge",
|
||||
"passthrough")
|
||||
|
||||
#if WITH_MACVTAP || WITH_VIRTUALPORT
|
||||
|
||||
# include "memory.h"
|
||||
# include "logging.h"
|
||||
# include "interface.h"
|
||||
# include "conf/domain_conf.h"
|
||||
# include "virterror_internal.h"
|
||||
# include "uuid.h"
|
||||
# include "files.h"
|
||||
@ -468,26 +473,6 @@ int openTap(const char *ifname,
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
macvtapModeFromInt(enum virDomainNetdevMacvtapType mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case VIR_DOMAIN_NETDEV_MACVTAP_MODE_PRIVATE:
|
||||
return MACVLAN_MODE_PRIVATE;
|
||||
|
||||
case VIR_DOMAIN_NETDEV_MACVTAP_MODE_BRIDGE:
|
||||
return MACVLAN_MODE_BRIDGE;
|
||||
|
||||
case VIR_DOMAIN_NETDEV_MACVTAP_MODE_PASSTHRU:
|
||||
return MACVLAN_MODE_PASSTHRU;
|
||||
|
||||
case VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA:
|
||||
default:
|
||||
return MACVLAN_MODE_VEPA;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* configMacvtapTap:
|
||||
* @tapfd: file descriptor of the macvtap tap
|
||||
@ -643,6 +628,13 @@ restoreMacAddress(const char *linkdev,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const uint32_t modeMap[VIR_MACVTAP_MODE_LAST] = {
|
||||
[VIR_MACVTAP_MODE_VEPA] = MACVLAN_MODE_VEPA,
|
||||
[VIR_MACVTAP_MODE_PRIVATE] = MACVLAN_MODE_PRIVATE,
|
||||
[VIR_MACVTAP_MODE_BRIDGE] = MACVLAN_MODE_BRIDGE,
|
||||
[VIR_MACVTAP_MODE_PASSTHRU] = MACVLAN_MODE_PASSTHRU,
|
||||
};
|
||||
|
||||
/**
|
||||
* openMacvtapTap:
|
||||
* Create an instance of a macvtap device and open its tap character
|
||||
@ -667,7 +659,7 @@ int
|
||||
openMacvtapTap(const char *tgifname,
|
||||
const unsigned char *macaddress,
|
||||
const char *linkdev,
|
||||
int mode,
|
||||
enum virMacvtapMode mode,
|
||||
int vnet_hdr,
|
||||
const unsigned char *vmuuid,
|
||||
virVirtualPortProfileParamsPtr virtPortProfile,
|
||||
@ -679,10 +671,12 @@ openMacvtapTap(const char *tgifname,
|
||||
int c, rc;
|
||||
char ifname[IFNAMSIZ];
|
||||
int retries, do_retry = 0;
|
||||
uint32_t macvtapMode = macvtapModeFromInt(mode);
|
||||
uint32_t macvtapMode;
|
||||
const char *cr_ifname;
|
||||
int ifindex;
|
||||
|
||||
macvtapMode = modeMap[mode];
|
||||
|
||||
*res_ifname = NULL;
|
||||
|
||||
VIR_DEBUG("%s: VM OPERATION: %s", __FUNCTION__, virVMOperationTypeToString(vmOp));
|
||||
@ -694,7 +688,7 @@ openMacvtapTap(const char *tgifname,
|
||||
* This is especially important when using SRIOV capable cards that
|
||||
* emulate their switch in firmware.
|
||||
*/
|
||||
if (mode == VIR_DOMAIN_NETDEV_MACVTAP_MODE_PASSTHRU) {
|
||||
if (mode == VIR_MACVTAP_MODE_PASSTHRU) {
|
||||
if (replaceMacAdress(macaddress, linkdev, stateDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -799,7 +793,7 @@ delMacvtap(const char *ifname,
|
||||
virVirtualPortProfileParamsPtr virtPortProfile,
|
||||
char *stateDir)
|
||||
{
|
||||
if (mode == VIR_DOMAIN_NETDEV_MACVTAP_MODE_PASSTHRU) {
|
||||
if (mode == VIR_MACVTAP_MODE_PASSTHRU) {
|
||||
restoreMacAddress(linkdev, stateDir);
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,17 @@ enum virVirtualPortType {
|
||||
VIR_VIRTUALPORT_TYPE_LAST,
|
||||
};
|
||||
|
||||
/* the mode type for macvtap devices */
|
||||
enum virMacvtapMode {
|
||||
VIR_MACVTAP_MODE_VEPA,
|
||||
VIR_MACVTAP_MODE_PRIVATE,
|
||||
VIR_MACVTAP_MODE_BRIDGE,
|
||||
VIR_MACVTAP_MODE_PASSTHRU,
|
||||
|
||||
VIR_MACVTAP_MODE_LAST,
|
||||
};
|
||||
|
||||
|
||||
# ifdef IFLA_VF_PORT_PROFILE_MAX
|
||||
# define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX IFLA_VF_PORT_PROFILE_MAX
|
||||
# else
|
||||
@ -78,7 +89,7 @@ enum virVMOperationType {
|
||||
int openMacvtapTap(const char *ifname,
|
||||
const unsigned char *macaddress,
|
||||
const char *linkdev,
|
||||
int mode,
|
||||
enum virMacvtapMode mode,
|
||||
int vnet_hdr,
|
||||
const unsigned char *vmuuid,
|
||||
virVirtualPortProfileParamsPtr virtPortProfile,
|
||||
@ -110,5 +121,6 @@ int vpDisassociatePortProfileId(const char *macvtap_ifname,
|
||||
|
||||
VIR_ENUM_DECL(virVirtualPort)
|
||||
VIR_ENUM_DECL(virVMOperation)
|
||||
VIR_ENUM_DECL(virMacvtapMode)
|
||||
|
||||
#endif /* __UTIL_MACVTAP_H__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user