Re: [PATCH 10/79] block: rust: add `command` getter to `Request`

From: Alice Ryhl

Date: Mon Mar 16 2026 - 06:31:54 EST


On Mon, Feb 16, 2026 at 12:34:57AM +0100, Andreas Hindborg wrote:
> Add a method to extract the command operation code from a request. The
> command is obtained by masking the lower bits of `cmd_flags` as defined by
> `REQ_OP_BITS`. This allows Rust block drivers to determine the type of
> operation being requested.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>

With the nit below fixed:
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

> rust/kernel/block/mq/request.rs | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request.rs
> index b49197a0c66d7..0dd329ae93dfc 100644
> --- a/rust/kernel/block/mq/request.rs
> +++ b/rust/kernel/block/mq/request.rs
> @@ -78,6 +78,12 @@ pub(crate) unsafe fn aref_from_raw(ptr: *mut bindings::request) -> ARef<Self> {
> unsafe { ARef::from_raw(NonNull::new_unchecked(ptr.cast())) }
> }
>
> + /// Get the command identifier for the request
> + pub fn command(&self) -> u32 {
> + // SAFETY: By C API contract and type invariant, `cmd_flags` is valid for read
> + unsafe { (*self.0.get()).cmd_flags & ((1 << bindings::REQ_OP_BITS) - 1) }

Nit: scope of unsafe

unsafe { (*self.0.get()).cmd_flags } & ((1 << bindings::REQ_OP_BITS) - 1)