io_uring: add mkdirat support
cover io_uring: add mkdirat support
This adds mkdirat support to io_uring and is heavily based on recently added renameat() / unlinkat() support.
The first patch is preparation with no functional changes, makes do_mkdirat accept struct filename pointer rather than the user string.
The second one leverages that to implement mkdirat in io_uring.
Based on for-5.11/io_uring.
Dmitry Kadashev (2):
fs: make do_mkdirat() take struct filename
io_uring: add support for IORING_OP_MKDIRAT
fs/internal.h | 1 + fs/io_uring.c | 58 +++++++++++++++++++++++++++++++++++ fs/namei.c | 20 ++++++++---- include/uapi/linux/io_uring.h | 1 + 4 files changed, 74 insertions(+), 6 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/2 fs: make do_mkdirat() take struct filename
Pass in the struct filename pointers instead of the user string, and update the three callers to do the same. This is heavily based on commit dbea8d345177 ("fs: make do_renameat2() take struct filename").
This behaves like do_unlinkat() and do_renameat2().
--- fs/internal.h | 1 + fs/namei.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)
fs/internal.h +1 -0
@@ -80,6 +80,7 @@ long do_unlinkat(int dfd, struct filename *name);int may_linkat (struct path *link);int do_renameat2 (int olddfd,struct filename *oldname,int newdfd,struct filename *newname,unsigned int flags); +long do_mkdirat (int dfd,struct filename *name,umode_t mode);/* * namespace.c
fs/namei.c +14 -6
@@ -3654,17 +3654,23 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) }EXPORT_SYMBOL (vfs_mkdir); -static long do_mkdirat (int dfd,const char __user *pathname,umode_t mode) +long do_mkdirat (int dfd,struct filename *name,umode_t mode) {struct dentry *dentry;struct path path;int error;unsigned int lookup_flags =LOOKUP_DIRECTORY ; +if (IS_ERR (name)) +return PTR_ERR (name); + retry: - dentry =user_path_create (dfd, pathname, &path, lookup_flags); -if (IS_ERR (dentry)) -return PTR_ERR (dentry); + name->refcnt++;/* filename_create() drops our ref */ + dentry =filename_create (dfd, name, &path, lookup_flags); +if (IS_ERR (dentry)) { + error =PTR_ERR (dentry); + goto out; + }if (!IS_POSIXACL (path.dentry->d_inode)) mode &= ~current_umask ();
@@ -3676,17 +3682,19 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) lookup_flags |=LOOKUP_REVAL ; goto retry; } +out: +putname (name);return error; } SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode) { -return do_mkdirat (dfd, pathname, mode); +return do_mkdirat (dfd,getname (pathname), mode); } SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode) { -return do_mkdirat (AT_FDCWD , pathname, mode); +return do_mkdirat (AT_FDCWD ,getname (pathname), mode); }int vfs_rmdir (struct inode *dir,struct dentry *dentry)
Signature · 1 line
2.28.0
PATCH 2/2 io_uring: add support for IORING_OP_MKDIRAT
In reply to Dmitry KadashevIORING_OP_MKDIRAT behaves like mkdirat(2) and takes the same flags and arguments.
--- fs/io_uring.c | 58 +++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 1 + 2 files changed, 59 insertions(+)
fs/io_uring.c +58 -0
@@ -565,6 +565,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;
@@ -692,6 +699,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; };
@@ -979,6 +987,10 @@ static const struct io_op_def io_op_defs[] = { .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_FILES | IO_WQ_WORK_FS | IO_WQ_WORK_BLKCG, }, + [IORING_OP_MKDIRAT] = { + .work_flags =IO_WQ_WORK_MM |IO_WQ_WORK_FILES | + IO_WQ_WORK_FS | IO_WQ_WORK_BLKCG, + }, };enum io_mem_account {
@@ -3745,6 +3757,44 @@ static int io_unlinkat(struct io_kiocb *req, bool force_nonblock)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); + + req->flags |=REQ_F_NEED_CLEANUP ; +return 0 ; +} + +static int io_mkdirat (struct io_kiocb *req,bool force_nonblock) +{ +struct io_mkdir *mkd = &req->mkdir; +int ret; + +if (force_nonblock) +return -EAGAIN ; + + ret =do_mkdirat (mkd->dfd, mkd->filename, mkd->mode); + + req->flags &= ~REQ_F_NEED_CLEANUP ; +if (ret <0 ) +req_set_fail_links (req); +io_req_complete (req, ret); +return 0 ; +} +static int io_shutdown_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe) {
@@ -5956,6 +6006,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)return io_renameat_prep (req, sqe);case IORING_OP_UNLINKAT :return io_unlinkat_prep (req, sqe); +case IORING_OP_MKDIRAT : +return io_mkdirat_prep (req, sqe); } printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",
@@ -6099,6 +6151,9 @@ static void __io_clean_op(struct io_kiocb *req)case IORING_OP_UNLINKAT :putname (req->unlink.filename);break ; +case IORING_OP_MKDIRAT : +putname (req->mkdir.filename); +break ; } req->flags &= ~REQ_F_NEED_CLEANUP ; }
@@ -6214,6 +6269,9 @@ static int io_issue_sqe(struct io_kiocb *req, bool force_nonblock,case IORING_OP_UNLINKAT : ret =io_unlinkat (req, force_nonblock);break ; +case IORING_OP_MKDIRAT : + ret =io_mkdirat (req, force_nonblock); +break ;default : ret = -EINVAL ;break ;
include/uapi/linux/io_uring.h +1 -0
@@ -137,6 +137,7 @@ enum {IORING_OP_SHUTDOWN ,IORING_OP_RENAMEAT ,IORING_OP_UNLINKAT , +IORING_OP_MKDIRAT ,/* this goes last, obviously */ IORING_OP_LAST,
Signature · 1 line
2.28.0
Jens Axboe
maintainerQuoted 7 lines · Dmitry Kadashev
This adds mkdirat support to
io_uringand is heavily based on recently addedrenameat()/unlinkat()support.The first patch is preparation with no functional changes, makes
do_mkdirataccept struct filename pointer rather than the user string.The second one leverages that to implement mkdirat in
io_uring.
Looks good to me - you should send the first patch to linux-fsdevel (and CC Al Viro), really needs to be acked on that side before it can go in.
Also, have you written some test cases?
Signature · 1 line
Jens Axboe
Quoted 11 lines · Jens Axboe
Quoted 7 lines · Dmitry Kadashev
This adds mkdirat support to
io_uringand is heavily based on recently addedrenameat()/unlinkat()support.The first patch is preparation with no functional changes, makes
do_mkdirataccept struct filename pointer rather than the user string.The second one leverages that to implement mkdirat in
io_uring.Looks good to me - you should send the first patch to linux-fsdevel (and CC Al Viro), really needs to be acked on that side before it can go in.
I'll resend the whole series with Al Viro and linux-fsdevel CCed, hope that is OK, gives them a bit more context and they can ignore the io_uring part. Hope that is OK.
Quoted 1 line
Also, have you written some test cases?
Yes, as part of liburing change - I'll send that shortly.
Signature · 1 line
Dmitry Kadashev