migration, xen: Fix block image lock issue on live migration
PATCH v2 1/1 migration, xen: Fix block image lock issue on live migration
When doing a live migration of a Xen guest with libxl, the images for block devices are locked by the original QEMU process, and this prevent the QEMU at the destination to take the lock and the migration fail.
Quoted 1 line
From QEMU point of view, once the RAM of a domain is migrated, there is
two QMP commands, "stop" then "xen-save-devices-state", at which point a new QEMU is spawned at the destination.
Release locks in "xen-save-devices-state" so the destination can takes them, if it's a live migration.
This patch add the "live" parameter to "xen-save-devices-state" which default to true so older version of libxenlight can work with newer version of QEMU.
---
Changes in V2:
- add the live parameter
also CCing libxl maintainers:
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
--- migration/savevm.c | 23 ++++++++++++++++++++++- qapi/migration.json | 6 +++++- 2 files changed, 27 insertions(+), 2 deletions(-)
migration/savevm.c +22 -1
@@ -2242,13 +2242,20 @@ int save_snapshot(const char *name, Error **errp)return ret; } -void qmp_xen_save_devices_state (const char *filename,Error **errp) +void qmp_xen_save_devices_state (const char *filename,bool has_live,bool live, +Error **errp) {QEMUFile *f;QIOChannelFile *ioc;int saved_vm_running;int ret; +if (!has_live) { +/* live default to true so old version of Xen tool stack can have a +* successfull live migration */ + live = true; + } + saved_vm_running =runstate_is_running ();vm_stop (RUN_STATE_SAVE_VM );global_state_store_running ();
@@ -2263,6 +2270,20 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp)qemu_fclose (f);if (ret <0 ) {error_setg (errp,QERR_IO_ERROR ); + }else { +/* libxl calls the QMP command "stop" before calling +* "xen-save-devices-state" and in case of migration failure, libxl +* would call "cont". +* So call bdrv_inactivate_all (release locks) here to let the other +* side of the migration take controle of the images. +*/ +if (live && !saved_vm_running) { + ret =bdrv_inactivate_all (); +if (ret) { +error_setg (errp,"%s: bdrv_inactivate_all() failed (%d)" , + __func__, ret); + } + } } the_end:
qapi/migration.json +5 -1
@@ -1075,6 +1075,9 @@ # data. See xen-save-devices-state.txt for a description of the binary # format. # +# @live: Optional argument to ask QEMU to treat this command as part of a live +# migration. Default to true. (since 2.11) +# # Returns: Nothing on success # # Since: 1.1
@@ -1086,7 +1089,8 @@ # <- { "return": {} } # ## -{ 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} } +{ 'command': 'xen-save-devices-state', + 'data': {'filename': 'str', '*live':'bool' } } ## # @xen-set-replication:
Signature · 1 line
Anthony PERARD
Am 16.11.2017 um 16:14 hat Anthony PERARD geschrieben:
Quoted 15 lines
When doing a live migration of a Xen guest with libxl, the images for block devices are locked by the original QEMU process, and this prevent the QEMU at the destination to take the lock and the migration fail.
From QEMU point of view, once the RAM of a domain is migrated, there is two QMP commands, "stop" then "xen-save-devices-state", at which point a new QEMU is spawned at the destination.
Release locks in "xen-save-devices-state" so the destination can takes them, if it's a live migration.
This patch add the "live" parameter to "xen-save-devices-state" which default to true so older version of libxenlight can work with newer version of QEMU.
Quoted 6 lines
Signed-off-by Anthony PERARD <[email protected]>---
Changes in V2:
- add the live parameterCC Kevin Wolf <[email protected]>
Makes sense to me.
Kevin
Quoted 8 lines · * Anthony PERARD ([email protected]) wrote:
When doing a live migration of a Xen guest with libxl, the images for block devices are locked by the original QEMU process, and this prevent the QEMU at the destination to take the lock and the migration fail.
From QEMU point of view, once the RAM of a domain is migrated, there is two QMP commands, "stop" then "xen-save-devices-state", at which point a new QEMU is spawned at the destination.
Quoted 8 lines
Release locks in "xen-save-devices-state" so the destination can takes them, if it's a live migration.
This patch add the "live" parameter to "xen-save-devices-state" which default to true so older version of libxenlight can work with newer version of QEMU.
Signed-off-by Anthony PERARD <[email protected]>
Quoted 88 lines
---
Changes in V2:
- add the live parameterCC Kevin Wolf <[email protected]>also CCing libxl maintainers:
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>--- migration/savevm.c | 23 ++++++++++++++++++++++- qapi/migration.json | 6 +++++- 2 files changed, 27 insertions(+), 2 deletions(-)migration/savevm.c +22
-1@@ -2242,13 +2242,20 @@ int save_snapshot(const char *name, Error **errp)return ret; } -void qmp_xen_save_devices_state (const char *filename,Error **errp) +void qmp_xen_save_devices_state (const char *filename,bool has_live,bool live, +Error **errp) {QEMUFile *f;QIOChannelFile *ioc;int saved_vm_running;int ret; +if (!has_live) { +/* live default to true so old version of Xen tool stack can have a +* successfull live migration */ + live = true; + } + saved_vm_running =runstate_is_running ();vm_stop (RUN_STATE_SAVE_VM );global_state_store_running ();@@ -2263,6 +2270,20 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp)qemu_fclose (f);if (ret <0 ) {error_setg (errp,QERR_IO_ERROR ); + }else { +/* libxl calls the QMP command "stop" before calling +* "xen-save-devices-state" and in case of migration failure, libxl +* would call "cont". +* So call bdrv_inactivate_all (release locks) here to let the other +* side of the migration take controle of the images. +*/ +if (live && !saved_vm_running) { + ret =bdrv_inactivate_all (); +if (ret) { +error_setg (errp,"%s: bdrv_inactivate_all() failed (%d)" , + __func__, ret); + } + } } the_end:qapi/migration.json +5
-1@@ -1075,6 +1075,9 @@ # data. See xen-save-devices-state.txt for a description of the binary # format. # +# @live: Optional argument to ask QEMU to treat this command as part of a live +# migration. Default to true. (since 2.11) +# # Returns: Nothing on success # # Since: 1.1@@ -1086,7 +1089,8 @@ # <- { "return": {} } # ## -{ 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} } +{ 'command': 'xen-save-devices-state', + 'data': {'filename': 'str', '*live':'bool' } } ## # @xen-set-replication:Signature · 1 line
Anthony PERARD
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 20 lines · Anthony PERARD
When doing a live migration of a Xen guest with libxl, the images for block devices are locked by the original QEMU process, and this prevent the QEMU at the destination to take the lock and the migration fail.
From QEMU point of view, once the RAM of a domain is migrated, there is two QMP commands, "stop" then "xen-save-devices-state", at which point a new QEMU is spawned at the destination.
Release locks in "xen-save-devices-state" so the destination can takes them, if it's a live migration.
This patch add the "live" parameter to "xen-save-devices-state" which default to true so older version of libxenlight can work with newer version of QEMU.
Signed-off-by Anthony PERARD <[email protected]>---
Changes in V2:
- add the live parameter
Quoted 5 lines
CC Kevin Wolf <[email protected]>also CCing libxl maintainers:
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
queued