@@ -16,50 +16,56 @@ use core::{
16
16
sync:: atomic:: { AtomicU64 , Ordering } ,
17
17
} ;
18
18
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.
20
21
///
21
22
/// # Implementation details
22
23
///
23
24
/// There are four states for a request that the Rust bindings care about:
24
25
///
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
27
28
/// (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
29
30
/// (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
31
32
/// (refcount > 2)
32
33
///
33
34
///
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
35
36
/// requests that are not owned by the driver.
36
37
///
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
38
39
/// back ownership to the block layer.
39
40
///
40
41
/// 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`] .
43
44
///
44
45
/// # Invariants
45
46
///
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.
47
49
/// * The private data area associated with this request must be an initialized
48
- /// and valid `RequestDataWrapper<T>`.
50
+ /// and valid [ `RequestDataWrapper<T>`] .
49
51
/// * `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
51
55
///
52
56
#[ repr( transparent) ]
53
57
pub struct Request < T : Operations > ( Opaque < bindings:: request > , PhantomData < T > ) ;
54
58
55
59
impl < T : Operations > Request < T > {
56
- /// Create an `ARef<Request>` from a `struct request` pointer.
60
+ /// Create an [ `ARef<Request>`] from a [ `struct request`] pointer.
57
61
///
58
62
/// # Safety
59
63
///
60
64
/// * 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
63
69
pub ( crate ) unsafe fn aref_from_raw ( ptr : * mut bindings:: request ) -> ARef < Self > {
64
70
// INVARIANT: By the safety requirements of this function, invariants are upheld.
65
71
// SAFETY: By the safety requirement of this function, we own a
@@ -84,12 +90,14 @@ impl<T: Operations> Request<T> {
84
90
}
85
91
86
92
/// 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`] .
89
95
///
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
93
101
fn try_set_end ( this : ARef < Self > ) -> Result < * mut bindings:: request , ARef < Self > > {
94
102
// We can race with `TagSet::tag_to_rq`
95
103
if let Err ( _old) = this. wrapper_ref ( ) . refcount ( ) . compare_exchange (
@@ -109,7 +117,7 @@ impl<T: Operations> Request<T> {
109
117
110
118
/// Notify the block layer that the request has been completed without errors.
111
119
///
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`]
113
121
/// referencing the request.
114
122
pub fn end_ok ( this : ARef < Self > ) -> Result < ( ) , ARef < Self > > {
115
123
let request_ptr = Self :: try_set_end ( this) ?;
@@ -123,13 +131,13 @@ impl<T: Operations> Request<T> {
123
131
Ok ( ( ) )
124
132
}
125
133
126
- /// Return a pointer to the `RequestDataWrapper` stored in the private area
134
+ /// Return a pointer to the [ `RequestDataWrapper`] stored in the private area
127
135
/// of the request structure.
128
136
///
129
137
/// # Safety
130
138
///
131
139
/// - `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`] .
133
141
pub ( crate ) unsafe fn wrapper_ptr ( this : * mut Self ) -> NonNull < RequestDataWrapper > {
134
142
let request_ptr = this. cast :: < bindings:: request > ( ) ;
135
143
// SAFETY: By safety requirements for this function, `this` is a
@@ -141,7 +149,7 @@ impl<T: Operations> Request<T> {
141
149
unsafe { NonNull :: new_unchecked ( wrapper_ptr) }
142
150
}
143
151
144
- /// Return a reference to the `RequestDataWrapper` stored in the private
152
+ /// Return a reference to the [ `RequestDataWrapper`] stored in the private
145
153
/// area of the request structure.
146
154
pub ( crate ) fn wrapper_ref ( & self ) -> & RequestDataWrapper {
147
155
// SAFETY: By type invariant, `self.0` is a valid allocation. Further,
@@ -152,13 +160,15 @@ impl<T: Operations> Request<T> {
152
160
}
153
161
}
154
162
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
156
166
pub ( crate ) struct RequestDataWrapper {
157
167
/// The Rust request refcount has the following states:
158
168
///
159
169
/// - 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.
162
172
refcount : AtomicU64 ,
163
173
}
164
174
@@ -204,7 +214,7 @@ fn atomic_relaxed_op_return(target: &AtomicU64, op: impl Fn(u64) -> u64) -> u64
204
214
}
205
215
206
216
/// 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.
208
218
fn atomic_relaxed_op_unless ( target : & AtomicU64 , op : impl Fn ( u64 ) -> u64 , pred : u64 ) -> bool {
209
219
target
210
220
. fetch_update ( Ordering :: Relaxed , Ordering :: Relaxed , |x| {
0 commit comments