Skip to contentSkip to conversation

virtio-9p: hotplug and migration support

PATCH Superseded Greg Kurz 4 participants 11 messages Oct 5, 2015 – Oct 9, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

cover virtio-9p: hotplug and migration support

This series brings both hoplug and migration support to virtio-9p devices.

Patch 1 is preliminary work.
Patch 2 brings hotplug and fixes a QEMU crash.
Patch 3 brings migration (of course it still depends on the 9p to be unmounted)

---

Greg Kurz (3):
virtio-9p-coth: add release function and fix init error path
virtio-9p: add unrealize handler
virtio-9p: add savem handlers

 hw/9pfs/virtio-9p-coth.c   |   13 +++++++++----
 hw/9pfs/virtio-9p-coth.h   |    1 +
 hw/9pfs/virtio-9p-device.c |   24 ++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)
author
#1 lore raw

PATCH 1/3 virtio-9p-coth: add release function and fix init error path

This is preliminary work to support hotplug/unplug of virtio-9p-device.

---
 hw/9pfs/virtio-9p-coth.c |   13 +++++++++----
 hw/9pfs/virtio-9p-coth.h |    1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
hw/9pfs/virtio-9p-coth.c +9 -4
index 8185c533c013..a4392586c9a2 100644
@@ -66,10 +66,7 @@ int v9fs_init_worker_threads(void)
     }
     p->completed = g_async_queue_new();
     if (!p->completed) {
-        /*
-         * We are going to terminate.
-         * So don't worry about cleanup
-         */
+        g_thread_pool_free(p->pool, true, true);
         ret = -1;
         goto err_out;
     }
@@ -80,3 +77,11 @@ err_out:
     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
     return ret;
 }
+
+int v9fs_release_worker_threads(void)
+{
+        V9fsThPool *p = &v9fs_pool;
+
+        g_thread_pool_free(p->pool, TRUE, TRUE);
+        g_async_queue_unref(p->completed);
+}
hw/9pfs/virtio-9p-coth.h +1 -0
index 4f51b250d1d4..6502e422cea8 100644
@@ -56,6 +56,7 @@ typedef struct V9fsThPool {
 
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
+extern int v9fs_release_worker_threads(void);
 extern int v9fs_co_readlink(V9fsPDU *, V9fsPath *, V9fsString *);
 extern int v9fs_co_readdir_r(V9fsPDU *, V9fsFidState *,
                            struct dirent *, struct dirent **result);
author
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] virtio-9p-coth: add release function and fix init error path

Quoted 4 lines · On Mon, 05 Oct 2015 11:07:16 +0200 Greg Kurz <[email protected]> wrote:

This is preliminary work to support hotplug/unplug of virtio-9p-device.

---

Hmm... still not good. Since this is shared by all virtio-9p devices, we need at least a refcount.

Quoted 46 lines
 hw/9pfs/virtio-9p-coth.c |   13 +++++++++----
 hw/9pfs/virtio-9p-coth.h |    1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
hw/9pfs/virtio-9p-coth.c +9 -4
index 8185c533c013..a4392586c9a2 100644
@@ -66,10 +66,7 @@ int v9fs_init_worker_threads(void)
     }
     p->completed = g_async_queue_new();
     if (!p->completed) {
-        /*
-         * We are going to terminate.
-         * So don't worry about cleanup
-         */
+        g_thread_pool_free(p->pool, true, true);
         ret = -1;
         goto err_out;
     }
@@ -80,3 +77,11 @@ err_out:
     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
     return ret;
 }
