MCPcopy Create free account
hub / github.com/axboe/liburing / test_read_overflow_refill

Function test_read_overflow_refill

test/buf-ring-stress.c:208–351  ·  view source on GitHub ↗

* Test: submit more reads than available buffers. Excess reads should * fail with -ENOBUFS. Then refill and retry. */

Source from the content-addressed store, hash-verified

206 * fail with -ENOBUFS. Then refill and retry.
207 */
208static int test_read_overflow_refill(void)
209{
210 struct io_uring ring;
211 struct io_uring_buf_ring *br;
212 struct io_uring_sqe *sqe;
213 struct io_uring_cqe *cqe;
214 void *buf_base;
215 const char *fname = ".buf-ring-overflow-tmp";
216 int fd, ret;
217 int nr_success = 0, nr_enobufs = 0;
218
219 ret = io_uring_queue_init(32, &ring, 0);
220 if (ret) {
221 fprintf(stderr, "ring setup: %d\n", ret);
222 return T_EXIT_FAIL;
223 }
224
225 br = io_uring_setup_buf_ring(&ring, NR_BUFS, BGID, 0, &ret);
226 if (!br) {
227 if (ret == -EINVAL || ret == -ENOENT) {
228 io_uring_queue_exit(&ring);
229 return T_EXIT_SKIP;
230 }
231 fprintf(stderr, "buf ring setup: %d\n", ret);
232 io_uring_queue_exit(&ring);
233 return T_EXIT_FAIL;
234 }
235
236 buf_base = malloc(NR_BUFS * BUF_SIZE);
237 if (!buf_base)
238 goto err;
239
240 /* Create test file */
241 t_create_file(fname, NR_BUFS * BUF_SIZE * 4);
242 fd = open(fname, O_RDONLY);
243 if (fd < 0) {
244 perror("open");
245 goto err;
246 }
247
248 /* Provide only NR_BUFS buffers */
249 provide_buffers(br, buf_base, NR_BUFS, BUF_SIZE);
250
251 /* Submit more reads than we have buffers */
252 for (int i = 0; i < NR_BUFS * 2; i++) {
253 sqe = io_uring_get_sqe(&ring);
254 io_uring_prep_read(sqe, fd, NULL, BUF_SIZE, i * BUF_SIZE);
255 sqe->flags |= IOSQE_BUFFER_SELECT;
256 sqe->buf_group = BGID;
257 sqe->user_data = i;
258 }
259
260 ret = io_uring_submit(&ring);
261 if (ret != NR_BUFS * 2) {
262 fprintf(stderr, "submit: %d\n", ret);
263 goto err_file;
264 }
265

Callers 1

mainFunction · 0.85

Calls 8

io_uring_queue_initFunction · 0.85
io_uring_setup_buf_ringFunction · 0.85
io_uring_queue_exitFunction · 0.85
t_create_fileFunction · 0.85
io_uring_submitFunction · 0.85
io_uring_free_buf_ringFunction · 0.85
provide_buffersFunction · 0.70
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected