@@ -16,50 +16,56 @@ use core::{
1616 sync:: atomic:: { AtomicU64 , Ordering } ,
1717} ;
1818
19- /// A wrapper around a blk-mq `struct request`. This represents an IO request.
19+ #[ allow( rustdoc:: private_intra_doc_links) ]
20+ /// A wrapper around a blk-mq [`struct request`]. This represents an IO request.
2021///
2122/// # Implementation details
2223///
2324/// There are four states for a request that the Rust bindings care about:
2425///
25- /// A) Request is owned by block layer (refcount 0)
26- /// B) Request is owned by driver but with zero `ARef`s in existence
26+ /// 1. Request is owned by block layer (refcount 0)
27+ /// 2. Request is owned by driver but with zero [ `ARef`] s in existence
2728/// (refcount 1)
28- /// C) Request is owned by driver with exactly one `ARef` in existence
29+ /// 3. Request is owned by driver with exactly one [ `ARef`] in existence
2930/// (refcount 2)
30- /// D) Request is owned by driver with more than one `ARef` in existence
31+ /// 4. Request is owned by driver with more than one [ `ARef`] in existence
3132/// (refcount > 2)
3233///
3334///
34- /// We need to track A and B to ensure we fail tag to request conversions for
35+ /// We need to track 1 and 2 to ensure we fail tag to request conversions for
3536/// requests that are not owned by the driver.
3637///
37- /// We need to track C and D to ensure that it is safe to end the request and hand
38+ /// We need to track 3 and 4 to ensure that it is safe to end the request and hand
3839/// back ownership to the block layer.
3940///
4041/// The states are tracked through the private `refcount` field of
41- /// `RequestDataWrapper`. This structure lives in the private data area of the C
42- /// `struct request`.
42+ /// [ `RequestDataWrapper`] . This structure lives in the private data area of the C
43+ /// [ `struct request`] .
4344///
4445/// # Invariants
4546///
46- /// * `self.0` is a valid `struct request` created by the C portion of the kernel.
47+ /// * `self.0` is a valid [`struct request`] created by the C portion of the
48+ /// kernel.
4749/// * The private data area associated with this request must be an initialized
48- /// and valid `RequestDataWrapper<T>`.
50+ /// and valid [ `RequestDataWrapper<T>`] .
4951/// * `self` is reference counted by atomic modification of
50- /// self.wrapper_ref().refcount().
52+ /// `self.wrapper_ref().refcount()`.
53+ ///
54+ /// [`struct request`]: srctree/include/linux/blk-mq.h
5155///
5256#[ repr( transparent) ]
5357pub struct Request < T : Operations > ( Opaque < bindings:: request > , PhantomData < T > ) ;
5458
5559impl < T : Operations > Request < T > {
56- /// Create an `ARef<Request>` from a `struct request` pointer.
60+ /// Create an [ `ARef<Request>`] from a [ `struct request`] pointer.
5761 ///
5862 /// # Safety
5963 ///
6064 /// * 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`.
65+ /// returned [`ARef`].
66+ /// * The type invariants for [`Request`] must hold for the pointee of `ptr`.
67+ ///
68+ /// [`struct request`]: srctree/include/linux/blk-mq.h
6369 pub ( crate ) unsafe fn aref_from_raw ( ptr : * mut bindings:: request ) -> ARef < Self > {
6470 // INVARIANT: By the safety requirements of this function, invariants are upheld.
6571 // SAFETY: By the safety requirement of this function, we own a
@@ -84,12 +90,14 @@ impl<T: Operations> Request<T> {
8490 }
8591
8692 /// 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`.
93+ /// This fails if `this` is not the only [ `ARef`] pointing to the underlying
94+ /// [ `Request`] .
8995 ///
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.
96+ /// If the operation is successful, [`Ok`] is returned with a pointer to the
97+ /// C [`struct request`]. If the operation fails, `this` is returned in the
98+ /// [`Err`] variant.
99+ ///
100+ /// [`struct request`]: srctree/include/linux/blk-mq.h
93101 fn try_set_end ( this : ARef < Self > ) -> Result < * mut bindings:: request , ARef < Self > > {
94102 // We can race with `TagSet::tag_to_rq`
95103 if let Err ( _old) = this. wrapper_ref ( ) . refcount ( ) . compare_exchange (
@@ -109,7 +117,7 @@ impl<T: Operations> Request<T> {
109117
110118 /// Notify the block layer that the request has been completed without errors.
111119 ///
112- /// This function will return `Err` if `this` is not the only `ARef`
120+ /// This function will return [ `Err`] if `this` is not the only [ `ARef`]
113121 /// referencing the request.
114122 pub fn end_ok ( this : ARef < Self > ) -> Result < ( ) , ARef < Self > > {
115123 let request_ptr = Self :: try_set_end ( this) ?;
@@ -123,13 +131,13 @@ impl<T: Operations> Request<T> {
123131 Ok ( ( ) )
124132 }
125133
126- /// Return a pointer to the `RequestDataWrapper` stored in the private area
134+ /// Return a pointer to the [ `RequestDataWrapper`] stored in the private area
127135 /// of the request structure.
128136 ///
129137 /// # Safety
130138 ///
131139 /// - `this` must point to a valid allocation of size at least size of
132- /// `Self` plus size of `RequestDataWrapper`.
140+ /// [ `Self`] plus size of [ `RequestDataWrapper`] .
133141 pub ( crate ) unsafe fn wrapper_ptr ( this : * mut Self ) -> NonNull < RequestDataWrapper > {
134142 let request_ptr = this. cast :: < bindings:: request > ( ) ;
135143 // SAFETY: By safety requirements for this function, `this` is a
@@ -141,7 +149,7 @@ impl<T: Operations> Request<T> {
141149 unsafe { NonNull :: new_unchecked ( wrapper_ptr) }
142150 }
143151
144- /// Return a reference to the `RequestDataWrapper` stored in the private
152+ /// Return a reference to the [ `RequestDataWrapper`] stored in the private
145153 /// area of the request structure.
146154 pub ( crate ) fn wrapper_ref ( & self ) -> & RequestDataWrapper {
147155 // SAFETY: By type invariant, `self.0` is a valid allocation. Further,
@@ -152,13 +160,15 @@ impl<T: Operations> Request<T> {
152160 }
153161}
154162
155- /// A wrapper around data stored in the private area of the C `struct request`.
163+ /// A wrapper around data stored in the private area of the C [`struct request`].
164+ ///
165+ /// [`struct request`]: srctree/include/linux/blk-mq.h
156166pub ( crate ) struct RequestDataWrapper {
157167 /// The Rust request refcount has the following states:
158168 ///
159169 /// - 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.
170+ /// - 1: The request is owned by Rust abstractions but there are no [ ARef] references to it.
171+ /// - 2+: There are [ `ARef`] references to the request.
162172 refcount : AtomicU64 ,
163173}
164174
@@ -204,7 +214,7 @@ fn atomic_relaxed_op_return(target: &AtomicU64, op: impl Fn(u64) -> u64) -> u64
204214}
205215
206216/// Store the result of `op(target.load)` in `target` if `target.load() !=
207- /// pred`, returning true if the target was updated.
217+ /// pred`, returning ` true` if the target was updated.
208218fn atomic_relaxed_op_unless ( target : & AtomicU64 , op : impl Fn ( u64 ) -> u64 , pred : u64 ) -> bool {
209219 target
210220 . fetch_update ( Ordering :: Relaxed , Ordering :: Relaxed , |x| {
0 commit comments