Skip to content

Commit 28e8483

Browse files
frazarojeda
authored andcommitted
rust: block: fix formatting of kernel::block::mq::request module
Fix several issues with rustdoc formatting for the `kernel::block::mq::Request` module, in particular: - An ordered list not rendering correctly, fixed by using numbers prefixes instead of letters. - Code snippets formatted as regular text, fixed by wrapping the code with `back-ticks`. - References to types missing intra-doc links, fixed by wrapping the types with [square brackets]. Reported-by: Miguel Ojeda <[email protected]> Closes: Rust-for-Linux/linux#1108 Signed-off-by: Francesco Zardi <[email protected]> Acked-by: Andreas Hindborg <[email protected]> Fixes: 3253aba ("rust: block: introduce `kernel::block::mq` module") Link: https://lore.kernel.org/r/[email protected] [ Added an extra intra-doc link. Took the chance to add some periods for consistency. Reworded slightly. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 15541c9 commit 28e8483

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

rust/kernel/block/mq/request.rs

+38-29
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,55 @@ use core::{
1616
sync::atomic::{AtomicU64, Ordering},
1717
};
1818

19-
/// A wrapper around a blk-mq `struct request`. This represents an IO request.
19+
/// A wrapper around a blk-mq [`struct request`]. This represents an IO request.
2020
///
2121
/// # Implementation details
2222
///
2323
/// There are four states for a request that the Rust bindings care about:
2424
///
25-
/// A) Request is owned by block layer (refcount 0)
26-
/// B) Request is owned by driver but with zero `ARef`s in existence
27-
/// (refcount 1)
28-
/// C) Request is owned by driver with exactly one `ARef` in existence
29-
/// (refcount 2)
30-
/// D) Request is owned by driver with more than one `ARef` in existence
31-
/// (refcount > 2)
25+
/// 1. Request is owned by block layer (refcount 0).
26+
/// 2. Request is owned by driver but with zero [`ARef`]s in existence
27+
/// (refcount 1).
28+
/// 3. Request is owned by driver with exactly one [`ARef`] in existence
29+
/// (refcount 2).
30+
/// 4. Request is owned by driver with more than one [`ARef`] in existence
31+
/// (refcount > 2).
3232
///
3333
///
34-
/// We need to track A and B to ensure we fail tag to request conversions for
34+
/// We need to track 1 and 2 to ensure we fail tag to request conversions for
3535
/// requests that are not owned by the driver.
3636
///
37-
/// We need to track C and D to ensure that it is safe to end the request and hand
37+
/// We need to track 3 and 4 to ensure that it is safe to end the request and hand
3838
/// back ownership to the block layer.
3939
///
4040
/// The states are tracked through the private `refcount` field of
4141
/// `RequestDataWrapper`. This structure lives in the private data area of the C
42-
/// `struct request`.
42+
/// [`struct request`].
4343
///
4444
/// # Invariants
4545
///
46-
/// * `self.0` is a valid `struct request` created by the C portion of the kernel.
46+
/// * `self.0` is a valid [`struct request`] created by the C portion of the
47+
/// kernel.
4748
/// * The private data area associated with this request must be an initialized
4849
/// and valid `RequestDataWrapper<T>`.
4950
/// * `self` is reference counted by atomic modification of
50-
/// self.wrapper_ref().refcount().
51+
/// `self.wrapper_ref().refcount()`.
52+
///
53+
/// [`struct request`]: srctree/include/linux/blk-mq.h
5154
///
5255
#[repr(transparent)]
5356
pub struct Request<T: Operations>(Opaque<bindings::request>, PhantomData<T>);
5457

