From: Christian Brauner <brauner@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arnd Bergmann" <arnd@arndb.de>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Jan Kara" <jack@suse.cz>, "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>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] rust: file: add f_pos and set_f_pos
Date: Fri, 27 Sep 2024 09:32:02 +0200 [thread overview]
Message-ID: <20240927-ergaben-abdrehen-a02a861abaf5@brauner> (raw)
In-Reply-To: <20240926-b4-miscdevice-v1-2-7349c2b2837a@google.com>
On Thu, Sep 26, 2024 at 02:58:56PM GMT, Alice Ryhl wrote:
> Add accessors for the file position. Most of the time, you should not
> use these methods directly, and you should instead use a guard for the
> file position to prove that you hold the fpos lock. However, under
> limited circumstances, files are allowed to choose a different locking
> strategy for their file position. These accessors can be used to handle
> that case.
>
> For now, these accessors are the only way to access the file position
> within the llseek and read_iter callbacks.
>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> rust/kernel/fs/file.rs | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs
> index e03dbe14d62a..c896a3b1d182 100644
> --- a/rust/kernel/fs/file.rs
> +++ b/rust/kernel/fs/file.rs
> @@ -333,6 +333,26 @@ pub fn flags(&self) -> u32 {
> // FIXME(read_once): Replace with `read_once` when available on the Rust side.
> unsafe { core::ptr::addr_of!((*self.as_ptr()).f_flags).read_volatile() }
> }
> +
> + /// Read the file position.
> + ///
> + /// # Safety
> + ///
> + /// You must hold the fpos lock or otherwise ensure that no data race will happen.
> + #[inline]
> + pub unsafe fn f_pos(&self) -> i64 {
> + unsafe { (*self.as_ptr()).f_pos }
> + }
> +
> + /// Set the file position.
> + ///
> + /// # Safety
> + ///
> + /// You must hold the fpos lock or otherwise ensure that no data race will happen.
> + #[inline]
> + pub unsafe fn set_f_pos(&self, value: i64) {
> + unsafe { (*self.as_ptr()).f_pos = value };
> + }
I don't think we want to expose f_pos with its weird locking rule
through rust wrappers. Ideally, it's completely opaque to the callers
and not accessed directly at all.
next prev parent reply other threads:[~2024-09-27 7:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-26 14:58 [PATCH 0/3] Miscdevices in Rust Alice Ryhl
2024-09-26 14:58 ` [PATCH 1/3] rust: types: add Opaque::try_ffi_init Alice Ryhl
2024-09-27 9:00 ` Fiona Behrens
2024-09-26 14:58 ` [PATCH 2/3] rust: file: add f_pos and set_f_pos Alice Ryhl
2024-09-26 22:08 ` Al Viro
2024-09-26 22:47 ` Al Viro
2024-09-26 22:52 ` Al Viro
2024-09-27 6:56 ` Alice Ryhl
2024-09-27 19:38 ` Al Viro
2024-10-01 8:20 ` Alice Ryhl
2024-09-27 6:48 ` Alice Ryhl
2024-09-27 7:32 ` Christian Brauner [this message]
2024-09-26 14:58 ` [PATCH 3/3] rust: miscdevice: add abstraction for defining miscdevices Alice Ryhl
2024-09-26 15:05 ` [PATCH 0/3] Miscdevices in Rust Greg Kroah-Hartman
2024-09-26 15:11 ` Miguel Ojeda
2024-09-26 15:20 ` Alice Ryhl
2024-09-26 15:36 ` Greg Kroah-Hartman
2024-09-26 18:58 ` Benno Lossin
2024-09-27 6:04 ` Greg Kroah-Hartman
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=20240927-ergaben-abdrehen-a02a861abaf5@brauner \
--to=brauner@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=arnd@arndb.de \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®