| 644 | } |
| 645 | |
| 646 | static int test_rem_buf(int batch, int sqe_flags) |
| 647 | { |
| 648 | struct io_uring_sqe *sqe; |
| 649 | struct io_uring_cqe *cqe; |
| 650 | struct io_uring ring; |
| 651 | int left, ret, nr = 0; |
| 652 | int bgid = 1; |
| 653 | |
| 654 | if (no_buf_select) |
| 655 | return 0; |
| 656 | |
| 657 | ret = io_uring_queue_init(64, &ring, 0); |
| 658 | if (ret) { |
| 659 | fprintf(stderr, "ring create failed: %d\n", ret); |
| 660 | return 1; |
| 661 | } |
| 662 | |
| 663 | ret = provide_buffers_iovec(&ring, bgid); |
| 664 | if (ret) |
| 665 | return ret; |
| 666 | |
| 667 | left = BUFFERS; |
| 668 | while (left) { |
| 669 | int to_rem = (left < batch) ? left : batch; |
| 670 | |
| 671 | left -= to_rem; |
| 672 | sqe = io_uring_get_sqe(&ring); |
| 673 | io_uring_prep_remove_buffers(sqe, to_rem, bgid); |
| 674 | sqe->user_data = to_rem; |
| 675 | sqe->flags |= sqe_flags; |
| 676 | ++nr; |
| 677 | } |
| 678 | |
| 679 | ret = io_uring_submit(&ring); |
| 680 | if (ret != nr) { |
| 681 | fprintf(stderr, "submit: %d\n", ret); |
| 682 | return -1; |
| 683 | } |
| 684 | |
| 685 | for (; nr > 0; nr--) { |
| 686 | ret = io_uring_wait_cqe(&ring, &cqe); |
| 687 | if (ret) { |
| 688 | fprintf(stderr, "wait_cqe=%d\n", ret); |
| 689 | return 1; |
| 690 | } |
| 691 | if (cqe->res != cqe->user_data) { |
| 692 | fprintf(stderr, "cqe->res=%d\n", cqe->res); |
| 693 | return 1; |
| 694 | } |
| 695 | io_uring_cqe_seen(&ring, cqe); |
| 696 | } |
| 697 | |
| 698 | io_uring_queue_exit(&ring); |
| 699 | return ret; |
| 700 | } |
| 701 | |
| 702 | static int test_rem_buf_single(int to_rem) |
| 703 | { |
no test coverage detected