Blame SOURCES/kvm-dataplane-enable-virtio-blk-x-data-plane-on-live-migration.patch

218e99
From 714d313805542063ea68e26a0d47b5059ee9952e Mon Sep 17 00:00:00 2001
218e99
From: Stefan Hajnoczi <stefanha@redhat.com>
218e99
Date: Tue, 13 Aug 2013 09:06:36 +0200
218e99
Subject: dataplane: enable virtio-blk x-data-plane=on live migration
218e99
218e99
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
218e99
Message-id: <1376384797-4701-6-git-send-email-stefanha@redhat.com>
218e99
Patchwork-id: 53210
218e99
O-Subject: [PATCH v2 5/6] dataplane: enable virtio-blk x-data-plane=on live migration
218e99
Bugzilla: 995030
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
218e99
218e99
Although the dataplane thread does not cooperate with dirty memory
218e99
logging yet it's fairly easy to temporarily disable dataplane during
218e99
live migration.  This way virtio-blk can live migrate when
218e99
x-data-plane=on.
218e99
218e99
The dataplane thread will restart after migration is cancelled or if the
218e99
guest resuming virtio-blk operation after migration completes.
218e99
218e99
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
218e99
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
(cherry picked from commit 84db52d059f3296abf7783968645c4a96d21b099)
218e99
218e99
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
218e99
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
218e99
index 2faed43..63c3ffa 100644
218e99
--- a/hw/block/dataplane/virtio-blk.c
218e99
+++ b/hw/block/dataplane/virtio-blk.c
218e99
@@ -18,7 +18,6 @@
218e99
 #include "qemu/error-report.h"
218e99
 #include "hw/virtio/dataplane/vring.h"
218e99
 #include "ioq.h"
218e99
-#include "migration/migration.h"
218e99
 #include "block/block.h"
218e99
 #include "hw/virtio/virtio-blk.h"
218e99
 #include "virtio-blk.h"
218e99
@@ -69,8 +68,6 @@ struct VirtIOBlockDataPlane {
218e99
                                              queue */
218e99
 
218e99
     unsigned int num_reqs;
218e99
-
218e99
-    Error *migration_blocker;
218e99
 };
218e99
 
218e99
 /* Raise an interrupt to signal guest, if necessary */
218e99
@@ -433,10 +430,6 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
218e99
     /* Prevent block operations that conflict with data plane thread */
218e99
     bdrv_set_in_use(blk->conf.bs, 1);
218e99
 
218e99
-    error_setg(&s->migration_blocker,
218e99
-            "x-data-plane does not support migration");
218e99
-    migrate_add_blocker(s->migration_blocker);
218e99
-
218e99
     *dataplane = s;
218e99
     return true;
218e99
 }
218e99
@@ -448,8 +441,6 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
218e99
     }
218e99
 
218e99
     virtio_blk_data_plane_stop(s);
218e99
-    migrate_del_blocker(s->migration_blocker);
218e99
-    error_free(s->migration_blocker);
218e99
     bdrv_set_in_use(s->blk->conf.bs, 0);
218e99
     g_free(s);
218e99
 }
218e99
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
218e99
index cf12469..cca0c77 100644
218e99
--- a/hw/block/virtio-blk.c
218e99
+++ b/hw/block/virtio-blk.c
218e99
@@ -19,6 +19,7 @@
218e99
 #include "hw/virtio/virtio-blk.h"
218e99
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
218e99
 # include "dataplane/virtio-blk.h"
218e99
+# include "migration/migration.h"
218e99
 #endif
218e99
 #include "block/scsi.h"
218e99
 #ifdef __linux__
218e99
@@ -628,6 +629,34 @@ void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
218e99
     memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
218e99
 }
218e99
 
218e99
+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
218e99
+/* Disable dataplane thread during live migration since it does not
218e99
+ * update the dirty memory bitmap yet.
218e99
+ */
218e99
+static void virtio_blk_migration_state_changed(Notifier *notifier, void *data)
218e99
+{
218e99
+    VirtIOBlock *s = container_of(notifier, VirtIOBlock,
218e99
+                                  migration_state_notifier);
218e99
+    MigrationState *mig = data;
218e99
+
218e99
+    if (migration_is_active(mig)) {
218e99
+        if (!s->dataplane) {
218e99
+            return;
218e99
+        }
218e99
+        virtio_blk_data_plane_destroy(s->dataplane);
218e99
+        s->dataplane = NULL;
218e99
+    } else if (migration_has_finished(mig) ||
218e99
+               migration_has_failed(mig)) {
218e99
+        if (s->dataplane) {
218e99
+            return;
218e99
+        }
218e99
+        bdrv_drain_all(); /* complete in-flight non-dataplane requests */
218e99
+        virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->blk,
218e99
+                                     &s->dataplane);
218e99
+    }
218e99
+}
218e99
+#endif /* CONFIG_VIRTIO_BLK_DATA_PLANE */
218e99
+
218e99
 static int virtio_blk_device_init(VirtIODevice *vdev)
218e99
 {
218e99
     DeviceState *qdev = DEVICE(vdev);
218e99
@@ -664,6 +693,8 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
218e99
         virtio_cleanup(vdev);
218e99
         return -1;
218e99
     }
218e99
+    s->migration_state_notifier.notify = virtio_blk_migration_state_changed;
218e99
+    add_migration_state_change_notifier(&s->migration_state_notifier);
218e99
 #endif
218e99
 
218e99
     s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
218e99
@@ -683,6 +714,7 @@ static int virtio_blk_device_exit(DeviceState *dev)
218e99
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
218e99
     VirtIOBlock *s = VIRTIO_BLK(dev);
218e99
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
218e99
+    remove_migration_state_change_notifier(&s->migration_state_notifier);
218e99
     virtio_blk_data_plane_destroy(s->dataplane);
218e99
     s->dataplane = NULL;
218e99
 #endif
218e99
diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
218e99
index fc71853..b87cf49 100644
218e99
--- a/include/hw/virtio/virtio-blk.h
218e99
+++ b/include/hw/virtio/virtio-blk.h
218e99
@@ -125,6 +125,7 @@ typedef struct VirtIOBlock {
218e99
     unsigned short sector_mask;
218e99
     VMChangeStateEntry *change;
218e99
 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
218e99
+    Notifier migration_state_notifier;
218e99
     struct VirtIOBlockDataPlane *dataplane;
218e99
 #endif
218e99
 } VirtIOBlock;