Split the function into separate net_tap_new() and net_tap_set_fd().
We start move to the following picture:
net_tap_new() - take QAPI @tap parameter, but don't have @fd,
initialize the net client, called during initialization.
net_tap_setup() - don't have @tap (QAPI), but have @fd parameter,
may be called at later point.
In this commit we introduce the first function.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
net/tap.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index eabfc0b8d8..3050fdea2e 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -386,19 +386,19 @@ static NetClientInfo net_tap_info = {
.get_vhost_net = tap_get_vhost_net,
};
-static TAPState *net_tap_fd_init(NetClientState *peer,
- const char *model,
- const char *name,
- int fd,
- int vnet_hdr)
+static TAPState *net_tap_new(NetClientState *peer, const char *model,
+ const char *name)
{
- NetClientState *nc;
- TAPState *s;
+ NetClientState *nc = qemu_new_net_client(&net_tap_info, peer, model, name);
+ TAPState *s = DO_UPCAST(TAPState, nc, nc);
- nc = qemu_new_net_client(&net_tap_info, peer, model, name);
+ s->fd = -1;
- s = DO_UPCAST(TAPState, nc, nc);
+ return s;
+}
+static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr)
+{
s->fd = fd;
s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
s->using_vnet_hdr = false;
@@ -415,8 +415,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
}
tap_read_poll(s, true);
s->vhost_net = NULL;
-
- return s;
}
static void close_all_fds_after_fork(int excluded_fd)
@@ -634,7 +632,9 @@ int net_init_bridge(const Netdev *netdev, const char *name,
close(fd);
return -1;
}
- s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr);
+
+ s = net_tap_new(peer, "bridge", name);
+ net_tap_set_fd(s, fd, vnet_hdr);
qemu_set_info_str(&s->nc, "helper=%s,br=%s", helper, br);
@@ -677,9 +677,11 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
int vnet_hdr, int fd, Error **errp)
{
Error *err = NULL;
- TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
+ TAPState *s = net_tap_new(peer, model, name);
int vhostfd;
+ net_tap_set_fd(s, fd, vnet_hdr);
+
tap_set_sndbuf(s->fd, tap, &err);
if (err) {
error_propagate(errp, err);
--
2.48.1