diff mbox

[2/3] virtio-9p: add unrealize handler

Message ID 20151005090722.20420.71571.stgit@bahia.huguette.org
State New
Headers show

Commit Message

Greg Kurz Oct. 5, 2015, 9:07 a.m. UTC
If the user tries to hot unplug a virtio-9p device, it seems to succeed but
in fact:
- virtio-9p coroutines thread pool and async queue are leaked
- QEMU crashes in virtio_vmstate_change() if the user tries to live migrate

This patch brings hot unplug support to virtio-9p-device. It fixes both
above issues.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Stefan Hajnoczi Oct. 6, 2015, 8:09 a.m. UTC | #1
On Mon, Oct 05, 2015 at 11:07:23AM +0200, Greg Kurz wrote:
> If the user tries to hot unplug a virtio-9p device, it seems to succeed but
> in fact:
> - virtio-9p coroutines thread pool and async queue are leaked
> - QEMU crashes in virtio_vmstate_change() if the user tries to live migrate
> 
> This patch brings hot unplug support to virtio-9p-device. It fixes both
> above issues.
> 
> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> ---
>  hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
>  1 file changed, 12 insertions(+)

What happens to in-flight I/O requests?  We cannot assume that the guest
driver quiesces the device.
Greg Kurz Oct. 6, 2015, 9:13 a.m. UTC | #2
On Tue, 6 Oct 2015 09:09:14 +0100
Stefan Hajnoczi <stefanha@gmail.com> wrote:

> On Mon, Oct 05, 2015 at 11:07:23AM +0200, Greg Kurz wrote:
> > If the user tries to hot unplug a virtio-9p device, it seems to succeed but
> > in fact:
> > - virtio-9p coroutines thread pool and async queue are leaked
> > - QEMU crashes in virtio_vmstate_change() if the user tries to live migrate
> > 
> > This patch brings hot unplug support to virtio-9p-device. It fixes both
> > above issues.
> > 
> > Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > ---
> >  hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> 
> What happens to in-flight I/O requests?  We cannot assume that the guest
> driver quiesces the device.
> 

We can assume that the guest has unmounted the 9p share otherwise migration
is blocked... is it possible we still have in-flight I/O requests in this
scenario ?
Aneesh Kumar K.V Oct. 7, 2015, 8:50 a.m. UTC | #3
Stefan Hajnoczi <stefanha@gmail.com> writes:

> On Mon, Oct 05, 2015 at 11:07:23AM +0200, Greg Kurz wrote:
>> If the user tries to hot unplug a virtio-9p device, it seems to succeed but
>> in fact:
>> - virtio-9p coroutines thread pool and async queue are leaked
>> - QEMU crashes in virtio_vmstate_change() if the user tries to live migrate
>> 
>> This patch brings hot unplug support to virtio-9p-device. It fixes both
>> above issues.
>> 
>> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
>> ---
>>  hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>
> What happens to in-flight I/O requests?  We cannot assume that the guest
> driver quiesces the device.

We enable migration blocker when we have an active mount. So if we get
here, that should indicate no active 9p mounts.

-aneesh
Greg Kurz Oct. 9, 2015, 7:23 a.m. UTC | #4
On Wed, 07 Oct 2015 14:20:28 +0530
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:

> Stefan Hajnoczi <stefanha@gmail.com> writes:
> 
> > On Mon, Oct 05, 2015 at 11:07:23AM +0200, Greg Kurz wrote:
> >> If the user tries to hot unplug a virtio-9p device, it seems to succeed but
> >> in fact:
> >> - virtio-9p coroutines thread pool and async queue are leaked
> >> - QEMU crashes in virtio_vmstate_change() if the user tries to live migrate
> >> 
> >> This patch brings hot unplug support to virtio-9p-device. It fixes both
> >> above issues.
> >> 
> >> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> >> ---
> >>  hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
> >>  1 file changed, 12 insertions(+)
> >
> > What happens to in-flight I/O requests?  We cannot assume that the guest
> > driver quiesces the device.
> 
> We enable migration blocker when we have an active mount. So if we get
> here, that should indicate no active 9p mounts.
> 
> -aneesh

