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 1/5] io_uring: add rename opcode for current working directory
Date: Tue, 31 May 2022 19:41:21 +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_RENAMEAT.

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

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 9f1c682d7caf..8bf56523ff7f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1306,6 +1306,7 @@ static const struct io_op_def io_op_defs[] = {
 	[IORING_OP_SHUTDOWN] = {
 		.needs_file		= 1,
 	},
+	[IORING_OP_RENAME] = {},
 	[IORING_OP_RENAMEAT] = {},
 	[IORING_OP_UNLINKAT] = {},
 	[IORING_OP_MKDIRAT] = {},
@@ -1449,6 +1450,8 @@ const char *io_uring_get_opcode(u8 opcode)
 		return "TEE";
 	case IORING_OP_SHUTDOWN:
 		return "SHUTDOWN";
+	case IORING_OP_RENAME:
+		return "RENAME";
 	case IORING_OP_RENAMEAT:
 		return "RENAMEAT";
 	case IORING_OP_UNLINKAT:
@@ -4553,8 +4556,8 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
 	return ret;
 }
 
-static int io_renameat_prep(struct io_kiocb *req,
-			    const struct io_uring_sqe *sqe)
+static int io_rename_prep(struct io_kiocb *req,
+			    const struct io_uring_sqe *sqe, bool is_cwd)
 {
 	struct io_rename *ren = &req->rename;
 	const char __user *oldf, *newf;
@@ -4564,10 +4567,14 @@ static int io_renameat_prep(struct io_kiocb *req,
 	if (unlikely(req->flags & REQ_F_FIXED_FILE))
 		return -EBADF;
 
-	ren->old_dfd = READ_ONCE(sqe->fd);
+	if (is_cwd) {
+		ren->old_dfd = ren->new_dfd = AT_FDCWD;
+	} else {
+		ren->old_dfd = READ_ONCE(sqe->fd);
+		ren->new_dfd = READ_ONCE(sqe->len);
+	}
 	oldf = u64_to_user_ptr(READ_ONCE(sqe->addr));
 	newf = u64_to_user_ptr(READ_ONCE(sqe->addr2));
-	ren->new_dfd = READ_ONCE(sqe->len);
 	ren->flags = READ_ONCE(sqe->rename_flags);
 
 	ren->oldpath = getname(oldf);
@@ -4584,7 +4591,7 @@ static int io_renameat_prep(struct io_kiocb *req,
 	return 0;
 }
 
-static int io_renameat(struct io_kiocb *req, unsigned int issue_flags)
+static int io_rename(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_rename *ren = &req->rename;
 	int ret;
@@ -8076,8 +8083,10 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 		return io_tee_prep(req, sqe);
 	case IORING_OP_SHUTDOWN:
 		return io_shutdown_prep(req, sqe);
+	case IORING_OP_RENAME:
+		return io_rename_prep(req, sqe, 1);
 	case IORING_OP_RENAMEAT:
-		return io_renameat_prep(req, sqe);
+		return io_rename_prep(req, sqe, 0);
 	case IORING_OP_UNLINKAT:
 		return io_unlinkat_prep(req, sqe);
 	case IORING_OP_MKDIRAT:
@@ -8229,6 +8238,7 @@ static void io_clean_op(struct io_kiocb *req)
 			if (req->open.filename)
 				putname(req->open.filename);
 			break;
+		case IORING_OP_RENAME:
 		case IORING_OP_RENAMEAT:
 			putname(req->rename.oldpath);
 			putname(req->rename.newpath);
@@ -8395,8 +8405,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 	case IORING_OP_SHUTDOWN:
 		ret = io_shutdown(req, issue_flags);
 		break;
+	case IORING_OP_RENAME:
 	case IORING_OP_RENAMEAT:
-		ret = io_renameat(req, issue_flags);
+		ret = io_rename(req, issue_flags);
 		break;
 	case IORING_OP_UNLINKAT:
 		ret = io_unlinkat(req, issue_flags);
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 53e7dae92e42..73f4e1c4133d 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -189,6 +189,7 @@ enum io_uring_op {
 	IORING_OP_GETXATTR,
 	IORING_OP_SOCKET,
 	IORING_OP_URING_CMD,
+	IORING_OP_RENAME,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
-- 
2.25.1


  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 ` Usama Arif [this message]
2022-05-31 18:41 ` [PATCH 2/5] io_uring: add unlink opcode " Usama Arif
2022-05-31 18:41 ` [PATCH 3/5] io_uring: add mkdir " Usama Arif
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