Re: [Libguestfs] [libnbd PATCH v3 07/22] generator: Add struct nbd_extent in prep for 64-bit extents

2023-07-24 Thread Eric Blake
On Mon, Jul 24, 2023 at 07:04:15PM -0500, Eric Blake wrote: > On Wed, Jun 07, 2023 at 04:23:27PM +0200, Laszlo Ersek wrote: > > > +++ b/generator/GoLang.ml > > > @@ -524,6 +528,18 @@ let > > > copy(ret, s) > > > return ret > > > } > > > + > > > +func copy_extent_array (entries

Re: [Libguestfs] [libnbd PATCH v3 07/22] generator: Add struct nbd_extent in prep for 64-bit extents

2023-07-24 Thread Eric Blake
On Wed, Jun 07, 2023 at 04:23:27PM +0200, Laszlo Ersek wrote: > > +++ b/generator/GoLang.ml > > @@ -524,6 +528,18 @@ let > > copy(ret, s) > > return ret > > } > > + > > +func copy_extent_array (entries *C.nbd_extent, count C.size_t) > > []LibnbdExtent { > > +unsafePtr :=

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

2023-07-24 Thread Richard W.M. Jones
On Mon, Jul 24, 2023 at 03:22:56PM -0400, 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

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

2023-07-24 Thread Stefan Hajnoczi
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: > > >>Add a new field `cbkind` to the

Re: [Libguestfs] [libnbd PATCH v4 6/6] states: Break deadlock if server goofs on extended replies

2023-07-24 Thread Eric Blake
On Mon, Jul 24, 2023 at 11:58:32AM +0200, Laszlo Ersek wrote: > On 7/21/23 18:08, Eric Blake wrote: > > One of the benefits of extended replies is that we can do a > > fixed-length read for the entire header of every server reply, which > > is fewer syscalls than the split-read approach required

[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 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 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 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 05/10] rust: Add a couple of integration tests

2023-07-24 Thread Tage Johansson
A couple of integration tests are added in rust/tests. They are mostly ported from the OCaml tests. --- rust/Cargo.toml | 4 + rust/Makefile.am | 1 + rust/run-tests.sh| 6 +-

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

2023-07-24 Thread Tage Johansson
Create another handle type: `AsyncHandle`, which makes use of Rust's builtin asynchronous functions (see ) and runs on top of the Tokio runtime (see ). For every asynchronous command, like `aio_connect()`, a corresponding

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

2023-07-24 Thread Tage Johansson
Add a couple of integration tests as rust/tests/test_async_*.rs. They are very similar to the tests for the synchronous API. --- rust/tests/test_async_100_handle.rs | 25 +++ rust/tests/test_async_200_connect_command.rs | 34 rust/tests/test_async_210_opt_abort.rs| 40

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

Re: [Libguestfs] [libnbd PATCH v4 4/6] states: Prepare to send 64-bit requests

2023-07-24 Thread Laszlo Ersek
On 7/21/23 18:08, Eric Blake wrote: > Support sending 64-bit requests if extended headers were negotiated. > This includes setting NBD_CMD_FLAG_PAYLOAD_LEN any time we send an > extended NBD_CMD_WRITE; this is such a fundamental part of the > protocol that for now it is easier to silently ignore

Re: [Libguestfs] [libnbd PATCH v4 6/6] states: Break deadlock if server goofs on extended replies

2023-07-24 Thread Laszlo Ersek
On 7/21/23 18:08, Eric Blake wrote: > One of the benefits of extended replies is that we can do a > fixed-length read for the entire header of every server reply, which > is fewer syscalls than the split-read approach required by structured > replies. But one of the drawbacks of doing a large

Re: [Libguestfs] [libnbd PATCH v4 5/6] states: Prepare to receive 64-bit replies

2023-07-24 Thread Laszlo Ersek
On 7/21/23 18:08, Eric Blake wrote: > Support receiving headers for 64-bit replies if extended headers were > negotiated. We already insist that the server not send us too much > payload in one reply, so we can exploit that and continue to use > h->payload_left as a 32-bit length for the rest of

Re: [Libguestfs] [libnbd PATCH v4 1/6] internal: Track chunk payload length left

2023-07-24 Thread Laszlo Ersek
On 7/21/23 18:08, Eric Blake wrote: > While working on later patches, I noticed that I was frequently > referring to the wire contents of h->sbuf.reply.hdr.structured.length, > byte-swapping it, then repeating open-coded math for how many bytes > were consumed in earlier states. It's easier to

Re: [Libguestfs] [libnbd PATCH v4 2/6] block_status: Refactor array storage

2023-07-24 Thread Laszlo Ersek
On 7/21/23 18:08, Eric Blake wrote: > For 32-bit block status, we were able to cheat and use an array with > an odd number of elements, with array[0] holding the context id, and > passing [1] to the user's callback. But once we have 64-bit > extents, we can no longer abuse array element 0 like

Re: [Libguestfs] [libnbd PATCH v4 3/6] protocol: Add definitions for extended headers

2023-07-24 Thread Laszlo Ersek
On 7/21/23 18:08, Eric Blake wrote: > Add the magic numbers and new structs necessary to implement the NBD > protocol extension of extended headers providing 64-bit lengths. This > corresponds to upstream nbd commits 36abf47d and a9384e2f on the > extension-ext-header branch[1] (commit e6f3b94a

[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

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

2023-07-24 Thread Tage Johansson
A couple of integration tests are added in rust/tests. They are mostly ported from the OCaml tests. --- rust/Cargo.toml | 4 + rust/Makefile.am | 1 + rust/run-tests.sh| 6 +-

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

2023-07-24 Thread Tage Johansson
Add a couple of integration tests as rust/tests/test_async_*.rs. They are very similar to the tests for the synchronous API. --- rust/tests/test_async_100_handle.rs | 25 +++ rust/tests/test_async_200_connect_command.rs | 34 rust/tests/test_async_210_opt_abort.rs| 40

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

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

2023-07-24 Thread Tage Johansson
Create another handle type: `AsyncHandle`, which makes use of Rust's builtin asynchronous functions (see ) and runs on top of the Tokio runtime (see ). For every asynchronous command, like `aio_connect()`, a corresponding

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

2023-07-24 Thread Tage Johansson
This second version of the Rust bindings splits up the `cbkind` field in the `closure` structure into `cblifetime` and `cbcount` in API.ml. It also adds a new field to the `call` structure: `modifies_fd`, which tells whether the call may modify the file descriptor. Please comment and give

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