Bug 204490 - libvirt fails when 'factory' pattern used in python
Summary: libvirt fails when 'factory' pattern used in python
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: libvirt
Version: rawhide
Hardware: All
OS: All
medium
medium
Target Milestone: ---
Assignee: Daniel Veillard
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-08-29 15:00 UTC by Pete Vetere
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-11-09 14:56:45 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Pete Vetere 2006-08-29 15:00:07 UTC
Description of problem:

When using a factory pattern to lookup a domain in python, libvirt produces the
following error:

    libvir: Xen error : failed Xen syscall  ioctl  3166208

Here's some sample code that reproduces the problem (assuming an existing domain
called "mydomain"):

    import libvirt
    def get_domain(dom_name):
        conn = libvirt.openReadOnly(None)
        domain = conn.lookupByName(dom_name)
        return domain
    d = get_domain("mydomain")
    print d.info()

The problem is that the connection object falls out of scope after the
get_domain routine ends, and is therefore garbage collected.  This leaves the
"d" domain object with no valid connection, resulting in the above error
message.  The simple solution would be for the connection object to pass a
reference to itself into each domain object it creates.  The domain objects
would then maintain the reference until they are destroyed.

Comment 1 Daniel Veillard 2006-11-09 14:56:45 UTC
 Fixed in CVS:

paphio:~ -> cat tst.py
#!/usr/bin/python -u

import libvirt
def get_domain(dom_name):
    conn = libvirt.openReadOnly(None)
    domain = conn.lookupByName(dom_name)
    return domain

d = get_domain("rhel5")
print d.info()
paphio:~ -> ./tst.py 
[2, 394240, 393824, 1, 24694771381L]
paphio:~ -> 

  commited upstream with this changelog:

Thu Nov  9 15:39:19 CET 2006 Daniel Veillard <veillard>

        * python/generator.py: changed the generator to generate a reference
          from Domain class instances to the Connect they were issued from
          should fix rhbz#204490

I think it's the simplest and cleanest fix.
 thanks !

Daniel


Note You need to log in before you can comment on or make changes to this bug.