[libvirt] Re: Libvirt PHP binding

Daniel Veillard veillard at redhat.com
Tue Apr 14 15:06:54 UTC 2009


On Tue, Apr 14, 2009 at 03:56:28PM +0200, Radek Hladik wrote:
> So one thing is that every memory allocated by libvirt (using malloc())  
> I need to copy to memory allocated using emalloc(). Also every memory,  
> that would be free()ed by libvirt I need to malloc() and copy from  
> emmaloc()ed memory. The first one is done by simple macro:
>
> #define RECREATE_STRING_WITH_E(str_out, str_in) \	
> 	 str_out = estrndup(str_in, strlen(str_in)); \
> 	 free(str_in);	

  Yeah, that's painful, but there is no good workaround. Trying to
  export an api to register new memory allocation routines for the
  library is usually unpractical because it becomes a global library
  setting. At least in the libxml2 case where I added that's why it's
  actually hard to use in practice except very controlled environments.

> The second case I encountered only on authentication callback and I use  
> simple strndup() to copy it for libvirt.
>
> When running from command line everything seems to work fine. This is of  
> course singlethreaded and potential resource leaks need not to cause a  
> problem. However when running from webserver, the result is much more  
> interesting. When connecting to qemu:///system (via local socket) using
> <?
> libvirt_connect($uri,true);
> ?>
> I can crash the libvirt daemon after cca 10 page reloads - sometimes  
> with message
> Apr 13 15:32:44 kvmtest kernel: libvirtd[8263]: segfault at 4 ip  
> 00000039d7223fc0 sp 00007fa6fbc29a88 error 6 in  
> libdbus-1.so.3.4.0[39d7200000+3c000]
> in system log, sometimes without any message.
> (When running the same script from command line it worked for 1000  
> executions without noticing a problem).
>
> When connecting to qemu+tcp:///system using credentials (explained later):
> <?
> libvirt_connect($uri,true,Array(VIR_CRED_AUTHNAME=>"fred",VIR_CRED_PASSPHRASE=>"fred"));
> ?>
>
> It works but httpd processes open a lot pipes and after a few hours with  
> page refreshing every 10 sec I even ran into error:
> [Mon Apr 13 02:40:26 2009] [error] [client 10.38.25.152] PHP Warning:  
> libvirt_connect()  unable to make pipe: Too many open files

[...]
> libvirt-0.6.0-2.fc11.x86_64

  Don't look further, you need 0.6.2 for this kind of things to not
  crash and burn on any serious reggression tests. forget about 0.6.0 !

> Next issue I am not sure about is callbacks. I need them mainly for  
> authentication. As PHP is intended to run the whole script  
> non-interactively at most times, I've created this solution. When  
> calling the libvirt_connect() PHP function you can provide list of  
> credentials in form of an array  
> Array(VIR_CRED_AUTHNAME=>"fred",VIR_CRED_PASSPHRASE=>"fred"). This PHP  
> array is parsed to C array and this prepopulated array is passed to my  
> authentication callback function. That function receives the requested  
> credential, looks it up in the provided array and returns it. I think  
> this suits more the PHP nature but in future I may provide real callback  
> solution.
> Little trouble is that libvirt free()s the values returned by callback  
> so I need to copy them to malloc()ed memory.
> I am not sure about multithread safety of callback functions but I think  
> that if the function only obtains the parameters via cbdata and operates  
> only with them then it should be safe. However sometimes I get error:
> [Mon Apr 13 14:19:48 2009] [error] [client 10.38.25.152] PHP Warning:  
> libvirt_connect(): Failed to collect auth credentials
> and I need to restart http daemon for a few times to make it work again.

  No idea here, danpb might know more about this.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list