[Libguestfs] [libnbd PATCH 2/2] rust: Add missing files to EXTRA_DIST

2023-09-01 Thread Tage Johansson
--- rust/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/Makefile.am b/rust/Makefile.am index 027097a..c5933e5 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -36,6 +36,7 @@ source_files = \ examples/connect-command.rs \ examples/get-size.rs \

[Libguestfs] [libnbd PATCH 0/2] (Attempt to) fix some Rust CI failures

2023-09-01 Thread Tage Johansson
These are two minor fixes to the Rust bindings to fix some CI failures. -- Best regards, Tage Tage Johansson (2): generator: Add string_starts_with functions to utils.ml rust: Add missing files to EXTRA_DIST generator/utils.ml | 11 +++ generator/utils.mli | 3 +++ rust

[Libguestfs] [libnbd PATCH 1/2] generator: Add string_starts_with functions to utils.ml

2023-09-01 Thread Tage Johansson
Previously, the file Rust.ml used the function String.starts_with. But this function is not available in older versions of OCaml. So an identical function (string_starts_with) has been created in utils.ml to be used instead. --- generator/utils.ml | 11 +++ generator/utils.mli | 3 +++

Re: [Libguestfs] [libnbd PATCH 2/2] rust: Use mio::poll instead of requiring epoll

2023-09-01 Thread Tage Johansson
an async friendly handle type") CC: Tage Johansson Signed-off-by: Eric Blake --- rust/Cargo.toml | 2 +- rust/src/async_handle.rs | 46 +--- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml in

Re: [Libguestfs] [libnbd PATCH v9 5/7] rust: async: Add a couple of integration tests

2023-08-31 Thread Tage Johansson
On 8/30/2023 10:19 PM, Eric Blake wrote: On Wed, Aug 30, 2023 at 12:16:07PM -0500, Eric Blake wrote: error[E0425]: cannot find value `EPOLL_CTL_ADD` in crate `libc` https://www.reddit.com/r/rust/comments/65kflg/does_rust_have_native_epoll_support/ mentions how epoll is Linux-specific, and has

[Libguestfs] [libnbd PATCH] rust: Cleanups in examples/concurrent-read-write.rs.

2023-09-04 Thread Tage Johansson
This patch makes some small cleanups in rust/examples/concurrent-read-write.rs. Specificly, it refrases one comment, removes some outcommented code, and removes a completely redundent if statement. It also replaces a hard coded number with the index of the task as seed to an RNG. ---

Re: [Libguestfs] [libnbd PATCH v9 6/7] rust: async: Add an example

2023-09-04 Thread Tage Johansson
On 9/1/2023 10:41 PM, Eric Blake wrote: On Sat, Aug 26, 2023 at 11:29:59AM +, Tage Johansson wrote: This patch adds an example using the asynchronous Rust bindings. --- rust/Cargo.toml| 1 + rust/examples/concurrent-read-write.rs | 149

Re: [Libguestfs] [libnbd PATCH 2/2] rust: Use mio::poll instead of requiring epoll

2023-09-04 Thread Tage Johansson
On 9/1/2023 3:41 PM, Eric Blake wrote: On Fri, Sep 01, 2023 at 08:35:58AM +, Tage Johansson wrote: On 8/30/2023 10:11 PM, Eric Blake wrote: CI shows our async handle fails to build on FreeBSD and MacOS (where epoll() is not available as a syscall, and therefore not available as a Rust

[Libguestfs] [libnbd PATCH] rust: Use mio::poll instead of requiring epoll

2023-09-04 Thread Tage Johansson
to epoll on Linux, and kqueue on BSD). Fixes: 223a9965 ("rust: async: Create an async friendly handle type") CC: Tage Johansson Signed-off-by: Eric Blake --- rust/Cargo.toml | 3 ++- rust/src/async_handle.rs | 40 +++- 2 files changed, 25

Re: [Libguestfs] [libnbd PATCH] rust: Use mio::poll instead of requiring epoll

2023-09-04 Thread Tage Johansson
On 9/4/2023 8:23 PM, Eric Blake wrote: On Mon, Sep 04, 2023 at 04:07:54PM +, Tage Johansson wrote: From: Eric Blake CI shows our async handle fails to build on FreeBSD and MacOS (where epoll() is not available as a syscall, and therefore not available as a Rust crate). We can instead

[Libguestfs] [libnbd PATCH v8 02/10] rust: Correct license field in Cargo.toml

2023-08-20 Thread Tage Johansson
Previously, the license field in rust/Cargo.toml was wrongly set to "LGPL-2.1-only". This commit changes it to the correct "LGPL-2.1-or-later", which conforms to the license preamble in the source files. --- rust/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git

[Libguestfs] [libnbd PATCH v8 08/10] rust: async: Use the modifies_fd flag to exclude calls

2023-08-20 Thread Tage Johansson
All handle calls which has the modifies_fd flag set to true will be excluded from AsyncHandle (the asynchronous handle in the rust bindings). This is a better approach then listing all calls that should be excluded in Rust.ml explicetly. --- generator/Rust.ml | 60

[Libguestfs] [libnbd PATCH v8 07/10] generator: Add `modifies_fd` flag to the [call] structure

