From: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>,
rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Miguel Ojeda <ojeda@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: "Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
linux-kernel@vger.kernel.org, patches@lists.linux.dev,
"Wedson Almeida Filho" <walmeida@microsoft.com>,
"Daniel Xu" <dxu@dxuuu.xyz>
Subject: Re: [RFC PATCH v1 1/5] rust: file: add bindings for `struct file`
Date: Tue, 8 Aug 2023 23:59:04 -0300 [thread overview]
Message-ID: <94a50510-c539-49d5-bc36-241f1f003172@gmail.com> (raw)
In-Reply-To: <20230720152820.3566078-2-aliceryhl@google.com>
On 7/20/23 12:28, Alice Ryhl wrote:
> From: Wedson Almeida Filho <walmeida@microsoft.com>
>
> Using these bindings it becomes possible to access files from drivers
> written in Rust. This patch only adds support for accessing the flags,
> and for managing the refcount of the file.
>
> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
> Co-Developed-by: Daniel Xu <dxu@dxuuu.xyz>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> Co-Developed-by: Alice Ryhl <aliceryhl@google.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> In this patch, I am defining an error type called `BadFdError`. I'd like
> your thoughts on doing it this way vs just using the normal `Error`
> type.
>
> Pros:
> * The type system makes it clear that the function can only fail with
> EBADF, and that no other errors are possible.
> * Since the compiler knows that `ARef<Self>` cannot be null and that
> `BadFdError` has only one possible value, the return type of
> `File::from_fd` is represented as a pointer with null being an error.
>
> Cons:
> * Defining additional error types involves boilerplate.
> * The return type becomes a tagged union, making it larger than a
> pointer.
These two are kinda passable, as a `impl_null_ptr_err` macro can be opted
to implement error types from nulls. Also if we consider that
`File::from_fd` isn't going to be called a gorillion times a second or a
recursive call is done, then I'd say that the tagged union won't bring
any other problems, except that a compiler optim is skipped.
> * The question mark operator will only utilize the `From` trait once,
> which prevents you from using the question mark operator on
> `BadFdError` in methods that return some third error type that the
> kernel `Error` is convertible into.
Although, I want this to be mentioned in the doc of `BadFdError` as this
cannot be overlooked when said usage of `?` is done.
>
> rust/bindings/bindings_helper.h | 2 +
> rust/helpers.c | 7 ++
> rust/kernel/file.rs | 176 ++++++++++++++++++++++++++++++++
> rust/kernel/lib.rs | 1 +
> 4 files changed, 186 insertions(+)
> create mode 100644 rust/kernel/file.rs
>
> [...]
> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
> [...]
> diff --git a/rust/helpers.c b/rust/helpers.c
> [...]
This one is making my head spin, shouldn't they go first?
next prev parent reply other threads:[~2023-08-09 4:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-20 15:28 [RFC PATCH v1 0/5] Various Rust bindings for files Alice Ryhl
2023-07-20 15:28 ` [RFC PATCH v1 1/5] rust: file: add bindings for `struct file` Alice Ryhl
2023-08-09 2:59 ` Martin Rodriguez Reboredo [this message]
2023-07-20 15:28 ` [RFC PATCH v1 2/5] rust: cred: add Rust bindings for `struct cred` Alice Ryhl
2023-07-20 15:28 ` [RFC PATCH v1 3/5] rust: file: add `FileDescriptorReservation` Alice Ryhl
2023-08-09 4:02 ` Martin Rodriguez Reboredo
2023-07-20 15:28 ` [RFC PATCH v1 4/5] rust: file: add bindings for `poll_table` Alice Ryhl
2023-07-20 15:28 ` [RFC PATCH v1 5/5] rust: file: add `DeferredFdCloser` Alice Ryhl
2023-07-20 18:22 ` Miguel Ojeda
2023-08-09 4:33 ` Martin Rodriguez Reboredo
2023-08-09 9:00 ` Miguel Ojeda
2023-08-09 9:09 ` Miguel Ojeda
2023-08-09 20:15 ` Martin Rodriguez Reboredo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=94a50510-c539-49d5-bc36-241f1f003172@gmail.com \
--to=yakoyoku@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=dxu@dxuuu.xyz \
--cc=gary@garyguo.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=patches@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=walmeida@microsoft.com \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).