summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-04-08 09:48:43 -0600
committerJens Axboe <axboe@kernel.dk>2020-04-08 09:48:43 -0600
commit884f44fd30026d55012a975c6f86c75b98a4c217 (patch)
tree08cde2ccca5c1cd27305f54167374d9b522ba341 /test
parentd50b2df35dfcfcb5a244dd0801228fbd35cda8f7 (diff)
downloadliburing-884f44fd30026d55012a975c6f86c75b98a4c217.tar.gz
liburing-884f44fd30026d55012a975c6f86c75b98a4c217.tar.bz2
test/lfs-openat-write: test LFS writes with OPENAT file
Heavily based on test case from Dmitry Kadashev <dkadashev@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile4
-rw-r--r--test/lfs-openat-write.c110
2 files changed, 112 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index d9b10de..f8baa46 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -21,7 +21,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
file-update statx accept-reuse poll-v-poll fadvise madvise \
short-read openat2 probe shared-wq personality eventfd \
send_recv eventfd-ring across-fork sq-poll-kthread splice \
- lfs-openat
+ lfs-openat lfs-openat-write
include ../Makefile.quiet
@@ -49,7 +49,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
file-update.c statx.c accept-reuse.c poll-v-poll.c fadvise.c \
madvise.c short-read.c openat2.c probe.c shared-wq.c \
personality.c eventfd.c eventfd-ring.c across-fork.c sq-poll-kthread.c \
- splice.c lfs-openat.c
+ splice.c lfs-openat.c lfs-openat-write.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/lfs-openat-write.c b/test/lfs-openat-write.c
new file mode 100644
index 0000000..b36a288
--- /dev/null
+++ b/test/lfs-openat-write.c
@@ -0,0 +1,110 @@
+#include <liburing.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+static const int RSIZE = 2;
+static const int OPEN_FLAGS = O_RDWR | O_CREAT;
+static const mode_t OPEN_MODE = S_IRUSR | S_IWUSR;
+
+#define DIE(...) do {\
+ fprintf(stderr, __VA_ARGS__);\
+ abort();\
+ } while(0);
+
+static int do_write(struct io_uring *ring, int fd, off_t offset)
+{
+ char buf[] = "some test write buf";
+ int res;
+ struct io_uring_sqe *sqe;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "failed to get sqe\n");
+ return 1;
+ }
+ io_uring_prep_write(sqe, fd, buf, sizeof(buf), offset);
+ int ret = io_uring_submit(ring);
+ if (ret < 0) {
+ fprintf(stderr, "failed to submit write: %s\n", strerror(-ret));
+ return 1;
+ }
+
+ struct io_uring_cqe *cqe;
+
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "wait_cqe failed: %s\n", strerror(-ret));
+ return 1;
+ }
+
+ res = cqe->res;
+ io_uring_cqe_seen(ring, cqe);
+ if (res < 0) {
+ fprintf(stderr, "write failed: %s\n", strerror(-res));
+ return 1;
+ }
+
+ return 0;
+}
+
+static int test_open_write(struct io_uring *ring, int dfd, const char *fn)
+{
+ struct io_uring_sqe *sqe;
+ int fd = -1;
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "failed to get sqe\n");
+ return 1;
+ }
+
+ io_uring_prep_openat(sqe, dfd, fn, OPEN_FLAGS, OPEN_MODE);
+ int ret = io_uring_submit(ring);
+ if (ret < 0) {
+ fprintf(stderr, "failed to submit openat: %s\n", strerror(-ret));
+ return 1;
+ }
+
+ struct io_uring_cqe *cqe;
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "wait_cqe failed: %s\n", strerror(-ret));
+ return 1;
+ }
+
+ fd = cqe->res;
+ io_uring_cqe_seen(ring, cqe);
+ if (fd < 0) {
+ fprintf(stderr, "openat failed: %s\n", strerror(-fd));
+ return 1;
+ }
+
+ return do_write(ring, fd, 1ULL << 32);
+}
+
+int main(int argc, char *argv[])
+{
+ int dfd = open("/tmp", O_RDONLY | O_DIRECTORY);
+ if (dfd < 0) {
+ DIE("open /tmp: %s\n", strerror(errno));
+ }
+ struct io_uring ring;
+ int ret = io_uring_queue_init(RSIZE, &ring, 0);
+ if (ret < 0) {
+ DIE("failed to init io_uring: %s\n", strerror(-ret));
+ }
+
+ ret = test_open_write(&ring, dfd, "io_uring_openat_write_test1");
+
+ io_uring_queue_exit(&ring);
+ close(dfd);
+ unlink("/tmp/io_uring_openat_write_test1");
+ return 0;
+}