[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] [PATCH] Python bindings: Use virDomain/NetworkGetConnect instead of storing connection in domain/network object



Daniel P. Berrange wrote:
On Mon, Jul 23, 2007 at 05:11:09PM +0100, Richard W.M. Jones wrote:
This is my test case:

------------------------------------------
#!/usr/bin/python

import libvirt

def get_dom():
    conn = libvirt.open ("xen");
    dom = conn.lookupByName ("debian32fv");
    return dom

dom = get_dom()
print "name = %s\n" % dom.name()
------------------------------------------

I would say that it's working as intended.

In this case yes, but if you add one further line at the end of
this example

   conn2  = dom.get_connection()

And then have python garbage collect 'dom' and the original 'conn'
you're not safe because 'conn2' didn't increment the reference
count:

I finally managed to reproduce this. For reference, the reproduction code is below:

--------------------
#!/usr/bin/python

import libvirt
import libvirtmod

def get_dom():
    conn = libvirt.open ("xen");
    dom = conn.lookupByName ("debian32fv");
    return dom

dom = get_dom()
print "name = %s" % dom.name()

conn2 =
  libvirt.virConnect (_obj = libvirtmod.virDomainGetConnect (dom._o))
dom2 = conn2.lookupByName ("debian32fv")
--------------------

This crashes at the last line because virConnectClose was called in the destructor of conn.

It doesn't seem like changing virDomainGetConnect to play with reference counts will fix this. The damage was done when virConnectClose was called, which happened much earlier. The only solution is to keep the relation that domain contains a connection explicit in the Python code. Same probably applies to OCaml bindings too.

/*
 * virDomainGetConnect:
 * @dom: pointer to a domain
 *
 * Provides the connection pointer associated with a domain.  The
 * reference counter on the connection is not increased by this
 * call.
 */

For this reason also I suggest that we remove virDomainGetConnect and virNetworkGetConnect calls entirely, to prevent anyone from thinking they can use them in a safe way. Patch is attached, and yes I know in this case it breaks strict ABI compatibility.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: include/libvirt/libvirt.h.in
===================================================================
RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h.in,v
retrieving revision 1.31
diff -u -p -r1.31 libvirt.h.in
--- include/libvirt/libvirt.h.in	18 Jul 2007 10:11:10 -0000	1.31
+++ include/libvirt/libvirt.h.in	24 Jul 2007 14:14:48 -0000
@@ -288,11 +288,6 @@ int			virConnectNumOfDomains	(virConnect
 
 
 /*
- * Get connection from domain.
- */
-virConnectPtr		virDomainGetConnect     (virDomainPtr domain);
-
-/*
  * Domain creation and destruction
  */
 virDomainPtr		virDomainCreateLinux	(virConnectPtr conn,
@@ -521,11 +516,6 @@ typedef struct _virNetwork virNetwork;
 typedef virNetwork *virNetworkPtr;
 
 /*
- * Get connection from network.
- */
-virConnectPtr		virNetworkGetConnect    (virNetworkPtr network);
-
-/*
  * List active networks
  */
 int			virConnectNumOfNetworks	(virConnectPtr conn);
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.90
diff -u -p -r1.90 libvirt.c
--- src/libvirt.c	17 Jul 2007 14:40:26 -0000	1.90
+++ src/libvirt.c	24 Jul 2007 14:14:50 -0000
@@ -743,28 +743,6 @@ virConnectNumOfDomains(virConnectPtr con
 }
 
 /**
- * virDomainGetConnect:
- * @dom: pointer to a domain
- *
- * Provides the connection pointer associated with a domain.  The
- * reference counter on the connection is not increased by this
- * call.
- *
- * Returns the virConnectPtr or NULL in case of failure.
- */
-virConnectPtr
-virDomainGetConnect (virDomainPtr dom)
-{
-    DEBUG("dom=%p", dom);
-
-    if (!VIR_IS_DOMAIN (dom)) {
-        virLibDomainError (dom, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        return NULL;
-    }
-    return dom->conn;
-}
-
-/**
  * virDomainCreateLinux:
  * @conn: pointer to the hypervisor connection
  * @xmlDesc: an XML description of the domain
@@ -2317,28 +2295,6 @@ virDomainDetachDevice(virDomainPtr domai
 }
 
 /**
- * virNetworkGetConnect:
- * @net: pointer to a network
- *
- * Provides the connection pointer associated with a network.  The
- * reference counter on the connection is not increased by this
- * call.
- *
- * Returns the virConnectPtr or NULL in case of failure.
- */
-virConnectPtr
-virNetworkGetConnect (virNetworkPtr net)
-{
-    DEBUG("net=%p", net);
-
-    if (!VIR_IS_NETWORK (net)) {
-        virLibNetworkError (net, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
-        return NULL;
-    }
-    return net->conn;
-}
-
-/**
  * virConnectNumOfNetworks:
  * @conn: pointer to the hypervisor connection
  *
Index: docs/libvir.html
===================================================================
RCS file: /data/cvs/libvirt/docs/libvir.html,v
retrieving revision 1.73
diff -u -p -r1.73 libvir.html
--- docs/libvir.html	16 Jul 2007 21:37:08 -0000	1.73
+++ docs/libvir.html	24 Jul 2007 14:14:52 -0000
@@ -2837,11 +2837,6 @@ updated on <i>2007-06-29</i>.
   <td> &ge; 0.3.0 </td>
 </tr>
 <tr>
-  <td> virDomainGetConnect </td>
-  <td> 0.3.0 </td>
-  <td colspan="4"> not a HV function </td>
-</tr>
-<tr>
   <td> virDomainGetID </td>
   <td> All </td>
   <td> All </td>
@@ -3140,9 +3135,6 @@ first appeared in libvirt 0.2.0.
   <td> virNetworkGetAutostart </td> <td> 0.2.1 </td>
 </tr>
 <tr>
-  <td> virNetworkGetConnect </td> <td> 0.3.0 </td>
-</tr>
-<tr>
   <td> virNetworkGetBridgeName </td> <td> 0.2.0 </td>
 </tr>
 <tr>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]