From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Laszlo Ersek <lersek@redhat.com>,
qemu-devel@nongnu.org,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 2/4] net: add net_is_tap_client()
Date: Thu, 18 Oct 2012 17:05:51 +0200 [thread overview]
Message-ID: <50801ACF.50203@redhat.com> (raw)
In-Reply-To: <1350572215-2231-3-git-send-email-stefanha@redhat.com>
Il 18/10/2012 16:56, Stefan Hajnoczi ha scritto:
> From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> The vhost-net code interacts closely with the net/tap.c backend so that
> it can pass the underlying file descriptor to the vhost_net.ko driver.
> We need a check that confirms a NetClientState is indeed a tap backend
> (and not something else like slirp or socket).
Could you use object_dynamic_cast(OBJECT(backend), TYPE_TAP_NET_CLIENT)
instead?
Paolo
> Formalize this in the new net_is_tap_client() function. This way
> callers do not reach inside net internals to check the type.
>
> Note that I've added this function to net/tap.c but named it
> net_is_tap_client(). Ideally it should be in net.c but I want to keep
> the code where the tap net client is defined.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
> hw/vhost_net.c | 5 ++---
> hw/virtio-net.c | 9 +++++----
> net/tap.c | 5 +++++
> net/tap.h | 1 +
> 4 files changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/hw/vhost_net.c b/hw/vhost_net.c
> index 6737600..d60da6a 100644
> --- a/hw/vhost_net.c
> +++ b/hw/vhost_net.c
> @@ -82,10 +82,9 @@ void vhost_net_ack_features(struct vhost_net *net, unsigned features)
>
> static int vhost_net_get_fd(NetClientState *backend)
> {
> - switch (backend->info->type) {
> - case NET_CLIENT_OPTIONS_KIND_TAP:
> + if (net_is_tap_client(backend)) {
> return tap_get_fd(backend);
> - default:
> + } else {
> fprintf(stderr, "vhost-net requires tap backend\n");
> return -EBADFD;
> }
> diff --git a/hw/virtio-net.c b/hw/virtio-net.c
> index 8342391..6668ff2 100644
> --- a/hw/virtio-net.c
> +++ b/hw/virtio-net.c
> @@ -108,7 +108,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
> if (!n->nic->nc.peer) {
> return;
> }
> - if (n->nic->nc.peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
> + if (!net_is_tap_client(n->nic->nc.peer)) {
> return;
> }
>
> @@ -205,8 +205,9 @@ static int peer_has_vnet_hdr(VirtIONet *n)
> if (!n->nic->nc.peer)
> return 0;
>
> - if (n->nic->nc.peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP)
> + if (!net_is_tap_client(n->nic->nc.peer)) {
> return 0;
> + }
>
> n->has_vnet_hdr = tap_has_vnet_hdr(n->nic->nc.peer);
>
> @@ -249,7 +250,7 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)
> }
>
> if (!n->nic->nc.peer ||
> - n->nic->nc.peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
> + !net_is_tap_client(n->nic->nc.peer)) {
> return features;
> }
> if (!tap_get_vhost_net(n->nic->nc.peer)) {
> @@ -288,7 +289,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
> (features >> VIRTIO_NET_F_GUEST_UFO) & 1);
> }
> if (!n->nic->nc.peer ||
> - n->nic->nc.peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
> + !net_is_tap_client(n->nic->nc.peer)) {
> return;
> }
> if (!tap_get_vhost_net(n->nic->nc.peer)) {
> diff --git a/net/tap.c b/net/tap.c
> index df89caa..22f8de7 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -304,6 +304,11 @@ static void tap_poll(NetClientState *nc, bool enable)
> tap_write_poll(s, enable);
> }
>
> +bool net_is_tap_client(NetClientState *nc)
> +{
> + return nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP;
> +}
> +
> int tap_get_fd(NetClientState *nc)
> {
> TAPState *s = DO_UPCAST(TAPState, nc, nc);
> diff --git a/net/tap.h b/net/tap.h
> index d44d83a..4a9431b 100644
> --- a/net/tap.h
> +++ b/net/tap.h
> @@ -50,6 +50,7 @@ int tap_probe_has_ufo(int fd);
> void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo);
> void tap_fd_set_vnet_hdr_len(int fd, int len);
>
> +bool net_is_tap_client(NetClientState *nc);
> int tap_get_fd(NetClientState *nc);
>
> struct vhost_net;
>
next prev parent reply other threads:[~2012-10-18 15:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-18 14:56 [Qemu-devel] [PATCH 0/4] net: convert NetClientState to QOM Stefan Hajnoczi
2012-10-18 14:56 ` [Qemu-devel] [PATCH 1/4] net: add public qemu_net_poll() function Stefan Hajnoczi
2012-10-18 14:56 ` [Qemu-devel] [PATCH 2/4] net: add net_is_tap_client() Stefan Hajnoczi
2012-10-18 15:05 ` Paolo Bonzini [this message]
2012-10-18 15:48 ` Stefan Hajnoczi
2012-10-18 14:56 ` [Qemu-devel] [PATCH 3/4] net: extract notify_link_status_changed() function Stefan Hajnoczi
2012-10-18 14:56 ` [Qemu-devel] [PATCH 4/4] net: convert NetClientState to QOM Stefan Hajnoczi
2012-10-18 15:06 ` Paolo Bonzini
2012-10-19 7:38 ` Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2012-07-02 10:56 [Qemu-devel] [PATCH 0/4] " Stefan Hajnoczi
2012-07-02 10:56 ` [Qemu-devel] [PATCH 2/4] net: add net_is_tap_client() Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50801ACF.50203@redhat.com \
--to=pbonzini@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=lersek@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.