[Libvir] uuid of newly created domain

Hi! I am running into interesting problem with UUID. I am using Ruby bindings, but I think the problem is not specific to Ruby. I am doing roughly the following: dom = c.define_domain_xml(xml) dom1 = c.ookup_domain_by_uuid(dom.uuid) and I got an error that domain with given UUID is not found. If I print UUID of newly defined domain and compare it with output of 'dominfo' command in virsh I can see that it differs. Could anybody shed some light on why UUID returned by define_domain_xml() is invalid? Sincerely, Vadim -- "La perfection est atteinte non quand il ne reste rien a ajouter, mais quand il ne reste rien a enlever." (Antoine de Saint-Exupery)

On Sat, Mar 29, 2008 at 03:53:22PM -0700, Vadim Zaliva wrote:
I am running into interesting problem with UUID. I am using Ruby bindings, but I think the problem is not specific to Ruby. I am doing roughly the following:
dom = c.define_domain_xml(xml) dom1 = c.ookup_domain_by_uuid(dom.uuid)
and I got an error that domain with given UUID is not found.
If I print UUID of newly defined domain and compare it with output of 'dominfo' command in virsh I can see that it differs.
Could anybody shed some light on why UUID returned by define_domain_xml() is invalid?
That's quite strange. Is this Xen? What does the XML look like? Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top

On Mar 31, 2008, at 3:09, Richard W.M. Jones wrote:
That's quite strange. Is this Xen? What does the XML look like?
Yes, this is XEN 3.2. XML is attached. Vadim -- "La perfection est atteinte non quand il ne reste rien a ajouter, mais quand il ne reste rien a enlever." (Antoine de Saint-Exupery)

