(&mut self, batch_request: &[BatchRequest])
| 154 | } |
| 155 | |
| 156 | fn submit_batch_requests(&mut self, batch_request: &[BatchRequest]) -> AsyncIoResult<()> { |
| 157 | if !self.batch_requests_enabled() { |
| 158 | return Ok(()); |
| 159 | } |
| 160 | |
| 161 | let (submitter, mut sq, _) = self.io_uring.split(); |
| 162 | let mut submitted = false; |
| 163 | |
| 164 | // Refuse the whole batch if it can't fit in the SQ to avoid having to unroll a partially |
| 165 | // successful push. |
| 166 | if batch_request.len() > sq.capacity() - sq.len() { |
| 167 | return Err(AsyncIoError::SubmitBatchRequests(Error::other( |
| 168 | "io_uring submission queue is full", |
| 169 | ))); |
| 170 | } |
| 171 | |
| 172 | for req in batch_request { |
| 173 | match req.request_type { |
| 174 | RequestType::In => { |
| 175 | // SAFETY: we know the file descriptor is valid and we |
| 176 | // relied on vm-memory to provide the buffer address. |
| 177 | unsafe { |
| 178 | sq.push( |
| 179 | &opcode::Readv::new( |
| 180 | types::Fd(self.fd), |
| 181 | req.iovecs.as_ptr(), |
| 182 | req.iovecs.len() as u32, |
| 183 | ) |
| 184 | .offset(req.offset as u64) |
| 185 | .build() |
| 186 | .user_data(req.user_data), |
| 187 | ) |
| 188 | .map_err(|e| { |
| 189 | AsyncIoError::ReadVectored(Error::other(format!( |
| 190 | "Submission queue is full: {e:?}" |
| 191 | ))) |
| 192 | })?; |
| 193 | }; |
| 194 | submitted = true; |
| 195 | } |
| 196 | RequestType::Out => { |
| 197 | // SAFETY: we know the file descriptor is valid and we |
| 198 | // relied on vm-memory to provide the buffer address. |
| 199 | unsafe { |
| 200 | sq.push( |
| 201 | &opcode::Writev::new( |
| 202 | types::Fd(self.fd), |
| 203 | req.iovecs.as_ptr(), |
| 204 | req.iovecs.len() as u32, |
| 205 | ) |
| 206 | .offset(req.offset as u64) |
| 207 | .build() |
| 208 | .user_data(req.user_data), |
| 209 | ) |
| 210 | .map_err(|e| { |
| 211 | AsyncIoError::WriteVectored(Error::other(format!( |
| 212 | "Submission queue is full: {e:?}" |
| 213 | ))) |
no test coverage detected