rust: Add support for dynamic .thread_model
commitf39d9a240262a908cc94f2f134f78aac966a9c28
authorEric Blake <eblake@redhat.com>
Fri, 16 Aug 2019 16:34:12 +0000 (16 11:34 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 16 Aug 2019 17:50:06 +0000 (16 12:50 -0500)
tree6a9dba394354575c83aab5fab6738a85ef997ef7
parent64e4f7097c159e46337dd84864745623c54d149f
rust: Add support for dynamic .thread_model

We do not promise API stability for non-C languages; this is an API
break as follows: instead of calling plugin_init with a static model,
you can now populate .thread_model in the Plugin struct, with a
default to Parallel.  As in C, the model is still chosen at .load time
(at most, making it a function allows you to alter it based on
configuration), and not something that can change per-connection.

Since all existing Rust plugins will have already thought about thread
models, they can convert their existing model into the new
.thread_model field (and thus, I don't feel too bad making Parallel
the default, even if it is not always the safest).

And something I learned the hard way: enum ThreadModel _must_ be
#[repr(C)], otherwise Rust will compile a return type of this enum
into a 1-byte return, even though C expects sign-extension into a
4-byte return; the garbage left in the other three bytes (at least on
x86 architecture) would generally render .thread_model broken
otherwise.

Fix some typos in the docs while at it (we didn't use _ in the Rust
enum names).

Signed-off-by: Eric Blake <eblake@redhat.com>
plugins/rust/examples/ramdisk.rs
plugins/rust/nbdkit-rust-plugin.pod
plugins/rust/src/lib.rs