提交 0d7d6997 编写于 作者: M Matthias Bolte

macvtap: Remove virConnectPtr from ReportError

Also rename ReportError to macvtapError.
上级 1870e707
...@@ -175,7 +175,7 @@ msg_gen_function += ERROR0 ...@@ -175,7 +175,7 @@ msg_gen_function += ERROR0
msg_gen_function += ESX_ERROR msg_gen_function += ESX_ERROR
msg_gen_function += ESX_VI_ERROR msg_gen_function += ESX_VI_ERROR
msg_gen_function += REMOTE_DEBUG msg_gen_function += REMOTE_DEBUG
msg_gen_function += ReportError msg_gen_function += macvtapError
msg_gen_function += VIR_FREE msg_gen_function += VIR_FREE
msg_gen_function += VIR_INFO msg_gen_function += VIR_INFO
msg_gen_function += VIR_USE_CPU msg_gen_function += VIR_USE_CPU
......
...@@ -1469,7 +1469,7 @@ qemudPhysIfaceConnect(virConnectPtr conn, ...@@ -1469,7 +1469,7 @@ qemudPhysIfaceConnect(virConnectPtr conn,
net->model && STREQ(net->model, "virtio")) net->model && STREQ(net->model, "virtio"))
vnet_hdr = 1; vnet_hdr = 1;
rc = openMacvtapTap(conn, net->ifname, net->mac, linkdev, brmode, rc = openMacvtapTap(net->ifname, net->mac, linkdev, brmode,
&res_ifname, vnet_hdr); &res_ifname, vnet_hdr);
if (rc >= 0) { if (rc >= 0) {
VIR_FREE(net->ifname); VIR_FREE(net->ifname);
......
...@@ -49,9 +49,9 @@ ...@@ -49,9 +49,9 @@
# define VIR_FROM_THIS VIR_FROM_NET # define VIR_FROM_THIS VIR_FROM_NET
# define ReportError(conn, code, ...) \ # define macvtapError(code, ...) \
virReportErrorHelper(conn, VIR_FROM_NET, code, __FILE__, \ virReportErrorHelper(NULL, VIR_FROM_NET, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__) __FUNCTION__, __LINE__, __VA_ARGS__)
# define MACVTAP_NAME_PREFIX "macvtap" # define MACVTAP_NAME_PREFIX "macvtap"
# define MACVTAP_NAME_PATTERN "macvtap%d" # define MACVTAP_NAME_PATTERN "macvtap%d"
...@@ -193,7 +193,7 @@ nlAppend(struct nlmsghdr *nlm, int totlen, const void *data, int datalen) ...@@ -193,7 +193,7 @@ nlAppend(struct nlmsghdr *nlm, int totlen, const void *data, int datalen)
static int static int
getIfIndex(virConnectPtr conn, getIfIndex(bool reportError,
const char *ifname, const char *ifname,
int *idx) int *idx)
{ {
...@@ -206,20 +206,20 @@ getIfIndex(virConnectPtr conn, ...@@ -206,20 +206,20 @@ getIfIndex(virConnectPtr conn,
if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname), if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
sizeof(ifreq.ifr_name)) == NULL) { sizeof(ifreq.ifr_name)) == NULL) {
if (conn) if (reportError)
ReportError(conn, VIR_ERR_INTERNAL_ERROR, macvtapError(VIR_ERR_INTERNAL_ERROR,
_("invalid interface name %s"), _("invalid interface name %s"),
ifname); ifname);
rc = EINVAL; rc = EINVAL;
goto err_exit; goto err_exit;
} }
if (ioctl(fd, SIOCGIFINDEX, &ifreq) >= 0) if (ioctl(fd, SIOCGIFINDEX, &ifreq) >= 0)
*idx = ifreq.ifr_ifindex; *idx = ifreq.ifr_ifindex;
else { else {
if (conn) if (reportError)
ReportError(conn, VIR_ERR_INTERNAL_ERROR, macvtapError(VIR_ERR_INTERNAL_ERROR,
_("interface %s does not exist"), _("interface %s does not exist"),
ifname); ifname);
rc = ENODEV; rc = ENODEV;
} }
...@@ -296,8 +296,7 @@ ifUp(const char *name, int up) ...@@ -296,8 +296,7 @@ ifUp(const char *name, int up)
static int static int
link_add(virConnectPtr conn, link_add(const char *type,
const char *type,
const unsigned char *macaddress, int macaddrsize, const unsigned char *macaddress, int macaddrsize,
const char *ifname, const char *ifname,
const char *srcdev, const char *srcdev,
...@@ -315,7 +314,7 @@ link_add(virConnectPtr conn, ...@@ -315,7 +314,7 @@ link_add(virConnectPtr conn,
char *recvbuf = NULL; char *recvbuf = NULL;
int recvbuflen; int recvbuflen;
if (getIfIndex(conn, srcdev, &ifindex) != 0) if (getIfIndex(true, srcdev, &ifindex) != 0)
return -1; return -1;
*retry = 0; *retry = 0;
...@@ -434,14 +433,14 @@ link_add(virConnectPtr conn, ...@@ -434,14 +433,14 @@ link_add(virConnectPtr conn,
return rc; return rc;
malformed_resp: malformed_resp:
ReportError(conn, VIR_ERR_INTERNAL_ERROR, macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
"%s", _("malformed netlink response message")); _("malformed netlink response message"));
VIR_FREE(recvbuf); VIR_FREE(recvbuf);
return -1; return -1;
buffer_too_small: buffer_too_small:
ReportError(conn, VIR_ERR_INTERNAL_ERROR, macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
"%s", _("internal buffer is too small")); _("internal buffer is too small"));
return -1; return -1;
} }
...@@ -512,21 +511,20 @@ link_del(const char *name) ...@@ -512,21 +511,20 @@ link_del(const char *name)
return rc; return rc;
malformed_resp: malformed_resp:
ReportError(NULL, VIR_ERR_INTERNAL_ERROR, macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
"%s", _("malformed netlink response message")); _("malformed netlink response message"));
VIR_FREE(recvbuf); VIR_FREE(recvbuf);
return -1; return -1;
buffer_too_small: buffer_too_small:
ReportError(NULL, VIR_ERR_INTERNAL_ERROR, macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
"%s", _("internal buffer is too small")); _("internal buffer is too small"));
return -1; return -1;
} }
/* Open the macvtap's tap device. /* Open the macvtap's tap device.
* @conn: Pointer to virConnect object * @ifname: Name of the macvtap interface
* @name: Name of the macvtap interface
* @retries : Number of retries in case udev for example may need to be * @retries : Number of retries in case udev for example may need to be
* waited for to create the tap chardev * waited for to create the tap chardev
* Returns negative value in case of error, the file descriptor otherwise. * Returns negative value in case of error, the file descriptor otherwise.
...@@ -677,7 +675,6 @@ configMacvtapTap(int tapfd, int vnet_hdr) ...@@ -677,7 +675,6 @@ configMacvtapTap(int tapfd, int vnet_hdr)
* openMacvtapTap: * openMacvtapTap:
* Create an instance of a macvtap device and open its tap character * Create an instance of a macvtap device and open its tap character
* device. * device.
* @conn: Pointer to virConnect object
* @tgifname: Interface name that the macvtap is supposed to have. May * @tgifname: Interface name that the macvtap is supposed to have. May
* be NULL if this function is supposed to choose a name * be NULL if this function is supposed to choose a name
* @macaddress: The MAC address for the macvtap device * @macaddress: The MAC address for the macvtap device
...@@ -689,13 +686,11 @@ configMacvtapTap(int tapfd, int vnet_hdr) ...@@ -689,13 +686,11 @@ configMacvtapTap(int tapfd, int vnet_hdr)
* to the caller to free the string. * to the caller to free the string.
* *
* Returns file descriptor of the tap device in case of success, * Returns file descriptor of the tap device in case of success,
* negative value otherwise with error message attached to the 'conn' * negative value otherwise with error reported.
* object.
* *
*/ */
int int
openMacvtapTap(virConnectPtr conn, openMacvtapTap(const char *tgifname,
const char *tgifname,
const unsigned char *macaddress, const unsigned char *macaddress,
const char *linkdev, const char *linkdev,
int mode, int mode,
...@@ -713,7 +708,7 @@ openMacvtapTap(virConnectPtr conn, ...@@ -713,7 +708,7 @@ openMacvtapTap(virConnectPtr conn,
*res_ifname = NULL; *res_ifname = NULL;
if (tgifname) { if (tgifname) {
if(getIfIndex(NULL, tgifname, &ifindex) == 0) { if(getIfIndex(false, tgifname, &ifindex) == 0) {
if (STRPREFIX(tgifname, if (STRPREFIX(tgifname,
MACVTAP_NAME_PREFIX)) { MACVTAP_NAME_PREFIX)) {
goto create_name; goto create_name;
...@@ -723,7 +718,7 @@ openMacvtapTap(virConnectPtr conn, ...@@ -723,7 +718,7 @@ openMacvtapTap(virConnectPtr conn,
return -1; return -1;
} }
cr_ifname = tgifname; cr_ifname = tgifname;
rc = link_add(conn, type, macaddress, 6, tgifname, linkdev, rc = link_add(type, macaddress, 6, tgifname, linkdev,
macvtapMode, &do_retry); macvtapMode, &do_retry);
if (rc) if (rc)
return -1; return -1;
...@@ -732,8 +727,8 @@ create_name: ...@@ -732,8 +727,8 @@ create_name:
retries = 5; retries = 5;
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 (getIfIndex(NULL, ifname, &ifindex) == ENODEV) { if (getIfIndex(false, ifname, &ifindex) == ENODEV) {
rc = link_add(conn, type, macaddress, 6, ifname, linkdev, rc = link_add(type, macaddress, 6, ifname, linkdev,
macvtapMode, &do_retry); macvtapMode, &do_retry);
if (rc == 0) if (rc == 0)
break; break;
......
...@@ -28,8 +28,7 @@ ...@@ -28,8 +28,7 @@
# include "internal.h" # include "internal.h"
int openMacvtapTap(virConnectPtr conn, int openMacvtapTap(const char *ifname,
const char *ifname,
const unsigned char *macaddress, const unsigned char *macaddress,
const char *linkdev, const char *linkdev,
int mode, int mode,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册