From patchwork Wed Sep 20 17:34:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13393106 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FCBAC04AB8 for ; Wed, 20 Sep 2023 17:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbjITRfh (ORCPT ); Wed, 20 Sep 2023 13:35:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbjITRfa (ORCPT ); Wed, 20 Sep 2023 13:35:30 -0400 Received: from outbound-ip7b.ess.barracuda.com (outbound-ip7b.ess.barracuda.com [209.222.82.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FD59B4 for ; Wed, 20 Sep 2023 10:35:23 -0700 (PDT) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2103.outbound.protection.outlook.com [104.47.55.103]) by mx-outbound20-254.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Sep 2023 17:35:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZsqVJ0uXECKv+lsJNfhHYKjQr3aRlSJdd81/bKPLRPN4oJ5qf6gckMir2YD+IDPshNsXBAzXc1rgg4Sep8r0RTHVsR2Yfr7+1nuTX7ByX5mtWFS+KwwRK4yBh0uhNuW8DMpYSezdh4m6UnKTpWuRv6mGuPc100YmaOE/w+RkKvIkp9nIkwdx0fVbKKSaVfvCd1JDmVew0V9zSvafoc32cByjYR+M2JgLK+0yjpZKDp3BR0i8ZiWABc68mNW+aL19M89CEEy3riPC1TjxSxJhtYOB9LCHHUlgSAaupvYN29GJ9J/bK5qC70x/k0/VtCuiJoNo8cCyFLGLxwe8eMJ4wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rIKchc+i1MBszxLkRo9yoa5Q8mu/F9AvOHkWVa4shWs=; b=RSOIcNx1yAWnKqh5AryTQZxo0Emx/NV6IPy0CEDngK5bt1I5HRlVOxlWdNd3i9B4dQ1s8BY30Kr50wB5M/U5wrGV2j2RRGLypQKwYH/NbIFHKvmpWdB8L12FsOS2hnY2FTwat4leFctbTpy12FEHuYigMBFMSy6mj6ID594nncwChgQWDj9Vop+/IGWHhfGyRjzCzUixS773ZVuKP3vSR1EkyFTf2nQGdrowT5Eq3gae8ve/QB0kM5iNhYXD7yA05RoHaOYTuXZgVEaG129hdqjmDsv2Yv1OauhY2/R93VgeCyXPK3um6YeSld/alHrnsjRxETfAMF+jpoAyKsi9Pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rIKchc+i1MBszxLkRo9yoa5Q8mu/F9AvOHkWVa4shWs=; b=pQwLUGv0Ze/FyAat+C0zdZK760HJVxd6JVxhzALALC28TDuusO404BOEo/eEYOK6MBmCsD7AlyNWkLCUEP5Xus9kArgYN5KsY0Tx0iL6a9iWhBW+1l303uqpDMQ8SQVCM2dFYd3sk7RgNplblxLE9NbLcDN51p2gRSojQYgJ0sY= Received: from MW4PR04CA0368.namprd04.prod.outlook.com (2603:10b6:303:81::13) by DM4PR19MB6248.namprd19.prod.outlook.com (2603:10b6:8:a9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20; Wed, 20 Sep 2023 17:34:50 +0000 Received: from MW2NAM04FT040.eop-NAM04.prod.protection.outlook.com (2603:10b6:303:81:cafe::3d) by MW4PR04CA0368.outlook.office365.com (2603:10b6:303:81::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.29 via Frontend Transport; Wed, 20 Sep 2023 17:34:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by MW2NAM04FT040.mail.protection.outlook.com (10.13.30.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20 via Frontend Transport; Wed, 20 Sep 2023 17:34:50 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 545D520C684C; Wed, 20 Sep 2023 11:35:55 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com, Bernd Schubert Subject: [PATCH v9 1/7] fuse: rename fuse_create_open Date: Wed, 20 Sep 2023 19:34:39 +0200 Message-Id: <20230920173445.3943581-2-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com> References: <20230920173445.3943581-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT040:EE_|DM4PR19MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 80e9a1a5-9494-48cf-9e5f-08dbb9ffe47b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZpxVbiRRI7E8kxFrbTQu3DuPvPtfhbUJ3W0rI92rFqayY8y6lrpt7aDt2UGtJKHfr6qg2jbFjqvGaJ5rMEpc5mWql4AiaAg7+AxxeB5I6/FFscFzzHp+DKj84GQ4nS+pb0M6LU6+5cexyDGBGapX93gvM6CMNrh724+ghnIoRzGbqxEFYszMpy5RmGh0+pHw13MKa7ib5aF0opXe2sw14jMIxMuZ9evs6iT3RHqvFP+7Z8dMjz9Y56dwZQ+Ej7FTOVExQ5A3o2vaGlMFWswK2sLTI0xGSGoS0BiiaKB61AyjPvlEb2jbgeACeSwyGKml2C6iNlUgUaMQ1s+iRuA/d3jbsBMQgd2jZILIKJiQ6rcG+8DLHHHvve01Q+U5rUm4GBTz4ULGC4e5E8TBXOdIq1tWA8rAc2Fko311IobJh9wCX3tvdphH68g7TwBysbezHg2rVONWc+NtRFYiNovFrUucuIZK+N3GnZ2aPyI2dhpY9KU7Cndsh//E2OLkko+TaVD5b9x0P79ASa2JZhaYrH8ykxL7b3kLzmQGVsVeF48tZNsbQsXeK2Fyiod1HptrmypVIfdAQJNesMkgAzGJRGGBpRLRrC+JiysPp+4nHqX67atZJ2mCW5ywUftjdgd76DeDE2GcP3hIO6KBCkKPQv+EoR9usKzweIJ4XYGr95gzI9o2h6eOKGM66wa2Bd7YrAEhQfzv5P47SXoauXI8LxMCS8RW7fIBejpDTh2QorvAtaJieMKRPw8UqseJcVPl X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(376002)(396003)(346002)(39850400004)(451199024)(186009)(1800799009)(82310400011)(46966006)(36840700001)(5660300002)(86362001)(40480700001)(36860700001)(6666004)(41300700001)(478600001)(8936002)(8676002)(4326008)(36756003)(316002)(6916009)(2616005)(70206006)(70586007)(26005)(1076003)(336012)(6266002)(83380400001)(2906002)(47076005)(82740400003)(81166007)(356005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: su6K2jlkJDxYCzcOPqRoDH5cDhGtrD952k9TajzWJ29KWtbog40tb5NmuvtiZiGW8Oov3he5MydsbujQwW60VGGECRhpbq7XyfCVWEIysw7uhzNVqL0o9OlR48XK/vQ4ugzBe0xXGw6W1LDAH4pY2VuAytU178YFRZLGyUz/H5FJqAc09W92vXvpaposMV4XhfD59waveU3FEr6Lyj8V9+mIRkYDvgKRCk1Pc84xQbaA2RqGf91Eke3j9iURkZ2M9s1ZLqAInlK5h/k4wljlFbOOx+WoRJfGQAqXRJtnbV6tgDDvPe754fvbYaUCmdtZdKTDZqSLH9E/1mL2jTLPaZXQzZmoAdGzxExqGnfsuS2Ykdz8llWlJ60FNpBjvjEPXj19HEn4vx3U4nU6vZz3Q9CqJXe8nB3LXVtE2nW2JwgBk+xxqUEut9AVfFO+Slxt9BmmKfstfILb9cSKT47LVdICuJM31DfOp7w5h4fvJtjXGf7CxudD+UOraIbt1j5zjr/nr5hUo4pWtyx6aQ5G8odiMd/MuBi3N6s2swwxiknBdtNurWT7YTfb1mQprJ/yLs70TSOm3sNYO7Mf7Ba3jA/ZOieAFGOtH3EyoANWKGx10/qUJ3lLdJAYetX+7D7U89gNRu0NcPXJWvx3I02dBdEr5baAq9RHIVQDK5Tl8Etv1gk3mJXQkHmTnJ3SXnQIgk7/3c4TXdkB0YkJXq8BmE6jMk7+zVcP5cLv78jG1UlA569PWu3BQ+U+qcD30CB/7lE8RKPXo9j345ZnNOZWOeVfSTuJXUj6NORUFUuDNAXrH5hD3GECMehm7FtWtLWnMDA5fVGFMo28oNkmlFiitYzQdj8U0nBA29Nq/WsCIhM= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 17:34:50.3381 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 80e9a1a5-9494-48cf-9e5f-08dbb9ffe47b X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM04FT040.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR19MB6248 X-BESS-ID: 1695231318-105374-17477-6411-1 X-BESS-VER: 2019.1_20230913.1749 X-BESS-Apparent-Source-IP: 104.47.55.103 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoamxpZAVgZQMM3CNM3EIjEl1S jFMsncNMnS0sjELNnQwjLR0CQ5NcVAqTYWACN7O41BAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250962 [from cloudscan22-178.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Just preparation work for atomic open. Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: linux-fsdevel@vger.kernel.org --- fs/fuse/dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index f67bef9d83c4..542086140781 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -611,7 +611,7 @@ static void free_ext_value(struct fuse_args *args) * If the filesystem doesn't support this, then fall back to separate * 'mknod' + 'open' requests. */ -static int fuse_create_open(struct inode *dir, struct dentry *entry, +static int _fuse_create_open(struct inode *dir, struct dentry *entry, struct file *file, unsigned int flags, umode_t mode, u32 opcode) { @@ -751,7 +751,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, if (fc->no_create) goto mknod; - err = fuse_create_open(dir, entry, file, flags, mode, FUSE_CREATE); + err = _fuse_create_open(dir, entry, file, flags, mode, FUSE_CREATE); if (err == -ENOSYS) { fc->no_create = 1; goto mknod; @@ -877,7 +877,7 @@ static int fuse_tmpfile(struct mnt_idmap *idmap, struct inode *dir, if (fc->no_tmpfile) return -EOPNOTSUPP; - err = fuse_create_open(dir, file->f_path.dentry, file, file->f_flags, mode, FUSE_TMPFILE); + err = _fuse_create_open(dir, file->f_path.dentry, file, file->f_flags, mode, FUSE_TMPFILE); if (err == -ENOSYS) { fc->no_tmpfile = 1; err = -EOPNOTSUPP; From patchwork Wed Sep 20 17:34:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13393107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7F4EC04ABA for ; Wed, 20 Sep 2023 17:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229543AbjITRfo (ORCPT ); Wed, 20 Sep 2023 13:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbjITRfi (ORCPT ); Wed, 20 Sep 2023 13:35:38 -0400 Received: from outbound-ip179b.ess.barracuda.com (outbound-ip179b.ess.barracuda.com [209.222.82.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DDD8B9 for ; Wed, 20 Sep 2023 10:35:24 -0700 (PDT) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2172.outbound.protection.outlook.com [104.47.57.172]) by mx-outbound-ea17-82.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Sep 2023 17:35:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZOaPLgSqDOAv5pJ8rhD3yKerNX9geMGvM86Dc0YLMc6LeNSGW59Nd0hEYSziuSBwb9jepNbsID0b6oHk+f1ekHuj3Zls5VGZ6PLTIh5nTpCjfRGfH6RUKFdKzqKiju+9kxgSpHPm8qHUC8lOt7RHfBGEi1nNpzScbh7Gr+nlSCUAQjDH+uw0qtVDoYgo9BsIHrvl8VCOKmd368wnd+BI7H4+nsJe4sgMqrIQb5SI27ilavD9wrtxNL4xWJ1woLJmAM+S7s4SLhgPIxZ7V6AoFLqsOP/+tEMvmbS2nAhrv9tSWENE6obGeO70yKY6jQMc6sNVWdYuqq33IxjGT5bzbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mbbC94ZywEbpEvq6+rADuITlvUXN+TjFGHOSOfnCsd4=; b=hO/K/JePzTc7L2ieu9nWF28rlCM024MxT5HVgPPeZMuVbCatqZYjGWigcg34N0Tm6LTKDsU0lEfM1EQ3JzDg1Y3KtFHI7dDDJq0dqPLyPKnCjGKGrP2p3WtDvgM+yzEHcrAhM3Z8ExdokUJbrkuIpZphlI539cWznPqw3z1VNeW/AUDMvHylIvCm4Jtq+q59pP0B0TSIw0wqzoXUQUJFmAf2KBh2dyhLDRgt9RCEX9/UCX2pEP4CALzU48NUAQ7A0NTFdua+PTHZ3lQh0NyUx8T0LFz6UOvdp5ofGsr1ldd7aR0wtUK3+EtPLcm1p4XZPGfJJOIGTwjqao0GHqui4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mbbC94ZywEbpEvq6+rADuITlvUXN+TjFGHOSOfnCsd4=; b=XKOuR3OflPX8YwbVmJIpByf74wLRXg/P3rOH1d+uZqZtJa3VulzmTZrmbb0guhLQy8RSkFbRyvQ4GG7QeTZd9+BlXhi+Z2l27ESI+O1LrSbDRKExUCZSNTmqTQMvCkNxho/E3mGDoz97Jcu8R+n1nP0MBOcjslx47Dr4z70QE0Y= Received: from BN9PR03CA0349.namprd03.prod.outlook.com (2603:10b6:408:f6::24) by SJ0PR19MB5462.namprd19.prod.outlook.com (2603:10b6:a03:3e0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Wed, 20 Sep 2023 17:34:51 +0000 Received: from BN8NAM04FT047.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:f6:cafe::4b) by BN9PR03CA0349.outlook.office365.com (2603:10b6:408:f6::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.29 via Frontend Transport; Wed, 20 Sep 2023 17:34:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by BN8NAM04FT047.mail.protection.outlook.com (10.13.161.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20 via Frontend Transport; Wed, 20 Sep 2023 17:34:51 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 5032B20C684B; Wed, 20 Sep 2023 11:35:56 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com, Bernd Schubert , Horst Birthelmer , Christian Brauner , Al Viro Subject: [PATCH v9 2/7] fuse: introduce atomic open Date: Wed, 20 Sep 2023 19:34:40 +0200 Message-Id: <20230920173445.3943581-3-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com> References: <20230920173445.3943581-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT047:EE_|SJ0PR19MB5462:EE_ X-MS-Office365-Filtering-Correlation-Id: ca371612-d2cf-4393-ea04-08dbb9ffe51b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wBfj9Y7ngkEDvzA9SnEzUastXtgpljD+bK2zGUR0IVw3syxGuQyl6raPFy9aTkyEo3IFwo5n1oGA/ir2wC/U1jrjc9FS66iKEsIroGjn8h+bN303bfRdFNqjZrE5nUZaRbUcIf4xJwsfxNmsaKAE3GRtTW996qKLshPK1h6Xmwb1IxLOdGTPMN5nFHDN68FCcqIkLcRd7PzXUZ+AdtUQT7P48950VMThil2Ewd0liv9WBuV+eed2DgeIwFiLgSdwc4KnwZy/eUvf9WiSQeGbERE9mC+e+U4eUZitLr+JWM73xXVobBAMOX+kTO/GiBLDUl+Z28l6gcuyErHyPmS2yzMlkV2ye5svh0KO6deQHg24WAmlu/L6mdUm0UAcglOpDaSZ1mbqAsHWkredrgOBazNJVKu7o0t0ahm+cW3OFuZz3mP1zMGzcVTfz+fBWD0Hv4E8azrTpXv4Y/QrJ2IODIz/wYfLnNoRtKS3aXYrROUkBYrzKB/VIiBxVSe2A6/kiHcoVk3ihzQ2k6JRZSA2TUutfYFwI785VIwpCWfxz1Fh3NbG7rtmWXqdZZTM6vFEnVLcEn2JfUWXBcwQcpCqn/fVpgxoo5EB4wkrzM9boLZmMggKtoBtvCrtiKHl9xVWcHe7+mCDLdOMhlODw8uZK1v7daCvuw6hkfVjhHHEiRRzT3Df9wOFj85wqR4Zu4US9gqRBZGaUpBFJfFta9I6Xs7trvzel1cY+CZawTasyldVM3bbe9ReiiuMabythLnU X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(136003)(346002)(396003)(39850400004)(451199024)(186009)(1800799009)(82310400011)(36840700001)(46966006)(6666004)(478600001)(81166007)(86362001)(356005)(36756003)(40480700001)(82740400003)(36860700001)(2616005)(2906002)(1076003)(26005)(336012)(47076005)(6266002)(83380400001)(8676002)(41300700001)(5660300002)(6916009)(4326008)(8936002)(70206006)(54906003)(316002)(70586007)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 6Le7W4XqFiFC7nNc86GCuxWREflJ/WSywi/508+6o9O99/OpdWNpPHEk5woUN/ICkM95txVARvn+BclZv7/2HU9Wwp/TirwalsawC9m5y9xnkCGYGc+mWpjXFN9VDSQa8pMNO/cVcTSEjug4mAHb9qHbxtAZSsyyCQxa4JhP7p5y8J8dUlcy1mZHu8u6zMFcpl7UI5Deatbia89URGlWcnrGv8J8dKjzHtBEKaAD8OpTionQG5fZPGO+oxBHE9cdsuchJCe9j02+QiiSjRle8V+YwG9GWyGDYRXBMLZmugOzXgvIKegpBKAo63YZ/h5vF4oFACpg3ZX3DZ6tlq2nyTeGzxjr5k5NNpaidlMJ06Ic2kfsugYLGVShTxlh4TzZ6wcv26UlT9NXJxvk7EGhEuCq/GALsSkMLDUdX4fy6wB1T0IV5avuX3psiznZKiNvV/qA0oGlu7cV7cQLNkMcmSDmdRGOxbGKkp9XsOVK5XA64N3GmxY0n2QCGOpae+LnNP/EXROzaacc+j2Hf19iWYK4XSULBvXY+xNuNIddYIKDH0WxE48UlOuuFs2qZVNrRDNDwdrQBi7S8vw92+OXINc+8ODOraE7e4N0NIhKyOgGYhdwnUPwP8mMrb+bKf/UGjN4cCFM2DEazubB6DkhNGDzWoXHiN0Dpl9plXXYThRxfAPEAdBIfk/4aaOeP9uP/FJxfu/ruEaAVfVmGTpQDAf+oWVJrWi1kGImZftKP0u+RWYd/l76PBSqSTcT1Moc7bKOS8QCV55kQdstQwcHgWE9I9Otks3IFczxmbIjFhnuMShiTZb7cQbhRQjcGakFVpFuuaMSqWRY/u+2j1ukHjzG8i1utULTUseDf3OPpucw1OIYF92Iw//YlrHPWSnhvojPQ8nd61oh//ecHbhoOXhrsARs7BD5Xy/49bFKO8uBSBoaTfFNK921TRfRMmq9 X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 17:34:51.3261 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca371612-d2cf-4393-ea04-08dbb9ffe51b X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM04FT047.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR19MB5462 X-BESS-ID: 1695231304-104434-8569-5778-1 X-BESS-VER: 2019.3_20230913.1605 X-BESS-Apparent-Source-IP: 104.47.57.172 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVhZGBgZAVgZQMDktycDI3DQpxd gkMS3FMDE1NcXU3NIk0dzY0iTNItFMqTYWABZhLqJBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250962 [from cloudscan20-6.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Dharmendra Singh This adds full atomic open support, to avoid lookup before open/create. If the implementation (fuse server/daemon) does not support atomic open it falls back to non-atomic open. Co-developed-by: Bernd Schubert Signed-off-by: Dharmendra Singh Signed-off-by: Horst Birthelmer Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Christian Brauner Cc: Al Viro Cc: Dharmendra Singh Cc: linux-fsdevel@vger.kernel.org --- fs/fuse/dir.c | 214 +++++++++++++++++++++++++++++++++++++- fs/fuse/fuse_i.h | 3 + include/uapi/linux/fuse.h | 3 + 3 files changed, 219 insertions(+), 1 deletion(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 542086140781..4cb2809a852d 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -722,7 +722,7 @@ static int _fuse_create_open(struct inode *dir, struct dentry *entry, static int fuse_mknod(struct mnt_idmap *, struct inode *, struct dentry *, umode_t, dev_t); -static int fuse_atomic_open(struct inode *dir, struct dentry *entry, +static int fuse_create_open(struct inode *dir, struct dentry *entry, struct file *file, unsigned flags, umode_t mode) { @@ -768,6 +768,218 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, return finish_no_open(file, res); } +static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, + struct file *file, unsigned flags, + umode_t mode) +{ + int err; + struct inode *inode; + struct fuse_mount *fm = get_fuse_mount(dir); + struct fuse_conn *fc = fm->fc; + FUSE_ARGS(args); + struct fuse_forget_link *forget; + struct fuse_create_in inarg; + struct fuse_open_out outopen; + struct fuse_entry_out outentry; + struct fuse_inode *fi; + struct fuse_file *ff; + struct dentry *switched_entry = NULL, *alias = NULL; + DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq); + + /* Expect a negative dentry */ + if (unlikely(d_inode(entry))) + goto fallback; + + /* Userspace expects S_IFREG in create mode */ + if ((flags & O_CREAT) && (mode & S_IFMT) != S_IFREG) + goto fallback; + + forget = fuse_alloc_forget(); + err = -ENOMEM; + if (!forget) + goto out_err; + + err = -ENOMEM; + ff = fuse_file_alloc(fm); + if (!ff) + goto out_put_forget_req; + + if (!fc->dont_mask) + mode &= ~current_umask(); + + flags &= ~O_NOCTTY; + memset(&inarg, 0, sizeof(inarg)); + memset(&outentry, 0, sizeof(outentry)); + inarg.flags = flags; + inarg.mode = mode; + inarg.umask = current_umask(); + + if (fc->handle_killpriv_v2 && (flags & O_TRUNC) && + !(flags & O_EXCL) && !capable(CAP_FSETID)) { + inarg.open_flags |= FUSE_OPEN_KILL_SUIDGID; + } + + args.opcode = FUSE_OPEN_ATOMIC; + args.nodeid = get_node_id(dir); + args.in_numargs = 2; + args.in_args[0].size = sizeof(inarg); + args.in_args[0].value = &inarg; + args.in_args[1].size = entry->d_name.len + 1; + args.in_args[1].value = entry->d_name.name; + args.out_numargs = 2; + args.out_args[0].size = sizeof(outentry); + args.out_args[0].value = &outentry; + args.out_args[1].size = sizeof(outopen); + args.out_args[1].value = &outopen; + + if (flags & O_CREAT) { + err = get_create_ext(&args, dir, entry, mode); + if (err) + goto out_free_ff; + } + + err = fuse_simple_request(fm, &args); + free_ext_value(&args); + if (err == -ENOSYS) { + fc->no_open_atomic = 1; + fuse_file_free(ff); + kfree(forget); + goto fallback; + } + + if (!err && !outentry.nodeid) + err = -ENOENT; + + if (err) + goto out_free_ff; + + err = -EIO; + if (invalid_nodeid(outentry.nodeid) || fuse_invalid_attr(&outentry.attr)) + goto out_free_ff; + + ff->fh = outopen.fh; + ff->nodeid = outentry.nodeid; + ff->open_flags = outopen.open_flags; + inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, + &outentry.attr, entry_attr_timeout(&outentry), 0); + if (!inode) { + flags &= ~(O_CREAT | O_EXCL | O_TRUNC); + fuse_sync_release(NULL, ff, flags); + fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1); + err = -ENOMEM; + goto out_err; + } + + /* prevent racing/parallel lookup on a negative hashed */ + if (!(flags & O_CREAT) && !d_in_lookup(entry)) { + d_drop(entry); + switched_entry = d_alloc_parallel(entry->d_parent, + &entry->d_name, &wq); + if (IS_ERR(switched_entry)) { + err = PTR_ERR(switched_entry); + goto out_free_ff; + } + + if (unlikely(!d_in_lookup(switched_entry))) { + /* fall back */ + dput(switched_entry); + switched_entry = NULL; + goto free_and_fallback; + } + + entry = switched_entry; + } + + if (d_really_is_negative(entry)) { + d_drop(entry); + alias = d_exact_alias(entry, inode); + if (!alias) { + alias = d_splice_alias(inode, entry); + if (IS_ERR(alias)) { + /* + * Close the file in user space, but do not unlink it, + * if it was created - with network file systems other + * clients might have already accessed it. + */ + fi = get_fuse_inode(inode); + fuse_sync_release(fi, ff, flags); + fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1); + err = PTR_ERR(alias); + goto out_err; + } + } + + if (alias) + entry = alias; + } + + fuse_change_entry_timeout(entry, &outentry); + + /* File was indeed created */ + if (outopen.open_flags & FOPEN_FILE_CREATED) { + if (!(flags & O_CREAT)) { + pr_debug("Server side bug, FOPEN_FILE_CREATED set " + "without O_CREAT, ignoring."); + } else { + /* This should be always set when the file is created */ + fuse_dir_changed(dir); + file->f_mode |= FMODE_CREATED; + } + } + + if (S_ISDIR(mode)) + ff->open_flags &= ~FOPEN_DIRECT_IO; + err = finish_open(file, entry, generic_file_open); + if (err) { + fi = get_fuse_inode(inode); + fuse_sync_release(fi, ff, flags); + } else { + file->private_data = ff; + fuse_finish_open(inode, file); + } + + kfree(forget); + + if (switched_entry) { + d_lookup_done(switched_entry); + dput(switched_entry); + } + + dput(alias); + + return err; + +out_free_ff: + fuse_file_free(ff); +out_put_forget_req: + kfree(forget); +out_err: + if (switched_entry) { + d_lookup_done(switched_entry); + dput(switched_entry); + } + + return err; + +free_and_fallback: + fuse_file_free(ff); + kfree(forget); +fallback: + return fuse_create_open(dir, entry, file, flags, mode); +} + +static int fuse_atomic_open(struct inode *dir, struct dentry *entry, + struct file *file, unsigned int flags, + umode_t mode) +{ + struct fuse_conn *fc = get_fuse_conn(dir); + + if (fc->no_open_atomic) + return fuse_create_open(dir, entry, file, flags, mode); + else + return _fuse_atomic_open(dir, entry, file, flags, mode); +} + /* * Code shared between mknod, mkdir, symlink and link */ diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 9b7fc7d3c7f1..c838708cfa2b 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -672,6 +672,9 @@ struct fuse_conn { /** Is open/release not implemented by fs? */ unsigned no_open:1; + /** Is open atomic not implemented by fs? */ + unsigned no_open_atomic:1; + /** Is opendir/releasedir not implemented by fs? */ unsigned no_opendir:1; diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index b3fcab13fcd3..33fefee42697 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -315,6 +315,7 @@ struct fuse_file_lock { * FOPEN_STREAM: the file is stream-like (no file position at all) * FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE) * FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the same inode + * FOPEN_FILE_CREATED: the file was indeed created */ #define FOPEN_DIRECT_IO (1 << 0) #define FOPEN_KEEP_CACHE (1 << 1) @@ -323,6 +324,7 @@ struct fuse_file_lock { #define FOPEN_STREAM (1 << 4) #define FOPEN_NOFLUSH (1 << 5) #define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6) +#define FOPEN_FILE_CREATED (1 << 7) /** * INIT request/reply flags @@ -575,6 +577,7 @@ enum fuse_opcode { FUSE_REMOVEMAPPING = 49, FUSE_SYNCFS = 50, FUSE_TMPFILE = 51, + FUSE_OPEN_ATOMIC = 52, /* CUSE specific operations */ CUSE_INIT = 4096, From patchwork Wed Sep 20 17:34:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13393103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D345C04AB8 for ; Wed, 20 Sep 2023 17:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbjITRfW (ORCPT ); Wed, 20 Sep 2023 13:35:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjITRfU (ORCPT ); Wed, 20 Sep 2023 13:35:20 -0400 Received: from outbound-ip7a.ess.barracuda.com (outbound-ip7a.ess.barracuda.com [209.222.82.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92010CC for ; Wed, 20 Sep 2023 10:35:09 -0700 (PDT) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2102.outbound.protection.outlook.com [104.47.70.102]) by mx-outbound14-166.us-east-2a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Sep 2023 17:34:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C0WHJVkrsceBYW1YIZwIN4xuZh8RR3sGrdKCoLAQSb6nI7DNk7/bfhu8FcLdwDQVlTqZXmU21Mkk7+ThIpUDbDwWmYL1QGVIJ5CosXGRPxjeVF6kv+qUz0yWzv7zIaUNxz7uAz3mrcSXQxYmnnf1hEpQR7Kb2BpAM1OCqC3iz7vamS5nJpflJL3bvPlm5SXt6zxBjMf+jlyX2LB7xW8Wba33EeHp8DcNXtmIGF3LKsRiJleNB1WF6YoVm38VPIJj5I2+g8PEDSD5ThS4K8uFE1S5nTbXbAa9ZbkcWw4RHsGDwXQbODxnL6/A6A1aAPc8JRVlL4CZ8rXjoYElyPE19Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HzE+7kHzN2f5CR/TI9nlO1F7CK36ngpY6AlE5EIhYZI=; b=NpwGutmlvtO1aqrZOm6usI0URPZcZC472pjnL0jYkEyIQyvgDLMKSZotWzTleQFu1mRXlLOSX6KO0vvhcokUnTYsB72YX2iNb9Vz5v2m1MTTfQv+cNlR4AFurlpgDOzpZDXHkYsINnvPWWJY6D1F3cOmYIrYvq+jG0v+wKjaE31MZVTW0QwiZBux5NdrFrEY0DYk6jv3uNd1MYxS+ojIQ+2UJoXt4ZktvZmH89Kjyh/bMtrhhFzOxbVFvFYTpGrmlFoESOl9cWUTr7+zNgHyzDdMm6TjS9QCwW+wV0oV2rCsJXdNursR5m9W8g+34FzBQSC5j8jf6Wbh0KZJmsX5OA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HzE+7kHzN2f5CR/TI9nlO1F7CK36ngpY6AlE5EIhYZI=; b=WXu/wukKGmI35d5VeOg9bJjlLg0iEVdnv5tXT4YhsXRPqZnaEvBsxwPAxQuFvtSe/P08pbDKEtVibt83lyhp7yvWIR1/11bXU6i/CetoM4Mhhzwlzpy1uBS3e2Cpb09tp0tvyrGbp301joTkA8JKAf+e6XCtiMRtLVKOVeIecSI= Received: from BY3PR03CA0005.namprd03.prod.outlook.com (2603:10b6:a03:39a::10) by DM6PR19MB4025.namprd19.prod.outlook.com (2603:10b6:5:24b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Wed, 20 Sep 2023 17:34:52 +0000 Received: from MW2NAM04FT044.eop-NAM04.prod.protection.outlook.com (2603:10b6:a03:39a:cafe::82) by BY3PR03CA0005.outlook.office365.com (2603:10b6:a03:39a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.30 via Frontend Transport; Wed, 20 Sep 2023 17:34:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by MW2NAM04FT044.mail.protection.outlook.com (10.13.31.2) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20 via Frontend Transport; Wed, 20 Sep 2023 17:34:52 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 4BD8620C684C; Wed, 20 Sep 2023 11:35:57 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com, Bernd Schubert , Christian Brauner , Al Viro Subject: [PATCH v9 3/7] [RFC] Allow atomic_open() on positive dentry Date: Wed, 20 Sep 2023 19:34:41 +0200 Message-Id: <20230920173445.3943581-4-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com> References: <20230920173445.3943581-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT044:EE_|DM6PR19MB4025:EE_ X-MS-Office365-Filtering-Correlation-Id: 9617c545-c291-4748-32b6-08dbb9ffe598 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fVI0O06L4EZ2OirX6plPRHR56hJ6/V2FWfG+Qycv30KsesYNIniwUvTO0fAONJ2rHZ9R4ynqinaOQ0cMfPA768HXK3ppsarulaT2Ko9mEszTR9G84RleWeAbthiF34XCnAugaFOMCEXqUpeS73mwpd/0823Ez2ZnOa79ZjN7o6sdqdeeGT8v+183b9lFfuIQekcCKS/L2WckCAy5rydT9v7PwcTb3JS11eeilxcbxw31JtuKRvVlxlovng5tDW0cKMmoOcIQnayPM1Y8RvqAdTpxY9CcF6pW96kd3GqJVIzXzWJlUGWa9OrJ84/Vdi1IcHXSZR2gmM+9YUAIUFV9ChOLdKVjeYbA9FE66vrVnDV/I9kM6LufvjfC46pzRFzZlKGb1TAT2mjAMHGbFzIV0Ru4BmFtZ7BTnJjqvATcwKI1GZPFf6PvGps1sbPmP76ytjPivWnDKHNOWx+HaliYdmpPCZqHPx3EmVKybcCA81t0eyt34HRse2hupcc1VkTFKgx2PIqOR736AHNlxM7kJzPjT2aT8DwnU0XFgBjhWYlWBCcD3h/6tu+P6joal/7dJp6auX9yjK2lTYIxcsK00/omolLeVmH4D8pFWRyWVzc+gr4RZzOfxU9UhPD91bB5wn081mz7Jax+ZmOPHdP9rlE3GDtakxb9sMuwYoPedSW5kbHaim8q9yDo7nWdWWkdfSHen0VLl8ExTMPen+lcYfKVqeQQQpU7N0XybFuNiw/0qz030gJCcDarezMQkY6O X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(396003)(376002)(39850400004)(346002)(186009)(1800799009)(451199024)(82310400011)(46966006)(36840700001)(6666004)(478600001)(36756003)(356005)(81166007)(40480700001)(82740400003)(36860700001)(86362001)(26005)(2616005)(47076005)(336012)(6266002)(5660300002)(2906002)(6916009)(316002)(41300700001)(8936002)(4326008)(1076003)(70206006)(83380400001)(8676002)(54906003)(70586007)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: JFnzcVAoEsB14qzkmWPZiBVhIpACvWoJ83cCnM6eAewAgVeN2IzJaSyM2m3/3bflUTU7q7utHr1IC8zPuwDE42XRSL12AHAD7GG5+0hZCsZNQnt40AbXLUyK7LArXVmLhFI1OkOSEmVCIIbOPcLI273b2p79XtKNWK1wS6TobDadKetUQ1EbdA5O/2xlqmn1DY/6JK/X90TOWFA8VvVjWJi6Ouie1LJVg9/PnHO+03jQxgxvsExGtA3qFgDosIKLuK5vrWTbm8yZt/t8W43TLqWo5NQj9jHm/uve/s8h917A5WuEwSqUBgQi5T0P+jukKqXnrDGi2RByVdd0a6lScflX55bTHSL+h8C/xCh79HHgWaCXeo3kzaZhBpViWTKcrCsxeBXqDg6qshbegU0GPkyp0FNCnw1hu4y+XuORzOM8j3dD6kV+Wka/tl0GruZkTUdkyHqKxP95jc1CoLL++QvLdPw9s0p55pA/anhmwVzWOEGZdTRM9SZb296jRK9fBvVWr1k/cgUEk3eKqGwdp65jndIhrVqs3oXr4d/gJCzvv/gD2XP3k6xK7eKOf3Oi6tav0UIoLmN93npLDpFKQ7D93oD37+ix3edWLwoZNnRlxqGeaqCBqB7xk4x2Ki59mdnlCtv1P21V/fn6HfyfZAX+qZc8Gx1VD8Gx3Lv7YBfvL1Om6APJsFjVWFw7Jo642HF7mrnBtO3oS9O7XjdED4tdzjFXRVRi4OBLC4rpmrAGxPnrDyPRv0zYpy6SqfBhjXtPqzSK9CtejLMGN7k+Z2EQyrAWtbXe9Nsdcyp15qyFalZ79X0YjHtEdF4XUX7tAcQjaG/RyYCsZN5Ho2YiG33JWrBcGNCqPqy7Cw7u3dZkzB4LL+EYzcWTUEG2HgCxhWm7eEpRMpQ0vTpg66SSAhCQRJmEqjS7qrbVD9LzzFyJPvGQOv9orwMRRp1yWYqa X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 17:34:52.2031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9617c545-c291-4748-32b6-08dbb9ffe598 X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM04FT044.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR19MB4025 X-BESS-ID: 1695231296-103750-3125-5195-1 X-BESS-VER: 2019.1_20230913.1749 X-BESS-Apparent-Source-IP: 104.47.70.102 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVibGpiZAVgZQ0Mgy0SQ1zdIixc QiNcnC0MA0NdkwJdnC0sjQwiLVyMxMqTYWALyzOdZBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250962 [from cloudscan15-125.us-east-2a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Miklos Szeredi atomic_open() will do an open-by-name or create-and-open depending on the flags. If file was created, then the old positive dentry is obviously stale, so it will be invalidated and a new one will be allocated. If not created, then check whether it's the same inode (same as in ->d_revalidate()) and if not, invalidate & allocate new dentry. Co-developed-by: Bernd Schubert Signed-off-by: Miklos Szeredi Signed-off-by: Bernd Schubert Cc: Christian Brauner Cc: Al Viro Cc: Dharmendra Singh Cc: linux-fsdevel@vger.kernel.org --- fs/namei.c | 25 ++++++++++++++++++++----- include/linux/namei.h | 7 +++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index e56ff39a79bc..f01b278ac0ef 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -858,7 +858,7 @@ static inline int d_revalidate(struct dentry *dentry, unsigned int flags) if (unlikely(dentry->d_flags & DCACHE_OP_REVALIDATE)) return dentry->d_op->d_revalidate(dentry, flags); else - return 1; + return D_REVALIDATE_VALID; } /** @@ -1611,10 +1611,11 @@ struct dentry *lookup_one_qstr_excl(const struct qstr *name, } EXPORT_SYMBOL(lookup_one_qstr_excl); -static struct dentry *lookup_fast(struct nameidata *nd) +static struct dentry *lookup_fast(struct nameidata *nd, bool *atomic_revalidate) { struct dentry *dentry, *parent = nd->path.dentry; int status = 1; + *atomic_revalidate = false; /* * Rename seqlock is not required here because in the off chance @@ -1656,6 +1657,10 @@ static struct dentry *lookup_fast(struct nameidata *nd) dput(dentry); return ERR_PTR(status); } + + if (status == D_REVALIDATE_ATOMIC) + *atomic_revalidate = true; + return dentry; } @@ -1981,6 +1986,7 @@ static const char *handle_dots(struct nameidata *nd, int type) static const char *walk_component(struct nameidata *nd, int flags) { struct dentry *dentry; + bool atomic_revalidate; /* * "." and ".." are special - ".." especially so because it has * to be able to know about the current root directory and @@ -1991,7 +1997,7 @@ static const char *walk_component(struct nameidata *nd, int flags) put_link(nd); return handle_dots(nd, nd->last_type); } - dentry = lookup_fast(nd); + dentry = lookup_fast(nd, &atomic_revalidate); if (IS_ERR(dentry)) return ERR_CAST(dentry); if (unlikely(!dentry)) { @@ -1999,6 +2005,9 @@ static const char *walk_component(struct nameidata *nd, int flags) if (IS_ERR(dentry)) return ERR_CAST(dentry); } + + WARN_ON(atomic_revalidate); + if (!(flags & WALK_MORE) && nd->depth) put_link(nd); return step_into(nd, flags, dentry); @@ -3430,7 +3439,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, dput(dentry); dentry = NULL; } - if (dentry->d_inode) { + if (dentry->d_inode && error != D_REVALIDATE_ATOMIC) { /* Cached positive dentry: will open in f_op->open */ return dentry; } @@ -3523,12 +3532,18 @@ static const char *open_last_lookups(struct nameidata *nd, } if (!(open_flag & O_CREAT)) { + bool atomic_revalidate; + if (nd->last.name[nd->last.len]) nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; /* we _can_ be in RCU mode here */ - dentry = lookup_fast(nd); + dentry = lookup_fast(nd, &atomic_revalidate); if (IS_ERR(dentry)) return ERR_CAST(dentry); + if (dentry && unlikely(atomic_revalidate)) { + dput(dentry); + dentry = NULL; + } if (likely(dentry)) goto finish_lookup; diff --git a/include/linux/namei.h b/include/linux/namei.h index 1463cbda4888..a70e87d2b2a9 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -47,6 +47,13 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT}; /* LOOKUP_* flags which do scope-related checks based on the dirfd. */ #define LOOKUP_IS_SCOPED (LOOKUP_BENEATH | LOOKUP_IN_ROOT) +/* ->d_revalidate return codes */ +enum { + D_REVALIDATE_INVALID = 0, /* invalid dentry */ + D_REVALIDATE_VALID = 1, /* valid dentry */ + D_REVALIDATE_ATOMIC = 2, /* atomic_open will revalidate */ +}; + extern int path_pts(struct path *path); extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty); From patchwork Wed Sep 20 17:34:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13393102 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46F1FC04ABA for ; Wed, 20 Sep 2023 17:35:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbjITRfU (ORCPT ); Wed, 20 Sep 2023 13:35:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjITRfT (ORCPT ); Wed, 20 Sep 2023 13:35:19 -0400 Received: from outbound-ip160b.ess.barracuda.com (outbound-ip160b.ess.barracuda.com [209.222.82.95]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 130D6DC for ; Wed, 20 Sep 2023 10:35:09 -0700 (PDT) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by mx-outbound23-131.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Sep 2023 17:34:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J2+5/3aopIn9pNbu88lCmgG13s/LWL4F6wHghDeyFju9n/G++n8bNPFL8NQnXaeSZo+eVqZX7BaNovNvF6JRTuwX8z/7xcSCRYRNKZI5XfULAn7nqqLqxiTadThBcibhPU35NBPbLPMoEOB/GRMKunPTZVJFupzXTIXyN8lS3Nehpc48QxFva9P8ep2+o1Br4Iwp6SBWz6BUkn1fDrv2JxGQPR5HPayYsL3epfhUx5fZ6lrQXpRNSAfrA+VFU7PYLWy8ZcHMYG/anjjW+Hz69ZTTUQDOz01WA+77aXTcpw48p21cQuAnvt9awX90LA2jLZy9uMdzoBD6twgrogWAqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mAO/exSgvbNugQQ4efSMFeaXx6l02kTihT9DlJKrY+Q=; b=k1afFF5U0gUPQEqHRB/ayERosSqZVpa/PwwChpNFpgmHuJEmrThzKsNX34iPRX7zOAecGJn6Q613VQ37Wihu23VkXicuUptcYlNLs10EoizfAYI4mLyKz9r2BT9acuJjrjKmIO7bg1vXQyqc8aULrNaBItwfAx7lTN2IcXFg/OLgZtLHjf6YPi/Jj6d9UL8OZIoSbgFAn4wX66pdFX2qqDWZcKRq1+DoXvld/oeYea5ZsseTpSvbV5dA8gg8nlt2rqkk5HOV99N7qljS8TuLAV38AHXTK+LufHyPNqz133da0v/f+fVlgRbRvqXHcYmeJYci8YJtmLywgAM+cGRs+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mAO/exSgvbNugQQ4efSMFeaXx6l02kTihT9DlJKrY+Q=; b=Ltpm+l+Pl6thxapeD8CcMT+EBQhGn566cL+Xd8RBkobHfA8B9zv4OEgBVswFe9vwC8K1d+nY0NOgewxEkdiSKubcJDLDeXJ0qkWqm5RCCrgnx+k6kKrwAkiK5+NWERJnAydwCbv6UZRERGzvzON7GGSrIumuSohPAtICRKAxLis= Received: from MWH0EPF00056D18.namprd21.prod.outlook.com (2603:10b6:30f:fff2:0:1:0:19) by PH0PR19MB4792.namprd19.prod.outlook.com (2603:10b6:510:24::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Wed, 20 Sep 2023 17:34:53 +0000 Received: from MW2NAM04FT061.eop-NAM04.prod.protection.outlook.com (2a01:111:f400:7e8c::208) by MWH0EPF00056D18.outlook.office365.com (2603:1036:d20::b) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.12 via Frontend Transport; Wed, 20 Sep 2023 17:34:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by MW2NAM04FT061.mail.protection.outlook.com (10.13.31.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20 via Frontend Transport; Wed, 20 Sep 2023 17:34:53 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 466CA20C684B; Wed, 20 Sep 2023 11:35:58 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com, Bernd Schubert , Christian Brauner , Al Viro Subject: [PATCH v9 4/7] vfs: Optimize atomic_open() on positive dentry Date: Wed, 20 Sep 2023 19:34:42 +0200 Message-Id: <20230920173445.3943581-5-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com> References: <20230920173445.3943581-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT061:EE_|PH0PR19MB4792:EE_ X-MS-Office365-Filtering-Correlation-Id: 3769eed4-da46-4fb3-0346-08dbb9ffe621 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vA4rdjpNzowaPcZTOdzuhuoSuwF78bHLje7f0/k/hlERkVObyTGrnUiJlfZxZs5vncjumnVwwq4ijzEBlv2Hv/BMueZpV22n47MFMVAcdCcsaIGmObDutZu9hoXX3bHZ7j/YWTtUSB66ZqJ5EyFCJ/c+UtS7Oq03BCeSj+Lew1FhvWvN9t9eEdwcwwldQCoGzdDYus2pqzfjmVq/iY46gGhY53dvDk30LliO/jUm7Z3GDuphoHHNZwWrFk3kQH5YAp4rifhElvczZrt9PnP8xyLek/NFI7ob4jThhfnSa3PBtWEgrjAcRByrRQmC6UmWgLx7DzBHJFlvsM45maBhvbvwrMfoz+DmG5YuOTuSGRPqyG7LRL0j12//iodwoV4AXwsJnKpUELGgzcnJWYcacG95W06d6a0hN8Z3y5Zz007LLUb6Y2mkEBXL+otiWfPFAxVnVQUsDOpV9WPuE42t1+hYPMwog7bCpuGwScn340fha2Ai8/jNAMgktIG4CTxBO2RtoAMlhfRUuxn6FxzvWSdp6t7ma6BhL6FDlAt5FX/UbHy/26Kesu5XbZdJpKXDfXyIFMAhSkyzQBn/lUGtZSj3JJJXvaHexNXTNkiOfUNrmg1avTMhVWDkXou/gbJeF58QmyPiyY13baDg2eODFfCEeBCS4DtTQjVSiLBMrCNbTeULZgxeQhjknVsNIDwbR1hxPU72gcePnM5ZcO6gA/3v7r/1jCeIlygU3waDKStII2nj7eu1M38ePyfB2Dr6 X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(136003)(396003)(39850400004)(376002)(1800799009)(186009)(82310400011)(451199024)(36840700001)(46966006)(6266002)(6916009)(54906003)(8676002)(8936002)(4326008)(41300700001)(1076003)(40480700001)(2616005)(83380400001)(26005)(36860700001)(336012)(6666004)(478600001)(36756003)(356005)(86362001)(81166007)(47076005)(82740400003)(316002)(70586007)(70206006)(2906002)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: nbp5tk4m+csWBNERXRM+AkCq7EFlqzaVtkE3cUtTZwAA+q6MXlNrzZXFrjKI6WYET9WT8Yp37qPqyW+mkBl278WyNc9VY/RGePJySa5jeDGypjh+64KCA1ylQaZW+LCyAkDy2dpNsiXz3a6uy3FTALNBwmplabW0g6BkCulxyy0ch18gxcvp6YN9HwF4d2+X4LaLtcjLu7yEUAaOC1D0gEEeLK61/6Ga3/mBDJ9Whf1MvGM1eZDlrlxtncKJaWYF1gRpKhairETp8J+/DlUb7EpTbT3zqqilM6nkzXAAdweHhCNvYwMnnYt92UGt+jpXCiOS5WcMPiYTchim2CKzy9WqjrNSbOCSaBWWVy1aVRGqPEeuvol4Lb/JgrusrCkpiTlo5hgLVGBhiiIU1yPqHGJHx2hZ45Q8tSxB9rF46OFhksAS+4tAAZvOupCT2hy2dnNEuLvX8Btl9PG5hbfY0EdE/xcHeYNAHhlnvhjjTGMmYGJtpUxGNoj3qnyhVurSXjJ+CgCiuIFKeGDIXMhH2bJKZ1ne8uaQgYfThA8L3ajo+S9Ko72bDtiYExlIGBFYWOPy8J5zJ2vBO/AtPq3t/MTBO/tWHinF5GPisRO51HXc32aQUxNOcrn2VywgxiPHkN6FCzrok3dVs0wC7wc+2G7zMcomzq1hdvFtMHDeVan92v6mu1MgC/JeXbo1djzQg1a1/g0ocJELE4pzrEqbh0k7zJUREPDO1G1976H900540KoEDiPnAGWSaUw2bwCdcAGDcrR8qIRKz2ReIzM3FZjNc1SwEUNrDmdUXcVBOQTs5+rGkqBp4bVKW3A34oUoVkihQFgUCw+vuNTSQDva43wMnd0Rab5X5sFMPDS3LoTa2ihStQgigdSn9fwdNn0VxrHXT8DftP988csx0Etxey3nRpIC4g8UHuNVnYP8Jtx5UlZ+l+q2+QOBdJn34Kqd X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 17:34:53.0841 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3769eed4-da46-4fb3-0346-08dbb9ffe621 X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM04FT061.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR19MB4792 X-BESS-ID: 1695231296-106019-20111-6391-1 X-BESS-VER: 2019.1_20230913.1749 X-BESS-Apparent-Source-IP: 104.47.55.171 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkZmFuZAVgZQMDk5zdzUOM3SwM Iy0Sgl1TjNyMg8JSUlLS3F3Dgp2chCqTYWAOlRWE9BAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250962 [from cloudscan13-15.us-east-2a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This was suggested by Miklos based on review from the previous patch that introduced atomic open for positive dentries. In open_last_lookups() the dentry was not used anymore when atomic revalidate was available, which required to release the dentry, then code fall through to lookup_open was done, which resulted in another d_lookup and also d_revalidate. All of that can be avoided by the new atomic_revalidate_open() function. Another included change is the introduction of an enum as d_revalidate return code. Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: Christian Brauner Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org --- fs/namei.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index f01b278ac0ef..8ad7a0dfa596 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3388,6 +3388,44 @@ static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, return dentry; } +static struct dentry *atomic_revalidate_open(struct dentry *dentry, + struct nameidata *nd, + struct file *file, + const struct open_flags *op, + bool *got_write) +{ + struct mnt_idmap *idmap; + struct dentry *dir = nd->path.dentry; + struct inode *dir_inode = dir->d_inode; + int open_flag = op->open_flag; + umode_t mode = op->mode; + + if (unlikely(IS_DEADDIR(dir_inode))) + return ERR_PTR(-ENOENT); + + file->f_mode &= ~FMODE_CREATED; + + if (unlikely(open_flag & O_CREAT)) { + WARN_ON(1); + return ERR_PTR(-EINVAL); + } + + if (open_flag & (O_TRUNC | O_WRONLY | O_RDWR)) + *got_write = !mnt_want_write(nd->path.mnt); + else + *got_write = false; + + if (!got_write) + open_flag &= ~O_TRUNC; + + inode_lock_shared(dir->d_inode); + dentry = atomic_open(nd, dentry, file, open_flag, mode); + inode_unlock_shared(dir->d_inode); + + return dentry; + +} + /* * Look up and maybe create and open the last component. * @@ -3541,8 +3579,10 @@ static const char *open_last_lookups(struct nameidata *nd, if (IS_ERR(dentry)) return ERR_CAST(dentry); if (dentry && unlikely(atomic_revalidate)) { - dput(dentry); - dentry = NULL; + BUG_ON(nd->flags & LOOKUP_RCU); + dentry = atomic_revalidate_open(dentry, nd, file, op, + &got_write); + goto drop_write; } if (likely(dentry)) goto finish_lookup; @@ -3580,6 +3620,7 @@ static const char *open_last_lookups(struct nameidata *nd, else inode_unlock_shared(dir->d_inode); +drop_write: if (got_write) mnt_drop_write(nd->path.mnt); From patchwork Wed Sep 20 17:34:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13393105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADD89C04ABC for ; Wed, 20 Sep 2023 17:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229534AbjITRf2 (ORCPT ); Wed, 20 Sep 2023 13:35:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbjITRf0 (ORCPT ); Wed, 20 Sep 2023 13:35:26 -0400 Received: from outbound-ip201b.ess.barracuda.com (outbound-ip201b.ess.barracuda.com [209.222.82.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96462B9 for ; Wed, 20 Sep 2023 10:35:14 -0700 (PDT) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2048.outbound.protection.outlook.com [104.47.73.48]) by mx-outbound16-233.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Sep 2023 17:35:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TwafHqrbPwqwJlBd/0aWG8D7qF7eMpNsER22zOfoaaMAwSYIUA0g1S4Wcf4lZc2ieyD6qJV6+5n1MGVLJ80e8f25pFdGBG4rvnScfma6owocNZq1xsPGkPwOLSSs+lKdnbaqzaZ+fQJdjufTIQu3aw41LAfmchIawkbErbsnYRvUvff6lSQmT8vd+H/WXlm7ck86m2NtnvGq+WIoOHRhITWf1O7dQEQRz1iJgRVfpXrAqKnNVi8bLby+5dni6xyMYfx5YFfOsUt5Osip+ZrK6QgWMSiF8hWDpBuN2KQmQU0yS5pFFnQ0jMF8iyX/V5rsRqpWuuapJBIKeBcFbDttXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wXR/rdIx0cAylq+12eF8vnP5D9doFD1zmaDrJFvyH7g=; b=VTz8g/yCGppFjxtCcqnqT8mwmGD8mpFexeQQgLu7nUNOQw0vmmNwquPxrKfpMRIlyz5Fg4aK/lvsBD1NGDGwc+QU36o9yvB6od8td5QWYprj3XB4fcZYQcP2BTvQanc2FP10JhX9IF/OEL5vGHEF2RqXYS1kOmI7I83r0o1oh1b1puOz4qGfTMDgmOysBPMT7nHN3E6nelxuqmCWtyloZdKW7WF/XBI+id6TBA8z/0Ii8xOYmH3wz52YTW+K2qhnf0KydubWk39dwk6ZK0kqAOcJ4OvjPxfF+YzRM9/p5WOPxMEwUihhQQ3WZnTEJXYoizrGGwCjfmo1W7RQfBMxqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wXR/rdIx0cAylq+12eF8vnP5D9doFD1zmaDrJFvyH7g=; b=DcCsVmU5Frsws9GAkGm6b4n8t0uL4uJihQwUlFvth0c4aqZxhpC6BB3IhygC0CsvJ/lznSMmKxJWmNGrPTfmgY4tgr1V58m5bgqmL0FkWPAzemDeR+lbIADcxqac+q+5R4TvaX8PyONJyKq+LHCY8Nencf0Z556gMqsxGO6YYM8= Received: from BN1PR10CA0002.namprd10.prod.outlook.com (2603:10b6:408:e0::7) by DM6PR19MB4091.namprd19.prod.outlook.com (2603:10b6:5:229::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Wed, 20 Sep 2023 17:34:54 +0000 Received: from BN8NAM04FT020.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:e0:cafe::2c) by BN1PR10CA0002.outlook.office365.com (2603:10b6:408:e0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.29 via Frontend Transport; Wed, 20 Sep 2023 17:34:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by BN8NAM04FT020.mail.protection.outlook.com (10.13.160.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Wed, 20 Sep 2023 17:34:54 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 41E5020C684C; Wed, 20 Sep 2023 11:35:59 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com, Bernd Schubert , Horst Birthelmer , Christian Brauner , Al Viro Subject: [PATCH v9 5/7] fuse: Revalidate positive entries in fuse_atomic_open Date: Wed, 20 Sep 2023 19:34:43 +0200 Message-Id: <20230920173445.3943581-6-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com> References: <20230920173445.3943581-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT020:EE_|DM6PR19MB4091:EE_ X-MS-Office365-Filtering-Correlation-Id: 1bc5f4f5-4091-496d-0aae-08dbb9ffe6d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VChQ28SZfP+wn8bcUZlFilUFxxms9ifVECiGIlzrygQn3laMyVDK3zSOMKdr3Db8BoHLbMR9gOIZ1hwqvvaHWNSMvwORFS8eML1dxwhYgnwfc+D3aOorsdP0oZq++NbfewpAnmoia8h+mEH2ASHWUlANJngMXSHsKr1khs4h+KL85bPRDxt7Zo8jI/zuClGb49MySDkCtYPg/gsyR6TUS6mkhZVMB5D1eczgABrz33GoyLQGgwmkBzIoRKKX8UUlrk1a/pKEr9bsi2PEYGMXSU8HL1at/VTsFp+Op+ODIv3IxZXMSp7AYiQuwYlX6+0PbkfC7voQ214+jSplNpv9ncxO9+YALDToWu+cbfvOWfoE61h4/gzkJKd+7X+p+4T+7dNqato8zF7pLR9XMt3j46iaoS9u6aLoizK6kKodAlQsk56obapdcvN57c/80j8WZMz+1v/zGThNCQES0skJ+JeS0UiEduguuG8LCPvRgj1jJ0SumBXOIYCdvYXZqhqlz3N4A7IG+abbiYcQ6+DK8jHI4M/OoihxreKJPGldL8EgBlIJ7xBrPnJ/Db4/TuHs+yThUec9gUPqD2zlnuesVFLaqAti/b5GKFP0NWmgGTT48aUG31/0891GdVzMIsYeOPXPGa6DpWny9w0a2Ke7M/JI1e7VEeVoA0qYtsev3r9msJg3sv4g6CAaj6NY7fzUXeCXj9W5hgXh+CHGgs1ynvOtWRs6S6gsbS9rrr1XCRosVmw5lt1RwGSLQhgpb3qnnmuX1e2Nc8/5q1UaIDOoWWeVFl9a9u9gtidGK/0B/KM= X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(39850400004)(136003)(346002)(186009)(451199024)(1800799009)(82310400011)(36840700001)(46966006)(6666004)(478600001)(356005)(81166007)(36756003)(82740400003)(40480700001)(1076003)(86362001)(36860700001)(8936002)(336012)(2906002)(47076005)(26005)(5660300002)(6266002)(83380400001)(6916009)(4326008)(41300700001)(8676002)(316002)(70206006)(54906003)(70586007)(2616005)(21314003)(36900700001)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: W18o46EMT9ydov2OlfEIon4j5zEAdsJ+z/77EUuKkb6nlIYFhk4dyVbHkWsHY0o21d6Vs/OXmoXGb23KVOYkwAn1+crR3ZPGjNGTCE/BgFKDsbWlr/LVm4NR3SksthELJJsnKnjwnVUUEDFX6qCniKGCTLwjIUEmgPH/mKS6sC/6AfhDG4z46cr3PgeomSXXMgL5/wLTtwpP1030L8E1VpWJuzavtu5Phu9EAp1FQ/hbESrZSC+tVJD5n3USxqm35p9x0WL1GIyHxUBq0PH5LjKegVMsCoojxeW97RO98XdzGuXJC6/vCulDIoOn2CbOsj/yUskOWWlvPtnZje0/CTkRv2099BIZ/Yd15tYa0iYt0mZSdt4lJXOhj4F6gyXJVtuCoOmET+S8SXh/0UY2Dw5TTn5wnOvDCsJNbW5U/nbT3uTCmDTL/wGpKOsdL6eL7JfHnCfLMUTlunltHXdPJiE3tLwK3DK7GvGIhlfeFwcV1ILslAc6heZeUAz3d2KVjGTvYX/phQIiz/Utb1QLuRyS8wAvlCI20S8dgeutQSKEaOjyPneenuH5pDfOsU85iZILIZvzx6t8wRsZG0qkJvd/2AK5epBORIcw+kwBWUHjNaSRt/bAR4o6nkzej/P/BzUvRmyU3X4xevrc+e/2o4IPIgeOh7NrhKngzL6RmEBnJATmX02UIlDkhSMREI+UosXMfsDqCtlX7fZdHxDldSC/bb6kOlwrHLy6kGTsSCWvG6JtrMLR71w3DSvETAjwdx6GpFuMY3ADMOGNRZE/QAaoFyO7aL+/xVnwGz3EH5bWt6/vartOvVx+DC4J2lzumxb25tjd1UQfNnZuHX6qHBd8C6mIJXfgBWZuFmTg/YJesR7CCi18tzGQ4BYgFzahdpz0CKlzWqgyJkzB3aVremiVw0oyLyorUJCgiA4QXA9PV3JfSCfWZXpoCDpVCSBn X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 17:34:54.2146 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1bc5f4f5-4091-496d-0aae-08dbb9ffe6d7 X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM04FT020.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR19MB4091 X-BESS-ID: 1695231301-104329-12361-15483-1 X-BESS-VER: 2019.1_20230913.1749 X-BESS-Apparent-Source-IP: 104.47.73.48 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVpYmpmZAVgZQ0CTNwDzZOMXYND HJyNjY0NTQ2MDM1Mw40dzI0MIw2cJYqTYWADlJN7tBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250962 [from cloudscan21-118.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Dharmendra Singh This makes use of the vfs changes and fuse_dentry_revalidate() can now skip revalidate, if the fuse implementation has atomic_open support, which will has to do the dentry revalidation. Skipping revalidate is only possible when we absolutely know that the implementation supports atomic_open, so another bit had to be added to struct fuse_conn, which is set when atomic_open was successful. Once struct fuse_conn has the positive 'has_open_atomic' fuse_dentry_revalidate() might set DCACHE_ATOMIC_OPEN. vfs use that flag to use atomic_open. If the file was newly created, the previous positive dentry is invalidated and a new dentry and inode are allocated and linked (d_splice_alias). If file was not created, we revalidate the inode. If inode is stale, current inode is marked as bad. And new inode is allocated and linked to new dentry(old dentry invalidated). In case of inode attributes differing with fresh attr, we allocate new dentry and hook current inode to it and open the file. For negative dentry, FS just allocate new inode and hook it onto passed entry from VFS and open the file. Co-developed-by: Bernd Schubert Signed-off-by: Dharmendra Singh Signed-off-by: Horst Birthelmer Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Christian Brauner Cc: Al Viro Cc: Dharmendra Singh Cc: linux-fsdevel@vger.kernel.org --- fs/fuse/dir.c | 203 ++++++++++++++++++++++++++++++++++++++++------- fs/fuse/fuse_i.h | 3 + 2 files changed, 176 insertions(+), 30 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 4cb2809a852d..aefd783c7552 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -230,6 +230,19 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) fm = get_fuse_mount(inode); + /* If open atomic is supported by FUSE then use this opportunity + * to avoid this lookup and combine lookup + open into a single call. + * + * Note: Fuse detects open atomic implementation automatically. + * Therefore first few call would go into open atomic code path + * , detects that open atomic is implemented or not by setting + * fc->no_open_atomic. In case open atomic is not implemented, + * calls fall back to non-atomic open. + */ + if (fm->fc->has_open_atomic && flags & LOOKUP_OPEN) { + ret = D_REVALIDATE_ATOMIC; + goto out; + } forget = fuse_alloc_forget(); ret = -ENOMEM; if (!forget) @@ -280,12 +293,12 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) dput(parent); } } - ret = 1; + ret = D_REVALIDATE_VALID; out: return ret; invalid: - ret = 0; + ret = D_REVALIDATE_INVALID; goto out; } @@ -768,12 +781,84 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, return finish_no_open(file, res); } +/** + * Revalidate inode hooked into dentry against freshly acquired + * attributes. If inode is stale then allocate new dentry and + * hook it onto fresh inode. + */ +static struct dentry * +fuse_atomic_open_revalidate(struct fuse_conn *fc, struct dentry *entry, + struct inode *inode, int switched, + struct fuse_entry_out *outentry, + wait_queue_head_t *wq, int *alloc_inode) +{ + u64 attr_version; + struct dentry *prev = entry; + + if (outentry->nodeid != get_node_id(inode) || + (bool) IS_AUTOMOUNT(inode) != + (bool) (outentry->attr.flags & FUSE_ATTR_SUBMOUNT)) { + *alloc_inode = 1; + } else if (fuse_stale_inode(inode, outentry->generation, + &outentry->attr)) { + fuse_make_bad(inode); + *alloc_inode = 1; + } + + if (*alloc_inode) { + struct dentry *new = NULL; + + if (!switched && !d_in_lookup(entry)) { + d_drop(entry); + new = d_alloc_parallel(entry->d_parent, &entry->d_name, + wq); + if (IS_ERR(new)) + return new; + + if (unlikely(!d_in_lookup(new))) { + dput(new); + new = ERR_PTR(-EIO); + return new; + } + } + + fuse_invalidate_entry(entry); + + entry = new; + } else if (!*alloc_inode) { + attr_version = fuse_get_attr_version(fc); + forget_all_cached_acls(inode); + fuse_change_attributes(inode, &outentry->attr, + entry_attr_timeout(outentry), + attr_version); + } + + if (prev == entry) { + /* nothing changed, atomic-open on the server side + * had increased the lookup count - do the same here + */ + struct fuse_inode *fi = get_fuse_inode(inode); + + spin_lock(&fi->lock); + fi->nlookup++; + spin_unlock(&fi->lock); + } + + return entry; +} + +/** + * Does 'lookup + create + open' or 'lookup + open' atomically. + * @entry might be positive as well, therefore inode is re-validated. + * Positive dentry is invalidated in case inode attributes differ or + * we encountered error. + */ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, struct file *file, unsigned flags, umode_t mode) { int err; - struct inode *inode; + struct inode *inode = d_inode(entry); struct fuse_mount *fm = get_fuse_mount(dir); struct fuse_conn *fc = fm->fc; FUSE_ARGS(args); @@ -785,10 +870,7 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, struct fuse_file *ff; struct dentry *switched_entry = NULL, *alias = NULL; DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq); - - /* Expect a negative dentry */ - if (unlikely(d_inode(entry))) - goto fallback; + int alloc_inode = 0; /* Userspace expects S_IFREG in create mode */ if ((flags & O_CREAT) && (mode & S_IFMT) != S_IFREG) @@ -840,37 +922,56 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, err = fuse_simple_request(fm, &args); free_ext_value(&args); - if (err == -ENOSYS) { - fc->no_open_atomic = 1; - fuse_file_free(ff); - kfree(forget); - goto fallback; - } if (!err && !outentry.nodeid) err = -ENOENT; - if (err) - goto out_free_ff; + if (err) { + if (err == -ENOSYS) { + fc->no_open_atomic = 1; + + /* Might come up if userspace tricks us and would + * return -ENOSYS for OPEN_ATOMIC after it was + * aready working + */ + if (unlikely(fc->has_open_atomic == 1)) + pr_info("fuse server/daemon bug, atomic open " + "got -ENOSYS although it was already " + "succeeding before."); + + /* This should better never happen, revalidate + * is missing for this entry*/ + if (d_really_is_positive(entry)) { + WARN_ON(1); + err = -EIO; + goto out_free_ff; + } + + fuse_file_free(ff); + kfree(forget); + goto fallback; + } else { + if (d_really_is_positive(entry)) { + if (err != -EINTR && err != -ENOMEM) + fuse_invalidate_entry(entry); + } + + goto out_free_ff; + } + } + + if (!err && !fc->has_open_atomic) { + /* Only set this flag when atomic open did not return an error, + * so that we are absolutely sure it is implemented. + */ + fc->has_open_atomic = 1; + } err = -EIO; if (invalid_nodeid(outentry.nodeid) || fuse_invalid_attr(&outentry.attr)) goto out_free_ff; - ff->fh = outopen.fh; - ff->nodeid = outentry.nodeid; - ff->open_flags = outopen.open_flags; - inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, - &outentry.attr, entry_attr_timeout(&outentry), 0); - if (!inode) { - flags &= ~(O_CREAT | O_EXCL | O_TRUNC); - fuse_sync_release(NULL, ff, flags); - fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1); - err = -ENOMEM; - goto out_err; - } - - /* prevent racing/parallel lookup on a negative hashed */ + /* prevent racing/parallel lookup */ if (!(flags & O_CREAT) && !d_in_lookup(entry)) { d_drop(entry); switched_entry = d_alloc_parallel(entry->d_parent, @@ -884,10 +985,52 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, /* fall back */ dput(switched_entry); switched_entry = NULL; - goto free_and_fallback; + + if (!inode) { + goto free_and_fallback; + } else { + /* XXX can this happen at all and is there a + * better way to handle it? + */ + err = -EIO; + goto out_free_ff; + } + } + } + + if (inode) { + struct dentry *new; + + err = -ESTALE; + new = fuse_atomic_open_revalidate(fm->fc, entry, inode, + !!switched_entry, + &outentry, &wq, &alloc_inode); + if (IS_ERR(new)) { + err = PTR_ERR(new); + goto out_free_ff; } + if (new != entry && new != NULL) + switched_entry = new; + } + + if (switched_entry) entry = switched_entry; + + ff->fh = outopen.fh; + ff->nodeid = outentry.nodeid; + ff->open_flags = outopen.open_flags; + + if (!inode || alloc_inode) { + inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, + &outentry.attr, entry_attr_timeout(&outentry), 0); + if (!inode) { + flags &= ~(O_CREAT | O_EXCL | O_TRUNC); + fuse_sync_release(NULL, ff, flags); + fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1); + err = -ENOMEM; + goto out_err; + } } if (d_really_is_negative(entry)) { diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index c838708cfa2b..3987046682b1 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -675,6 +675,9 @@ struct fuse_conn { /** Is open atomic not implemented by fs? */ unsigned no_open_atomic:1; + /** Is open atomic is proven to be implemented by fs? */ + unsigned has_open_atomic:1; + /** Is opendir/releasedir not implemented by fs? */ unsigned no_opendir:1; From patchwork Wed Sep 20 17:34:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13393100 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EC31C04AB8 for ; Wed, 20 Sep 2023 17:35:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229524AbjITRfK (ORCPT ); Wed, 20 Sep 2023 13:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjITRfJ (ORCPT ); Wed, 20 Sep 2023 13:35:09 -0400 Received: from outbound-ip7b.ess.barracuda.com (outbound-ip7b.ess.barracuda.com [209.222.82.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF87BB for ; Wed, 20 Sep 2023 10:35:02 -0700 (PDT) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2174.outbound.protection.outlook.com [104.47.57.174]) by mx-outbound17-66.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Sep 2023 17:34:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MGkuY5qLUu5DNfvr1wsNjH9mb0vOYgHnr6QuqrBhyqJFQu0PsSe3NYIeKW1jpB8MUf/VOwVe4o631FhVCumVx/jFtA/9UhAqdQlSO43ws+HVYHPqsoXfheXNy+I2O489atwZEPE/pnWNyXl0OWmyTA1z/vsgC6d9qzuT4+4YtO3foS91izp19ZpSQxmZTaDmAmjfpVKLuubUtqyQ4hADGMxNXTQiY+r/2YgtH7OjCa9mqwwcD6lo7swljaN2th4IeeNwe+wJS94HuyRSY7KlWK1Vv9z0nD/UA2g5qpHesRWxmshoG/qNyrqiYdIRnbeFP+EbgTS0HXkWBPDYOoXYRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZnAv9eSklNgUbvw+BCiAvWERywVGheoB8VOv6vhtePA=; b=PFkaZgxiRz663B6JQOR7gewXzaU0HdJmfxY3iqDpwmCdBJ0C9BxtattdDaZILQ0bz0mfwyJ3K7t36lVryC8CDydxQQzW/FQcJ8QLEqo2wG2sSlTAF8r+wZwk/AQFeGNWH/ueNAKLQetjFWCGHdVgNOS32yJ4r+Fcv9jxqiSFIdqG6dCELQNiUumk95a+nanDF02TLjbdhKO5ooBD1IYXO6cROi2Ywyh/znIGsjJSp9NW12lOde/vP3WlkEaSJl+2guoTps/rkkRhaFej+ucsdpcjrEEy2Vi9PjtPmobCkU2NwUr46qXsp+majs6BRT2qOLUEjxEDXFGQfnrrHtzyDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZnAv9eSklNgUbvw+BCiAvWERywVGheoB8VOv6vhtePA=; b=g9aYhnh6giucryiB51PEqb5csYvjvNROHGk1TaTt7SAuD3+iOGNjTQbdfI6hvJK1S6qtFR9GvS1VSSNe5VF6srNKc2hbeuSC891WQeQxdaEKfhytwvHAj/iy3sgPF/DcrAdQmUAQAjw+1nRqJR33uf1hJafMQomJgjtW6X4bqsk= Received: from BN0PR04CA0026.namprd04.prod.outlook.com (2603:10b6:408:ee::31) by CY8PR19MB7273.namprd19.prod.outlook.com (2603:10b6:930:99::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.18; Wed, 20 Sep 2023 17:34:55 +0000 Received: from BN8NAM04FT041.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:ee:cafe::c2) by BN0PR04CA0026.outlook.office365.com (2603:10b6:408:ee::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.29 via Frontend Transport; Wed, 20 Sep 2023 17:34:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by BN8NAM04FT041.mail.protection.outlook.com (10.13.161.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Wed, 20 Sep 2023 17:34:55 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 3C2BD20C684B; Wed, 20 Sep 2023 11:36:00 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com, Bernd Schubert , Horst Birthelmer Subject: [PATCH v9 6/7] fuse: Return D_REVALIDATE_ATOMIC for cached dentries Date: Wed, 20 Sep 2023 19:34:44 +0200 Message-Id: <20230920173445.3943581-7-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com> References: <20230920173445.3943581-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT041:EE_|CY8PR19MB7273:EE_ X-MS-Office365-Filtering-Correlation-Id: 2328f052-7e9a-4139-c539-08dbb9ffe760 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h2cSyGauaCe2hkOo1ebvxpqMCJIfqP7Bo+6UMhlLY636x+s8146UmchHLh31AM6okl7GF7pyPSNpa41io6GpSW8dlhmQ42zfw97UhNmrz/jaPHAz4RAyGO6EWdm3UFcdke++282q0vEkL1o7zZLdxLYorAap27Ae5vEHmwXPEkUthQTMa0e6jO86PpRpuQFYbOPhbu7C8zdzEWu3ZXucL6BSr36beBgXgjfV2gzYsZa15ApxI5lmgUzHdsKMvhTtkWbcnhD7wFqFcho+MjvYrMEPBiqUq+74j0ZS/sTYCsTX5KNhw7ugu5RK67H2LrFfCo5U6pjTTnXKpnBBjhKGh+CNh5jI3eq8W5JVUC+rWBbBPk3oZDO/TiIaE5vvsdKrDh8rdmu7nx5S7FBbCn/Qgj/I0dEGqyr0fFN20p0MVBINwMKJGtWi/5TeKLLI9GdxeWmG2bSwQSk3ELxJ4Tb+5fANb6KT4CodjiBKUe7BFHLCV79FEARDoL9j8QM1xbl6PPBMxs5pEgjgTsSDO4hmA54MwF9+RnWkSoj3DvQb7IPJIzP5roBcj2YuZQq/hmzk421L0mPmRB0iKKcRbzGZJnviXxhROok5089fNa731MnpTb+BvMNW1zLei003aOXZ1pYcXlnfPCWEsHi69qJHHiQE1MGApUg64Q+NPGaeGtLM8LjwzsbtnO39WA6CWjI701m41FWn2wO5z/eghG4E5mHGxsDaQdzfs2fUPpiZ93c= X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(346002)(396003)(376002)(39850400004)(451199024)(1800799009)(82310400011)(186009)(46966006)(36840700001)(40480700001)(70206006)(41300700001)(70586007)(54906003)(316002)(6916009)(81166007)(82740400003)(478600001)(356005)(36756003)(2906002)(86362001)(5660300002)(4326008)(6666004)(1076003)(336012)(36860700001)(2616005)(6266002)(8936002)(8676002)(83380400001)(47076005)(26005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: auN3agotPlK4nKXgO7H/0rdChuU05WnqpPGwd5iA9Mf5KIoHnGGyOoKm/sHuDoIOdIihzoq3DHCIP1W6DwgHUGt8YswSsdjuaqc3oHYeCGJLwaSswXARBQ/S6ifB7UsG/CL6MyH0PKw3+jdVlMzd6sbszJgoORHqqA/BVpTHPaGqzjmdpLB3++JCcyn2hu2kvRxrXJ3CH8KL+vrvu2DZ8hqzQLt+qDEC626k25lZq8uWbLVV5mQkr3gEAmqojvRBZ8SJP8e+Sa6qOR3wBNlp5dCJgrFrrzdV95jyd1ekbNRxfRLTkBhD9+OpkeWre7gwgktd9Ud5jPmSuBcRuZPrZ425b2pkiJl185Nyz9Czkp01Tc6MmGPdjRgdXB7jsjaIfrVFR8cPSJSgbXiIVybygWug+p1VTjU7g2Ez39oFdTo930EZUwuvzonZMSMiqdVKNi7GloR8E5xeQoSMN4jv9MLcjFv1CWqLv43ip5Zl6dBXI1QXyDeZmxBEAj91tpFtL0Ihh+ghrov8JuRYMcDHT9IrbmClRmHc6SsjdmIGTiNwvSQHm+42+3eK3dchVE9ZHuT3Z+Zd75rV/Nqbg/3g1HdjvAn+9mcu5K3soXdcG09fDv7BuB3Xpx8zLFCesjg4HvMfyg+ET7RGg1QlWvCMrY5FDXh+5MXRu/hE04gRsa2CH+/xImXH1c8dAeU6sysjpTWQpa5g75VvKsOOMamHW6xeG0cnuCye3KbMfpNrRp+0dcXtvDJTbUNiiqNLtLNIRw6ZFjfxIOxjacfSjXdk1aMiLV1T2tMphwN/Y2MGqz4604h3IkrKf8tEbVQlme+VnRL2DQngOWEvrvxACOsaioUBlpGxeHQBb43782as+o0= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 17:34:55.1485 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2328f052-7e9a-4139-c539-08dbb9ffe760 X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM04FT041.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR19MB7273 X-BESS-ID: 1695231298-104418-18341-14534-1 X-BESS-VER: 2019.1_20230913.1749 X-BESS-Apparent-Source-IP: 104.47.57.174 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVsaWxpZAVgZQ0NTE0MzS3NLQPN nUwtTE1CgtOdk40dwy0TTZyNDAwMRcqTYWAMcHNY1BAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250962 [from cloudscan13-242.us-east-2a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Cached dentries do not get revalidate, but open would still result in open + getattr, instead of one atomic_open call only. libfuse logs (passthrough_hp): Unpatched: ---------- unique: 22, opcode: OPEN (14), nodeid: 140698229673544, insize: 48, pid: 3434 unique: 22, success, outsize: 32 unique: 24, opcode: GETATTR (3), nodeid: 140698229673544, insize: 56, pid: 3434 unique: 24, success, outsize: 120 unique: 26, opcode: FLUSH (25), nodeid: 140698229673544, insize: 64, pid: 3434 unique: 26, success, outsize: 16 unique: 28, opcode: RELEASE (18), nodeid: 140698229673544, insize: 64, pid: 0 unique: 28, success, outsize: 16 Patched: ---------- unique: 20, opcode: OPEN_ATOMIC (52), nodeid: 1, insize: 63, pid: 3397 unique: 20, success, outsize: 160 unique: 22, opcode: FLUSH (25), nodeid: 140024188243528, insize: 64, pid: 3397 unique: 22, success, outsize: 16 unique: 24, opcode: RELEASE (18), nodeid: 140024188243528, insize: 64, pid: 0 unique: 24, success, outsize: 16 Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: Horst Birthelmer Cc: linux-fsdevel@vger.kernel.org --- fs/fuse/dir.c | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index aefd783c7552..e2c397e6e4bf 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -193,6 +193,22 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args, args->out_args[0].value = outarg; } +/* + * If open atomic is supported by FUSE then use this opportunity + * to avoid this lookup and combine lookup + open into a single call. + */ +static int fuse_dentry_do_atomic_revalidate(struct dentry *entry, + unsigned int flags, + struct fuse_conn *fc) +{ + int ret = 0; + + if (flags & LOOKUP_OPEN && fc->has_open_atomic) + ret = D_REVALIDATE_ATOMIC; + + return ret; +} + /* * Check whether the dentry is still valid * @@ -230,19 +246,10 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) fm = get_fuse_mount(inode); - /* If open atomic is supported by FUSE then use this opportunity - * to avoid this lookup and combine lookup + open into a single call. - * - * Note: Fuse detects open atomic implementation automatically. - * Therefore first few call would go into open atomic code path - * , detects that open atomic is implemented or not by setting - * fc->no_open_atomic. In case open atomic is not implemented, - * calls fall back to non-atomic open. - */ - if (fm->fc->has_open_atomic && flags & LOOKUP_OPEN) { - ret = D_REVALIDATE_ATOMIC; + ret = fuse_dentry_do_atomic_revalidate(entry, flags, fm->fc); + if (ret) goto out; - } + forget = fuse_alloc_forget(); ret = -ENOMEM; if (!forget) @@ -285,6 +292,16 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) } else if (inode) { fi = get_fuse_inode(inode); if (flags & LOOKUP_RCU) { + fm = get_fuse_mount(inode); + if (fm->fc->has_open_atomic) { + /* Atomic open is preferred, as it does entry + * revalidate and attribute refresh, but + * DCACHE_ATOMIC_OPEN cannot be set in RCU mode + */ + if (flags & LOOKUP_OPEN) + return -ECHILD; + } + if (test_bit(FUSE_I_INIT_RDPLUS, &fi->state)) return -ECHILD; } else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) { @@ -292,6 +309,14 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) fuse_advise_use_readdirplus(d_inode(parent)); dput(parent); } + + /* revalidate is skipped, but we still want atomic open to + * update attributes during open + */ + fm = get_fuse_mount(inode); + ret = fuse_dentry_do_atomic_revalidate(entry, flags, fm->fc); + if (ret) + goto out; } ret = D_REVALIDATE_VALID; out: From patchwork Wed Sep 20 17:34:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13393101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE566C04ABA for ; Wed, 20 Sep 2023 17:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229513AbjITRfL (ORCPT ); Wed, 20 Sep 2023 13:35:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbjITRfK (ORCPT ); Wed, 20 Sep 2023 13:35:10 -0400 Received: from outbound-ip141a.ess.barracuda.com (outbound-ip141a.ess.barracuda.com [209.222.82.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C162DCA for ; Wed, 20 Sep 2023 10:35:03 -0700 (PDT) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2041.outbound.protection.outlook.com [104.47.51.41]) by mx-outbound47-222.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Sep 2023 17:35:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R34CydF1KkaXZZaUBSBLf+HUz8FyiBBKnxig+wZxRs9TY07T80jMU6iZZidI3Q/ewBiocncM9SHTK7+zp8uHizDpweQyAQ5mzgHXfOeMMh5VZAujeFvXi4x7k8K0FvEPrR03e+zypP1WsnriygNnlP4RhkB627hJuKv9wsj/937fx0GBz++Wx0DcIhKXpj0zyDTh3cd25e6JMghE8Zz5G2/wvT5GElq2nSlcURCYbQKCB7J5/ePQLLl+EZ1uiq+TMJMdjuzKG6lfFPOS4sj/6zML6VkODJkJ7bzm8GNg6RGU1Zz2PiavqLEs0AQa1Vxiqo5XH+7aAWAYqIEOOZbsAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fQhiNYZxNCqIYSC0x3YMHHJRwnKRTwmTeDL54z9n008=; b=SuZCA1Cz7ljeDLKDFPYc7K107XnHiAab4ZNIT88IQ9IjHNCjoUsyBko7nsvMQM2gFgZaZtR5jUvX/OonQ3uV46nKv9V0lnaSYwMEEuTpyJyykQ/ifkyHC/xFGWbQcCLVtSOqxS85YCzDfyB+hB1jqdnLd0MLL0Yqm+OgZ7Y+4DHz55VdyvePbXxa7bMX1iHkYrhs8xGA1gxmuVRg6aczr7NTWfpgpySb7notOqrCDOZGqYuFT0L5NCm6IE7FooOHo0BTDHp0SxtuSSOiSoKoarC5lr1iSHVYotWndlA4LUze+1a3LU0bjvKDo1AkZWuo84p6AZpdheBFHbRjQG85LQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 50.222.100.11) smtp.rcpttodomain=ddn.com smtp.mailfrom=ddn.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ddn.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ddn.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fQhiNYZxNCqIYSC0x3YMHHJRwnKRTwmTeDL54z9n008=; b=gSlrPDP45DnOXPYkbA7i2bUQZ2MH2rLTG7iGJebS/9ls4U9nX07yYh0GbBNhPVEuECwkNRgSHPbhGdhYw6Cgr3rn+GwGGGMPDGFlYSajRTCKAvD43DC+D7sHWsG+vYaNR+McXpydRWzIAO1C2N0jaUr8xQhKb4XvL00o5BlRFdA= Received: from MW4PR03CA0240.namprd03.prod.outlook.com (2603:10b6:303:b9::35) by SN4PR19MB5472.namprd19.prod.outlook.com (2603:10b6:806:20f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Wed, 20 Sep 2023 17:34:57 +0000 Received: from MW2NAM04FT025.eop-NAM04.prod.protection.outlook.com (2603:10b6:303:b9:cafe::a2) by MW4PR03CA0240.outlook.office365.com (2603:10b6:303:b9::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.30 via Frontend Transport; Wed, 20 Sep 2023 17:34:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by MW2NAM04FT025.mail.protection.outlook.com (10.13.31.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20 via Frontend Transport; Wed, 20 Sep 2023 17:34:57 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 36DD420C684C; Wed, 20 Sep 2023 11:36:01 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, miklos@szeredi.hu, dsingh@ddn.com, Bernd Schubert , Horst Birthelmer Subject: [PATCH v9 7/7] fuse: Avoid code duplication in atomic open Date: Wed, 20 Sep 2023 19:34:45 +0200 Message-Id: <20230920173445.3943581-8-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920173445.3943581-1-bschubert@ddn.com> References: <20230920173445.3943581-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT025:EE_|SN4PR19MB5472:EE_ X-MS-Office365-Filtering-Correlation-Id: d5bbc374-2a7a-4d7c-f3e6-08dbb9ffe876 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /aF4PQ5mSc4QrSMFBdBs+N/g5r4yE/9bxQpgKo0DTgSTz0ipvpxKBIYlkQK97/i1BsQpgVjdKCfTqfxqkE4fN3sikzUAH6fpW5bYRiBOgeOdhPQ3tWTnwZcLcvCd4SJ+YJ0atKIKGDuNegw6jTUl6pockCJBNIi1yIBxAqd98k/PAOuFi0wTlwK+lt5Xa54aBD3ENMBtWbg+GIOr/ESEZrXuedNwcXQwdv0JxF+YsSOCvIPcW8Usy6vfC8zypj+iey50TToPsRV0o5NF2xZ6LVRuB9VBREEYyXzERgWGEjsMn3d6PeMlsH17Cm52nTCUNslxf4Y6eBFbz/zAa6AbmjZJ4q9CufI3nxspZw9bFW0+Fpn270XxdLbollKASy7qv0h950/qWrLTdh3oZNCjXJFceiEX2pp3GyuTsdwCuJqjyhI2N4sX9DoMsIl5d3ReroKlwt+bVdjumtsRlvabhfRoV4VftgNUd0E1KYVlmUsHnBQRpY0WmwUzfc/OH/aVwjuUt1rm8uG3ppvjPDikUjqvbkPSPBJNVDm030qNH/mVXsb8IweSrv99TQJBEY+6HZLaGwLpjBfz5coaPsbbRBQZR1tlV3hr24+omk3eqrVGKPDzr4uHqWK5dB+Cv3cdUJdrGzRrMMfpvCEVugyijyKLSOhJButD8ga2Q++lbcqsKpQrUcfrxkAGRdlvvP0dRysdJINVCK7vPMy6CdknTjxE6gm8oeG3oN7gEwQM+rVd8ykH5y+uIeRHAWtNj29jE49qZqBWXPPT6UmP+OBd/Q== X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39850400004)(396003)(376002)(346002)(136003)(82310400011)(186009)(451199024)(1800799009)(36840700001)(46966006)(2906002)(83380400001)(86362001)(6666004)(36756003)(1076003)(2616005)(478600001)(6266002)(336012)(40480700001)(26005)(8676002)(36860700001)(8936002)(4326008)(47076005)(70586007)(5660300002)(41300700001)(316002)(81166007)(356005)(82740400003)(54906003)(6916009)(70206006)(21314003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Hwvl/eH6eJM6+x7z/mEyCA4guQI3jkweL+BfBaWw2EjIe+eimQG+ganriOkVNlh/gb5FcRP+x0ucjqBiYN/Rq8jMBuMxDyj5SZgVHS9gqq9gK4OUHyjHMoe2iW5i7maoig5+eWdyXir15gnmCXh7ZkYXS3s9MmXUEjbbTD+57PuVXKkDSRT+ULt5ZxC/GOQyGBcMff+8+hbzMjAhPkpIk5iJXKWc9S+Pq8Mu0ntixdKVjxcjA8SsHIPq0qNRrjeNlYwz5/icMl64zuGTQtBPj15q4OtvE4BF6/HQW+A3Tye3JDSG+JeK+v/gkTDYeA6i+NxYOUSJ1QH6CusqVBWaSDhD9y5fls4GufjiBMnvguvPJu5JAEPHJdmEpC0/t+Nz/TggAuuPAWW5da6+iIliWE5+oEUK9vRf+GKLnmEV+NozHKE86M02QYdzD1saG410hphoewRD44G9dN9iNFo7sC9hN5U7AKEbVk6LUaLAZubmBAjKattiGWpiFq3CS8vL7UFW7inrZ1qJp87NkpuEYSgByslXfdjyKY58CuQUdAhqF5Gb9DHbgTN7B9t5NWKrWcdUhZ7aspVER8jdeu1j3RewdiZd5WgLYYUMDZgO0jXPMWqcO6nj9IrHTuJwfuq8mywOz8EZCRbJL5A0OgtAmTI6oNOZol2n7x4DjRYdEI+qKDUyo+6CYrfRXpO92NyN+iJ/mofA9pmoEQePx6TKoaUtoJoSnmfF1dmqNX2TVVQYpOmw2vVndWeBp6WCJGQ5h7AumsrJfryKttzFi7QZCNGbSB1kvX4QdLtRiz9NKGmYfGKQisJdK7KSiY/EDAD4/R/NiMc/h6ulbUovyvGy6Qc/H/bfGOVGAdP6W5+/LC4= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 17:34:57.0184 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5bbc374-2a7a-4d7c-f3e6-08dbb9ffe876 X-MS-Exchange-CrossTenant-Id: 753b6e26-6fd3-43e6-8248-3f1735d59bb4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=753b6e26-6fd3-43e6-8248-3f1735d59bb4;Ip=[50.222.100.11];Helo=[uww-mx01.datadirectnet.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM04FT025.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR19MB5472 X-BESS-ID: 1695231300-112254-12344-2098-1 X-BESS-VER: 2019.1_20230913.1749 X-BESS-Apparent-Source-IP: 104.47.51.41 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkbmxiZAVgZQMNHCLDE1zdzc0C DJMNE8JTk5ycQ81dI0JTE1yTw52cRQqTYWACKZhYpBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250962 [from cloudscan9-231.us-east-2a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The same code was used in fuse_atomic_open_revalidate() _fuse_atomic_open(). (If preferred, this could be merged into the main fuse atomic revalidate patch). Or adding the function could be moved up in the series. Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: Horst Birthelmer Cc: linux-fsdevel@vger.kernel.org --- fs/fuse/dir.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index e2c397e6e4bf..4e285af2f17f 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -806,6 +806,25 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, return finish_no_open(file, res); } +static struct dentry *fuse_atomic_open_alloc_dentry(struct dentry *entry, + wait_queue_head_t *wq) +{ + struct dentry *new; + + d_drop(entry); + new = d_alloc_parallel(entry->d_parent, &entry->d_name, + wq); + if (IS_ERR(new)) + return new; + + /* XXX Can this happen at all and there a way to handle it? */ + if (unlikely(!d_in_lookup(new))) { + dput(new); + new = ERR_PTR(-EIO); + } + return new; +} + /** * Revalidate inode hooked into dentry against freshly acquired * attributes. If inode is stale then allocate new dentry and @@ -834,17 +853,9 @@ fuse_atomic_open_revalidate(struct fuse_conn *fc, struct dentry *entry, struct dentry *new = NULL; if (!switched && !d_in_lookup(entry)) { - d_drop(entry); - new = d_alloc_parallel(entry->d_parent, &entry->d_name, - wq); + new = fuse_atomic_open_alloc_dentry(entry, wq); if (IS_ERR(new)) return new; - - if (unlikely(!d_in_lookup(new))) { - dput(new); - new = ERR_PTR(-EIO); - return new; - } } fuse_invalidate_entry(entry); @@ -998,26 +1009,13 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, /* prevent racing/parallel lookup */ if (!(flags & O_CREAT) && !d_in_lookup(entry)) { - d_drop(entry); - switched_entry = d_alloc_parallel(entry->d_parent, - &entry->d_name, &wq); + switched_entry = fuse_atomic_open_alloc_dentry(entry, &wq); if (IS_ERR(switched_entry)) { - err = PTR_ERR(switched_entry); - goto out_free_ff; - } - - if (unlikely(!d_in_lookup(switched_entry))) { - /* fall back */ - dput(switched_entry); - switched_entry = NULL; - if (!inode) { goto free_and_fallback; } else { - /* XXX can this happen at all and is there a - * better way to handle it? - */ - err = -EIO; + /* XXX Is there a better way to handle it? */ + err = PTR_ERR(switched_entry); goto out_free_ff; } }