mirror of
https://github.com/qemu/qemu.git
synced 2026-02-04 02:24:51 +00:00
net/tap: rework tap_set_sndbuf()
Keep NetdevTapOptions related logic in tap.c, and make tap_set_sndbuf a simple system call wrapper, more like other functions in tap-linux.c Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
committed by
Jason Wang
parent
638a302b1b
commit
3183bd395a
@@ -206,7 +206,7 @@ error:
|
||||
}
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
|
||||
bool tap_set_sndbuf(int fd, int sndbuf, Error **errp)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -143,21 +143,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||
* Ethernet NICs generally have txqueuelen=1000, so 1Mb is
|
||||
* a good value, given a 1500 byte MTU.
|
||||
*/
|
||||
#define TAP_DEFAULT_SNDBUF 0
|
||||
|
||||
bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
|
||||
bool tap_set_sndbuf(int fd, int sndbuf, Error **errp)
|
||||
{
|
||||
int sndbuf;
|
||||
|
||||
sndbuf = !tap->has_sndbuf ? TAP_DEFAULT_SNDBUF :
|
||||
tap->sndbuf > INT_MAX ? INT_MAX :
|
||||
tap->sndbuf;
|
||||
|
||||
if (!sndbuf) {
|
||||
sndbuf = INT_MAX;
|
||||
}
|
||||
|
||||
if (ioctl(fd, TUNSETSNDBUF, &sndbuf) == -1 && tap->has_sndbuf) {
|
||||
if (ioctl(fd, TUNSETSNDBUF, &sndbuf) == -1) {
|
||||
error_setg_errno(errp, errno, "TUNSETSNDBUF ioctl failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||
return fd;
|
||||
}
|
||||
|
||||
bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
|
||||
bool tap_set_sndbuf(int fd, int sndbuf, Error **errp)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
|
||||
bool tap_set_sndbuf(int fd, int sndbuf, Error **errp)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -711,8 +711,12 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
||||
{
|
||||
TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
|
||||
int vhostfd;
|
||||
bool sndbuf_required = tap->has_sndbuf;
|
||||
int sndbuf =
|
||||
(tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT_MAX;
|
||||
|
||||
if (!tap_set_sndbuf(s->fd, tap, errp)) {
|
||||
if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) &&
|
||||
sndbuf_required) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#ifndef NET_TAP_INT_H
|
||||
#define NET_TAP_INT_H
|
||||
|
||||
#include "qapi/qapi-types-net.h"
|
||||
#include "net/net.h"
|
||||
|
||||
int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||
@@ -34,7 +33,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||
|
||||
ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen);
|
||||
|
||||
bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp);
|
||||
bool tap_set_sndbuf(int fd, int sndbuf, Error **errp);
|
||||
int tap_probe_vnet_hdr(int fd, Error **errp);
|
||||
int tap_probe_has_ufo(int fd);
|
||||
int tap_probe_has_uso(int fd);
|
||||
|
||||
Reference in New Issue
Block a user