From: Liu Ping Fan <qemulist@gmail.com>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
mdroth <mdroth@linux.vnet.ibm.com>,
Anthony Liguori <anthony@codemonkey.ws>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [RFC PATCH 2/2] net: port hub onto glib
Date: Wed, 13 Mar 2013 13:59:06 +0800 [thread overview]
Message-ID: <1363154346-14827-3-git-send-email-qemulist@gmail.com> (raw)
In-Reply-To: <1363154346-14827-1-git-send-email-qemulist@gmail.com>
From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
Attach each hubport with a GSource. Currently the GSource is attached
to default main context, and the hub still run on iothread, but in
future, after making the whole layer thread-safe, we will admit ports
to run on different thread(GMainContext).
Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
hw/qdev-properties-system.c | 1 +
include/net/net.h | 7 +++++--
include/net/queue.h | 14 ++++++++++++++
net/hub.c | 34 ++++++++++++++++++++++++++++++++--
net/net.c | 1 +
net/queue.c | 4 ++--
6 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/hw/qdev-properties-system.c b/hw/qdev-properties-system.c
index ce3af22..bb2448d 100644
--- a/hw/qdev-properties-system.c
+++ b/hw/qdev-properties-system.c
@@ -307,6 +307,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
name, prop->info->name);
return;
}
+ hubport->info->bind_ctx(hubport, NULL);
*ptr = hubport;
}
diff --git a/include/net/net.h b/include/net/net.h
index 4f3eed1..3f01711 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -65,10 +65,13 @@ typedef struct NetClientSource {
GSource source;
/* fix me, to expand as array in future */
GPollFD gfd;
- bool last_rd_sts;
- bool last_wr_sts;
+
Pollable readable;
Pollable writeable;
+ /* status returned by pollable last time */
+ bool last_rd_sts;
+ bool last_wr_sts;
+
void *opaque;
} NetClientSource;
diff --git a/include/net/queue.h b/include/net/queue.h
index fc02b33..f60e57f 100644
--- a/include/net/queue.h
+++ b/include/net/queue.h
@@ -38,6 +38,20 @@ NetQueue *qemu_new_net_queue(void *opaque);
void qemu_del_net_queue(NetQueue *queue);
+void qemu_net_queue_append(NetQueue *queue,
+ NetClientState *sender,
+ unsigned flags,
+ const uint8_t *buf,
+ size_t size,
+ NetPacketSent *sent_cb);
+
+void qemu_net_queue_append_iov(NetQueue *queue,
+ NetClientState *sender,
+ unsigned flags,
+ const struct iovec *iov,
+ int iovcnt,
+ NetPacketSent *sent_cb);
+
ssize_t qemu_net_queue_send(NetQueue *queue,
NetClientState *sender,
unsigned flags,
diff --git a/net/hub.c b/net/hub.c
index df32074..ab47b1b 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -31,6 +31,7 @@ typedef struct NetHubPort {
QLIST_ENTRY(NetHubPort) next;
NetHub *hub;
int id;
+ EventNotifier e;
} NetHubPort;
struct NetHub {
@@ -52,7 +53,9 @@ static ssize_t net_hub_receive(NetHub *hub, NetHubPort *source_port,
continue;
}
- qemu_send_packet(&port->nc, buf, len);
+ qemu_net_queue_append(port->nc.peer->send_queue, &port->nc,
+ QEMU_NET_PACKET_FLAG_NONE, buf, len, NULL);
+ event_notifier_set(&port->e);
}
return len;
}
@@ -68,7 +71,9 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
continue;
}
- qemu_sendv_packet(&port->nc, iov, iovcnt);
+ qemu_net_queue_append_iov(port->nc.peer->send_queue, &port->nc,
+ QEMU_NET_PACKET_FLAG_NONE, iov, iovcnt, NULL);
+ event_notifier_set(&port->e);
}
return len;
}
@@ -129,6 +134,11 @@ static void net_hub_port_cleanup(NetClientState *nc)
QLIST_REMOVE(port, next);
}
+static void net_hub_port_bind(NetClientState *nc, GMainContext *ctx)
+{
+ g_source_attach(&nc->nsrc->source, ctx);
+}
+
static NetClientInfo net_hub_port_info = {
.type = NET_CLIENT_OPTIONS_KIND_HUBPORT,
.size = sizeof(NetHubPort),
@@ -136,14 +146,29 @@ static NetClientInfo net_hub_port_info = {
.receive = net_hub_port_receive,
.receive_iov = net_hub_port_receive_iov,
.cleanup = net_hub_port_cleanup,
+ .bind_ctx = net_hub_port_bind,
};
+static gboolean hub_port_handler(gpointer data)
+{
+ NetClientSource *nsrc = (NetClientSource *)data;
+ NetHubPort *port = (NetHubPort *)nsrc->opaque;
+
+ if (nsrc->gfd.revents & G_IO_IN) {
+ event_notifier_test_and_clear(&port->e);
+ qemu_net_queue_flush(port->nc.peer->send_queue);
+ return true;
+ }
+ return false;
+}
+
static NetHubPort *net_hub_port_new(NetHub *hub, const char *name)
{
NetClientState *nc;
NetHubPort *port;
int id = hub->num_ports++;
char default_name[128];
+ NetClientSource *nsrc;
if (!name) {
snprintf(default_name, sizeof(default_name),
@@ -155,6 +180,11 @@ static NetHubPort *net_hub_port_new(NetHub *hub, const char *name)
port = DO_UPCAST(NetHubPort, nc, nc);
port->id = id;
port->hub = hub;
+ event_notifier_init(&port->e, 0);
+ nsrc = (NetClientSource *)g_source_new(&net_gsource_funcs,
+ sizeof(NetClientSource));
+ net_init_gsource(nc, nsrc, event_notifier_get_fd(&port->e), G_IO_IN,
+ NULL, NULL, hub_port_handler, port);
QLIST_INSERT_HEAD(&hub->ports, port, next);
diff --git a/net/net.c b/net/net.c
index fd5269f..646cad8 100644
--- a/net/net.c
+++ b/net/net.c
@@ -871,6 +871,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
(opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
!opts->nic->has_netdev)) {
peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
+ peer->info->bind_ctx(peer, NULL);
}
if (net_client_init_fun[opts->kind](opts, name, peer) < 0) {
diff --git a/net/queue.c b/net/queue.c
index 859d02a..67959f8 100644
--- a/net/queue.c
+++ b/net/queue.c
@@ -87,7 +87,7 @@ void qemu_del_net_queue(NetQueue *queue)
g_free(queue);
}
-static void qemu_net_queue_append(NetQueue *queue,
+void qemu_net_queue_append(NetQueue *queue,
NetClientState *sender,
unsigned flags,
const uint8_t *buf,
@@ -110,7 +110,7 @@ static void qemu_net_queue_append(NetQueue *queue,
QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
}
-static void qemu_net_queue_append_iov(NetQueue *queue,
+void qemu_net_queue_append_iov(NetQueue *queue,
NetClientState *sender,
unsigned flags,
const struct iovec *iov,
--
1.7.4.4
next prev parent reply other threads:[~2013-03-13 5:59 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-13 5:59 [Qemu-devel] [RFC PATCH 0/2] port network layer onto glib Liu Ping Fan
2013-03-13 5:59 ` [Qemu-devel] [RFC PATCH 1/2] net: port tap " Liu Ping Fan
2013-03-13 5:59 ` Liu Ping Fan [this message]
2013-03-13 10:58 ` [Qemu-devel] [RFC PATCH 0/2] port network layer " Paolo Bonzini
2013-03-13 12:34 ` Anthony Liguori
2013-03-13 16:21 ` Paolo Bonzini
2013-03-13 17:06 ` mdroth
2013-03-13 17:31 ` Paolo Bonzini
2013-03-13 17:52 ` Michael S. Tsirkin
2013-03-13 18:09 ` Anthony Liguori
2013-03-13 17:23 ` Anthony Liguori
2013-03-13 17:35 ` Paolo Bonzini
2013-03-13 17:52 ` Anthony Liguori
2013-03-14 9:29 ` Stefan Hajnoczi
2013-03-14 9:53 ` Paolo Bonzini
2013-03-13 17:58 ` Anthony Liguori
2013-03-13 18:08 ` Paolo Bonzini
2013-03-13 18:51 ` Anthony Liguori
2013-03-14 10:04 ` Peter Maydell
2013-03-14 10:53 ` Paolo Bonzini
2013-03-14 11:00 ` Peter Maydell
2013-03-14 11:04 ` Paolo Bonzini
2013-03-14 11:26 ` Peter Maydell
2013-03-15 9:13 ` Stefan Hajnoczi
2013-03-19 9:30 ` Markus Armbruster
2013-03-19 10:12 ` Peter Maydell
2013-03-19 10:34 ` Paolo Bonzini
2013-03-19 10:38 ` Peter Maydell
2013-03-19 10:45 ` Paolo Bonzini
2013-03-14 14:08 ` liu ping fan
2013-03-14 14:18 ` Paolo Bonzini
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=1363154346-14827-3-git-send-email-qemulist@gmail.com \
--to=qemulist@gmail.com \
--cc=anthony@codemonkey.ws \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).