Lines Matching full:request

3 //! This module provides a wrapper for the C `struct request` type.
16 /// A wrapper around a blk-mq [`struct request`]. This represents an IO request.
20 /// There are four states for a request that the Rust bindings care about:
22 /// 1. Request is owned by block layer (refcount 0).
23 /// 2. Request is owned by driver but with zero [`ARef`]s in existence
25 /// 3. Request is owned by driver with exactly one [`ARef`] in existence
27 /// 4. Request is owned by driver with more than one [`ARef`] in existence
31 /// We need to track 1 and 2 to ensure we fail tag to request conversions for
34 /// We need to track 3 and 4 to ensure that it is safe to end the request and hand
42 /// [`struct request`].
46 /// * `self.0` is a valid [`struct request`] created by the C portion of the
48 /// * The private data area associated with this request must be an initialized
53 /// [`struct request`]: srctree/include/linux/blk-mq.h
56 pub struct Request<T>(Opaque<bindings::request>, PhantomData<T>);
58 impl<T: Operations> Request<T> {
59 /// Create an [`ARef<Request>`] from a [`struct request`] pointer.
65 /// * The type invariants for [`Request`] must hold for the pointee of `ptr`.
67 /// [`struct request`]: srctree/include/linux/blk-mq.h
68 pub(crate) unsafe fn aref_from_raw(ptr: *mut bindings::request) -> ARef<Self> {
75 /// Notify the block layer that a request is going to be processed now.
79 /// drivers call this function when starting to process a request.
86 // SAFETY: By type invariant, `self.0` is a valid `struct request` and
93 /// [`Request`].
96 /// C [`struct request`]. If the operation fails, `this` is returned in the
99 /// [`struct request`]: srctree/include/linux/blk-mq.h
100 fn try_set_end(this: ARef<Self>) -> Result<*mut bindings::request, ARef<Self>> {
120 /// Notify the block layer that the request has been completed without errors.
123 /// referencing the request.
127 // SAFETY: By type invariant, `this.0` was a valid `struct request`. The
129 // `ARef`s pointing to this request. Therefore it is safe to hand it
141 /// Complete the request by scheduling `Operations::complete` for
149 let ptr = ARef::into_raw(this).cast::<bindings::request>().as_ptr();
150 // SAFETY: By type invariant, `self.0` is a valid `struct request`
153 let this = unsafe { Request::aref_from_raw(ptr) };
159 /// of the request structure.
166 let request_ptr = this.cast::<bindings::request>();
177 /// area of the request structure.
180 // the private data associated with this request is initialized and
187 /// A wrapper around data stored in the private area of the C [`struct request`].
189 /// [`struct request`]: srctree/include/linux/blk-mq.h
191 /// The Rust request refcount has the following states:
193 /// - 0: The request is owned by C block layer.
194 /// - 1: The request is owned by Rust abstractions but there are no [`ARef`] references to it.
195 /// - 2+: There are [`ARef`] references to the request.
200 /// Return a reference to the refcount of the request that is embedding
206 /// Return a pointer to the refcount of the request that is embedding the
219 // SAFETY: Exclusive access is thread-safe for `Request`. `Request` has no `&mut
222 unsafe impl<T: Operations> Send for Request<T> {}
224 // SAFETY: Shared access is thread-safe for `Request`. `&self` methods that
226 unsafe impl<T: Operations> Sync for Request<T> {}
228 // SAFETY: All instances of `Request<T>` are reference counted. This
232 unsafe impl<T: Operations> AlwaysRefCounted for Request<T> {
241 // SAFETY: The type invariant of `Request` guarantees that the private
250 panic!("Request reached refcount zero in Rust abstractions");