2023-08-20 Thread Tage Johansson
Add a flag (modifies_fd) to the call structure in generator/API.ml which is set to true if the handle call may do something with the file descriptor. That is, it is true for all calls which are or may call aio_notify_*, including all synchronous commands like nbd_connect or nbd_opt_go. The

[Libguestfs] [libnbd PATCH v8 06/10] rust: async: Create an async friendly handle type

2023-08-20 Thread Tage Johansson
};\n"; + pr "self.add_command(completion_predicate)?;\n"; + pr "ret_rx.await.unwrap()\n"; + pr "}\n\n" + +(* Print an impl with all handle calls. *) +let print_rust_async_handle_impls () = + pr "impl AsyncHandle {\n"; + NameMap.iter print_rus

[Libguestfs] [libnbd PATCH v8 09/10] rust: async: Add a couple of integration tests

2023-08-20 Thread Tage Johansson
_handle.rs b/rust/tests/test_async_100_handle.rs new file mode 100644 index 000..e50bad9 --- /dev/null +++ b/rust/tests/test_async_100_handle.rs @@ -0,0 +1,25 @@ +// libnbd Rust test case +// Copyright Tage Johansson +// +// This library is free software; you can redistribute it and/or +//

[Libguestfs] [libnbd PATCH v8 10/10] rust: async: Add an example

2023-08-20 Thread Tage Johansson
This patch adds an example using the asynchronous Rust bindings. --- rust/Cargo.toml| 1 + rust/examples/concurrent-read-write.rs | 149 + rust/run-tests.sh.in | 2 + 3 files changed, 152 insertions(+) create mode 100644

[Libguestfs] [libnbd PATCH v8 04/10] rust: Make it possible to run examples with a URI

2023-08-20 Thread Tage Johansson
Previously, the examples fetch-first-sector and get-size in rust/examples only accepted a unix socket as argument. This commit makes it possible to provide a URI as well. --- rust/examples/fetch-first-sector.rs | 15 +++ rust/examples/get-size.rs | 20 +++- 2

[Libguestfs] [libnbd PATCH v8 05/10] generator: Add information about asynchronous handle calls

2023-08-20 Thread Tage Johansson
A new field (async_kind) is added to the call data type in generator/API.ml*. The purpose is to tell if a certain handle call is an asynchronous command and if so how one can know when it is completed. The motivation for this is that all asynchronous commands on the AsyncHandle in the Rust

[Libguestfs] [libnbd PATCH v8 03/10] rust: Format some files to conform to rustfmt and rustfmt.toml

2023-08-20 Thread Tage Johansson
Some Rust files were previously not formatted according to rustfmt and the top-level rustfmt.toml. This commit correct the formatting in those files. --- rust/examples/connect-command.rs | 1 - rust/tests/test_200_connect_command.rs | 11 ++- rust/tests/test_300_get_size.rs

[Libguestfs] [libnbd PATCH v8 01/10] rust: Specify minimum Rust version in Cargo.toml

2023-08-20 Thread Tage Johansson
+20,10 @@ [workspace.package] authors = ["Tage Johansson"] version = "0.1.0" +# Make sure that the values of the edition and rust-version fields in +# rust_test/Cargo.toml matches the values here. edition = "2021" +rust-version = "1.69" description = &qu

[Libguestfs] [libnbd PATCH v8 00/10] Rust Bindings for Libnbd

2023-08-20 Thread Tage Johansson
Tage Johansson (10): rust: Specify minimum Rust version in Cargo.toml rust: Correct license field in Cargo.toml rust: Format some files to conform to rustfmt and rustfmt.toml rust: Make it possible to run examples with a URI generator: Add information about asynchronous handle calls rust

Re: [Libguestfs] [libnbd PATCH v7 0/9] Rust Bindings for Libnbd

2023-08-16 Thread Tage Johansson
On 8/16/2023 9:11 PM, Eric Blake wrote: On Thu, Aug 10, 2023 at 11:24:27AM +, Tage Johansson wrote: This is the 7th version of the Rust bindings for Libnbd. It is more or less identical to the 6th version without the already merged patches. Best regards, Tage I still hope to do more

Re: [Libguestfs] [libnbd PATCH v5 02/12] rust: Add a couple of integration tests

2023-08-16 Thread Tage Johansson
On 8/16/2023 11:35 PM, Eric Blake wrote: On Thu, Aug 03, 2023 at 03:36:06PM +, Tage Johansson wrote: A couple of integration tests are added in rust/tests. They are mostly ported from the OCaml tests. --- Overall, this looked like a nice counterpart to the OCaml unit tests, and I

Re: [Libguestfs] [libnbd PATCH v7 0/9] Rust Bindings for Libnbd

2023-08-18 Thread Tage Johansson
On 8/17/2023 6:09 PM, Richard W.M. Jones wrote: On Thu, Aug 17, 2023 at 09:29:47AM -0500, Eric Blake wrote: On Thu, Aug 17, 2023 at 04:13:36AM +, Tage Johansson wrote: It is possible to add a minimum version requirement in Cargo.toml, I guess I should do that to make the errors a bit

[Libguestfs] [libnbd PATCH v9 4/7] rust: async: Use the modifies_fd flag to exclude calls

2023-08-26 Thread Tage Johansson
All handle calls which has the modifies_fd flag set to true will be excluded from AsyncHandle (the asynchronous handle in the rust bindings). This is a better approach then listing all calls that should be excluded in Rust.ml explicetly. --- generator/Rust.ml | 29 - 1

[Libguestfs] [libnbd PATCH v9 3/7] generator: Add `modifies_fd` flag to the [call] structure

2023-08-26 Thread Tage Johansson
Add a flag (modifies_fd) to the call structure in generator/API.ml which is set to true if the handle call may do something with the file descriptor. That is, it is true for all calls which are or may call aio_notify_*, including all synchronous commands like nbd_connect or nbd_opt_go. The

[Libguestfs] [libnbd PATCH v9 5/7] rust: async: Add a couple of integration tests

2023-08-26 Thread Tage Johansson
_handle.rs b/rust/tests/test_async_100_handle.rs new file mode 100644 index 000..e50bad9 --- /dev/null +++ b/rust/tests/test_async_100_handle.rs @@ -0,0 +1,25 @@ +// libnbd Rust test case +// Copyright Tage Johansson +// +// This library is free software; you can redistribute it and/or +//

[Libguestfs] [libnbd PATCH v9 6/7] rust: async: Add an example

2023-08-26 Thread Tage Johansson
This patch adds an example using the asynchronous Rust bindings. --- rust/Cargo.toml| 1 + rust/examples/concurrent-read-write.rs | 149 + rust/run-tests.sh.in | 2 + 3 files changed, 152 insertions(+) create mode 100644

[Libguestfs] [libnbd PATCH v9 0/7] Rust Bindings for Libnbd

2023-08-26 Thread Tage Johansson
regards, Tage Tage Johansson (7): generator: Add information about asynchronous handle calls rust: async: Create an async friendly handle type generator: Add `modifies_fd` flag to the [call] structure rust: async: Use the modifies_fd flag to exclude calls rust: async: Add a couple

[Libguestfs] [libnbd PATCH v9 1/7] generator: Add information about asynchronous handle calls

2023-08-26 Thread Tage Johansson
A new field (async_kind) is added to the call data type in generator/API.ml*. The purpose is to tell if a certain handle call is an asynchronous command and if so how one can know when it is completed. The motivation for this is that all asynchronous commands on the AsyncHandle in the Rust

[Libguestfs] [libnbd PATCH v9 2/7] rust: async: Create an async friendly handle type

2023-08-26 Thread Tage Johansson
pl with all handle calls. *) +let print_rust_async_handle_impls () = + pr "impl AsyncHandle {\n"; + NameMap.iter print_rust_sync_handle_call sync_handle_calls; + async_handle_calls + |> NameMap.iter (fun name (aio_name, call, async_kind) -> + match async_kind with +

[Libguestfs] [libnbd PATCH v9 7/7] rust: Check that compilation works with default features disabled

2023-08-26 Thread Tage Johansson
The Rust crate has some default features, (tokio and log), to enable the asynchronous API and logging facilities. This patch extends the test suite to check that the crate compiles even with these features disabled. The crate did in fact not compile without those features, so the patch adds a

Re: [Libguestfs] [libnbd PATCH v8 06/10] rust: async: Create an async friendly handle type

2023-08-26 Thread Tage Johansson
On 8/24/2023 11:55 PM, Eric Blake wrote: On Sun, Aug 20, 2023 at 02:16:25PM +, Tage Johansson wrote: Create another handle type: AsyncHandle, which makes use of Rust's builtin asynchronous functions (see <https://doc.rust-lang.org/std/keyword.async.html>) and runs on top of the

Re: [Libguestfs] [libnbd PATCH v7 9/9] rust: async: Add an example

2023-08-15 Thread Tage Johansson
On 8/15/2023 11:07 AM, Richard W.M. Jones wrote: So what do I think about the patch series as a whole ... (in particular, the patches I didn't add Reviewed-by tags to). It would be much nicer IMHO if we didn't have to define callback lifetimes in this way, since they were not intended to be

Re: [Libguestfs] [libnbd PATCH v7 9/9] rust: async: Add an example

2023-08-15 Thread Tage Johansson
On 8/15/2023 11:00 AM, Richard W.M. Jones wrote: On Thu, Aug 10, 2023 at 11:24:36AM +, Tage Johansson wrote: This patch adds an example using the asynchronous Rust bindings. --- rust/Cargo.toml| 1 + rust/examples/concurrent-read-write.rs | 135

Re: [Libguestfs] [libnbd PATCH v5 01/12] rust: create basic Rust bindings

2023-08-14 Thread Tage Johansson
On 8/11/2023 2:00 PM, Eric Blake wrote: On Thu, Aug 03, 2023 at 03:36:05PM +, Tage Johansson wrote: This commit creates basic Rust bindings in the rust directory. The bindings are generated by generator/Rust.ml and generator/RustSys.ml. --- --- /dev/null +++ b/generator/RustSys.ml

Re: [Libguestfs] [libnbd PATCH v5 01/12] rust: create basic Rust bindings

2023-08-14 Thread Tage Johansson
On 8/11/2023 3:41 PM, Richard W.M. Jones wrote: On Fri, Aug 11, 2023 at 08:22:34AM -0500, Eric Blake wrote: On Thu, Aug 03, 2023 at 03:36:05PM +, Tage Johansson wrote: This commit creates basic Rust bindings in the rust directory. The bindings are generated by generator/Rust.ml

[Libguestfs] [libnbd PATCH] rust: Add cargo as an optional build dependency in README

2023-08-14 Thread Tage Johansson
This patch adds cargo to the list of optional build dependencies in top-level README.md. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c716661..5ce27bd 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,8 @@ ## Building from source * FUSE 3 to

Re: [Libguestfs] [libnbd PATCH v5 00/12] Rust Bindings for Libnbd

2023-08-14 Thread Tage Johansson
On 8/11/2023 10:54 PM, Eric Blake wrote: On Thu, Aug 03, 2023 at 03:36:04PM +, Tage Johansson wrote: A new version of the Rust bindings for Libnbd. Most changes have been mentioned as replies to the comments I got on v4. But the most significant change is probably that the patches have

Re: [Libguestfs] Libnbd asynchronous API with epoll

2023-07-07 Thread Tage Johansson
On 7/6/2023 7:06 PM, Nir Soffer wrote: - After calling for example aio_notify_read(3), can I know that the next reading from the file descriptor would block? No, you have to call again aio_get_direction() and poll again until the event happens. Well, what I mean is: After calling

[Libguestfs] libnbd: When are callbacks freed

2023-07-12 Thread Tage Johansson
Hello, While writing some tests for the Rust bindings, I discovered a memory leak with Valgrind due to a completion callback not being freed. More specificly, the completion callback of `aio_opt_info()` doesn't seem to be if `aio_opt_info()` failes. In this case, `aio_opt_info()` was called

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
On 7/13/2023 4:36 PM, Eric Blake wrote: On Thu, Jul 13, 2023 at 01:37:49PM +, Tage Johansson wrote: On 7/13/2023 3:26 PM, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 08:01:09AM -0500, Eric Blake wrote: On Thu, Jul 13, 2023 at 07:13:37AM -0500, Eric Blake wrote: I have replaced

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
Apologize if resending, but I'm not sure my previous email was actually delivered. On 7/12/2023 10:33 PM, Eric Blake wrote: On Wed, Jul 12, 2023 at 03:19:59PM +, Tage Johansson wrote: Hello, While writing some tests for the Rust bindings, I discovered a memory leak with Valgrind due

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
On 7/13/2023 2:13 PM, Eric Blake wrote: On Thu, Jul 13, 2023 at 12:03:24PM +0100, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 09:53:58AM +, Tage Johansson wrote: Apologize if resending, but I'm not sure my previous email was actually delivered. On 7/12/2023 10:33 PM, Eric Blake

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
On 7/13/2023 1:03 PM, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 09:53:58AM +, Tage Johansson wrote: Apologize if resending, but I'm not sure my previous email was actually delivered. On 7/12/2023 10:33 PM, Eric Blake wrote: On Wed, Jul 12, 2023 at 03:19:59PM +, Tage

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
On 7/13/2023 3:26 PM, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 08:01:09AM -0500, Eric Blake wrote: On Thu, Jul 13, 2023 at 07:13:37AM -0500, Eric Blake wrote: I have replaced a call to `nbd_opt_info()` with a call to `nbd_aio_opt_info()` and passed in a completion callback which

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
On 7/12/2023 10:33 PM, Eric Blake wrote: On Wed, Jul 12, 2023 at 03:19:59PM +, Tage Johansson wrote: Hello, While writing some tests for the Rust bindings, I discovered a memory leak with Valgrind due to a completion callback not being freed. More specificly, the completion callback

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
On 7/13/2023 5:37 PM, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 03:05:30PM +, Tage Johansson wrote: On 7/13/2023 4:36 PM, Eric Blake wrote: On Thu, Jul 13, 2023 at 01:37:49PM +, Tage Johansson wrote: On 7/13/2023 3:26 PM, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 08

[Libguestfs] [libnbd PATCH 03/10] generator: Add information about asynchronous handle calls

2023-07-19 Thread Tage Johansson
A new field `async_kind` is added to the `call` data type in generator/API.ml*. The purpose is to tell if a certain handle call is an asynchronous command and if so how one can know when it is completed. The motivation for this is that all asynchronous commands on the `AsyncHandle` in the Rust

[Libguestfs] [libnbd PATCH 04/10] generator: Add information about the lifetime of closures

2023-07-19 Thread Tage Johansson
Add a new field `cbkind` to the `closure` type in generator/API.ml*. It tells how many times the closure may be invoked and for how long time it might be used. More specifically, it can take any of these values: - `CBOnceCommand`: The closure may only be called once and shall not be called after

[Libguestfs] OCaml 5.0 warning

2023-07-12 Thread Tage Johansson
When running make with OCaml 5.0 installed, I get some warnings complaining about changed lib directory layout. It suggests adding "-I +unix -I +str" to the invocation of ocamlc. So this patch does just that. It does silence the warnings for me, but someone should probably test that it works with

[Libguestfs] [PATCH] generator: Add some arguments to ocamlc in generator/Makefile.am to silence some warnings

2023-07-12 Thread Tage Johansson
From: Tage Johansson When running make with OCaml 5.0.0, the following warnings are sometimes shown: ``` OCaml's lib directory layout changed in 5.0. The unix subdirectory has been automatically added to the search path, but you should add -I +unix to the command-line to silence this alert (e.g

Re: [Libguestfs] [libnbd PATCH 1/2] api: Tighten rules on completion.callback

2023-07-17 Thread Tage Johansson
: 1 call mid-command .free: 1 call completion .free: 1 call Reported-by: Tage Johansson Fixes: 6f4dcdab ("docs: Clarify how callbacks should handle errors", v1.11.8) Signed-off-by: Eric Blake --- docs/libnbd.pod | 26 -- lib/handle.c

[Libguestfs] [libnbd PATCH 00/10] Rust bindings

2023-07-19 Thread Tage Johansson
. The Rust bindings are of course not complete with these patches. The goal is still to get rid of the dependency on rust-bindgen and LLVM. And there needs to be documentation and thoroughly tested examples. Best regards, Tage Tage Johansson (10): generator: Add copyright argument to `generate_header

[Libguestfs] [libnbd PATCH 01/10] generator: Add copyright argument to `generate_header`

2023-07-19 Thread Tage Johansson
Add an optional argument: `?(copyright = "Red Hat")`, to `generate_header` in generator/utils.ml and generator/utils.mli. Makes it possible for authors to license generated code under their own name or organization. --- generator/utils.ml | 5 +++-- generator/utils.mli | 3 ++- 2 files changed,

[Libguestfs] [libnbd PATCH 07/10] rust: Add a couple of integration tests

2023-07-19 Thread Tage Johansson
nt library in userspace -# Copyright Red Hat +# Copyright Tage Johansson # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,4 +21,6 @@ set -e set -x -cargo test +requires nbdkit --version + +$CARGO tes

[Libguestfs] [libnbd PATCH 08/10] rust: Make it possible to run tests with Valgrind

2023-07-19 Thread Tage Johansson
Make it possible to run Rust tests with Valgrind with `make check-valgrind` in the rust directory. --- rust/Makefile.am | 3 +++ rust/run-tests.sh | 6 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/Makefile.am b/rust/Makefile.am index 9ff0779..5dc14e9 100644 ---

[Libguestfs] [libnbd PATCH 09/10] rust: async: Create an async friendly handle type

2023-07-19 Thread Tage Johansson
ll handle calls. *) +let print_rust_async_handle_impls () = + pr "impl AsyncHandle {\n"; + NameMap.iter print_rust_sync_handle_call sync_handle_calls; + NameMap.iter +(fun name (call, async_kind) -> + match async_kind with + | WithCompletionCallback -> + print_

[Libguestfs] [libnbd PATCH 05/10] rust: Use FnOnce for callbacks which only will be used once

2023-07-19 Thread Tage Johansson
For closures with `cbkind = CBOnceCommand` an `FnOnce` instead of an `FnMut` is required. (See [here](https://doc.rust-lang.org/std/ops/trait.FnOnce.html) for more information about `FnOnce.) This makes the API more ergonomic since the user can provide a closure which may only be called once

[Libguestfs] [libnbd PATCH 06/10] rust: Don't enforce 'static lifetimes on some closures

2023-07-19 Thread Tage Johansson
For closure arguments to synchronous commands which has `cbkind` `CBOnceCommand` or `CBManyCommand`, the requirement of the `'static` lifetime is removed. This greatly simplifies the API for the user as the user might otherwise have to use both an `Arc` and a `Mutex` when calling for instance

[Libguestfs] [libnbd PATCH 10/10] rust: async: Add a couple of integration tests

2023-07-19 Thread Tage Johansson
/test_async_100_handle.rs new file mode 100644 index 000..e50bad9 --- /dev/null +++ b/rust/tests/test_async_100_handle.rs @@ -0,0 +1,25 @@ +// libnbd Rust test case +// Copyright Tage Johansson +// +// This library is free software; you can redistribute it and/or +// modify it under the terms

[Libguestfs] Libnbd asynchronous API with epoll

2023-07-05 Thread Tage Johansson
Hello, As part of the Rust bindings for Libnbd, I try to integrate the asynchronous (aio_*) functions with Tokio , the most used asynchronous runtime in Rust. However, in its eventloop, Tokio uses epoll(7) instead of poll(2) (which is used internally in

Re: [Libguestfs] libnbd: When are callbacks freed

2023-07-13 Thread Tage Johansson
On 7/13/2023 6:50 PM, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 05:46:56PM +0100, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 04:18:03PM +, Tage Johansson wrote: On 7/13/2023 5:37 PM, Richard W.M. Jones wrote: On Thu, Jul 13, 2023 at 03:05:30PM +, Tage Johansson wrote

Re: [Libguestfs] [libnbd PATCH v4 08/11] generator: Add `modifies_fd` flag to the [call] structure

2023-08-03 Thread Tage Johansson
On 8/2/2023 6:39 PM, Richard W.M. Jones wrote: On Wed, Aug 02, 2023 at 12:40:53PM +, Tage Johansson wrote: Add a flag (`modifies_fd`) to the [call] structure in generator/API.ml which is set to [true] if the handle call may do something with the file descriptor. That is, it is [true

[Libguestfs] [libnbd PATCH v5 12/12] rust: async: Add an example

2023-08-03 Thread Tage Johansson
This patch adds an example using the asynchronous Rust bindings. --- rust/Cargo.toml| 1 + rust/examples/concurrent-read-write.rs | 135 + rust/run-tests.sh.in | 2 + 3 files changed, 138 insertions(+) create mode 100644

Re: [Libguestfs] [libnbd PATCH v4 04/11] rust: Use more specific closure traits

2023-08-03 Thread Tage Johansson
On 8/2/2023 6:32 PM, Richard W.M. Jones wrote: On Wed, Aug 02, 2023 at 12:40:49PM +, Tage Johansson wrote: For closures with `cb,count = CBOnce`, `FnOnce` will be used instead of I think there's an extra ',' here. Previous comments about use of markdown apply too. `FnMut`. Moreover

Re: [Libguestfs] [libnbd PATCH v4 11/11] rust: Add some examples

2023-08-03 Thread Tage Johansson
On 8/2/2023 6:53 PM, Richard W.M. Jones wrote: On Wed, Aug 02, 2023 at 12:40:56PM +, Tage Johansson wrote: This patch adds a few examples in rust/examples/. The examples are compiled and run as part of the test suite. --- rust/Makefile.am | 3 + rust/examples

[Libguestfs] [libnbd PATCH v5 00/12] Rust Bindings for Libnbd

2023-08-03 Thread Tage Johansson
A new version of the Rust bindings for Libnbd. Most changes have been mentioned as replies to the comments I got on v4. But the most significant change is probably that the patches have been reordered. Best regards, Tage Tage Johansson (12): rust: create basic Rust bindings rust: Add

[Libguestfs] [libnbd PATCH v5 10/12] rust: async: Use the modifies_fd flag to exclude calls

2023-08-03 Thread Tage Johansson
All handle calls which has the modifies_fd flag set to true will be excluded from AsyncHandle (the asynchronous handle in the rust bindings). This is a better approach then listing all calls that should be excluded in Rust.ml explicetly. --- generator/Rust.ml | 60

[Libguestfs] [libnbd PATCH v5 04/12] rust: Add some examples

2023-08-03 Thread Tage Johansson
This patch adds a few examples in rust/examples/. The examples are compiled and run as part of the test suite. --- rust/Cargo.toml | 2 ++ rust/Makefile.am| 3 +++ rust/examples/connect-command.rs| 39 +

[Libguestfs] [libnbd PATCH v5 05/12] generator: Add information about asynchronous handle calls

2023-08-03 Thread Tage Johansson
A new field (async_kind) is added to the call data type in generator/API.ml*. The purpose is to tell if a certain handle call is an asynchronous command and if so how one can know when it is completed. The motivation for this is that all asynchronous commands on the AsyncHandle in the Rust

[Libguestfs] [libnbd PATCH v5 01/12] rust: create basic Rust bindings

2023-08-03 Thread Tage Johansson
b/generator/Makefile.am index c3d53b2..5e148be 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -60,6 +60,10 @@ sources = \ OCaml.ml \ GoLang.mli \ GoLang.ml \ + RustSys.mli \ + RustSys.ml \ + Rust.mli \ + Rust.ml \ generator

[Libguestfs] [libnbd PATCH v5 02/12] rust: Add a couple of integration tests

2023-08-03 Thread Tage Johansson
x f4d220c..d45b1bf 100755 --- a/rust/run-tests.sh.in +++ b/rust/run-tests.sh.in @@ -1,6 +1,6 @@ #!/bin/bash - # nbd client library in userspace -# Copyright Red Hat +# Copyright Tage Johansson # # This library is free software; you can redistribute it and/or # modify it under the terms of the

[Libguestfs] [libnbd PATCH v5 03/12] rust: Make it possible to run tests with Valgrind

2023-08-03 Thread Tage Johansson
Make it possible to run Rust tests with Valgrind with `make check-valgrind` in the rust directory. --- rust/Makefile.am | 3 +++ rust/run-tests.sh.in | 6 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/Makefile.am b/rust/Makefile.am index db8fc66..f9830d0 100644 ---

[Libguestfs] [libnbd PATCH v5 06/12] generator: Add information about the lifetime of closures

2023-08-03 Thread Tage Johansson
Add two new fields, cblifetime and cbcount, to the `closure` type in generator/API.ml*. cblifetime tells if the closure may only be used for as long as the command is in flight or if the closure may be used until the handle is destructed. cbcount tells whether the closure may be called many times

[Libguestfs] [libnbd PATCH v5 09/12] generator: Add `modifies_fd` flag to the [call] structure

2023-08-03 Thread Tage Johansson
Add a flag (modifies_fd) to the call structure in generator/API.ml which is set to true if the handle call may do something with the file descriptor. That is, it is true for all calls which are or may call aio_notify_*, including all synchronous commands like nbd_connect or nbd_opt_go. The

[Libguestfs] [libnbd PATCH v5 08/12] rust: async: Create an async friendly handle type

2023-08-03 Thread Tage Johansson
; + pr "self.add_command(completion_predicate)?;\n"; + pr "ret_rx.await.unwrap()\n"; + pr "}\n\n" + +(* Print an impl with all handle calls. *) +let print_rust_async_handle_impls () = + pr "impl AsyncHandle {\n"; + NameMap.iter print_rust_sync_han

[Libguestfs] [libnbd PATCH v5 11/12] rust: async: Add a couple of integration tests

2023-08-03 Thread Tage Johansson
ync_100_handle.rs b/rust/tests/test_async_100_handle.rs new file mode 100644 index 000..e50bad9 --- /dev/null +++ b/rust/tests/test_async_100_handle.rs @@ -0,0 +1,25 @@ +// libnbd Rust test case +// Copyright Tage Johansson +// +// This library is free software; you can redistribute it and/or +//

[Libguestfs] [libnbd PATCH v5 07/12] rust: Use more specific closure traits

2023-08-03 Thread Tage Johansson
For closures with cbcount = CBOnce, FnOnce will be used instead of FnMut. Moreover, closures in synchronous commands with cblifetime = CBCommand will not need to live for the static lifetime. See [here](https://doc.rust-lang.org/std/ops/trait.FnOnce.html) for more information about the advantages

Re: [Libguestfs] [libnbd PATCH 07/10] rust: Add a couple of integration tests

2023-07-21 Thread Tage Johansson
On 7/19/2023 4:50 PM, Richard W.M. Jones wrote: On Wed, Jul 19, 2023 at 09:09:51AM +, Tage Johansson wrote: +fn test_connect_command() { +let nbd = libnbd::Handle::new().unwrap(); +nbd.connect_command(&[ +c_str!("nbdkit"), +c_str!("-s"),

Re: [Libguestfs] [libnbd PATCH 09/10] rust: async: Create an async friendly handle type

2023-07-21 Thread Tage Johansson
On 7/21/2023 12:05 PM, Richard W.M. Jones wrote: On Fri, Jul 21, 2023 at 09:58:52AM +, Tage Johansson wrote: On 7/19/2023 4:47 PM, Richard W.M. Jones wrote: On Wed, Jul 19, 2023 at 09:09:53AM +, Tage Johansson wrote: Create another handle type: `AsyncHandle`, which

Re: [Libguestfs] [libnbd PATCH 04/10] generator: Add information about the lifetime of closures

2023-07-21 Thread Tage Johansson
On 7/19/2023 4:35 PM, Richard W.M. Jones wrote: On Wed, Jul 19, 2023 at 09:09:48AM +, Tage Johansson wrote: Add a new field `cbkind` to the `closure` type in generator/API.ml*. It tells how many times the closure may be invoked and for how long time it might be used. More specifically

Re: [Libguestfs] [libnbd PATCH 09/10] rust: async: Create an async friendly handle type

2023-07-21 Thread Tage Johansson
On 7/19/2023 4:47 PM, Richard W.M. Jones wrote: On Wed, Jul 19, 2023 at 09:09:53AM +, Tage Johansson wrote: Create another handle type: `AsyncHandle`, which makes use of Rust's builtin asynchronous functions (see <https://doc.rust-lang.org/std/keyword.async.html>) and runs

[Libguestfs] [libnbd PATCH v3 00/10] Rust bindings

2023-07-24 Thread Tage Johansson
Hello again, In patch v2, two tests were not compiling. This update fixes that. Best regards, Tage Tage Johansson (10): rust: create basic Rust bindings generator: Add information about asynchronous handle calls generator: Add information about the lifetime of closures rust: Use more

[Libguestfs] [libnbd PATCH v3 06/10] rust: Make it possible to run tests with Valgrind

2023-07-24 Thread Tage Johansson
Make it possible to run Rust tests with Valgrind with `make check-valgrind` in the rust directory. --- rust/Makefile.am | 3 +++ rust/run-tests.sh | 6 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/Makefile.am b/rust/Makefile.am index d353949..cc17bb9 100644 ---

[Libguestfs] [libnbd PATCH v3 03/10] generator: Add information about the lifetime of closures

2023-07-24 Thread Tage Johansson
Add two new fields, `cblifetime` and `cbcount`, to the `closure` type in generator/API.ml*. `cblifetime` tells if the closure may only be used for as long as the command is in flight or if the closure may be used until the handle is destructed. `cbcount` tells whether the closure may be called

[Libguestfs] [libnbd PATCH v3 07/10] rust: async: Create an async friendly handle type

2023-07-24 Thread Tage Johansson
; + NameMap.iter print_rust_sync_handle_call sync_handle_calls; + NameMap.iter +(fun name (call, async_kind) -> + match async_kind with + | WithCompletionCallback -> + print_rust_async_handle_call_with_completion_cb name call + | ChangesState (predicate, value) -> +

[Libguestfs] [libnbd PATCH v3 08/10] rust: async: Add a couple of integration tests

2023-07-24 Thread Tage Johansson
/test_async_100_handle.rs new file mode 100644 index 000..e50bad9 --- /dev/null +++ b/rust/tests/test_async_100_handle.rs @@ -0,0 +1,25 @@ +// libnbd Rust test case +// Copyright Tage Johansson +// +// This library is free software; you can redistribute it and/or +// modify it under the terms

[Libguestfs] [libnbd PATCH v3 05/10] rust: Add a couple of integration tests

2023-07-24 Thread Tage Johansson
nt library in userspace -# Copyright Red Hat +# Copyright Tage Johansson # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,4 +21,6 @@ set -e set -x -cargo test +requires nbdkit --version + +$CARGO tes

[Libguestfs] [libnbd PATCH v3 09/10] generator: Add `modifies_fd` flag to the [call] structure

2023-07-24 Thread Tage Johansson
Add a flag (`modifies_fd`) to the [call] structure in generator/API.ml which is set to [true] if the handle call may do something with the file descriptor. That is, it is [true] for all calls which are or may call [aio_notify_*], including all synchronous commands like [nbd_connect] or

[Libguestfs] [libnbd PATCH v3 04/10] rust: Use more specific closure traits

2023-07-24 Thread Tage Johansson
For closures with `cb,count = CBOnce`, `FnOnce` will be used instead of `FnMut`. Moreover, closures in synchronous commands with `cblifetime = CBCommand` will not need to live for the static lifetime. See [here](https://doc.rust-lang.org/std/ops/trait.FnOnce.html) for more information about the

[Libguestfs] [libnbd PATCH v3 02/10] generator: Add information about asynchronous handle calls

2023-07-24 Thread Tage Johansson
A new field `async_kind` is added to the `call` data type in generator/API.ml*. The purpose is to tell if a certain handle call is an asynchronous command and if so how one can know when it is completed. The motivation for this is that all asynchronous commands on the `AsyncHandle` in the Rust

[Libguestfs] [libnbd PATCH v3 10/10] rust: async: Use the `modifies_fd` flag to exclude calls

2023-07-24 Thread Tage Johansson
All handle calls which has the `modifies_fd` flag set to [true] will be excluded from `AsyncHandle` (the asynchronous handle in the rust bindings). This is a better approach then listing all calls that should be excluded in Rust.ml explicetly. --- generator/Rust.ml | 63

[Libguestfs] [libnbd PATCH v2 03/10] generator: Add information about the lifetime of closures

2023-07-24 Thread Tage Johansson
Add two new fields, `cblifetime` and `cbcount`, to the `closure` type in generator/API.ml*. `cblifetime` tells if the closure may only be used for as long as the command is in flight or if the closure may be used until the handle is destructed. `cbcount` tells whether the closure may be called

[Libguestfs] [libnbd PATCH v2 04/10] rust: Use more specific closure traits

2023-07-24 Thread Tage Johansson
For closures with `cb,count = CBOnce`, `FnOnce` will be used instead of `FnMut`. Moreover, closures in synchronous commands with `cblifetime = CBCommand` will not need to live for the static lifetime. See [here](https://doc.rust-lang.org/std/ops/trait.FnOnce.html) for more information about the

[Libguestfs] [libnbd PATCH v2 07/10] rust: async: Create an async friendly handle type

2023-07-24 Thread Tage Johansson
; + NameMap.iter print_rust_sync_handle_call sync_handle_calls; + NameMap.iter +(fun name (call, async_kind) -> + match async_kind with + | WithCompletionCallback -> + print_rust_async_handle_call_with_completion_cb name call + | ChangesState (predicate, value) -> +

[Libguestfs] [libnbd PATCH v2 00/10] Second draft of the Rust bindings

2023-07-24 Thread Tage Johansson
feedback. Best regards, Tage Tage Johansson (10): rust: create basic Rust bindings generator: Add information about asynchronous handle calls generator: Add information about the lifetime of closures rust: Use more specific closure traits rust: Add a couple of integration tests rust: Make

[Libguestfs] [libnbd PATCH v2 09/10] generator: Add `modifies_fd` flag to the [call] structure

2023-07-24 Thread Tage Johansson
Add a flag (`modifies_fd`) to the [call] structure in generator/API.ml which is set to [true] if the handle call may do something with the file descriptor. That is, it is [true] for all calls which are or may call [aio_notify_*], including all synchronous commands like [nbd_connect] or

[Libguestfs] [libnbd PATCH v2 10/10] rust: async: Use the `modifies_fd` flag to exclude calls

2023-07-24 Thread Tage Johansson
All handle calls which has the `modifies_fd` flag set to [true] will be excluded from `AsyncHandle` (the asynchronous handle in the rust bindings). This is a better approach then listing all calls that should be excluded in Rust.ml explicetly. --- generator/Rust.ml | 63

[Libguestfs] [libnbd PATCH v2 06/10] rust: Make it possible to run tests with Valgrind

2023-07-24 Thread Tage Johansson
Make it possible to run Rust tests with Valgrind with `make check-valgrind` in the rust directory. --- rust/Makefile.am | 3 +++ rust/run-tests.sh | 6 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/Makefile.am b/rust/Makefile.am index d353949..cc17bb9 100644 ---

  1   2   >