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

Alice Ryhl
2026-03-16T10:30:18Z

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@kernel.org>

With the nit below fixed:
Reviewed-by: Alice Ryhl <aliceryhl@google.com>

> 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)