提交 57f0de4c 编写于 作者: D Daniel P. Berrange

Rename low level macvlan creation APIs

Rename ifaceMacvtapLinkAdd to virNetDevMacVLanCreate and
ifaceLinkDel to virNetDevMacVLanDelete. Strictly speaking
the latter isn't restricted to macvlan devices, but that's
the only use libvirt has for it.

* util/interface.c, util/interface.h,
  util/virnetdevmacvlan.c: Rename APIs
上级 191090ae
...@@ -583,8 +583,8 @@ ifaceGetPhysicalFunction; ...@@ -583,8 +583,8 @@ ifaceGetPhysicalFunction;
ifaceGetVirtualFunctionIndex; ifaceGetVirtualFunctionIndex;
ifaceGetVlanID; ifaceGetVlanID;
ifaceIsVirtualFunction; ifaceIsVirtualFunction;
ifaceLinkDel; virNetDevMacVLanCreate;
ifaceMacvtapLinkAdd; virNetDevMacVLanDelete;
ifaceMacvtapLinkDump; ifaceMacvtapLinkDump;
ifaceReplaceMacAddress; ifaceReplaceMacAddress;
ifaceRestoreMacAddress; ifaceRestoreMacAddress;
......
...@@ -313,12 +313,11 @@ ifaceGetIPAddress(const char *ifname ATTRIBUTE_UNUSED, ...@@ -313,12 +313,11 @@ ifaceGetIPAddress(const char *ifname ATTRIBUTE_UNUSED,
#endif /* __linux__ */ #endif /* __linux__ */
/** /**
* ifaceLinkAdd * virNetDevMacVLanCreate:
* *
* @ifname: The name the interface is supposed to have; optional parameter
* @type: The type of device, i.e., "macvtap" * @type: The type of device, i.e., "macvtap"
* @macaddress: The MAC address of the device * @macaddress: The MAC address of the device
* @macaddrsize: The size of the MAC address, typically '6'
* @ifname: The name the interface is supposed to have; optional parameter
* @srcdev: The name of the 'link' device * @srcdev: The name of the 'link' device
* @macvlan_mode: The macvlan mode to use * @macvlan_mode: The macvlan mode to use
* @retry: Pointer to integer that will be '1' upon return if an interface * @retry: Pointer to integer that will be '1' upon return if an interface
...@@ -331,12 +330,12 @@ ifaceGetIPAddress(const char *ifname ATTRIBUTE_UNUSED, ...@@ -331,12 +330,12 @@ ifaceGetIPAddress(const char *ifname ATTRIBUTE_UNUSED,
*/ */
#if defined(__linux__) && WITH_MACVTAP #if defined(__linux__) && WITH_MACVTAP
int int
ifaceMacvtapLinkAdd(const char *type, virNetDevMacVLanCreate(const char *ifname,
const unsigned char *macaddress, int macaddrsize, const char *type,
const char *ifname, const unsigned char *macaddress,
const char *srcdev, const char *srcdev,
uint32_t macvlan_mode, uint32_t macvlan_mode,
int *retry) int *retry)
{ {
int rc = 0; int rc = 0;
struct nlmsghdr *resp; struct nlmsghdr *resp;
...@@ -366,7 +365,7 @@ ifaceMacvtapLinkAdd(const char *type, ...@@ -366,7 +365,7 @@ ifaceMacvtapLinkAdd(const char *type,
if (nla_put_u32(nl_msg, IFLA_LINK, ifindex) < 0) if (nla_put_u32(nl_msg, IFLA_LINK, ifindex) < 0)
goto buffer_too_small; goto buffer_too_small;
if (nla_put(nl_msg, IFLA_ADDRESS, macaddrsize, macaddress) < 0) if (nla_put(nl_msg, IFLA_ADDRESS, VIR_MAC_BUFLEN, macaddress) < 0)
goto buffer_too_small; goto buffer_too_small;
if (ifname && if (ifname &&
...@@ -458,14 +457,12 @@ buffer_too_small: ...@@ -458,14 +457,12 @@ buffer_too_small:
#else #else
int int virNetDevMacVLanCreate(const char *ifname ATTRIBUTE_UNUSED,
ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED, const char *type ATTRIBUTE_UNUSED,
const unsigned char *macaddress ATTRIBUTE_UNUSED, const unsigned char *macaddress ATTRIBUTE_UNUSED,
int macaddrsize ATTRIBUTE_UNUSED, const char *srcdev ATTRIBUTE_UNUSED,
const char *ifname ATTRIBUTE_UNUSED, uint32_t macvlan_mode ATTRIBUTE_UNUSED,
const char *srcdev ATTRIBUTE_UNUSED, int *retry ATTRIBUTE_UNUSED)
uint32_t macvlan_mode ATTRIBUTE_UNUSED,
int *retry ATTRIBUTE_UNUSED)
{ {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s", ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !WITH_MACVTAP # if defined(__linux__) && !WITH_MACVTAP
...@@ -483,7 +480,7 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED, ...@@ -483,7 +480,7 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED,
/** /**
* ifaceLinkDel * virNetDevMacVLanDelete:
* *
* @ifname: Name of the interface * @ifname: Name of the interface
* *
...@@ -492,8 +489,7 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED, ...@@ -492,8 +489,7 @@ ifaceMacvtapLinkAdd(const char *type ATTRIBUTE_UNUSED,
* Returns 0 on success, -1 on fatal error. * Returns 0 on success, -1 on fatal error.
*/ */
#if defined( __linux__) && WITH_MACVTAP #if defined( __linux__) && WITH_MACVTAP
int int virNetDevMacVLanDelete(const char *ifname)
ifaceLinkDel(const char *ifname)
{ {
int rc = 0; int rc = 0;
struct nlmsghdr *resp; struct nlmsghdr *resp;
...@@ -572,8 +568,7 @@ buffer_too_small: ...@@ -572,8 +568,7 @@ buffer_too_small:
#else #else
int int virNetDevMacVLanDelete(const char *ifname ATTRIBUTE_UNUSED)
ifaceLinkDel(const char *ifname ATTRIBUTE_UNUSED)
{ {
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s", ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !WITH_MACVTAP # if defined(__linux__) && !WITH_MACVTAP
......
...@@ -39,14 +39,17 @@ int ifaceGetVlanID(const char *vlanifname, int *vlanid); ...@@ -39,14 +39,17 @@ int ifaceGetVlanID(const char *vlanifname, int *vlanid);
int ifaceGetIPAddress(const char *ifname, virSocketAddrPtr addr); int ifaceGetIPAddress(const char *ifname, virSocketAddrPtr addr);
int ifaceMacvtapLinkAdd(const char *type, int virNetDevMacVLanCreate(const char *ifname,
const unsigned char *macaddress, int macaddrsize, const char *type,
const char *ifname, const unsigned char *macaddress,
const char *srcdev, const char *srcdev,
uint32_t macvlan_mode, uint32_t macvlan_mode,
int *retry); int *retry)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
int ifaceLinkDel(const char *ifname); ATTRIBUTE_RETURN_CHECK;
int virNetDevMacVLanDelete(const char *ifname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int ifaceMacvtapLinkDump(bool nltarget_kernel, const char *ifname, int ifindex, int ifaceMacvtapLinkDump(bool nltarget_kernel, const char *ifname, int ifindex,
struct nlattr **tb, unsigned char **recvbuf, struct nlattr **tb, unsigned char **recvbuf,
......
...@@ -284,8 +284,8 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname, ...@@ -284,8 +284,8 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
return -1; return -1;
} }
cr_ifname = tgifname; cr_ifname = tgifname;
rc = ifaceMacvtapLinkAdd(type, macaddress, 6, tgifname, linkdev, rc = virNetDevMacVLanCreate(tgifname, type, macaddress, linkdev,
macvtapMode, &do_retry); macvtapMode, &do_retry);
if (rc < 0) if (rc < 0)
return -1; return -1;
} else { } else {
...@@ -294,8 +294,8 @@ create_name: ...@@ -294,8 +294,8 @@ create_name:
for (c = 0; c < 8192; c++) { for (c = 0; c < 8192; c++) {
snprintf(ifname, sizeof(ifname), MACVTAP_NAME_PATTERN, c); snprintf(ifname, sizeof(ifname), MACVTAP_NAME_PATTERN, c);
if (ifaceGetIndex(false, ifname, &ifindex) == -ENODEV) { if (ifaceGetIndex(false, ifname, &ifindex) == -ENODEV) {
rc = ifaceMacvtapLinkAdd(type, macaddress, 6, ifname, linkdev, rc = virNetDevMacVLanCreate(ifname, type, macaddress, linkdev,
macvtapMode, &do_retry); macvtapMode, &do_retry);
if (rc == 0) if (rc == 0)
break; break;
...@@ -350,7 +350,7 @@ disassociate_exit: ...@@ -350,7 +350,7 @@ disassociate_exit:
vmOp)); vmOp));
link_del_exit: link_del_exit:
ifaceLinkDel(cr_ifname); ignore_value(virNetDevMacVLanDelete(cr_ifname));
return rc; return rc;
} }
...@@ -385,7 +385,7 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname, ...@@ -385,7 +385,7 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname,
linkdev, linkdev,
VIR_NETDEV_VPORT_PROFILE_OP_DESTROY) < 0) VIR_NETDEV_VPORT_PROFILE_OP_DESTROY) < 0)
ret = -1; ret = -1;
if (ifaceLinkDel(ifname) < 0) if (virNetDevMacVLanDelete(ifname) < 0)
ret = -1; ret = -1;
} }
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册