public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing 0/3] add mkdirat support
@ 2020-11-16  5:10 Dmitry Kadashev
  2020-11-16  5:10 ` [PATCH liburing 1/3] io_uring.h: add mkdirat opcode Dmitry Kadashev
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dmitry Kadashev @ 2020-11-16  5:10 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, Dmitry Kadashev

This series adds support for mkdirat opcode along with a testcase for it
to liburing. Heavily based on a series that added unlinkat support
(commit: 44db0f437a2b ("io_uring.h: add renameat and unlinkat opcodes")
and a couple of subsequent ones).

The kernel side of the change:
https://lore.kernel.org/io-uring/[email protected]/T/

Dmitry Kadashev (3):
  io_uring.h: add mkdirat opcode
  liburing.h: add mkdirat prep helpers
  Add mkdirat test case

 .gitignore                      |   1 +
 src/include/liburing.h          |   6 ++
 src/include/liburing/io_uring.h |   1 +
 test/Makefile                   |   2 +
 test/mkdir.c                    | 106 ++++++++++++++++++++++++++++++++
 5 files changed, 116 insertions(+)
 create mode 100644 test/mkdir.c

-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH liburing 1/3] io_uring.h: add mkdirat opcode
  2020-11-16  5:10 [PATCH liburing 0/3] add mkdirat support Dmitry Kadashev
@ 2020-11-16  5:10 ` Dmitry Kadashev
  2020-11-16  5:10 ` [PATCH liburing 2/3] liburing.h: add mkdirat prep helpers Dmitry Kadashev
  2020-11-16  5:10 ` [PATCH liburing 3/3] Add mkdirat test case Dmitry Kadashev
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Kadashev @ 2020-11-16  5:10 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, Dmitry Kadashev

Signed-off-by: Dmitry Kadashev <[email protected]>
---
 src/include/liburing/io_uring.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index e52ad2d..23a699c 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -141,6 +141,7 @@ enum {
 	IORING_OP_SHUTDOWN,
 	IORING_OP_RENAMEAT,
 	IORING_OP_UNLINKAT,
+	IORING_OP_MKDIRAT,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH liburing 2/3] liburing.h: add mkdirat prep helpers
  2020-11-16  5:10 [PATCH liburing 0/3] add mkdirat support Dmitry Kadashev
  2020-11-16  5:10 ` [PATCH liburing 1/3] io_uring.h: add mkdirat opcode Dmitry Kadashev
@ 2020-11-16  5:10 ` Dmitry Kadashev
  2020-11-16  5:10 ` [PATCH liburing 3/3] Add mkdirat test case Dmitry Kadashev
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Kadashev @ 2020-11-16  5:10 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, Dmitry Kadashev

Signed-off-by: Dmitry Kadashev <[email protected]>
---
 src/include/liburing.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index cc32232..f1b16dc 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -486,6 +486,12 @@ static inline void io_uring_prep_renameat(struct io_uring_sqe *sqe, int olddfd,
 	sqe->rename_flags = flags;
 }
 
+static inline void io_uring_prep_mkdirat(struct io_uring_sqe *sqe, int dfd,
+					const char *path, mode_t mode)
+{
+	io_uring_prep_rw(IORING_OP_MKDIRAT, sqe, dfd, path, mode, 0);
+}
+
 /*
  * Returns number of unconsumed (if SQPOLL) or unsubmitted entries exist in
  * the SQ ring
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH liburing 3/3] Add mkdirat test case
  2020-11-16  5:10 [PATCH liburing 0/3] add mkdirat support Dmitry Kadashev
  2020-11-16  5:10 ` [PATCH liburing 1/3] io_uring.h: add mkdirat opcode Dmitry Kadashev
  2020-11-16  5:10 ` [PATCH liburing 2/3] liburing.h: add mkdirat prep helpers Dmitry Kadashev
@ 2020-11-16  5:10 ` Dmitry Kadashev
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Kadashev @ 2020-11-16  5:10 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, Dmitry Kadashev

The test is relative basic: tests only success, EEXISTS, ENOENT (no
parent dir).

Signed-off-by: Dmitry Kadashev <[email protected]>
---
 .gitignore    |   1 +
 test/Makefile |   2 +
 test/mkdir.c  | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 test/mkdir.c

