three18ti has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I'm using Ceph for storage in my virtualization cluster and I would like to be able to control it programmatically from a Perl script. I looked at using SWIG or h2xs to generate a wrapper, but it seems I require more intimate knowledge of the source library than I currently posess to make effective use of those tools.
After a bit of googling, I did come across a thread where a Ceph module was started. Ceph::RADOS.
This module seems to work great except for the list_pools function which causes a segfault.
The relevant code from the module is here:
sub list_pools { my $self = shift; my @pools = list_pools_c($self->{conn}); return \@pools; } __C__ void list_pools_c (rados_t clu) { int buf_sz = rados_pool_list(clu,NULL,0); char buf[buf_sz]; int r = rados_pool_list(clu,buf,buf_sz); if (r != buf_sz) { printf("buffer size mismatch: got %d the first time, but %d " "the second.\n", buf_sz, r); } Inline_Stack_Vars; Inline_Stack_Reset; const char *b = buf; while(1) { if(b[0] == '\0') { Inline_Stack_Done; break; } Inline_Stack_Push(sv_2mortal(newSVpv(b,0))); b += strlen(b) +1; } }
We can observe this behavior when running a stacktrace on the testrados2.pl script that comes with the attachment 2 (I added a print "Testing list_pools\n" before the actual call to $c->list_pools to make debugging easier):
write(1, "Testing list_pools\n", 19Testing list_pools ) = 19 --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x7fffd5dd +5000} --- +++ killed by SIGSEGV (core dumped) +++ Segmentation fault (core dumped)
Running this code through gdb I get possibly a little more helpful error: ( gdb ; set args testrados2.pl ; run )
Testing list_pools Program received signal SIGSEGV, Segmentation fault. __memset_sse2 () at ../sysdeps/x86_64/multiarch/../memset.S:913 913 ../sysdeps/x86_64/multiarch/../memset.S: No such file or direc +tory.
But googling that error has not provided my any assistance.
I think this error is coming from the c function "list_pools_c" because Perl doesn't (that I've encountered) emit stack traces under "normal" circumstances.
I was hoping someone could help me debug the error as I'm not really sure where to go from here. I've asked a similar question on the ceph-users mailing list, but I've only gotten crickets.
Also, any words of wisdom on extending c libraries would be greatly appreciated. I've read perlxstut and related documentation. My C is a bit rusty and I'm attempting to extend someone else's library, I get the feeling that this project may take a bit of work.
Thanks Monks!
Edits: to fix links to Ceph mailing list and Ceph::RADOS package