From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SleJc-0008OJ-BA for qemu-devel@nongnu.org; Mon, 02 Jul 2012 06:57:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SleJa-0000YP-7Q for qemu-devel@nongnu.org; Mon, 02 Jul 2012 06:57:11 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:49893) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SleJZ-0000Y4-Un for qemu-devel@nongnu.org; Mon, 02 Jul 2012 06:57:10 -0400 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Jul 2012 11:57:05 +0100 Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q62AuvuG2424972 for ; Mon, 2 Jul 2012 11:56:57 +0100 Received: from d06av03.portsmouth.uk.ibm.com (localhost.localdomain [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q62Auvog028006 for ; Mon, 2 Jul 2012 04:56:57 -0600 From: Stefan Hajnoczi Date: Mon, 2 Jul 2012 11:56:51 +0100 Message-Id: <1341226613-15577-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1341226613-15577-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1341226613-15577-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/4] net: add net_is_tap_client() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Anthony Liguori , lersek@redhat.com, Stefan Hajnoczi 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). 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 --- 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 ac3e616..47710ee 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_TYPE_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 d5527d4..1575879 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_TYPE_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_TYPE_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_TYPE_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_TYPE_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 20ce3ff..d5bdfa0 100644 --- a/net/tap.c +++ b/net/tap.c @@ -303,6 +303,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_TYPE_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 2966d81..9a341bf 100644 --- a/net/tap.h +++ b/net/tap.h @@ -52,6 +52,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; -- 1.7.10