<br><br><div class="gmail_quote">On Wed, Jan 13, 2010 at 2:39 AM, Daniel P. Berrange <span dir="ltr"><<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Tue, Jan 12, 2010 at 04:06:32PM -0800, su disheng wrote:<br>
> Hi,<br>
>     In the following libvirt API calling sequence, I always get an error "no<br>
> domain with matching uuid"<br>
>         Connect _conn = new Connect("qemu:///system", false);<br>
>          _conn.domainDefineXML(kvm_guest_xml);<br>
>          Domain dm = _conn.domainLookupByName(kvm_guest_name);<br>
>          dm.create();<br>
><br>
>          /* stop, undefine, and re-start the vm*/<br>
>          dm.shutdown();<br>
>          dm.undefine();<br>
>          dm.domainDefineXML(kvm_guest_xml);<br>
>          /****A****/<br>
>          Domain dm = _conn.domainLookupByName(kvm_guest_name);<br>
>          dm.create()  /********Error!!!!**/<br>
><br>
>        if I close the connection, and re-connect qemu at the end of<br>
> /****A****/, then everything is OK.<br>
<br>
</div>I think the first 'dm'  object you create is not being freed / garbage<br>
collected. This means the underlying libvirt virDomainPtr object is<br>
not released. And so when you then _conn.domainLookupByName() after<br>
'****A****'  you are still getting an handle to the old object and<br>
thus the stale UUID.<br>
<div class="im"><br></div></blockquote><div><br>Hmm, got it. If free all the returned virDomainPtr, then the issue is gone.<br>One frustrated thing is that the API virDomainDefineXML, which returns a virDomainPtr, I need to explicitly free it, even I don't reference it after that function call... Got me crazy to debug it. Maybe it's better to mention it in the API reference?<br>
<br>Another thing is "/* TODO search by UUID first as they are better differenciators */" in virGetDomain, if libvirt does what it said here, my issue will not be an issue again, right?<br>  </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">
<br>
>        From the log, seems that uuid is not updated immediately, for this<br>
> connection, the uuid is in the stale state?<br>
>        I am using libvirt 0.6.3, if it's a bug, does it fixed in the latest<br>
> code? or Have I need to close the connection for each vm shutdown/re-define?<br>
<br>
</div>You should not need to close the connection, provided you ensure all the<br>
'Domain' objects are freed/garbage collected<br>
<br>
Alternatively, if you wish to re-use the same name,then you could try<br>
auto-generating the  UUID yourself, so you use the same UUID when<br>
defining the domain for the second time<br>
<br>
<br>
Daniel<br>
<font color="#888888">--<br>
|: Red Hat, Engineering, London   -o-   <a href="http://people.redhat.com/berrange/" target="_blank">http://people.redhat.com/berrange/</a> :|<br>
|: <a href="http://libvirt.org" target="_blank">http://libvirt.org</a>  -o-  <a href="http://virt-manager.org" target="_blank">http://virt-manager.org</a>  -o-  <a href="http://ovirt.org" target="_blank">http://ovirt.org</a> :|<br>

|: <a href="http://autobuild.org" target="_blank">http://autobuild.org</a>       -o-         <a href="http://search.cpan.org/%7Edanberr/" target="_blank">http://search.cpan.org/~danberr/</a> :|<br>
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|<br>
</font></blockquote></div><br>