Merge branch 'AddDocForSplice' of https://github.com/NobodyXu/liburing

* 'AddDocForSplice' of https://github.com/NobodyXu/liburing:
  Add inline doc in the comments for io_uring_prep_splice
diff --git a/src/queue.c b/src/queue.c
index 94f791e..4bd4c48 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -59,7 +59,8 @@
 			break;
 
 		cqe = &ring->cq.cqes[head & mask];
-		if (cqe->user_data == LIBURING_UDATA_TIMEOUT) {
+		if (!(ring->features & IORING_FEAT_EXT_ARG) &&
+				cqe->user_data == LIBURING_UDATA_TIMEOUT) {
 			if (cqe->res < 0)
 				err = cqe->res;
 			io_uring_cq_advance(ring, 1);
@@ -89,12 +90,13 @@
 {
 	struct io_uring_cqe *cqe = NULL;
 	const int to_wait = data->wait_nr;
-	int ret = 0, err;
+	int err;
 
 	do {
 		bool cq_overflow_flush = false;
 		unsigned flags = 0;
 		unsigned nr_available;
+		int ret;
 
 		err = __io_uring_peek_cqe(ring, &cqe, &nr_available);
 		if (err)
@@ -106,21 +108,24 @@
 			}
 			cq_overflow_flush = true;
 		}
-		if (data->wait_nr && cqe)
-			data->wait_nr--;
 		if (data->wait_nr || cq_overflow_flush)
 			flags = IORING_ENTER_GETEVENTS | data->get_flags;
 		if (data->submit)
 			sq_ring_needs_enter(ring, &flags);
-		if (data->wait_nr > nr_available || data->submit ||
-		    cq_overflow_flush)
-			ret = __sys_io_uring_enter2(ring->ring_fd, data->submit,
-					data->wait_nr, flags, data->arg,
-					data->sz);
+		if (data->wait_nr <= nr_available && !data->submit &&
+		    !cq_overflow_flush)
+			break;
+
+		ret = __sys_io_uring_enter2(ring->ring_fd, data->submit,
+				data->wait_nr, flags, data->arg,
+				data->sz);
 		if (ret < 0) {
 			err = -errno;
-		} else if (ret == (int)data->submit) {
-			data->submit = 0;
+			break;
+		}
+
+		data->submit -= ret;
+		if (ret == (int)data->submit) {
 			/*
 			 * When SETUP_IOPOLL is set, __sys_io_uring enter()
 			 * must be called to reap new completions but the call
@@ -129,12 +134,10 @@
 			 */
 			if (!(ring->flags & IORING_SETUP_IOPOLL))
 				data->wait_nr = 0;
-		} else {
-			data->submit -= ret;
 		}
 		if (cqe)
 			break;
-	} while (!err);
+	} while (1);
 
 	*cqe_ptr = cqe;
 	return err;
@@ -267,8 +270,9 @@
 
 /*
  * Like io_uring_wait_cqe(), except it accepts a timeout value as well. Note
- * that an sqe is used internally to handle the timeout. Applications using
- * this function must never set sqe->user_data to LIBURING_UDATA_TIMEOUT!
+ * that an sqe is used internally to handle the timeout. For kernel doesn't
+ * support IORING_FEAT_EXT_ARG, applications using this function must never
+ * set sqe->user_data to LIBURING_UDATA_TIMEOUT!
  *
  * For kernels without IORING_FEAT_EXT_ARG (5.10 and older), if 'ts' is
  * specified, the application need not call io_uring_submit() before
diff --git a/test/poll-cancel-ton.c b/test/poll-cancel-ton.c
index 1a75463..e9d612e 100644
--- a/test/poll-cancel-ton.c
+++ b/test/poll-cancel-ton.c
@@ -102,6 +102,7 @@
 int main(int argc, char *argv[])
 {
 	struct io_uring ring;
+	struct io_uring_params p = { };
 	int pipe1[2];
 	int ret;
 
@@ -113,10 +114,18 @@
 		return 1;
 	}
 
-	ret = io_uring_queue_init(1024, &ring, 0);
+	p.flags = IORING_SETUP_CQSIZE;
+	p.cq_entries = 16384;
+	ret = io_uring_queue_init_params(1024, &ring, &p);
 	if (ret) {
-		fprintf(stderr, "ring setup failed: %d\n", ret);
-		return 1;
+		if (ret == -EINVAL) {
+			fprintf(stdout, "No CQSIZE, trying without\n");
+			ret = io_uring_queue_init(1024, &ring, 0);
+			if (ret) {
+				fprintf(stderr, "ring setup failed: %d\n", ret);
+				return 1;
+			}
+		}
 	}
 
 	add_polls(&ring, pipe1[0], 30000);
diff --git a/test/poll-many.c b/test/poll-many.c
index 723a353..3f8d08d 100644
--- a/test/poll-many.c
+++ b/test/poll-many.c
@@ -140,6 +140,7 @@
 int main(int argc, char *argv[])
 {
 	struct io_uring ring;
+	struct io_uring_params params = { };
 	struct rlimit rlim;
 	int i, ret;
 
@@ -169,9 +170,18 @@
 		}
 	}
 
-	if (io_uring_queue_init(RING_SIZE, &ring, 0)) {
-		fprintf(stderr, "failed ring init\n");
-		goto err_noring;
+	params.flags = IORING_SETUP_CQSIZE;
+	params.cq_entries = 4096;
+	ret = io_uring_queue_init_params(RING_SIZE, &ring, &params);
+	if (ret) {
+		if (ret == -EINVAL) {
+			fprintf(stdout, "No CQSIZE, trying without\n");
+			ret = io_uring_queue_init(RING_SIZE, &ring, 0);
+			if (ret) {
+				fprintf(stderr, "ring setup failed: %d\n", ret);
+				return 1;
+			}
+		}
 	}
 
 	if (arm_polls(&ring))