[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220531184125.2665210-6-usama.arif@bytedance.com>
Date: Tue, 31 May 2022 19:41:25 +0100
From: Usama Arif <usama.arif@...edance.com>
To: io-uring@...r.kernel.org, axboe@...nel.dk,
linux-kernel@...r.kernel.org
Cc: fam.zheng@...edance.com, Usama Arif <usama.arif@...edance.com>
Subject: [PATCH 5/5] io_uring: add link opcode for current working directory
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_LINKAT.
Signed-off-by: Usama Arif <usama.arif@...edance.com>
---
fs/io_uring.c | 29 ++++++++++++++++++++---------
include/uapi/linux/io_uring.h | 1 +
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 4050377619d3..31dfad3a7312 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1314,6 +1314,7 @@ static const struct io_op_def io_op_defs[] = {
[IORING_OP_MKDIRAT] = {},
[IORING_OP_SYMLINK] = {},
[IORING_OP_SYMLINKAT] = {},
+ [IORING_OP_LINK] = {},
[IORING_OP_LINKAT] = {},
[IORING_OP_MSG_RING] = {
.needs_file = 1,
@@ -1469,6 +1470,8 @@ const char *io_uring_get_opcode(u8 opcode)
return "SYMLINK";
case IORING_OP_SYMLINKAT:
return "SYMLINKAT";
+ case IORING_OP_LINK:
+ return "LINK";
case IORING_OP_LINKAT:
return "LINKAT";
case IORING_OP_MSG_RING:
@@ -4991,8 +4994,8 @@ static int io_symlink(struct io_kiocb *req, unsigned int issue_flags)
return 0;
}
-static int io_linkat_prep(struct io_kiocb *req,
- const struct io_uring_sqe *sqe)
+static int io_link_prep(struct io_kiocb *req,
+ const struct io_uring_sqe *sqe, bool is_cwd)
{
struct io_hardlink *lnk = &req->hardlink;
const char __user *oldf, *newf;
@@ -5002,8 +5005,12 @@ static int io_linkat_prep(struct io_kiocb *req,
if (unlikely(req->flags & REQ_F_FIXED_FILE))
return -EBADF;
- lnk->old_dfd = READ_ONCE(sqe->fd);
- lnk->new_dfd = READ_ONCE(sqe->len);
+ if (is_cwd) {
+ lnk->old_dfd = lnk->new_dfd = AT_FDCWD;
+ } else {
+ lnk->old_dfd = READ_ONCE(sqe->fd);
+ lnk->new_dfd = READ_ONCE(sqe->len);
+ }
oldf = u64_to_user_ptr(READ_ONCE(sqe->addr));
newf = u64_to_user_ptr(READ_ONCE(sqe->addr2));
lnk->flags = READ_ONCE(sqe->hardlink_flags);
@@ -5022,7 +5029,7 @@ static int io_linkat_prep(struct io_kiocb *req,
return 0;
}
-static int io_linkat(struct io_kiocb *req, unsigned int issue_flags)
+static int io_link(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_hardlink *lnk = &req->hardlink;
int ret;
@@ -8117,8 +8124,10 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return io_symlink_prep(req, sqe, 1);
case IORING_OP_SYMLINKAT:
return io_symlink_prep(req, sqe, 0);
+ case IORING_OP_LINK:
+ return io_link_prep(req, sqe, 1);
case IORING_OP_LINKAT:
- return io_linkat_prep(req, sqe);
+ return io_link_prep(req, sqe, 0);
case IORING_OP_MSG_RING:
return io_msg_ring_prep(req, sqe);
case IORING_OP_FSETXATTR:
@@ -8280,6 +8289,7 @@ static void io_clean_op(struct io_kiocb *req)
putname(req->symlink.oldpath);
putname(req->symlink.newpath);
break;
+ case IORING_OP_LINK:
case IORING_OP_LINKAT:
putname(req->hardlink.oldpath);
putname(req->hardlink.newpath);
@@ -8442,14 +8452,15 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
break;
case IORING_OP_MKDIR:
case IORING_OP_MKDIRAT:
- ret = io_mkdirat(req, issue_flags);
+ ret = io_mkdir(req, issue_flags);
break;
case IORING_OP_SYMLINK:
case IORING_OP_SYMLINKAT:
- ret = io_symlinkat(req, issue_flags);
+ ret = io_symlink(req, issue_flags);
break;
+ case IORING_OP_LINK:
case IORING_OP_LINKAT:
- ret = io_linkat(req, issue_flags);
+ ret = io_link(req, issue_flags);
break;
case IORING_OP_MSG_RING:
ret = io_msg_ring(req, issue_flags);
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 74e6b70638ee..41391a762ad1 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -193,6 +193,7 @@ enum io_uring_op {
IORING_OP_UNLINK,
IORING_OP_MKDIR,
IORING_OP_SYMLINK,
+ IORING_OP_LINK,
/* this goes last, obviously */
IORING_OP_LAST,
--
2.25.1
Powered by blists - more mailing lists