Re: ruby-libvirt issue

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

 



2010/11/24 PaweÅ KrzeÅniak <pawel.krzesniak@xxxxxxxxx>:
> On Tue, Nov 23, 2010 at 14:28, Chris Lalancette <clalance@xxxxxxxxxx> wrote:
>> In terms of making this automatically happen during connection closing, I'm
>> not entirely sure what we can (and should) do. ÂI guess we could keep some sort
>> of list of objects that "depend" on this connection object, and then during
>> connection close Âfree them all up. Does anyone know how the python bindings
>> handle this?
>
> python bindings work more or less the same way (see attachment).
>
> So conclusion is, that all objects must be free() before closing connection.
> It's not so intuitive, so maybe info about that should be somewhere in docs?
>

Actually it is supposed to work correctly as long as you match every
virConnectOpen* call with a virConnectFree call and each call that
returns a virDomainPtr, virStorageVolPtr etc with the corresponding
free call. It should not matter in which order you call the close/free
functions, the internal refcounting should make it work.

Obviously the order seems to matter regarding the output of "netstat
-na | grep -v LISTENING | grep -c libvirt-sock". The problem is not in
the Python or Ruby bindings as I can reproduce it using the C API
(current git version). This might indicate a problem in libvirt.

I attached the test program. With NORMAL_ORDER = 1 the initial value
stays the same, with NORMAL_ORDER = 0 it grows by 1 per iteration.

Matthias
#include <stdio.h>
#include <stdlib.h>
#include <libvirt/libvirt.h>

#define NORMAL_ORDER 1

int main(void)
{
	int ret, i;

	for (i = 0; i < 2; ++i) {
		printf("initial:\n");
		system("netstat -na | grep -v LISTENING | grep -c libvirt-sock");

		virConnectPtr conn = virConnectOpen("qemu:///system");
		printf("after virConnectOpen -> conn=%p:\n", conn);
		system("netstat -na | grep -v LISTENING | grep -c libvirt-sock");

		virDomainPtr domain = virDomainLookupByName(conn, "esxi4");
		printf("after virDomainLookupByName -> domain=%p:\n", domain);
		system("netstat -na | grep -v LISTENING | grep -c libvirt-sock");

#if NORMAL_ORDER
		ret = virDomainFree(domain);
		printf("after virDomainFree -> ret=%d:\n", ret);
		system("netstat -na | grep -v LISTENING | grep -c libvirt-sock");

		ret = virConnectClose(conn);
		printf("after virConnectClose -> ret=%d:\n", ret);
		system("netstat -na | grep -v LISTENING | grep -c libvirt-sock");
#else
		ret = virConnectClose(conn);
		printf("after virConnectClose -> ret=%d:\n", ret);
		system("netstat -na | grep -v LISTENING | grep -c libvirt-sock");

		ret = virDomainFree(domain);
		printf("after virDomainFree -> ret=%d:\n", ret);
		system("netstat -na | grep -v LISTENING | grep -c libvirt-sock");
#endif
	}

	return 0;
}
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]