[libvirt] [libvirt-php] libvirt_connect not reading out credential info on 0.5.2

I'm running libvirt-php 0.5.2 on CentOS 7 with libvirt 2.1.0. Using virsh I'm able to connect to hyper-v hosts correctly but using libvirt-php it fails during authentication since it seems that the credentials are not being passed along. This is the php code I'm using: <?php $logfile = 'test.log'; unlink($logfile); if (!libvirt_logfile_set($logfile)) die('Cannot set the log file'); $connstr = 'hyperv://user@hyperv-host/?transport=http'; $credentials = array(VIR_CRED_AUTHNAME=>'Administrator',VIR_CRED_PASSPHRASE=>'somepass'); $conn = libvirt_connect($connstr, false, $credentials); echo libvirt_get_last_error(); unset($conn); $fp = fopen($logfile, 'r'); $str = fread($fp, filesize($logfile)); fclose($fp); echo '<pre>'; echo $str; print_r($credentials); echo '</pre>'; ?> And this is the output: authentication failed: Password request failed [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Found 0 elements for credentials [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: cred 0, type 5, prompt Enter Administrator's password for hyperv-host challenge hyperv-host [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: result (null) (0) [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Cannot establish connection to hyperv://Administrator@hyperv-host/?transport=http Array ( [2] => Administrator [5] => somepass ) Note the "Found 0 elements for credentials". After doing some googling I found an email thread "[libvirt] [libvirt-php PATCH 0/3] Fix PHP5 compatibilty issues." that I think is related to my problem, especially patch 2/3. I also checked github project and saw that those patches are already merged in the code so I went ahead and apply them to 0.5.2 source code and rebuild: use VIRT_FOREACH macros everywhere - Commit: f4b760d libvirt_connect: use loop macros to read cred info - Commit: d704106 Define macros for looping php hash tables - Commit: 673a0bf The build went fine but now when I'm trying to connect to the hyper-v host using libvirt-php I get an internal server error (500) so it seems PHP is crashing. From the system log I see: kernel: traps: php-cgi[43452] general protection ip:7f63907f74a0 sp:7fff12d61f68 error:0 in libvirt.so.0.2001.0[7f6390735000+385000] Is there any other patch that I'm missing? Any ideas on how to fix the libvirt_connect credentials issue without applying the patches above? Sofware versions: OS: CentOS Linux release 7.2.1511 (Core) Kernel: 3.10.0-327.28.2.el7.x86_64 PHP: 5.4.16-36.3.el7_2.x86_64 libvirt: 2.1.0-4.1.x86_64 libvirt-php: 0.5.2 Thanks in advance for your replies. Fer

