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

macvtap: Remove virConnectPtr from ReportError

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