summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-12-13 11:15:16 -0700
committerJens Axboe <axboe@kernel.dk>2019-12-13 11:15:16 -0700
commit4cf05b8734973c5c6aa84f72f52299d89845b9d1 (patch)
tree7fae8e2ca04846e23436af9f3573ed4fa72a7f53
parent15226c1f4e99cd0bbba78b5364b4dfe7db3845d2 (diff)
downloadliburing-4cf05b8734973c5c6aa84f72f52299d89845b9d1.tar.gz
liburing-4cf05b8734973c5c6aa84f72f52299d89845b9d1.tar.bz2
test/file-update: register files in multiple rings
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/Makefile6
-rw-r--r--test/file-update.c129
2 files changed, 133 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index f93761e..b6e8d0b 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -17,7 +17,8 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
link-timeout cq-overflow link_drain fc2a85cb02ef-test \
poll-link accept-link fixed-link poll-cancel-ton teardowns \
poll-many b5837bd5311d-test accept-test d77a67ed5f27-test \
- connect 7ad0e4b2f83c-test submit-reuse fallocate open-close
+ connect 7ad0e4b2f83c-test submit-reuse fallocate open-close \
+ file-update
include ../Makefile.quiet
@@ -37,7 +38,8 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
cq-overflow.c link_drain.c fc2a85cb02ef-test.c poll-link.c \
accept-link.c fixed-link.c poll-cancel-ton.c teardowns.c poll-many.c \
b5837bd5311d-test.c accept-test.c d77a67ed5f27-test.c connect.c \
- 7ad0e4b2f83c-test.c submit-reuse.c fallocate.c open-close.c
+ 7ad0e4b2f83c-test.c submit-reuse.c fallocate.c open-close.c \
+ file-update.c
test_objs := $(patsubst %.c,%.ol,$(test_srcs))
diff --git a/test/file-update.c b/test/file-update.c
new file mode 100644
index 0000000..c3b91ac
--- /dev/null
+++ b/test/file-update.c
@@ -0,0 +1,129 @@
+/*
+ * Description: run various file registration tests
+ *
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "liburing.h"
+
+static void close_files(int *files, int nr_files, int add)
+{
+ char fname[32];
+ int i;
+
+ for (i = 0; i < nr_files; i++) {
+ if (files)
+ close(files[i]);
+ if (!add)
+ sprintf(fname, ".reg.%d", i);
+ else
+ sprintf(fname, ".add.%d", i + add);
+ unlink(fname);
+ }
+ if (files)
+ free(files);
+}
+
+static int *open_files(int nr_files, int extra, int add)
+{
+ char fname[32];
+ int *files;
+ int i;
+
+ files = calloc(nr_files + extra, sizeof(int));
+
+ for (i = 0; i < nr_files; i++) {
+ if (!add)
+ sprintf(fname, ".reg.%d", i);
+ else
+ sprintf(fname, ".add.%d", i + add);
+ files[i] = open(fname, O_RDWR | O_CREAT, 0644);
+ if (files[i] < 0) {
+ perror("open");
+ free(files);
+ files = NULL;
+ break;
+ }
+ }
+ if (extra) {
+ for (i = nr_files; i < nr_files + extra; i++)
+ files[i] = -1;
+ }
+
+ return files;
+}
+
+static int test_update_multiring(struct io_uring *r1, struct io_uring *r2,
+ struct io_uring *r3, int do_unreg)
+{
+ int *fds, *newfds;
+
+ fds = open_files(10, 0, 0);
+ newfds = open_files(10, 0, 1);
+
+ if (io_uring_register_files(r1, fds, 10) ||
+ io_uring_register_files(r2, fds, 10) ||
+ io_uring_register_files(r3, fds, 10)) {
+ fprintf(stderr, "%s: register files failed\n", __FUNCTION__);
+ goto err;
+ }
+
+ if (io_uring_register_files_update(r1, 0, newfds, 10) != 10 ||
+ io_uring_register_files_update(r2, 0, newfds, 10) != 10 ||
+ io_uring_register_files_update(r3, 0, newfds, 10) != 10) {
+ fprintf(stderr, "%s: update files failed\n", __FUNCTION__);
+ goto err;
+ }
+
+ if (!do_unreg)
+ goto done;
+
+ if (io_uring_unregister_files(r1) ||
+ io_uring_unregister_files(r2) ||
+ io_uring_unregister_files(r3)) {
+ fprintf(stderr, "%s: unregister files failed\n", __FUNCTION__);
+ goto err;
+ }
+
+done:
+ close_files(fds, 10, 0);
+ close_files(newfds, 10, 1);
+ return 0;
+err:
+ close_files(fds, 10, 0);
+ close_files(newfds, 10, 1);
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring r1, r2, r3;
+ int ret;
+
+ if (io_uring_queue_init(8, &r1, 0) ||
+ io_uring_queue_init(8, &r2, 0) ||
+ io_uring_queue_init(8, &r3, 0)) {
+ fprintf(stderr, "ring setup failed\n");
+ return 1;
+ }
+
+ ret = test_update_multiring(&r1, &r2, &r3, 1);
+ if (ret) {
+ fprintf(stderr, "test_update_multiring w/unreg\n");
+ return ret;
+ }
+
+ ret = test_update_multiring(&r1, &r2, &r3, 0);
+ if (ret) {
+ fprintf(stderr, "test_update_multiring wo/unreg\n");
+ return ret;
+ }
+
+
+ return 0;
+}