qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH 1/8] net: add qemu_purge_queued_packets()
Date: Thu, 18 Jun 2009 18:21:29 +0100	[thread overview]
Message-ID: <1245345696-20915-2-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1245345696-20915-1-git-send-email-markmc@redhat.com>

If net client sends packets asynchronously, it needs to purge its queued
packets in cleanup() so as to prevent sent callbacks being invoked with
a freed client.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   16 ++++++++++++++++
 net.h |    1 +
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/net.c b/net.c
index 9f9e363..0753a7c 100644
--- a/net.c
+++ b/net.c
@@ -439,6 +439,22 @@ qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size)
     return ret;
 }
 
+void qemu_purge_queued_packets(VLANClientState *vc)
+{
+    VLANPacket **pp = &vc->vlan->send_queue;
+
+    while (*pp != NULL) {
+        VLANPacket *packet = *pp;
+
+        if (packet->sender == vc) {
+            *pp = packet->next;
+            qemu_free(packet);
+        } else {
+            pp = &packet->next;
+        }
+    }
+}
+
 void qemu_flush_queued_packets(VLANClientState *vc)
 {
     VLANPacket *packet;
diff --git a/net.h b/net.h
index a9abf63..ef85087 100644
--- a/net.h
+++ b/net.h
@@ -70,6 +70,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
 ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
                                int size, NetPacketSent *sent_cb);
+void qemu_purge_queued_packets(VLANClientState *vc);
 void qemu_flush_queued_packets(VLANClientState *vc);
 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
-- 
1.6.0.6

  reply	other threads:[~2009-06-18 17:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-18 17:21 [Qemu-devel] [PATCH 0/8] TUNSETSNDBUF - pushback to help UDP tx Mark McLoughlin
2009-06-18 17:21 ` Mark McLoughlin [this message]
2009-06-18 17:21   ` [Qemu-devel] [PATCH 2/8] net: purge queued packets in tap_cleanup() Mark McLoughlin
2009-06-18 17:21     ` [Qemu-devel] [PATCH 3/8] net: add tap_read_poll() helper Mark McLoughlin
2009-06-18 17:21       ` [Qemu-devel] [PATCH 4/8] net: handle EAGAIN from tapfd write() Mark McLoughlin
2009-06-18 17:21         ` [Qemu-devel] [PATCH 5/8] net: return TAPState from net_tap_init() Mark McLoughlin
2009-06-18 17:21           ` [Qemu-devel] [PATCH 6/8] net: add '-net tap,sndbuf=nbytes' Mark McLoughlin
2009-06-18 17:21             ` [Qemu-devel] [PATCH 7/8] net: add packet length to NetPacketSent callback Mark McLoughlin
2009-06-18 17:21               ` [Qemu-devel] [PATCH 8/8] virtio-net: implement async packet sending Mark McLoughlin

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=1245345696-20915-2-git-send-email-markmc@redhat.com \
    --to=markmc@redhat.com \
    --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).