Disable hotplug during migration
v2 cover Disable hotplug during migration
Hi
This updates patches with all the comments received. I move qdev_unplug() to make linux-user compile.
Please, review.
[RFC - v1]
This series disable hotplug/unplug during migration. Thank to Markus for explaining where I had to put the checks. Why? Because during migration we will fail if there are changes. For instance, in postcopy, if we add a memory region, we would failing. Same for other devices if they are not setup exactly the same on destination.
Iidea would be to disable it, andthen enable for the thing that we know that work.
This series are on top of my previous RAMState v2 serie.
Commets, please?
Thanks, Juan.
*** BLURB HERE ***
Juan Quintela (5):
qdev: qdev_hotplug is really a bool
qdev: Export qdev_hot_removed
qdev: Move qdev_unplug() to qdev-monitor.c
migration: Disable hotplug/unplug during migration
ram: Remove migration_bitmap_extend()
exec.c | 1 - hw/core/qdev.c | 40 +++------------------------------------- include/exec/ram_addr.h | 2 -- include/hw/qdev-core.h | 3 ++- migration/ram.c | 34 ---------------------------------- qdev-monitor.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 75 deletions(-)
Signature · 1 line
2.9.3
PATCH v2 1/5 qdev: qdev_hotplug is really a bool
--- hw/core/qdev.c | 4 ++-- include/hw/qdev-core.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/core/qdev.c +2 -2
@@ -39,7 +39,7 @@#include "qapi-event.h" #include "migration/migration.h" -int qdev_hotplug =0 ; +bool qdev_hotplug = false;static bool qdev_hot_added = false;static bool qdev_hot_removed = false;
@@ -385,7 +385,7 @@ void qdev_machine_creation_done(void)* ok, initial machine setup is done, starting from now we can * only create hotpluggable devices */ - qdev_hotplug =1 ; + qdev_hotplug = true; }bool qdev_machine_modified (void )
include/hw/qdev-core.h +1 -1
@@ -386,7 +386,7 @@ Object *qdev_get_machine(void);/* FIXME: make this a link<> */ void qdev_set_parent_bus (DeviceState *dev,BusState *bus); -extern int qdev_hotplug; +extern bool qdev_hotplug;char *qdev_get_dev_path (DeviceState *dev);
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 1/5] qdev: qdev_hotplug is really a bool
Quoted 5 lines · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev.c | 4 ++-- include/hw/qdev-core.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/5] qdev: qdev_hotplug is really a bool
In reply to Juan QuintelaQuoted 1 line · Juan Quintela
Signed-off-by Juan Quintela <[email protected]>
Quoted 41 lines
--- hw/core/qdev.c | 4 ++-- include/hw/qdev-core.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)hw/core/qdev.c +2
-2@@ -39,7 +39,7 @@#include "qapi-event.h" #include "migration/migration.h" -int qdev_hotplug =0 ; +bool qdev_hotplug = false;static bool qdev_hot_added = false;static bool qdev_hot_removed = false;@@ -385,7 +385,7 @@ void qdev_machine_creation_done(void)* ok, initial machine setup is done, starting from now we can * only create hotpluggable devices */ - qdev_hotplug =1 ; + qdev_hotplug = true; }bool qdev_machine_modified (void )include/hw/qdev-core.h +1
-1@@ -386,7 +386,7 @@ Object *qdev_get_machine(void);/* FIXME: make this a link<> */ void qdev_set_parent_bus (DeviceState *dev,BusState *bus); -extern int qdev_hotplug; +extern bool qdev_hotplug;char *qdev_get_dev_path (DeviceState *dev);
PATCH v2 2/5 qdev: Export qdev_hot_removed
In reply to Juan QuintelaI need to move qdev_unplug to qdev-monitor in the following patch, and it needs access to this variable.
--- hw/core/qdev.c | 2 +- include/hw/qdev-core.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
hw/core/qdev.c +1 -1
@@ -41,7 +41,7 @@bool qdev_hotplug = false;static bool qdev_hot_added = false; -static bool qdev_hot_removed = false; +bool qdev_hot_removed = false;const VMStateDescription *qdev_get_vmsd (DeviceState *dev) {
include/hw/qdev-core.h +1 -0
@@ -387,6 +387,7 @@ Object *qdev_get_machine(void);void qdev_set_parent_bus (DeviceState *dev,BusState *bus);extern bool qdev_hotplug; +extern bool qdev_hot_removed;char *qdev_get_dev_path (DeviceState *dev);
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 2/5] qdev: Export qdev_hot_removed
Quoted 9 lines · Juan Quintela
I need to move
qdev_unplugto qdev-monitor in the following patch, and it needs access to this variable.Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev.c | 2 +- include/hw/qdev-core.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/5] qdev: Export qdev_hot_removed
In reply to Juan QuintelaQuoted 14 lines · Juan Quintela
I need to move
qdev_unplugto qdev-monitor in the following patch, and it needs access to this variable.Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev.c | 2 +- include/hw/qdev-core.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)hw/core/qdev.c +0
-0
hw/core/qdev.c line 44
Quoted 5 lines
hw/core/qdev.c +1
-1@@ -41,7 +41,7 @@bool qdev_hotplug = false;static bool qdev_hot_added = false; -static bool qdev_hot_removed = false; +bool qdev_hot_removed = false;
Makes qdev_hot_added and qdev_hot_removed differently static, which is weird.
The reason for this asymmetry is the asymmetry in how they get set:
* qdev_hot_added gets set .instance_init() method in device_initfn() when it runs after qdev_machine_creation_done(). It's called by qdev_device_add() via object_new()... then.
* qdev_hot_removed gets set directly in qdev_unplug(), not in the .instance_finalize() method device_finalize().
Note that for some devices, qdev_unplug() only requests unplug. Actual unplug happens later, or even not at all. device_finalize() runs on actual unplug.
Questions:
* Is setting qdev_hot_removed on unplug *requests* correct? Or should it be set only on *actual* unplug?
* Can we avoid the asymmetry? It's a bit ugly.
Quoted 13 lines
hw/core/qdev.c +0
-0const VMStateDescription *qdev_get_vmsd (DeviceState *dev) {include/hw/qdev-core.h +1
-0@@ -387,6 +387,7 @@ Object *qdev_get_machine(void);void qdev_set_parent_bus (DeviceState *dev,BusState *bus);extern bool qdev_hotplug; +extern bool qdev_hot_removed;char *qdev_get_dev_path (DeviceState *dev);
PATCH v2 3/5 qdev: Move qdev_unplug() to qdev-monitor.c
In reply to Juan QuintelaIt is not used by linux-user, otherwise I need to to create one stub for migration_is_idle() on following patch.
--- hw/core/qdev.c | 34 ---------------------------------- qdev-monitor.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-)
hw/core/qdev.c +0 -34
@@ -271,40 +271,6 @@ HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)return hotplug_ctrl; } -void qdev_unplug (DeviceState *dev,Error **errp) -{ -DeviceClass *dc =DEVICE_GET_CLASS (dev); -HotplugHandler *hotplug_ctrl; -HotplugHandlerClass *hdc; - -if (dev->parent_bus && !qbus_is_hotpluggable (dev->parent_bus)) { -error_setg (errp,QERR_BUS_NO_HOTPLUG , dev->parent_bus->name); -return ; - } - -if (!dc->hotpluggable) { -error_setg (errp,QERR_DEVICE_NO_HOTPLUG , -object_get_typename (OBJECT (dev))); -return ; - } - - qdev_hot_removed = true; - - hotplug_ctrl =qdev_get_hotplug_handler (dev); -/* hotpluggable device MUST have HotplugHandler, if it doesn't -* then something is very wrong with it */ -g_assert (hotplug_ctrl); - -/* If device supports async unplug just request it to be done, -* otherwise just remove it synchronously */ - hdc =HOTPLUG_HANDLER_GET_CLASS (hotplug_ctrl); -if (hdc->unplug_request) { -hotplug_handler_unplug_request (hotplug_ctrl, dev, errp); - }else { -hotplug_handler_unplug (hotplug_ctrl, dev, errp); - } -} -static int qdev_reset_one (DeviceState *dev,void *opaque) {device_reset (dev);
qdev-monitor.c +34 -0
@@ -836,6 +836,40 @@ static DeviceState *find_device_state(const char *id, Error **errp)return DEVICE (obj); } +void qdev_unplug (DeviceState *dev,Error **errp) +{ +DeviceClass *dc =DEVICE_GET_CLASS (dev); +HotplugHandler *hotplug_ctrl; +HotplugHandlerClass *hdc; + +if (dev->parent_bus && !qbus_is_hotpluggable (dev->parent_bus)) { +error_setg (errp,QERR_BUS_NO_HOTPLUG , dev->parent_bus->name); +return ; + } + +if (!dc->hotpluggable) { +error_setg (errp,QERR_DEVICE_NO_HOTPLUG , +object_get_typename (OBJECT (dev))); +return ; + } + + qdev_hot_removed = true; + + hotplug_ctrl =qdev_get_hotplug_handler (dev); +/* hotpluggable device MUST have HotplugHandler, if it doesn't +* then something is very wrong with it */ +g_assert (hotplug_ctrl); + +/* If device supports async unplug just request it to be done, +* otherwise just remove it synchronously */ + hdc =HOTPLUG_HANDLER_GET_CLASS (hotplug_ctrl); +if (hdc->unplug_request) { +hotplug_handler_unplug_request (hotplug_ctrl, dev, errp); + }else { +hotplug_handler_unplug (hotplug_ctrl, dev, errp); + } +} +void qmp_device_del (const char *id,Error **errp) {DeviceState *dev =find_device_state (id, errp);
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 3/5] qdev: Move qdev_unplug() to qdev-monitor.c
Quoted 8 lines · Juan Quintela
It is not used by linux-user, otherwise I need to to create one stub for
migration_is_idle()on following patch.Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev.c | 34 ---------------------------------- qdev-monitor.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/5] qdev: Move qdev_unplug() to qdev-monitor.c
In reply to Juan QuintelaQuoted 8 lines · Juan Quintela
It is not used by linux-user, otherwise I need to to create one stub for
migration_is_idle()on following patch.Signed-off-by Juan Quintela <[email protected]>--- hw/core/qdev.c | 34 ---------------------------------- qdev-monitor.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-)
Makes sense because its buddy qdev_device_add() is already in qdev-monitor.c.
PATCH v2 4/5 migration: Disable hotplug/unplug during migration
In reply to Juan QuintelaUntil we have reviewed what can/can't be hotplug during migration, disable it. We can enable it later for the things that we know that work. For instance, memory hotplug during postcopy don't work currently.
--
- Fix typo. Thanks Thomas.
- Delay migration check after we have checked that we can hotplug that device.
--- qdev-monitor.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
qdev-monitor.c +11 -0
@@ -29,6 +29,7 @@#include "qemu/error-report.h" #include "qemu/help_option.h" #include "sysemu/block-backend.h" +#include "migration/migration.h" /* * Aliases were a bad idea from the start. Let's keep them
@@ -603,6 +604,11 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)return NULL ; } +if (!migration_is_idle ()) { +error_setg (errp,"device_add not allowed while migrating" ); +return NULL ; + } +/* create device */ dev =DEVICE (object_new (driver));
@@ -853,6 +859,11 @@ void qdev_unplug(DeviceState *dev, Error **errp)return ; } +if (!migration_is_idle ()) { +error_setg (errp,"device_add not allowed while migrating" ); +return ; + } + qdev_hot_removed = true; hotplug_ctrl =qdev_get_hotplug_handler (dev);
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 4/5] migration: Disable hotplug/unplug during migration
Quoted 1 line · Juan Quintela
Until we have reviewed what can/can't be hotplug during migration,
s/hotplug/hotplugged/
Quoted 2 lines
disable it. We can enable it later for the things that we know that work. For instance, memory hotplug during postcopy don't work
s/don't/doesn't/
Quoted 20 lines
currently.
Signed-off-by Juan Quintela <[email protected]>--
qdev-monitor.c +5
-0@@ -603,6 +604,11 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)return NULL ; } +if (!migration_is_idle ()) { +error_setg (errp,"device_add not allowed while migrating" ); +return NULL ; + } +/* create device */ dev =DEVICE (object_new (driver));
qdev-monitor.c void qdev_unplug(DeviceState *dev, Error **errp) · line 863
Quoted 5 lines
qdev-monitor.c +2
-0@@ -853,6 +859,11 @@ void qdev_unplug(DeviceState *dev, Error **errp)return ; } +if (!migration_is_idle ()) { +error_setg (errp,"device_add not allowed while migrating" );
s/device_add/device_del/ ?
Quoted 7 lines
qdev-monitor.c +3
-0+return ; + } + qdev_hot_removed = true; hotplug_ctrl =qdev_get_hotplug_handler (dev);
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 4/5] migration: Disable hotplug/unplug during migration
Quoted 9 lines · Eric Blake
Quoted 1 line · Juan Quintela
Until we have reviewed what can/can't be hotplug during migration,
s/hotplug/hotplugged/
Quoted 2 lines
disable it. We can enable it later for the things that we know that work. For instance, memory hotplug during postcopy don't work
s/don't/doesn't/
Fixed the three typos, thanks.
PATCH v2 5/5 ram: Remove migration_bitmap_extend()
In reply to Juan QuintelaWe have disabled memory hotplug, so we don't need to handle migration_bitamp there.
--- exec.c | 1 - include/exec/ram_addr.h | 2 -- migration/ram.c | 34 ---------------------------------- 3 files changed, 37 deletions(-)
exec.c +0 -1
@@ -1758,7 +1758,6 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) new_ram_size =MAX (old_ram_size, (new_block->offset + new_block->max_length) >>TARGET_PAGE_BITS );if (new_ram_size > old_ram_size) { -migration_bitmap_extend (old_ram_size, new_ram_size);dirty_memory_extend (old_ram_size, new_ram_size); }/* Keep the list sorted from biggest to smallest block. Unlike QTAILQ,
include/exec/ram_addr.h +0 -2
@@ -413,7 +413,5 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest,return num_dirty; } - -void migration_bitmap_extend (ram_addr_t old,ram_addr_t new);#endif #endif
migration/ram.c +0 -34
@@ -1496,40 +1496,6 @@ static void ram_state_reset(RAMState *rs)#define MAX_WAIT 50/* ms, half buffered_file limit */ -void migration_bitmap_extend (ram_addr_t old,ram_addr_t new) -{ -RAMState *rs = &ram_state; - -/* called in qemu main thread, so there is -* no writing race against this migration_bitmap -*/ -if (rs->ram_bitmap) { -RAMBitmap *old_bitmap = rs->ram_bitmap, *bitmap; - bitmap =g_new (RAMBitmap,1 ); - bitmap->bmap =bitmap_new (new); - -/* prevent migration_bitmap content from being set bit -* by migration_bitmap_sync_range() at the same time. -* it is safe to migration if migration_bitmap is cleared bit -* at the same time. -*/ -qemu_mutex_lock (&rs->bitmap_mutex); -bitmap_copy (bitmap->bmap, old_bitmap->bmap, old); -bitmap_set (bitmap->bmap, old, new - old); - -/* We don't have a way to safely extend the sentmap -* with RCU; so mark it as missing, entry to postcopy -* will fail. -*/ - bitmap->unsentmap =NULL ; - -atomic_rcu_set (&rs->ram_bitmap, bitmap); -qemu_mutex_unlock (&rs->bitmap_mutex); - rs->migration_dirty_pages += new - old; -call_rcu (old_bitmap, migration_bitmap_free, rcu); - } -} -/* * 'expected' is the value you expect the bitmap mostly to be full * of; it won't bother printing lines that are all this value.
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH 5/5] ram: Remove migration_bitmap_extend()
Quoted 9 lines · Juan Quintela
We have disabled memory hotplug, so we don't need to handle
migration_bitampthere.Signed-off-by Juan Quintela <[email protected]>--- exec.c | 1 - include/exec/ram_addr.h | 2 -- migration/ram.c | 34 ---------------------------------- 3 files changed, 37 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 15 lines · Juan Quintela
Hi
This updates patches with all the comments received. I move
qdev_unplug()to make linux-user compile.Please, review.
[RFC - v1]
This series disable hotplug/unplug during migration. Thank to Markus for explaining where I had to put the checks. Why? Because during migration we will fail if there are changes. For instance, in postcopy, if we add a memory region, we would failing. Same for other devices if they are not setup exactly the same on destination.
Quoted 5 lines
Iidea would be to disable it, andthen enable for the thing that we know that work.
This series are on top of my previous RAMState v2 serie.
Commets, please?
Make sense, this will benefit COLO too :)
After the types found by Eric be fixed in patch 5,
Quoted 20 lines
Thanks, Juan.
*** BLURB HERE ***
Juan Quintela (5):
qdev:qdev_hotplugis really a bool
qdev: Exportqdev_hot_removed
qdev: Moveqdev_unplug()toqdev-monitor.c
migration: Disable hotplug/unplug during migration
ram: Removemigration_bitmap_extend()exec.c | 1 - hw/core/qdev.c | 40 +++------------------------------------- include/exec/ram_addr.h | 2 -- include/hw/qdev-core.h | 3 ++- migration/ram.c | 34 ---------------------------------- qdev-monitor.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 75 deletions(-)