Message ID | 1350666502-11224-2-git-send-email-stefanha@redhat.com |
---|---|
State | New |
Headers | show |
Stefan Hajnoczi <stefanha@redhat.com> writes: > From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> > > The NetClientInfo .poll() callback is being called directly by > hw/vhost_net.c. Create a public net.c function so callers do not > depend on internals. > > This change is useful because later patches change net internals. Those > changes shouldn't affect .poll() callers. > > Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> > --- > hw/vhost_net.c | 6 +++--- > net.c | 7 +++++++ > net.h | 2 ++ > 3 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/hw/vhost_net.c b/hw/vhost_net.c > index df2c4a3..6737600 100644 > --- a/hw/vhost_net.c > +++ b/hw/vhost_net.c > @@ -160,7 +160,7 @@ int vhost_net_start(struct vhost_net *net, > goto fail_start; > } > > - net->nc->info->poll(net->nc, false); > + qemu_net_poll(net->nc, false); Unconditional call of info->poll() is safe, because we know the backend is tap (see vhost_net_get_fd()), and tap implements poll. > qemu_set_fd_handler(net->backend, NULL, NULL, NULL); > file.fd = net->backend; > for (file.index = 0; file.index < net->dev.nvqs; ++file.index) { > @@ -177,7 +177,7 @@ fail: > int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file); > assert(r >= 0); > } > - net->nc->info->poll(net->nc, true); > + qemu_net_poll(net->nc, true); > vhost_dev_stop(&net->dev, dev); > if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) { > tap_set_vnet_hdr_len(net->nc, sizeof(struct virtio_net_hdr)); > @@ -197,7 +197,7 @@ void vhost_net_stop(struct vhost_net *net, > int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file); > assert(r >= 0); > } > - net->nc->info->poll(net->nc, true); > + qemu_net_poll(net->nc, true); > vhost_dev_stop(&net->dev, dev); > if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) { > tap_set_vnet_hdr_len(net->nc, sizeof(struct virtio_net_hdr)); > diff --git a/net.c b/net.c > index ae4bc0d..eb4f4bf 100644 > --- a/net.c > +++ b/net.c > @@ -466,6 +466,13 @@ qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, int iovcnt) > return qemu_sendv_packet_async(nc, iov, iovcnt, NULL); > } > > +void qemu_net_poll(NetClientState *nc, bool enable) > +{ > + if (nc->info->poll) { > + nc->info->poll(nc, enable); > + } > +} > + Here, we don't have such context, so we check, defensively. poll()'s semantics aren't documented, so I can't say whether "do nothing" is appropriate for backends that don't implement it. > NetClientState *qemu_find_netdev(const char *id) > { > NetClientState *nc; > diff --git a/net.h b/net.h > index 04fda1d..763f926 100644 > --- a/net.h > +++ b/net.h > @@ -111,6 +111,8 @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender, > int iovcnt, > void *opaque); > > +void qemu_net_poll(NetClientState *nc, bool enable); > + > void print_net_client(Monitor *mon, NetClientState *nc); > void do_info_network(Monitor *mon);
diff --git a/hw/vhost_net.c b/hw/vhost_net.c index df2c4a3..6737600 100644 --- a/hw/vhost_net.c +++ b/hw/vhost_net.c @@ -160,7 +160,7 @@ int vhost_net_start(struct vhost_net *net, goto fail_start; } - net->nc->info->poll(net->nc, false); + qemu_net_poll(net->nc, false); qemu_set_fd_handler(net->backend, NULL, NULL, NULL); file.fd = net->backend; for (file.index = 0; file.index < net->dev.nvqs; ++file.index) { @@ -177,7 +177,7 @@ fail: int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file); assert(r >= 0); } - net->nc->info->poll(net->nc, true); + qemu_net_poll(net->nc, true); vhost_dev_stop(&net->dev, dev); if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) { tap_set_vnet_hdr_len(net->nc, sizeof(struct virtio_net_hdr)); @@ -197,7 +197,7 @@ void vhost_net_stop(struct vhost_net *net, int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file); assert(r >= 0); } - net->nc->info->poll(net->nc, true); + qemu_net_poll(net->nc, true); vhost_dev_stop(&net->dev, dev); if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) { tap_set_vnet_hdr_len(net->nc, sizeof(struct virtio_net_hdr)); diff --git a/net.c b/net.c index ae4bc0d..eb4f4bf 100644 --- a/net.c +++ b/net.c @@ -466,6 +466,13 @@ qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, int iovcnt) return qemu_sendv_packet_async(nc, iov, iovcnt, NULL); } +void qemu_net_poll(NetClientState *nc, bool enable) +{ + if (nc->info->poll) { + nc->info->poll(nc, enable); + } +} + NetClientState *qemu_find_netdev(const char *id) { NetClientState *nc; diff --git a/net.h b/net.h index 04fda1d..763f926 100644 --- a/net.h +++ b/net.h @@ -111,6 +111,8 @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender, int iovcnt, void *opaque); +void qemu_net_poll(NetClientState *nc, bool enable); + void print_net_client(Monitor *mon, NetClientState *nc); void do_info_network(Monitor *mon);