Re: [PATCH v5 02/10] io_uring: add support for IORING_OP_MKDIRAT
From: Pavel Begunkov <asml.silence@gmail.com>
Date: 2021-06-22 11:50:33
Also in:
linux-fsdevel
On 6/22/21 12:41 PM, Pavel Begunkov wrote:
On 6/3/21 6:18 AM, Dmitry Kadashev wrote:quoted
IORING_OP_MKDIRAT behaves like mkdirat(2) and takes the same flags and arguments. Signed-off-by: Dmitry Kadashev <redacted> --- fs/io_uring.c | 55 +++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 1 + 2 files changed, 56 insertions(+)diff --git a/fs/io_uring.c b/fs/io_uring.c index a1ca6badff36..8ab4eb559520 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c@@ -665,6 +665,13 @@ struct io_unlink { struct filename *filename; }; +struct io_mkdir { + struct file *file; + int dfd; + umode_t mode; + struct filename *filename; +}; + struct io_completion { struct file *file; struct list_head list;@@ -809,6 +816,7 @@ struct io_kiocb { struct io_shutdown shutdown; struct io_rename rename; struct io_unlink unlink; + struct io_mkdir mkdir; /* use only after cleaning per-op data, see io_clean_op() */ struct io_completion compl; };@@ -1021,6 +1029,7 @@ static const struct io_op_def io_op_defs[] = { }, [IORING_OP_RENAMEAT] = {}, [IORING_OP_UNLINKAT] = {}, + [IORING_OP_MKDIRAT] = {}, }; static bool io_disarm_next(struct io_kiocb *req);@@ -3530,6 +3539,44 @@ static int io_unlinkat(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) +{ + struct io_mkdir *mkd = &req->mkdir; + const char __user *fname; + + if (unlikely(req->flags & REQ_F_FIXED_FILE)) + return -EBADF; + + mkd->dfd = READ_ONCE(sqe->fd); + mkd->mode = READ_ONCE(sqe->len); + + fname = u64_to_user_ptr(READ_ONCE(sqe->addr)); + mkd->filename = getname(fname); + if (IS_ERR(mkd->filename)) + return PTR_ERR(mkd->filename);We have to check unused fields, e.g. buf_index and off, to be able to use them in the future if needed. if (sqe->buf_index || sqe->off) return -EINVAL; Please double check what fields are not used, and same goes for all other opcodes.
+ opcode specific flags, e.g. if (sqe->rw_flags) return -EINVAL; -- Pavel Begunkov