In future (to support backend-transfer migration for virtio-net/tap, which includes fds passing through unix socket) we'll want to postpone fd-initialization to the later point, when QAPI structured parameters are not available. So, let's now rework the function to interface without "tap" parameter.
Also, rename to net_tap_open(), as it's just a wrapper on tap_open(), and having net_tap_init() and net_init_tap() functions in one file is confusing. Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Maksim Davydov <[email protected]> --- net/tap.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/net/tap.c b/net/tap.c index 3bd81883fd..05f7480334 100644 --- a/net/tap.c +++ b/net/tap.c @@ -668,20 +668,12 @@ int net_init_bridge(const Netdev *netdev, const char *name, return 0; } -static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, +static int net_tap_open(int *vnet_hdr, bool vnet_hdr_required, const char *setup_script, char *ifname, size_t ifname_sz, int mq_required, Error **errp) { Error *err = NULL; - int fd, vnet_hdr_required; - - if (tap->has_vnet_hdr) { - *vnet_hdr = tap->vnet_hdr; - vnet_hdr_required = *vnet_hdr; - } else { - *vnet_hdr = 1; - vnet_hdr_required = 0; - } + int fd; fd = RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required, mq_required, errp)); @@ -989,6 +981,7 @@ free_fail: tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT); g_autofree char *downscript = tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT); + bool vnet_hdr_required = tap->has_vnet_hdr && tap->vnet_hdr; if (tap->vhostfds) { error_setg(errp, "vhostfds= is invalid if fds= wasn't specified"); @@ -1002,7 +995,9 @@ free_fail: } for (i = 0; i < queues; i++) { - fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? NULL : script, + vnet_hdr = tap->has_vnet_hdr ? tap->vnet_hdr : 1; + fd = net_tap_open(&vnet_hdr, vnet_hdr_required, + i >= 1 ? NULL : script, ifname, sizeof ifname, queues > 1, errp); if (fd == -1) { return -1; -- 2.48.1