On Mar 31, 2008, at 3:09, Richard W.M. Jones wrote:
That's quite strange. Is this Xen? What does the XML look like?
I am trying to track down the problem. One thing I see is that if I define/undefine twice, returned UUID is the same. Does not it have some random component in it (I see some random stuff in uuid.c)? Here is roughly what I am seeing right now: D, [11:29:06#15021] DEBUG -- : xdefine_domain_xml(xml) D, [11:29:06#15021] DEBUG -- : New domain defined with UUID 6911f001-6991-bc1c-e455-11f6f99e3951 D, [11:29:06#15021] DEBUG -- : undefine(6911f001-6991-bc1c- e455-11f6f99e3951) Then, the second attempt, within same process, second later: D, [11:29:33#15021] DEBUG -- : define_domain_xml(xml) D, [11:29:33#15021] DEBUG -- : New domain defined with UUID 6911f001-6991-bc1c-e455-11f6f99e3951 D, [11:29:34#15021] DEBUG -- : undefine(6911f001-6991-bc1c- e455-11f6f99e3951) E, [11:29:34#15021] ERROR -- : unknown error - libvir call virDomainLookupByUUID failed (SystemCallError) after the second attempt, because 'undefine' failed, I can see still defined domain in virsh: virsh # dominfo sample-domain Id: - Name: sample-domain UUID: ccdbf043-cf3d-902b-f08f-1d6a0d571f13 OS Type: linux State: shut off CPU(s): 1 Max memory: 262144 kB Used memory: 262144 kB the UUID is different. So it looks like the "define_domain_xml" returns wrong UUID second time. I am continuing to debug this, any hints are appreciated. Sincerely, Vadim -- "La perfection est atteinte non quand il ne reste rien a ajouter, mais quand il ne reste rien a enlever." (Antoine de Saint-Exupery)

On Mar 31, 2008, at 11:40, Vadim Zaliva wrote:
I am trying to track down the problem.
OK, I have been able to reproduce the problem, is C, without Ruby. Attached is source code and XML file. Here is a sample output: Attempt 0: define Domain defined with UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 lookup by UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 Lookup found domain with UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 undefine Attempt 1: define Domain defined with UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 lookup by UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 libvir: Xen Daemon error : GET operation failed: Failed to lookup by UUID string domain As you can see, it works OK first time, but the second time, returns the same UUID, lookup on which fails. The reason it fails is that the actual UUID is different second time: virsh # dominfo sample-domain-lord Id: - Name: sample-domain-lord UUID: b6eba85c-0f21-f79e-0607-1211d3fb4e36 OS Type: linux State: shut off CPU(s): 1 Max memory: 262144 kB Used memory: 262144 kB I am not sure if I can fix that myself. Sincerely, Vadim -- "La perfection est atteinte non quand il ne reste rien a ajouter, mais quand il ne reste rien a enlever." (Antoine de Saint-Exupery)

On Mon, Mar 31, 2008 at 03:53:09PM -0700, Vadim Zaliva wrote:
On Mar 31, 2008, at 11:40, Vadim Zaliva wrote:
I am trying to track down the problem.
OK, I have been able to reproduce the problem, is C, without Ruby. Attached is source code and XML file. Here is a sample output:
Attempt 0: define Domain defined with UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 lookup by UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 Lookup found domain with UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 undefine
Attempt 1: define Domain defined with UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 lookup by UUID 714b96db-a6b4-a4ea-ad58-39e4b44575c0 libvir: Xen Daemon error : GET operation failed: Failed to lookup by UUID string domain
As you can see, it works OK first time, but the second time, returns the same UUID, lookup on which fails.
The problem is that you are not freeing the virDomainPtr object after you undefine the first VM. Libvirt caches virDomainPtr objects based on the 'name' value. So the second time around you are getting the cached handle. You are also leaking memory. You need to call virDomainFree(virDomainPtr dom) to actually release the handle. Dan. -- |: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Mar 31, 2008, at 16:28, Daniel P. Berrange wrote:
The problem is that you are not freeing the virDomainPtr object after you undefine the first VM. Libvirt caches virDomainPtr objects based on the 'name' value. So the second time around you are getting the cached handle. You are also leaking memory.
You need to call
virDomainFree(virDomainPtr dom)
to actually release the handle.
Thanks for the explanation. I will try this in my code. However, I think this behavior is counter-intuitive. I was expecting that undefining domain should remove it from cache, or creating new domain with same name should replace old definition with a new one. Sincerely, Vadim -- "La perfection est atteinte non quand il ne reste rien a ajouter, mais quand il ne reste rien a enlever." (Antoine de Saint-Exupery)

On Mar 31, 2008, at 16:28, Daniel P. Berrange wrote:
The problem is that you are not freeing the virDomainPtr object after you undefine the first VM. Libvirt caches virDomainPtr objects based on the 'name' value. So the second time around you are getting the cached handle. You are also leaking memory.
You need to call
virDomainFree(virDomainPtr dom)
to actually release the handle.
I could not figure out how this could be expressed via Ruby bindings. This function is called when object is freed, but when it happens is controlled by GC. For example, KDE Ruby binding are using dispose() method paradigm to solve this kind of problem: http://developer.kde.org/language-bindings/ruby/ Should we add one to Domain class? Sincerely, Vadim P.S. I think the Python bindings have the same problem, virDomainPtr() is called from __del__() there. -- "La perfection est atteinte non quand il ne reste rien a ajouter, mais quand il ne reste rien a enlever." (Antoine de Saint-Exupery)

On Mon, Mar 31, 2008 at 06:17:44PM -0700, Vadim Zaliva wrote:
On Mar 31, 2008, at 16:28, Daniel P. Berrange wrote:
You need to call virDomainFree(virDomainPtr dom) to actually release the handle.
I could not figure out how this could be expressed via Ruby bindings. This function is called when object is freed, but when it happens is controlled by GC.
For example, KDE Ruby binding are using dispose() method paradigm to solve this kind of problem:
http://developer.kde.org/language-bindings/ruby/
Should we add one to Domain class? [...] P.S. I think the Python bindings have the same problem, virDomainPtr() is called from __del__() there.
OCaml bindings have the same problem as well, but it's not something I feel any urge to fix there. To me it seems more like a C/libvirt bug. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v

On Wed, 2008-04-02 at 17:24 +0100, Richard W.M. Jones wrote:
OCaml bindings have the same problem as well, but it's not something I feel any urge to fix there. To me it seems more like a C/libvirt bug.
The Ruby bindings now have methods to call virXXXFree manually; but I agree, it feels to me like leaking an implementation detail through the API. David

On Wed, Apr 02, 2008 at 10:01:19AM -0700, David Lutterkort wrote:
On Wed, 2008-04-02 at 17:24 +0100, Richard W.M. Jones wrote:
OCaml bindings have the same problem as well, but it's not something I feel any urge to fix there. To me it seems more like a C/libvirt bug.
The Ruby bindings now have methods to call virXXXFree manually; but I agree, it feels to me like leaking an implementation detail through the API.
Yes, the OCaml bindings too. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v

On Sat, 2008-03-29 at 15:53 -0700, Vadim Zaliva wrote:
I am running into interesting problem with UUID. I am using Ruby bindings, but I think the problem is not specific to Ruby. I am doing roughly the following:
dom = c.define_domain_xml(xml) dom1 = c.ookup_domain_by_uuid(dom.uuid)
and I got an error that domain with given UUID is not found.
Very strange .. I just tried the same, albeit with the KVM backend, and it works fine. The two UUID's are the same, both if the XML used to define it has an explicit UUID, and if it is assigned in the backend. I don't have a Xen host set up right now, so it's probably a silly question: Does Xen assign UUID's when domains are defined, or only once a domain is created ? David
participants (4)
-
Daniel P. Berrange
-
David Lutterkort
-
Richard W.M. Jones
-
Vadim Zaliva