[libvirt] Connection release is not correct in libvirt and libvrt java
Benjamin Wang (gendwang)
gendwang at cisco.com
Tue Dec 18 15:14:20 UTC 2012
Hi,
The following is the current code to release connection in libvirt.
int
virConnectClose(virConnectPtr conn)
{
...
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
goto error;
}
...
error:
virDispatchError(NULL);
return ret;
}
Now if the cable is unplugged and the application call virConnectClose to release connection, the code will enter into the error procedure, the connection
Can't be released. I have changed the following two parts to fix this issue. Please give your comments:
Changed Code1:
int
virConnectClose(virConnectPtr conn)
{
...
+ if(NULL == conn) {
+ return 0;
+ }
...
- if (!VIR_IS_CONNECT(conn)) {
- virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
- goto error;
- }
...
error:
virDispatchError(NULL);
return ret;
}
Changed Code2:
int
virUnrefConnect(virConnectPtr conn) {
...
+ if(NULL == conn) {
+ return 0;
+ }
- if ((!VIR_IS_CONNECT(conn))) {
- virLibConnError(VIR_ERR_INVALID_ARG, _("no connection"));
- return -1;
- }
...
}
For libvirt java, there are similar issue. I have changed code as following in Collect.java. Please also give your comments.
public int close() throws LibvirtException {
int success = 0;
if (VCP != null) {
+ try {
success = libvirt.virConnectClose(VCP);
processError();
+ }
+ finally {
// If leave an invalid pointer dangling around JVM crashes and burns
// if someone tries to call a method on us
// We rely on the underlying libvirt error handling to detect that
// it's called with a null virConnectPointer
VCP = null;
+ }
}
return success;
}
B.R.
Benjamin Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20121218/ab565d1b/attachment-0001.htm>
More information about the libvir-list
mailing list