* [PATCH v9 0/7] net/tap: simple refactoring
@ 2025-10-30 16:40 Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 1/7] net/tap: net_init_tap_one(): drop extra error propagation Vladimir Sementsov-Ogievskiy
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
Hi all!
These are some refactoring patches, extracted from
[PATCH v8 00/19] virtio-net: live-TAP local migration
These patches are good in general, even not considered as
preparation to the feature. I hope, they may be queued
in advance, to simplify further work on the rest of
the series.
The (reworked) rest of the series is coming soon and will
be based on this one.
v9: Mostly unchanged, so keep r-bs. Still, drop t-bs, as there
were still some conflicts due to commits reordering.
Vladimir Sementsov-Ogievskiy (7):
net/tap: net_init_tap_one(): drop extra error propagation
net/tap: net_init_tap_one(): move parameter checking earlier
net/tap: pass NULL to net_init_tap_one() in cases when scripts are
NULL
net/tap: rework scripts handling
net/tap: setup exit notifier only when needed
net/tap: tap_set_sndbuf(): add return value
net/tap: rework tap_set_sndbuf()
net/tap-bsd.c | 3 +-
net/tap-linux.c | 19 +++-------
net/tap-solaris.c | 3 +-
net/tap-stub.c | 3 +-
net/tap.c | 94 +++++++++++++++++++++++++----------------------
net/tap_int.h | 3 +-
6 files changed, 62 insertions(+), 63 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v9 1/7] net/tap: net_init_tap_one(): drop extra error propagation
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
@ 2025-10-30 16:40 ` Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 2/7] net/tap: net_init_tap_one(): move parameter checking earlier Vladimir Sementsov-Ogievskiy
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
---
net/tap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index abe3b2d036..70de798fe8 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -736,9 +736,8 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
}
if (vhostfdname) {
- vhostfd = monitor_fd_param(monitor_cur(), vhostfdname, &err);
+ vhostfd = monitor_fd_param(monitor_cur(), vhostfdname, errp);
if (vhostfd == -1) {
- error_propagate(errp, err);
goto failed;
}
if (!qemu_set_blocking(vhostfd, false, errp)) {
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v9 2/7] net/tap: net_init_tap_one(): move parameter checking earlier
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 1/7] net/tap: net_init_tap_one(): drop extra error propagation Vladimir Sementsov-Ogievskiy
@ 2025-10-30 16:40 ` Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 3/7] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL Vladimir Sementsov-Ogievskiy
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
Let's keep all similar argument checking in net_init_tap() function.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
---
net/tap.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index 70de798fe8..f90050c3a0 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -768,9 +768,6 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
"vhost-net requested but could not be initialized");
goto failed;
}
- } else if (vhostfdname) {
- error_setg(errp, "vhostfd(s)= is not valid without vhost");
- goto failed;
}
return;
@@ -832,6 +829,11 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}
+ if (tap->has_vhost && !tap->vhost && (tap->vhostfds || tap->vhostfd)) {
+ error_setg(errp, "vhostfd(s)= is not valid without vhost");
+ return -1;
+ }
+
if (tap->fd) {
if (tap->ifname || tap->script || tap->downscript ||
tap->has_vnet_hdr || tap->helper || tap->has_queues ||
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v9 3/7] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 1/7] net/tap: net_init_tap_one(): drop extra error propagation Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 2/7] net/tap: net_init_tap_one(): move parameter checking earlier Vladimir Sementsov-Ogievskiy
@ 2025-10-30 16:40 ` Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 4/7] net/tap: rework scripts handling Vladimir Sementsov-Ogievskiy
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
Directly pass NULL in cases where we report an error if script or
downscript are set.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
---
net/tap.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index f90050c3a0..5c6b9399e0 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -808,8 +808,6 @@ int net_init_tap(const Netdev *netdev, const char *name,
const NetdevTapOptions *tap;
int fd, vnet_hdr = 0, i = 0, queues;
/* for the no-fd, no-helper case */
- const char *script;
- const char *downscript;
Error *err = NULL;
const char *vhostfdname;
char ifname[128];
@@ -819,8 +817,6 @@ int net_init_tap(const Netdev *netdev, const char *name,
tap = &netdev->u.tap;
queues = tap->has_queues ? tap->queues : 1;
vhostfdname = tap->vhostfd;
- script = tap->script;
- downscript = tap->downscript;
/* QEMU hubs do not support multiqueue tap, in this case peer is set.
* For -netdev, peer is always NULL. */
@@ -861,7 +857,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
}
net_init_tap_one(tap, peer, "tap", name, NULL,
- script, downscript,
+ NULL, NULL,
vhostfdname, vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
@@ -922,7 +918,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
}
net_init_tap_one(tap, peer, "tap", name, ifname,
- script, downscript,
+ NULL, NULL,
tap->vhostfds ? vhost_fds[i] : NULL,
vnet_hdr, fd, &err);
if (err) {
@@ -967,7 +963,7 @@ free_fail:
}
net_init_tap_one(tap, peer, "bridge", name, ifname,
- script, downscript, vhostfdname,
+ NULL, NULL, vhostfdname,
vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
@@ -975,6 +971,8 @@ free_fail:
return -1;
}
} else {
+ const char *script = tap->script;
+ const char *downscript = tap->downscript;
g_autofree char *default_script = NULL;
g_autofree char *default_downscript = NULL;
if (tap->vhostfds) {
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v9 4/7] net/tap: rework scripts handling
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
` (2 preceding siblings ...)
2025-10-30 16:40 ` [PATCH v9 3/7] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL Vladimir Sementsov-Ogievskiy
@ 2025-10-30 16:40 ` Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 5/7] net/tap: setup exit notifier only when needed Vladimir Sementsov-Ogievskiy
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
Simplify handling scripts: parse all these "no" and '\0' once, and
then keep simpler logic for net_tap_open() and net_init_tap_one(): NULL
means no script to run, otherwise run script.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
---
net/tap.c | 46 ++++++++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index 5c6b9399e0..017c184933 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -91,6 +91,21 @@ static void launch_script(const char *setup_script, const char *ifname,
static void tap_send(void *opaque);
static void tap_writable(void *opaque);
+static char *tap_parse_script(const char *script_arg, const char *default_path)
+{
+ g_autofree char *res = g_strdup(script_arg);
+
+ if (!res) {
+ res = get_relocated_path(default_path);
+ }
+
+ if (res[0] == '\0' || strcmp(res, "no") == 0) {
+ return NULL;
+ }
+
+ return g_steal_pointer(&res);
+}
+
static void tap_update_fd_handler(TAPState *s)
{
qemu_set_fd_handler(s->fd,
@@ -676,9 +691,7 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,
return -1;
}
- if (setup_script &&
- setup_script[0] != '\0' &&
- strcmp(setup_script, "no") != 0) {
+ if (setup_script) {
launch_script(setup_script, ifname, fd, &err);
if (err) {
error_propagate(errp, err);
@@ -714,9 +727,9 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
} else {
qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
- script, downscript);
+ script ?: "no", downscript ?: "no");
- if (strcmp(downscript, "no") != 0) {
+ if (downscript) {
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
snprintf(s->down_script_arg, sizeof(s->down_script_arg),
"%s", ifname);
@@ -971,23 +984,16 @@ free_fail:
return -1;
}
} else {
- const char *script = tap->script;
- const char *downscript = tap->downscript;
- g_autofree char *default_script = NULL;
- g_autofree char *default_downscript = NULL;
+ g_autofree char *script =
+ tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT);
+ g_autofree char *downscript =
+ tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT);
+
if (tap->vhostfds) {
error_setg(errp, "vhostfds= is invalid if fds= wasn't specified");
return -1;
}
- if (!script) {
- script = default_script = get_relocated_path(DEFAULT_NETWORK_SCRIPT);
- }
- if (!downscript) {
- downscript = default_downscript =
- get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIPT);
- }
-
if (tap->ifname) {
pstrcpy(ifname, sizeof ifname, tap->ifname);
} else {
@@ -995,7 +1001,7 @@ free_fail:
}
for (i = 0; i < queues; i++) {
- fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script,
+ fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? NULL : script,
ifname, sizeof ifname, queues > 1, errp);
if (fd == -1) {
return -1;
@@ -1010,8 +1016,8 @@ free_fail:
}
net_init_tap_one(tap, peer, "tap", name, ifname,
- i >= 1 ? "no" : script,
- i >= 1 ? "no" : downscript,
+ i >= 1 ? NULL : script,
+ i >= 1 ? NULL : downscript,
vhostfdname, vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v9 5/7] net/tap: setup exit notifier only when needed
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
` (3 preceding siblings ...)
2025-10-30 16:40 ` [PATCH v9 4/7] net/tap: rework scripts handling Vladimir Sementsov-Ogievskiy
@ 2025-10-30 16:40 ` Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 6/7] net/tap: tap_set_sndbuf(): add return value Vladimir Sementsov-Ogievskiy
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
No reason to setup notifier on each queue of multique tap,
when we actually want to run downscript only once.
As well, let's not setup notifier, when downscript is
not enabled (downsciprt="no").
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
---
net/tap.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index 017c184933..5653578ccb 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -326,11 +326,9 @@ static void tap_exit_notify(Notifier *notifier, void *data)
TAPState *s = container_of(notifier, TAPState, exit);
Error *err = NULL;
- if (s->down_script[0]) {
- launch_script(s->down_script, s->down_script_arg, s->fd, &err);
- if (err) {
- error_report_err(err);
- }
+ launch_script(s->down_script, s->down_script_arg, s->fd, &err);
+ if (err) {
+ error_report_err(err);
}
}
@@ -346,8 +344,11 @@ static void tap_cleanup(NetClientState *nc)
qemu_purge_queued_packets(nc);
- tap_exit_notify(&s->exit, NULL);
- qemu_remove_exit_notifier(&s->exit);
+ if (s->exit.notify) {
+ tap_exit_notify(&s->exit, NULL);
+ qemu_remove_exit_notifier(&s->exit);
+ s->exit.notify = NULL;
+ }
tap_read_poll(s, false);
tap_write_poll(s, false);
@@ -443,9 +444,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
tap_read_poll(s, true);
s->vhost_net = NULL;
- s->exit.notify = tap_exit_notify;
- qemu_add_exit_notifier(&s->exit);
-
return s;
}
@@ -733,6 +731,8 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
snprintf(s->down_script_arg, sizeof(s->down_script_arg),
"%s", ifname);
+ s->exit.notify = tap_exit_notify;
+ qemu_add_exit_notifier(&s->exit);
}
}
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v9 6/7] net/tap: tap_set_sndbuf(): add return value
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
` (4 preceding siblings ...)
2025-10-30 16:40 ` [PATCH v9 5/7] net/tap: setup exit notifier only when needed Vladimir Sementsov-Ogievskiy
@ 2025-10-30 16:40 ` Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 7/7] net/tap: rework tap_set_sndbuf() Vladimir Sementsov-Ogievskiy
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
Follow common recommendations in include/qapi/error.h of having
a return value together with errp. This allows to avoid error propagation.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
---
net/tap-bsd.c | 3 ++-
net/tap-linux.c | 5 ++++-
net/tap-solaris.c | 3 ++-
net/tap-stub.c | 3 ++-
net/tap.c | 5 +----
net/tap_int.h | 2 +-
6 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index bbf84d1828..9bd282b69c 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -206,8 +206,9 @@ error:
}
#endif /* __FreeBSD__ */
-void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
+bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, 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 2a90b58467..db68693bbf 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -145,7 +145,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
*/
#define TAP_DEFAULT_SNDBUF 0
-void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
+bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
{
int sndbuf;
@@ -159,7 +159,10 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
if (ioctl(fd, TUNSETSNDBUF, &sndbuf) == -1 && tap->has_sndbuf) {
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 75397e6c54..e5ba89d926 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -208,8 +208,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, const NetdevTapOptions *tap, 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 f7a5e0c163..86d7d38e0f 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, const NetdevTapOptions *tap, Error **errp)
{
+ return true;
}
int tap_probe_vnet_hdr(int fd, Error **errp)
diff --git a/net/tap.c b/net/tap.c
index 5653578ccb..ed20155b11 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -709,13 +709,10 @@ 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_fd_init(peer, model, name, fd, vnet_hdr);
int vhostfd;
- tap_set_sndbuf(s->fd, tap, &err);
- if (err) {
- error_propagate(errp, err);
+ if (!tap_set_sndbuf(s->fd, tap, errp)) {
goto failed;
}
diff --git a/net/tap_int.h b/net/tap_int.h
index b76a05044b..7963dd6aae 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -34,7 +34,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
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, const NetdevTapOptions *tap, 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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v9 7/7] net/tap: rework tap_set_sndbuf()
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
` (5 preceding siblings ...)
2025-10-30 16:40 ` [PATCH v9 6/7] net/tap: tap_set_sndbuf(): add return value Vladimir Sementsov-Ogievskiy
@ 2025-10-30 16:40 ` Vladimir Sementsov-Ogievskiy
2025-11-04 16:59 ` [PATCH v9 0/7] net/tap: simple refactoring Lei Yang
2025-12-04 20:04 ` Vladimir Sementsov-Ogievskiy
8 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-10-30 16:40 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, vsementsov, leiyang, davydov-max, yc-core
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>
---
net/tap-bsd.c | 2 +-
net/tap-linux.c | 16 ++--------------
net/tap-solaris.c | 2 +-
net/tap-stub.c | 2 +-
net/tap.c | 6 +++++-
net/tap_int.h | 3 +--
6 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 9bd282b69c..4cea60664e 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -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;
}
diff --git a/net/tap-linux.c b/net/tap-linux.c
index db68693bbf..bb73fa4b13 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -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;
}
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index e5ba89d926..e925ca8ae9 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -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;
}
diff --git a/net/tap-stub.c b/net/tap-stub.c
index 86d7d38e0f..6aa60d96ad 100644
--- a/net/tap-stub.c
+++ b/net/tap-stub.c
@@ -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;
}
diff --git a/net/tap.c b/net/tap.c
index ed20155b11..3bd81883fd 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -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;
}
diff --git a/net/tap_int.h b/net/tap_int.h
index 7963dd6aae..dc4f484006 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -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);
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v9 0/7] net/tap: simple refactoring
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
` (6 preceding siblings ...)
2025-10-30 16:40 ` [PATCH v9 7/7] net/tap: rework tap_set_sndbuf() Vladimir Sementsov-Ogievskiy
@ 2025-11-04 16:59 ` Lei Yang
2025-12-04 20:04 ` Vladimir Sementsov-Ogievskiy
8 siblings, 0 replies; 12+ messages in thread
From: Lei Yang @ 2025-11-04 16:59 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy; +Cc: jasowang, qemu-devel, davydov-max, yc-core
Tested this series of patches with virtio-net regression tests,
everything works fine.
Tested-by: Lei Yang <leiyang@redhat.com>
On Fri, Oct 31, 2025 at 12:40 AM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> Hi all!
>
> These are some refactoring patches, extracted from
>
> [PATCH v8 00/19] virtio-net: live-TAP local migration
>
> These patches are good in general, even not considered as
> preparation to the feature. I hope, they may be queued
> in advance, to simplify further work on the rest of
> the series.
>
> The (reworked) rest of the series is coming soon and will
> be based on this one.
>
> v9: Mostly unchanged, so keep r-bs. Still, drop t-bs, as there
> were still some conflicts due to commits reordering.
>
> Vladimir Sementsov-Ogievskiy (7):
> net/tap: net_init_tap_one(): drop extra error propagation
> net/tap: net_init_tap_one(): move parameter checking earlier
> net/tap: pass NULL to net_init_tap_one() in cases when scripts are
> NULL
> net/tap: rework scripts handling
> net/tap: setup exit notifier only when needed
> net/tap: tap_set_sndbuf(): add return value
> net/tap: rework tap_set_sndbuf()
>
> net/tap-bsd.c | 3 +-
> net/tap-linux.c | 19 +++-------
> net/tap-solaris.c | 3 +-
> net/tap-stub.c | 3 +-
> net/tap.c | 94 +++++++++++++++++++++++++----------------------
> net/tap_int.h | 3 +-
> 6 files changed, 62 insertions(+), 63 deletions(-)
>
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v9 0/7] net/tap: simple refactoring
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
` (7 preceding siblings ...)
2025-11-04 16:59 ` [PATCH v9 0/7] net/tap: simple refactoring Lei Yang
@ 2025-12-04 20:04 ` Vladimir Sementsov-Ogievskiy
2025-12-05 6:19 ` Jason Wang
8 siblings, 1 reply; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-12-04 20:04 UTC (permalink / raw)
To: jasowang; +Cc: qemu-devel, leiyang, davydov-max, yc-core
ping
(now as 11.0 material)
On 30.10.25 19:40, Vladimir Sementsov-Ogievskiy wrote:
> Hi all!
>
> These are some refactoring patches, extracted from
>
> [PATCH v8 00/19] virtio-net: live-TAP local migration
>
> These patches are good in general, even not considered as
> preparation to the feature. I hope, they may be queued
> in advance, to simplify further work on the rest of
> the series.
>
> The (reworked) rest of the series is coming soon and will
> be based on this one.
>
> v9: Mostly unchanged, so keep r-bs. Still, drop t-bs, as there
> were still some conflicts due to commits reordering.
>
> Vladimir Sementsov-Ogievskiy (7):
> net/tap: net_init_tap_one(): drop extra error propagation
> net/tap: net_init_tap_one(): move parameter checking earlier
> net/tap: pass NULL to net_init_tap_one() in cases when scripts are
> NULL
> net/tap: rework scripts handling
> net/tap: setup exit notifier only when needed
> net/tap: tap_set_sndbuf(): add return value
> net/tap: rework tap_set_sndbuf()
>
> net/tap-bsd.c | 3 +-
> net/tap-linux.c | 19 +++-------
> net/tap-solaris.c | 3 +-
> net/tap-stub.c | 3 +-
> net/tap.c | 94 +++++++++++++++++++++++++----------------------
> net/tap_int.h | 3 +-
> 6 files changed, 62 insertions(+), 63 deletions(-)
>
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v9 0/7] net/tap: simple refactoring
2025-12-04 20:04 ` Vladimir Sementsov-Ogievskiy
@ 2025-12-05 6:19 ` Jason Wang
2025-12-05 14:27 ` Vladimir Sementsov-Ogievskiy
0 siblings, 1 reply; 12+ messages in thread
From: Jason Wang @ 2025-12-05 6:19 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy; +Cc: qemu-devel, leiyang, davydov-max, yc-core
On Fri, Dec 5, 2025 at 4:05 AM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> ping
>
> (now as 11.0 material)
>
I've queued this.
Thanks
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v9 0/7] net/tap: simple refactoring
2025-12-05 6:19 ` Jason Wang
@ 2025-12-05 14:27 ` Vladimir Sementsov-Ogievskiy
0 siblings, 0 replies; 12+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2025-12-05 14:27 UTC (permalink / raw)
To: Jason Wang; +Cc: qemu-devel, leiyang, davydov-max, yc-core
On 05.12.25 09:19, Jason Wang wrote:
> On Fri, Dec 5, 2025 at 4:05 AM Vladimir Sementsov-Ogievskiy
> <vsementsov@yandex-team.ru> wrote:
>>
>> ping
>>
>> (now as 11.0 material)
>>
>
> I've queued this.
>
Thanks!
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-12-05 14:27 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 16:40 [PATCH v9 0/7] net/tap: simple refactoring Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 1/7] net/tap: net_init_tap_one(): drop extra error propagation Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 2/7] net/tap: net_init_tap_one(): move parameter checking earlier Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 3/7] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 4/7] net/tap: rework scripts handling Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 5/7] net/tap: setup exit notifier only when needed Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 6/7] net/tap: tap_set_sndbuf(): add return value Vladimir Sementsov-Ogievskiy
2025-10-30 16:40 ` [PATCH v9 7/7] net/tap: rework tap_set_sndbuf() Vladimir Sementsov-Ogievskiy
2025-11-04 16:59 ` [PATCH v9 0/7] net/tap: simple refactoring Lei Yang
2025-12-04 20:04 ` Vladimir Sementsov-Ogievskiy
2025-12-05 6:19 ` Jason Wang
2025-12-05 14:27 ` Vladimir Sementsov-Ogievskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).