Whit Blauvelt
2011-Jul-25 20:06 UTC
[libvirt-users] Wanted: method for qemu hook script to know if called for migration
Hi, "Before a QEMU guest is started, the qemu hook script is called" (http://libvirt.org/hooks.html)... In writing a simple bash script to prevent a VM on shared storage from being started on one host if it's already running on another, it's easy enough to check if virsh on the other host reports the particular VM as "shut off" there, and go ahead if that's the case. What's I'm having trouble coming up with is a simple method to allow a migration from the second system over to the first with that script in place. As the doc says, /etc/libvirt/hooks/qemu is "Executed when a QEMU guest is started, stopped, or migrated," so when it's simply being started, it makes sense to be sure it's not already running on the second system, and prevent the start if it's not. Works fine for me. But when a migration is requested, the script is called in the same way as when it's being started. What I need is a way, from within the script, to tell whether it's a migration context, so that then the start will be allowed, despite the VM's already being running on the second system. Any ideas how to do that? Unfortunately what's passed to the script directly is just "[vmname] start begin -" in both cases. And I don't see that a separate migrate process shows up in the process tables until after getting beyond the qemu hook script. As a feature suggestion, it would be nice if that fourth input variable, currently "-", was something like "migrate" in this instance. Thanks, Whit
Eric Blake
2011-Jul-25 20:17 UTC
[libvirt-users] Wanted: method for qemu hook script to know if called for migration
On 07/25/2011 02:06 PM, Whit Blauvelt wrote:> In writing a simple bash script to prevent a VM on shared storage from being > started on one host if it's already running on another,Not to distract from your bug report, but have you considered using the new sanlock (0.9.3) or fcntl (0.9.4) lock managers, that do this automatically, without the need for using hook scripts. http://libvirt.org/locking.html> Any ideas how to do that? Unfortunately what's passed to the script directly > is just "[vmname] start begin -" in both cases. And I don't see that a > separate migrate process shows up in the process tables until after getting > beyond the qemu hook script. > > As a feature suggestion, it would be nice if that fourth input variable, > currently "-", was something like "migrate" in this instance.Yes, that is probably a bug worth fixing. -- Eric Blake eblake at redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org