Skip to contentSkip to conversation

migration, xen: Fix block image lock issue on live migration

PATCH Superseded Anthony PERARD 4 participants 6 messages Oct 2, 2017 – Oct 24, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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.

---
CCing libxl maintainers:
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

---
 migration/savevm.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
migration/savevm.c +14 -0
index 4a88228614..69d904c179 100644
@@ -2263,6 +2263,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 (!saved_vm_running) {
+            ret = bdrv_inactivate_all();
+            if (ret) {
+                error_setg(errp, "%s: bdrv_inactivate_all() failed (%d)",
+                           __func__, ret);
+            }
+        }
     }
 
  the_end:
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

Adding in kwolf; it looks sane to me; Kevin?
If I'm reading this right, this is just after the device state save.

Dave

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

Release locks in "xen-save-devices-state" so the destination can takes them.

---
CCing libxl maintainers:
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

---
 migration/savevm.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
migration/savevm.c +14 -0
index 4a88228614..69d904c179 100644
@@ -2263,6 +2263,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 (!saved_vm_running) {
+            ret = bdrv_inactivate_all();
+            if (ret) {
+                error_setg(errp, "%s: bdrv_inactivate_all() failed (%d)",
+                           __func__, ret);
+            }
+        }
     }
 
  the_end:
Signature · 1 line
Anthony PERARD

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

Am 02.10.2017 um 21:18 hat Dr. David Alan Gilbert geschrieben:

Quoted 2 lines

Adding in kwolf; it looks sane to me; Kevin?
If I'm reading this right, this is just after the device state save.

Is this actual migration? Because the code looks more like it's copied and adapted from the snapshot code rather than from the actual migration code.

If Xen doesn't use the standard mechanisms, I don't know what they need to do. Snapshots don't need to inactivate images, but migration does. Compared to the normal migration path, this looks very simplistic, so I wouldn't be surprised if there was more wrong than just file locking.

This looks like it could work as a hack to the problem at hand. Whether it is a proper solution, I can't say without investing a lot more time.

Kevin

Quoted 45 lines · * Anthony PERARD ([email protected]) wrote:
Quoted 44 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.

---
CCing libxl maintainers:
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

---
 migration/savevm.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
migration/savevm.c +14 -0
index 4a88228614..69d904c179 100644
@@ -2263,6 +2263,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 (!saved_vm_running) {
+            ret = bdrv_inactivate_all();
+            if (ret) {
+                error_setg(errp, "%s: bdrv_inactivate_all() failed (%d)",
+                           __func__, ret);
+            }
+        }
     }
 
Quoted 6 lines
Quoted 4 lines
migration/savevm.c +0 -0
  the_end:
Signature · 1 line
Anthony PERARD

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 7 lines · Kevin Wolf

Am 02.10.2017 um 21:18 hat Dr. David Alan Gilbert geschrieben:

Quoted 2 lines

Adding in kwolf; it looks sane to me; Kevin?
If I'm reading this right, this is just after the device state save.

Is this actual migration? Because the code looks more like it's copied and adapted from the snapshot code rather than from the actual migration code.

Well the Xen tool stack takes care of the migration, we only need to save the device states from QEMU, I guess similair to a snapshot.

Quoted 4 lines

If Xen doesn't use the standard mechanisms, I don't know what they need to do. Snapshots don't need to inactivate images, but migration does. Compared to the normal migration path, this looks very simplistic, so I wouldn't be surprised if there was more wrong than just file locking.

I realize now that if one would want to take a snapshot of a running Xen guest, this xen-save-devices-state qmp command will be called as well.

So I can see a few options to better handle snapshots, we could:
- Add a new parameter to xen-save-devices-state, "live_migration" which could default to 'true' so older version of Xen will still works.
- Create a new qmp command that sole purpose is to call bdrv_inactivate_all, I don't know what else this command would have to do.
- or just take this patch.

Thanks.

Quoted 2 lines

This looks like it could work as a hack to the problem at hand. Whether it is a proper solution, I can't say without investing a lot more time.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw
In reply to Anthony PERARD
Quoted 10 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.

What happens if the migration fails on the destination? Will QEMU pick the lock again when resuming on the source in this case?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 9 lines · Roger Pau Monné
Quoted 8 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.

Quoted 5 lines
Quoted 2 lines

Release locks in "xen-save-devices-state" so the destination can takes them.

What happens if the migration fails on the destination? Will QEMU pick the lock again when resuming on the source in this case?

Yes, calling the QMP command "cont" to resume the activity makes QEMU take the lock again, and libxl would call "cont". (I don't think you can pick this kind of lock ;-). )

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel