mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
util: Introduce flags field for macvtap creation
Currently, there is one flag passed in during macvtap creation (withTap) -- Let's convert this field to an unsigned int flag field for future expansion. Signed-off-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
628c2255a9
commit
7199d2c523
@ -331,12 +331,12 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
|
|||||||
net->ifname, &net->mac,
|
net->ifname, &net->mac,
|
||||||
virDomainNetGetActualDirectDev(net),
|
virDomainNetGetActualDirectDev(net),
|
||||||
virDomainNetGetActualDirectMode(net),
|
virDomainNetGetActualDirectMode(net),
|
||||||
false, false, def->uuid,
|
false, def->uuid,
|
||||||
virDomainNetGetActualVirtPortProfile(net),
|
virDomainNetGetActualVirtPortProfile(net),
|
||||||
&res_ifname,
|
&res_ifname,
|
||||||
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
|
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
|
||||||
cfg->stateDir,
|
cfg->stateDir,
|
||||||
virDomainNetGetActualBandwidth(net)) < 0)
|
virDomainNetGetActualBandwidth(net), 0) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = res_ifname;
|
ret = res_ifname;
|
||||||
|
@ -177,6 +177,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
|
|||||||
char *res_ifname = NULL;
|
char *res_ifname = NULL;
|
||||||
int vnet_hdr = 0;
|
int vnet_hdr = 0;
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
|
||||||
|
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNET_HDR) &&
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNET_HDR) &&
|
||||||
net->model && STREQ(net->model, "virtio"))
|
net->model && STREQ(net->model, "virtio"))
|
||||||
@ -186,11 +187,12 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
|
|||||||
net->ifname, &net->mac,
|
net->ifname, &net->mac,
|
||||||
virDomainNetGetActualDirectDev(net),
|
virDomainNetGetActualDirectDev(net),
|
||||||
virDomainNetGetActualDirectMode(net),
|
virDomainNetGetActualDirectMode(net),
|
||||||
true, vnet_hdr, def->uuid,
|
vnet_hdr, def->uuid,
|
||||||
virDomainNetGetActualVirtPortProfile(net),
|
virDomainNetGetActualVirtPortProfile(net),
|
||||||
&res_ifname,
|
&res_ifname,
|
||||||
vmop, cfg->stateDir,
|
vmop, cfg->stateDir,
|
||||||
virDomainNetGetActualBandwidth(net));
|
virDomainNetGetActualBandwidth(net),
|
||||||
|
macvlan_create_flags);
|
||||||
if (rc >= 0) {
|
if (rc >= 0) {
|
||||||
virDomainAuditNetDevice(def, net, res_ifname, true);
|
virDomainAuditNetDevice(def, net, res_ifname, true);
|
||||||
VIR_FREE(net->ifname);
|
VIR_FREE(net->ifname);
|
||||||
|
@ -796,26 +796,31 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
|
|||||||
* @res_ifname: Pointer to a string pointer where the actual name of the
|
* @res_ifname: Pointer to a string pointer where the actual name of the
|
||||||
* interface will be stored into if everything succeeded. It is up
|
* interface will be stored into if everything succeeded. It is up
|
||||||
* to the caller to free the string.
|
* to the caller to free the string.
|
||||||
|
* @flags: OR of virNetDevMacVLanCreateFlags.
|
||||||
*
|
*
|
||||||
* Returns file descriptor of the tap device in case of success with @withTap,
|
* Returns file descriptor of the tap device in case of success with
|
||||||
* otherwise returns 0; returns -1 on error.
|
* @flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP, otherwise returns 0; returns
|
||||||
|
* -1 on error.
|
||||||
*/
|
*/
|
||||||
int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
|
int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
|
||||||
const virMacAddr *macaddress,
|
const virMacAddr *macaddress,
|
||||||
const char *linkdev,
|
const char *linkdev,
|
||||||
virNetDevMacVLanMode mode,
|
virNetDevMacVLanMode mode,
|
||||||
bool withTap,
|
|
||||||
int vnet_hdr,
|
int vnet_hdr,
|
||||||
const unsigned char *vmuuid,
|
const unsigned char *vmuuid,
|
||||||
virNetDevVPortProfilePtr virtPortProfile,
|
virNetDevVPortProfilePtr virtPortProfile,
|
||||||
char **res_ifname,
|
char **res_ifname,
|
||||||
virNetDevVPortProfileOp vmOp,
|
virNetDevVPortProfileOp vmOp,
|
||||||
char *stateDir,
|
char *stateDir,
|
||||||
virNetDevBandwidthPtr bandwidth)
|
virNetDevBandwidthPtr bandwidth,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
const char *type = withTap ? "macvtap" : "macvlan";
|
const char *type = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
|
||||||
const char *prefix = withTap ? MACVTAP_NAME_PREFIX : MACVLAN_NAME_PREFIX;
|
"macvtap" : "macvlan";
|
||||||
const char *pattern = withTap ? MACVTAP_NAME_PATTERN : MACVLAN_NAME_PATTERN;
|
const char *prefix = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
|
||||||
|
MACVTAP_NAME_PREFIX : MACVLAN_NAME_PREFIX;
|
||||||
|
const char *pattern = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
|
||||||
|
MACVTAP_NAME_PATTERN : MACVLAN_NAME_PATTERN;
|
||||||
int c, rc;
|
int c, rc;
|
||||||
char ifname[IFNAMSIZ];
|
char ifname[IFNAMSIZ];
|
||||||
int retries, do_retry = 0;
|
int retries, do_retry = 0;
|
||||||
@ -903,7 +908,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
|
|||||||
goto disassociate_exit;
|
goto disassociate_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withTap) {
|
if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) {
|
||||||
if ((rc = virNetDevMacVLanTapOpen(cr_ifname, 10)) < 0)
|
if ((rc = virNetDevMacVLanTapOpen(cr_ifname, 10)) < 0)
|
||||||
goto disassociate_exit;
|
goto disassociate_exit;
|
||||||
|
|
||||||
@ -922,7 +927,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (virNetDevBandwidthSet(cr_ifname, bandwidth, false) < 0) {
|
if (virNetDevBandwidthSet(cr_ifname, bandwidth, false) < 0) {
|
||||||
if (withTap)
|
if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP)
|
||||||
VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
|
VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
|
||||||
else
|
else
|
||||||
rc = -1;
|
rc = -1;
|
||||||
@ -1066,15 +1071,16 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *ifname ATTRIBUTE_UNUSED,
|
|||||||
const virMacAddr *macaddress ATTRIBUTE_UNUSED,
|
const virMacAddr *macaddress ATTRIBUTE_UNUSED,
|
||||||
const char *linkdev ATTRIBUTE_UNUSED,
|
const char *linkdev ATTRIBUTE_UNUSED,
|
||||||
virNetDevMacVLanMode mode ATTRIBUTE_UNUSED,
|
virNetDevMacVLanMode mode ATTRIBUTE_UNUSED,
|
||||||
bool withTap ATTRIBUTE_UNUSED,
|
|
||||||
int vnet_hdr ATTRIBUTE_UNUSED,
|
int vnet_hdr ATTRIBUTE_UNUSED,
|
||||||
const unsigned char *vmuuid ATTRIBUTE_UNUSED,
|
const unsigned char *vmuuid ATTRIBUTE_UNUSED,
|
||||||
virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
|
virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
|
||||||
char **res_ifname ATTRIBUTE_UNUSED,
|
char **res_ifname ATTRIBUTE_UNUSED,
|
||||||
virNetDevVPortProfileOp vmop ATTRIBUTE_UNUSED,
|
virNetDevVPortProfileOp vmop ATTRIBUTE_UNUSED,
|
||||||
char *stateDir ATTRIBUTE_UNUSED,
|
char *stateDir ATTRIBUTE_UNUSED,
|
||||||
virNetDevBandwidthPtr bandwidth ATTRIBUTE_UNUSED)
|
virNetDevBandwidthPtr bandwidth ATTRIBUTE_UNUSED,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
|
virCheckFlags(0, -1);
|
||||||
virReportSystemError(ENOSYS, "%s",
|
virReportSystemError(ENOSYS, "%s",
|
||||||
_("Cannot create macvlan devices on this platform"));
|
_("Cannot create macvlan devices on this platform"));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -40,6 +40,12 @@ typedef enum {
|
|||||||
} virNetDevMacVLanMode;
|
} virNetDevMacVLanMode;
|
||||||
VIR_ENUM_DECL(virNetDevMacVLanMode)
|
VIR_ENUM_DECL(virNetDevMacVLanMode)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VIR_NETDEV_MACVLAN_CREATE_NONE = 0,
|
||||||
|
/* Create with a tap device */
|
||||||
|
VIR_NETDEV_MACVLAN_CREATE_WITH_TAP = 1 << 0,
|
||||||
|
} virNetDevMacVLanCreateFlags;
|
||||||
|
|
||||||
int virNetDevMacVLanCreate(const char *ifname,
|
int virNetDevMacVLanCreate(const char *ifname,
|
||||||
const char *type,
|
const char *type,
|
||||||
const virMacAddr *macaddress,
|
const virMacAddr *macaddress,
|
||||||
@ -56,16 +62,16 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *ifname,
|
|||||||
const virMacAddr *macaddress,
|
const virMacAddr *macaddress,
|
||||||
const char *linkdev,
|
const char *linkdev,
|
||||||
virNetDevMacVLanMode mode,
|
virNetDevMacVLanMode mode,
|
||||||
bool withTap,
|
|
||||||
int vnet_hdr,
|
int vnet_hdr,
|
||||||
const unsigned char *vmuuid,
|
const unsigned char *vmuuid,
|
||||||
virNetDevVPortProfilePtr virtPortProfile,
|
virNetDevVPortProfilePtr virtPortProfile,
|
||||||
char **res_ifname,
|
char **res_ifname,
|
||||||
virNetDevVPortProfileOp vmop,
|
virNetDevVPortProfileOp vmop,
|
||||||
char *stateDir,
|
char *stateDir,
|
||||||
virNetDevBandwidthPtr bandwidth)
|
virNetDevBandwidthPtr bandwidth,
|
||||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(7)
|
unsigned int flags)
|
||||||
ATTRIBUTE_NONNULL(9) ATTRIBUTE_NONNULL(11) ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(6)
|
||||||
|
ATTRIBUTE_NONNULL(8) ATTRIBUTE_NONNULL(10) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname,
|
int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname,
|
||||||
const virMacAddr *macaddress,
|
const virMacAddr *macaddress,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user