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