<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jun 6, 2020 at 3:39 AM Richard W.M. Jones <<a href="mailto:rjones@redhat.com">rjones@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">[To continue the conversation from<br>
<a href="https://github.com/libguestfs/nbdkit/issues/5" rel="noreferrer" target="_blank">https://github.com/libguestfs/nbdkit/issues/5</a>]<br>
<br>
> Currently there's no way for the Rust plugin to report an error. The<br>
> idiomatic way to do it would be for each callback to return a Result<br>
> object, much like how the Go plugin currently does it.<br>
<br>
I'm sure it's not idiomatic for Rust, but I just wanted to say that<br>
there is a way to return an error: return -1.  But a bigger issue<br>
seems to be how to pass back the correct errno (assuming that Rust<br>
even collects this from low-level syscalls?).<br>
<br>
For historical reasons nbdkit plugins written in C set errno on error<br>
and nbdkit server reads the errno and may translate it into NBD errors<br>
on the wire (so it's generally important to get it right).<br>
<br>
However your plugin may set .errno_is_preserved = 0, then you can call<br>
nbdkit_set_error() whenever convenient before returning an error to<br>
set the errno that nbdkit will use.  In OCaml plugins we have to go<br>
through some hoops to convert OCaml errno (which use a different<br>
numbering) to system errno:<br>
<br>
<a href="https://github.com/libguestfs/nbdkit/blob/904c4e5fdca557d6d25a60e6fb12fa058263481e/plugins/ocaml/NBDKit.ml#L250" rel="noreferrer" target="_blank">https://github.com/libguestfs/nbdkit/blob/904c4e5fdca557d6d25a60e6fb12fa058263481e/plugins/ocaml/NBDKit.ml#L250</a><br>
<br>
The other issue (from golang bindings) was threads.  Does Rust use<br>
native system pthreads?  If it does then there shouldn't be an issue.<br>
golang implements its own green threads and that was a problem.<br>
<br>
Rich.<br>
<br>
-- <br>
Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/~rjones" rel="noreferrer" target="_blank">http://people.redhat.com/~rjones</a><br>
Read my programming and virtualization blog: <a href="http://rwmj.wordpress.com" rel="noreferrer" target="_blank">http://rwmj.wordpress.com</a><br>
libguestfs lets you edit virtual machines.  Supports shell scripting,<br>
bindings from many languages.  <a href="http://libguestfs.org" rel="noreferrer" target="_blank">http://libguestfs.org</a><br></blockquote><div><br></div><div>Yes, Rust uses native threads.  Setting the errno explicitly with nbdkit_set_error sounds good.  I have a good start on new bindings, and should have something to show next week.</div><div>-Alan<br></div></div></div>