From: Luigi Rizzo <rizzo@iet.unipi.it>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] fix unbounded qemu NetQueue
Date: Thu, 17 Jan 2013 07:07:11 +0100 [thread overview]
Message-ID: <20130117060711.GA59416@onelab2.iet.unipi.it> (raw)
In-Reply-To: <CA+hQ2+imk7Z-MzTfMkeRYitzQxwbLGjzoPDkf_g8EEomhkx89g@mail.gmail.com>
The comment at the beginning of net/queue.c says that packets that
cannot be sent by qemu_net_queue_send() should not be enqueued
unless a callback is set.
This patch implements this behaviour, that prevents a queue to grow
unbounded (e.g. when a network backend is not connected).
Also for good measure the patch implements bounded size queues
(though it should not be necessary now because each source can only have
one packet queued). When a packet is dropped because excessive
queue size the callback is not supposed to be called.
cheers
luigi
Signed-off-by: Luigi Rizzo <rizzo@iet.unipi.it>
--- ../orig/net/queue.c 2012-12-03 11:37:05.000000000 -0800
+++ ./net/queue.c 2013-01-16 21:37:20.109732443 -0800
@@ -50,6 +50,8 @@ struct NetPacket {
struct NetQueue {
void *opaque;
+ uint32_t nq_maxlen;
+ uint32_t nq_count;
QTAILQ_HEAD(packets, NetPacket) packets;
@@ -63,6 +65,8 @@ NetQueue *qemu_new_net_queue(void *opaqu
queue = g_malloc0(sizeof(NetQueue));
queue->opaque = opaque;
+ queue->nq_maxlen = 10000; /* arbitrary limit */
+ queue->nq_count = 0;
QTAILQ_INIT(&queue->packets);
@@ -92,6 +96,8 @@ static void qemu_net_queue_append(NetQue
{
NetPacket *packet;
+ if (!sent_cb || queue->nq_count >= queue->nq_maxlen)
+ return;
packet = g_malloc(sizeof(NetPacket) + size);
packet->sender = sender;
packet->flags = flags;
@@ -99,6 +105,7 @@ static void qemu_net_queue_append(NetQue
packet->sent_cb = sent_cb;
memcpy(packet->data, buf, size);
+ queue->nq_count++;
QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
}
@@ -113,6 +120,8 @@ static void qemu_net_queue_append_iov(Ne
size_t max_len = 0;
int i;
+ if (!sent_cb || queue->nq_count >= queue->nq_maxlen)
+ return;
for (i = 0; i < iovcnt; i++) {
max_len += iov[i].iov_len;
}
@@ -130,6 +139,7 @@ static void qemu_net_queue_append_iov(Ne
packet->size += len;
}
+ queue->nq_count++;
QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
}
@@ -220,6 +230,7 @@ void qemu_net_queue_purge(NetQueue *queu
QTAILQ_FOREACH_SAFE(packet, &queue->packets, entry, next) {
if (packet->sender == from) {
QTAILQ_REMOVE(&queue->packets, packet, entry);
+ queue->nq_count--;
g_free(packet);
}
}
@@ -233,6 +244,7 @@ bool qemu_net_queue_flush(NetQueue *queu
packet = QTAILQ_FIRST(&queue->packets);
QTAILQ_REMOVE(&queue->packets, packet, entry);
+ queue->nq_count--;
ret = qemu_net_queue_deliver(queue,
packet->sender,
@@ -240,6 +252,7 @@ bool qemu_net_queue_flush(NetQueue *queu
packet->data,
packet->size);
if (ret == 0) {
+ queue->nq_count++;
QTAILQ_INSERT_HEAD(&queue->packets, packet, entry);
return false;
}
next prev parent reply other threads:[~2013-01-17 6:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-06 19:23 [Qemu-devel] unbounded qemu NetQue's ? Luigi Rizzo
2013-01-07 13:49 ` Stefan Hajnoczi
2013-01-07 14:27 ` Luigi Rizzo
2013-01-10 12:29 ` Stefan Hajnoczi
2013-01-16 21:57 ` Luigi Rizzo
2013-01-17 6:07 ` Luigi Rizzo [this message]
2013-01-17 10:21 ` [Qemu-devel] [PATCH] fix unbounded qemu NetQueue Stefan Hajnoczi
2013-01-17 15:56 ` Luigi Rizzo
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=20130117060711.GA59416@onelab2.iet.unipi.it \
--to=rizzo@iet.unipi.it \
--cc=qemu-devel@nongnu.org \
/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).