[Libguestfs] [nbdkit PATCH 0/2] bind .zero to more languages

Eric Blake eblake at redhat.com
Thu Jan 26 02:48:10 UTC 2017


On 01/24/2017 09:16 AM, Richard W.M. Jones wrote:

> In Perl, old code to raise an error would look like:
> 
>   sub pread
>   {
>      my $h = shift;
>      my $count = shift;
>      my $offset = shift;
>      my $ret;
>      read ($FH, $ret, $count, $offset) || die "read: $!"
>      return $ret;
>   }
> 
> (Note that die does not exit the program, it raises an exception which
> is caught and turned into nbdkit_error in the Perl nbdkit plugin).
> 
> This would continue to work fine, but new code which cared about the
> errno could do this instead:
> 
>   sub pread
>   {
>      my $h = shift;
>      my $count = shift;
>      my $offset = shift;
>      my $ret;
>      read ($FH, $ret, $count, $offset) || {
>        nbdkit_set_errno (POSIX::errno ());
>        die "read: $!"
>      }
>      return $ret;
>   }

Except I can't even figure out how to expose nbdkit_set_error (hmm, I
named it set_error instead of set_errno in my v2 series) to the perl
code.  In fact, with just this change to example.pl:

diff --git i/plugins/perl/example.pl w/plugins/perl/example.pl
index fcdac33..64f6de3 100644
--- i/plugins/perl/example.pl
+++ w/plugins/perl/example.pl
@@ -1,4 +1,5 @@
 use strict;
+use POSIX ();

 # Example Perl plugin.
 #
@@ -80,6 +81,8 @@ sub pwrite
     my $buf = shift;
     my $count = length ($buf);
     my $offset = shift;
+    my $err = POSIX::EPERM;

     substr ($disk, $offset, $count) = $buf;
+    die "forced write failure";
 }

I'm getting this failure:

$ ./src/nbdkit -e foo -fv plugins/perl/.libs/nbdkit-perl-plugin.so \
    script=plugins/perl/example.pl
nbdkit: debug: registering plugins/perl/.libs/nbdkit-perl-plugin.so
nbdkit: debug: registered plugins/perl/.libs/nbdkit-perl-plugin.so (name
perl)
nbdkit: debug: plugins/perl/.libs/nbdkit-perl-plugin.so: load
nbdkit: debug: plugins/perl/.libs/nbdkit-perl-plugin.so: config
key=script, value=plugins/perl/example.pl
Can't load module Fcntl, dynamic loading not available in this perl.
  (You may need to build a new perl executable which either supports
  dynamic loading or has the Fcntl module statically linked into it.)
 at /usr/lib64/perl5/POSIX.pm line 17.
Compilation failed in require at /usr/lib64/perl5/POSIX.pm line 17.
BEGIN failed--compilation aborted at /usr/lib64/perl5/POSIX.pm line 17.
Compilation failed in require at plugins/perl/example.pl line 2.
BEGIN failed--compilation aborted at plugins/perl/example.pl line 2.
nbdkit: error: plugins/perl/example.pl: one of the required callbacks
'open', 'get_size' or 'pread' is not defined by this Perl script.
nbdkit requires these callbacks.

So I'm not sure how anyone else is doing anything fancy in an NBD perl
script.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170125/49364a65/attachment.sig>


More information about the Libguestfs mailing list