@@ -42,6 +42,9 @@ pub trait Operations: Sized {
4242 /// Called by the kernel to indicate that queued requests should be submitted.
4343 fn commit_rqs ( queue_data : ForeignBorrowed < ' _ , Self :: QueueData > ) ;
4444
45+ /// Called by the kernel when the request is completed.
46+ fn complete ( rq : ARef < Request < Self > > ) ;
47+
4548 /// Called by the kernel to poll the device for completed requests. Only
4649 /// used for poll queues.
4750 fn poll ( ) -> bool {
@@ -143,13 +146,21 @@ impl<T: Operations> OperationsVTable<T> {
143146 T :: commit_rqs ( queue_data)
144147 }
145148
146- /// This function is called by the C kernel. It is not currently
147- /// implemented, and there is no way to exercise this code path .
149+ /// This function is called by the C kernel. A pointer to this function is
150+ /// installed in the `blk_mq_ops` vtable for the driver .
148151 ///
149152 /// # Safety
150153 ///
151- /// This function may only be called by blk-mq C infrastructure.
152- unsafe extern "C" fn complete_callback ( _rq : * mut bindings:: request ) { }
154+ /// This function may only be called by blk-mq C infrastructure. `rq` must
155+ /// point to a valid request that has been marked as completed. The pointee
156+ /// of `rq` must be valid for write for the duration of this function.
157+ unsafe extern "C" fn complete_callback ( rq : * mut bindings:: request ) {
158+ // SAFETY: This function can only be dispatched through
159+ // `Request::complete`. We leaked a refcount then which we pick back up
160+ // now.
161+ let aref = unsafe { Request :: aref_from_raw ( rq) } ;
162+ T :: complete ( aref) ;
163+ }
153164
154165 /// This function is called by the C kernel. A pointer to this function is
155166 /// installed in the `blk_mq_ops` vtable for the driver.
0 commit comments