提交 d36897c7 编写于 作者: M Michal Privoznik

virNetDevMacVLanTapOpen: Rework to support multiple FDs

For the multiqueue on macvtaps we are going to need to open
the device multiple times. Currently, this is not supported.
Rework the function, so that upper layers can be reworked too.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 025a8706
...@@ -226,20 +226,26 @@ int virNetDevMacVLanDelete(const char *ifname) ...@@ -226,20 +226,26 @@ int virNetDevMacVLanDelete(const char *ifname)
/** /**
* virNetDevMacVLanTapOpen: * virNetDevMacVLanTapOpen:
* Open the macvtap's tap device.
* @ifname: Name of the macvtap interface * @ifname: Name of the macvtap interface
* @tapfd: array of file descriptor return value for the new macvtap device
* @tapfdSize: number of file descriptors in @tapfd
* @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. *
* Open the macvtap's tap device, possibly multiple times if @tapfdSize > 1.
*
* Returns 0 on success, -1 otherwise.
*/ */
static static int
int virNetDevMacVLanTapOpen(const char *ifname, virNetDevMacVLanTapOpen(const char *ifname,
int retries) int *tapfd,
size_t tapfdSize,
int retries)
{ {
int ret = -1; int ret = -1;
int ifindex; int ifindex;
char *tapname = NULL; char *tapname = NULL;
int tapfd; size_t i = 0;
if (virNetDevGetIndex(ifname, &ifindex) < 0) if (virNetDevGetIndex(ifname, &ifindex) < 0)
return -1; return -1;
...@@ -247,25 +253,32 @@ int virNetDevMacVLanTapOpen(const char *ifname, ...@@ -247,25 +253,32 @@ int virNetDevMacVLanTapOpen(const char *ifname,
if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0) if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
goto cleanup; goto cleanup;
while (1) { for (i = 0; i < tapfdSize; i++) {
/* may need to wait for udev to be done */ int fd = -1;
tapfd = open(tapname, O_RDWR);
if (tapfd < 0 && retries > 0) { while (fd < 0) {
retries--; if ((fd = open(tapname, O_RDWR)) >= 0) {
usleep(20000); tapfd[i] = fd;
continue; } else if (retries-- > 0) {
/* may need to wait for udev to be done */
usleep(20000);
} else {
/* However, if haven't succeeded, quit. */
virReportSystemError(errno,
_("cannot open macvtap tap device %s"),
tapname);
goto cleanup;
}
} }
break;
} }
if (tapfd < 0) { ret = 0;
virReportSystemError(errno,
_("cannot open macvtap tap device %s"),
tapname);
goto cleanup;
}
ret = tapfd;
cleanup: cleanup:
if (ret < 0) {
while (i--)
VIR_FORCE_CLOSE(tapfd[i]);
}
VIR_FREE(tapname); VIR_FREE(tapname);
return ret; return ret;
} }
...@@ -832,7 +845,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname, ...@@ -832,7 +845,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
} }
if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) { if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) {
if ((rc = virNetDevMacVLanTapOpen(cr_ifname, 10)) < 0) if (virNetDevMacVLanTapOpen(cr_ifname, &rc, 1, 10) < 0)
goto disassociate_exit; goto disassociate_exit;
if (virNetDevMacVLanTapSetup(rc, vnet_hdr) < 0) { if (virNetDevMacVLanTapSetup(rc, vnet_hdr) < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册