public inbox for [email protected]
 help / color / mirror / Atom feed
From: Usama Arif <[email protected]>
To: [email protected], [email protected], [email protected]
Cc: [email protected], Usama Arif <[email protected]>
Subject: [PATCH 3/5] io_uring: add mkdir opcode for current working directory
Date: Tue, 31 May 2022 19:41:23 +0100	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

This provides consistency between io_uring and the respective I/O syscall
and avoids having the user of liburing specify the cwd in sqe for
IORING_OP_MKDIRAT.

Signed-off-by: Usama Arif <[email protected]>
---
 fs/io_uring.c                 | 20 +++++++++++++++-----
 include/uapi/linux/io_uring.h |  1 +
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index d38c5f54f6a4..9c9fa0b3938d 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1310,6 +1310,7 @@ static const struct io_op_def io_op_defs[] = {
 	[IORING_OP_RENAMEAT] = {},
 	[IORING_OP_UNLINK] = {},
 	[IORING_OP_UNLINKAT] = {},
+	[IORING_OP_MKDIR] = {},
 	[IORING_OP_MKDIRAT] = {},
 	[IORING_OP_SYMLINKAT] = {},
 	[IORING_OP_LINKAT] = {},
@@ -1459,6 +1460,8 @@ const char *io_uring_get_opcode(u8 opcode)
 		return "UNLINK";
 	case IORING_OP_UNLINKAT:
 		return "UNLINKAT";
+	case IORING_OP_MKDIR:
+		return "MKDIR";
 	case IORING_OP_MKDIRAT:
 		return "MKDIRAT";
 	case IORING_OP_SYMLINKAT:
@@ -4897,8 +4900,8 @@ static int io_unlink(struct io_kiocb *req, unsigned int issue_flags)
 	return 0;
 }
 
-static int io_mkdirat_prep(struct io_kiocb *req,
-			    const struct io_uring_sqe *sqe)
+static int io_mkdir_prep(struct io_kiocb *req,
+			    const struct io_uring_sqe *sqe, bool is_cwd)
 {
 	struct io_mkdir *mkd = &req->mkdir;
 	const char __user *fname;
@@ -4908,7 +4911,10 @@ static int io_mkdirat_prep(struct io_kiocb *req,
 	if (unlikely(req->flags & REQ_F_FIXED_FILE))
 		return -EBADF;
 
-	mkd->dfd = READ_ONCE(sqe->fd);
+	if (is_cwd)
+		mkd->dfd = AT_FDCWD;
+	else
+		mkd->dfd = READ_ONCE(sqe->fd);
 	mkd->mode = READ_ONCE(sqe->len);
 
 	fname = u64_to_user_ptr(READ_ONCE(sqe->addr));
@@ -4920,7 +4926,7 @@ static int io_mkdirat_prep(struct io_kiocb *req,
 	return 0;
 }
 
-static int io_mkdirat(struct io_kiocb *req, unsigned int issue_flags)
+static int io_mkdir(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_mkdir *mkd = &req->mkdir;
 	int ret;
@@ -8097,8 +8103,10 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 		return io_unlink_prep(req, sqe, 1);
 	case IORING_OP_UNLINKAT:
 		return io_unlink_prep(req, sqe, 0);
+	case IORING_OP_MKDIR:
+		return io_mkdir_prep(req, sqe, 1);
 	case IORING_OP_MKDIRAT:
-		return io_mkdirat_prep(req, sqe);
+		return io_mkdir_prep(req, sqe, 0);
 	case IORING_OP_SYMLINKAT:
 		return io_symlinkat_prep(req, sqe);
 	case IORING_OP_LINKAT:
@@ -8255,6 +8263,7 @@ static void io_clean_op(struct io_kiocb *req)
 		case IORING_OP_UNLINKAT:
 			putname(req->unlink.filename);
 			break;
+		case IORING_OP_MKDIR:
 		case IORING_OP_MKDIRAT:
 			putname(req->mkdir.filename);
 			break;
@@ -8422,6 +8431,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 	case IORING_OP_UNLINKAT:
 		ret = io_unlink(req, issue_flags);
 		break;
+	case IORING_OP_MKDIR:
 	case IORING_OP_MKDIRAT:
 		ret = io_mkdirat(req, issue_flags);
 		break;
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 7828b7183d01..58f2e0611152 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -191,6 +191,7 @@ enum io_uring_op {
 	IORING_OP_URING_CMD,
 	IORING_OP_RENAME,
 	IORING_OP_UNLINK,
+	IORING_OP_MKDIR,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
-- 
2.25.1



  parent reply	other threads:[~2022-05-31 18:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-31 18:41 [PATCH 0/5] io_uring: add opcodes for current working directory Usama Arif
2022-05-31 18:41 ` [PATCH 1/5] io_uring: add rename opcode " Usama Arif
2022-05-31 18:41 ` [PATCH 2/5] io_uring: add unlink " Usama Arif
2022-05-31 18:41 ` Usama Arif [this message]
2022-05-31 18:41 ` [PATCH 4/5] io_uring: add symlink " Usama Arif
2022-05-31 18:41 ` [PATCH 5/5] io_uring: add link " Usama Arif
2022-05-31 18:58 ` [PATCH 0/5] io_uring: add opcodes " Jens Axboe
2022-05-31 19:18   ` [External] " Usama Arif
2022-05-31 19:22     ` Jens Axboe
2022-05-31 21:35       ` Usama Arif
2022-06-01  2:57         ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox