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]> Tested-by: Lei Yang <[email protected]> Reviewed-by: Maksim Davydov <[email protected]> --- net/tap.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/tap.c b/net/tap.c index f90050c3a0..b1b64c508d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -655,20 +655,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)); @@ -977,6 +969,8 @@ free_fail: } else { g_autofree char *default_script = NULL; g_autofree char *default_downscript = NULL; + 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"); return -1; @@ -997,7 +991,9 @@ free_fail: } for (i = 0; i < queues; i++) { - fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script, + vnet_hdr = tap->has_vnet_hdr ? tap->vnet_hdr : 1; + fd = net_tap_open(&vnet_hdr, vnet_hdr_required, + i >= 1 ? "no" : script, ifname, sizeof ifname, queues > 1, errp); if (fd == -1) { return -1; -- 2.48.1