+
+int v9fs_release_worker_threads(void)
+{
+        V9fsThPool *p = &v9fs_pool;
+
+        g_thread_pool_free(p->pool, TRUE, TRUE);
+        g_async_queue_unref(p->completed);
+}
hw/9pfs/virtio-9p-coth.h +1 -0
index 4f51b250d1d4..6502e422cea8 100644
@@ -56,6 +56,7 @@ typedef struct V9fsThPool {
 
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
+extern int v9fs_release_worker_threads(void);
 extern int v9fs_co_readlink(V9fsPDU *, V9fsPath *, V9fsString *);
 extern int v9fs_co_readdir_r(V9fsPDU *, V9fsFidState *,
                            struct dirent *, struct dirent **result);
author
#3 lore raw

PATCH 2/3 virtio-9p: add unrealize handler

In reply to Greg Kurz

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.

---
 hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/9pfs/virtio-9p-device.c +12 -0
index 93a407c45926..ed133c40493a 100644
@@ -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;
 }
#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-9p: add unrealize handler

Quoted 5 lines · Greg Kurz

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

Quoted 7 lines

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

---
 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.

author
#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-9p: add unrealize handler

Quoted 9 lines · On Tue, 6 Oct 2015 09:09:14 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 8 lines · Greg Kurz

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.

Quoted 8 lines
Quoted 4 lines
---
 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 ?

#6 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-9p: add unrealize handler

In reply to Stefan Hajnoczi
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Greg Kurz

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.

Quoted 7 lines
Quoted 4 lines
---
 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

author
#7 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-9p: add unrealize handler

Quoted 16 lines · On Wed, 07 Oct 2015 14:20:28 +0530 "Aneesh Kumar K.V"…
Quoted 14 lines · Stefan Hajnoczi
Quoted 12 lines · Greg Kurz

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.

---
 hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
Quoted 7 lines
Quoted 2 lines

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

#8 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-9p: add unrealize handler

Quoted 22 lines · Greg Kurz
Quoted 19 lines · On Wed, 07 Oct 2015 14:20:28 +0530 "Aneesh Kumar K.V"…
Quoted 16 lines · Stefan Hajnoczi
Quoted 5 lines · Greg Kurz

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

Quoted 7 lines

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

---
 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.

Quoted 7 lines
Quoted 4 lines

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.

Quoted 2 lines

--
Greg

author
#9 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-9p: add unrealize handler

Quoted 26 lines · On Fri, 9 Oct 2015 10:36:56 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 25 lines · Greg Kurz
Quoted 22 lines · On Wed, 07 Oct 2015 14:20:28 +0530 "Aneesh Kumar K.V"…
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Greg Kurz

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.

Quoted 7 lines
Quoted 4 lines
---
 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.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

-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

author
#10 lore raw

PATCH 3/3 virtio-9p: add savem handlers

In reply to Greg Kurz

We don't support migration of mounted 9p shares. This is handled by a migration blocker.

One would expect, however, to be able to migrate if the share is unmounted. Unfortunately virtio-9p-device does not register savevm handlers at all ! Migration succeeds and leaves the guest with a dangling device...

This patch simply registers migration handlers for virtio-9p-device. Whether migration is possible or not still depends on the migration blocker.

---
 hw/9pfs/virtio-9p-device.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
hw/9pfs/virtio-9p-device.c +12 -0
index ed133c40493a..bd7f10a0a902 100644
@@ -43,6 +43,16 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config)
     g_free(cfg);
 }
 
+static void virtio_9p_save(QEMUFile *f, void *opaque)
+{
+    virtio_save(VIRTIO_DEVICE(opaque), f);
+}
+
+static int virtio_9p_load(QEMUFile *f, void *opaque, int version_id)
+{
+    return virtio_load(VIRTIO_DEVICE(opaque), f, version_id);
+}
+
 static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -130,6 +140,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
     }
     v9fs_path_free(&path);
 
+    register_savevm(dev, "virtio-9p", -1, 1, virtio_9p_save, virtio_9p_load, s);
     return;
 out:
     g_free(s->ctx.fs_root);
@@ -146,6 +157,7 @@ static void virtio_9p_device_unrealize(DeviceState *dev, Error **errp)
     v9fs_release_worker_threads();
     g_free(s->ctx.fs_root);
     g_free(s->tag);
+    unregister_savevm(dev, "virtio-9p", s);
     virtio_cleanup(vdev);
 }