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


In reply to [Ceph::RADOS] Help Debugging Inline C by three18ti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.