5558
impl<T: Operations> Request<T> {
56-
/// Create an `ARef<Request>` from a `struct request` pointer.
59+
/// Create an [`ARef<Request>`] from a [`struct request`] pointer.
5760
///
5861
/// # Safety
5962
///
6063
/// * The caller must own a refcount on `ptr` that is transferred to the
61-
/// returned `ARef`.
62-
/// * The type invariants for `Request` must hold for the pointee of `ptr`.
64+
/// returned [`ARef`].
65+
/// * The type invariants for [`Request`] must hold for the pointee of `ptr`.
66+
///
67+
/// [`struct request`]: srctree/include/linux/blk-mq.h
6368
pub(crate) unsafe fn aref_from_raw(ptr: *mut bindings::request) -> ARef<Self> {
6469
// INVARIANT: By the safety requirements of this function, invariants are upheld.
6570
// SAFETY: By the safety requirement of this function, we own a
@@ -84,12 +89,14 @@ impl<T: Operations> Request<T> {
8489
}
8590

8691
/// Try to take exclusive ownership of `this` by dropping the refcount to 0.
87-
/// This fails if `this` is not the only `ARef` pointing to the underlying
88-
/// `Request`.
92+
/// This fails if `this` is not the only [`ARef`] pointing to the underlying
93+
/// [`Request`].
8994
///
90-
/// If the operation is successful, `Ok` is returned with a pointer to the
91-
/// C `struct request`. If the operation fails, `this` is returned in the
92-
/// `Err` variant.
95+
/// If the operation is successful, [`Ok`] is returned with a pointer to the
96+
/// C [`struct request`]. If the operation fails, `this` is returned in the
97+
/// [`Err`] variant.
98+
///
99+
/// [`struct request`]: srctree/include/linux/blk-mq.h
93100
fn try_set_end(this: ARef<Self>) -> Result<*mut bindings::request, ARef<Self>> {
94101
// We can race with `TagSet::tag_to_rq`
95102
if let Err(_old) = this.wrapper_ref().refcount().compare_exchange(
@@ -109,7 +116,7 @@ impl<T: Operations> Request<T> {
109116

110117
/// Notify the block layer that the request has been completed without errors.
111118
///
112-
/// This function will return `Err` if `this` is not the only `ARef`
119+
/// This function will return [`Err`] if `this` is not the only [`ARef`]
113120
/// referencing the request.
114121
pub fn end_ok(this: ARef<Self>) -> Result<(), ARef<Self>> {
115122
let request_ptr = Self::try_set_end(this)?;
@@ -123,13 +130,13 @@ impl<T: Operations> Request<T> {
123130
Ok(())
124131
}
125132

126-
/// Return a pointer to the `RequestDataWrapper` stored in the private area
133+
/// Return a pointer to the [`RequestDataWrapper`] stored in the private area
127134
/// of the request structure.
128135
///
129136
/// # Safety
130137
///
131138
/// - `this` must point to a valid allocation of size at least size of
132-
/// `Self` plus size of `RequestDataWrapper`.
139+
/// [`Self`] plus size of [`RequestDataWrapper`].
133140
pub(crate) unsafe fn wrapper_ptr(this: *mut Self) -> NonNull<RequestDataWrapper> {
134141
let request_ptr = this.cast::<bindings::request>();
135142
// SAFETY: By safety requirements for this function, `this` is a
@@ -141,7 +148,7 @@ impl<T: Operations> Request<T> {
141148
unsafe { NonNull::new_unchecked(wrapper_ptr) }
142149
}
143150

144-
/// Return a reference to the `RequestDataWrapper` stored in the private
151+
/// Return a reference to the [`RequestDataWrapper`] stored in the private
145152
/// area of the request structure.
146153
pub(crate) fn wrapper_ref(&self) -> &RequestDataWrapper {
147154
// SAFETY: By type invariant, `self.0` is a valid allocation. Further,
@@ -152,13 +159,15 @@ impl<T: Operations> Request<T> {
152159
}
153160
}
154161

155-
/// A wrapper around data stored in the private area of the C `struct request`.
162+
/// A wrapper around data stored in the private area of the C [`struct request`].
163+
///
164+
/// [`struct request`]: srctree/include/linux/blk-mq.h
156165
pub(crate) struct RequestDataWrapper {
157166
/// The Rust request refcount has the following states:
158167
///
159168
/// - 0: The request is owned by C block layer.
160-
/// - 1: The request is owned by Rust abstractions but there are no ARef references to it.
161-
/// - 2+: There are `ARef` references to the request.
169+
/// - 1: The request is owned by Rust abstractions but there are no [`ARef`] references to it.
170+
/// - 2+: There are [`ARef`] references to the request.
162171
refcount: AtomicU64,
163172
}
164173

@@ -204,7 +213,7 @@ fn atomic_relaxed_op_return(target: &AtomicU64, op: impl Fn(u64) -> u64) -> u64
204213
}
205214

206215
/// Store the result of `op(target.load)` in `target` if `target.load() !=
207-
/// pred`, returning true if the target was updated.
216+
/// pred`, returning [`true`] if the target was updated.
208217
fn atomic_relaxed_op_unless(target: &AtomicU64, op: impl Fn(u64) -> u64, pred: u64) -> bool {
209218
target
210219
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |x| {

0 commit comments

Comments
 (0)