[libvirt] Re: Libvirt PHP binding

Daniel P. Berrange berrange at redhat.com
Tue Apr 14 15:00:18 UTC 2009

On Tue, Apr 14, 2009 at 03:56:28PM +0200, Radek Hladik wrote:
> 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.

Crashing the libvirtd daemon is not your fault !  It is supposed to be
completely robust against whatever bad stuff the client may throw at
it. So even if the client has a bug, then it shouldn't crash the daemon.

If possible it'd be helpful if you can get a stack trace from the daemon.
You can do this by stopping the demon '/etc/init.d/libvirtd stop' and
then running it under GDB directly

  'gdb /usr/sbin/libvirtd'

make sure you have libvirt-debuginfo RPM installed if using Fedora, or 
have built with '-g' debug option if built manually.

> 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] PHP Warning: 
> libvirt_connect()  unable to make pipe: Too many open files

This is interesting. It suggests that the virConnectPtr  object you
have created is not being relased. Each object will require at least
2 file descriptors, so if they're not released, then either the 
libvirtd daemon, or the PHP client, or the OS as a whole will run
out of file descriptors and start showing this error message.

> And if you are still reading then I can point you to 
> http://phplibvirt.cybersales.cz/ where you can download the source code 
> and browse the documentation - you can find there list of implemented 
> functions and brief instructions how to install the extension. But be 
> warned it really can crash your libvirt and maybe apache! For 
> completeness: I use Fedora 10 with some rawhide updates:
> httpd-2.2.11-6.x86_64
> php-5.2.9-1.fc11.x86_64
> php-devel-5.2.9-1.fc11.x86_64
> libvirt-0.6.0-2.fc11.x86_64
> qemu-0.9.1-12.fc11.x86_64
> libvirt-devel-0.6.0-2.fc11.x86_64

I'd recommend updating to the latest libvirt 0.6.2 release that should be
available in rawhide now. It fixed quite a few crashes & leaks, which 
you may be unlucky enough to be hitting

|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

More information about the libvir-list mailing list