From patchwork Fri Aug 11 18:37:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13351319 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 52D28C001B0 for ; Fri, 11 Aug 2023 18:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234425AbjHKSio (ORCPT ); Fri, 11 Aug 2023 14:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbjHKSin (ORCPT ); Fri, 11 Aug 2023 14:38:43 -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 AD16630E5 for ; Fri, 11 Aug 2023 11:38:40 -0700 (PDT) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2171.outbound.protection.outlook.com [104.47.73.171]) by mx-outbound41-67.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 11 Aug 2023 18:38:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jJcqX4g4rHAvJgLol5nxTj3zuggsOTkHXyO0G2AOxu6yxqZ24rfwwaeKeu5rjTWJf/Zb2fFF4C5KvYCAZZGOBGgkHRwiRjuWz7TsTBVkdWCHRG542C+PvOVN3uwa7bYjh9M9Us1mbPGnjmxyimuXwBIYnlmYrpCjxr7AYJe4wLhiwi79UbpK9s3yC1W2P6O5mxwuRWq6FYb+NsuMAXeAoL80nRdkRX3NxXHv/yvpJLk/j/F7pXHI63hQoT58pl4kbTQuxpI0KO58y8nWXYl/BVHYKNPDswidwb9Y19nlnpu3EAhthn+WH5j/xsFUoIDgGBkQfNxby0Qeh3gMLIvlKg== 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=QbUdR33arxc2Sp/fkeK4Lwp/Ej2JA2nuRcPsROJXg6s=; b=Ec5vu3oV8ESfH5ilG1Yhe16fa0enbXgYPFHNXiirlAzhcS6H3NuGcZ2XHtAF/Nw5yeycLzqyIl7IsvYo4QOFIUi7GsPgDlc8VCcFrwtzPYmnj4hYI/BS2DWFxysqas7dCNVMzjmPsvqQ2B6Jo3OsrHjx6OCOpb3z9zW5dKmK5btBEtgBZS1xCxuqC793Yc9eFocOwWNxv+SjIhG94jp2cvbJKIKpCfunlDa7pqV0XmM/nOeUuMJaEzCpElMah5S69SFit2szeGPqwUYQEJ/G9LbNrc7OvXHSNyl6zVXvhPGikioJzUTKs3/7Tdn3+iDz1V659gj1HNy1wUoNvi3TrA== 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=QbUdR33arxc2Sp/fkeK4Lwp/Ej2JA2nuRcPsROJXg6s=; b=YnJWtIY3V1dp+M9hbLOHy0r3n5p9Vfbk8MEbPMef7hWR9L7aJN0DCPGk2puPXpn1JfWyln0qD2ViNlO2uY2gsKntvz61lwXVblzr5Tc+V6oWeruONQa49cci1DBm8ZlSm3oFhqroIZXXnMurI9L7whPeLS1Y6gARNC3opUx4vWg= Received: from BYAPR06CA0066.namprd06.prod.outlook.com (2603:10b6:a03:14b::43) by SN7PR19MB7844.namprd19.prod.outlook.com (2603:10b6:806:2e0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Fri, 11 Aug 2023 18:38:24 +0000 Received: from DM6NAM04FT029.eop-NAM04.prod.protection.outlook.com (2603:10b6:a03:14b:cafe::45) by BYAPR06CA0066.outlook.office365.com (2603:10b6:a03:14b::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28 via Frontend Transport; Fri, 11 Aug 2023 18:38:24 +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 DM6NAM04FT029.mail.protection.outlook.com (10.13.158.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.19 via Frontend Transport; Fri, 11 Aug 2023 18:38:24 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id AF87C20C684B; Fri, 11 Aug 2023 12:39:29 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, fuse-devel@lists.sourceforge.net, Bernd Schubert , Miklos Szeredi , Dharmendra Singh , Horst Birthelmer Subject: [PATCH 1/6] fuse: rename fuse_create_open Date: Fri, 11 Aug 2023 20:37:47 +0200 Message-Id: <20230811183752.2506418-2-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811183752.2506418-1-bschubert@ddn.com> References: <20230811183752.2506418-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM04FT029:EE_|SN7PR19MB7844:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f353a76-8dae-4b14-db7b-08db9a9a2583 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OYTR0aV7/GArTVzkZlFZv9D6ZDsfPJOwMKAVTg3XvaXinezP8F/HjALcvCnK+a8dymeXhrE/XLpM5mjGen+69hMPuVPqZgmGhYJHtY552uq/sHjBXZ52bh8TZtFatFroQr+qlj7sMSWbeQ41j9ALtE/2SH/KAQvcqtRfv/9ADUlOkUyTgsA9tV5x0U3RBqop6b73YHrGPbYwhSu0pvf4k7/F7MRB4Q0Wa8HzIbwEdmbMR4eQzpkCckhZ+3+6T80gWxPvjCloJLIfCj7Ae/ZtVfiz3cTulwPVw4UYc7uCIv6HQHYKVATK/rmSETAiD81YR3xo2hQ17o9j5Je+Ha0ciB9/qdcFjkBTApFr3TUq8LBue1iLY3QS1ZYZo9pM68vBtkpWLVm2C2bHuuN1DoLk+A/FLpnldUvkTdxuYwc8zc21BcITOPAXWxA5MKp/wWs1NNs4+Wt43wSrxKb30d2z3OmraEMPBHypbrc+BcOfvk/Wc6rlPvciYQjGlHBDZuZJ1iyCjqg+yUrOMidqxTV3bf23+3CLyQ8UghhWiP1bDdJagbOke49Tt9VpXUzlr5NsVJw6l9ADqaDtvCUKqU2FE8aPgA0XMs4o20b1QWxmZylLVuVzUg3ylbZcLcTpCxDwX5YE19H3dJBuIJGQrcASAUWhqAKVsgpsuXN1c6r7x1RWk8JP7LULsBYVMS1DfMmKyDJoOMJaZ7s+4Gz08CS+4X0+xqeUtAzapnKQnoRqw/aM5dQoGreA8qvdoBR6v4hS 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:(13230028)(4636009)(136003)(396003)(376002)(346002)(39850400004)(451199021)(1800799006)(186006)(82310400008)(36840700001)(46966006)(2906002)(83380400001)(2616005)(41300700001)(36756003)(6666004)(86362001)(54906003)(316002)(6916009)(4326008)(70206006)(82740400003)(70586007)(81166007)(356005)(36860700001)(40480700001)(47076005)(5660300002)(336012)(6266002)(478600001)(8676002)(8936002)(26005)(1076003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: XWiQLMMozoQBHpDTbE6BhWevsVoBC8kszyWJWY16TmMkw3ZF5nkJ2b8MwcQnNYJobt4QEGkj6uFp+VVe+5Ra0qkPLZK4cIPvqLSPdsRnoVOSVC0uQ6i5oLgMv3as21LM1yiG/D7vFeYCQenQhwAIpzvxLEJrNuGpJ37I4ZlxrRlBDdjXghYEi5hD5PgNiPkjI7boDxJCwXWlqF02+pC6nKb9PSsMhJbO+NAqT6Sk0wh+DuLESDNUVmqPTTl53O/YdHsy8pn67OvovVxuzdAXGY0gTL07vBi08DBoZLBu5yTDnW/U9MPKefRE6zhO1CzB+Ef5AXD1B7h38xQcr8cDO44XNk+m0ZGaXno7zIWDNoD0HbIsJ33W9aHfn0Unnb9GvLBX+iv+gyHp5u76AZyU3FqbC+pFdJV+j9qSxIaWxl0gBbEY3TuXZPRlzeWMczG10/s/9pnE30hEgJlMCRqEoZu8wsEIHWNY+9tDLPiDOsPPK/eIC0UTsSTf2tqsqU+y2F9nSAdxawCmb4hpiA2gmAhhrkUQz7WNytoMG/9ISlMvxyWeESNN0H73PujAgGgKzS9wDGV7Bmy/3smLYgpOiqMdJsz4L+o20hCS9e6g/lXbEvTw9BXJKFWhKP4nTSci/u7gLVaBmwkDDXEMalLzm+JKlUGrpJTbBeViFuYygeSKcJKjuXyBtjN97NshY/4hPBgFtZ6lhY2X5NEWc2K5oBcWEL4k8m2kZZWgfeE9kORLILKoFJoRB+l4J1fHE3SlCG8wCu0y27RgaRFU579hPxKuhayrWP/tW9FQwf/tTuYceeF8HSFJ6IMnt6Ebas+2UPgeAXhc7FxpEU7PZiqZyOBDjVugftbeY5efLBGwqIQZXt3GAucGwExMB5olT+dIgOPwLRdRBeWYu9Dy9S0gZeiYyJgQ257r8eTDr0zwdvI= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 18:38:24.7315 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f353a76-8dae-4b14-db7b-08db9a9a2583 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: DM6NAM04FT029.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR19MB7844 X-BESS-ID: 1691779106-110563-12432-5431-1 X-BESS-VER: 2019.1_20230807.1901 X-BESS-Apparent-Source-IP: 104.47.73.171 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoamFsZAVgZQ0NjILNkiLTXNIt HU2NIsJcXSyDTRNNkkOc0QyDYzNlKqjQUADsiY/0EAAAA= X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250079 [from cloudscan17-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 Just preparation work for atomic open. Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: Horst Birthelmer 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 35bc174f9ba2..6ffc573de470 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -613,7 +613,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) { @@ -753,7 +753,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; @@ -879,7 +879,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 Fri Aug 11 18:37:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13351320 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 8FF48C04A6A for ; Fri, 11 Aug 2023 18:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234892AbjHKSip (ORCPT ); Fri, 11 Aug 2023 14:38:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230287AbjHKSin (ORCPT ); Fri, 11 Aug 2023 14:38:43 -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 153BE30DC for ; Fri, 11 Aug 2023 11:38:39 -0700 (PDT) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2103.outbound.protection.outlook.com [104.47.70.103]) by mx-outbound19-176.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 11 Aug 2023 18:38:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lcJFSt/XIvaF4qqUSKFPWKkEJo6RxL/ANAGtOiu0SyhGhQAad1sJrllc7bp3uqcZFtUcwb/gq80XBtN7Ki+jut4CRWTNy/Ka4eZ+N2g2FZtob7pyFFnCZQdBU1W0SuBpCppNLGV+v+vg74/aDLEllfuTL4X4hlZMets0hft2II64TdCN2xNURIjl4qMPsyRbN6LfOwc6zXCPI1bLCtCmnRIhyhOFz8sJ+PVi/LQNuJILV8QZ+IWOBrHQeKyLjh52Vh9GerjurQTygukUt6Y6gYtgbJynkPGfFgjIhjH4zaQiPrvGCHRM3VZVASVjX5jKVBAmj4VoG5tX3WIITmi61Q== 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=NDgiDraLOqUY0epzpyLv4XeGEfNhSHKb/QaFImf7jks=; b=KqD+VJXFUAVO2ENaYgNHcjDT+84qalrKuJ6ERnw9dUQm9evzU8lUPd8nbC+b+Pq5T5rPysuctLH5MmRLKw55pkCjYn+BZEirzBSFF3EsC4kXfzWxIHsrw0h7FQIkFmNlIXEjPCXDdTrlg0lw/5Rv+TzJ0IeRIPJc6NNGdKWKa+5uXOzW+GnmEaYuKk0r2ww3y2DuGCjKRzv/nEx2Sj6qZsrOpf9BPhdZy+VFEYYhjSFMT0jgiS7v1s/7A+C166GP41sBKB2LJuu3mSp9cxr3ol7o/3gwEzvgEXnrpM5H5AfkKQMSUhj4h1qr0EPFHN8r8pK7ClFlA3wl1tiC6HghOg== 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=NDgiDraLOqUY0epzpyLv4XeGEfNhSHKb/QaFImf7jks=; b=xGKY2zHEU/4tDkR8uaUCKwBSSK91jnYxpS8T8PvcaWsheMzRSfP3/HeERLBSVEG1ZVvaRe7a0HPWFHAtQfrnPOQUgmbuWBvYuvIKWbfzyRTEb0ALT25njAJV1b5gQAwinAIXqTk3dWepJbVoe2zSBVbAB/6PrSWaarnVLPHriB0= Received: from MW2PR16CA0032.namprd16.prod.outlook.com (2603:10b6:907::45) by SA0PR19MB4459.namprd19.prod.outlook.com (2603:10b6:806:b1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Fri, 11 Aug 2023 18:38:26 +0000 Received: from MW2NAM04FT063.eop-NAM04.prod.protection.outlook.com (2603:10b6:907:0:cafe::7e) by MW2PR16CA0032.outlook.office365.com (2603:10b6:907::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.31 via Frontend Transport; Fri, 11 Aug 2023 18:38:25 +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 MW2NAM04FT063.mail.protection.outlook.com (10.13.31.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.9 via Frontend Transport; Fri, 11 Aug 2023 18:38:26 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 9601420C684B; Fri, 11 Aug 2023 12:39:31 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, fuse-devel@lists.sourceforge.net, Bernd Schubert , Dharmendra Singh , Horst Birthelmer , Miklos Szeredi Subject: [PATCH 2/6] fuse: introduce atomic open Date: Fri, 11 Aug 2023 20:37:48 +0200 Message-Id: <20230811183752.2506418-3-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811183752.2506418-1-bschubert@ddn.com> References: <20230811183752.2506418-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT063:EE_|SA0PR19MB4459:EE_ X-MS-Office365-Filtering-Correlation-Id: bcdfdece-5489-403e-711e-08db9a9a26ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: smQa4Q+WWrIRYMn9Afb5WHQ+ZrQLdzLR0l04zpGaAjx7NHNNkJrCSzAvho4T3J6SxvD25fD7tWbet2KBo7aCSp9Mokjd+ZIPi5puhJpFcuYy92j3Y7MjUrh/p770kvqaMQj/kkfBwTgkptbCMud3B1nJy3kXgWk4vlUwSCgHK2/fmf7HeKT/mwznt2GG/XLZXZ3OUT6l0Usnfriw2PiR+PUEL9Ss7L7sLaQXcP1flo+1QquhMNhEHLEn9EUgwl/UTCCkMj6JefjYQsSHhgq/6mq9vFYlrVpzP59PV83COdVLSzOMwFqpiWTKOdPz0UUSqAqwO39nVpJZ895Uk2YlcePoKCepBhvBrSM3zdwxHOExDmDYRqhmETbxHNl5lGR8Go2cvSXL0k52DX9nS4G51aYFM6+DMQ7SmKoCIHdusj/3zHNTcx05E/C4R/CRXFUdc0VdzsCbXIQ3Ck6IJGABIn2zDwsA3VXkuvK57naQlRPR0hHZuYeeRvyoy0pRhWP9bKCeWf1in54PcEZgHjVXUKXdA6iXYxbVqIQsDO6hgEd2cRwGvD6/4ZRcxJu+6Gl+R2/ZxmnHuzlzZ/Exyww7t2RIq5RLRFJ6DS4DYf00GwV1CeHU+XKpzWpzQI4uVXaGDwqg5Gh0RdrB7NXbw8DOzLzfz8mgDYee6RMQQoYiDtWmhF3/CwqINNBSfb6rLIyhJ/BJKibWUIalyQZRFVfE1ZhrXRuZsUIkGCz0Ou7axrWRRMIkOZRanl1fLM7SKCKW 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:(13230028)(4636009)(136003)(346002)(39850400004)(376002)(396003)(186006)(451199021)(1800799006)(82310400008)(46966006)(36840700001)(6666004)(478600001)(6916009)(70586007)(4326008)(70206006)(5660300002)(316002)(54906003)(41300700001)(8676002)(8936002)(26005)(1076003)(86362001)(82740400003)(6266002)(336012)(40480700001)(36756003)(36860700001)(47076005)(356005)(83380400001)(81166007)(2906002)(2616005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: IJX09dwLLi5yS7jm0gge7xlj6oVxmZkyE0eS+B3YGnCfeqjfJz3bPgGA//LfhLPsyYsyp+paEJFbYl3fyvMU4PU8Ig2NVpp5Ju9uVbQGSVHJTep60zisWodgJWW2oxAa9UmNMtulFduMGa78HaV0EbHryJv7M5SsfOkCfgQ0z+ZIvkiDftAquFZ7AZYqvMFwD6E9W+3NjKK0ADJ+0a7gpdd5iiMhpVmvg55hjBp7TiHIHKs3y3XSmofyyR9jFmJcNZVBaUbzjIUy+M0xL2CWTowkdiTWGtNKS+7ITOGaK2jpcNY+FvhooYYjiLDWOxVPqKskw6v6lOMU1BcXm1FXwGizJgxiJ3HUR+j1OFx6QlBfbrvfwo+PnVGJDvDHxjLi4z59oqZpq5ecbYrfjGalzyflR3T/TKpypa5NjywXV8kH4QeTFerZdWHGBQB4kC2DuzMlu6EHxCcmNThMN6fNVJ4YrImrJr5vF/FOuN+WAQaGImmFWxoQpHiBqmECJS2yEXZjJ3wGCwAfZYCFAI+wgJZ64aq0gJ0kj5tjPnDUf7SGFvzLOae5r3SzRdzkmVbGMpoNnAiqXvNMBBNTfB6LaX1EtJATw0FaNhw8BchNFySX6CJu8qTJ1fENkmIntUE6kJ4XjrS7P+Lsp4uXYLBWMFkt+4fY80M/CSx586/HdYyGE3n2EEoOXcvE6bFyfYP+tN+LJzo4rjmrzhPGBWXXfQH3HfWlhOFWkP4stumDEeweFPR/7KXjbdrVM7djagW79kmHE/b3QinYK/VGcgMQYFihXy/sElonXR67gn9bm3e57bBLDNcarA9ptXESWV3qhI2oQejYYrWb3Lq1b0OPlAH+jIwJQ8igXk61wFfQNhlMrH7uMhcrHEdLvC+nYNubcpLAyEXtubnxGZ8jVgYafp2G+SDbM75yY0ASa6xCZcM= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 18:38:26.6661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bcdfdece-5489-403e-711e-08db9a9a26ad 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: MW2NAM04FT063.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR19MB4459 X-BESS-ID: 1691779111-105040-12337-14224-1 X-BESS-VER: 2019.1_20230807.1901 X-BESS-Apparent-Source-IP: 104.47.70.103 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVhYmZsZAVgZQ0DIpNTklyTTF2D w11cQ4NcXQwjI1KSU1KSkl0TItJcVQqTYWACsuU7tBAAAA X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250079 [from cloudscan11-179.us-east-2a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, 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: Dharmendra Singh Cc: linux-fsdevel@vger.kernel.org --- fs/fuse/dir.c | 222 +++++++++++++++++++++++++++++++++++++- fs/fuse/fuse_i.h | 3 + include/uapi/linux/fuse.h | 3 + 3 files changed, 227 insertions(+), 1 deletion(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 6ffc573de470..c02b63fe91ca 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -724,7 +724,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) { @@ -770,6 +770,226 @@ 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; + } + + /* modified version of _nfs4_open_and_get_state - nfs does not open + * dirs, fuse doe + * nfs has additional d_really_is_negative condition, which does not + * make sense as long as only negative dentries come into this function, + * see BUG_ON above and missing revalidate patch - but needed if + * we are going to handle revalidate + */ + 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 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..4e2ebcc28912 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 impelmented 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 1b9d0dfae72d..ee36263c0f3a 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -314,6 +314,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) @@ -322,6 +323,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 @@ -572,6 +574,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 Fri Aug 11 18:37:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13351323 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 DDDADC001B0 for ; Fri, 11 Aug 2023 18:39:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235184AbjHKSjE (ORCPT ); Fri, 11 Aug 2023 14:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235573AbjHKSjC (ORCPT ); Fri, 11 Aug 2023 14:39:02 -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 2731230E8 for ; Fri, 11 Aug 2023 11:39:02 -0700 (PDT) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2175.outbound.protection.outlook.com [104.47.55.175]) by mx-outbound46-215.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 11 Aug 2023 18:38:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cdlF8t4+bGQPhO3ZHjRoLGqo9jXpyFCivgcPHQbc7z1XHMC0sydpkHcldEZN9SO6sn1Y7qc7Bse/DNTUztvQIVtbYlfXp2wn7z9IV9CEsEKxk0W2ENBo/5E8wmZ5IbfrlE1y0/cSc7rgGcbr80joAX1vgGFkEyhugmUFy44jgrwmmxdPKxwLtS30Ls3RC//6ZEOIShn0d6LjShMhsKL0NsDSnPn2pZItju6LTAqfj8dBvLBsoBrqbqV/OwsqjF2ofbntutGmwE5YbxTcj4U1MC2sfNd3c43nhCh42yIio7tROSC0KqsyDywiqS8ECKB9tGt8kMyaBt4Ef1zZ1zphgA== 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=hc0gZidMxZAsC9qVDHsL4I2niulPDO0WSv/kjqbSjBk=; b=ZVPD6+Zzt13XjAMzM9rsWypz0m7g3zn2FSnhxPIkn++W8x8V7dhC2MGjSedmL6XWy2qGgNb4hMgwljpfletux5yGF01yzPmkf96dlq26CvYda0Nu1nW7lzC2iCboccrM3hvqwachik6X8kwh0TEpxGHc6BUP3qg/BRzek+IBwNvcbfhIsj7TZnN4jPtnJVJRCRObXhJOkDBSzKIVkhymB5u8FuOyZzp5m3StPtgcc3/6qJ2Tufr2iPcjCJtrN4Y3EOzE1dQG8rRqTeXFW+IypMe0UUjCIae3Bojds8bpkknBYCoy8tz2Fc/Haw9FUXhDzMeI6j1EZv20KLEStaiJTA== 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=hc0gZidMxZAsC9qVDHsL4I2niulPDO0WSv/kjqbSjBk=; b=0yXm37mSFg6QeF7+qWUVBTl7yNUvNRPS2X6Q1qZQVOULsLXkaOJqP8ucENB2sTgOOGj4b1B562ROMPntErqFACN6veSsTiuVnvEeTGTsqpXgrV83103bL5H2rA0iNCvyRTTrWwpmIP7upUBNu3brvWnc5frXbMJM0iR4vD2k5E4= Received: from SJ0PR05CA0036.namprd05.prod.outlook.com (2603:10b6:a03:33f::11) by PH0PR19MB5504.namprd19.prod.outlook.com (2603:10b6:510:129::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Fri, 11 Aug 2023 18:38:28 +0000 Received: from MW2NAM04FT062.eop-NAM04.prod.protection.outlook.com (2603:10b6:a03:33f:cafe::2) by SJ0PR05CA0036.outlook.office365.com (2603:10b6:a03:33f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.18 via Frontend Transport; Fri, 11 Aug 2023 18:38:28 +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 MW2NAM04FT062.mail.protection.outlook.com (10.13.31.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.10 via Frontend Transport; Fri, 11 Aug 2023 18:38:28 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 7F54A20C684B; Fri, 11 Aug 2023 12:39:33 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, fuse-devel@lists.sourceforge.net, Miklos Szeredi , Bernd Schubert , Christian Brauner , Al Viro , Dharmendra Singh Subject: [PATCH 3/6] [RFC] Allow atomic_open() on positive dentry Date: Fri, 11 Aug 2023 20:37:49 +0200 Message-Id: <20230811183752.2506418-4-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811183752.2506418-1-bschubert@ddn.com> References: <20230811183752.2506418-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT062:EE_|PH0PR19MB5504:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ba2034b-9d18-4472-40b0-08db9a9a27cf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RAq5FRTS0PV5gE1gBdU+rVvn4Gx8LqwugdtkCDnzEi8Cd6RU3F90Q45Uhm8VBj5+F7P6x6dN/6cnZ9+Jh9TERLW8q6D1vVIQMYXehNOdN+0RHnePMz56RJ5KafcLUOLocJKWqbNFbDQSe0r64x5E83z/QMYc0EeHPAcsgsC6KxK/GTfJcenJYexdt7h223HO9Q6i8FWjkAzqR4vBj67w77KS4rT6RTVmZf3Fi1QuQ+/KqONHh1NXpr5WMXs/2XUo/xDEJNbsUSd6zhhYk5qbDPucISMDeNuvkxJMebcVAcrtRL8sJvQeKO0P3yhFIP4BUBhB4lGQM9X4Oy38cailY+aEB+WqP/aGvfzG8/7FRtw7PPdOkoyoj13cr3QVE6saQjWPf/0PvK6LJXJoXZVvkZ7+asz0O9+QKTygvnvJfkZji371oFQ/gxfmb+2wwvhT2n04V+yIi88k6du1fttrDZhke6tsKg35y3kgkZ9+V/t7jUMjd5K5OKIGG0KsGBLAOGojbbGC7ZQc3ay21XZA0VbzYSKnuMwer+/cFk5wIlcphIFglKFGrRlpTK0fbPbsuAdbwF8+FUCgailkhfZtiPxkzlY+zyjjx+Y6bNqXivBUVgkUVvE4hRBtysVLCng07irlxg+xEr1W4TGGodcKo8u+sjubcwxgsa5n4x8H6e8U4O6NfnKi7pze099Y7xrb0vFt0snoX84+/HteCCW5Eh1KZMQg/GRY0ndPvaTUB4FeHtt0AafXphFfsw5kd2JF 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:(13230028)(4636009)(396003)(136003)(39850400004)(376002)(346002)(186006)(1800799006)(82310400008)(451199021)(46966006)(36840700001)(83380400001)(8676002)(2906002)(2616005)(41300700001)(47076005)(36756003)(336012)(6266002)(40480700001)(5660300002)(1076003)(36860700001)(26005)(8936002)(86362001)(54906003)(82740400003)(6666004)(70206006)(478600001)(81166007)(356005)(316002)(4326008)(6916009)(70586007)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: JP/VzyqUjDykciOBSMpk43VIM/OwVjJkUv6CuzfaTG/N/V0L4NSAhohdZ8iq7iTZPPAerVz64QEEbj6eIxtO+8d6oovoe6ChMciFugj4+KU2+E8q/XOgC4DQ962qHVeRywSDTAF6bks0pEUTyZx1zsniIYyL8UjadzaZPlQEFv50C1cfsILCLGq7wHKYBqPLHhGPENk4nX0EzAKdNxhAyFIpJaGQ0w8lJ7boelwvgY4blHaiM2XQuH6fACtrE/C8JtImupopvLuMv3biAWAEIENsfRjCXkxZZWdYp2K02W438wsfRkrtB4hJx3Z0tiDU78w2xTB3gddYHg+WVkonddizoNyyztzIfXngvehlBnVpTa7Ie0mAeWf1q407eGioGhJheFtd5fqniKioiu1pDnFdHQe/ktqcZRt3a1AX9/D621TR91HofxZf5EC8IGQiHqT54XGrPdbDCjaZUVahHNWxhK0ItVPds3AQxf9ntXkrmUV6JUvI/s7FspPPS6mlhiAK1SMahE6G2EpgyMp3Cw0WUM3dgH/m1mK43MxwIeBPBSxZvFen3WvH2uhNVMedRl62HtFCzLePFsXBjHLpfjp12qdcp4viNFWlGtQ06wOqh1Dsp4lkxshQ9+o3ZQv8uirCus2ZfiIFtLn7ejuRN34bfsXX7+/SD9Fmnuc+D3ILIgRLd9kwurMOX7mRFUrvdj1PlFzLQ7R1sEmdLA+5F63vgAnjlSFuGFKfrd9sJEPtRQBxlLTc6+mN7ZXjbvxutZm0L77cN6LZql6N5g/iKv1HDzNH3fQSr6a6vIb24dRQfacCQXoSDnTSXP75vKrF4zxk/luoQlIDrUY2Vw59KJv3fk0jNeaAe4OBmLSSqew9bRG6tUWcwxkhgsMGLZ6BMtB86WSNv95KD4n3WAgOe5HAo/dEjlYnnziFnD4WxSw1Tk9T0WwyMwDUf2R4f1Ayrw5O/VRCUjjuvTJemGpRtzOMumvzfdkM/KzG0e0P76B+zmbpHwIuSpPDA94QiVW4 X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 18:38:28.5810 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ba2034b-9d18-4472-40b0-08db9a9a27cf 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: MW2NAM04FT062.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR19MB5504 X-BESS-ID: 1691779110-111991-4730-9748-1 X-BESS-VER: 2019.1_20230807.1901 X-BESS-Apparent-Source-IP: 104.47.55.175 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVqYGhpZAVgZQ0DLV2MAwJS3VMN kASKQkGhgnJ5sYmhqlpBqkmZqYpCjVxgIA5uQW2UEAAAA= X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250079 [from cloudscan21-52.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: 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. Changes from Miklos initial patch (by Bernd): - LOOKUP_ATOMIC_REVALIDATE was added and is set for revalidate calls into the file system when revalidate by atomic open is supported - this is to avoid that ->d_revalidate() would skip revalidate and set DCACHE_ATOMIC_OPEN, although vfs does not supported it in the given code path (for example when LOOKUP_RCU is set)). - Support atomic-open-revalidate in lookup_fast() - allow atomic open for positive dentries without O_CREAT being set. 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/fuse/dir.c | 5 ++--- fs/namei.c | 17 +++++++++++++---- include/linux/dcache.h | 6 ++++++ include/linux/namei.h | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index c02b63fe91ca..8ccd49d63235 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -380,7 +380,6 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name if (name->len > FUSE_NAME_MAX) goto out; - forget = fuse_alloc_forget(); err = -ENOMEM; if (!forget) @@ -771,8 +770,8 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, } static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, - struct file *file, unsigned flags, - umode_t mode) + struct file *file, unsigned flags, + umode_t mode) { int err; diff --git a/fs/namei.c b/fs/namei.c index e4fe0879ae55..5dae1b1afd0e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1643,12 +1643,14 @@ static struct dentry *lookup_fast(struct nameidata *nd) return ERR_PTR(-ECHILD); if (status == -ECHILD) /* we'd been told to redo it in non-rcu mode */ - status = d_revalidate(dentry, nd->flags); + status = d_revalidate(dentry, + nd->flags | LOOKUP_ATOMIC_REVALIDATE); } else { dentry = __d_lookup(parent, &nd->last); if (unlikely(!dentry)) return NULL; - status = d_revalidate(dentry, nd->flags); + status = d_revalidate(dentry, + nd->flags | LOOKUP_ATOMIC_REVALIDATE); } if (unlikely(status <= 0)) { if (!status) @@ -1656,6 +1658,12 @@ static struct dentry *lookup_fast(struct nameidata *nd) dput(dentry); return ERR_PTR(status); } + + if (unlikely(d_atomic_open(dentry))) { + dput(dentry); + return NULL; + } + return dentry; } @@ -3421,7 +3429,8 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, if (d_in_lookup(dentry)) break; - error = d_revalidate(dentry, nd->flags); + error = d_revalidate(dentry, + nd->flags | LOOKUP_ATOMIC_REVALIDATE); if (likely(error > 0)) break; if (error) @@ -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 && !d_atomic_open(dentry)) { /* Cached positive dentry: will open in f_op->open */ return dentry; } diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 6b351e009f59..f90eec22691c 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -208,6 +208,7 @@ struct dentry_operations { #define DCACHE_FALLTHRU 0x01000000 /* Fall through to lower layer */ #define DCACHE_NOKEY_NAME 0x02000000 /* Encrypted name encoded without key */ #define DCACHE_OP_REAL 0x04000000 +#define DCACHE_ATOMIC_OPEN 0x08000000 /* Always use ->atomic_open() to open this file */ #define DCACHE_PAR_LOOKUP 0x10000000 /* being looked up (with parent locked shared) */ #define DCACHE_DENTRY_CURSOR 0x20000000 @@ -496,6 +497,11 @@ static inline bool d_is_fallthru(const struct dentry *dentry) return dentry->d_flags & DCACHE_FALLTHRU; } +static inline bool d_atomic_open(const struct dentry *dentry) +{ + return dentry->d_flags & DCACHE_ATOMIC_OPEN; +} + extern int sysctl_vfs_cache_pressure; diff --git a/include/linux/namei.h b/include/linux/namei.h index 1463cbda4888..7eec6c06b192 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -33,6 +33,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT}; #define LOOKUP_CREATE 0x0200 /* ... in object creation */ #define LOOKUP_EXCL 0x0400 /* ... in exclusive creation */ #define LOOKUP_RENAME_TARGET 0x0800 /* ... in destination of rename() */ +#define LOOKUP_ATOMIC_REVALIDATE 0x1000 /* atomic revalidate possible */ /* internal use only */ #define LOOKUP_PARENT 0x0010 From patchwork Fri Aug 11 18:37:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13351324 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 AE4EFC04A6A for ; Fri, 11 Aug 2023 18:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235573AbjHKSjE (ORCPT ); Fri, 11 Aug 2023 14:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235419AbjHKSjB (ORCPT ); Fri, 11 Aug 2023 14:39:01 -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 0AC9E30E7 for ; Fri, 11 Aug 2023 11:39:00 -0700 (PDT) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2176.outbound.protection.outlook.com [104.47.55.176]) by mx-outbound17-57.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 11 Aug 2023 18:38:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oYeqqIXEDpjFKx1/X2OdnCemiptv3lqQBrMIfEMh0tDOR2OXBrVvI2QS/RaYZHj1iwNbwjDQ0N6cwLMLGEH3KlXFId6tMWlPTo79ujY14e7CE9JiVzIeBeyN9E7nKHN193Eu9LLw1HiExxWYcj507j5RUO4LV7zxBDVJkXtFLsbSCePhQVKFnr9c2rq6YReQPbsbMD6u28nBt9bweIdRZ0YD3zYVc3LBNwYGQtAGmvBNLTk3wROGG6tJVN3hodtNvPHdzhkGWxM5sDMWt/c65hSfY7WYwSQgtaGneDw1FG3dHnLZa3tad/epdyg7RRgicev9pyRsW9bPGsYflC5wYg== 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=11+XzhLqiLXWB1or4dSmzijzIMduABGC9Fp8Ebs+XAA=; b=S8QflNj8F4cloZXMJcmMSQDmUJmt6/M8rTF1lIrwbJ5Hm4c3wzF6s9hgxAHn+OSXJ4OUlPoOdOFL6o36+Fb5tzOX2sT6I8QRZkh3gGojv10p283oh2GYFuptO/r9duEoBwhZUv8cfqA0thEGclA7zR+uKrOXi/r5LbZn7rUtq7sTbkDFMmHpNtiPZyE9Hw/LdVESi2fG7sFbIYsvQj8D+riHTNU96Qko5xqVnyYkwq56gBz2tfKf/Efw+ipIJdbJHH73yQ9ILvKrCtfdr/+zkHPnpC5NZ8c5aJ1WvfEC1QWoRCGeoChM/OuM+vK+QfinU9bfPxaH/7p98mFQ7BKx9w== 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=11+XzhLqiLXWB1or4dSmzijzIMduABGC9Fp8Ebs+XAA=; b=vHXttL4XMehVi1AMKFtWCKDXzjeFMI6CoEvhSSdOvEtCWi5Tr63yqecYjENoS5yzU5i23ccM01YBj8QMqpLKMjCxgP2fb2MK6CFlve2OMDMDcEg7Ar8ehNEaPFeSlqxuL1npEuTJaoDuMuPX3Brm0pK+CEvfjm0h887zeDn7xuY= Received: from DM6PR11CA0039.namprd11.prod.outlook.com (2603:10b6:5:14c::16) by PH7PR19MB5992.namprd19.prod.outlook.com (2603:10b6:510:1df::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Fri, 11 Aug 2023 18:38:30 +0000 Received: from DM6NAM04FT015.eop-NAM04.prod.protection.outlook.com (2603:10b6:5:14c:cafe::1) by DM6PR11CA0039.outlook.office365.com (2603:10b6:5:14c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30 via Frontend Transport; Fri, 11 Aug 2023 18:38:30 +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 DM6NAM04FT015.mail.protection.outlook.com (10.13.159.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.9 via Frontend Transport; Fri, 11 Aug 2023 18:38:30 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id DE1AF20C684B; Fri, 11 Aug 2023 12:39:35 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, fuse-devel@lists.sourceforge.net, Bernd Schubert , Dharmendra Singh , Horst Birthelmer , Miklos Szeredi , Christian Brauner , Al Viro Subject: [PATCH 4/6] fuse: Revalidate positive entries in fuse_atomic_open Date: Fri, 11 Aug 2023 20:37:50 +0200 Message-Id: <20230811183752.2506418-5-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811183752.2506418-1-bschubert@ddn.com> References: <20230811183752.2506418-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM04FT015:EE_|PH7PR19MB5992:EE_ X-MS-Office365-Filtering-Correlation-Id: bfb2e3cd-0976-4086-8c3e-08db9a9a292c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w1lz89mPoFrdCqA3urE85gKlh6MXmiulIrLMPt1D3F7ErWx3AOXxQn8lVF7Pn5aBmYSE13cTNYTaZkNeUFcuguHf40WVbRtK0l+I4nRGjejtf3s8B4XUlVcfBVvcUoMCfh4sKz5qQ3GtbEhGS5PPQJah6EkpyGDSzaEaBI6h4gIuVQIhIcPTUF0WECvV8hAc/xxdafa864NMbEaip0qfKrRwhvBRywYMAE8otM23TDbXfiRcHFeqP5iAvg7F+cVF2a8rEo/N82nPmoraGavBvBzQpoXPvULNpY3LSEirQgGzFzEVLCU3DWF+R0mAweruOXmtBlg2Il2ar8LUZSPoyTGaTkLetQibG626oNX6kE1b9Hvp0AivxiYPTPFsIS4L4Ds+dgGfcy+ebEIucJhdcIDpz5+xLzYAJGpGkbS7p9WSl18gS4JoO8yyLHVpIuvoJaLgtaHyThj327gPFr/ybd7kZFJFza3KILsVY2cAvl52J5VzQgkeQcdhkP+timL5/bHFA8ukCCrlXv+ZCrw0/5Bisj+VaI3596k5hXVA7iY2Jnx4zg4icUvsnJI/TvwZspOp1NhmDfuIRP4uXPqT6UKXakYhnjw1vBLpHo2d+lQiQcKWvK/V7GdDsfSt1Si4R+3qO+7/F0b9AJNidWR/pRE3h3/IyXCwD73V/CjcTuP+9JZA+21KJHLO7ae+ZBubNBRrC58mhz0nmyYRcr2JOsB+NagyvZSUz4oc3j4A9QS31K8fBiG2qFlEAUFRy+yllrA181uxYwIqmj+GQLYJ94GdI/NIRY/ZXRWLpW5IoTI= 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:(13230028)(4636009)(39850400004)(136003)(396003)(376002)(346002)(186006)(451199021)(1800799006)(82310400008)(46966006)(36840700001)(2616005)(6666004)(356005)(81166007)(82740400003)(36756003)(1076003)(26005)(6266002)(336012)(40480700001)(5660300002)(47076005)(54906003)(4326008)(70206006)(36860700001)(70586007)(6916009)(316002)(2906002)(86362001)(478600001)(83380400001)(8676002)(8936002)(41300700001)(21314003)(36900700001)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: GAKJkdc4sW4CNwi9ysQEpAJQkDoFZSyKLCH9P5k1ZOXgsJJjxkPBfisQH18cGcuK0BqInfzQ9QviPVuODNI5JU9spNbbys8nXU93BydRNEzC7s418TKAjVXHiymhHujiS1cD3gUgq42+MTqT8PhSS09u0gBkZk2WNk+M0C6v67CtBCP+tDrlKo7kvIo73ytmpHIid6gEGRXcZUr1TmmcjtBco7ZZsK7+Tq9okL1opXOzEuhzycb+bQJ4NwT1ofQIgMn0L9D7dqkf5WrSduDGtOs/kiCxxqzhWcGH7BkrlqYdspwOxyeTnSUJK94B+VEMlnvR850+jctUCQXqJtMwwrEeW+FphCtZQ2RfA7YTjX2Uc4nFVF6w6TdYicy6jJJbmBrMfllqziZjouedKqkM2jaG+j9/XfvxizJPkIeMBdN5QtVTHSfql6Qsg2V8i2Lx1R9XQaQfCQb63lioJ9dekWNzZbZr0boB3cD7E7yptkIJ7CVoVpQhp0eGzCMP9y6zpfnDxAHSQn9+CO8YCgmDZYJe5F/t8stwUIjj1qm8XW8HiC/HbrjpOL+QRnuTEGhcY7thYaClBHdHgezMh1OJLFIkncOYIVtHzPX+Gw24Q7RoFCgVGbXzdEhmTsD3WvJPR5/cmAVPNNGnsfpoe3lXCttyUoVAz16cQ9E9r+gJ0DH1yPv3orKeAVJT0cs4Lyb271ZEzCgclFO9cD7X4GX4K8XWPbtC+dU5PVOokJ7s6aiCrTVpTb5EzTQrwtTcwwduxrgVU1LgVElXGoLv7yMPXKV8qcX53MyqGoStK3wgmlgdYCntkxJNvvLra9s01E3ifQzP1MRn7fuYO7Fun07Ecsjd2j8wGtd57KAP6U5oiBm3ZPs4T6vkBA0ZkIdXLNqXc1IlIWc7i15DyR3YnDZ1Kba2BmvnKRsfeHKUtneRO9E/TPsWZxHbPZ6PAwwDBTtE3F7jyAf0mIhFnMBzz8OIQyXIgb6Y8t9yfV72uE1KBQo4aAHsWFXxKSldMWFYf50V X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 18:38:30.8702 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bfb2e3cd-0976-4086-8c3e-08db9a9a292c 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: DM6NAM04FT015.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR19MB5992 X-BESS-ID: 1691779113-104409-12512-5345-1 X-BESS-VER: 2019.1_20230807.1901 X-BESS-Apparent-Source-IP: 104.47.55.176 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVpYmhmZAVgZQMDnJIM002dQ0Jd nMwMQo2dLUMs3YwszA3CDNJDXVLC1JqTYWAIz8b7pBAAAA X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250079 [from cloudscan19-167.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, 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 | 207 ++++++++++++++++++++++++++++++++++++++++------- fs/fuse/fuse_i.h | 3 + 2 files changed, 182 insertions(+), 28 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 8ccd49d63235..d872453a6cd0 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -230,6 +230,24 @@ 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 && + flags & LOOKUP_ATOMIC_REVALIDATE) { + spin_lock(&entry->d_lock); + entry->d_flags |= DCACHE_ATOMIC_OPEN; + spin_unlock(&entry->d_lock); + + ret = 1; + goto out; + } forget = fuse_alloc_forget(); ret = -ENOMEM; if (!forget) @@ -769,13 +787,87 @@ 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; + + WARN_ON(*alloc_inode != 0); + + 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); @@ -787,10 +879,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) @@ -842,37 +931,57 @@ 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, @@ -886,10 +995,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 = PTR_ERR(new); + 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; + } } /* modified version of _nfs4_open_and_get_state - nfs does not open diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 4e2ebcc28912..c0da4fce1a9c 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -675,6 +675,9 @@ struct fuse_conn { /** Is open atomic not impelmented by fs? */ unsigned no_open_atomic:1; + /** Is open atomic is proven to be implemented by fs? */ + unsigned has_open_atomic; + /** Is opendir/releasedir not implemented by fs? */ unsigned no_opendir:1; From patchwork Fri Aug 11 18:37:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13351322 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 ECF5AC001DE for ; Fri, 11 Aug 2023 18:38:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235154AbjHKSi7 (ORCPT ); Fri, 11 Aug 2023 14:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbjHKSi5 (ORCPT ); Fri, 11 Aug 2023 14:38:57 -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 D69FF30E6 for ; Fri, 11 Aug 2023 11:38:53 -0700 (PDT) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by mx-outbound12-57.us-east-2a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 11 Aug 2023 18:38:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UUEvV0MMTSGWyFcv6yCYWgB63qeZEQinGC3d413EHF0wD+RwpR+DxKCBxc9Et7HwLH2feoLmWqz5N4105EE86/FRN3oEp/ofN/bLKdmAYrmfEs0LvGRwN7an4B+QymsMDG09O94+b2LHRUff9tToUQgAsMCMCwi+2yXkQa/XZ9txDiUjPNR8uwi7bJcxQnr3+GYu79MiPUbr6MJ3CFhKL28GZAfVhVPtQe3vA/pgFeTUrDhHNlAMbdNu5maUPEXkrZ+ZFzyrBotvxe9KZwXWOEc3hoPc7FRSWNph1VchI6TjkJ1Rw1WKLuiakUvLRmCeZEJJ72WdIisJnlvXIkd32A== 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=2ahHQLBCIo4xLtEMkDJWK0ZnYsbNe0wNTUzEIwRRe3U=; b=T5c2KjJAcVUTHfDShYgNS/LeNEnFnubHmo+rYsV7TYpW2QM/Uc5DauOTL5mA8bWiO2OyUhpcsiQHjv9osNyXXuRX76gfVyoTaR54+cBOPpat2WqQirletyz233liLYrQG9UF4tBd2rAZobDqVHl1ew73QUkVD09NA22M8PxP2PMr+/Q7A8+fbXKBmhj+nMjn7/YzIYaKSKccv4b3X4XQsh9c7OKhPcrli0/k5cqVktVcHcwEr6w++b/3+sC9n1OiO2kG7vYDhfP18cMmKsZnEbO36oaGOMgmXFh6wyspr63VzjlqTMD33jyE6+Nl4Xmr1Sim+gwEVBOaYTBC8Vvz9Q== 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=2ahHQLBCIo4xLtEMkDJWK0ZnYsbNe0wNTUzEIwRRe3U=; b=uq/IIVJlovk/f6qqMuO+SvRVsyd9uwynzIblqP5Qy82xF2SWY6sXvQZI0RSSCCRJAPeayjCXrZBuIhNPIEWci+PDqImcVJ9dyxS2FT2UYtCa+BbNIgMxPcaESpUm2et19ZYqJTDyQtpZky8xhP3r5Xsafuoq7Vqng6yRD33xAtc= Received: from BN9PR03CA0285.namprd03.prod.outlook.com (2603:10b6:408:f5::20) by LV2PR19MB5885.namprd19.prod.outlook.com (2603:10b6:408:174::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Fri, 11 Aug 2023 18:38:32 +0000 Received: from BN8NAM04FT003.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:f5:cafe::a0) by BN9PR03CA0285.outlook.office365.com (2603:10b6:408:f5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.31 via Frontend Transport; Fri, 11 Aug 2023 18:38:32 +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 BN8NAM04FT003.mail.protection.outlook.com (10.13.161.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.20 via Frontend Transport; Fri, 11 Aug 2023 18:38:33 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 036D120C684B; Fri, 11 Aug 2023 12:39:37 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, fuse-devel@lists.sourceforge.net, Bernd Schubert , Miklos Szeredi , Dharmendra Singh , Horst Birthelmer Subject: [PATCH 5/6] fuse: revalidate Set DCACHE_ATOMIC_OPEN for cached dentries Date: Fri, 11 Aug 2023 20:37:51 +0200 Message-Id: <20230811183752.2506418-6-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811183752.2506418-1-bschubert@ddn.com> References: <20230811183752.2506418-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT003:EE_|LV2PR19MB5885:EE_ X-MS-Office365-Filtering-Correlation-Id: f1a64fe3-1e84-425a-8e3c-08db9a9a2a91 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M4tGFFXltK7oWflCwVXPDh8zMvOvVp1DlFvfGmh7J0Jerg40XHhn8+U1SXBwiYSm1jK6USE7YhPDtUYGS5ZurPW3hu6WZeRaWyuUgR6Phe7sVFMThYOSA/YnbsVcO2vyWOC2dpifcteIooe+OCLy8LqDd27mzHPeyUU+BORfGfKfsqG67yilkM49hkvpYi1XKAuLzUSb+evzWIGuuECZAx7NDDAXtIX20oncFQVgB49eAXEQgrzM6QV/dGu2cp+5CJW8cOdSD/87Y8k+6RKkCxrX03VeQ75YP/ShedWNp6k6wFw/smvgS7p9SsE6Iy1vv9r0hl+Wy/2jULP5GfTlg+aiNVmVnyKxQSNGa5BQ5FHMThUtWV+ad1bHeQDr0pgGBagjhbxUP3y8CbSwPMPE9jJL9TZ9QEK4tnxYA1ss7Q3yGw5pnVmK0bdxIpzrlNz2nXE/0AkU8btVlrqgSpQ/mJwQdxlxqtuuXwaTGd4JNqcy+kLb65nCB759snxjDBCOloGSXBdpaE5Uw22smaOFOTGyLyalDeZbqwA/4tEwfnymMQkgsDx7f9JVKOyT7+fjBAyrozMSIkZ1X13cCSiOIwb6J4D/Y4miCLkzskxcUi8cI6NYc4GYYkUUebjHFdW4w1EHyawk25uWFyMEEzJm47KJW8bdupn5OEz+vMbk+XIfJWkp625KUrL0szo+08ZEl1qKg7vd4DB7svk4v9kRgGDV+Tn4UCFBtBkUtF1cXUQ= 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:(13230028)(4636009)(376002)(136003)(396003)(346002)(39850400004)(82310400008)(186006)(1800799006)(451199021)(36840700001)(46966006)(2906002)(356005)(54906003)(83380400001)(1076003)(26005)(86362001)(6266002)(336012)(8936002)(2616005)(82740400003)(47076005)(81166007)(36860700001)(40480700001)(478600001)(6666004)(36756003)(70206006)(316002)(4326008)(6916009)(5660300002)(70586007)(8676002)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /BLItIcmWb6sAPbcvjXzcg1GVo7A9hmsE1pDelNUgM5zJrhcqenuVrlf+zhsYLI/FKTcMPInB7wQpU3zPD578UlWSM7gs7zmCyjobxkr5aLPyb1bty0f+0n+Cb9bTZCmyQJ7H7NxFJVdYPeHm1E5sb5oJbuAj0LkAhMJ3NQ3tBMACs9r3rgoID0k9WjSZgnU2KY07Lo31CtLWsM+NSte/I0r7bUcyHhLq2sCtrvfJwDVbrPOqUAtSux/WKlYtECOHOOuX4um24fShPinO+VAHJshAeEsYvKVMb0jWsAe1hkVgLtbbQTXHSyZmYZnFgpa+XM/c3j+dOjz8+TiKnEHwdnwiip5yn5xfYY1v1dcJCRfsI8+394xfc3LejB1IPH9baOaEhSDmqJ3uXaeSqgvVr81PvlFC35jbR0SqPMcQQ2U4jTkSI+V9O08ofk4nPNFct0lXpTgJrH00VdZ0VyriGHdiLBh0lsn8Qo8JxwcbFI8aA4Nq5v4ukEBB7U2gHUYZAKw8zp7rRN2QSxUMw96nR3dWO9JLo5T6NlIHuRBDGFOFUxRa0aISU7FhbhNEQvIXwdxXZ2KZdD9ZpXfn+wcr4w0ImpM9Wvgqr8Xz0IFEkJGtIlFDqmlrVybh3szRBWkElp8DXjetDvRZjGbFEOP5Y7YVnjRU1Vece9m3owzNhl25oT3pPHNT5SC0hapkZctnrx1AP7/AFmDq8jATxRcvClYmFGslAPT37V1ZQTZaHv77/RgmZIDbYNSPpG2A5/Sq0TzEaUAEM9/4WpCjcRmObuZwu16jjoXDtYQ4pHPmdpMqrVLEC3PYPpsLfgIluusetK7eHEzYiNYKeEwYveicnVGeA7frP5WGFn5nJ/0tzIk2ASV0StpZyi5wqcBXxZ7RdfDjVioMxeJWEFlM0aL5NnHhX6II3XkxUm/l5PM/J8= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 18:38:33.1630 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1a64fe3-1e84-425a-8e3c-08db9a9a2a91 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: BN8NAM04FT003.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR19MB5885 X-BESS-ID: 1691779119-103129-29064-6501-1 X-BESS-VER: 2019.1_20230807.1901 X-BESS-Apparent-Source-IP: 104.47.70.101 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKViZmRgZAVgZQ0NI4zSg1xSzJJN XAyNLM0NQgKcXU0DIx2dLEyMwgycRMqTYWAORVPT9BAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250079 [from cloudscan10-134.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 will result in open + getattr, but we want one 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 | 58 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index d872453a6cd0..067e1a2fb23a 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -193,6 +193,25 @@ 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 && flags & LOOKUP_ATOMIC_REVALIDATE && + fc->has_open_atomic) { + spin_lock(&entry->d_lock); + entry->d_flags |= DCACHE_ATOMIC_OPEN; + ret = 1; + spin_unlock(&entry->d_lock); + } + return ret; +} + /* * Check whether the dentry is still valid * @@ -230,24 +249,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 && - flags & LOOKUP_ATOMIC_REVALIDATE) { - spin_lock(&entry->d_lock); - entry->d_flags |= DCACHE_ATOMIC_OPEN; - spin_unlock(&entry->d_lock); - - ret = 1; + ret = fuse_dentry_do_atomic_revalidate(entry, flags, fm->fc); + if (ret) goto out; - } + forget = fuse_alloc_forget(); ret = -ENOMEM; if (!forget) @@ -290,6 +295,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)) { @@ -297,6 +312,12 @@ 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); + fuse_dentry_do_atomic_revalidate(entry, flags, fm->fc); } ret = 1; out: @@ -943,11 +964,10 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, * return -ENOSYS for OPEN_ATOMIC after it was * aready working */ - if (unlikely(fc->has_open_atomic == 1)) { + 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*/ From patchwork Fri Aug 11 18:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13351321 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 642B4C001B0 for ; Fri, 11 Aug 2023 18:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235078AbjHKSiz (ORCPT ); Fri, 11 Aug 2023 14:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbjHKSiy (ORCPT ); Fri, 11 Aug 2023 14:38:54 -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 34AD530ED for ; Fri, 11 Aug 2023 11:38:48 -0700 (PDT) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2047.outbound.protection.outlook.com [104.47.57.47]) by mx-outbound43-95.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 11 Aug 2023 18:38:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Znf8A3G9FfzFlBCh+A5RjsuhLX4ZnKxul6hiOfx9eHaIeIuC0M1q4SsJcjXfYobSeaddizLupd768mLOuoPGABX1Fhol+CNOijDhL4oidCbixKGa+hMU7WQXNVBQb1yL8wSC+63vcpedUkx+MzIhq4fRoWQaQQ8hSfCQbygYNlXE46bRMc+zRdrM9nDVVimewQG9eR/IuiOidwcd/pi5fQoYp0HKkPE8c3QiXT8mab3uBj3tbFbUlZqM8frjMvrM+vmluhHIoHmpk/ROs74XA7DkyGDREjOoyhdrjKYu5cktCkj1W/KGtotD5E68BObqrx6NowvC4eGebqxAQj7rWQ== 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=kKjyBGRmHM2FO5O+kc+f/LscX/QoRWAM5KBI78zcvtg=; b=Q2HdhZAjKjftoNjuYKqaOqWlKVypSy66LEXe+q+4cRs3Z2X48auUvqRFTDcRO5yXiU3tAlnDHX1ZQWJ1/G0dJrhuvnjJjJYyF54ouI88zSy82K+LuPuU2yJqEcADkcAxJLbFgwIze4Cseh8B9IJZJJ7dIpdLK/SLbcg7n7+96kOpUPmpnV02U/T2KhW2PdulcVuDr5rpL6aX7ScdS80wQsl0ulNm+9K0vcpRoTK7ASLRvvsFJlg5+hevZCTn4C3/GGzGvwWjYH96O3j3VlQIlI7+eOWIdgKVVWGslDIfXBL2JvSfjcBgRPaCjY8L9ntridfFc7UjfZhUeXFGZW4PAg== 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=kKjyBGRmHM2FO5O+kc+f/LscX/QoRWAM5KBI78zcvtg=; b=S1/G/h4T8VsvEEG+Mupx06mlOUEYMCuiAFuVRptuF2OEVpSIgfRa1/gacCAQEIF7edQQx1vBHjqiC7ypry741Ki64OJKF/tdNBh21XG9Frmw3MazWleiHbY5rxP4rt7D7JtHvU2GgyTUde1cSIBbnCUQfY6r0zx6XT90MuqivEM= Received: from SJ0PR13CA0193.namprd13.prod.outlook.com (2603:10b6:a03:2c3::18) by DS7PR19MB7723.namprd19.prod.outlook.com (2603:10b6:8:d9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Fri, 11 Aug 2023 18:38:36 +0000 Received: from MW2NAM04FT026.eop-NAM04.prod.protection.outlook.com (2603:10b6:a03:2c3:cafe::87) by SJ0PR13CA0193.outlook.office365.com (2603:10b6:a03:2c3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.7 via Frontend Transport; Fri, 11 Aug 2023 18:38:35 +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 MW2NAM04FT026.mail.protection.outlook.com (10.13.30.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.9 via Frontend Transport; Fri, 11 Aug 2023 18:38:36 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 8574420C684B; Fri, 11 Aug 2023 12:39:40 -0600 (MDT) From: Bernd Schubert To: linux-fsdevel@vger.kernel.org Cc: bernd.schubert@fastmail.fm, fuse-devel@lists.sourceforge.net, Bernd Schubert , Miklos Szeredi , Dharmendra Singh , Horst Birthelmer Subject: [PATCH 6/6] fuse: Avoid code duplication in atomic open Date: Fri, 11 Aug 2023 20:37:52 +0200 Message-Id: <20230811183752.2506418-7-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811183752.2506418-1-bschubert@ddn.com> References: <20230811183752.2506418-1-bschubert@ddn.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT026:EE_|DS7PR19MB7723:EE_ X-MS-Office365-Filtering-Correlation-Id: f5b0a06b-5096-4ffa-e21f-08db9a9a2c99 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VoMxg/okmLJHafduNZttkb+p8sdEqMHlNqHBDWTbGzG7IkmZxG/B8uR9xFHEoUjydREaxFRzSY4Fr7ZaVHC1gaWUbjwPiUBO5jzogm/5b97XJgdqrvP1H55ZIs7f020fl7YXQ91KmJIe3oLDG/0T1QWzF1noU9BG8Ma+OayCJvVDzrfWGOUcl5jeWNhAISqtw5HxSE10zRJC7A08r2K4hmgyPTwqipcNqoauvCBsUpCbFJi4uCGvCoGSNGeY27kvesKslZUgpky9I1WqpUal8qqcKSI73b9qcZPITsA/bHzqGRPaQpLBIMAAmohZWqNl/e+p4VDu9OqSTesoZ8LFcxrSWXQQ0wTjfINI2X7ZKXj0HbuMrkt0F5oUhlRE7PEY0KmApr+0Pe8ZlomYb3ILDPlWdjhZPuT3qYX0ckCfL8fKUwskvHoos4ZRwLL/AvGidwnDUc2zaobCFxvKX+KZodiO/ie6sv0UauLaO2I5CZvC/nEFXIqSwayrTRykPzQcHb7IWpCQ1RB/Iiub7KM6ZHmYHHqmMs/BoJCrhj8gJXU3IYl7H2KL+8HTqCrADLcWR7Jd50Xo8DN4zpb+lTbAAnay1ruZcFmVe42b7fCrWm4FyBsvoOinBfwlcyCzOLVYNrzUIpPlAnVrY3iQa2+ZezZll6IEYhnza8lFTP5wTUaArYeqU6165jILorSt+kFQV3iQxCYHVEg+DK5v4hSPAK5ZqDMY1stEKRKee/4qMYiE0f8yy1uFOv42h09NmljMq1IkyYbqN4HgRb25cRE91w== 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:(13230028)(4636009)(396003)(39850400004)(376002)(136003)(346002)(82310400008)(451199021)(186006)(1800799006)(46966006)(36840700001)(36860700001)(2906002)(54906003)(4326008)(47076005)(70206006)(70586007)(6916009)(83380400001)(478600001)(356005)(86362001)(82740400003)(2616005)(81166007)(40480700001)(316002)(8676002)(8936002)(5660300002)(36756003)(41300700001)(336012)(6666004)(6266002)(1076003)(26005)(21314003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lRz4nZG65S91CH7AxLmZkWnn9qPziSneI8nWf1qNOuiVFRmQrolISYWV1fxmpCLosjvs+AhLhWchMDZxHKCTd/BkIsd9OdSE+8BZafLLsGztmj1Yr0+ewMc/h8IzMdJj/jTDQjuK9K24S6UcOIx8LzPxvzylkKC+P+nvKfHmpSale8C94k58yf+JxG+5n9roQNIkTIJm27rtMMUIPgVWUd/oIVFkr7bs9EgkpsuYqPyQMqIrHcPjSn1kBAiSJjmIHLdTkUHkFp69CIRoHSlmV046uF7ZPVy7F7b58JNAhnvGOa33/OsVGGj5aHiNcvHp4ty1HCWLczliweywssVljBSwbx5Qrg8bpHJDRB6hwLWn8d4aDoULp3Lat8oO7Dsn5P+i1qtV2VAd/u6rAVJjYp3wMu899JKeu8JIiGNU4IQ0Jyf/TsOlx3870VSTsHc8QHO3L7VWulzbuuL+vlnitt5BYHzIdcSOm/wvPI2EmCe7c4MoExpEzAuXmAmzlI+w3DPGz90ps9Ng2a1oBUn9bQlARBF4V0u2DVOvulMIAElfsjVA5Uq1eIzAog6C8reiOGRVYKXNNtgLHJ6vAYZ8qjzTKZu4rghMNK03pSLA4bqyg5APPSPZoP+CFKFGILS4CSy43n4NoNUxBK3liOeNN6zw5n7xNWfsnu3hcsPf6Wz0kb9++9pH4ou4SmTKMdnum2ZvZX8ff5zgb2PPNdqjVFhiR3wbZKDXhJWfDtI+6lgXmXsMvpVmqnZZFb9wiTqXOF8ZySaK1+zEWTkPzNBM0AU9kS6hqqvpWncS74kK2rNniU0MJCWFHa9eEY3EH8pCUKqIrN4uG8gpZ8QzBtooWliLRwA0puqQyUGB4XdAGnYQkP2AEm6wBYp47KtwOc7c63y57PvIY/japREAvIsxijS4F6sF9pADwIxfwUgAxqY= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 18:38:36.6043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f5b0a06b-5096-4ffa-e21f-08db9a9a2c99 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: MW2NAM04FT026.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR19MB7723 X-BESS-ID: 1691779119-111103-12494-6466-1 X-BESS-VER: 2019.1_20230807.1901 X-BESS-Apparent-Source-IP: 104.47.57.47 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkYWZsZAVgZQMM3QIi3JyMwyMc nMINEiJdXMNC3V2CDVwsDSwtgyNcVMqTYWANDT35tBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.250079 [from cloudscan12-184.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 | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 067e1a2fb23a..f6f993a51d33 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -808,6 +808,24 @@ 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 (unlikely(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 @@ -839,17 +857,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); - if (IS_ERR(new)) + new = fuse_atomic_open_alloc_dentry(entry, wq); + if (unlikely(IS_ERR(new))) return new; - - if (unlikely(!d_in_lookup(new))) { - dput(new); - new = ERR_PTR(-EIO); - return new; - } } fuse_invalidate_entry(entry); @@ -1003,26 +1013,14 @@ 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); - 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; - + switched_entry = fuse_atomic_open_alloc_dentry(entry, &wq); + if (unlikely(IS_ERR(switched_entry))) { if (!inode) { goto free_and_fallback; } else { - /* XXX can this happen at all and is there a - * better way to handle it? - */ - err = PTR_ERR(new); + /* XXX Is there a better way to handle it? + * Especially !d_in_lookup?*/ + err = PTR_ERR(switched_entry); goto out_free_ff; } }