summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-03-20 15:08:02 -0600
committerJens Axboe <axboe@kernel.dk>2020-03-20 15:08:02 -0600
commitfea5b7057eedfd6ee4fec69cfd6d1f67197bbe9b (patch)
tree35934ca1f09d82ea329b21f1512d4ad6a0a4f4f1 /test
parent88329a785394131f7f3e3a9aec968058fb641cdb (diff)
downloadliburing-fea5b7057eedfd6ee4fec69cfd6d1f67197bbe9b.tar.gz
liburing-fea5b7057eedfd6ee4fec69cfd6d1f67197bbe9b.tar.bz2
test/fallocate: add test case for exceeding RLIMIT_FSIZE
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test')
-rw-r--r--test/fallocate.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/fallocate.c b/test/fallocate.c
index f925553..747f774 100644
--- a/test/fallocate.c
+++ b/test/fallocate.c
@@ -8,6 +8,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/resource.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
@@ -16,6 +17,68 @@
static int no_fallocate;
+static int test_fallocate_rlimit(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ struct rlimit rlim;
+ char buf[32];
+ int fd, ret;
+
+ if (getrlimit(RLIMIT_FSIZE, &rlim) < 0) {
+ perror("getrlimit");
+ return 1;
+ }
+ rlim.rlim_cur = 64 * 1024;
+ rlim.rlim_max = 64 * 1024;
+ if (setrlimit(RLIMIT_FSIZE, &rlim) < 0) {
+ perror("setrlimit");
+ return 1;
+ }
+
+ sprintf(buf, "./XXXXXX");
+ fd = mkstemp(buf);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "get sqe failed\n");
+ goto err;
+ }
+ io_uring_prep_fallocate(sqe, fd, 0, 0, 128*1024);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "wait completion %d\n", ret);
+ goto err;
+ }
+
+ if (cqe->res == -EINVAL) {
+ fprintf(stdout, "Fallocate not supported, skipping\n");
+ no_fallocate = 1;
+ goto out;
+ } else if (cqe->res != -EFBIG) {
+ fprintf(stderr, "Expected -EFBIG: %d\n", cqe->res);
+ goto err;
+ }
+ io_uring_cqe_seen(ring, cqe);
+out:
+ unlink(buf);
+ return 0;
+err:
+ unlink(buf);
+ return 1;
+}
+
static int test_fallocate(struct io_uring *ring)
{
struct io_uring_cqe *cqe;
@@ -176,5 +239,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_fallocate_rlimit(&ring);
+ if (ret) {
+ fprintf(stderr, "test_fallocate_rlimit failed\n");
+ return ret;
+ }
+
return 0;
}