summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-10-09 15:24:30 -0600
committerJens Axboe <axboe@kernel.dk>2019-10-09 15:24:30 -0600
commit24bd08736590ef541708ad258086fac9b7573cc3 (patch)
treea27f8d03366e5574cf3747dc49cecc7fe0e1c04c
parentb00ba56bd510084ed86d6256a8b4fbed227dc81f (diff)
downloadliburing-24bd08736590ef541708ad258086fac9b7573cc3.tar.gz
liburing-24bd08736590ef541708ad258086fac9b7573cc3.tar.bz2
Add regression test case for commit 8a9973408177
Anything that causes an async punt after a fileset has been unregistered will cause a NULL pointer deref. Add a test case for that. We use fsync() since that will always need an async punt. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/8a9973408177-test.c102
-rw-r--r--test/Makefile4
2 files changed, 104 insertions, 2 deletions
diff --git a/test/8a9973408177-test.c b/test/8a9973408177-test.c
new file mode 100644
index 0000000..25c0bee
--- /dev/null
+++ b/test/8a9973408177-test.c
@@ -0,0 +1,102 @@
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+static int register_file(struct io_uring *ring)
+{
+ char buf[32];
+ int ret, fd;
+
+ sprintf(buf, "./XXXXXX");
+ fd = mkstemp(buf);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ ret = io_uring_register_files(ring, &fd, 1);
+ if (ret) {
+ fprintf(stderr, "file register %d\n", ret);
+ return 1;
+ }
+
+ ret = io_uring_unregister_files(ring);
+ if (ret) {
+ fprintf(stderr, "file register %d\n", ret);
+ return 1;
+ }
+
+ unlink(buf);
+ close(fd);
+ return 0;
+}
+
+static int test_single_fsync(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ char buf[32];
+ int fd, ret;
+
+ sprintf(buf, "./XXXXXX");
+ fd = mkstemp(buf);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ goto err;
+ }
+
+ io_uring_prep_fsync(sqe, fd, 0);
+
+ ret = io_uring_submit(ring);
+ if (ret <= 0) {
+ printf("sqe submit failed: %d\n", ret);
+ goto err;
+ }
+
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ printf("wait completion %d\n", ret);
+ goto err;
+ }
+
+ io_uring_cqe_seen(ring, cqe);
+ unlink(buf);
+ return 0;
+err:
+ unlink(buf);
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring ring;
+ int ret;
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret) {
+ printf("ring setup failed\n");
+ return 1;
+ }
+
+ ret = register_file(&ring);
+ if (ret)
+ return ret;
+ ret = test_single_fsync(&ring);
+ if (ret) {
+ printf("test_single_fsync failed\n");
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/test/Makefile b/test/Makefile
index 5ab9143..13f0346 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -7,7 +7,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
917257daa0fe-test b19062a56726-test eeed8b54e0df-test link \
send_recvmsg a4c0b3decb33-test 500f9fbadef8-test timeout \
sq-space_left stdout cq-ready cq-peek-batch file-register \
- cq-size
+ cq-size 8a9973408177-test
include ../Makefile.quiet
@@ -21,7 +21,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
35fa71a030ca-test.c 917257daa0fe-test.c b19062a56726-test.c \
eeed8b54e0df-test.c link.c send_recvmsg.c a4c0b3decb33-test.c \
500f9fbadef8-test.c timeout.c sq-space_left.c stdout.c cq-ready.c\
- cq-peek-batch.c file-register.c cq-size.c
+ cq-peek-batch.c file-register.c cq-size.c 8a9973408177-test.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))