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 comments about tokio
trying to build on top of mio in order to be platform-independent (mio
uses epoll on Linux where it is available, but does not require epoll
on other platforms).

So I spent a couple hours experimenting with whether I could use
mio::poll instead of epoll, and at least got things compiling on
FreeBSD with the tests still passing on Linux (I'm not quite set up to
actually prove that the tests work on FreeBSD).  Review appreciated:

https://listman.redhat.com/archives/libguestfs/2023-August/032464.html



Interesting. I tried with the polling 
 crate in order to get a cross 
platform version of epoll. But the disconnect call failes for some 
reason then.



I'll try to take a look at mio later today.


--

Best regards,
Tage

___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs


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

2023-08-30 Thread Eric Blake
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 comments about tokio
> trying to build on top of mio in order to be platform-independent (mio
> uses epoll on Linux where it is available, but does not require epoll
> on other platforms).

So I spent a couple hours experimenting with whether I could use
mio::poll instead of epoll, and at least got things compiling on
FreeBSD with the tests still passing on Linux (I'm not quite set up to
actually prove that the tests work on FreeBSD).  Review appreciated:

https://listman.redhat.com/archives/libguestfs/2023-August/032464.html

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs



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

2023-08-30 Thread Eric Blake
On Wed, Aug 30, 2023 at 08:42:00AM -0500, Eric Blake wrote:
> On Tue, Aug 29, 2023 at 05:17:19PM -0500, Eric Blake wrote:
> > On Sat, Aug 26, 2023 at 11:29:58AM +, Tage Johansson wrote:
> > > 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_460_block_status.rs |  98 
> > >  rust/tests/test_async_620_stats.rs|  69 
> > 
> > Our series crossed paths.  My commit 5aec7d3b add
> > test_465_block_status_64.rs, but this commit of yours (at 0ed92592)
> > did not add a counterpart async test, because you started your series
> > before I added the 64-bit block status API.  Since I heavily
> > copy/pasted the synchronous 460 into 465, I'll probably end up doing
> > the same for the async version, unless you beat me to it.
> 
> I've done that in commit ac633f84.  It missed Rich's cut of release
> 1.17.4, and CI is now picking up a different set of failures, but it's
> progress.
> 
> x86_64-freebsd-current, aarch64-macos-13:
>Compiling epoll v4.3.3
> error[E0425]: cannot find value `EPOLL_CTL_ADD` in crate `libc`
>   --> 
> /.cargo/registry/src/index.crates.io-6f17d22bba15001f/epoll-4.3.3/src/lib.rs:19:27
>|
> 19 | EPOLL_CTL_ADD = libc::EPOLL_CTL_ADD,
>|   ^ not found in `libc`
>|
> help: consider importing this unit variant
>|
> 11 + use ControlOptions::EPOLL_CTL_ADD;

Note that epoll() is a Linux-specific syscall, with no direct BSD
counterpart, explaining the failures on FreeBSD and MacOS with its BSD
heritage.

https://www.reddit.com/r/rust/comments/65kflg/does_rust_have_native_epoll_support/
mentions how epoll is Linux-specific, and has comments about tokio
trying to build on top of mio in order to be platform-independent (mio
uses epoll on Linux where it is available, but does not require epoll
on other platforms).

Right now, I see rust/Cargo.tml is explicitly requiring epoll, which
means it can only be built on Linux.  Is there a way to drop the
explicit dependency on epoll, where we instead configure epoll to use
whatever it prefers (deferring to mio and eventually epoll on Linux,
but to other code on BSD)?  Or at a bare minimum, can we make it so
that compiling the Rust async handler be limited to Linux-only, while
building the synchronous code still works on BSD?

[If it doesn't show by the content of my questions, I'm still quite
new to Rust, and trying to figure out how crate dependencies work in
cross-platform environments]

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs



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

2023-08-30 Thread Eric Blake
On Tue, Aug 29, 2023 at 05:17:19PM -0500, Eric Blake wrote:
> On Sat, Aug 26, 2023 at 11:29:58AM +, Tage Johansson wrote:
> > 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_460_block_status.rs |  98 
> >  rust/tests/test_async_620_stats.rs|  69 
> 
> Our series crossed paths.  My commit 5aec7d3b add
> test_465_block_status_64.rs, but this commit of yours (at 0ed92592)
> did not add a counterpart async test, because you started your series
> before I added the 64-bit block status API.  Since I heavily
> copy/pasted the synchronous 460 into 465, I'll probably end up doing
> the same for the async version, unless you beat me to it.

I've done that in commit ac633f84.  It missed Rich's cut of release
1.17.4, and CI is now picking up a different set of failures, but it's
progress.

