This makes more obvious, where the variables make sense.
Note that ifname, script and downscript variables are not used in
net_init_tap_one() for fd/fds/helper cases.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Tested-by: Lei Yang <leiyang@redhat.com>
---
net/tap.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index 8e6a276e4b..a1a315a9f0 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -790,19 +790,11 @@ static int get_fds(char *str, char *fds[], int max)
int net_init_tap(const Netdev *netdev, const char *name,
NetClientState *peer, Error **errp)
{
- const NetdevTapOptions *tap;
- int fd, vnet_hdr = 0, i = 0, queues;
- /* for the no-fd, no-helper case */
- const char *script;
- const char *downscript;
- char ifname[128];
+ const NetdevTapOptions *tap = &netdev->u.tap;
+ int fd, vnet_hdr = 0, i = 0;
int ret = 0;
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
- tap = &netdev->u.tap;
- queues = tap->has_queues ? tap->queues : 1;
- 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. */
@@ -848,7 +840,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
}
ret = net_init_tap_one(tap, peer, "tap", name, NULL,
- script, downscript,
+ NULL, NULL,
tap->vhostfd, vnet_hdr, fd, errp);
if (ret < 0) {
return -1;
@@ -902,8 +894,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
goto free_fail;
}
- ret = net_init_tap_one(tap, peer, "tap", name, ifname,
- script, downscript,
+ ret = net_init_tap_one(tap, peer, "tap", name, NULL,
+ NULL, NULL,
tap->vhostfds ? vhost_fds[i] : NULL,
vnet_hdr, fd, errp);
if (ret < 0) {
@@ -944,16 +936,21 @@ free_fail:
return -1;
}
- ret = net_init_tap_one(tap, peer, "bridge", name, ifname,
- script, downscript, tap->vhostfd,
+ ret = net_init_tap_one(tap, peer, "bridge", name, NULL,
+ NULL, NULL, tap->vhostfd,
vnet_hdr, fd, errp);
if (ret < 0) {
close(fd);
return -1;
}
} else {
+ const char *script = tap->script;
+ const char *downscript = tap->downscript;
+ int queues = tap->has_queues ? tap->queues : 1;
g_autofree char *default_script = NULL;
g_autofree char *default_downscript = NULL;
+ char ifname[128];
+
if (tap->vhostfds) {
error_setg(errp, "vhostfds= is invalid if fds= wasn't specified");
return -1;
--
2.48.1