From patchwork Tue Mar 30 05:59:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12171693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4C19C433E0 for ; Tue, 30 Mar 2021 06:01:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7ED77619A9 for ; Tue, 30 Mar 2021 06:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230306AbhC3GBR (ORCPT ); Tue, 30 Mar 2021 02:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbhC3GAp (ORCPT ); Tue, 30 Mar 2021 02:00:45 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE4E9C061762; Mon, 29 Mar 2021 23:00:44 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id v15so21972852lfq.5; Mon, 29 Mar 2021 23:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JwROeegWkdODKVv6qZWwI8EA184sTShpBe/vCXlorak=; b=UJxvvBqz5bl8G7NT6kKSOQDKLyXmtJbjqyJlobuZhqjr8z5zgO2SICPXO8P96LnKA2 8BkdKF/oPoayORmPLS3sptL4cxWeRXMMHxy+/E/QMV7GT2Tcz3YEyXctTy1abtHaN7HY abrg2E+wjtg+AzJgyU98zF2BnSwANn+yJMmWQUJWYmE7dqj0WqqXp0W7zfEdi3eDBuVW xwZOf9lCGlKc/F2eHUcKzSYiQfvgkSl/btjfEwZcXR2d0oJBHINQD31WedOswdoWgHN7 DbIU1rk23Hmre529UGODIRslprL9x1kvYYHRNZyVJc5aBn5fWLeGqc/mb798nSgu9ioY X0cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JwROeegWkdODKVv6qZWwI8EA184sTShpBe/vCXlorak=; b=d6X0Td6hrt2BlyQHuVOSfmospYDgI9f9L9i/SKp1ut1MVzHUkT2JtmGMjV6MmNsh0I TxPO5yji+OawslkuNoU3LAEM3m4MpooqS1gK+jaY7E4+K1MvDInl4gDgjsTG/u977CRx IDPD67vIqkJJKE54ZM2GYq7UFHUa3o+vgW2wHF8rOox1N7Z4h2x2O7lot6Iapvrpc07I aviUHgUKB/uCH7arMCdp/yymhTtTNnMJH7h0v8j0UkjuFJXfQf641y3VeqIlhm1qG7rS 0BsXsDOnRdE9Ra7igWuIeLQmTvb5/0hm4nW3Xyn9CZ/pgpsiv4YQ6kJJrxyPb4IZy3uo VI/A== X-Gm-Message-State: AOAM532Ey6C5E1Pb59k2T8JXGJKetBHB4MW/WBKIXmdZp/2RpUX9JsiR 90ZPekC5Dl9oAneyqVxHDb8= X-Google-Smtp-Source: ABdhPJx2Xmi12CPyHphDdORgzz5equIfy63s9f/Y8Est4G6m+K2dmdr9BT2GXwktbdb4f5zdPHUe9g== X-Received: by 2002:ac2:5fa2:: with SMTP id s2mr18478955lfe.486.1617084043413; Mon, 29 Mar 2021 23:00:43 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id e6sm2050089lfj.96.2021.03.29.23.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 23:00:43 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v3 1/2] fs: make do_mkdirat() take struct filename Date: Tue, 30 Mar 2021 12:59:56 +0700 Message-Id: <20210330055957.3684579-2-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330055957.3684579-1-dkadashev@gmail.com> References: <20210330055957.3684579-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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(). Cc: Al Viro Signed-off-by: Dmitry Kadashev Signed-off-by: Christian Brauner --- fs/internal.h | 1 + fs/namei.c | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 6aeae7ef3380..848e165ef0f1 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -77,6 +77,7 @@ long do_unlinkat(int dfd, struct filename *name); int may_linkat(struct user_namespace *mnt_userns, 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 diff --git a/fs/namei.c b/fs/namei.c index 216f16e74351..bfdc3128bf8d 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3560,7 +3560,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, return file; } -static struct dentry *filename_create(int dfd, struct filename *name, +static struct dentry *__filename_create(int dfd, struct filename *name, struct path *path, unsigned int lookup_flags) { struct dentry *dentry = ERR_PTR(-EEXIST); @@ -3616,7 +3616,6 @@ static struct dentry *filename_create(int dfd, struct filename *name, error = err2; goto fail; } - putname(name); return dentry; fail: dput(dentry); @@ -3631,6 +3630,16 @@ static struct dentry *filename_create(int dfd, struct filename *name, return dentry; } +static inline struct dentry *filename_create(int dfd, struct filename *name, + struct path *path, unsigned int lookup_flags) +{ + struct dentry *res = __filename_create(dfd, name, path, lookup_flags); + + if (!IS_ERR(res)) + putname(name); + return res; +} + struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path, unsigned int lookup_flags) { @@ -3821,15 +3830,18 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, } 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); + dentry = __filename_create(dfd, name, &path, lookup_flags); if (IS_ERR(dentry)) return PTR_ERR(dentry); @@ -3847,17 +3859,18 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) lookup_flags |= LOOKUP_REVAL; goto retry; } + 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); } /** From patchwork Tue Mar 30 05:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12171691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C92DC433C1 for ; Tue, 30 Mar 2021 06:01:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 449BD6198F for ; Tue, 30 Mar 2021 06:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230302AbhC3GBV (ORCPT ); Tue, 30 Mar 2021 02:01:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbhC3GAw (ORCPT ); Tue, 30 Mar 2021 02:00:52 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1F1C061762; Mon, 29 Mar 2021 23:00:51 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id d12so899782lfv.11; Mon, 29 Mar 2021 23:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yLK0swGoAGAfWrFvdyaIBTEbLse0KE0XBAgDjxBZppA=; b=R6fnDhi+6UM/fZamHcltmjBIsqP4pdQZZvnHqGxOdKjSr9yZ95gmjWbsV01YocnSrv HWC/BoY2ZygLo3tfcObOL9vrJFuw+f/gYmjVCPu0t2Zu2nB5VfeNBnJeD3FzcOxjoUuv 4+KilRtXvS0CWd5mmZDrNkHx+hD3E9A7Ptj52JAX40ITwdgPWkRcyolfsq8IOFIupfTS ork+/dkIjJew2duvaWUJeo+wHnWzwdGFaVoxK7+Ez6ZnNd48VVczQnZx1FS2TdNSRY5h n/nOwBmg1W129DRdd8C+ZXL5k4tnf8ggOVnbdHactNqeEBMe2+gskSbklAjsnE0O4so7 E0Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yLK0swGoAGAfWrFvdyaIBTEbLse0KE0XBAgDjxBZppA=; b=nD52O5I4joeeo4RIYlZwmVJea3Ph1xf0LRDWck6zTVawBpIPbDpQWijSxQhUGlx/go x50sWnoze0+ltbcIDnXqLVrvksdpPrjoO76yrJ6bpI1qY0iDigrqlVfAP+F0AmoJVhTv aiqCsS6R+Fv+95CJqIdpm6+RVwklIJryi40B9HiXSNsmqSBgE3N29yVHtlXpNi7Jip2J Sk0T8cQ38yH3+yIr6tZJEzULKqYrfNfiXjAo39YRDsZGAN7BZuxJpIuTjod4yPfaCFCN qrT2W6Eo1ECIwx+dpIaKfQmsCEqnJVQWaKKM8vv3RQiMXOBj/68TptXudBXGPjiT2jPf fsSQ== X-Gm-Message-State: AOAM531g/AoJjvq6E2HLufFBjEf0Gdu2PqcG4QQDj8BY/2m73PIk4Kl0 pJv++aMVrJfWt+0Wm9DXt3A= X-Google-Smtp-Source: ABdhPJwcosGN8xcjtwRUGS7nQZAXNXFXE2RbGvwntJ8stZj1d7Vq+Aqkc31vPdAYoKfo2ZvtQPMYYw== X-Received: by 2002:a05:6512:6cd:: with SMTP id u13mr18737993lff.326.1617084050511; Mon, 29 Mar 2021 23:00:50 -0700 (PDT) Received: from carbon.v ([94.143.149.146]) by smtp.googlemail.com with ESMTPSA id e6sm2050089lfj.96.2021.03.29.23.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 23:00:50 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro Cc: Pavel Begunkov , linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v3 2/2] io_uring: add support for IORING_OP_MKDIRAT Date: Tue, 30 Mar 2021 12:59:57 +0700 Message-Id: <20210330055957.3684579-3-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330055957.3684579-1-dkadashev@gmail.com> References: <20210330055957.3684579-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org IORING_OP_MKDIRAT behaves like mkdirat(2) and takes the same flags and arguments. Signed-off-by: Dmitry Kadashev --- 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 9a1a02fb3c9a..d9c100ed6132 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -663,6 +663,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; @@ -803,6 +810,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; }; @@ -1016,6 +1024,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); @@ -3523,6 +3532,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); + + req->flags |= REQ_F_NEED_CLEANUP; + return 0; +} + +static int io_mkdirat(struct io_kiocb *req, int issue_flags) +{ + struct io_mkdir *mkd = &req->mkdir; + int ret; + + if (issue_flags & IO_URING_F_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) { @@ -5942,6 +5989,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", @@ -6083,6 +6132,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; } @@ -6198,6 +6250,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags) case IORING_OP_UNLINKAT: ret = io_unlinkat(req, issue_flags); break; + case IORING_OP_MKDIRAT: + ret = io_mkdirat(req, issue_flags); + break; default: ret = -EINVAL; break; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 5beaa6bbc6db..cf26a94ab880 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -137,6 +137,7 @@ enum { IORING_OP_SHUTDOWN, IORING_OP_RENAMEAT, IORING_OP_UNLINKAT, + IORING_OP_MKDIRAT, /* this goes last, obviously */ IORING_OP_LAST,