diff --git a/.gitignore b/.gitignore
index 53c076f..0a49dad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,6 +68,7 @@
 /test/link-timeout
 /test/link_drain
 /test/madvise
+/test/mkdir
 /test/nop
 /test/nop-all-sizes
 /test/open-close
diff --git a/test/Makefile b/test/Makefile
index f457ac7..718bca9 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -66,6 +66,7 @@ test_targets += \
 	link-timeout \
 	link_drain \
 	madvise \
+	mkdir \
 	nop \
 	nop-all-sizes \
 	open-close \
@@ -186,6 +187,7 @@ test_srcs := \
 	link.c \
 	link_drain.c \
 	madvise.c \
+	mkdir.c \
 	nop-all-sizes.c \
 	nop.c \
 	open-close.c \
diff --git a/test/mkdir.c b/test/mkdir.c
new file mode 100644
index 0000000..88bb9b6
--- /dev/null
+++ b/test/mkdir.c
@@ -0,0 +1,105 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Description: test io_uring mkdirat handling
+ */
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "liburing.h"
+
+static int test_mkdirat(struct io_uring *ring, const char *fn)
+{
+	int ret;
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+
+	sqe = io_uring_get_sqe(ring);
+	if (!sqe) {
+		fprintf(stderr, "sqe get failed\n");
+		goto err;
+	}
+	io_uring_prep_mkdirat(sqe, AT_FDCWD, fn, 0700);
+
+	ret = io_uring_submit(ring);
+	if (ret != 1) {
+		fprintf(stderr, "submit failed: %d\n", ret);
+		goto err;
+	}
+
+	ret = io_uring_wait_cqes(ring, &cqe, 1, 0, 0);
+	if (ret) {
+		fprintf(stderr, "wait_cqe failed: %d\n", ret);
+		goto err;
+	}
+	ret = cqe->res;
+	io_uring_cqe_seen(ring, cqe);
+	return ret;
+err:
+	return 1;
+}
+
+static int stat_file(const char *buf)
+{
+	struct stat sb;
+
+	if (!stat(buf, &sb))
+		return 0;
+
+	return errno;
+}
+
+int main(int argc, char *argv[])
+{
+	static const char fn[] = "io_uring-mkdirat-test";
+	int ret;
+	struct io_uring ring;
+
+	ret = io_uring_queue_init(8, &ring, 0);
+	if (ret) {
+		fprintf(stderr, "queue init failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = test_mkdirat(&ring, fn);
+	if (ret < 0) {
+		if (ret == -EBADF || ret == -EINVAL) {
+			fprintf(stdout, "mkdirat not supported, skipping\n");
+			goto out;
+		}
+		fprintf(stderr, "mkdirat: %s\n", strerror(-ret));
+		goto err;
+	} else if (ret) {
+		goto err;
+	}
+
+	if (stat_file(fn)) {
+		perror("stat");
+		goto err;
+	}
+
+	ret = test_mkdirat(&ring, fn);
+	if (ret != -EEXIST) {
+		fprintf(stderr, "test_mkdirat already exists failed: %d\n", ret);
+		goto err1;
+	}
+
+	ret = test_mkdirat(&ring, "surely/this/wont/exist");
+	if (ret != -ENOENT) {
+		fprintf(stderr, "test_mkdirat no parent failed: %d\n", ret);
+		goto err1;
+	}
+
+out:
+	unlinkat(AT_FDCWD, fn, AT_REMOVEDIR);
+	io_uring_queue_exit(&ring);
+	return 0;
+err1:
+	unlinkat(AT_FDCWD, fn, AT_REMOVEDIR);
+err:
+	io_uring_queue_exit(&ring);
+	return 1;
+}
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-16  5:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-16  5:10 [PATCH liburing 0/3] add mkdirat support Dmitry Kadashev
2020-11-16  5:10 ` [PATCH liburing 1/3] io_uring.h: add mkdirat opcode Dmitry Kadashev
2020-11-16  5:10 ` [PATCH liburing 2/3] liburing.h: add mkdirat prep helpers Dmitry Kadashev
2020-11-16  5:10 ` [PATCH liburing 3/3] Add mkdirat test case Dmitry Kadashev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox