net-hub: Drop can_receive
PATCH v2 1/1 net-hub: Drop can_receive
This moves the semantics from net_hub_port_can_receive to receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.
--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)
net/hub.c +29 -25
@@ -31,6 +31,7 @@ typedef struct NetHubPort {QLIST_ENTRY (NetHubPort) next;NetHub *hub;int id; +bool needs_flush; } NetHubPort;struct NetHub {
@@ -42,35 +43,58 @@ struct NetHub { static QLIST_HEAD(, NetHub) hubs = QLIST_HEAD_INITIALIZER(&hubs); +static void net_hub_port_send_cb (NetClientState *nc,ssize_t ret) +{ +NetHubPort *port =DO_UPCAST (NetHubPort, nc, nc); +NetHub *hub = port->hub; + + QLIST_FOREACH(port, &hub->ports, next) { +if (port->needs_flush) { + port->needs_flush = false; +qemu_flush_queued_packets (&port->nc); + } + } +} +static ssize_t net_hub_receive (NetHub *hub,NetHubPort *source_port,const uint8_t *buf,size_t len) {NetHubPort *port; +ssize_t ret =-1 ; QLIST_FOREACH(port, &hub->ports, next) { +ssize_t r;if (port == source_port) {continue ; } -qemu_send_packet (&port->nc, buf, len); + r =qemu_send_packet_async (&port->nc, buf, len, + net_hub_port_send_cb); + ret =MAX (r, ret); } -return len; + source_port->needs_flush = ret ==0 ; + +return ret; }static ssize_t net_hub_receive_iov (NetHub *hub,NetHubPort *source_port,const struct iovec *iov,int iovcnt) {NetHubPort *port; -ssize_t len =iov_size (iov, iovcnt); +ssize_t ret =-1 ; QLIST_FOREACH(port, &hub->ports, next) { +ssize_t r;if (port == source_port) {continue ; } -qemu_sendv_packet (&port->nc, iov, iovcnt); + r =qemu_sendv_packet_async (&port->nc, iov, + iovcnt, net_hub_port_send_cb); + ret =MAX (r, ret); } -return len; + source_port->needs_flush = ret ==0 ; +return ret; }static NetHub *net_hub_new (int id)
@@ -87,25 +111,6 @@ static NetHub *net_hub_new(int id)return hub; } -static int net_hub_port_can_receive (NetClientState *nc) -{ -NetHubPort *port; -NetHubPort *src_port =DO_UPCAST (NetHubPort, nc, nc); -NetHub *hub = src_port->hub; - - QLIST_FOREACH(port, &hub->ports, next) { -if (port == src_port) { -continue ; - } - -if (qemu_can_send_packet (&port->nc)) { -return 1 ; - } - } - -return 0 ; -} -static ssize_t net_hub_port_receive (NetClientState *nc,const uint8_t *buf,size_t len) {
@@ -132,7 +137,6 @@ static void net_hub_port_cleanup(NetClientState *nc)static NetClientInfo net_hub_port_info = { .type =NET_CLIENT_OPTIONS_KIND_HUBPORT , .size =sizeof (NetHubPort), - .can_receive = net_hub_port_can_receive, .receive = net_hub_port_receive, .receive_iov = net_hub_port_receive_iov, .cleanup = net_hub_port_cleanup,
Signature · 1 line
2.4.3
Quoted 8 lines · Fam Zheng
This moves the semantics from
net_hub_port_can_receiveto receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.Signed-off-by Fam Zheng <[email protected]>--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)
This patch revision doesn't take into account the special case code in qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to the previous revision of this patch.
The queue is now flushed twice because you've introduced net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already calls net_hub_flush().
If you want to get rid of net_hub_flush(), that's great. But please remove the duplicate code.
Quoted 14 lines · Stefan Hajnoczi
Quoted 8 lines · Fam Zheng
This moves the semantics from
net_hub_port_can_receiveto receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.Signed-off-by Fam Zheng <[email protected]>--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)This patch revision doesn't take into account the special case code in
qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to the previous revision of this patch.
Quoted 6 lines
The queue is now flushed twice because you've introduced
net_hub_port_send_cb()butqemu_flush_or_purge_queued_packets()already callsnet_hub_flush().If you want to get rid of
net_hub_flush(), that's great. But please remove the duplicate code.
Right, I missed that. I'll remove the duplicate and send again.
Quoted 15 lines · Fam Zheng
Quoted 14 lines · Stefan Hajnoczi
Quoted 8 lines · Fam Zheng
This moves the semantics from
net_hub_port_can_receiveto receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.Signed-off-by Fam Zheng <[email protected]>--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)This patch revision doesn't take into account the special case code in
qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to the previous revision of this patch.
Quoted 8 lines
Quoted 6 lines
The queue is now flushed twice because you've introduced
net_hub_port_send_cb()butqemu_flush_or_purge_queued_packets()already callsnet_hub_flush().If you want to get rid of
net_hub_flush(), that's great. But please remove the duplicate code.Right, I missed that. I'll remove the duplicate and send again.
Ping?
Quoted 20 lines · Stefan Hajnoczi
Quoted 19 lines · Fam Zheng
Quoted 18 lines · Stefan Hajnoczi
Quoted 8 lines · Fam Zheng
This moves the semantics from
net_hub_port_can_receiveto receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.Signed-off-by Fam Zheng <[email protected]>--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)This patch revision doesn't take into account the special case code in
qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to the previous revision of this patch.The queue is now flushed twice because you've introduced
net_hub_port_send_cb()butqemu_flush_or_purge_queued_packets()already callsnet_hub_flush().
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
If you want to get rid of
net_hub_flush(), that's great. But please remove the duplicate code.Right, I missed that. I'll remove the duplicate and send again.
Ping?
I thought the net_hub_flush in qemu_flush_or_purge_queued_packets already makes sure net-hub is working, so it's just about cleaning up. That's why I deferred this to 2.5. Am I wrong?
Fam
Quoted 24 lines · Fam Zheng
Quoted 23 lines · Stefan Hajnoczi
Quoted 22 lines · Fam Zheng
Quoted 20 lines · Stefan Hajnoczi
Quoted 8 lines · Fam Zheng
This moves the semantics from
net_hub_port_can_receiveto receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.Signed-off-by Fam Zheng <[email protected]>--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)This patch revision doesn't take into account the special case code in
qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to the previous revision of this patch.The queue is now flushed twice because you've introduced
net_hub_port_send_cb()butqemu_flush_or_purge_queued_packets()already callsnet_hub_flush().If you want to get rid of
net_hub_flush(), that's great. But please remove the duplicate code.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Right, I missed that. I'll remove the duplicate and send again.
Ping?
I thought the
net_hub_flushinqemu_flush_or_purge_queued_packetsalready makes sure net-hub is working, so it's just about cleaning up. That's why I deferred this to 2.5. Am I wrong?
My concern was that your NIC patches remove .can_receive() functions but net/hub.c still relies on them via qemu_can_send_packet().
After thinking about it more, the code should still work the same even though net_hub_can_receive() is now mostly useless and should be removed in QEMU 2.5.
We can leave this patch for now.
Quoted 33 lines · Stefan Hajnoczi
Quoted 24 lines · Fam Zheng
Quoted 23 lines · Stefan Hajnoczi
Quoted 22 lines · Fam Zheng
Quoted 20 lines · Stefan Hajnoczi
Quoted 8 lines · Fam Zheng
This moves the semantics from
net_hub_port_can_receiveto receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.Signed-off-by Fam Zheng <[email protected]>--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)This patch revision doesn't take into account the special case code in
qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to the previous revision of this patch.The queue is now flushed twice because you've introduced
net_hub_port_send_cb()butqemu_flush_or_purge_queued_packets()already callsnet_hub_flush().If you want to get rid of
net_hub_flush(), that's great. But please remove the duplicate code.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Right, I missed that. I'll remove the duplicate and send again.
Ping?
I thought the
net_hub_flushinqemu_flush_or_purge_queued_packetsalready makes sure net-hub is working, so it's just about cleaning up. That's why I deferred this to 2.5. Am I wrong?
Quoted 6 lines
My concern was that your NIC patches remove .can_receive() functions but
net/hub.cstill relies on them viaqemu_can_send_packet().After thinking about it more, the code should still work the same even though
net_hub_can_receive()is now mostly useless and should be removed in QEMU 2.5.
Yes. Completely removing .can_receive from the code base for 2.5 is trivial if the proposed fixes are correct, but it doesn't matter much now.
Quoted 2 lines
We can leave this patch for now.
OK, so net-hub is cleared, please proceed with merging the bulk .can_receive series, or if there are other issues, revert the qemu_set_fd_handler .can_send patches and I'll redo it in 2.5.
Fam
Quoted 45 lines · Fam Zheng
Quoted 33 lines · Stefan Hajnoczi
Quoted 24 lines · Fam Zheng
Quoted 23 lines · Stefan Hajnoczi
Quoted 22 lines · Fam Zheng
Quoted 20 lines · Stefan Hajnoczi
Quoted 8 lines · Fam Zheng
This moves the semantics from
net_hub_port_can_receiveto receive functions, by returning 0 if all receiving ports return 0. Also, remember to flush the source port's queue in that case.Signed-off-by Fam Zheng <[email protected]>--- net/hub.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)This patch revision doesn't take into account the special case code in
qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to the previous revision of this patch.The queue is now flushed twice because you've introduced
net_hub_port_send_cb()butqemu_flush_or_purge_queued_packets()already callsnet_hub_flush().If you want to get rid of
net_hub_flush(), that's great. But please remove the duplicate code.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Right, I missed that. I'll remove the duplicate and send again.
Ping?
I thought the
net_hub_flushinqemu_flush_or_purge_queued_packetsalready makes sure net-hub is working, so it's just about cleaning up. That's why I deferred this to 2.5. Am I wrong?Quoted 6 lines
My concern was that your NIC patches remove .can_receive() functions but
net/hub.cstill relies on them viaqemu_can_send_packet().After thinking about it more, the code should still work the same even though
net_hub_can_receive()is now mostly useless and should be removed in QEMU 2.5.Yes. Completely removing .can_receive from the code base for 2.5 is trivial if the proposed fixes are correct, but it doesn't matter much now.
Quoted 1 line
Quoted 5 lines
Quoted 1 line
We can leave this patch for now.
OK, so net-hub is cleared, please proceed with merging the bulk .can_receive series, or if there are other issues, revert the
qemu_set_fd_handler.can_send patches and I'll redo it in 2.5.
By the way, as part of getting rid of qemu_can_send_packet() it would be good to simplify things so all logic whether to queue or deliver is in one place. Right now it's spread across qemu_deliver_packet(), qemu_can_send_packet(), and qemu_send_packet_async_with_flags().
We didn't notice buggy NICs without flush calls previously because net/net.c uses a mixture of "polling" (checking conditions for each packet) and "blocking" (setting receive_disabled and only clearing it upon flush). Things seemed to work due to the polling code paths.
When we started hitting the blocking code path it became apparent that flushes were missing.
Stefan