Oops.. Stefan is talking about hot-unplug versus in-flight requests... not
about migration. And there is no such thing as a hot-unplug blocker...

--
Greg
Michael S. Tsirkin Oct. 9, 2015, 7:36 a.m. UTC | #5
On Fri, Oct 09, 2015 at 09:23:49AM +0200, Greg Kurz wrote:
> On Wed, 07 Oct 2015 14:20:28 +0530
> "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> 
> > Stefan Hajnoczi <stefanha@gmail.com> writes:
> > 
> > > On Mon, Oct 05, 2015 at 11:07:23AM +0200, Greg Kurz wrote:
> > >> If the user tries to hot unplug a virtio-9p device, it seems to succeed but
> > >> in fact:
> > >> - virtio-9p coroutines thread pool and async queue are leaked
> > >> - QEMU crashes in virtio_vmstate_change() if the user tries to live migrate
> > >> 
> > >> This patch brings hot unplug support to virtio-9p-device. It fixes both
> > >> above issues.
> > >> 
> > >> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > >> ---
> > >>  hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
> > >>  1 file changed, 12 insertions(+)
> > >
> > > What happens to in-flight I/O requests?  We cannot assume that the guest
> > > driver quiesces the device.
> > 
> > We enable migration blocker when we have an active mount. So if we get
> > here, that should indicate no active 9p mounts.
> > 
> > -aneesh
> 
> Oops.. Stefan is talking about hot-unplug versus in-flight requests... not
> about migration. And there is no such thing as a hot-unplug blocker...

If unplug request fails, that should be enough.

> --
> Greg
Greg Kurz Oct. 9, 2015, 10:54 a.m. UTC | #6
On Fri, 9 Oct 2015 10:36:56 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Fri, Oct 09, 2015 at 09:23:49AM +0200, Greg Kurz wrote:
> > On Wed, 07 Oct 2015 14:20:28 +0530
> > "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> > 
> > > Stefan Hajnoczi <stefanha@gmail.com> writes:
> > > 
> > > > On Mon, Oct 05, 2015 at 11:07:23AM +0200, Greg Kurz wrote:
> > > >> If the user tries to hot unplug a virtio-9p device, it seems to succeed but
> > > >> in fact:
> > > >> - virtio-9p coroutines thread pool and async queue are leaked
> > > >> - QEMU crashes in virtio_vmstate_change() if the user tries to live migrate
> > > >> 
> > > >> This patch brings hot unplug support to virtio-9p-device. It fixes both
> > > >> above issues.
> > > >> 
> > > >> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > > >> ---
> > > >>  hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
> > > >>  1 file changed, 12 insertions(+)
> > > >
> > > > What happens to in-flight I/O requests?  We cannot assume that the guest
> > > > driver quiesces the device.
> > > 
> > > We enable migration blocker when we have an active mount. So if we get
> > > here, that should indicate no active 9p mounts.
> > > 
> > > -aneesh
> > 
> > Oops.. Stefan is talking about hot-unplug versus in-flight requests... not
> > about migration. And there is no such thing as a hot-unplug blocker...
> 
> If unplug request fails, that should be enough.
> 

Like setting @hotpluggable to false for the virtio-9p-pci class ? I see no
other way for the unplug request to fail... but I will happily accept all
suggestions :)

--
Greg
diff mbox

Patch

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 93a407c45926..ed133c40493a 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -138,6 +138,17 @@  out:
     v9fs_path_free(&path);
 }
 
+static void virtio_9p_device_unrealize(DeviceState *dev, Error **errp)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    V9fsState *s = VIRTIO_9P(dev);
+
+    v9fs_release_worker_threads();
+    g_free(s->ctx.fs_root);
+    g_free(s->tag);
+    virtio_cleanup(vdev);
+}
+
 /* virtio-9p device */
 
 static Property virtio_9p_properties[] = {
@@ -154,6 +165,7 @@  static void virtio_9p_class_init(ObjectClass *klass, void *data)
     dc->props = virtio_9p_properties;
     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
     vdc->realize = virtio_9p_device_realize;
+    vdc->unrealize = virtio_9p_device_unrealize;
     vdc->get_features = virtio_9p_get_features;
     vdc->get_config = virtio_9p_get_config;
 }