public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 2/2] tests: skip when large buf register fails
Date: Wed, 25 Aug 2021 18:53:36 +0100	[thread overview]
Message-ID: <682c09c1d153cd4dfe505ded6069b294e98078e3.1629913874.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Registering lots of memory will fail for non-privileged users, so skip
tests if that happens.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/helpers.c    | 19 +++++++++++++++++++
 test/helpers.h    |  4 ++++
 test/iopoll.c     | 24 ++++++++++++------------
 test/read-write.c | 26 +++++++++++---------------
 4 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/test/helpers.c b/test/helpers.c
index 930d82a..975e7cb 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -114,3 +114,22 @@ enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
 	p.flags = flags;
 	return t_create_ring_params(depth, ring, &p);
 }
+
+enum t_setup_ret t_register_buffers(struct io_uring *ring,
+				    const struct iovec *iovecs,
+				    unsigned nr_iovecs)
+{
+	int ret;
+
+	ret = io_uring_register_buffers(ring, iovecs, nr_iovecs);
+	if (!ret)
+		return T_SETUP_OK;
+
+	if ((ret == -EPERM || ret == -ENOMEM) && geteuid()) {
+		fprintf(stdout, "too large non-root buffer registration, skip\n");
+		return T_SETUP_SKIP;
+	}
+
+	fprintf(stderr, "buffer register failed: %s\n", strerror(-ret));
+	return ret;
+}
diff --git a/test/helpers.h b/test/helpers.h
index 18de463..7526d46 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -54,6 +54,10 @@ enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring,
 enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
 			       unsigned int flags);
 
+enum t_setup_ret t_register_buffers(struct io_uring *ring,
+				    const struct iovec *iovecs,
+				    unsigned nr_iovecs);
+
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 #ifdef __cplusplus
diff --git a/test/iopoll.c b/test/iopoll.c
index 7037c31..de36473 100644
--- a/test/iopoll.c
+++ b/test/iopoll.c
@@ -60,14 +60,13 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int sqt
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	int open_flags;
-	int i, fd, ret;
+	int i, fd = -1, ret;
 	off_t offset;
 
-	if (buf_select && write)
+	if (buf_select) {
 		write = 0;
-	if (buf_select && fixed)
 		fixed = 0;
-
+	}
 	if (buf_select && provide_buffers(ring))
 		return 1;
 
@@ -77,19 +76,20 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int sqt
 		open_flags = O_RDONLY;
 	open_flags |= O_DIRECT;
 
-	fd = open(file, open_flags);
-	if (fd < 0) {
-		perror("file open");
-		goto err;
-	}
-
 	if (fixed) {
-		ret = io_uring_register_buffers(ring, vecs, BUFFERS);
-		if (ret) {
+		ret = t_register_buffers(ring, vecs, BUFFERS);
+		if (ret == T_SETUP_SKIP)
+			return 0;
+		if (ret != T_SETUP_OK) {
 			fprintf(stderr, "buffer reg failed: %d\n", ret);
 			goto err;
 		}
 	}
+	fd = open(file, open_flags);
+	if (fd < 0) {
+		perror("file open");
+		goto err;
+	}
 	if (sqthread) {
 		ret = io_uring_register_files(ring, &fd, 1);
 		if (ret) {
diff --git a/test/read-write.c b/test/read-write.c
index 1cfa2d5..0c55159 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -49,7 +49,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	int open_flags;
-	int i, fd, ret;
+	int i, fd = -1, ret;
 	off_t offset;
 
 #ifdef VERBOSE
@@ -57,13 +57,6 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 							buffered, sqthread,
 							fixed, nonvec);
 #endif
-	if (sqthread && geteuid()) {
-#ifdef VERBOSE
-		fprintf(stdout, "SKIPPED (not root)\n");
-#endif
-		return 0;
-	}
-
 	if (write)
 		open_flags = O_WRONLY;
 	else
@@ -71,19 +64,22 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 	if (!buffered)
 		open_flags |= O_DIRECT;
 
+	if (fixed) {
+		ret = t_register_buffers(ring, vecs, BUFFERS);
+		if (ret == T_SETUP_SKIP)
+			return 0;
+		if (ret != T_SETUP_OK) {
+			fprintf(stderr, "buffer reg failed: %d\n", ret);
+			goto err;
+		}
+	}
+
 	fd = open(file, open_flags);
 	if (fd < 0) {
 		perror("file open");
 		goto err;
 	}
 
-	if (fixed) {
-		ret = io_uring_register_buffers(ring, vecs, BUFFERS);
-		if (ret) {
-			fprintf(stderr, "buffer reg failed: %d\n", ret);
-			goto err;
-		}
-	}
 	if (sqthread) {
 		ret = io_uring_register_files(ring, &fd, 1);
 		if (ret) {
-- 
2.32.0


  parent reply	other threads:[~2021-08-25 17:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25 17:53 [PATCH liburing 0/2] non-root tests Pavel Begunkov
2021-08-25 17:53 ` [PATCH liburing 1/2] tests: don't skip sqpoll needlessly Pavel Begunkov
2021-08-25 17:53 ` Pavel Begunkov [this message]
2021-08-25 17:59 ` [PATCH liburing 0/2] non-root tests Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=682c09c1d153cd4dfe505ded6069b294e98078e3.1629913874.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox