[PATCH liburing 3/3] test/rw: test reg bufs with non-align sizes/offset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Broaden registered buffers coverage with registering buffers with
non-aligned random offsets and sizes. That in particular test how we're
setting and advancing in-kernel bvecs.

Pass exp_len==-1 for that, so it compares against iov_len with which it
was initialised. Also, direct IO requires alignment, so do it in
buffered mode.

Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
---
 test/read-write.c | 71 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 65 insertions(+), 6 deletions(-)

diff --git a/test/read-write.c b/test/read-write.c
index 2399c32..84ea3a2 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -37,6 +37,23 @@ static int create_buffers(void)
 	return 0;
 }
 
+static int create_nonaligned_buffers(void)
+{
+	int i;
+
+	vecs = malloc(BUFFERS * sizeof(struct iovec));
+	for (i = 0; i < BUFFERS; i++) {
+		char *p = malloc(3 * BS);
+
+		if (!p)
+			return 1;
+		vecs[i].iov_base = p + (rand() % BS);
+		vecs[i].iov_len = 1 + (rand() % BS);
+	}
+
+	return 0;
+}
+
 static int create_file(const char *file)
 {
 	ssize_t ret;
@@ -155,6 +172,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 			}
 
 		}
+		sqe->user_data = i;
 		if (sqthread)
 			sqe->flags |= IOSQE_FIXED_FILE;
 		if (buf_select) {
@@ -162,7 +180,6 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 				sqe->addr = 0;
 			sqe->flags |= IOSQE_BUFFER_SELECT;
 			sqe->buf_group = buf_select;
-			sqe->user_data = i;
 		}
 		if (seq)
 			offset += BS;
@@ -187,6 +204,14 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 				warned = 1;
 				no_read = 1;
 			}
+		} else if (exp_len == -1) {
+			int iov_len = vecs[cqe->user_data].iov_len;
+
+			if (cqe->res != iov_len) {
+				fprintf(stderr, "cqe res %d, wanted %d\n",
+					cqe->res, iov_len);
+				goto err;
+			}
 		} else if (cqe->res != exp_len) {
 			fprintf(stderr, "cqe res %d, wanted %d\n", cqe->res, exp_len);
 			goto err;
@@ -238,7 +263,7 @@ err:
 	return 1;
 }
 static int test_io(const char *file, int write, int buffered, int sqthread,
-		   int fixed, int nonvec)
+		   int fixed, int nonvec, int exp_len)
 {
 	struct io_uring ring;
 	int ret, ring_flags;
@@ -263,7 +288,7 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 	}
 
 	ret = __test_io(file, &ring, write, buffered, sqthread, fixed, nonvec,
-			0, 0, BS);
+			0, 0, exp_len);
 
 	io_uring_queue_exit(&ring);
 	return ret;
@@ -593,14 +618,15 @@ static int test_write_efbig(void)
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	struct io_uring ring;
-	struct rlimit rlim;
+	struct rlimit rlim, old_rlim;
 	int i, fd, ret;
 	loff_t off;
 
-	if (getrlimit(RLIMIT_FSIZE, &rlim) < 0) {
+	if (getrlimit(RLIMIT_FSIZE, &old_rlim) < 0) {
 		perror("getrlimit");
 		return 1;
 	}
+	rlim = old_rlim;
 	rlim.rlim_cur = 64 * 1024;
 	rlim.rlim_max = 64 * 1024;
 	if (setrlimit(RLIMIT_FSIZE, &rlim) < 0) {
@@ -660,6 +686,11 @@ static int test_write_efbig(void)
 	io_uring_queue_exit(&ring);
 	close(fd);
 	unlink(".efbig");
+
+	if (setrlimit(RLIMIT_FSIZE, &old_rlim) < 0) {
+		perror("setrlimit");
+		return 1;
+	}
 	return 0;
 err:
 	if (fd != -1)
@@ -698,7 +729,8 @@ int main(int argc, char *argv[])
 		int fixed = (i & 8) != 0;
 		int nonvec = (i & 16) != 0;
 
-		ret = test_io(fname, write, buffered, sqthread, fixed, nonvec);
+		ret = test_io(fname, write, buffered, sqthread, fixed, nonvec,
+			      BS);
 		if (ret) {
 			fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n",
 				write, buffered, sqthread, fixed, nonvec);
@@ -754,6 +786,33 @@ int main(int argc, char *argv[])
 		goto err;
 	}
 
+	srand((unsigned)time(NULL));
+	if (create_nonaligned_buffers()) {
+		fprintf(stderr, "file creation failed\n");
+		goto err;
+	}
+
+	/* test fixed bufs with non-aligned len/offset */
+	for (i = 0; i < nr; i++) {
+		int write = (i & 1) != 0;
+		int buffered = (i & 2) != 0;
+		int sqthread = (i & 4) != 0;
+		int fixed = (i & 8) != 0;
+		int nonvec = (i & 16) != 0;
+
+		/* direct IO requires alignment, skip it */
+		if (!buffered || !fixed || nonvec)
+			continue;
+
+		ret = test_io(fname, write, buffered, sqthread, fixed, nonvec,
+			      -1);
+		if (ret) {
+			fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n",
+				write, buffered, sqthread, fixed, nonvec);
+			goto err;
+		}
+	}
+
 	if (fname != argv[1])
 		unlink(fname);
 	return 0;
-- 
2.24.0




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux