Greetings Peter, > Sent: Friday, January 04, 2019 at 4:47 PM > From: "Peter Krempa" <pkrempa@xxxxxxxxxx> > To: daggs <daggs@xxxxxxx> > Cc: libvirt-users@xxxxxxxxxx > Subject: Re: script called from qemu hook freezes. > > On Thu, Jan 03, 2019 at 18:07:58 +0100, daggs wrote: > > Greetings, > > > > I'm executing an external script when the qemu hook is called with start or release, the script is rather simple, upon start it iterates over the output of lsusb -t and for each device, it looks if it should be added to the vm we started, if so, it attaches it to the vm as follows: > > virsh --connect qemu:///system "${cmd}" "${domain}" /dev/stdin << END > > <hostdev mode='subsystem' type='usb'> > > <source> > > <address bus='${busnum}' device='${devnum}' /> > > </source> > > </hostdev> > > END > > > > where cmd is attach-device, domain is the vm's name, busnum and devnum come from the output of the lsusb -t. > > my issue is that upon the first attach attempt, the cmd hangs, I need to kill it and after than I cannot preform any virsh cmd, I must restart the host. > > if I try to execute the same cmd after the vm is up, it works great. > > > > why the attach process gets stuck? do I need to execute it under different stage? > > Hook scripts shall never call any libvirt API (even through virsh). At > the point when the hook script is called the VM startup process is > paused until the script returns. If the script attempts to modify the VM > it gets stuck as the VM is locked at that point. > > You either need to add the device prior to startup, but AFAIK that is > not possible with a hook script or after but the script needs to return. > > So you either fork off a process which will wait for the startup to > finish from the hook script or write an APP using the libvirt API which > will wait for the VM start event and then execute what's necessary. > I see, is there another way to do what I need (on startup usb hotplug) or maybe optional hotplug (e.g. don't fail the device isn't present)? _______________________________________________ libvirt-users mailing list libvirt-users@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvirt-users