From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: Anthony Liguori <aliguori@amazon.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
qemu-stable@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/3] net: complete all queued packets on VM stop
Date: Thu, 4 Sep 2014 13:32:32 +0300 [thread overview]
Message-ID: <20140904103232.GA13325@redhat.com> (raw)
In-Reply-To: <54083BB0.60202@redhat.com>
On Thu, Sep 04, 2014 at 06:15:12PM +0800, Jason Wang wrote:
> On 09/04/2014 04:39 PM, Michael S. Tsirkin wrote:
> > This completes all packets, ensuring that callbacks
> > will not run when VM is stopped.
> >
> > Cc: qemu-stable@nongnu.org
> > Cc: Jason Wang <jasowang@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > net/net.c | 33 ++++++++++++++++++++++++++++++++-
> > 1 file changed, 32 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/net.c b/net/net.c
> > index 6d930ea..25fdb07 100644
> > --- a/net/net.c
> > +++ b/net/net.c
> > @@ -47,6 +47,7 @@
> > # define CONFIG_NET_BRIDGE
> > #endif
> >
> > +static VMChangeStateEntry *net_change_state_entry;
> > static QTAILQ_HEAD(, NetClientState) net_clients;
> >
> > const char *host_net_devices[] = {
> > @@ -504,7 +505,8 @@ void qemu_purge_queued_packets(NetClientState *nc)
> > qemu_net_queue_purge(nc->peer->incoming_queue, nc);
> > }
> >
> > -void qemu_flush_queued_packets(NetClientState *nc)
> > +static
> > +void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge)
> > {
> > nc->receive_disabled = 0;
> >
> > @@ -518,9 +520,17 @@ void qemu_flush_queued_packets(NetClientState *nc)
> > * the file descriptor (for tap, for example).
> > */
> > qemu_notify_event();
> > + } else if (purge) {
> > + /* Unable to empty the queue, purge remaining packets */
> > + qemu_net_queue_purge(nc->incoming_queue, nc);
> > }
> > }
> >
> > +void qemu_flush_queued_packets(NetClientState *nc)
> > +{
> > + qemu_flush_or_purge_queued_packets(nc, false);
> > +}
> > +
> > static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
> > unsigned flags,
> > const uint8_t *buf, int size,
> > @@ -1168,6 +1178,22 @@ void qmp_set_link(const char *name, bool up, Error **errp)
> > }
> > }
> >
> > +static void net_vm_change_state_handler(void *opaque, int running,
> > + RunState state)
> > +{
> > + /* Complete all queued packets, to guarantee we don't modify
> > + * state later when VM is not running.
> > + */
> > + if (!running) {
> > + NetClientState *nc;
> > + NetClientState *tmp;
> > +
> > + QTAILQ_FOREACH_SAFE(nc, &net_clients, next, tmp) {
> > + qemu_flush_or_purge_queued_packets(nc, true);
> > + }
> > + }
> > +}
> > +
> > void net_cleanup(void)
> > {
> > NetClientState *nc;
> > @@ -1183,6 +1209,8 @@ void net_cleanup(void)
> > qemu_del_net_client(nc);
> > }
> > }
> > +
> > + qemu_del_vm_change_state_handler(net_change_state_entry);
> > }
> >
> > void net_check_clients(void)
> > @@ -1268,6 +1296,9 @@ int net_init_clients(void)
> > #endif
> > }
> >
> > + net_change_state_entry =
> > + qemu_add_vm_change_state_handler(net_vm_change_state_handler, NULL);
> > +
> > QTAILQ_INIT(&net_clients);
> >
> > if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, 1) == -1)
>
> A problem is the dependency between state change handlers (e.g. virtio).
> Current virtio vmstate change handler will be called before this
> handler. Which means vdev->vm_running was false when we purge the queue,
> this will trigger the assert of vdev->vm_running in virtio_net_flush_tx().
True but that's a virtio bug: it changes vm_running too early.
I will send a patch to fix that now.
Long term with the core changes, we mught be able to get rid of
vm_running field completely.
next prev parent reply other threads:[~2014-09-04 10:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-04 8:39 [Qemu-devel] [PATCH 1/3] net: invoke callback when purging queue Michael S. Tsirkin
2014-09-04 8:39 ` [Qemu-devel] [PATCH 2/3] net: complete all queued packets on VM stop Michael S. Tsirkin
2014-09-04 10:15 ` Jason Wang
2014-09-04 10:32 ` Michael S. Tsirkin [this message]
2014-09-04 8:39 ` [Qemu-devel] [PATCH 3/3] virtio-net: purge outstanding packets when starting vhost Michael S. Tsirkin
2014-09-04 9:58 ` [Qemu-devel] [PATCH 1/3] net: invoke callback when purging queue Jason Wang
2014-09-04 13:38 ` Stefan Hajnoczi
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=20140904103232.GA13325@redhat.com \
--to=mst@redhat.com \
--cc=aliguori@amazon.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=stefanha@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.