On 02.09.2016 11:11, Fernando Casas Schössow wrote:
I'm running libvirt-php 0.5.2 on CentOS 7 with libvirt 2.1.0. Using virsh I'm able to connect to hyper-v hosts correctly but using libvirt-php it fails during authentication since it seems that the credentials are not being passed along.
This is the php code I'm using:
<?php $logfile = 'test.log';
unlink($logfile); if (!libvirt_logfile_set($logfile)) die('Cannot set the log file');
$connstr = 'hyperv://user@hyperv-host/?transport=http'; $credentials = array(VIR_CRED_AUTHNAME=>'Administrator',VIR_CRED_PASSPHRASE=>'somepass'); $conn = libvirt_connect($connstr, false, $credentials); echo libvirt_get_last_error(); unset($conn);
$fp = fopen($logfile, 'r'); $str = fread($fp, filesize($logfile)); fclose($fp);
echo '<pre>'; echo $str; print_r($credentials); echo '</pre>'; ?>
Unfortunately, I don't have a hyperv instance to try this out, but for other connection URIs (like qemu:///system) this works for me.
And this is the output:
authentication failed: Password request failed
[2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Found 0 elements for credentials [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: cred 0, type 5, prompt Enter Administrator's password for hyperv-host challenge hyperv-host [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: result (null) (0) [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Cannot establish connection to hyperv://Administrator@hyperv-host/?transport=http Array ( [2] => Administrator [5] => somepass )
Note the "Found 0 elements for credentials". After doing some googling I found an email thread "[libvirt] [libvirt-php PATCH 0/3] Fix PHP5 compatibilty issues." that I think is related to my problem, especially patch 2/3. I also checked github project and saw that those patches are already merged in the code so I went ahead and apply them to 0.5.2 source code and rebuild:
use VIRT_FOREACH macros everywhere - Commit: f4b760d libvirt_connect: use loop macros to read cred info - Commit: d704106 Define macros for looping php hash tables - Commit: 673a0bf
The build went fine but now when I'm trying to connect to the hyper-v host using libvirt-php I get an internal server error (500) so it seems PHP is crashing. From the system log I see:
kernel: traps: php-cgi[43452] general protection ip:7f63907f74a0 sp:7fff12d61f68 error:0 in libvirt.so.0.2001.0[7f6390735000+385000]
If you could attach a debugger and get a stack trace where this is happening that'd be great.
Is there any other patch that I'm missing?
Doesn't look like it, but if you could try the current git HEAD that would help. I mean, if you see the error even with that the bug is still there.
Any ideas on how to fix the libvirt_connect credentials issue without applying the patches above?
I should probably do a release soon. Not that there was a much movement since the last one though. Michal

Thanks for your reply Michal. Actually you don't need a Hyper-V server to reproduce the problem since the connection to the server is never initiated because the process crash before that stage (got wireshark on the network to confirm this). So you should be able to reproduce the problem without a Hyper-V server, just using the same PHP code I'm using (or any other hyperv URI for that matter). ============================================================================================================== Following your advice I attached strace to the PHP processes and reproduced the issue. This is the trace result: Process 34978 attached Process 34979 attached Process 34981 attached Process 34983 attached Process 34984 attached Process 34986 attached Process 34987 attached Process 34989 attached [pid 34989] accept(0, <unfinished ...> [pid 34987] wait4(-1, <unfinished ...> [pid 34986] accept(0, <unfinished ...> [pid 34981] accept(0, <unfinished ...> [pid 34979] wait4(-1, <unfinished ...> [pid 34978] wait4(-1, <unfinished ...> [pid 34984] wait4(-1, <unfinished ...> [pid 34983] accept(0, <unfinished ...> [pid 34989] <... accept resumed> {sa_family=AF_LOCAL, NULL}, [2]) = 4 [pid 34989] poll([{fd=4, events=POLLIN}], 1, 5000) = 1 ([{fd=4, revents=POLLIN}]) [pid 34989] read(4, "\1\1\0\1\0\10\0\0", 8) = 8 [pid 34989] read(4, "\0\1\0\0\0\0\0\0", 8) = 8 [pid 34989] read(4, "\1\4\0\1\2\351\0\0", 8) = 8 [pid 34989] read(4, "\17\10SERVER_SOFTWARElighttpd\v\fSERVE"..., 745) = 745 [pid 34989] read(4, "\1\4\0\1\0\0\0\0", 8) = 8 [pid 34989] lstat("/storage/lighttpd/wwwroot/libvirt.php", {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] lstat("/storage/lighttpd/wwwroot", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 [pid 34989] lstat("/storage/lighttpd", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0 [pid 34989] lstat("/storage", {st_mode=S_IFDIR|0755, st_size=31, ...}) = 0 [pid 34989] gettimeofday({1473102621, 318809}, NULL) = 0 [pid 34989] stat("/storage/lighttpd/wwwroot/.user.ini", 0x7ffc541fcbe0) = -1 ENOENT (No such file or directory) [pid 34989] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0 [pid 34989] rt_sigaction(SIGPROF, {0x7f9772bbb970, [PROF], SA_RESTORER|SA_RESTART, 0x7f976f07b670}, {SIG_DFL, [], 0}, 8) = 0 [pid 34989] rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0 [pid 34989] open("/storage/lighttpd/wwwroot/libvirt.php", O_RDONLY) = 5 [pid 34989] fstat(5, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] fstat(5, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] fstat(5, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] mmap(NULL, 633, PROT_READ, MAP_SHARED, 5, 0) = 0x7f9772959000 [pid 34989] getcwd("/usr/bin", 4095) = 9 [pid 34989] chdir("/storage/lighttpd/wwwroot") = 0 [pid 34989] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={14400, 0}}, NULL) = 0 [pid 34989] munmap(0x7f9772959000, 633) = 0 [pid 34989] close(5) = 0 [pid 34989] unlink("test.log") = 0 [pid 34989] access("test.log", F_OK) = -1 ENOENT (No such file or directory) [pid 34989] open("test.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 5 [pid 34989] lseek(5, 0, SEEK_END) = 0 [pid 34989] dup3(5, 2, 0) = 2 [pid 34989] close(5) = 0 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] fstat(2, {st_mode=S_IFREG|0755, st_size=0, ...}) = 0 [pid 34989] mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9772956000 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 80) = 80 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 80) = 80 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 93) = 93 [pid 34989] futex(0x7f976ae3cb18, FUTEX_WAKE_PRIVATE, 2147483647) = 0 [pid 34989] futex(0x7f976ae3d078, FUTEX_WAKE_PRIVATE, 2147483647) = 0 [pid 34989] geteuid() = 997 [pid 34989] geteuid() = 997 [pid 34989] socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 5 [pid 34989] connect(5, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) [pid 34989] close(5) = 0 [pid 34989] socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 5 [pid 34989] connect(5, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) [pid 34989] close(5) = 0 [pid 34989] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 34989] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 34989] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9772955000 [pid 34989] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 34989] close(5) = 0 [pid 34989] munmap(0x7f9772955000, 4096) = 0 [pid 34989] access("/var/www/lighttpd/.config/libvirt/libvirt.conf", F_OK) = -1 ENOENT (No such file or directory) [pid 34989] geteuid() = 997 [pid 34989] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 34989] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 34989] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9772955000 [pid 34989] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 34989] close(5) = 0 [pid 34989] munmap(0x7f9772955000, 4096) = 0 [pid 34989] access("/var/www/lighttpd/.config/libvirt/auth.conf", R_OK) = -1 ENOENT (No such file or directory) [pid 34989] access("/etc/libvirt/auth.conf", R_OK) = -1 EACCES (Permission denied) [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 168) = 168 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 104) = 104 [pid 34989] open("/etc/openwsman/openwsman_client.conf", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 34989] --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} --- [pid 34989] +++ killed by SIGSEGV +++ [pid 34987] <... wait4 resumed> [{WIFSIGNALED(s) && WTERMSIG(s) == SIGSEGV}], 0, NULL) = 34989 [pid 34987] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=34989, si_status=SIGSEGV, si_utime=0, si_stime=0} --- [pid 34987] clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f9772942b10) = 35616 [pid 34987] wait4(-1, ============================================================================================================== I also got a trace *without* the patches applied in which case there is no crash but the connection doesn't work either (I think the credentials are not passed along). The output is slightly different: {sa_family=AF_LOCAL, NULL}, [2]) = 2 [pid 49430] poll([{fd=2, events=POLLIN}], 1, 5000) = 1 ([{fd=2, revents=POLLIN}]) [pid 49430] read(2, "\1\1\0\1\0\10\0\0", 8) = 8 [pid 49430] read(2, "\0\1\0\0\0\0\0\0", 8) = 8 [pid 49430] read(2, "\1\4\0\1\2\351\0\0", 8) = 8 [pid 49430] read(2, "\17\10SERVER_SOFTWARElighttpd\v\fSERVE"..., 745) = 745 [pid 49430] read(2, "\1\4\0\1\0\0\0\0", 8) = 8 [pid 49430] lstat("/storage/lighttpd/wwwroot/libvirt.php", {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] lstat("/storage/lighttpd/wwwroot", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 [pid 49430] lstat("/storage/lighttpd", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0 [pid 49430] lstat("/storage", {st_mode=S_IFDIR|0755, st_size=31, ...}) = 0 [pid 49430] gettimeofday({1473102046, 10224}, NULL) = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0 [pid 49430] rt_sigaction(SIGPROF, {0x7f1014f4c970, [PROF], SA_RESTORER|SA_RESTART, 0x7f101140c670}, {0x7f1014f4c970, [PROF], SA_RESTORER|SA_RESTART, 0x7f101140c670}, 8) = 0 [pid 49430] rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0 [pid 49430] open("/storage/lighttpd/wwwroot/libvirt.php", O_RDONLY) = 4 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] mmap(NULL, 633, PROT_READ, MAP_SHARED, 4, 0) = 0x7f1014cea000 [pid 49430] getcwd("/usr/bin", 4095) = 9 [pid 49430] chdir("/storage/lighttpd/wwwroot") = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={14400, 0}}, NULL) = 0 [pid 49430] munmap(0x7f1014cea000, 633) = 0 [pid 49430] close(4) = 0 [pid 49430] unlink("test.log") = -1 ENOENT (No such file or directory) [pid 49430] access("test.log", F_OK) = -1 ENOENT (No such file or directory) [pid 49430] open("test.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 4 [pid 49430] lseek(4, 0, SEEK_END) = 0 [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=0, ...}) = 0 [pid 49430] mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1014ce7000 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 93) = 93 [pid 49430] geteuid() = 997 [pid 49430] geteuid() = 997 [pid 49430] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 49430] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 49430] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1014ce6000 [pid 49430] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 49430] close(5) = 0 [pid 49430] munmap(0x7f1014ce6000, 4096) = 0 [pid 49430] access("/var/www/lighttpd/.config/libvirt/libvirt.conf", F_OK) = -1 ENOENT (No such file or directory) [pid 49430] geteuid() = 997 [pid 49430] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 49430] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 49430] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1014ce6000 [pid 49430] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 49430] close(5) = 0 [pid 49430] munmap(0x7f1014ce6000, 4096) = 0 [pid 49430] access("/var/www/lighttpd/.config/libvirt/auth.conf", R_OK) = -1 ENOENT (No such file or directory) [pid 49430] access("/etc/libvirt/auth.conf", R_OK) = -1 EACCES (Permission denied) [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 168) = 168 [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 93) = 93 [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 142) = 142 [pid 49430] getcwd("/storage/lighttpd/wwwroot", 4096) = 26 [pid 49430] lstat("/storage/lighttpd/wwwroot/test.log", {st_mode=S_IFREG|0755, st_size=496, ...}) = 0 [pid 49430] open("/storage/lighttpd/wwwroot/test.log", O_RDONLY) = 5 [pid 49430] fstat(5, {st_mode=S_IFREG|0755, st_size=496, ...}) = 0 [pid 49430] lseek(5, 0, SEEK_CUR) = 0 [pid 49430] stat("test.log", {st_mode=S_IFREG|0755, st_size=496, ...}) = 0 [pid 49430] read(5, "[2016-09-05 21:00:46 libvirt-php"..., 8192) = 496 [pid 49430] close(5) = 0 [pid 49430] chdir("/usr/bin") = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 [pid 49430] write(2, "\1\7\0\1\0\361\7\0PHP Warning: unlink(tes"..., 928) = 928 [pid 49430] shutdown(2, SHUT_WR) = 0 [pid 49430] recvfrom(2, "\1\5\0\1\0\0\0\0", 8, 0, NULL, NULL) = 8 [pid 49430] close(2) = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 [pid 49430] accept(0, ============================================================================================================== I'm not an expert debugger but I suspect that the patches are actually working, the credentials are passed along and the connection attempt is moving forward but crashing in the next stage before any actual connection attempt to the remote server is attempted. I still need to try with the git HEAD code tough. Not sure if it worth mention this again but the same connection is working without any problems using virsh. Thanks for looking into this. Cheers. Fer On lun, sep 5, 2016 at 9:33 , Michal Privoznik <mprivozn@redhat.com> wrote:
On 02.09.2016 11:11, Fernando Casas Schössow wrote:
I'm running libvirt-php 0.5.2 on CentOS 7 with libvirt 2.1.0. Using virsh I'm able to connect to hyper-v hosts correctly but using libvirt-php it fails during authentication since it seems that the credentials are not being passed along.
This is the php code I'm using:
<?php $logfile = 'test.log';
unlink($logfile); if (!libvirt_logfile_set($logfile)) die('Cannot set the log file');
$connstr = 'hyperv://user@hyperv-host/?transport=http'; $credentials =
array(VIR_CRED_AUTHNAME=>'Administrator',VIR_CRED_PASSPHRASE=>'somepass'); $conn = libvirt_connect($connstr, false, $credentials); echo libvirt_get_last_error(); unset($conn);
$fp = fopen($logfile, 'r'); $str = fread($fp, filesize($logfile)); fclose($fp);
echo '<pre>'; echo $str; print_r($credentials); echo '</pre>'; ?>
Unfortunately, I don't have a hyperv instance to try this out, but for other connection URIs (like qemu:///system) this works for me.
And this is the output:
authentication failed: Password request failed
[2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Found 0 elements for credentials [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: cred 0, type 5, prompt Enter Administrator's password for hyperv-host challenge hyperv-host [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: result (null) (0) [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Cannot establish connection to hyperv://Administrator@hyperv-host/?transport=http Array ( [2] => Administrator [5] => somepass )
Note the "Found 0 elements for credentials". After doing some googling I found an email thread "[libvirt] [libvirt-php PATCH 0/3] Fix PHP5 compatibilty issues." that I think is related to my problem, especially patch 2/3. I also checked github project and saw that those patches are already merged in the code so I went ahead and apply them to 0.5.2 source code and rebuild:
use VIRT_FOREACH macros everywhere - Commit: f4b760d libvirt_connect: use loop macros to read cred info - Commit: d704106 Define macros for looping php hash tables - Commit: 673a0bf
The build went fine but now when I'm trying to connect to the hyper-v host using libvirt-php I get an internal server error (500) so it seems PHP is crashing. From the system log I see:
kernel: traps: php-cgi[43452] general protection ip:7f63907f74a0 sp:7fff12d61f68 error:0 in libvirt.so.0.2001.0[7f6390735000+385000]
If you could attach a debugger and get a stack trace where this is happening that'd be great.
Is there any other patch that I'm missing?
Doesn't look like it, but if you could try the current git HEAD that would help. I mean, if you see the error even with that the bug is still there.
Any ideas on how to fix the libvirt_connect credentials issue without applying the patches above?
I should probably do a release soon. Not that there was a much movement since the last one though.
Michal

Hi again Michal, I have more information to share. I think I can confirm that the patches are actually fixing the credentials problem and they are passed along. This is the content of test.log with libvirt-php output: [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: credentials index 2 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: credentials index 5 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: Found 2 elements for credentials [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_virConnectAuthCallback: cred 0, type 5, prompt Enter Administrator's password for 192.168.7.2 challenge 192.168.7.2 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_virConnectAuthCallback: result somepass (16) Of course then the process is crashing and the connection is aborted so I believe that the patches work fine (they fix the connection credentials not passed along issue) but once this is fixed the other problem is uncovered. I also took a trace of virsh to compare the behavior and I found that right after trying to open the file "/etc/openwsman/openwsman_client.conf" which doesn't exist, the network connection to the Hyper-V host starts: open("/etc/openwsman/openwsman_client.conf", O_RDONLY) = -1 ENOENT (No such file or directory) gettimeofday({1473108181, 503801}, NULL) = 0 socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 6 ioctl(6, SIOCGIFCONF, {80, {{"lo", {AF_INET, inet_addr("127.0.0.1")}}, {"eth0", {AF_INET, inet_addr("192.168.0.24")}}}}) = 0 ioctl(6, SIOCGIFFLAGS, {ifr_name="lo", ifr_flags=IFF_UP|IFF_LOOPBACK|IFF_RUNNING}) = 0 ioctl(6, SIOCGIFFLAGS, {ifr_name="eth0", ifr_flags=IFF_UP|IFF_BROADCAST|IFF_RUNNING|IFF_MULTICAST}) = 0 ioctl(6, SIOCGIFHWADDR, {ifr_name="eth0", ifr_hwaddr=00:15:5d:07:32:03}) = 0 close(6) = 0 futex(0x7fa9b602fd48, FUTEX_WAKE_PRIVATE, 2147483647) = 0 open("/etc/openwsman/openwsman_client.conf", O_RDONLY) = -1 ENOENT (No such file or directory) brk(0) = 0x7fa9b881f000 brk(0x7fa9b8840000) = 0x7fa9b8840000 clock_gettime(CLOCK_MONOTONIC, {1530071, 524608469}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524644770}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524680171}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524715271}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524753172}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524791573}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524823274}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524875775}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 524976977}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 525034178}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 525103179}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 525135580}) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 525176581}) = 0 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 6 fcntl(6, F_GETFL) = 0x2 (flags O_RDWR) fcntl(6, F_SETFL, O_RDWR|O_NONBLOCK) = 0 clock_gettime(CLOCK_MONOTONIC, {1530071, 525334084}) = 0 connect(6, {sa_family=AF_INET, sin_port=htons(5985), sin_addr=inet_addr("192.168.0.2")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {1530071, 525458286}) = 0 While in the case of libvirt-php, it will crash and abort the connection. If you want me to send you the full virsh trace, just let me know. Also, not sure if it worth mention it and I guess you are aware that libvirt depends on openwsman to connect to a Hyper-V host. Thanks in advance for your help. Fer On lun, sep 5, 2016 at 9:38 , Fernando Casas Schössow <casasfernando@hotmail.com> wrote:
Thanks for your reply Michal.
Actually you don't need a Hyper-V server to reproduce the problem since the connection to the server is never initiated because the process crash before that stage (got wireshark on the network to confirm this). So you should be able to reproduce the problem without a Hyper-V server, just using the same PHP code I'm using (or any other hyperv URI for that matter).
==============================================================================================================
Following your advice I attached strace to the PHP processes and reproduced the issue. This is the trace result:
Process 34978 attached Process 34979 attached Process 34981 attached Process 34983 attached Process 34984 attached Process 34986 attached Process 34987 attached Process 34989 attached [pid 34989] accept(0, <unfinished ...> [pid 34987] wait4(-1, <unfinished ...> [pid 34986] accept(0, <unfinished ...> [pid 34981] accept(0, <unfinished ...> [pid 34979] wait4(-1, <unfinished ...> [pid 34978] wait4(-1, <unfinished ...> [pid 34984] wait4(-1, <unfinished ...> [pid 34983] accept(0, <unfinished ...> [pid 34989] <... accept resumed> {sa_family=AF_LOCAL, NULL}, [2]) = 4 [pid 34989] poll([{fd=4, events=POLLIN}], 1, 5000) = 1 ([{fd=4, revents=POLLIN}]) [pid 34989] read(4, "\1\1\0\1\0\10\0\0", 8) = 8 [pid 34989] read(4, "\0\1\0\0\0\0\0\0", 8) = 8 [pid 34989] read(4, "\1\4\0\1\2\351\0\0", 8) = 8 [pid 34989] read(4, "\17\10SERVER_SOFTWARElighttpd\v\fSERVE"..., 745) = 745 [pid 34989] read(4, "\1\4\0\1\0\0\0\0", 8) = 8 [pid 34989] lstat("/storage/lighttpd/wwwroot/libvirt.php", {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] lstat("/storage/lighttpd/wwwroot", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 [pid 34989] lstat("/storage/lighttpd", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0 [pid 34989] lstat("/storage", {st_mode=S_IFDIR|0755, st_size=31, ...}) = 0 [pid 34989] gettimeofday({1473102621, 318809}, NULL) = 0 [pid 34989] stat("/storage/lighttpd/wwwroot/.user.ini", 0x7ffc541fcbe0) = -1 ENOENT (No such file or directory) [pid 34989] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0 [pid 34989] rt_sigaction(SIGPROF, {0x7f9772bbb970, [PROF], SA_RESTORER|SA_RESTART, 0x7f976f07b670}, {SIG_DFL, [], 0}, 8) = 0 [pid 34989] rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0 [pid 34989] open("/storage/lighttpd/wwwroot/libvirt.php", O_RDONLY) = 5 [pid 34989] fstat(5, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] fstat(5, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] fstat(5, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 34989] mmap(NULL, 633, PROT_READ, MAP_SHARED, 5, 0) = 0x7f9772959000 [pid 34989] getcwd("/usr/bin", 4095) = 9 [pid 34989] chdir("/storage/lighttpd/wwwroot") = 0 [pid 34989] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={14400, 0}}, NULL) = 0 [pid 34989] munmap(0x7f9772959000, 633) = 0 [pid 34989] close(5) = 0 [pid 34989] unlink("test.log") = 0 [pid 34989] access("test.log", F_OK) = -1 ENOENT (No such file or directory) [pid 34989] open("test.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 5 [pid 34989] lseek(5, 0, SEEK_END) = 0 [pid 34989] dup3(5, 2, 0) = 2 [pid 34989] close(5) = 0 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] fstat(2, {st_mode=S_IFREG|0755, st_size=0, ...}) = 0 [pid 34989] mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9772956000 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 80) = 80 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 80) = 80 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 93) = 93 [pid 34989] futex(0x7f976ae3cb18, FUTEX_WAKE_PRIVATE, 2147483647) = 0 [pid 34989] futex(0x7f976ae3d078, FUTEX_WAKE_PRIVATE, 2147483647) = 0 [pid 34989] geteuid() = 997 [pid 34989] geteuid() = 997 [pid 34989] socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 5 [pid 34989] connect(5, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) [pid 34989] close(5) = 0 [pid 34989] socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 5 [pid 34989] connect(5, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) [pid 34989] close(5) = 0 [pid 34989] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 34989] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 34989] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9772955000 [pid 34989] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 34989] close(5) = 0 [pid 34989] munmap(0x7f9772955000, 4096) = 0 [pid 34989] access("/var/www/lighttpd/.config/libvirt/libvirt.conf", F_OK) = -1 ENOENT (No such file or directory) [pid 34989] geteuid() = 997 [pid 34989] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 34989] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 34989] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f9772955000 [pid 34989] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 34989] close(5) = 0 [pid 34989] munmap(0x7f9772955000, 4096) = 0 [pid 34989] access("/var/www/lighttpd/.config/libvirt/auth.conf", R_OK) = -1 ENOENT (No such file or directory) [pid 34989] access("/etc/libvirt/auth.conf", R_OK) = -1 EACCES (Permission denied) [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 168) = 168 [pid 34989] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 34989] write(2, "[2016-09-05 21:10:21 libvirt-php"..., 104) = 104 [pid 34989] open("/etc/openwsman/openwsman_client.conf", O_RDONLY) = -1 ENOENT (No such file or directory) [pid 34989] --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} --- [pid 34989] +++ killed by SIGSEGV +++ [pid 34987] <... wait4 resumed> [{WIFSIGNALED(s) && WTERMSIG(s) == SIGSEGV}], 0, NULL) = 34989 [pid 34987] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=34989, si_status=SIGSEGV, si_utime=0, si_stime=0} --- [pid 34987] clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f9772942b10) = 35616 [pid 34987] wait4(-1,
==============================================================================================================
I also got a trace *without* the patches applied in which case there is no crash but the connection doesn't work either (I think the credentials are not passed along). The output is slightly different:
{sa_family=AF_LOCAL, NULL}, [2]) = 2 [pid 49430] poll([{fd=2, events=POLLIN}], 1, 5000) = 1 ([{fd=2, revents=POLLIN}]) [pid 49430] read(2, "\1\1\0\1\0\10\0\0", 8) = 8 [pid 49430] read(2, "\0\1\0\0\0\0\0\0", 8) = 8 [pid 49430] read(2, "\1\4\0\1\2\351\0\0", 8) = 8 [pid 49430] read(2, "\17\10SERVER_SOFTWARElighttpd\v\fSERVE"..., 745) = 745 [pid 49430] read(2, "\1\4\0\1\0\0\0\0", 8) = 8 [pid 49430] lstat("/storage/lighttpd/wwwroot/libvirt.php", {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] lstat("/storage/lighttpd/wwwroot", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 [pid 49430] lstat("/storage/lighttpd", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0 [pid 49430] lstat("/storage", {st_mode=S_IFDIR|0755, st_size=31, ...}) = 0 [pid 49430] gettimeofday({1473102046, 10224}, NULL) = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={60, 0}}, NULL) = 0 [pid 49430] rt_sigaction(SIGPROF, {0x7f1014f4c970, [PROF], SA_RESTORER|SA_RESTART, 0x7f101140c670}, {0x7f1014f4c970, [PROF], SA_RESTORER|SA_RESTART, 0x7f101140c670}, 8) = 0 [pid 49430] rt_sigprocmask(SIG_UNBLOCK, [PROF], NULL, 8) = 0 [pid 49430] open("/storage/lighttpd/wwwroot/libvirt.php", O_RDONLY) = 4 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=633, ...}) = 0 [pid 49430] mmap(NULL, 633, PROT_READ, MAP_SHARED, 4, 0) = 0x7f1014cea000 [pid 49430] getcwd("/usr/bin", 4095) = 9 [pid 49430] chdir("/storage/lighttpd/wwwroot") = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={14400, 0}}, NULL) = 0 [pid 49430] munmap(0x7f1014cea000, 633) = 0 [pid 49430] close(4) = 0 [pid 49430] unlink("test.log") = -1 ENOENT (No such file or directory) [pid 49430] access("test.log", F_OK) = -1 ENOENT (No such file or directory) [pid 49430] open("test.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 4 [pid 49430] lseek(4, 0, SEEK_END) = 0 [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] fstat(4, {st_mode=S_IFREG|0755, st_size=0, ...}) = 0 [pid 49430] mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1014ce7000 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 93) = 93 [pid 49430] geteuid() = 997 [pid 49430] geteuid() = 997 [pid 49430] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 49430] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 49430] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1014ce6000 [pid 49430] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 49430] close(5) = 0 [pid 49430] munmap(0x7f1014ce6000, 4096) = 0 [pid 49430] access("/var/www/lighttpd/.config/libvirt/libvirt.conf", F_OK) = -1 ENOENT (No such file or directory) [pid 49430] geteuid() = 997 [pid 49430] open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 [pid 49430] fstat(5, {st_mode=S_IFREG|0644, st_size=1998, ...}) = 0 [pid 49430] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1014ce6000 [pid 49430] read(5, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1998 [pid 49430] close(5) = 0 [pid 49430] munmap(0x7f1014ce6000, 4096) = 0 [pid 49430] access("/var/www/lighttpd/.config/libvirt/auth.conf", R_OK) = -1 ENOENT (No such file or directory) [pid 49430] access("/etc/libvirt/auth.conf", R_OK) = -1 EACCES (Permission denied) [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 168) = 168 [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 93) = 93 [pid 49430] stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0 [pid 49430] write(4, "[2016-09-05 21:00:46 libvirt-php"..., 142) = 142 [pid 49430] getcwd("/storage/lighttpd/wwwroot", 4096) = 26 [pid 49430] lstat("/storage/lighttpd/wwwroot/test.log", {st_mode=S_IFREG|0755, st_size=496, ...}) = 0 [pid 49430] open("/storage/lighttpd/wwwroot/test.log", O_RDONLY) = 5 [pid 49430] fstat(5, {st_mode=S_IFREG|0755, st_size=496, ...}) = 0 [pid 49430] lseek(5, 0, SEEK_CUR) = 0 [pid 49430] stat("test.log", {st_mode=S_IFREG|0755, st_size=496, ...}) = 0 [pid 49430] read(5, "[2016-09-05 21:00:46 libvirt-php"..., 8192) = 496 [pid 49430] close(5) = 0 [pid 49430] chdir("/usr/bin") = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 [pid 49430] write(2, "\1\7\0\1\0\361\7\0PHP Warning: unlink(tes"..., 928) = 928 [pid 49430] shutdown(2, SHUT_WR) = 0 [pid 49430] recvfrom(2, "\1\5\0\1\0\0\0\0", 8, 0, NULL, NULL) = 8 [pid 49430] close(2) = 0 [pid 49430] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0 [pid 49430] accept(0,
==============================================================================================================
I'm not an expert debugger but I suspect that the patches are actually working, the credentials are passed along and the connection attempt is moving forward but crashing in the next stage before any actual connection attempt to the remote server is attempted.
I still need to try with the git HEAD code tough. Not sure if it worth mention this again but the same connection is working without any problems using virsh.
Thanks for looking into this.
Cheers.
Fer
On lun, sep 5, 2016 at 9:33 , Michal Privoznik <mprivozn@redhat.com> wrote:
On 02.09.2016 11:11, Fernando Casas Schössow wrote:
I'm running libvirt-php 0.5.2 on CentOS 7 with libvirt 2.1.0. Using virsh I'm able to connect to hyper-v hosts correctly but using libvirt-php it fails during authentication since it seems that the credentials are not being passed along.
This is the php code I'm using:
<?php $logfile = 'test.log';
unlink($logfile); if (!libvirt_logfile_set($logfile)) die('Cannot set the log file');
$connstr = 'hyperv://user@hyperv-host/?transport=http'; $credentials =
array(VIR_CRED_AUTHNAME=>'Administrator',VIR_CRED_PASSPHRASE=>'somepass'); $conn = libvirt_connect($connstr, false, $credentials); echo libvirt_get_last_error(); unset($conn);
$fp = fopen($logfile, 'r'); $str = fread($fp, filesize($logfile)); fclose($fp);
echo '<pre>'; echo $str; print_r($credentials); echo '</pre>'; ?>
Unfortunately, I don't have a hyperv instance to try this out, but for other connection URIs (like qemu:///system) this works for me.
And this is the output:
authentication failed: Password request failed
[2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Found 0 elements for credentials [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: cred 0, type 5, prompt Enter Administrator's password for hyperv-host challenge hyperv-host [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_virConnectAuthCallback: result (null) (0) [2016-09-02 11:10:02 libvirt-php/core ]: libvirt_connect: Cannot establish connection to hyperv://Administrator@hyperv-host/?transport=http Array ( [2] => Administrator [5] => somepass )
Note the "Found 0 elements for credentials". After doing some googling I found an email thread "[libvirt] [libvirt-php PATCH 0/3] Fix PHP5 compatibilty issues." that I think is related to my problem, especially patch 2/3. I also checked github project and saw that those patches are already merged in the code so I went ahead and apply them to 0.5.2 source code and rebuild:
use VIRT_FOREACH macros everywhere - Commit: f4b760d libvirt_connect: use loop macros to read cred info - Commit: d704106 Define macros for looping php hash tables - Commit: 673a0bf
The build went fine but now when I'm trying to connect to the hyper-v host using libvirt-php I get an internal server error (500) so it seems PHP is crashing. From the system log I see:
kernel: traps: php-cgi[43452] general protection ip:7f63907f74a0 sp:7fff12d61f68 error:0 in libvirt.so.0.2001.0[7f6390735000+385000]
If you could attach a debugger and get a stack trace where this is happening that'd be great.
Is there any other patch that I'm missing?
Doesn't look like it, but if you could try the current git HEAD that would help. I mean, if you see the error even with that the bug is still there.
Any ideas on how to fix the libvirt_connect credentials issue without applying the patches above?
I should probably do a release soon. Not that there was a much movement since the last one though.
Michal

On 05.09.2016 23:08, Fernando Casas Schössow wrote:
Hi again Michal,
I have more information to share. I think I can confirm that the patches are actually fixing the credentials problem and they are passed along. This is the content of test.log with libvirt-php output:
[2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: credentials index 2 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: credentials index 5 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: Found 2 elements for credentials [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_virConnectAuthCallback: cred 0, type 5, prompt Enter Administrator's password for 192.168.7.2 challenge 192.168.7.2 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_virConnectAuthCallback: result somepass (16)
Of course then the process is crashing and the connection is aborted so I believe that the patches work fine (they fix the connection credentials not passed along issue) but once this is fixed the other problem is uncovered.
Cool, so at least that's confirmed. Can you please attach a debugger to your php (or run php straight from it). Also, the stack trace is the result of 'backtrace' command in gdb, not strace (which is a system call tracer). $ gdb $(which php) (gdb) run test.php (gbd) backtrace And while you're at it: $ valgrind --leak-check=full $(which php) test.php Thank you.

Thanks for the instructions since I'm not familiar with debugging as you probably guessed. :) Here you have gdb output: GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/bin/php...Reading symbols from /usr/bin/php...(no debugging symbols found)...done. (no debugging symbols found)...done. Missing separate debuginfos, use: debuginfo-install php-cli-5.4.16-36.3.el7_2.x86_64 (gdb) run /storage/lighttpd/wwwroot/libvirt.php Starting program: /usr/bin/php /storage/lighttpd/wwwroot/libvirt.php [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [New Thread 0x7fffe2ceb700 (LWP 31799)] [Thread 0x7fffe2ceb700 (LWP 31799) exited] PHP Warning: unlink(test.log): No such file or directory in /storage/lighttpd/wwwroot/libvirt.php on line 4 Program received signal SIGSEGV, Segmentation fault. 0x00007fffe9ad54a0 in virClassIsDerivedFrom () from /lib64/libvirt.so.0 (gdb) backtrace #0 0x00007fffe9ad54a0 in virClassIsDerivedFrom () from /lib64/libvirt.so.0 #1 0x00007fffe9b861ac in virDomainLookupByUUIDString () from /lib64/libvirt.so.0 #2 0x00007fffea1e82c5 in generate_uuid () from /usr/lib64/php/modules/libvirt-php.so #3 0x00007fffe7d3385a in wsmc_create_request () from /lib64/libwsman_client.so.4 #4 0x00007fffe7d3546f in wsmc_action_enumerate () from /lib64/libwsman_client.so.4 #5 0x00007fffe9c8e34a in hypervEnumAndPull () from /lib64/libvirt.so.0 #6 0x00007fffe9c8ee49 in hypervGetMsvmComputerSystemList () from /lib64/libvirt.so.0 #7 0x00007fffe9c8dacd in hypervConnectOpen () from /lib64/libvirt.so.0 #8 0x00007fffe9b82f39 in virConnectOpenInternal () from /lib64/libvirt.so.0 #9 0x00007fffe9b845ce in virConnectOpenAuth () from /lib64/libvirt.so.0 #10 0x00007fffea1e1190 in zif_libvirt_connect () from /usr/lib64/php/modules/libvirt-php.so #11 0x000055555586b57c in zend_do_fcall_common_helper_SPEC () #12 0x00005555557e8527 in execute () #13 0x00005555557c115f in zend_execute_scripts () #14 0x0000555555760976 in php_execute_script () #15 0x000055555586d598 in do_cli () #16 0x000055555561a12e in main () Also please find attached valgrind output (libvirt-php_vlagrind.zip). Thanks. Fer On mar, sep 6, 2016 at 12:59 , Michal Privoznik <mprivozn@redhat.com> wrote:
On 05.09.2016 23:08, Fernando Casas Schössow wrote:
Hi again Michal,
I have more information to share. I think I can confirm that the patches are actually fixing the credentials problem and they are passed along. This is the content of test.log with libvirt-php output:
[2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: credentials index 2 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: credentials index 5 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_connect: Found 2 elements for credentials [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_virConnectAuthCallback: cred 0, type 5, prompt Enter Administrator's password for 192.168.7.2 challenge 192.168.7.2 [2016-09-05 22:06:05 libvirt-php/core ]: libvirt_virConnectAuthCallback: result somepass (16)
Of course then the process is crashing and the connection is aborted so I believe that the patches work fine (they fix the connection credentials not passed along issue) but once this is fixed the other problem is uncovered.
Cool, so at least that's confirmed. Can you please attach a debugger to your php (or run php straight from it). Also, the stack trace is the result of 'backtrace' command in gdb, not strace (which is a system call tracer).
$ gdb $(which php) (gdb) run test.php (gbd) backtrace
And while you're at it: $ valgrind --leak-check=full $(which php) test.php
Thank you.

On 06.09.2016 13:45, Fernando Casas Schössow wrote:
Thanks for the instructions since I'm not familiar with debugging as you probably guessed. :)
Here you have gdb output:
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/bin/php...Reading symbols from /usr/bin/php...(no debugging symbols found)...done. (no debugging symbols found)...done. Missing separate debuginfos, use: debuginfo-install php-cli-5.4.16-36.3.el7_2.x86_64 (gdb) run /storage/lighttpd/wwwroot/libvirt.php Starting program: /usr/bin/php /storage/lighttpd/wwwroot/libvirt.php [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [New Thread 0x7fffe2ceb700 (LWP 31799)] [Thread 0x7fffe2ceb700 (LWP 31799) exited] PHP Warning: unlink(test.log): No such file or directory in /storage/lighttpd/wwwroot/libvirt.php on line 4
Program received signal SIGSEGV, Segmentation fault. 0x00007fffe9ad54a0 in virClassIsDerivedFrom () from /lib64/libvirt.so.0 (gdb) backtrace #0 0x00007fffe9ad54a0 in virClassIsDerivedFrom () from /lib64/libvirt.so.0 #1 0x00007fffe9b861ac in virDomainLookupByUUIDString () from /lib64/libvirt.so.0 #2 0x00007fffea1e82c5 in generate_uuid () from /usr/lib64/php/modules/libvirt-php.so #3 0x00007fffe7d3385a in wsmc_create_request () from /lib64/libwsman_client.so.4 #4 0x00007fffe7d3546f in wsmc_action_enumerate () from /lib64/libwsman_client.so.4 #5 0x00007fffe9c8e34a in hypervEnumAndPull () from /lib64/libvirt.so.0 #6 0x00007fffe9c8ee49 in hypervGetMsvmComputerSystemList () from /lib64/libvirt.so.0 #7 0x00007fffe9c8dacd in hypervConnectOpen () from /lib64/libvirt.so.0 #8 0x00007fffe9b82f39 in virConnectOpenInternal () from /lib64/libvirt.so.0 #9 0x00007fffe9b845ce in virConnectOpenAuth () from /lib64/libvirt.so.0 #10 0x00007fffea1e1190 in zif_libvirt_connect () from /usr/lib64/php/modules/libvirt-php.so #11 0x000055555586b57c in zend_do_fcall_common_helper_SPEC () #12 0x00005555557e8527 in execute () #13 0x00005555557c115f in zend_execute_scripts () #14 0x0000555555760976 in php_execute_script () #15 0x000055555586d598 in do_cli () #16 0x000055555561a12e in main ()
Ah, this is exactly what I needed. Well, we're doomed. There are two problems here. The first one is: libvirt-php is exporting symbols that is shouldn't have. Like for instance generate_uuid which is clearly meant as an internal helper but because of our own bug (well, missing implementation) it is being exported. Thus, when linker is linking the libraries together it finds out that libwsman_client.so.4 needs generate_uuid symbol which it finds in libvirt-pgp.so instead of libwsman.so.1.0.0 (which is what libwsman devels intended). objdump -T /usr/lib64/libwsman_client.so.4 | grep generate_uuid 0000000000000000 D *UND* 0000000000000000 generate_uuid bjdump -T /usr/lib64/php/modules/libvirt-php.so | grep generate 000000000002b660 g DF .text 00000000000000ce Base generate_uuid 000000000002b590 g DF .text 00000000000000cb Base generate_uuid_any objdump -T /lib64/libwsman.so.1.0.0 | grep generate 000000000000e820 g DF .text 00000000000001bd Base generate_uuid 000000000001f950 g DF .text 000000000000005a Base wsman_generate_fault_buffer 000000000001f8c0 g DF .text 0000000000000082 Base wsman_generate_fault The fix on our part is obvious. The second problem is, libwsman devels should not really be using such generic names in their libraries. At least they need to prefix their public function names with wsman_ (see those other 'generate_fault' functions?). I'll work on fix and let you test it - since the backtrace proof this is hyperv specific bug. That's why I was unable to reproduce it. Thanks for the report! Michal

Thanks for the explanation Michal. I will be looking forward the fix to try it. :) On mar, sep 6, 2016 at 6:59 , Michal Privoznik <mprivozn@redhat.com> wrote:
On 06.09.2016 13:45, Fernando Casas Schössow wrote:
Thanks for the instructions since I'm not familiar with debugging as you probably guessed. :)
Here you have gdb output:
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/bin/php...Reading symbols from /usr/bin/php...(no debugging symbols found)...done. (no debugging symbols found)...done. Missing separate debuginfos, use: debuginfo-install php-cli-5.4.16-36.3.el7_2.x86_64 (gdb) run /storage/lighttpd/wwwroot/libvirt.php Starting program: /usr/bin/php /storage/lighttpd/wwwroot/libvirt.php [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [New Thread 0x7fffe2ceb700 (LWP 31799)] [Thread 0x7fffe2ceb700 (LWP 31799) exited] PHP Warning: unlink(test.log): No such file or directory in /storage/lighttpd/wwwroot/libvirt.php on line 4
Program received signal SIGSEGV, Segmentation fault. 0x00007fffe9ad54a0 in virClassIsDerivedFrom () from /lib64/libvirt.so.0 (gdb) backtrace #0 0x00007fffe9ad54a0 in virClassIsDerivedFrom () from /lib64/libvirt.so.0 #1 0x00007fffe9b861ac in virDomainLookupByUUIDString () from /lib64/libvirt.so.0 #2 0x00007fffea1e82c5 in generate_uuid () from /usr/lib64/php/modules/libvirt-php.so #3 0x00007fffe7d3385a in wsmc_create_request () from /lib64/libwsman_client.so.4 #4 0x00007fffe7d3546f in wsmc_action_enumerate () from /lib64/libwsman_client.so.4 #5 0x00007fffe9c8e34a in hypervEnumAndPull () from /lib64/libvirt.so.0 #6 0x00007fffe9c8ee49 in hypervGetMsvmComputerSystemList () from /lib64/libvirt.so.0 #7 0x00007fffe9c8dacd in hypervConnectOpen () from /lib64/libvirt.so.0 #8 0x00007fffe9b82f39 in virConnectOpenInternal () from /lib64/libvirt.so.0 #9 0x00007fffe9b845ce in virConnectOpenAuth () from /lib64/libvirt.so.0 #10 0x00007fffea1e1190 in zif_libvirt_connect () from /usr/lib64/php/modules/libvirt-php.so #11 0x000055555586b57c in zend_do_fcall_common_helper_SPEC () #12 0x00005555557e8527 in execute () #13 0x00005555557c115f in zend_execute_scripts () #14 0x0000555555760976 in php_execute_script () #15 0x000055555586d598 in do_cli () #16 0x000055555561a12e in main ()
Ah, this is exactly what I needed. Well, we're doomed. There are two problems here.
The first one is: libvirt-php is exporting symbols that is shouldn't have. Like for instance generate_uuid which is clearly meant as an internal helper but because of our own bug (well, missing implementation) it is being exported. Thus, when linker is linking the libraries together it finds out that libwsman_client.so.4 needs generate_uuid symbol which it finds in libvirt-pgp.so instead of libwsman.so.1.0.0 (which is what libwsman devels intended).
objdump -T /usr/lib64/libwsman_client.so.4 | grep generate_uuid 0000000000000000 D *UND* 0000000000000000 generate_uuid
bjdump -T /usr/lib64/php/modules/libvirt-php.so | grep generate 000000000002b660 g DF .text 00000000000000ce Base generate_uuid 000000000002b590 g DF .text 00000000000000cb Base generate_uuid_any
objdump -T /lib64/libwsman.so.1.0.0 | grep generate 000000000000e820 g DF .text 00000000000001bd Base generate_uuid 000000000001f950 g DF .text 000000000000005a Base wsman_generate_fault_buffer 000000000001f8c0 g DF .text 0000000000000082 Base wsman_generate_fault
The fix on our part is obvious.
The second problem is, libwsman devels should not really be using such generic names in their libraries. At least they need to prefix their public function names with wsman_ (see those other 'generate_fault' functions?).
I'll work on fix and let you test it - since the backtrace proof this is hyperv specific bug. That's why I was unable to reproduce it.
Thanks for the report!
Michal

On 06.09.2016 19:27, Fernando Casas Schössow wrote:
Thanks for the explanation Michal.
I will be looking forward the fix to try it. :)
Hey, so before I push the patches to the repo, do you mind testing it? I've uploaded them here: https://mprivozn.fedorapeople.org/php/ you can also find .tar.gz archive made with them applied and also rpms for convenience. Thank you. Michal

Thanks for the patches Michal. I'm using OBS to build my custom packages so let me apply this patches and build a new RPM. I will test them and come back to you ASAP. Fer On mié, sep 7, 2016 at 10:44 , Michal Privoznik <mprivozn@redhat.com> wrote:
On 06.09.2016 19:27, Fernando Casas Schössow wrote:
Thanks for the explanation Michal.
I will be looking forward the fix to try it. :)
Hey, so before I push the patches to the repo, do you mind testing it? I've uploaded them here:
https://mprivozn.fedorapeople.org/php/
you can also find .tar.gz archive made with them applied and also rpms for convenience.
Thank you.
Michal

Ok. I managed to build the new source you shared with me with a couple of small changes to the spec file I was using. Nothing significant tough. And the good news is that the problem is now solved. :) I was able to connect to the Hyper-V host, get a list of the VMs, etc from PHP. Thank you very much for your help Michal. I will be looking forward the next release (0.5.3?) of libvirt-php! Cheers, Fer On mié, sep 7, 2016 at 10:58 , Fernando Casas Schössow <casasfernando@hotmail.com> wrote:
Thanks for the patches Michal. I'm using OBS to build my custom packages so let me apply this patches and build a new RPM.
I will test them and come back to you ASAP.
Fer
On mié, sep 7, 2016 at 10:44 , Michal Privoznik <mprivozn@redhat.com> wrote:
On 06.09.2016 19:27, Fernando Casas Schössow wrote:
Thanks for the explanation Michal.
I will be looking forward the fix to try it. :)
Hey, so before I push the patches to the repo, do you mind testing it? I've uploaded them here:
https://mprivozn.fedorapeople.org/php/
you can also find .tar.gz archive made with them applied and also rpms for convenience.
Thank you.
Michal

On 07.09.2016 13:02, Fernando Casas Schössow wrote:
Ok. I managed to build the new source you shared with me with a couple of small changes to the spec file I was using. Nothing significant tough.
And the good news is that the problem is now solved. :)
Awesome. I've merged the patches.
I was able to connect to the Hyper-V host, get a list of the VMs, etc from PHP.
Thank you very much for your help Michal.
I will be looking forward the next release (0.5.3?) of libvirt-php!
Yeah, that'll be the next release. Although, I'd like to fix a few bugs before doing that. How badly do you need the new release? Michal

Not urgent I can use this patched source until the next good release. :) Also I think I found another problem that needs to be fixed with one of the functions. libvirt_list_active_domains() returns garbage as a result. On the other hand libvirt_list_inactive_domains and libvirt_list_domains work like a charm. Anyway I will open another thread for that since it's an entire different thing and I don't want to mix them. Fer On mié, sep 7, 2016 at 2:01 , Michal Privoznik <mprivozn@redhat.com> wrote:
On 07.09.2016 13:02, Fernando Casas Schössow wrote:
Ok. I managed to build the new source you shared with me with a couple of small changes to the spec file I was using. Nothing significant tough.
And the good news is that the problem is now solved. :)
Awesome. I've merged the patches.
I was able to connect to the Hyper-V host, get a list of the VMs, etc from PHP.
Thank you very much for your help Michal.
I will be looking forward the next release (0.5.3?) of libvirt-php!
Yeah, that'll be the next release. Although, I'd like to fix a few bugs before doing that. How badly do you need the new release?
Michal
participants (2)
-
Fernando Casas Schössow
-
Michal Privoznik