From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] net: delay freeing peer host device
Date: Mon, 27 Sep 2010 23:53:30 +0200 [thread overview]
Message-ID: <20100927215330.GB12472@redhat.com> (raw)
In-Reply-To: <1285618717.4951.32.camel@x201>
On Mon, Sep 27, 2010 at 02:18:37PM -0600, Alex Williamson wrote:
> On Mon, 2010-09-27 at 15:00 +0200, Michael S. Tsirkin wrote:
> > With -netdev, virtio devices present offload
> > features to guest, depending on the backend used.
> > Thus, removing host netdev peer while guest is
> > active leads to guest-visible inconsistency and/or crashes.
> >
> > As a solution, while guest (NIC) peer device exists,
> > we prevent the host peer from being deleted.
> > This patch does this by adding peer_deleted flag in nic state:
> > if host device is going away while guest device
> > is around, set this flag and keep a shell of
> > the host device around for as long as guest device exists.
> >
> > The link is put down so all packets will get discarded.
> >
> > At the moment, management can detect that device deletion
> > is delayed by doing info net. As a next step, we shall add
> > commands that control hotplug/unplug without
> > removing the device, and an event to report that
> > guest has responded to the hotplug event.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > net.c | 40 +++++++++++++++++++++++++++++++++-------
> > net.h | 1 +
> > 2 files changed, 34 insertions(+), 7 deletions(-)
> >
> > diff --git a/net.c b/net.c
> > index 3d0fde7..edb87af 100644
> > --- a/net.c
> > +++ b/net.c
> > @@ -281,29 +281,55 @@ NICState *qemu_new_nic(NetClientInfo *info,
> > return nic;
> > }
> >
> > -void qemu_del_vlan_client(VLANClientState *vc)
> > +static void qemu_free_vlan_client(VLANClientState *vc)
> > {
> > if (vc->vlan) {
> > QTAILQ_REMOVE(&vc->vlan->clients, vc, next);
> > } else {
> > + QTAILQ_REMOVE(&non_vlan_clients, vc, next);
> > if (vc->send_queue) {
> > qemu_del_net_queue(vc->send_queue);
> > }
> > - QTAILQ_REMOVE(&non_vlan_clients, vc, next);
> > if (vc->peer) {
> > vc->peer->peer = NULL;
> > }
> > }
> > -
> > - if (vc->info->cleanup) {
> > - vc->info->cleanup(vc);
> > - }
> > -
> > qemu_free(vc->name);
> > qemu_free(vc->model);
> > qemu_free(vc);
> > }
> >
> > +void qemu_del_vlan_client(VLANClientState *vc)
> > +{
> > + /* If there is a peer NIC, delete and cleanup client, but do not free. */
> > + if (!vc->vlan && vc->peer && vc->peer->info->type == NET_CLIENT_TYPE_NIC) {
> > + NICState *nic = DO_UPCAST(NICState, nc, vc->peer);
> > + if (nic->peer_deleted) {
> > + return;
> > + }
> > + nic->peer_deleted = true;
> > + /* Let NIC know peer is gone. */
> > + vc->peer->link_down = true;
> > + if (vc->peer->info->link_status_changed) {
> > + vc->peer->info->link_status_changed(vc->peer);
>
> Are we potentially introducing more races here? Now we have the tap
> trying to call link change on a peer device that's potentially in the
> middle of going away. Thanks,
>
> Alex
You mean in guest?
This could always happen anyway: user can call link state change
command. So drivers must be ready for this.
There's no race in qemu because everything is singlethreaded.
> > + }
> > + if (vc->info->cleanup) {
> > + vc->info->cleanup(vc);
> > + }
> > + return;
> > + }
> > +
> > + /* If this is a peer NIC and peer has already been deleted, free it now. */
> > + if (!vc->vlan && vc->peer && vc->info->type == NET_CLIENT_TYPE_NIC) {
> > + NICState *nic = DO_UPCAST(NICState, nc, vc);
> > + if (nic->peer_deleted) {
> > + qemu_free_vlan_client(vc->peer);
> > + }
> > + }
> > +
> > + qemu_free_vlan_client(vc);
> > +}
> > +
> > VLANClientState *
> > qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
> > const char *client_str)
> > diff --git a/net.h b/net.h
> > index 518cf9c..44c31a9 100644
> > --- a/net.h
> > +++ b/net.h
> > @@ -72,6 +72,7 @@ typedef struct NICState {
> > VLANClientState nc;
> > NICConf *conf;
> > void *opaque;
> > + bool peer_deleted;
> > } NICState;
> >
> > struct VLANState {
>
>
prev parent reply other threads:[~2010-09-27 21:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-27 13:00 [Qemu-devel] [PATCH] net: delay freeing peer host device Michael S. Tsirkin
2010-09-27 20:18 ` [Qemu-devel] " Alex Williamson
2010-09-27 21:53 ` Michael S. Tsirkin [this message]
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=20100927215330.GB12472@redhat.com \
--to=mst@redhat.com \
--cc=alex.williamson@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 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.