[libvirt-users] Guest startup process blocks if a hook's child process is still running (i.e : after forking)

Nicolas Roy-Renaud nicolas.roy-renaud.1 at ens.etsmtl.ca
Sun Oct 23 21:24:26 UTC 2016


I've been having issues with KVM lately where I sometimes put my host 
into sleep while a guest is still running, which prevents it from waking 
up properly. This is somewhat expected due to my setup, but I have 
mistakenly done this more than once and could use a workaround to stop 
this from happening.

So I've been trying to setup a libvirt hook to fork an instance of 
systemd-inhibit when the start hook is called and keep it running until 
the shutdown hook is called. This seems to work well when I run the hook 
script in a normal bash shell, but running it through libvirt simply 
blocks the starting process until systemd-inhibit quits.

Here's the script :

LOCK_FILE="/tmp/vfio-lock-$OBJECT"

if [ "$OPERATION" == "start" ]; then
	(
		touch "$LOCK_FILE";
		systemd-inhibit --what="sleep" \
		--who="libvirt" \
		--mode="block" \
		inotifywait -qq -e delete "$LOCK_FILE"
	) & disown $!
	exit
fi

if [ "$OPERATION" == "shutdown" ]; then
         rm "$LOCK_FILE"
fi

Is there some way to make it so libvirt sees the hook script exiting and 
carries on with the rest of its guest startup process even after a 
process fork or would that require changes in the internal hook handling 
functions?

- Nicolas




More information about the libvirt-users mailing list