x86_64-freebsd-current, aarch64-macos-13:
   Compiling epoll v4.3.3
error[E0425]: cannot find value `EPOLL_CTL_ADD` in crate `libc`
  --> 
/.cargo/registry/src/index.crates.io-6f17d22bba15001f/epoll-4.3.3/src/lib.rs:19:27
   |
19 | EPOLL_CTL_ADD = libc::EPOLL_CTL_ADD,
   |   ^ not found in `libc`
   |
help: consider importing this unit variant
   |
11 + use ControlOptions::EPOLL_CTL_ADD;


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs



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

2023-08-29 Thread Eric Blake
On Sat, Aug 26, 2023 at 11:29:58AM +, Tage Johansson wrote:
> 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_460_block_status.rs |  98 
>  rust/tests/test_async_620_stats.rs|  69 

Our series crossed paths.  My commit 5aec7d3b add
test_465_block_status_64.rs, but this commit of yours (at 0ed92592)
did not add a counterpart async test, because you started your series
before I added the 64-bit block status API.  Since I heavily
copy/pasted the synchronous 460 into 465, I'll probably end up doing
the same for the async version, unless you beat me to it.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs



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

2023-08-26 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/Cargo.toml   |   1 +
 rust/tests/test_async_100_handle.rs   |  25 +++
 rust/tests/test_async_200_connect_command.rs  |  26 +++
 rust/tests/test_async_210_opt_abort.rs|  32 
 rust/tests/test_async_220_opt_list.rs |  86 ++
 rust/tests/test_async_230_opt_info.rs | 122 ++
 rust/tests/test_async_240_opt_list_meta.rs| 150 ++
 .../test_async_245_opt_list_meta_queries.rs   |  94 +++
 rust/tests/test_async_250_opt_set_meta.rs | 125 +++
 .../test_async_255_opt_set_meta_queries.rs| 110 +
 rust/tests/test_async_400_pread.rs|  40 +
 rust/tests/test_async_405_pread_structured.rs |  84 ++
 rust/tests/test_async_410_pwrite.rs   |  59 +++
 rust/tests/test_async_460_block_status.rs |  98 
 rust/tests/test_async_620_stats.rs|  69 
 15 files changed, 1121 insertions(+)
 create mode 100644 rust/tests/test_async_100_handle.rs
 create mode 100644 rust/tests/test_async_200_connect_command.rs
 create mode 100644 rust/tests/test_async_210_opt_abort.rs
 create mode 100644 rust/tests/test_async_220_opt_list.rs
 create mode 100644 rust/tests/test_async_230_opt_info.rs
 create mode 100644 rust/tests/test_async_240_opt_list_meta.rs
 create mode 100644 rust/tests/test_async_245_opt_list_meta_queries.rs
 create mode 100644 rust/tests/test_async_250_opt_set_meta.rs
 create mode 100644 rust/tests/test_async_255_opt_set_meta_queries.rs
 create mode 100644 rust/tests/test_async_400_pread.rs
 create mode 100644 rust/tests/test_async_405_pread_structured.rs
 create mode 100644 rust/tests/test_async_410_pwrite.rs
 create mode 100644 rust/tests/test_async_460_block_status.rs
 create mode 100644 rust/tests/test_async_620_stats.rs

diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index a9b5988..c49f9f2 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -59,3 +59,4 @@ anyhow = "1.0.72"
 once_cell = "1.18.0"
 pretty-hex = "0.3.0"
 tempfile = "3.6.0"
+tokio = { version = "1.29.1", default-features = false, features = 
["rt-multi-thread", "macros"] }
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
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+//! Just check that we can link with libnbd and create a handle.
+
+#![deny(warnings)]
+
+#[tokio::test]
+async fn test_async_nbd_handle_new() {
+let _ = libnbd::AsyncHandle::new().unwrap();
+}
diff --git a/rust/tests/test_async_200_connect_command.rs 
b/rust/tests/test_async_200_connect_command.rs
new file mode 100644
index 000..2f4e7cc
--- /dev/null
+++ b/rust/tests/test_async_200_connect_command.rs
@@ -0,0 +1,26 @@
+// libnbd Rust test case
+// 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
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#![deny(warnings)]
+
+#[tokio::test]
+async fn test_async_connect_command() {
+let nbd = libnbd::AsyncHandle::new().unwrap();
+nbd.connect_command(&["nbdkit", "-s", "--exit-with-parent", "-v", "null"])
+.await
+.unwrap();
+}
diff --git a/rust/tests/test_async_210_opt_abort.rs 
b/rust/tests/test_async_210_opt_abort.rs
new file mode 100644
index 000..e85fa0c
--- /dev/null
+++ b/rust/tests/test_async_210_opt_abort.rs
@@