From patchwork Thu Jul 15 10:45:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379809 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.8 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,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 34164C47E48 for ; Thu, 15 Jul 2021 10:45:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 194D0613BF for ; Thu, 15 Jul 2021 10:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241621AbhGOKsp (ORCPT ); Thu, 15 Jul 2021 06:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241613AbhGOKsn (ORCPT ); Thu, 15 Jul 2021 06:48:43 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5DF3C06175F; Thu, 15 Jul 2021 03:45:50 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id w14so7422215edc.8; Thu, 15 Jul 2021 03:45:50 -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=wzJqs9cxilHIENiONBLdLggc6lvi7ZWmcjeK3sDHhqk=; b=RcDFthTCV4TOFu9dTLpXXrh3Aaj+Y5OETVo0gIUNIODO9zllsuIlwp5Izkv4gOY+w0 c5h8cRD2Rfb6a+Jb7KPmYU5Enzq/PHwk/Y8pSv9AV6wQ30cfFcDbJWmgl154LYmPAIC8 IqNfLci7CfY5VyMBEUCpEaj5ttroop0gJgKUhjJUscrYR27bccG0FvDPNMD5PyX/HTlB dZqVLDan0ie8F6J5f52nrfGOH/rZEqq3prjadIe5elrX/8LTydJWhn6yg5nX61G1fELQ etftdIi+/KgtTRegtZ0QvB7xJdhRT3EvTalqkOt/25/Q3AuemEHyaDH4dJ8Qml/Wo7Af xaDw== 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=wzJqs9cxilHIENiONBLdLggc6lvi7ZWmcjeK3sDHhqk=; b=MB4j9vCNsYz/WIaGAYSQ5OgZ39YmC7QrDQm3dnaAyXvyiiiSZCG0/nq+PxNZI9REc+ uN0typJYn+dJ5GKr8Sd/TeJ4B9fEb3BofTk86wuGXBTW2h88BcJqoKcNodMn5of0JX5k zgJMg8xbiDzJN3ZSFLHhs47A6xxRH3cNl0IkpKwmctng3ou0A4hzN892tDWJ5pTBCWRF ofFRXfHZ4hEsKKcaEVdPxmrxP8L6A0QoXL7E96S46JKtQtiSohtpL337/nmarvMdkXCX CvLFFOcsze3RTwkRY8g7bnvbZXhCXSzvjq3FJFEwVzTLVxo8bkKjPVHLShjqcyRQW6Re 5Vjg== X-Gm-Message-State: AOAM533SpcPwI4Nm9zsQAHnevEo6PgnxApqw1H5pLVqBanVSrJvAR+TA 1dF4U8kJ+Yfsm0RS6wqStug= X-Google-Smtp-Source: ABdhPJwmAiAbqn3u8vr8Sz9H6rXDZFMqwEfbYn0VNLTkpSDweMhNdTYge9znG1S0jAI32p7f7pXrQQ== X-Received: by 2002:a05:6402:3192:: with SMTP id di18mr6180049edb.186.1626345949424; Thu, 15 Jul 2021 03:45:49 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:49 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 01/14] namei: prepare do_rmdir for refactoring Date: Thu, 15 Jul 2021 17:45:23 +0700 Message-Id: <20210715104536.3598130-2-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is just a preparation for the move of the main rmdir logic to a separate function to make the logic easier to follow. This change contains the flow changes so that the actual change to move the main logic to a separate function does no change the flow at all. Two changes here: 1. Previously on filename_parentat() error the function used to exit immediately, and now it will check the return code to see if ESTALE retry is appropriate. The filename_parentat() does its own retries on ESTALE, but this extra check should be completely fine. 2. The retry_estale() check is wrapped in unlikely(). Some other places already have that and overall it seems to make sense. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wh=cpt_tQCirzFZRPawRpbuFTZ2MxNpXiyUF+eBXF=+sw@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=wjFd0qn6asio=zg7zUTRmSty_TpAEhnwym1Qb=wFgCKzA@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index b5adfd4f7de6..99d5c3a4c12e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3998,11 +3998,11 @@ int do_rmdir(int dfd, struct filename *name) mnt_drop_write(path.mnt); exit2: path_put(&path); - if (retry_estale(error, lookup_flags)) { +exit1: + if (unlikely(retry_estale(error, lookup_flags))) { lookup_flags |= LOOKUP_REVAL; goto retry; } -exit1: putname(name); return error; } From patchwork Thu Jul 15 10:45:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379811 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.8 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,USER_AGENT_GIT autolearn=ham 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 AB540C47E4B for ; Thu, 15 Jul 2021 10:45:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92F4961380 for ; Thu, 15 Jul 2021 10:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241624AbhGOKsp (ORCPT ); Thu, 15 Jul 2021 06:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241620AbhGOKsp (ORCPT ); Thu, 15 Jul 2021 06:48:45 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F8EC06175F; Thu, 15 Jul 2021 03:45:52 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id dp20so6617082ejc.7; Thu, 15 Jul 2021 03:45:52 -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=uvty18VOG05/H+n1wBlbsuIYvE4GDjObXZQJFvjmwnM=; b=t5R2wX95ccmsCYEPK1M0YCInfJsTdVzvCx9PztOYvvr/8/DNfzFfavqq1dWyYUWt7J i1zgVvGRvasP7Pys7nz0DUfMn1UdK36FzavewtScHiTRHh+FQ1bOG7oAQRiFNAUGHUya zVcjmca3yuUxD6gokF87KQWtRTrCnsaqdMeQ2hGitErv05S1qYptJ+co+w+zBCZtP1UJ AmKpvGQiNPVzHKIW3yeVDxgISqBVY7iARUrffM2jAHWLVQ8TPlZywfO73zOuLphWEXKZ zzMYGhC1PYgb5Zx+2aHUAmZuBkkQlYOqTMWvDNzwK5iqjw9S0cuxtXadlMms/jPz8vB2 ksNA== 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=uvty18VOG05/H+n1wBlbsuIYvE4GDjObXZQJFvjmwnM=; b=B0RRLQmGxsNSDkxdwqANxlAnKaU3HhN1MVEkCIP0JiEmwaf8oX0je6LYS8/jtagjzh I3AsDJR+3IH9Qe9PMF416/9UlRNLntY04ys8mYJTNUBRWWAuH8KjJitf9uevtBCuXuxL 1uxBHAx9xPhUp/PccXCsgh8k9ErdQvNJdSlbBoUN4tM/qVYfQ9mA3oHh2NiovG/b3S3a TJe1rY0WCbOLcXSXzRoi3Gcv5mXKWjmcmY2WRHfe2kyWoClbQ2gchbpAo2qrPxTACEOJ HfamxfpGDn+3BGhER/SWpE+PlRmaKZz6mHHVigTNnk+AKpyQ+e0PeLrIfDd8z/bmyZ8/ QA7Q== X-Gm-Message-State: AOAM532slkub8+O9umFXZTf/02Rx1uZmAr1isIrGg1ugvCSgrwZUwZQW wjSAlmBO7mXzC1OJaCNvs4E= X-Google-Smtp-Source: ABdhPJzC54kam/0M33gVI+97K1sgLFv+EbTgVv2DP5zscNB1EVSgXbOEeQmME5Z5S1qGBYbQ178zxA== X-Received: by 2002:a17:906:616:: with SMTP id s22mr4833879ejb.210.1626345950944; Thu, 15 Jul 2021 03:45:50 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:50 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 02/14] namei: clean up do_rmdir retry logic Date: Thu, 15 Jul 2021 17:45:24 +0700 Message-Id: <20210715104536.3598130-3-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No functional changes, just move the main logic to a helper function to make the whole thing easier to follow. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wh=cpt_tQCirzFZRPawRpbuFTZ2MxNpXiyUF+eBXF=+sw@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 99d5c3a4c12e..fbae4e9fcf53 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3947,7 +3947,7 @@ int vfs_rmdir(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_rmdir); -int do_rmdir(int dfd, struct filename *name) +static int try_rmdir(int dfd, struct filename *name, unsigned int lookup_flags) { struct user_namespace *mnt_userns; int error; @@ -3955,54 +3955,60 @@ int do_rmdir(int dfd, struct filename *name) struct path path; struct qstr last; int type; - unsigned int lookup_flags = 0; -retry: + error = __filename_parentat(dfd, name, lookup_flags, &path, &last, &type); if (error) - goto exit1; + return error; switch (type) { case LAST_DOTDOT: error = -ENOTEMPTY; - goto exit2; + goto exit1; case LAST_DOT: error = -EINVAL; - goto exit2; + goto exit1; case LAST_ROOT: error = -EBUSY; - goto exit2; + goto exit1; } error = mnt_want_write(path.mnt); if (error) - goto exit2; + goto exit1; inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT); dentry = __lookup_hash(&last, path.dentry, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto exit3; + goto exit2; if (!dentry->d_inode) { error = -ENOENT; - goto exit4; + goto exit3; } error = security_path_rmdir(&path, dentry); if (error) - goto exit4; + goto exit3; mnt_userns = mnt_user_ns(path.mnt); error = vfs_rmdir(mnt_userns, path.dentry->d_inode, dentry); -exit4: - dput(dentry); exit3: + dput(dentry); +exit2: inode_unlock(path.dentry->d_inode); mnt_drop_write(path.mnt); -exit2: - path_put(&path); exit1: - if (unlikely(retry_estale(error, lookup_flags))) { - lookup_flags |= LOOKUP_REVAL; - goto retry; - } + path_put(&path); + + return error; +} + +int do_rmdir(int dfd, struct filename *name) +{ + int error; + + error = try_rmdir(dfd, name, 0); + if (unlikely(retry_estale(error, 0))) + error = try_rmdir(dfd, name, LOOKUP_REVAL); + putname(name); return error; } From patchwork Thu Jul 15 10:45:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379813 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.8 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,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 1834BC07E96 for ; Thu, 15 Jul 2021 10:45:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F217C61380 for ; Thu, 15 Jul 2021 10:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241625AbhGOKsr (ORCPT ); Thu, 15 Jul 2021 06:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241620AbhGOKsr (ORCPT ); Thu, 15 Jul 2021 06:48:47 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8929C061760; Thu, 15 Jul 2021 03:45:53 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id dp20so6617161ejc.7; Thu, 15 Jul 2021 03:45:53 -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=Gv8tSwp/UrSv6bP9FmaW3UOv2WYkCE+hVRpziUUM44U=; b=VOFZabhX6UGXXHGitS4GHVJ9g5fm+VVzw7fJhpTIagio6lea/PD0JUkjCHyoSCKZtz khXQRT1JyOa4dVhB1kMzF3BEKuyO74n/NHvKz8GI8V2QtUcddEQl+/z8yxHhovyTNnQb G6Rhs3ViqxNkJSKxKcTBBwDuav/uzabneUE21TespT1x76Urwp2TyX+Ar8w4/eIxNx7C d5eoFY8WgHmvM607K1jgqbIT0mNeiKTLkSuCpcNisJlwWYk4P0ua9t5vvl5pxwyELXEj 3CwbkGI3+E+i3SbTnahtThfqvFOLHLnVRGZQFkYl1RWrz/B86+QtlIJDncvFNz53dPwN rQIA== 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=Gv8tSwp/UrSv6bP9FmaW3UOv2WYkCE+hVRpziUUM44U=; b=rzKZ3yxoZS6zSJCpySEDtWlTOFjUZq1MvN+xMgpasqpFgojajHwik/ovWZMZNaaXd1 JoafIj0A3exwe18B2LuTy0ywibnDm6d/TDIWAV1xVDrKJBNvC9vyuxpW4BNUoPqaP6HD P8/6szyHStTEJLNGWEQ5DaAlQ4p2fdx658pQowP6BukfAoWO85eBTHyZe98li/x931Tt pCimSrtGyfonemXLlJa0nRGvbW0cgHZNEjTB6ZyAEm2zOUrJWvYVPZiFHcBn6vDJ9Xzq FAGTpcMuLvjNXIl9eRcCgE0fMk+vsY9/IDtvwqh+qkS5zadZVqK3YF3KdxlQdbiElKc4 KWGw== X-Gm-Message-State: AOAM5307oNiB/m4hG7MHpKUNmwQtONg+BNabkKFM8MC/yo6r4HkvtKS0 7YnlJ6qv0pAzC7pvVSHw0FsxI7eAwvBBwoIU X-Google-Smtp-Source: ABdhPJwd4P2A7ar44tXH7NKXjhhAVKfwLe0/e4KnnyfNo5tMfOTme7BI5lXssN9FWMwbpJ7r84aqTg== X-Received: by 2002:a17:906:3acb:: with SMTP id z11mr4968721ejd.0.1626345952458; Thu, 15 Jul 2021 03:45:52 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:52 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 03/14] namei: prepare do_unlinkat for refactoring Date: Thu, 15 Jul 2021 17:45:25 +0700 Message-Id: <20210715104536.3598130-4-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is just a preparation for the move of the main unlinkat logic to a separate function to make the logic easier to follow. This change contains the flow changes so that the actual change to move the main logic to a separate function does no change the flow at all. Just like the similar patch for rmdir a few commits before, there are two changes here: 1. Previously on filename_parentat() error the function used to exit immediately, and now it will check the return code to see if ESTALE retry is appropriate. The filename_parentat() does its own retries on ESTALE, but this extra check should be completely fine. 2. The retry_estale() check is wrapped in unlikely(). Some other places already have that and overall it seems to make sense. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wh=cpt_tQCirzFZRPawRpbuFTZ2MxNpXiyUF+eBXF=+sw@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=wjFd0qn6asio=zg7zUTRmSty_TpAEhnwym1Qb=wFgCKzA@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index fbae4e9fcf53..6253486718d5 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4148,12 +4148,12 @@ int do_unlinkat(int dfd, struct filename *name) mnt_drop_write(path.mnt); exit2: path_put(&path); - if (retry_estale(error, lookup_flags)) { +exit1: + if (unlikely(retry_estale(error, lookup_flags))) { lookup_flags |= LOOKUP_REVAL; inode = NULL; goto retry; } -exit1: putname(name); return error; From patchwork Thu Jul 15 10:45:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379815 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.8 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,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 06020C47E48 for ; Thu, 15 Jul 2021 10:45:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6E66613BC for ; Thu, 15 Jul 2021 10:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241631AbhGOKst (ORCPT ); Thu, 15 Jul 2021 06:48:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241620AbhGOKss (ORCPT ); Thu, 15 Jul 2021 06:48:48 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41EDBC06175F; Thu, 15 Jul 2021 03:45:55 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id c17so8466993ejk.13; Thu, 15 Jul 2021 03:45:55 -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=rr2ogX0F2b70BRK2G5XV9Y3jelCgb4ODEp6gY/X8CXA=; b=VUrcUNoojJdJfReNxHKdn1+Fy0YF4oc734QwFt5MzD2lo4SBZwBLHajYzAkxUNRrUa ZmzAP4hWrW0fFlSXneWaea+Z/IEsMoh2G9uEg6zvZjyIurSrbNy5GL6zQ2PTW0a563Jx 5bDa4AW9jZ88Kv82Ns7Duq82YLLAIkpesvCgPNlaF6mxYa8N8eerQaXuz4FnlAv6zZYx twqHbp7AxNep0xmr1VJcr9f4wn07qIzpSV1O18LOX63S+tKadiXoF4IfPk9lbHN8347j 4zTzIipY6CJDJw6aj3PpGK5iWuVaoZ3RXPn8mSPFv1EjiqwSadBzUoGeM9VHPG4rME3f 23WQ== 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=rr2ogX0F2b70BRK2G5XV9Y3jelCgb4ODEp6gY/X8CXA=; b=O5pebVqvEVqnTfG6G4yEFTjjzRhK4Sf3T98JYQemgaQnFPjNZEZMljgHg9V2OURdzU /0PT7mjxSlyv8XskJQLtNFF14guT2XRjP6vG+G/jEJxtRDTTwVaYqsnySEiY1pA7Kvnl kX1orsZjHvnDMZfUs47+fLx1y7UWPFqvuk8JKWhGFzXdmQ8JdvkHOfPLnGtCsBRAvu+/ keTXimBIBrqzzyqIMTw+7VGI4Nghgiyodfuc+qU7ihlbz3IJteJPrELlbSbZ1MwxbCeO AZ2iMGOqBt4O8ixZXotEk/elDrgYlb52K9RpewQ2oh73hwtnXa9GUHtKBT4Fn0Lq1HCf PWDg== X-Gm-Message-State: AOAM532RKZ62WWI3z/BpoOLE+0o9k1SszHuRELQJul4Zv36w1tJNLaum 9WDD+T5B2nXi69nRzB+9FVA= X-Google-Smtp-Source: ABdhPJypD0CKHsYzl4fyP2SF/zakWlrPZeMyq8KPeQdtkZGM5hwxwc+oFf0myGgkx78Az26nMGOZww== X-Received: by 2002:a17:906:1299:: with SMTP id k25mr4779177ejb.139.1626345953924; Thu, 15 Jul 2021 03:45:53 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:53 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 04/14] namei: clean up do_unlinkat retry logic Date: Thu, 15 Jul 2021 17:45:26 +0700 Message-Id: <20210715104536.3598130-5-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No functional changes, just move the main logic to a helper function to make the whole thing easier to follow. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wh=cpt_tQCirzFZRPawRpbuFTZ2MxNpXiyUF+eBXF=+sw@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 6253486718d5..703cce40d597 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4091,7 +4091,9 @@ EXPORT_SYMBOL(vfs_unlink); * writeout happening, and we don't want to prevent access to the directory * while waiting on the I/O. */ -int do_unlinkat(int dfd, struct filename *name) + +static int try_unlinkat(int dfd, struct filename *name, + unsigned int lookup_flags) { int error; struct dentry *dentry; @@ -4100,19 +4102,18 @@ int do_unlinkat(int dfd, struct filename *name) int type; struct inode *inode = NULL; struct inode *delegated_inode = NULL; - unsigned int lookup_flags = 0; -retry: + error = __filename_parentat(dfd, name, lookup_flags, &path, &last, &type); if (error) - goto exit1; + return error; error = -EISDIR; if (type != LAST_NORM) - goto exit2; + goto exit1; error = mnt_want_write(path.mnt); if (error) - goto exit2; + goto exit1; retry_deleg: inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT); dentry = __lookup_hash(&last, path.dentry, lookup_flags); @@ -4129,11 +4130,11 @@ int do_unlinkat(int dfd, struct filename *name) ihold(inode); error = security_path_unlink(&path, dentry); if (error) - goto exit3; + goto exit2; mnt_userns = mnt_user_ns(path.mnt); error = vfs_unlink(mnt_userns, path.dentry->d_inode, dentry, &delegated_inode); -exit3: +exit2: dput(dentry); } inode_unlock(path.dentry->d_inode); @@ -4146,17 +4147,9 @@ int do_unlinkat(int dfd, struct filename *name) goto retry_deleg; } mnt_drop_write(path.mnt); -exit2: - path_put(&path); exit1: - if (unlikely(retry_estale(error, lookup_flags))) { - lookup_flags |= LOOKUP_REVAL; - inode = NULL; - goto retry; - } - putname(name); + path_put(&path); return error; - slashes: if (d_is_negative(dentry)) error = -ENOENT; @@ -4164,7 +4157,20 @@ int do_unlinkat(int dfd, struct filename *name) error = -EISDIR; else error = -ENOTDIR; - goto exit3; + goto exit2; +} + +int do_unlinkat(int dfd, struct filename *name) +{ + int error; + + error = try_unlinkat(dfd, name, 0); + if (unlikely(retry_estale(error, 0))) + error = try_unlinkat(dfd, name, LOOKUP_REVAL); + + putname(name); + return error; + } SYSCALL_DEFINE3(unlinkat, int, dfd, const char __user *, pathname, int, flag) From patchwork Thu Jul 15 10:45:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379817 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.8 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,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 DFE67C47E4B for ; Thu, 15 Jul 2021 10:45:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDCDF613BC for ; Thu, 15 Jul 2021 10:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241636AbhGOKsv (ORCPT ); Thu, 15 Jul 2021 06:48:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241632AbhGOKsu (ORCPT ); Thu, 15 Jul 2021 06:48:50 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8D1EC06175F; Thu, 15 Jul 2021 03:45:56 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id bu12so8609599ejb.0; Thu, 15 Jul 2021 03:45:56 -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=+MzqW1FGpWE2/HiJKOcK3CZTGi1+seN/N4XAEsKSZdc=; b=Ta4DYJlqXq9iplYXdZB3LW+xfWxJxbf+ojWnk4ZVrcXd84ag/Fbu/SPxbzZMYVdq9u m1B/bZSy1URZR/Ax6xErXeTy9AZvRa13Yk3Fe0bLFobm9YUoHdtk+0AGEw4MazaAUEil RDxuiqMdELlWptBeZ/UqpBJKYofq7dFE/fZCYOrnbEoRMcl47ziDGgWw6rBXQMTRym4f 1c+2XINzSaDHLaZCLG8t9nq71gpOBDMiK9S3vRkjVgUEfyEeJcNB1qcOaZFTxYe40XZM G6q58gk5t2qfA0srqQJ3qRT1C/Pd+T80OYFQovpVnBu9FFYl7dnssQApFfbRrAgO9fw0 BZkQ== 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=+MzqW1FGpWE2/HiJKOcK3CZTGi1+seN/N4XAEsKSZdc=; b=eWsaob43jO6jRDMEHjk1PRBTdvG+rvsWc/MbAzS2C4nnDT5+4yVMbXb0ZMUMQ+a/2u uqlLKgNBZbAmTD+D5QHXMnkSEGm48x8W636jQjJeCb5zIIdxOeEYT/0aXKDBI8HxwDx5 md3gN5qcXzSc56Mu8MkLe1MvD6KdoWiISy1QnXkaHBCPPFsDM980+OMINwqsrgPKVbHr H9poPbjcnTC0o3vvglYc03HLFY/0pX7hXR8dRL3UuEQRzQ+LmL2nHLRzkSL76x5SIsps PZjdePZDsuGJCBKZFddqxAVd/gXN4RLcOtBHM4cG4GcChSdmmpx9iHWO5k/0244x2Zgn DykA== X-Gm-Message-State: AOAM533ZBYBdr5gt+Sl4JkRF8V9wU+zwlgvW8wN4GTXfb5hCdmRW0FXZ /4T+6rjhquBcdTIibEmOFfQ= X-Google-Smtp-Source: ABdhPJwKAto5nuGVQO3oSTP04S00UvJ90twAOWO1Y4Yf99C85d1mqBznvk6XlmbXUvtcF70tSp35Pw== X-Received: by 2002:a17:906:c7d6:: with SMTP id dc22mr4882611ejb.517.1626345955384; Thu, 15 Jul 2021 03:45:55 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:55 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 05/14] namei: prepare do_mkdirat for refactoring Date: Thu, 15 Jul 2021 17:45:27 +0700 Message-Id: <20210715104536.3598130-6-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is just a preparation for the move of the main mkdirat logic to a separate function to make the logic easier to follow. This change contains the flow changes so that the actual change to move the main logic to a separate function does no change the flow at all. Just like the similar patches for rmdir and unlink a few commits before, there two changes here: 1. Previously on filename_create() error the function used to exit immediately, and now it will check the return code to see if ESTALE retry is appropriate. The filename_create() does its own retries on ESTALE (at least via filename_parentat() used inside), but this extra check should be completely fine. 2. The retry_estale() check is wrapped in unlikely(). Some other places already have that and overall it seems to make sense Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wijsw1QSsQHFu_6dEoZEr_zvT7++WJWohcuEkLqqXBGrQ@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=wjFd0qn6asio=zg7zUTRmSty_TpAEhnwym1Qb=wFgCKzA@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 703cce40d597..54dbd1e38298 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3861,7 +3861,7 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode) dentry = __filename_create(dfd, name, &path, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto out_putname; + goto out; if (!IS_POSIXACL(path.dentry->d_inode)) mode &= ~current_umask(); @@ -3873,11 +3873,11 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode) mode); } done_path_create(&path, dentry); - if (retry_estale(error, lookup_flags)) { +out: + if (unlikely(retry_estale(error, lookup_flags))) { lookup_flags |= LOOKUP_REVAL; goto retry; } -out_putname: putname(name); return error; } From patchwork Thu Jul 15 10:45:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379819 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.8 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,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 9D082C47E48 for ; Thu, 15 Jul 2021 10:45:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88B71613C1 for ; Thu, 15 Jul 2021 10:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241639AbhGOKsv (ORCPT ); Thu, 15 Jul 2021 06:48:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241633AbhGOKsv (ORCPT ); Thu, 15 Jul 2021 06:48:51 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37C64C06175F; Thu, 15 Jul 2021 03:45:58 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id c17so8467186ejk.13; Thu, 15 Jul 2021 03:45:58 -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=QloIpUWxseObgf+NMoNExWhUt5BhExzUbRQoNBg+DnM=; b=ZHHH0UjigMOKSgiXRKFqrPd+X49KS5O60/nQIizlXVAhX9ONwUdnEX8KkT4hrHBvrc +yhB059rNqvDt5QxwGybJogTCNStSBbdNCEEs9Fm8ThHO82OA+vVN1lMMPcxHVBb+T+c nGBF+6cHYTStsaVz/LSqbLtboL8AnWKG+smAU8xdu0VwmwnVrXo9WnMHn++uZqNKJ8aX avOazwQkniKeDX7+JvVjuXiH0q/zYORsKOcnMxXG1g7hgVkhOYQcJ9+glbaHNaBcnPdH te0z/pditlZRSO1kIyPQoQK6kx/uKP667VXDtvpHtuBk5blcvabO1ImJ0jlqI0Uu2pxY y7Ag== 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=QloIpUWxseObgf+NMoNExWhUt5BhExzUbRQoNBg+DnM=; b=Zfw7V4y/hl7grg2BgkK21EG7ginzmIyojOGaCgOvus/6AWRBBjlVhk/Imc1kTnd9d3 cQAS+arCrXxYj4C5QZ2ngR21fs7PLIppElekA8rhA3ABAJ6hLkWLZQPUUxPeyIEFxz/x thceVNB/vvSZK2ikKIPPs+GdHHADWTLPy/f6oFKqVWEZY/ttP9wwHmmEYwQpq0VslQyR UNzO8vaNIPlczV7oZ1SSh92QAH04FulBcoB+jtr+fkXS7SlZkwr+jf8Vw308IDl74Uo6 UN32BztlPRk1cRSM+Jklz44yfyxtm5iffI0Bb9I5rlTS8+Ug83XffAlvykQBQlOVRWQ+ 9QuQ== X-Gm-Message-State: AOAM530V7h2hNhde2AmJDbvQOLz1pctidIfLzDt8NO9Sfm8VbDG9JQwU VpoPj4xP6YptVW0UauY2pTM= X-Google-Smtp-Source: ABdhPJyaBwgiqcBK8AFphL8KlFhQW1d2aliH82g9zIeRRXDzMnVuqNuP12o1K3NJAdbqFHwUl5ITUw== X-Received: by 2002:a17:906:b6c5:: with SMTP id ec5mr4796651ejb.290.1626345956904; Thu, 15 Jul 2021 03:45:56 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:56 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 06/14] namei: clean up do_mkdirat retry logic Date: Thu, 15 Jul 2021 17:45:28 +0700 Message-Id: <20210715104536.3598130-7-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No functional changes, just move the main logic to a helper function to make the whole thing easier to follow. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wijsw1QSsQHFu_6dEoZEr_zvT7++WJWohcuEkLqqXBGrQ@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 54dbd1e38298..50ab1cd00983 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3850,18 +3850,16 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_mkdir); -int do_mkdirat(int dfd, struct filename *name, umode_t mode) +static int try_mkdirat(int dfd, struct filename *name, umode_t mode, + unsigned int lookup_flags) { struct dentry *dentry; struct path path; int error; - unsigned int lookup_flags = LOOKUP_DIRECTORY; -retry: dentry = __filename_create(dfd, name, &path, lookup_flags); - error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto out; + return PTR_ERR(dentry); if (!IS_POSIXACL(path.dentry->d_inode)) mode &= ~current_umask(); @@ -3873,11 +3871,18 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode) mode); } done_path_create(&path, dentry); -out: - if (unlikely(retry_estale(error, lookup_flags))) { - lookup_flags |= LOOKUP_REVAL; - goto retry; - } + + return error; +} + +int do_mkdirat(int dfd, struct filename *name, umode_t mode) +{ + int error; + + error = try_mkdirat(dfd, name, mode, 0); + if (unlikely(retry_estale(error, 0))) + error = try_mkdirat(dfd, name, mode, LOOKUP_REVAL); + putname(name); return error; } From patchwork Thu Jul 15 10:45:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379821 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.8 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,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 EE59EC47E4D for ; Thu, 15 Jul 2021 10:46:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DABB161380 for ; Thu, 15 Jul 2021 10:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241648AbhGOKsx (ORCPT ); Thu, 15 Jul 2021 06:48:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241632AbhGOKsx (ORCPT ); Thu, 15 Jul 2021 06:48:53 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD9A5C061760; Thu, 15 Jul 2021 03:45:59 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id hd33so8498291ejc.9; Thu, 15 Jul 2021 03:45:59 -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=SfC+DG3exxcIswvWTHcK8XQLBwJSVXknIHN8ZFcehb8=; b=c+o+LX1DFlAbZD+qqsWTz6DI42ihXnfV5hOU+zs8bqFce/oDkjJXstUrnJxTWvU/mk teOLEMNR6mVQhU8tWJRYBjUAtEp84oLewZHI5iDTSQsoTNQtYRZZTOBkLXSL6/iuDdY8 IVOuq+teu53DTt9N+z9KVLswaGeatCDWTctyfJL7lJLhPo/AOEk41XEV4g51XLu4W1JJ KDN9arB/x/3SZ9wqB/sVhxdKMPJsGRoJHEBtyjp+xQCZr5erZZUh9Tn1xSgTIBwbFXqo vks/KUNMh5Q3B3boLm7DUlZrosFgSbOxzNopc1tEDo/1k1HKMyrKtfKUR3p1yzjB7nZ/ 4kjw== 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=SfC+DG3exxcIswvWTHcK8XQLBwJSVXknIHN8ZFcehb8=; b=VnKGTFDkRQJWHRohfchlrgpssZwpBt4OBj0B7J9SqQxmO+Y7Kbeb9vcEYrXejpn/OX 1YTEs8m/Irmdi7aJUr5rRUnOVnZER7YMeqOqPHf9feOaBXIvdS4QFWi0MFBIJ41+FKI2 7IBEWKqHOyb256l91TcNugv0fyLSOdJXbci2iNZ+K93Ns0yGXlU0gZDROuevi5yv9qYK ApNxcHJ3/THW8nKw06Y7UnrOSPNfqtadJWIqUTWzRlSEHIDcqCGo3nWFS0I+xIa6iqWQ dcyjMateU+HhMXqQ4ccDGn932Dap3tGbEdD56oCWAME8GFXbakbD9rypvq7un2oM+e18 LcSw== X-Gm-Message-State: AOAM533OhfqBXu+8T0xFfCcrblwUn8ePx2jwERBUVHVs17v5pNtYjzav qhjcrbIaB237INOK+E09xV4= X-Google-Smtp-Source: ABdhPJy0j+IbVEkS+gzETwBblZcL1EsV8+WBrvFz1YGkTe22shWCJ4bobnDjIxeu8aWoE3peqb0eBw== X-Received: by 2002:a17:906:e117:: with SMTP id gj23mr4905058ejb.131.1626345958349; Thu, 15 Jul 2021 03:45:58 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:58 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 07/14] namei: prepare do_mknodat for refactoring Date: Thu, 15 Jul 2021 17:45:29 +0700 Message-Id: <20210715104536.3598130-8-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is just a preparation for the move of the main mknodat logic to a separate function to make the logic easier to follow. This change contains the flow changes so that the actual change to move the main logic to a separate function does no change the flow at all. There are 3 changes to the flow here: 1. may_mknod() call is repeated on ESTALE retry now. It's OK to do since the call is very cheap (and ESTALE retry is a slow path) and the result doesn't change; 2. Just like the similar patches for rmdir and others a few commits before, previously on filename_create() error the function used to exit immediately, and now it will check the return code to see if ESTALE retry is appropriate. The filename_create() does its own retries on ESTALE (at least via filename_parentat() used inside), but this extra check should be completely fine. 3. The retry_estale() check is wrapped in unlikely(). Some other places already have that and overall it seems to make sense Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wijsw1QSsQHFu_6dEoZEr_zvT7++WJWohcuEkLqqXBGrQ@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=wjFd0qn6asio=zg7zUTRmSty_TpAEhnwym1Qb=wFgCKzA@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 50ab1cd00983..4008867e516d 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3754,10 +3754,10 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, int error; unsigned int lookup_flags = 0; +retry: error = may_mknod(mode); if (error) goto out1; -retry: dentry = __filename_create(dfd, name, &path, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) @@ -3788,11 +3788,11 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, } out2: done_path_create(&path, dentry); - if (retry_estale(error, lookup_flags)) { +out1: + if (unlikely(retry_estale(error, lookup_flags))) { lookup_flags |= LOOKUP_REVAL; goto retry; } -out1: putname(name); return error; } From patchwork Thu Jul 15 10:45:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379823 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.8 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,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 04DC0C47E48 for ; Thu, 15 Jul 2021 10:46:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3E5361380 for ; Thu, 15 Jul 2021 10:46:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234530AbhGOKs4 (ORCPT ); Thu, 15 Jul 2021 06:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240397AbhGOKsz (ORCPT ); Thu, 15 Jul 2021 06:48:55 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46C4CC06175F; Thu, 15 Jul 2021 03:46:01 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id dt7so8491377ejc.12; Thu, 15 Jul 2021 03:46:01 -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=Eg5z+PqQJCS7nsIZodl87fjo91xdwFW+8QRSOZStkvM=; b=LQWgcm7KRHjf93vBGy203TlbK968/zscfRdA2n1dVI4piLF9FfmeFA126caPP2oE78 DVWVOgAU6dFr6wO+YSioRibIdl1/RXXeH3JLLR0We9YaIa2uAeAk6YWUbf5J6pTxO1B+ Ds68eROYSfQsPXOxEwzeGevWMZh429GeKyfmzh8YpIoMlevNz8rsZ/SUjU0F3Jhsspw5 79YSq+z7RROV/RPzgEpUQbRbcD9aM3u7R1of6hj4ND3k0xygqHj5iWGR6fNnbKEPq237 RMsCqw/0OecmxaWEY5GsXCrOeY0pYqI9Awc32k1+XDGXdKcJecrAWGVymVZzKkxGUdF6 yD6Q== 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=Eg5z+PqQJCS7nsIZodl87fjo91xdwFW+8QRSOZStkvM=; b=MKSLh4IUuUtXjMw3keruruthwKtCMpV0GYbv3NJEj+QvrpNGloZFDfO4AlLS2kl+HW DevsAZ9JqYtE40qZKU+DjKsGvXqnPPJYbfuAh+CBsr92OP1s9qdevtktKHi1UDopRoEa tcSaRogg4P81opN2CqJNGgOKyEvG8VaLBiL1kAms91WyH8Zg33mutMHRUw6dBq9TzRQr hBbMpmL0Y0mnzaXaf9soQvSBDKdvU6It/iuPTL7CBcXWSd2X9KNk0d+sLeZs7WDY+yIh bpE3pOTkYrOtsVCiSOdyAVd59fUo9C9E/y8ZMBRink1LfTyLokC6bXzLZeACCrYzpwxc N5iw== X-Gm-Message-State: AOAM5315gOSPFtZ/5ltprIycXojAASh8NUtMCHKC9MHA7ZxDsLYOSQQP WyrZlk/EQjxck/b2rYiZvSU= X-Google-Smtp-Source: ABdhPJwF8vbY3o/S8MxXSPmtad1KLXkdp7coSv4pKOiKkG9lQ1G66Ypabmk1yxdG29pT+t9GpHTUDg== X-Received: by 2002:a17:906:d541:: with SMTP id cr1mr4800913ejc.81.1626345959863; Thu, 15 Jul 2021 03:45:59 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.45.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:45:59 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 08/14] namei: clean up do_mknodat retry logic Date: Thu, 15 Jul 2021 17:45:30 +0700 Message-Id: <20210715104536.3598130-9-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No functional changes, just move the main logic to a helper function to make the whole thing easier to follow. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wiG+sN+2zSoAOggKCGue2kOJvw3rQySvQXsZstRQFTN+g@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 4008867e516d..f7cde1543b47 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3745,29 +3745,26 @@ static int may_mknod(umode_t mode) } } -static int do_mknodat(int dfd, struct filename *name, umode_t mode, - unsigned int dev) +static int try_mknodat(int dfd, struct filename *name, umode_t mode, + unsigned int dev, unsigned int lookup_flags) { struct user_namespace *mnt_userns; struct dentry *dentry; struct path path; int error; - unsigned int lookup_flags = 0; -retry: error = may_mknod(mode); if (error) - goto out1; + return error; dentry = __filename_create(dfd, name, &path, lookup_flags); - error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto out1; + return PTR_ERR(dentry); if (!IS_POSIXACL(path.dentry->d_inode)) mode &= ~current_umask(); error = security_path_mknod(&path, dentry, mode, dev); if (error) - goto out2; + goto out; mnt_userns = mnt_user_ns(path.mnt); switch (mode & S_IFMT) { @@ -3786,13 +3783,20 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, dentry, mode, 0); break; } -out2: +out: done_path_create(&path, dentry); -out1: - if (unlikely(retry_estale(error, lookup_flags))) { - lookup_flags |= LOOKUP_REVAL; - goto retry; - } + return error; +} + +static int do_mknodat(int dfd, struct filename *name, umode_t mode, + unsigned int dev) +{ + int error; + + error = try_mknodat(dfd, name, mode, dev, 0); + if (unlikely(retry_estale(error, 0))) + error = try_mknodat(dfd, name, mode, dev, LOOKUP_REVAL); + putname(name); return error; } From patchwork Thu Jul 15 10:45:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379825 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.8 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,USER_AGENT_GIT autolearn=ham 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 8B39AC47E4D for ; Thu, 15 Jul 2021 10:46:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7576361396 for ; Thu, 15 Jul 2021 10:46:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241651AbhGOKs4 (ORCPT ); Thu, 15 Jul 2021 06:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240406AbhGOKsz (ORCPT ); Thu, 15 Jul 2021 06:48:55 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C015BC061760; Thu, 15 Jul 2021 03:46:02 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id c17so8467447ejk.13; Thu, 15 Jul 2021 03:46:02 -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=0N8efY66+skeToBJjCOx9AdHtvBrjHdTGSW8mN497nw=; b=d/obLiIK4cONRFb3+nisZ4RSwOUnxlbMhbp+atFFDSldraI2mMSeVUlty9vKHT23qg 6Z6V1vp76jALWdH7RnujBAUtpbpO3EA7PcYxWV4OgaLxIynrJk3lF5rsGRjWhdhOK8XS a80sD3bpjkMPPvJe3471PYl/CNjTjIoEO80VGIHWZVLHZDR94CkGj8bRIgrwRT6vQ2mL vEZsECgJFalw6Tx97jgMqpNcJ6dt1t6Zu0YtPksF0NVLqpGTa87JPH/PgjycAlvaE2/B BEHFiiEB7zmvHgnOJPjJDrfR9+2zzyn6B+hcPKDsEKRHemeyH8GxwMqzm9F8/PDBwqDU zvQQ== 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=0N8efY66+skeToBJjCOx9AdHtvBrjHdTGSW8mN497nw=; b=s7t1KLKwfdr0LTXV1PhZ2k7St6e/CuY7UmBq99rHVgLT7XXH8oJA8jSW7TqwNFMxBN cQ28w9yx+/cgEbRadNTZKJEff721mYcN8PdG822NOjw1gl8Rlw8O6BjTTT2qTw2DdAe2 jzQz5oGDbsrSSeixMuc2mhC48QvA1kxqm5pHuNJx4U2/Y1bbDZlC3sSLzdFqOZSPg1dE IJ86GEK15e+j6cUvxv+JGS7vKMbwS3E/2zx2ouvPbyy/OVVJMNnRiFGF5ZseKGf47G6W gDzIB4Mrf77V/Vir+y/ZuE17dpO/RBB9+oHTxcK2p+erYgsPJz51ywRs7kUP2ar7dgxM 4aRA== X-Gm-Message-State: AOAM533pXsnbxfVCGOc12KSj8fOg39ZuZq2o7yjVaPoN0BUZzPzrS2k9 pFFemxFy8lkbBN97RwWTqMk= X-Google-Smtp-Source: ABdhPJzms5OPKKoGFdRkyYUNXdPWeLKCJe3whtABrEsxdh6BLV+G1zRDIqkX1D2rameC5R42flFzng== X-Received: by 2002:a17:906:6b8a:: with SMTP id l10mr4852391ejr.509.1626345961398; Thu, 15 Jul 2021 03:46:01 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.46.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:46:01 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 09/14] namei: prepare do_symlinkat for refactoring Date: Thu, 15 Jul 2021 17:45:31 +0700 Message-Id: <20210715104536.3598130-10-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is just a preparation for the move of the main symlinkat logic to a separate function to make the logic easier to follow. This change contains the flow changes so that the actual change to move the main logic to a separate function does no change the flow at all. There are 3 changes to the flow here: 1. IS_ERR(from) check is repeated on ESTALE retry now. It's OK to do since the call is trivial (and ESTALE retry is a slow path); 2. Just like the similar patches for rmdir and others a few commits before, previously on filename_create() error the function used to exit immediately, and now it will check the return code to see if ESTALE retry is appropriate. The filename_create() does its own retries on ESTALE (at least via filename_parentat() used inside), but this extra check should be completely fine. 3. The retry_estale() check is wrapped in unlikely(). Some other places already have that and overall it seems to make sense Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wiG+sN+2zSoAOggKCGue2kOJvw3rQySvQXsZstRQFTN+g@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=whH4msnFkj=iYZ9NDmZEAiZKM+vii803M8gnEwEsF1-Yg@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index f7cde1543b47..c4d75c94adce 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4241,15 +4241,15 @@ int do_symlinkat(struct filename *from, int newdfd, struct filename *to) struct path path; unsigned int lookup_flags = 0; +retry: if (IS_ERR(from)) { error = PTR_ERR(from); - goto out_putnames; + goto out; } -retry: dentry = __filename_create(newdfd, to, &path, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto out_putnames; + goto out; error = security_path_symlink(&path, dentry, from->name); if (!error) { @@ -4260,11 +4260,11 @@ int do_symlinkat(struct filename *from, int newdfd, struct filename *to) from->name); } done_path_create(&path, dentry); - if (retry_estale(error, lookup_flags)) { +out: + if (unlikely(retry_estale(error, lookup_flags))) { lookup_flags |= LOOKUP_REVAL; goto retry; } -out_putnames: putname(to); putname(from); return error; From patchwork Thu Jul 15 10:45:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379827 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.8 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,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 913CCC47E4F for ; Thu, 15 Jul 2021 10:46:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D9E761396 for ; Thu, 15 Jul 2021 10:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241660AbhGOKs5 (ORCPT ); Thu, 15 Jul 2021 06:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241656AbhGOKs5 (ORCPT ); Thu, 15 Jul 2021 06:48:57 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41478C06175F; Thu, 15 Jul 2021 03:46:04 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id c17so8467532ejk.13; Thu, 15 Jul 2021 03:46:04 -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=EHG39bGGVJfcCHnCV+DYwcxM8Y412mNnw+khYb5tB2Y=; b=SZk4DOX0jqnKexk8NF6TvR+H2/qpz/5RT4AHZEA72GMcvb5OwQ8Ta3p+Z0WD+8zOZE +fVPJCEcaFZARI4+KpUO91I8+wru3oPDVk2QE00DtkOuLV082+Bo6O3sWHRyRTRFJxjd EWGkx3/W6ixqJLbGryk6uuQ7OWkr+oc4przZGM56CbjUtxcweOJAqHF2cjp9RhLbM0gC nHBQIgIvbNA0bQ9tdZaEBSvFinDtGwshfmpg7rbYOHhsopQMuAWbocRRbFxBGDab+x2W 6/6w+46Ucr8h26XN9Oio/qT8LcO7R8XaKUP5yo3UhXwS7yp0m4PrLMV9mlmVdwDMlkEL Wn/A== 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=EHG39bGGVJfcCHnCV+DYwcxM8Y412mNnw+khYb5tB2Y=; b=jRScQgu1n8zgfqqWz0CP/oUWNzWu0BbJfsGuP47wPXjenxFTduKohCKWJFVNwjqajo cwo8xrvTcHuwVXEVxwcAlRsqiCaIXSWF1r3HdZG6eNG5LV3FuYamnG82eKRAKTmHd+9S BD/q3kB/FMr0CmYejedvTOwasmXxdYfo85DUK5+xydac8/TMQTMu/kixKiudnF29csI4 GcZFpSgZmAuwH8Ui/4UqUAO3Deraafw22KbQGXhwdnj0lXZGNzGiqJ12Hhv+C2rsCPWn 6A+9MsdlnTm1/wnH7VK2FmkGCxtSBLcU+ts8O7xweHk4CvjXqc7o/IFjEJD9GrqYboNg zzbA== X-Gm-Message-State: AOAM530U8yvtUj4aDxiWuKIlFxIyYkEruV0ErwtyPARyT3fkYMSUlPeA E3aWzlmGFK+B09D9qQ6MFFo= X-Google-Smtp-Source: ABdhPJztfnHXYPlJqjrpHD3hnIH74hi/0GnPqzwJP9ssqx/7Biq7ciKwrFbEvuLxwIz2TDCOrGJ8Cg== X-Received: by 2002:a17:906:4ad9:: with SMTP id u25mr4827809ejt.174.1626345962859; Thu, 15 Jul 2021 03:46:02 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:46:02 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 10/14] namei: clean up do_symlinkat retry logic Date: Thu, 15 Jul 2021 17:45:32 +0700 Message-Id: <20210715104536.3598130-11-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No functional changes, just move the main logic to a helper function to make the whole thing easier to follow. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wiG+sN+2zSoAOggKCGue2kOJvw3rQySvQXsZstRQFTN+g@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c4d75c94adce..61cf6bbe1e5c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4234,22 +4234,18 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, } EXPORT_SYMBOL(vfs_symlink); -int do_symlinkat(struct filename *from, int newdfd, struct filename *to) +static int try_symlinkat(struct filename *from, int newdfd, struct filename *to, + unsigned int lookup_flags) { int error; struct dentry *dentry; struct path path; - unsigned int lookup_flags = 0; -retry: - if (IS_ERR(from)) { - error = PTR_ERR(from); - goto out; - } + if (IS_ERR(from)) + return PTR_ERR(from); dentry = __filename_create(newdfd, to, &path, lookup_flags); - error = PTR_ERR(dentry); if (IS_ERR(dentry)) - goto out; + return PTR_ERR(dentry); error = security_path_symlink(&path, dentry, from->name); if (!error) { @@ -4260,11 +4256,17 @@ int do_symlinkat(struct filename *from, int newdfd, struct filename *to) from->name); } done_path_create(&path, dentry); -out: - if (unlikely(retry_estale(error, lookup_flags))) { - lookup_flags |= LOOKUP_REVAL; - goto retry; - } + return error; +} + +int do_symlinkat(struct filename *from, int newdfd, struct filename *to) +{ + int error; + + error = try_symlinkat(from, newdfd, to, 0); + if (unlikely(retry_estale(error, 0))) + error = try_symlinkat(from, newdfd, to, LOOKUP_REVAL); + putname(to); putname(from); return error; From patchwork Thu Jul 15 10:45:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379829 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.8 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,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 77C16C47E48 for ; Thu, 15 Jul 2021 10:46:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60F7E61396 for ; Thu, 15 Jul 2021 10:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241661AbhGOKtA (ORCPT ); Thu, 15 Jul 2021 06:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241664AbhGOKs7 (ORCPT ); Thu, 15 Jul 2021 06:48:59 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF048C061760; Thu, 15 Jul 2021 03:46:05 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id t3so7422915edc.7; Thu, 15 Jul 2021 03:46:05 -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=ioWuu96IeE32YNzL5QXexV2ZKLA96CBJT2HyMPWI7/c=; b=FYmbehir2pKczPV8ftJhOteSPZcnq4Jr140WuuGo2P2q+V8NTy6SYNPF8Xtycxe5Cv nxzDx4FIcRCTJsKR7VgYKnxD+43kFi0ZBd5UTgU5gddIAluCZxVfRt2JAUEorEJcZRgA 7ZA3XHD5lKbCagneYYY28f98gH8NYPTseT4Teqjy8c3TFCCiYsYIqK1w32ZLvwQj3Ika h+dL6n0JmSf1FSsgMGyK3xdTuhy/jp7/x1aPO1ZBKOS9gfcyC34+n990V8ezyD6eT21s PuqynkNrccgpunzj+ockwSMi76658zjzxv6uaUJltrJWAvw+EWl65LjCxs5MNMtxnBQx ypZg== 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=ioWuu96IeE32YNzL5QXexV2ZKLA96CBJT2HyMPWI7/c=; b=Cf7jJ34LokeUUvwpMIYaXkynNAvIRs6YL2++RmYf4/Tdj2z8tHaISBhg6923vahU2p SRZyg8NLYJySOQ1a+UcyrhzZYRK286MGS9Hr4d5yyQKwr2yi9UtWHYBtfEIYYqakYt4M RIEVWiHXpJN2bpvAogdsDEzRope0ITp/6XS6R1oHW9QqUwLwQ8q4DJt09nkHTNTgzumM jExyVOLCJ5o2BKitMwhSVqta0wpoE8YN1LIPoEDZNKasl3jNCLNlI32Pi7lK5MRuSdwg 0hg4W+vvp9m8c2iQXP9smAhPpHuCQjFWujB7K+TBGE5apknycuDTjfXny4+SO0z+OUp5 qx0w== X-Gm-Message-State: AOAM530cey2DxAe+gmZ7hs6wOJvhMxEeDqZQobpTfx4zFBLzD25Stu6n X9pZ/V0BBsw++27ZXS0wJzQ= X-Google-Smtp-Source: ABdhPJxaUcufsy4j3Yr9RaDsKRdX9/LG5Dka2l5r+uWatmZ2XiXsejh9odp82NLWTF+Ab07zr/jioA== X-Received: by 2002:a05:6402:2788:: with SMTP id b8mr6031146ede.244.1626345964336; Thu, 15 Jul 2021 03:46:04 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:46:04 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 11/14] namei: prepare do_linkat for refactoring Date: Thu, 15 Jul 2021 17:45:33 +0700 Message-Id: <20210715104536.3598130-12-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is just a preparation for the move of the main linkat logic to a separate function to make the logic easier to follow. This change contains the flow changes so that the actual change to move the main logic to a separate function does no change the flow at all. Changes to the flow here: 1. Flags handling is moved into the retry loop. So it can be moved into the function with the main logic. The cost here is mainly the capabilities check on retry, but hopefully that is OK, ESTALE retries are a slow path anyway. 2. Just like the similar patches for rmdir and others a few commits before, previously on filename_create() and filename_lookup() error the function used to exit immediately, and now it will check the return code to see if ESTALE retry is appropriate. Both filename_create() and filename_lookup() do their own retries on ESTALE (at least via filename_parentat() used inside), but this extra check should be completely fine. Invalid flags will now hit `if retry_estale()` as well. 3. unlikely() is added around the ESTALE check; Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wiG+sN+2zSoAOggKCGue2kOJvw3rQySvQXsZstRQFTN+g@mail.gmail.com/ Link https://lore.kernel.org/io-uring/CAHk-=wiE_JVny73KRZ6wuhL_5U0RRSmAw678_Cnkh3OHM8C7Jg@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 61cf6bbe1e5c..82cb6421b6df 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4391,6 +4391,7 @@ int do_linkat(int olddfd, struct filename *old, int newdfd, int how = 0; int error; +retry: if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) { error = -EINVAL; goto out_putnames; @@ -4407,7 +4408,7 @@ int do_linkat(int olddfd, struct filename *old, int newdfd, if (flags & AT_SYMLINK_FOLLOW) how |= LOOKUP_FOLLOW; -retry: + error = __filename_lookup(olddfd, old, how, &old_path, NULL); if (error) goto out_putnames; @@ -4439,14 +4440,13 @@ int do_linkat(int olddfd, struct filename *old, int newdfd, goto retry; } } - if (retry_estale(error, how)) { - path_put(&old_path); - how |= LOOKUP_REVAL; - goto retry; - } out_putpath: path_put(&old_path); out_putnames: + if (unlikely(retry_estale(error, how))) { + how |= LOOKUP_REVAL; + goto retry; + } putname(old); putname(new); From patchwork Thu Jul 15 10:45:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379831 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.8 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,USER_AGENT_GIT autolearn=ham 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 005E7C47E4E for ; Thu, 15 Jul 2021 10:46:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DDA58613C7 for ; Thu, 15 Jul 2021 10:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241665AbhGOKtB (ORCPT ); Thu, 15 Jul 2021 06:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240405AbhGOKtA (ORCPT ); Thu, 15 Jul 2021 06:49:00 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A54CC061762; Thu, 15 Jul 2021 03:46:07 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id h8so7462692eds.4; Thu, 15 Jul 2021 03:46:07 -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=oHTyVssJOKOMNYLoKsanZl5rYRQNpuGGGknPYRfBiFQ=; b=Lk1e7v1opZ6cVSQWmvBhOflQ5lr6jIulj+Y7tha9yIw27WEK8xUjosK7p9SNgDvcwP iTW3bYpnJqOkXTbAeR9KmlgBVmfd9cbYyiD8mgUxuULSItEP9FGZZGmTggbn5l4GtTBU Y/sbNbLtspkaH5OjpY6v5WYpqre/uRdjXVR/Sn7WqRLuuUdT3MsVUf0MDy7grXGWLSjc gZLZjWZF9gJx8146iUDZagqMpBG3Jq0oPNf00QBf1H+av9GVnYyogM1jK3oSEpWrxbUt 47cBZ3hsuKk84zYfgG00ONml8O2xYrL1LVLi6gSzzFroQzDN/W4boskWeqlPPV9ab4Wi dSxQ== 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=oHTyVssJOKOMNYLoKsanZl5rYRQNpuGGGknPYRfBiFQ=; b=Z/debBfuX66Tb0R+zxen2Ei91c1B2xQbODvggJ9pectLUwiZ7E1qbmruC+RshmscsH ZBDLynqH9j0AVtqLiu2JbjqUSUzuwq8atjyyrO7DydKpkfVYJs8Fhty5XihBmbBRxozS 16W9lpXyqlSj5jZxDu11X4LP2UGIKj1jwOBWh8oCHGuEGm3KhBLYVMXoMiGh3KBxqDkc XSNaSZJRs5bfGg20CFfgX670Z9FfVIODJpRdyyVV8LPXYF0RXaFKTgGO0ZDkIqPbGK1i R7vSkIVjtmhUuQjFseazQrBaVk711USdwKOtfu0upDLh2UoQqMVl2OWuIV1AcfBit13a ghlg== X-Gm-Message-State: AOAM533GL9mPboYaWFyZ4n6WL/9tr9Qq5flt1FG0qJE3t4hLB24jIVBy zuIYLK7Q4buFZ02MmHxzAAo= X-Google-Smtp-Source: ABdhPJyNQhzwbKup7VT/cN+NGWBsses1SeBDISFgChKHNOLVOnFAyp4PNJvkwm7rN61rm3X5KYrGyw== X-Received: by 2002:a05:6402:64e:: with SMTP id u14mr6051187edx.122.1626345965798; Thu, 15 Jul 2021 03:46:05 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:46:05 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 12/14] namei: clean up do_linkat retry logic Date: Thu, 15 Jul 2021 17:45:34 +0700 Message-Id: <20210715104536.3598130-13-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No functional changes, just move the main logic to a helper function to make the whole thing easier to follow. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wiG+sN+2zSoAOggKCGue2kOJvw3rQySvQXsZstRQFTN+g@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=wiE_JVny73KRZ6wuhL_5U0RRSmAw678_Cnkh3OHM8C7Jg@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 82cb6421b6df..b93e9623eb5d 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4381,37 +4381,32 @@ EXPORT_SYMBOL(vfs_link); * with linux 2.0, and to avoid hard-linking to directories * and other special files. --ADM */ -int do_linkat(int olddfd, struct filename *old, int newdfd, - struct filename *new, int flags) +static int try_linkat(int olddfd, struct filename *old, int newdfd, + struct filename *new, int flags, unsigned int how) { struct user_namespace *mnt_userns; struct dentry *new_dentry; struct path old_path, new_path; struct inode *delegated_inode = NULL; - int how = 0; int error; retry: - if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) { - error = -EINVAL; - goto out_putnames; - } + if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) + return -EINVAL; /* * To use null names we require CAP_DAC_READ_SEARCH * This ensures that not everyone will be able to create * handlink using the passed filedescriptor. */ - if (flags & AT_EMPTY_PATH && !capable(CAP_DAC_READ_SEARCH)) { - error = -ENOENT; - goto out_putnames; - } + if (flags & AT_EMPTY_PATH && !capable(CAP_DAC_READ_SEARCH)) + return -ENOENT; if (flags & AT_SYMLINK_FOLLOW) how |= LOOKUP_FOLLOW; error = __filename_lookup(olddfd, old, how, &old_path, NULL); if (error) - goto out_putnames; + return error; new_dentry = __filename_create(newdfd, new, &new_path, (how & LOOKUP_REVAL)); @@ -4442,14 +4437,20 @@ int do_linkat(int olddfd, struct filename *old, int newdfd, } out_putpath: path_put(&old_path); -out_putnames: - if (unlikely(retry_estale(error, how))) { - how |= LOOKUP_REVAL; - goto retry; - } + return error; +} + +int do_linkat(int olddfd, struct filename *old, int newdfd, + struct filename *new, int flags) +{ + int error; + + error = try_linkat(olddfd, old, newdfd, new, flags, 0); + if (unlikely(retry_estale(error, 0))) + error = try_linkat(olddfd, old, newdfd, new, flags, LOOKUP_REVAL); + putname(old); putname(new); - return error; } From patchwork Thu Jul 15 10:45:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379833 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.8 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,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 D74A0C47E48 for ; Thu, 15 Jul 2021 10:46:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1C0F61396 for ; Thu, 15 Jul 2021 10:46:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241669AbhGOKtD (ORCPT ); Thu, 15 Jul 2021 06:49:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241666AbhGOKtB (ORCPT ); Thu, 15 Jul 2021 06:49:01 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B16F1C06175F; Thu, 15 Jul 2021 03:46:08 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id hd33so8498915ejc.9; Thu, 15 Jul 2021 03:46:08 -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=YFvz8qx7mcSZDL2EvDSdDLDKIjaZI9QM888C94zIFc8=; b=Dbztf1nwQhEqhAwI69bvytJqvwVkDA6RugBGa5Ak+G0KK6l8rd6jiSXRMXaOvY2iTV sJ5l8fIBdg8zZfuJsFdWUZXloqY8eEMmQiDJWNZTw52wHaQxrf0bpr+Q7REECkcbg+nz ND1OxLXMqbSKjQAz+90NK7c5m7hq+8NYgdmP7A0pzlJAzoDh/4G33eqmpfThFoSr9Y72 oIfCxqhQo+AUNQ3IZlfMWss+2gzL0X+DBxmDwMWaVHKJi4pSxkn/4+peef41dcD/XpMG uFZSu7qK2J6c8H5vPcwOS60VraeICpzKGLF037/9R/echpkyPcmx0Qz/ParLBULZ4+xh gObA== 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=YFvz8qx7mcSZDL2EvDSdDLDKIjaZI9QM888C94zIFc8=; b=sftM+dxOgAm2KjLcdEqAQKs3DXvVQjiUCZqytmN9HuO2oHq1nEM6CODkCrbfqHX0Nd GsTX/qvFy98Lrg/xeLbeyf1r5f7FKDX41dgaV0V4j7qwZrBUvOQAXiZu46X4T2YqCwwZ Jn5NBuUoqVoXOQg/oTSXkKRcP9Csl4op5iStHDfDSb4tHW26SMOTiXc/o4W3NL+CDcqt EUCkYOxaPWYDJwQF8IHi0aQgNR8oiuIKMJ3lggPlM3bx3OEde4ssPTyhl5f8VgvVjuSx GsLpJEwEv17avfeBCqCJ9xZvUofA6Q+ESdP8saoq7xAAhpv4TFBtYVXsYcjZ7v8K+qbQ eF2Q== X-Gm-Message-State: AOAM531tzhBWwzDRUMtQ9EMZSQWaK8w3uGOq1Ekp1ObMyB/bcpiwJuWQ cS8ymcKtgzIHgRUnKrioAuA= X-Google-Smtp-Source: ABdhPJwjCk0ZiATJtOEfaUzzsjhu/lIahfKkJpXrGAd3qnaj6Qr93ylYe8hRlWVu+oYQI8WjKB3I6w== X-Received: by 2002:a17:906:7302:: with SMTP id di2mr4782179ejc.409.1626345967293; Thu, 15 Jul 2021 03:46:07 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:46:07 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 13/14] namei: prepare do_renameat2 for refactoring Date: Thu, 15 Jul 2021 17:45:35 +0700 Message-Id: <20210715104536.3598130-14-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This is just a preparation for the move of the main renameat logic to a separate function to make the logic easier to follow. This change contains the flow changes so that the actual change to move the main logic to a separate function does no change the flow at all. Changes to the flow here: 1. Flags handling is moved into the retry loop. So it can be moved into the function with the main logic. A few extra arithmetic checks on a slow path should be OK. 2. Just like the similar patches for rmdir and others a few commits before, previously on filename_create() and filename_lookup() error the function used to exit immediately, and now it will check the return code to see if ESTALE retry is appropriate. Both filename_create() and filename_lookup() do their own retries on ESTALE (at least via filename_parentat() used inside), but this extra check should be completely fine. Invalid flags will now hit `if retry_estale()` as well. 3. unlikely() is added around the ESTALE check; Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wiG+sN+2zSoAOggKCGue2kOJvw3rQySvQXsZstRQFTN+g@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=wjFd0qn6asio=zg7zUTRmSty_TpAEhnwym1Qb=wFgCKzA@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index b93e9623eb5d..a75abff5a9a6 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4654,9 +4654,9 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, int old_type, new_type; struct inode *delegated_inode = NULL; unsigned int lookup_flags = 0, target_flags = LOOKUP_RENAME_TARGET; - bool should_retry = false; int error = -EINVAL; +retry: if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) goto put_names; @@ -4667,7 +4667,6 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, if (flags & RENAME_EXCHANGE) target_flags = 0; -retry: error = __filename_parentat(olddfd, from, lookup_flags, &old_path, &old_last, &old_type); if (error) @@ -4769,17 +4768,14 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, } mnt_drop_write(old_path.mnt); exit2: - if (retry_estale(error, lookup_flags)) - should_retry = true; path_put(&new_path); exit1: path_put(&old_path); - if (should_retry) { - should_retry = false; +put_names: + if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; goto retry; } -put_names: putname(from); putname(to); return error; From patchwork Thu Jul 15 10:45:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kadashev X-Patchwork-Id: 12379835 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.8 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,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 3DE3FC47E4B for ; Thu, 15 Jul 2021 10:46:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2931161396 for ; Thu, 15 Jul 2021 10:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241673AbhGOKtF (ORCPT ); Thu, 15 Jul 2021 06:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241668AbhGOKtD (ORCPT ); Thu, 15 Jul 2021 06:49:03 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 378C1C06175F; Thu, 15 Jul 2021 03:46:10 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id qb4so8484261ejc.11; Thu, 15 Jul 2021 03:46:10 -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=/XgiQe0Wv3FtiAdsvVsEc/R5dgx1mVv6tXWWM5MWLsk=; b=juqdp6oXw2gdRl/WZyFBQaK/lOW3x4Jl4/hQ0ahmPlTb5ICOHgvD4KyrK7PClzbQic GQ6AWVGtNBT7r9xrh8HN8mcqamFZCBxTP8xBYU4GgDUmaPe5jMymSl9GuzGIplo7VIjZ ooPpgsV6GA4GSbx+2EhE+Y3YMeiZigoGCcV90vTDT/Wc8W6zPgQN7HonG1txz06NGfR1 Nd5n6oAsp2hQRY9t8sTuZid5opd9D7jl5wDH0uC8SkMZBpDXshLI6MiVhDn7dKGPQz5O 6ue4xzDvYubgP1HWbPswiCQgMJEEAKjwwRxV4wllerfwEW6Fg9S5a8kYVDvQVz6n8akg +ISA== 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=/XgiQe0Wv3FtiAdsvVsEc/R5dgx1mVv6tXWWM5MWLsk=; b=YDDDh08G1Gf+EPUla0y1YP+78YLDEH/WwGPm73VzipLGzjMVfeyRTA4IudJeVa7Efl zLWsYwLD+uetbKTpr4I0VlyxZJJGIDSlv58ZIYYV5ac5UKumIoRP9yzq+JFgXpTVijRD mXXcHJODBiiok35WY+hW2FH7kIL5iqurky6dnQWaI6BTVIhOs2rMeIBv9xcIk0sfYSbu VGlMpDN/s8H6/ot7VDM/RFUwrkRtsUaoxveepQt3zOiMAj6BbqlIP4MKQz5/UtmyPRyT MQIaD9xQ6yBawX6snSL5H9ie80wdNm4fjv6UPWo9+SBa/Wfhn/9n5YDpPz9oA765BFZ/ NxCw== X-Gm-Message-State: AOAM531T2lxGl+NBrRlrPtGUVp5PemUz94sGT+Q9dFaBmJfiqKOEN+BZ EmWqwYPKWc5XkaeCS794fIM= X-Google-Smtp-Source: ABdhPJwq4fu1DOev/CZX+6O1LfB87sWvhqFET0ffqeX+nV47pLnJdjB+OAW1jT6W/vKVpdEdZ79u5A== X-Received: by 2002:a17:906:8252:: with SMTP id f18mr4793118ejx.261.1626345968849; Thu, 15 Jul 2021 03:46:08 -0700 (PDT) Received: from carbon.v ([108.61.166.58]) by smtp.googlemail.com with ESMTPSA id d19sm2231498eds.54.2021.07.15.03.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 03:46:08 -0700 (PDT) From: Dmitry Kadashev To: Jens Axboe , Alexander Viro , Christian Brauner , Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Dmitry Kadashev Subject: [PATCH v2 14/14] namei: clean up do_renameat2 retry logic Date: Thu, 15 Jul 2021 17:45:36 +0700 Message-Id: <20210715104536.3598130-15-dkadashev@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210715104536.3598130-1-dkadashev@gmail.com> References: <20210715104536.3598130-1-dkadashev@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No functional changes, just move the main logic to a helper function to make the whole thing easier to follow. Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Suggested-by: Linus Torvalds Link: https://lore.kernel.org/io-uring/CAHk-=wiG+sN+2zSoAOggKCGue2kOJvw3rQySvQXsZstRQFTN+g@mail.gmail.com/ Link: https://lore.kernel.org/io-uring/CAHk-=wjFd0qn6asio=zg7zUTRmSty_TpAEhnwym1Qb=wFgCKzA@mail.gmail.com/ Signed-off-by: Dmitry Kadashev --- fs/namei.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index a75abff5a9a6..dce0e427b95a 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4643,8 +4643,9 @@ int vfs_rename(struct renamedata *rd) } EXPORT_SYMBOL(vfs_rename); -int do_renameat2(int olddfd, struct filename *from, int newdfd, - struct filename *to, unsigned int flags) +static int try_renameat(int olddfd, struct filename *from, int newdfd, + struct filename *to, unsigned int flags, + unsigned int lookup_flags) { struct renamedata rd; struct dentry *old_dentry, *new_dentry; @@ -4653,16 +4654,15 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, struct qstr old_last, new_last; int old_type, new_type; struct inode *delegated_inode = NULL; - unsigned int lookup_flags = 0, target_flags = LOOKUP_RENAME_TARGET; - int error = -EINVAL; + unsigned int target_flags = LOOKUP_RENAME_TARGET; + int error; -retry: if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) - goto put_names; + return -EINVAL; if ((flags & (RENAME_NOREPLACE | RENAME_WHITEOUT)) && (flags & RENAME_EXCHANGE)) - goto put_names; + return -EINVAL; if (flags & RENAME_EXCHANGE) target_flags = 0; @@ -4670,7 +4670,7 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, error = __filename_parentat(olddfd, from, lookup_flags, &old_path, &old_last, &old_type); if (error) - goto put_names; + return error; error = __filename_parentat(newdfd, to, lookup_flags, &new_path, &new_last, &new_type); @@ -4771,11 +4771,19 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, path_put(&new_path); exit1: path_put(&old_path); -put_names: - if (retry_estale(error, lookup_flags)) { - lookup_flags |= LOOKUP_REVAL; - goto retry; - } + return error; +} + +int do_renameat2(int olddfd, struct filename *from, int newdfd, + struct filename *to, unsigned int flags) +{ + int error; + + error = try_renameat(olddfd, from, newdfd, to, flags, 0); + if (unlikely(retry_estale(error, 0))) + error = try_renameat(olddfd, from, newdfd, to, flags, + LOOKUP_REVAL); + putname(from); putname(to); return error;