[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87wm8in3c0.fsf@kernel.org>
Date: Tue, 08 Jul 2025 16:51:11 +0200
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Alice Ryhl" <aliceryhl@...gle.com>
Cc: "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>, "Alexander Viro"
<viro@...iv.linux.org.uk>, "Arnd Bergmann" <arnd@...db.de>, "Miguel
Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>, "Gary
Guo" <gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>,
"Trevor Gross" <tmgross@...ch.edu>, "Danilo Krummrich"
<dakr@...nel.org>, "Matthew Maurer" <mmaurer@...gle.com>, "Lee Jones"
<lee@...nel.org>, <linux-kernel@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>, "Benno Lossin" <lossin@...nel.org>
Subject: Re: [PATCH v2 3/4] rust: miscdevice: Provide additional
abstractions for iov_iter and kiocb structures
"Alice Ryhl" <aliceryhl@...gle.com> writes:
> These will be used for the read_iter() and write_iter() callbacks, which
> are now the preferred back-ends for when a user operates on a char device
> with read() and write() respectively.
>
> Co-developed-by: Lee Jones <lee@...nel.org>
> Signed-off-by: Lee Jones <lee@...nel.org>
> Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>
> ---
> rust/kernel/miscdevice.rs | 97 ++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 96 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs
> index 22f291211636f66efca6b33b675833236332719e..a49954c9b0d14117645be8139db792f1fd22589d 100644
> --- a/rust/kernel/miscdevice.rs
> +++ b/rust/kernel/miscdevice.rs
> @@ -14,13 +14,14 @@
> error::{to_result, Error, Result, VTABLE_DEFAULT_ERROR},
> ffi::{c_int, c_long, c_uint, c_ulong},
> fs::File,
> + iov::{IovIterDest, IovIterSource},
> mm::virt::VmaNew,
> prelude::*,
> seq_file::SeqFile,
> str::CStr,
> types::{ForeignOwnable, Opaque},
> };
> -use core::{marker::PhantomData, mem::MaybeUninit, pin::Pin};
> +use core::{marker::PhantomData, mem::MaybeUninit, pin::Pin, ptr::NonNull};
>
> /// Options for creating a misc device.
> #[derive(Copy, Clone)]
> @@ -136,6 +137,16 @@ fn mmap(
> build_error!(VTABLE_DEFAULT_ERROR)
> }
>
> + /// Read from this miscdevice.
> + fn read_iter(_kiocb: Kiocb<'_, Self::Ptr>, _iov: &mut IovIterDest<'_>) -> Result<usize> {
> + build_error!(VTABLE_DEFAULT_ERROR)
> + }
> +
> + /// Write to this miscdevice.
> + fn write_iter(_kiocb: Kiocb<'_, Self::Ptr>, _iov: &mut IovIterSource<'_>) -> Result<usize> {
> + build_error!(VTABLE_DEFAULT_ERROR)
> + }
> +
> /// Handler for ioctls.
> ///
> /// The `cmd` argument is usually manipulated using the utilities in [`kernel::ioctl`].
> @@ -177,6 +188,36 @@ fn show_fdinfo(
> }
> }
>
> +/// Wrapper for the kernel's `struct kiocb`.
> +///
> +/// The type `T` represents the private data of the file.
Could you give more context? Please describe the purpose for the type
and intended use. Perhaps give an example that can be compile tested.
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists