<div class="zcontentRow"> <p><span style="font-size: 12px;">Hi John,</span></p><p><span style="font-size: 12px;">Thanks for your review!</span></p><p><span style="font-size: 12px;">> This seems to be a strange sequence of operations, but the claim is that</span></p><p><span style="font-size: 12px;">> by adding this logic to CreateWithFlags, then the problem you're facing</span></p><p><span style="font-size: 12px;">> is resolved. However, is adding this to the Create logic the right thing</span></p><p><span style="font-size: 12px;">> to do?</span></p><p><span style="font-size: 12px;">> IIUC:</span></p><p><span style="font-size: 12px;">This condition is rare, so I designed some operations which can help us to understand what happened:</span></p><p><span style="font-size: 12px;"># virsh define win7 -> successful</span></p><p><span style="font-size: 12px;"># virsh start win7 &; sleep 0.2; virsh undefine win7 -> start failed and undefine successful</span></p><p><span style="font-size: 12px;"> </span></p><p><span style="font-size: 12px;">and we may see libvirtd output such logs like this:</span></p><p><span style="font-size: 12px;">qemuDomainDefineXMLFlags:7386 : Creating domain win7</span></p><p><span style="font-size: 12px;">qemuProcessStart:6086 : conn=....</span></p><p><span style="font-size: 12px;">qemuDomainUndefineFlags:7501 : Undefining domain win7</span></p><p><span style="font-size: 12px;">error : qemuMonitorOpenUnix:379 : failed to connect to monitor socket</span></p><p><span style="font-size: 12px;"> </span></p><p><span style="font-size: 12px;">Libvirtd unlocked vm during qemuProcessStart, so qemuDomainUndefineFlags can get the lock and undefine vm successfully.</span></p><p><span style="font-size: 12px;">After finishing the above steps, we can get something wrong:</span></p><p><span style="font-size: 12px;"># virsh list --all</span></p><p><span style="font-size: 12px;"> Id    Name                           State</span></p><p><span style="font-size: 12px;">----------------------------------------------------</span></p><p><span style="font-size: 12px;"> -     win7                           shut off</span></p><p><span style="font-size: 12px;"> </span></p><p><span style="font-size: 12px;"># virsh undefine win7</span></p><p><span style="font-size: 12px;">error: Failed to undefine domain win7</span></p><p><span style="font-size: 12px;">error: Requested operation is not valid: cannot undefine transient domain</span></p><p><span style="font-size: 12px;"> </span></p><p><br></p><p><span style="font-size: 12px;">> There's two reasons to get to the endjob: label...</span></p><p><span style="font-size: 12px;">> #1 virDomainObjIsActive (domain already active)</span></p><p><span style="font-size: 12px;">> #2 qemuDomainObjStart fails</span></p><p><span style="font-size: 12px;">> So this certainly wouldn't be right for the IsActive condition, under</span></p><p><span style="font-size: 12px;">> "normal" circumstances. And again, I don't think requiring a subsequent</span></p><p><span style="font-size: 12px;">> call to Start would be "correct" either.  I am curious though if when in</span></p><p><span style="font-size: 12px;">> this condition, is the vm->def->id set?  IOW: What does 'virsh list'</span></p><p><span style="font-size: 12px;">> indicate or even virsh dominfo $domain?</span></p><p><span style="font-size: 12px;">What you said sounds reasonable, I can call qemuDomainObjStart at once after qemuDomainObjStart fails like libvirt does in qemuDomainCreateXML, but end job should be called before qemuDomainRemoveInactive :)</span></p><p><br></p></div>