KVM live migration with sanlock using virsh

Sanlock helps you avoid screwing things up by starting the same virtual machine on multiple hosts, which will quickly mangle the guest file systems. But you may quickly find KVM live migration no longer works from the virt-manager GUI.

I was in shock when I first saw this migration error from virt-manager!

virt manager error dialog

Internal error cannot use migrate v2 protocol with lock manager sanlock? But alas, all is not lost.

Migration from the virsh command shell works just fine for me. And it’s quicker and more efficient than doing it pointy-clicky style from a gui anyway. If i’m migrating a guest from one host to another, it’s usually because I need to shut down the host hardware. I’m not migrating just one guest, i’m migrating one at a time.

With the shell method, I repeat the migration command in a loop and move them all, one after another automatically. Monday migrate, tuesday migrate, everybody. It’ll get in your bones!

root@host1~# for x in 1 2 3 4 5 6 7 8; do
virsh migrate –live guest$x qemu+ssh://host2/system
done

When I first set up sanlock for qemu locking, I saw errors during migration of several hosts that were already up and running with local locking before sanlock locking was implemented.

error: Failed to inquire lock: No such process

There is no impact to the guest or for users connected to the guest. The end result is the migration doesn’t complete and I found the guest still running on the original host. Other guests migrated without error.

A scheduled reboot of the guests allowed migration to proceed. No reboot or disruption to the existing host was required at all.

Leave a Reply

Your email address will not be published. Required fields are marked *