First, follow common recommendations to avoid error propagation:
add return value to tap_set_sndbuf().
Second, 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>
---
net/tap-bsd.c | 3 ++-
net/tap-linux.c | 19 +++++--------------
net/tap-solaris.c | 3 ++-
net/tap-stub.c | 3 ++-
net/tap.c | 9 +++++----
net/tap_int.h | 4 +---
6 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index b4c84441ba..3bfc1cc577 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -198,8 +198,9 @@ error:
}
#endif /* __FreeBSD__ */
-void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
+bool tap_set_sndbuf(int fd, int sndbuf, Error **errp)
{
+ return true;
}
int tap_probe_vnet_hdr(int fd, Error **errp)
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 22ec2f45d2..c46f488c08 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -138,23 +138,14 @@ 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
-
-void 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;
}
+
+ return true;
}
int tap_probe_vnet_hdr(int fd, Error **errp)
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 51b7830bef..2932c2de39 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -202,8 +202,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
return fd;
}
-void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
+bool tap_set_sndbuf(int fd, int sndbuf, Error **errp)
{
+ return true;
}
int tap_probe_vnet_hdr(int fd, Error **errp)
diff --git a/net/tap-stub.c b/net/tap-stub.c
index 38673434cb..326e76843e 100644
--- a/net/tap-stub.c
+++ b/net/tap-stub.c
@@ -33,8 +33,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
return -1;
}
-void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
+bool tap_set_sndbuf(int fd, int sndbuf, Error **errp)
{
+ return true;
}
int tap_probe_vnet_hdr(int fd, Error **errp)
diff --git a/net/tap.c b/net/tap.c
index 3050fdea2e..5cb639a71d 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -676,15 +676,16 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
const char *downscript, const char *vhostfdname,
int vnet_hdr, int fd, Error **errp)
{
- Error *err = NULL;
TAPState *s = net_tap_new(peer, model, name);
int vhostfd;
+ bool sndbuf_required = tap->has_sndbuf;
+ int sndbuf =
+ (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT_MAX;
net_tap_set_fd(s, fd, vnet_hdr);
- tap_set_sndbuf(s->fd, tap, &err);
- if (err) {
- error_propagate(errp, err);
+ if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) &&
+ sndbuf_required) {
goto failed;
}
diff --git a/net/tap_int.h b/net/tap_int.h
index 8857ff299d..08e4a592a0 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -26,14 +26,12 @@
#ifndef NET_TAP_INT_H
#define NET_TAP_INT_H
-#include "qapi/qapi-types-net.h"
-
int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
int vnet_hdr_required, int mq_required, Error **errp);
ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen);
-void 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);
--
2.48.1