[libvirt-users] libvirt prepare and start hooks not callled

Hello, I am using RHEL 7.1 and libvirt 1.2.8. My intention is to intercept the prepare and start hooks of libvirt during VM placement to inject a virtio PCI device into the VM's domain xml. I placed a python script with execute permissions in /etc/libvirt/hooks/qemu. In there, I opened a log file to record the arguments received: log.write("avfd called with args: %s\n" % sys.argv) But all I get in the log file is: avfd called with args: ['/etc/libvirt/hooks/qemu', 'vm1', 'started', 'begin', '-'] There are no prepare or start calls. Can somebody explain what it takes to fix this? Cheers, Sundar ________________________________ Confidentiality Notice. This message may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution, or copying of this message, or any attachments, is strictly prohibited. If you have received this message in error, please advise the sender by reply e-mail, and delete the message and any attachments. Thank you.

Hi. On Fri, Nov 13, 2015 at 20:44:15 +0000, Sundar Nadathur wrote:
I am using RHEL 7.1 and libvirt 1.2.8. My intention is to intercept the prepare and start hooks of libvirt during VM placement to inject a virtio PCI device into the VM's domain xml.
You are not supposed to talk to libvirtd from any hooks.
I placed a python script with execute permissions in /etc/libvirt/hooks/qemu. In there, I opened a log file to record the arguments received: log.write("avfd called with args: %s\n" % sys.argv)
But all I get in the log file is: avfd called with args: ['/etc/libvirt/hooks/qemu', 'vm1', 'started', 'begin', '-']
There are no prepare or start calls. Can somebody explain what it takes to fix this?
If you're trying to update the domain's configuration from the hook, you caused a deadlock between libvirt and your hook. Thus your hook script will never finish and libvirtd will be waiting for the hook to finish and it will never start the domain. Jirka

Hello Jirka, The script is not even invoked for prepare/start calls, not that it is invoking libvirt APIs or is hanging. When it is invoked for 'started', it runs to completion. I did notice the warning about talking to libvirt from the hooks. However, if the script were to be invoked, I will only be writing the modified xml to stdout. This is based on: https://libvirt.org/hooks.html For migrate and restore calls, "the script acts as a filter and is supposed to modify the domain XML and print it out on its standard output". I am hoping the same method will work for prepare or start calls. If there is a better way to update the VM's xml before it is launched, please let me know. Thank you for the response. Regards, Sundar -----Original Message----- From: Jiri Denemark [mailto:jdenemar@redhat.com] Sent: Monday, November 16, 2015 4:27 AM To: Sundar Nadathur Cc: libvirt-users@redhat.com Subject: Re: [libvirt-users] libvirt prepare and start hooks not callled Hi. On Fri, Nov 13, 2015 at 20:44:15 +0000, Sundar Nadathur wrote:
I am using RHEL 7.1 and libvirt 1.2.8. My intention is to intercept the prepare and start hooks of libvirt during VM placement to inject a virtio PCI device into the VM's domain xml.
You are not supposed to talk to libvirtd from any hooks.
I placed a python script with execute permissions in /etc/libvirt/hooks/qemu. In there, I opened a log file to record the arguments received: log.write("avfd called with args: %s\n" % sys.argv)
But all I get in the log file is: avfd called with args: ['/etc/libvirt/hooks/qemu', 'vm1', 'started', 'begin', '-']
There are no prepare or start calls. Can somebody explain what it takes to fix this?
If you're trying to update the domain's configuration from the hook, you caused a deadlock between libvirt and your hook. Thus your hook script will never finish and libvirtd will be waiting for the hook to finish and it will never start the domain. Jirka ________________________________ Confidentiality Notice. This message may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution, or copying of this message, or any attachments, is strictly prohibited. If you have received this message in error, please advise the sender by reply e-mail, and delete the message and any attachments. Thank you.

On Mon, Nov 16, 2015 at 12:43:21 +0000, Sundar Nadathur wrote:
Hello Jirka, The script is not even invoked for prepare/start calls, not that it is invoking libvirt APIs or is hanging. When it is invoked for 'started', it runs to completion.
Strange. Do you see corresponding "Calling hook" messages in libvirtd debug logs? (See http://wiki.libvirt.org/page/DebugLogs for instructions how to enable debug logs.)
I did notice the warning about talking to libvirt from the hooks. However, if the script were to be invoked, I will only be writing the modified xml to stdout. This is based on: https://libvirt.org/hooks.html For migrate and restore calls, "the script acts as a filter and is supposed to modify the domain XML and print it out on its standard output".
I am hoping the same method will work for prepare or start calls.
No, the hook only works as a filter for migrate and restore calls.
If there is a better way to update the VM's xml before it is launched, please let me know.
There is, just redefine the XML before starting the domain. There's no way of doing this via hooks. Jirka

Hello, Is there a reason why the prepare and start hooks cannot modify the domain xml? One would think it is a common use case to inject a device or some content at VM creation time. Thank you very much. Cheers, Sundar -----Original Message----- From: Jiri Denemark [mailto:jdenemar@redhat.com] Sent: Monday, November 16, 2015 5:17 AM To: Sundar Nadathur Cc: 'libvirt-users@redhat.com' Subject: Re: [libvirt-users] libvirt prepare and start hooks not callled On Mon, Nov 16, 2015 at 12:43:21 +0000, Sundar Nadathur wrote:
Hello Jirka, The script is not even invoked for prepare/start calls, not that it is invoking libvirt APIs or is hanging. When it is invoked for 'started', it runs to completion.
Strange. Do you see corresponding "Calling hook" messages in libvirtd debug logs? (See http://wiki.libvirt.org/page/DebugLogs for instructions how to enable debug logs.)
I did notice the warning about talking to libvirt from the hooks. However, if the script were to be invoked, I will only be writing the modified xml to stdout. This is based on: https://libvirt.org/hooks.html For migrate and restore calls, "the script acts as a filter and is supposed to modify the domain XML and print it out on its standard output".
I am hoping the same method will work for prepare or start calls.
No, the hook only works as a filter for migrate and restore calls.
If there is a better way to update the VM's xml before it is launched, please let me know.
There is, just redefine the XML before starting the domain. There's no way of doing this via hooks. Jirka ________________________________ Confidentiality Notice. This message may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution, or copying of this message, or any attachments, is strictly prohibited. If you have received this message in error, please advise the sender by reply e-mail, and delete the message and any attachments. Thank you.

On Thu, Nov 19, 2015 at 21:32:05 +0000, Sundar Nadathur wrote:
Hello, Is there a reason why the prepare and start hooks cannot modify the domain xml?
Because they were not designed that way. It's already too late to change the domain definition in any of the hooks.
One would think it is a common use case to inject a device or some content at VM creation time.
Not really, there's no reason to do anything like that. You can just change the XML before starting it. Or you can use transient domains if you want domain XMLs to be generated dynamically. It would certainly be possible to add a new hook which would work as a filter when starting a new domain, but using existing methods may be easier. Both migrate and restore hooks were designed as filters because they are (in case of migration) or can be (in case of restore) called on a different host where, e.g., disk image files are mounted in a different path. Jirka
participants (2)
-
Jiri Denemark
-
Sundar Nadathur