Re: Error connecting to virConnectOpen("qemu:///system"); after 20 times

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

 



Thanks it worked.

Regards,
Pankaj Rawat
NECHCLST

-----Original Message-----
From: Daniel P. Berrange [mailto:berrange@xxxxxxxxxx]
Sent: 22 January 2013 17:13
To: Pankaj Rawat
Cc: libvir-list@xxxxxxxxxx
Subject: Re:  Error connecting to virConnectOpen("qemu:///system"); after 20 times

On Tue, Jan 22, 2013 at 11:31:27AM +0000, Pankaj Rawat wrote:
> Hi,
> I am using libvirt api to create an app, I am facing a problem.
> I can connect to connection object 20 number of times in programm
> after that it gives connection object null.

By default libvirtd has a limit of 20 concurrent active connections/

> Here is the sample code.
>
> Normally code should run 1000 times but it only runs 20 times
> Filename: list.cpp
>
> #include<pthread.h>
> #include<stdlib.h>
> #include<stdio.h>
> #include<malloc.h>
> #include <iostream>
> #include<string.h>
> #include <libvirt/libvirt.h>
> #include <libvirt/virterror.h>
> static int count;
>     static void customErrorFunc(void *userdata, virErrorPtr err)
>     {
>     }
>
> int main()
> {
>     virConnectPtr conn;
>
>   for ( int i=0; i< 1000;i++)
>   {
>      conn = virConnectOpen("qemu:///system");
>      if (conn == NULL) {
>         fprintf(stderr, "Failed to open connection to qemu:///system\n");
>         printf("Failed to open connection to qemu:///system\n");
>         virConnectClose(conn);
>         return NULL;
>         }
>         printf("Hello %d\n",i);
>         virError err;
>         virSetErrorFunc(NULL, customErrorFunc);
>         int j;
>         int numDomains1,numDomains2,numDomains;
>         int *activeDomains;
>         numDomains1 = virConnectNumOfDomains(conn);
>         activeDomains = (int*)malloc(sizeof(int) * numDomains1);
>         numDomains1 = virConnectListDomains(conn, activeDomains, numDomains1);
>         for (int j = 0 ; j < numDomains1 ; j++)
>         {
>                 virDomainPtr dom;
>                 dom = virDomainLookupByID(conn,activeDomains[j]);
>                 free(dom);

You should be using virDomainFree(dom), not 'free(dom)' The latter is leaking memory & loosing the reference on virConnectPtr causing the connection to be left open. Hence you are hitting the 20 conn limit.

>         }
>         free(activeDomains);
>         count--;
>         virConnectClose(conn);
>    }
> }

Daniel
--
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|



DISCLAIMER:

-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and
intended

for the named recipient(s) only. 

It shall not attach any liability on the originator or NECHCL or its

affiliates. Any views or opinions presented in 

this email are solely those of the author and may not necessarily reflect the

opinions of NECHCL or its affiliates. 

Any form of reproduction, dissemination, copying, disclosure, modification,

distribution and / or publication of 

this message without the prior written consent of the author of this e-mail is

strictly prohibited. If you have 

received this email in error please delete it and notify the sender

immediately. .

-----------------------------------------------------------------------------------------------------------------------

--
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]