Patchwork [2/7] ivshmem: use migration blockers to prevent live migration in peer mode

login
register
mail settings
Submitter Anthony Liguori
Date Nov. 12, 2011, 3:56 p.m.
Message ID <1321113420-3252-2-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/125348/
State New
Headers show

Comments

Anthony Liguori - Nov. 12, 2011, 3:56 p.m.
Now when you try to migrate with ivshmem, you get a proper QMP error:

(qemu) migrate tcp:localhost:1025
Migration is disabled when using feature 'peer mode' in device 'ivshmem'
(qemu)

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/ivshmem.c |   12 +++++++++++-
 qerror.c     |    4 ++++
 qerror.h     |    3 +++
 3 files changed, 18 insertions(+), 1 deletions(-)
Juan Quintela - Nov. 14, 2011, 1:05 p.m.
Anthony Liguori <aliguori@us.ibm.com> wrote:
> Now when you try to migrate with ivshmem, you get a proper QMP error:
>
> (qemu) migrate tcp:localhost:1025
> Migration is disabled when using feature 'peer mode' in device 'ivshmem'
> (qemu)

This was the only user of register_device_unmigratable(), just to remove
function if we continue this path.
Anthony Liguori - Nov. 14, 2011, 1:52 p.m.
On 11/14/2011 07:05 AM, Juan Quintela wrote:
> Anthony Liguori<aliguori@us.ibm.com>  wrote:
>> Now when you try to migrate with ivshmem, you get a proper QMP error:
>>
>> (qemu) migrate tcp:localhost:1025
>> Migration is disabled when using feature 'peer mode' in device 'ivshmem'
>> (qemu)
>
> This was the only user of register_device_unmigratable(), just to remove
> function if we continue this path.

There are a couple more in usb also but I can convert them too.

Regards,

Anthony Liguori

>
Juan Quintela - Nov. 14, 2011, 7:52 p.m.
Anthony Liguori <aliguori@us.ibm.com> wrote:
> On 11/14/2011 07:05 AM, Juan Quintela wrote:
>> Anthony Liguori<aliguori@us.ibm.com>  wrote:
>>> Now when you try to migrate with ivshmem, you get a proper QMP error:
>>>
>>> (qemu) migrate tcp:localhost:1025
>>> Migration is disabled when using feature 'peer mode' in device 'ivshmem'
>>> (qemu)
>>
>> This was the only user of register_device_unmigratable(), just to remove
>> function if we continue this path.
>
> There are a couple more in usb also but I can convert them too.

usb uses "yet another" way to make devices unmigratable.

static const VMStateDescription vmstate_usb_host = {
    .name = "usb-host",
    .unmigratable = 1,
};

So, we have "already" two ways to make a device unmigratable:
- calling register_device_unmigratable() (ivhs)
- definining in vmstate .unmigratable = 1
- and now your new way.

My point was that only one (or even two) should be enough.

Why two? because the .unmigratable way is very useful for devices that
haven't been made "migratable", but that are converted to qdev.  Not
jthat this couldn't be "fixed" on registration with a call to
migrate_add_blocker.

Later, Juan.
Anthony Liguori - Nov. 14, 2011, 7:55 p.m.
On 11/14/2011 01:52 PM, Juan Quintela wrote:
> Anthony Liguori<aliguori@us.ibm.com>  wrote:
>> On 11/14/2011 07:05 AM, Juan Quintela wrote:
>>> Anthony Liguori<aliguori@us.ibm.com>   wrote:
>>>> Now when you try to migrate with ivshmem, you get a proper QMP error:
>>>>
>>>> (qemu) migrate tcp:localhost:1025
>>>> Migration is disabled when using feature 'peer mode' in device 'ivshmem'
>>>> (qemu)
>>>
>>> This was the only user of register_device_unmigratable(), just to remove
>>> function if we continue this path.
>>
>> There are a couple more in usb also but I can convert them too.
>
> usb uses "yet another" way to make devices unmigratable.
>
> static const VMStateDescription vmstate_usb_host = {
>      .name = "usb-host",
>      .unmigratable = 1,
> };
>
> So, we have "already" two ways to make a device unmigratable:
> - calling register_device_unmigratable() (ivhs)
> - definining in vmstate .unmigratable = 1
> - and now your new way.
>
> My point was that only one (or even two) should be enough.

Ah, yes, I see now.  I'll remove that function.

Regards,

Anthony Liguori

>
> Why two? because the .unmigratable way is very useful for devices that
> haven't been made "migratable", but that are converted to qdev.  Not
> jthat this couldn't be "fixed" on registration with a call to
> migrate_add_blocker.
>
> Later, Juan.
>

Patch

diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 242fbea..a3a0e98 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -18,6 +18,8 @@ 
 #include "pci.h"
 #include "msix.h"
 #include "kvm.h"
+#include "migration.h"
+#include "qerror.h"
 
 #include <sys/mman.h>
 #include <sys/types.h>
@@ -78,6 +80,8 @@  typedef struct IVShmemState {
     uint32_t features;
     EventfdEntry *eventfd_table;
 
+    Error *migration_blocker;
+
     char * shmobj;
     char * sizearg;
     char * role;
@@ -646,7 +650,8 @@  static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     if (s->role_val == IVSHMEM_PEER) {
-        register_device_unmigratable(&s->dev.qdev, "ivshmem", s);
+        error_set(&s->migration_blocker, QERR_DEVICE_FEATURE_BLOCKS_MIGRATION, "ivshmem", "peer mode");
+        migrate_add_blocker(s->migration_blocker);
     }
 
     pci_conf = s->dev.config;
@@ -741,6 +746,11 @@  static int pci_ivshmem_uninit(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
 
+    if (s->migration_blocker) {
+        migrate_del_blocker(s->migration_blocker);
+        error_free(s->migration_blocker);
+    }
+
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
     memory_region_destroy(&s->ivshmem);
diff --git a/qerror.c b/qerror.c
index 4b48b39..8e30e2d 100644
--- a/qerror.c
+++ b/qerror.c
@@ -73,6 +73,10 @@  static const QErrorStringTable qerror_table[] = {
         .desc      = "Device '%(device)' is in use",
     },
     {
+        .error_fmt = QERR_DEVICE_FEATURE_BLOCKS_MIGRATION,
+        .desc      = "Migration is disabled when using feature '%(feature)' in device '%(device)'",
+    },
+    {
         .error_fmt = QERR_DEVICE_LOCKED,
         .desc      = "Device '%(device)' is locked",
     },
diff --git a/qerror.h b/qerror.h
index d4bfcfd..7e2eebf 100644
--- a/qerror.h
+++ b/qerror.h
@@ -72,6 +72,9 @@  QError *qobject_to_qerror(const QObject *obj);
 #define QERR_DEVICE_IN_USE \
     "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }"
 
+#define QERR_DEVICE_FEATURE_BLOCKS_MIGRATION \
+    "{ 'class': 'DeviceFeatureBlocksMigration', 'data': { 'device': %s, 'feature': %s } }"
+
 #define QERR_DEVICE_LOCKED \
     "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"