Registering lots of memory will fail for non-privileged users, so skip tests if that happens. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- 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