[Libguestfs] Rust Bindings for Libnbd

2023-06-20 Thread Tage Johansson
This is Tage. I am a Google Summer of Code contributer this summer working on Rust bindings for Libnbd. So far, I have made a very basic first draft which is far from complete. But I'll send the patches anyway so you can take a look. I have created "generator/Rust.ml" which generates Rust code for

[Libguestfs] [PATCH 2/2] rust: add some (but not yet all) tests

2023-06-20 Thread Tage Johansson
From: Tage Johansson --- rust/Cargo.toml | 3 + rust/tests/test_100_handle.rs | 25 rust/tests/test_110_defaults.rs | 33 ++ rust/tests/test_120_set_non_defaults.rs | 56 + rust/tests/test_130_private_data.rs | 28

[Libguestfs] Rust Bindings for Libnbd

2023-06-26 Thread Tage Johansson
>> +let hidden_handle_calls : NameSt.t = + NameSet.of_list +[ >> "get_debug"; "set_debug"; "set_debug_callback"; >> "clear_debug_callback" ] > > So, hmm. Isn't it better to track this in the API.ml file? Perhaps, but it is only specific to Rust, so I thought it was best placed in the Rust.ml

[Libguestfs] [PATCH v2 1/3] generator: Move [camel_case] function from GoLang.ml to utils.ml as it will be used in Rust.ml as well

2023-06-26 Thread Tage Johansson
From: Tage Johansson --- generator/GoLang.ml | 11 --- generator/utils.ml | 8 generator/utils.mli | 3 +++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/generator/GoLang.ml b/generator/GoLang.ml index 4ab6b26..50ed722 100644 --- a/generator/GoLang.ml

[Libguestfs] [PATCH v2 3/3] rust: add some (but not yet all) tests

2023-06-26 Thread Tage Johansson
From: Tage Johansson --- rust/Cargo.toml | 3 + rust/Makefile.am| 1 + rust/run-tests.sh | 6 +- rust/tests/test_100_handle.rs | 25 +++ rust/tests/test_110_defaults.rs | 33 ++ rust/tests

[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 L

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 aio_not

[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

[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
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 +0000, Tage Johansson wrote: Hello, While writing some tests for the Rust bindings, I discovered a memory leak with Valgrin

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 of

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 +0000,

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 just

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

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 a

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

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 1/2] api: Tighten rules on completion.callback

2023-07-17 Thread Tage Johansson
.callback: 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

[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 bind

[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] [libnbd PATCH 09/10] rust: async: Create an async friendly handle type

2023-07-19 Thread Tage Johansson
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_handle_call sync_handle_calls; + NameMap.iter +(fun name (call, async_kind) -> + match async_kind with +

[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 instea

[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_h

[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, 5

[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 `opt_

[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 --- a/rust

[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 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 of

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/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 on

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, it

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

[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 many

[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 adv

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

2023-07-24 Thread Tage Johansson
sync_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_rust_async_handle_call_with_completion_cb name

[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 it

[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 [nbd_opt_go]

[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 --- a/rust

[Libguestfs] [libnbd PATCH v2 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 v2 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 of

[Libguestfs] [libnbd PATCH v2 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 bind

[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 --- a/rust

[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 many

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

2023-07-24 Thread Tage Johansson
sync_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_rust_async_handle_call_with_completion_cb name

[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 of

[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 [nbd_opt_go]

[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 adv

[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 bind

[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 ++-

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

2023-07-24 Thread Tage Johansson
On 7/24/2023 9:22 PM, Stefan Hajnoczi wrote: On Fri, Jul 21, 2023 at 11:37:09AM +0100, Richard W.M. Jones wrote: On Fri, Jul 21, 2023 at 10:13:02AM +, Tage Johansson wrote: On 7/19/2023 4:35 PM, Richard W.M. Jones wrote: On Wed, Jul 19, 2023 at 09:09:48AM +, Tage Johansson wrote

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

2023-07-26 Thread Tage Johansson
Johansson wrote: 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

Re: [Libguestfs] [libnbd PATCH v3 01/10] rust: create basic Rust bindings

2023-07-31 Thread Tage Johansson
On 7/27/2023 9:43 AM, Richard W.M. Jones wrote: On Wed, Jul 26, 2023 at 09:58:03AM +, Tage Johansson wrote: I have never used rpm, but if you are using Fedora, the following command should be enough:     dnf install clang-devel We need to work with whatever environment we find ourselves

[Libguestfs] [libnbd PATCH v4 00/11] Rust Bindings for Libnbd

2023-08-02 Thread Tage Johansson
been somewhat changed. Secondly, the dependency on rust-bindgen is finally removed. So LLVM is no longer needed to build the bindings. Best regards, Tage Tage Johansson (11): rust: create basic Rust bindings generator: Add information about asynchronous handle calls generator: Add

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

2023-08-02 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 251a139..19dbf02 100644 --- a/rust

[Libguestfs] [libnbd PATCH v4 09/11] rust: async: Use the `modifies_fd` flag to exclude calls

2023-08-02 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 v4 02/11] generator: Add information about asynchronous handle calls

2023-08-02 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 bind

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

2023-08-02 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]

[Libguestfs] [libnbd PATCH v4 05/11] rust: Add a couple of integration tests

2023-08-02 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 v4 04/11] rust: Use more specific closure traits

2023-08-02 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 adv

[Libguestfs] [libnbd PATCH v4 07/11] rust: async: Create an async friendly handle type

2023-08-02 Thread Tage Johansson
_tx.take().unwrap().send(ret).ok();\n"; + pr " true\n"; + pr "};\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_

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

2023-08-02 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/Makefile.am | 3 + rust/examples/concurrent-read-write.rs | 135 + rust/examples/connect-command.rs | 39 +++ rust/exam

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

2023-08-02 Thread Tage Johansson
t;, "min_const_gen"] } diff --git a/rust/tests/test_async_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 +// +// T

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

2023-08-02 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

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. `F

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] for

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 08/12] rust: async: Create an async friendly handle type

2023-08-03 Thread Tage Johansson
ret_tx.take().unwrap().send(ret).ok();\n"; + pr " true\n"; + pr "};\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

[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 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 a

[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 + rust/examples/fetch-

[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 bindings

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

2023-08-03 Thread Tage Johansson
t a/generator/Makefile.am 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

[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 o

[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 motivat

[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 o

[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 rust/e

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

2023-08-04 Thread Tage Johansson
On 8/4/2023 10:54 AM, Richard W.M. Jones wrote: I applied the first 4 patches to my local repo. 'make clean' now fails at: error: failed to load manifest for dependency `libnbd-sys` Caused by: failed to parse manifest at `/home/rjones/d/libnbd/rust/libnbd-sys/Cargo.toml` Caused

[Libguestfs] [libnbd PATCH v6 01/13] generator: Add an optional `formatter` argument to the [output_to] function in generator/utils.mli. This defaults to [None] and the only code formatter supported s

2023-08-04 Thread Tage Johansson
--- generator/utils.ml | 13 +++-- generator/utils.mli | 8 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/generator/utils.ml b/generator/utils.ml index 61cce87..201fb54 100644 --- a/generator/utils.ml +++ b/generator/utils.ml @@ -419,7 +419,10 @@ let files_equa

[Libguestfs] [libnbd PATCH v6 02/13] rust: create basic Rust bindings

2023-08-04 Thread Tage Johansson
quot; diff --git a/generator/Makefile.am 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.

[Libguestfs] [libnbd PATCH v6 00/13] Rust Bindings for Libnbd

2023-08-04 Thread Tage Johansson
This is the 6th version of the Rust bindings. It solves a problem with make clean and includes one more patch which I for some reason thought was already upstream. Best regards, Tage Tage Johansson (13): generator: Add an optional `formatter` argument to the [output_to] function in

[Libguestfs] [libnbd PATCH v6 04/13] rust: Make it possible to run tests with Valgrind

2023-08-04 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 1e63724..bb2e6f0 100644 ---

[Libguestfs] [libnbd PATCH v6 07/13] generator: Add information about the lifetime of closures

2023-08-04 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 o

[Libguestfs] [libnbd PATCH v6 05/13] rust: Add some examples

2023-08-04 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 + rust/examples/fetch-

[Libguestfs] [libnbd PATCH v6 06/13] generator: Add information about asynchronous handle calls

2023-08-04 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 bindings

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

2023-08-04 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 v6 11/13] rust: async: Use the modifies_fd flag to exclude calls

2023-08-04 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 v6 10/13] generator: Add `modifies_fd` flag to the [call] structure

2023-08-04 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 motivat

[Libguestfs] [libnbd PATCH v6 03/13] rust: Add a couple of integration tests

2023-08-04 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 v6 09/13] rust: async: Create an async friendly handle type

2023-08-04 Thread Tage Johansson
ret_tx.take().unwrap().send(ret).ok();\n"; + pr " true\n"; + pr "};\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

[Libguestfs] [libnbd PATCH v6 13/13] rust: async: Add an example

2023-08-04 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 rust/e

[Libguestfs] [libnbd PATCH v6 08/13] rust: Use more specific closure traits

2023-08-04 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 o

Re: [Libguestfs] [libnbd PATCH v6 04/13] rust: Make it possible to run tests with Valgrind

2023-08-04 Thread Tage Johansson
On 8/4/2023 3:04 PM, Richard W.M. Jones wrote: On Fri, Aug 04, 2023 at 11:34:07AM +, Tage Johansson wrote: 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

[Libguestfs] [libnbd PATCH v7 2/9] generator: Add information about asynchronous handle calls

2023-08-10 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 bindings

  1   2   >