From patchwork Mon Oct 23 18:30:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433388 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EFD3219E6 for ; Mon, 23 Oct 2023 18:31:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="NOOrdYoU" Received: from outbound-ip141a.ess.barracuda.com (outbound-ip141a.ess.barracuda.com [209.222.82.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E70F8E for ; Mon, 23 Oct 2023 11:31:04 -0700 (PDT) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by mx-outbound11-51.us-east-2a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:30:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KpKeNzswxjEpt7jIa5yr6lKpl5S3qPJe2XxUjWXrEFDvwxmvoRO7YXxtte7ovqeodeQpOGz8HihGazZVgDhoQ2BYFg7cDU8GjaV6RgtPsbqyXRQRbST/fTxjz1Cg06uGs1lYATzmqL/t5eE1Z7dJXmKDLd0dxrKNKm6/xyCbOpFgj4ymGGP/4dqMv9nDyBtVMDafcgY+FLl1VAGdFXmrxyTndwh4Ixw0J38ykzHl2rY8pq1ZGtFvRzxaiIKVgDQiF3UW1J0HsTOYUusA8RNnCZCAJvOuOAw6LepcQb8nXkrS3wrXRTkp6mFN3w8SEBrCH39vDVRbwbhXWBCBgCPvEw== 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=yOfzqRdxntQ8twOX2lAGKELQYMznGFdeTzTwyl29bxU=; b=IVD1+ZdRtLuxPjFbP25hEhs5/k7WYgA7MyfKCeuc0l5sZxc1Dv8WtBNFsdRwdMs51GAVYS+Txk1+CHshKBsyFIra/QLRZ7lGYfXkhFxiyNZ4aK/jtwWuF+psrxnykk+TMjACuQhR6CMaEeQ/aZhJBX+DnRx0b7TLH3+nXBQ7QmogNs6v7GmVGrQvVSa+NzRBNkjntSATDHskdpFlg9O7WskL/mGf9NrX5IOFzuwsnXdBGVIoYMPDQWNrIq/siEZVZZ97hHbS0+r+TZqYZaStOU6xVRk0nD+9XuEOMOwPLmyaDtp56SJhZVEF/BjBWqKLkQcs+ohiuLArZRwHyWCUpw== 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=yOfzqRdxntQ8twOX2lAGKELQYMznGFdeTzTwyl29bxU=; b=NOOrdYoUxKmTZZKN9bQS6xMKy9SvE+T3ZrqlunLbcXwwDKJJAEXBeVh5fijs2zXnHc87aWEqLkA7yM6a2p+biqoAUmn0aPhqae/La8zUxpOmdO4cqab9jEns+7VEud17wJViHQ58tunXliZiGq05VHDeKeXx/rzDn9PkUCxk8zM= Received: from BN8PR15CA0057.namprd15.prod.outlook.com (2603:10b6:408:80::34) by LV2PR19MB5719.namprd19.prod.outlook.com (2603:10b6:408:17c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Mon, 23 Oct 2023 18:30:39 +0000 Received: from BN8NAM04FT007.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:80:cafe::9b) by BN8PR15CA0057.outlook.office365.com (2603:10b6:408:80::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 18:30:39 +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 BN8NAM04FT007.mail.protection.outlook.com (10.13.160.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.16 via Frontend Transport; Mon, 23 Oct 2023 18:30:39 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 8B63A20C684C; Mon, 23 Oct 2023 12:31:43 -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 v10 1/8] fuse: rename fuse_create_open Date: Mon, 23 Oct 2023 20:30:28 +0200 Message-Id: <20231023183035.11035-2-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT007:EE_|LV2PR19MB5719:EE_ X-MS-Office365-Filtering-Correlation-Id: 167b2876-1173-415d-145b-08dbd3f62870 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DqhBGtwP4USUfpxU9RLwJdq2ukKGaJtN2+cIXb2ugWfalaTqWQDLTYvveI97ac0X156cYk7lyf1EI9RQ+rw08IKtV0YgRpw0njPtSQCW08UrS9jvAwQ+qkm08k4DgTLxClcvsILO0YQQRzxRN7S4bJnY9xV4j1l7k8IhXakz/4KLKAVAifZUMF0N3NWbMJph1ULj3Ug8z3G6XEa8xhIkiKuvDXA8ksgjhQCzJpgEiORQ4sI3Abmhy0RzXuwjY38+bpkkEYpV4i63IVMqNoCxW/UMRitiJlZtq4fINBD1C195F2GfSLYmozwLUeJDozT2Abqvs4C9X7I4RM4KTyjRfu24qSWio6B4evvC3elQZtyszKd8cgywFc1Wj5v8FEoRxlKLtQ0bQzBXRcmqnxVQQZngUXJFe6f3EVQIMFXGsONxTr+b+4YQp5Gj/N7UOtCo0zmFlso+wUYCftURhdI9izbbhEHTYupdIhOlW2fsPvGyIeyjC2E0cM8FfgFCPIGx7ASBJJLix3o19rxswbA4ekZiwQHwjSsEoIv5hxz0IA/7dl++pYX6Eovnck1hF1/GJaz2Etli44GybKLsFMa1Nr3o65ngcFSBzE9kvJl06JGiOeFHl0ah3Ltam6bw+XFcsUfu0esFkYG3B2GhtK+gWR1BIZ7OpVEmkQqwShU+hoc6/gvOIHLBvD6wjUWsUV1vBnWuHa3qn6dgoctlF3h2XwBEh6WX46rj4T9RSOlHmDrP5BmdPiPv/p9eBg2W+G3m 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)(230922051799003)(1800799009)(186009)(451199024)(82310400011)(64100799003)(36840700001)(46966006)(356005)(82740400003)(81166007)(40480700001)(86362001)(36756003)(316002)(6916009)(70586007)(2616005)(70206006)(478600001)(1076003)(6666004)(8936002)(4326008)(41300700001)(8676002)(5660300002)(26005)(36860700001)(2906002)(47076005)(336012)(6266002)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: FOTzGfaZlwb0bUmY/tAvq9KlMN98Ny2kKLm1fqUfCeNiaWw6FdY6V6k2da9sc/xb3SgD/aGe/exSPl29rgapVp4rIAJl/FgqXcX7Zb+EEY7XEzThU8R5LemZ9VHHpmIDm8eRMo2b61u4piaukmu4rxvDojKJRHel5NySgIdCcDfjiQCd3R5g7DHCE/syHMMnyE1CRVj2rAL2/Jupn60KW1NK6Q4PaaS1aHVbT0lYnoLJazn0HjESdZbgpORHe3uQ0Sfk91LHEjwh7jRemHOQ2HukHlkNSTlc9NF3FGZU0OSfoGloDUEIKUB4BqmhKLGaSnwqqNSbTz9ZcGYdHaNd0TxCwOQIewYz2XBil7I3la8VVD1Hu8GlOSzpY/aVya1TEMr9ulPCklpvWBnGBes3o2OfHXLnXmTw6rADsjKTutGKvhyUraROHxMAdNj6ioZPVCYWY11WqfzohIiViLrNOZX81Cf56HkFLpWpNE9cHeRq+x5jfqMK+Tp25+T0jF4adz9rJUjqnrau5t896jqHPdBuhOq/VdyhBHkBZWMb2VKkWqf5EYnBPSY7HGx2im93ddlebjKc+xUM2cZ2J3XDAR8kQH7yI6nuP8eoJq5aoM/q4TP2qPzQFASvOJVjkrn8V420vy+OgSIHQTGcxyTnX5kvNlaNkK4+PKfFHxRa96ZfAlTOenrqUlLCfuu8+XWiq7RbVLMKJTp6iFNP5K3EJDg1XESLbjRckpfpAQDXWr63Yyh/IloeUyYL8KwxA2Y5LpdmB9N0xQv0hck6Gah/gGWJkkZKpBvAo2REmW3QJBa23BrKw8BGSKYf5o9iScd1Kt+F45cCpx5EKzgADiPwpiM/1/52Ny817zXMDZEZmKw= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:39.5500 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 167b2876-1173-415d-145b-08dbd3f62870 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: BN8NAM04FT007.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR19MB5719 X-BESS-ID: 1698085842-102867-32709-2475-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.58.169 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoamxpZAVgZQMMXQ2MDAPNE4yT DJzNwoNSnFwNDA1DLJJM3cyMIyzTJFqTYWAClpD3VBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan21-222.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 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 d707e6987da9..e1095852601c 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -605,7 +605,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) { @@ -745,7 +745,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; @@ -874,7 +874,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 Mon Oct 23 18:30:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433386 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82B434C6F for ; Mon, 23 Oct 2023 18:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="cOSAuUbf" Received: from outbound-ip7b.ess.barracuda.com (outbound-ip7b.ess.barracuda.com [209.222.82.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D6EB7 for ; Mon, 23 Oct 2023 11:30:59 -0700 (PDT) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2041.outbound.protection.outlook.com [104.47.73.41]) by mx-outbound41-169.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:30:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CNptpna6jjdTi+C6GpM+VjkpAvKGU0x/H4qFWDBKrhQ5g1ZMUNEQMKaAAuzAP4xdT39bWqosVO+n2sKgT39ou9nfc0Aatgone5edl3jZF3+rpgBBdaYdq+lkfvKrguX8bHl2tTi+2VwIw5iu31xOz+xewSUNmovWsUO2Ue9WI1ABhdnD3jc+JaiceyMy5zFaTwoi9hGW5Cw5FGDu2Pr8JB2d2NUo/l7ZhRdLAzPv0fGYNmvWX8HoQZLOs3fEV9VMEWNl/y+dvhmznm8VTCP1Gm+It5JCjGrC4m/ZJbAQjaI8bcICj0n/6QlsIdVXoJmkwznhoZ0kjn4nw2k5nrSfbw== 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=f9lubp9IQcAala/CRAjpjNW6Bvzqq7U4KrlsYTMOS7A=; b=WD4QqzDKeIeGcK4tgUUI03PdppcrK9Tk3E5ZPuhsN6OFeX79+qiUV9wXS2Vh5mCAFxN0+KOmham6PeETTN9VIAMjZkrqqyTAFM44W8RUxKSZwutBz3/FEPtPaacJhURE0dfzuZBd285j53LMbDr+Exc9xtS2Q50HZNdGpc+I/OFbmvnW18I73z5NApZzV5hwcmibrzVoM3Cl1IP7vU3rvS+KUOT2rAWA1yT+fujquTJXNxrSZqKU6ajjx5fIBA/ZDrSU2obYAB/StphB7iyo78vp5Kp+eGkGz6oe0JK0yTjUcUUBqro+UL+K68ncsyARtjagq6PqhPB/TWIEftQz7A== 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=f9lubp9IQcAala/CRAjpjNW6Bvzqq7U4KrlsYTMOS7A=; b=cOSAuUbfmXL88BNN9WZ7687q/YBO+a3/VEzQKJHZuU0aZHE9+XNurntXDqDmbO7Toldtsxq5G4xJsGkRxPl+aXXvnp93gxr1qvglWLhiEoYeHCGUIUcHAUiH1VxXSSh1KlY0FA7VrDPfATz8s+z0ngf8Gx1DOKCHUpjK5guFKlY= Received: from BN0PR02CA0041.namprd02.prod.outlook.com (2603:10b6:408:e5::16) by LV2PR19MB5696.namprd19.prod.outlook.com (2603:10b6:408:177::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Mon, 23 Oct 2023 18:30:40 +0000 Received: from BN8NAM04FT039.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:e5:cafe::19) by BN0PR02CA0041.outlook.office365.com (2603:10b6:408:e5::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 18:30:40 +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 BN8NAM04FT039.mail.protection.outlook.com (10.13.160.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.18 via Frontend Transport; Mon, 23 Oct 2023 18:30:40 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 855CE20C684D; Mon, 23 Oct 2023 12:31:44 -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 v10 2/8] fuse: introduce atomic open Date: Mon, 23 Oct 2023 20:30:29 +0200 Message-Id: <20231023183035.11035-3-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT039:EE_|LV2PR19MB5696:EE_ X-MS-Office365-Filtering-Correlation-Id: 39fa6378-a09a-4bfd-f992-08dbd3f62903 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a1/zKtic9Sujd7wfp9VaO7g70tKQHMsmswXFxTPtqydvApwm1i+iHa2qAWozzpqGu4pX6BFWuYCSIZXdqIxFj5J/O1XQn7o5i5JF/IJyAu+1yAsy9Z6CLMoZPiyg5sBdK6w1bdBvqZOEE8w9oXalr6LnZVV6o8gNpFPNOADsLoku4RzZtrZC3XDqtB2TwEsduNMPMIrl8FoRG8+eGZrvopCwTeoqqne+JZjFcIMssf7Vjc44h3qcZsqU8YdGhNngaBmenVRpGLbTr9UReeNW8R1VC/57vGRlN9kAHnfX5gfMYo+MtiO51eH9h2E0Bd3iDRXdXzEf+/0pgFN+NgSbLKCahUujG0ZE+YU29FWDv3ltMBMDJWId0T9x4Ekkaddi9EqRg9nIEhdsYkXWqdr0PxM+XmrYFMFDQ0N7Wa9Su5/5We6LdfWtF5psqPZhyQP5Bk+IbvpG1Iw66ID/zY2O8hUlogK5ulwjqaR6mtY3uNP9z9n11NzcEPfVcg28fBzMpUxfNjGAUOOc6XH64hk+xdmaQgzTMAvsAvQxJJmiCd0aT0JDazKc6Qn+FSeUZnJgfBWyV3+8f0O2TXuo+/lBkmT5KbtYBSkE4El/TJrIaaLa6GK61ZWWuxchE7PdGai+hhY63feEjin0cbCDIJ2dja32CP9pvIoHwmobkWeQo13rc2Q8ZhOvhhKbi4sYpGNA60UD9urOYTQkdxEZGJUetBKVEc7eBBnGfsuflkMZv4YwH5aQFKjs9Bc6LYmyGaUv 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)(230922051799003)(1800799009)(82310400011)(64100799003)(451199024)(186009)(36840700001)(46966006)(478600001)(36756003)(6666004)(86362001)(81166007)(5660300002)(336012)(2906002)(6266002)(83380400001)(2616005)(6916009)(47076005)(1076003)(41300700001)(316002)(70586007)(70206006)(54906003)(36860700001)(4326008)(8676002)(8936002)(40480700001)(356005)(26005)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 9hb4RLPOxqreYmqAyVEbBFIGiblLrvrncFbjlHf939Y1YcDNR+CqR0A8d9+esKcT63L2ZyX1W9fa+1dJSIwBhkKAmtk65yjS55kWZhoj5MZK2I9lIPGnHdP3vyvvBEQ0Gz/xMTqojXQTHCCz251UW5yI36iHLn0zyN374p1+anYTFqjtmIssmQIi0aPZULrR0Gi7hezVAyTej9WCK+C3sk8z4NVwzY4R3aPaRiV2gneVm2eialmiSlAtOHPPrsjOOauen8U91u9QC1Ohh44Vu/4vlVl/MoM1kR4gPPIaDqUJeh4PHHNO6jZx30gks8wNTdRr/SCbK2A7Sc2PkWJbCLukK80pZb7sUk7UCV91Sy/N3RViN7F3c8cJzmX0/ZboURYXKl2wpSfNSCdt0erd0rd/+BHt9x/JYeBjlO/d6ru4rqUy1cXJ/SlPk7Nv+T1nnqE4eo2sdsB4qHpqkgFoNWGE+fK5JPKiZockPQpz47jPKlTqeLxQyKxAqsMtdTA9UYtWl8COy2G2hx1GSt+IC1ZjYl8pWeoPjnTiYH2yz+RgeqEdbkaoBK+luspAqTujuKaQAzrFJODZdtv6KPoZ2nLkEd8IcPzT0PhmrAz/Az07wp4JTiNxxe4KNSbId/yNaE6A78Kg1UHWALzS5ZVYmfRNuzUGPChBJe9nt6cVMFaHFiqNr2L69ERvIi1uU1kq4+k48z/eWtycfwt6AgTYAlmZWAfIhD9Wht38l+BEnXlwdiv3Q4YCf16a1vEhDVBnm/Us2/V+q2w57llz9mUcJ+ZlJTa4aahNQjRQTpFfjk335wYTm323MhuG0DzR5UMDQbHYejcaXpEUCUznK8RHk6j9WpSyv4fQD8S3xl06rx5DN45yx3VwDq1XHJ5wWMNx6z3uwkMhFDAVj2wqTee6kMTnpen6oZlna89OryjMk5HlcjPQp5AdAvEgbb4XpiHt X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:40.4411 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39fa6378-a09a-4bfd-f992-08dbd3f62903 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: BN8NAM04FT039.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR19MB5696 X-BESS-ID: 1698085843-110665-12446-697-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.73.41 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVhZGxuZAVgZQ0CDNxMw0xdgi2S wx2djCLNnMPNHM2CAl2SDZ3MTMJNVEqTYWAKuB0ApBAAAA X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan17-102.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 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: Bernd Schubert Signed-off-by: Dharmendra Singh Signed-off-by: Horst Birthelmer 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 e1095852601c..61cdb8e5f68e 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -716,7 +716,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) { @@ -763,6 +763,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 int flags, + umode_t mode) +{ + int err; + struct inode *inode; + FUSE_ARGS(args); + struct fuse_mount *fm = get_fuse_mount(dir); + struct fuse_conn *fc = fm->fc; + 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 || err == -ELOOP) { + if (unlikely(err == -ENOSYS)) + fc->no_open_atomic = 1; + goto free_and_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, 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); + switched_entry = NULL; + 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 bf0b85d0b95c..af69578763ef 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -677,6 +677,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 db92a7202b34..1508afbd9446 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -353,6 +353,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) @@ -361,6 +362,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 @@ -617,6 +619,7 @@ enum fuse_opcode { FUSE_SYNCFS = 50, FUSE_TMPFILE = 51, FUSE_STATX = 52, + FUSE_OPEN_ATOMIC = 53, /* CUSE specific operations */ CUSE_INIT = 4096, From patchwork Mon Oct 23 18:30:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433385 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8E62219F2 for ; Mon, 23 Oct 2023 18:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="zZiIJIqt" Received: from outbound-ip179a.ess.barracuda.com (outbound-ip179a.ess.barracuda.com [209.222.82.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD28100 for ; Mon, 23 Oct 2023 11:30:59 -0700 (PDT) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2041.outbound.protection.outlook.com [104.47.74.41]) by mx-outbound47-12.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:30:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZRj995sMZulNT64zkuGT7xAkhc0FxX1humEZOiuXhODMAEGyHG+iIXzHl7CMiUg2QYk3+eLjWB6ESp5lW7mhAob4J1rgMhzvdpv9TgnNVUOrdnWqEdB0j8UwWUEfpGxuFR7OmVlPfTHvYiMBHY4zbqmI5FSzes5vTgqv5ze5JllEIgAwE1h6lkPIrq0S1zzythcXulVqKRzH2+1HpCVsyv7So6m6ubOp55Qv/P297j6L/+nX+O21335OzeVuFfolcaCP7tcNftII/sDdG8F4Fd/ernlkMh0nUhWThLiE1V2qWJ9rCiROwwNaGJ5OHoAZKyFmkjIdY6W6THjCloMAVA== 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=jC8HcmX/NlF7J1DEGtJ7Fl7q/p5K7KFOWCXDW4M5qDI=; b=EEszzpRpp1xRF0wkHzpvZbUBxB1HTnqkp38SM98WPtJrEmyjWU0GFHzmD9UyUsE9kobOrxCOAebRnMLmS5Xvm2agtoYR4oxf+6zkcxgwczjwYIJsAm/ip7krCjWD1iUM69xqCmGE0t0Y5n0CX4ztdQ9h/HDOjLF8X5foL1AKz/Pp72+iuKkMFISR9VCt75+x9PWureK1hMGnuS2TuQKFBeD1LUBRwXrUlgyW1K2zgLTRIFu13liyfUK7/uoy42o7PbwmxCmvzEmxCLff07t2B+bjfLSTEV82Uoc8lTB28t8Y08u+R8IvF9IthYXlMv9nZEhoo6qMogzHcY9q9OINDA== 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=jC8HcmX/NlF7J1DEGtJ7Fl7q/p5K7KFOWCXDW4M5qDI=; b=zZiIJIqtb+35QBRGVAOFOg3wqDMzU/y8DtZdYZlyEk01t098yZCQ5Zuemajk/nXS7VlrOO5ya81ioAh8+aMZpCg9iKCksaM/bnXLmVLIX1diD89ZsxoOb8A5PlgiNcudd2E6jNIbVaD37smjzesuHkJs2Rrk7oaq53n1fy82AII= Received: from MW4PR03CA0312.namprd03.prod.outlook.com (2603:10b6:303:dd::17) by SA1PR19MB4880.namprd19.prod.outlook.com (2603:10b6:806:1aa::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Mon, 23 Oct 2023 18:30:43 +0000 Received: from MW2NAM04FT024.eop-NAM04.prod.protection.outlook.com (2603:10b6:303:dd:cafe::7b) by MW4PR03CA0312.outlook.office365.com (2603:10b6:303:dd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 18:30:42 +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 MW2NAM04FT024.mail.protection.outlook.com (10.13.30.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.18 via Frontend Transport; Mon, 23 Oct 2023 18:30:42 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 7E6D020C684B; Mon, 23 Oct 2023 12:31:45 -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 , Amir Goldstein Subject: [PATCH v10 3/8] [RFC] Allow atomic_open() on positive dentry (O_CREAT) Date: Mon, 23 Oct 2023 20:30:30 +0200 Message-Id: <20231023183035.11035-4-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT024:EE_|SA1PR19MB4880:EE_ X-MS-Office365-Filtering-Correlation-Id: 26a59001-2d36-4617-0692-08dbd3f62a13 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zoVWP2WfZnx3JDIM153e02P5NEmQNFCPyvieVW+vvXHprX8kq9lLw7CX/iJaWIzAHd8m/X0/BdKhhVxZgse+IaY+koX9gzFAI0sC0KpI5HceZynJV/OGOt5ybO7nXfyHHqWIA6HAYFglumkQUkCBBLcXokzsQEIBbqV684GSZhoglqAP+OF6I1e1tUcWs3pbHaINrGZ/QHGIQTNQ9z8BKlYuhmYq3/Zvo3YDOQiogphm6zDUDIqzuwbnA1jeM3RTfm1BJEMN/qacNVnDL5vjX2HeFRMy6SA/VzG9lM5izAOdyoLPKQalNcLpVwxYFCO57MGsjDsVEkr5E8JQNpNINLDKDpl8X3zTGztgZzuG/7ogGa7zYpNl4AgP85G5hz6EHvrjzJPM8x86KzyQexs121uVHF+VhJT1SZikRRGjqZ34hYiGRAs0bJZn++IoCYysqjZbp9lfnjeI2gmJGe3Dgw8XhOg54I9dZMgg8HHyhjhmuy7uEFVR/XKy7u22/bmqtdkZc6nFw9cSDxYchr55oPmOiRLuWo3/N4HQLGHpcsId1dBJieks7Sxgu06YtxXWCMqp8z58HmPibeIYSLEjvdcXg1uHPFVJIPRKk6Xa7FA8NOcVxga+kf+Lv4gtaoQxwAoTTWorIjMo8aE24Z7uKuIvoPkO1SizXTLxtfXxCbtnLSC2wMnD+kiHLYDlbxRp/Ql2HPXzxMnWlaMFURZb/tizV4Ubhzr/vqi/3haC1mv41EHEQlkiZjwjjPxykrzj 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)(39850400004)(346002)(230922051799003)(451199024)(1800799009)(186009)(82310400011)(64100799003)(36840700001)(46966006)(81166007)(356005)(82740400003)(86362001)(40480700001)(36756003)(316002)(54906003)(6916009)(70586007)(2616005)(70206006)(478600001)(1076003)(6666004)(8676002)(8936002)(4326008)(41300700001)(5660300002)(26005)(2906002)(47076005)(36860700001)(6266002)(336012)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Yfyk5pP++P++3tutR0707tDjmSi3pMJtIIZ2jhykWfcnt/UgfevST9Q/YoIRQgE8cVzhX7DeVYigwLB406V9Tf7/MgQNzSPOCzJDR6rI8mEK4An3C9GNzxwp1yVRnzyHrBO6pLBZa1ckCf8vzJIVUyITgrod0XT4Jf9wks6po9Z5jfwjGCWlBNhYQc6Jty6MS+KGtwCIkrFAkpP3KkOseACdGCdRSr0hdbreQJBBWIifjK6p0Y9L+kTewmveJs2+xQNDJ03luLR+5u+SikudXgeWEVd2eXXSV0bTjrVg8S2q33WNIBLEXa7skuiv4HTmDMkOPW7FGxAx9fn3aXIRUtgbog1hbFTAr2Xf4Ffouny9zqYIOk4X6z0dgcDKUF20rhFXNAEwpzvG9I41oMKkdSUEFAgUcxkS5Fdgdr/xRhxk1910S4+0A4mypn/AG2FKSR06Id2Y33RfDMXkelPmiHLkkCZpSiuCzXkZd/s2rxowHpQbECi6NJLVSoYqeVvPlijeAWMius3yB8j0YkntmIxLtx2lVZzIPF2NNmEDPlU+OFbdjl9gQ70sQCPZ3KQStTl4tiJl7ZJBc63RMQvZ4FTDaWyQPEIVDPCleLEBsxQhYCZZF5lDOFY9oql4Fj2P3p135fCOfZY8bg8gCRx9UAu6jzylLYvRdXFxIQatSYFr6s/ikT3li1eqjUvLIxV/FQkBiPtHA8rGj0Ra2XSg9pPtJqu1MUEdBvX5gn1zmrYFlJ0CWvEen+z7/HIGLqFr7QaAQ8sJBxhqd91c2kc6z2UhtGwwOEECO+4ezPmzWkSgQme+E/N/27wJpP0UfCGaGEp6RbfmsVqw9RJMdMVZYAck8GZxsGK74f0L6JuQe2gynnEbz1FWgYV01pGAq6ld0DXQo1qk4a6clzPk+VHe3kAI5Yfh5qKRMk1wRU3d/XgLQ1Di8j8AbRvohaRBNGhWNlAsra2LYLwd4H2PoxpKVw== X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:42.3425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26a59001-2d36-4617-0692-08dbd3f62a13 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: MW2NAM04FT024.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR19MB4880 X-BESS-ID: 1698085846-112044-12599-1009-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.74.41 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVsbGZmZAVgZQ0NwsMSk1MdHU0D wxxcTI3MzMzCQtJcUkNdkk0cLC0sJIqTYWAA8jtT5BAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan18-214.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 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. This only works with O_CREAT, without O_CREAT open_last_lookups will call into lookup_fast and then return the dentry via finish_lookup - lookup_open is never called. This is going to be addressed in the next commit. Another included change is the introduction of an enum as d_revalidate return code. Co-developed-by: Bernd Schubert Signed-off-by: Bernd Schubert Signed-off-by: Miklos Szeredi Cc: Christian Brauner Cc: Al Viro Cc: Dharmendra Singh Cc: Amir Goldstein Cc: linux-fsdevel@vger.kernel.org --- fs/namei.c | 11 ++++++----- include/linux/namei.h | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 567ee547492b..ff913e6b12b4 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -860,7 +860,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; } /** @@ -3330,8 +3330,9 @@ static int may_o_create(struct mnt_idmap *idmap, } /* - * Attempt to atomically look up, create and open a file from a negative - * dentry. + * Attempt to atomically look up, create and open a file from a + * dentry. Unless the file system returns D_REVALIDATE_ATOMIC in ->d_revalidate, + * the dentry is always negative. * * Returns 0 if successful. The file will have been created and attached to * @file by the filesystem calling finish_open(). @@ -3406,7 +3407,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, struct inode *dir_inode = dir->d_inode; int open_flag = op->open_flag; struct dentry *dentry; - int error, create_error = 0; + int error = 0, create_error = 0; umode_t mode = op->mode; DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq); @@ -3433,7 +3434,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; } 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 Mon Oct 23 18:30:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433390 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DF37219FC for ; Mon, 23 Oct 2023 18:31:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="pJd9bnAA" Received: from outbound-ip7a.ess.barracuda.com (outbound-ip7a.ess.barracuda.com [209.222.82.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32F9E8E for ; Mon, 23 Oct 2023 11:31:28 -0700 (PDT) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by mx-outbound10-173.us-east-2a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:30:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M8sA7cs4MsZvogDWhAz+kOCMlPx3B3TBSspbP8jJDEEs0Tzw8VnHsksHi6H6BUducmBPgZ5pQ8a3I3c+CJoR6AlJwGtGQoH6mXQmhC92KaaxxkRfzSl7iLO2V4eXNQJ/plrHiI9nsRpfFhP2RwE3KJ5qCcFEYPAFFxk/PCcbBhoUygRrH6DVhB26ZnvbCsh50WMIxRkyVs+KHOtKrR2BNZLqb5fNHScKPz4ThGewMEBuMuBFUundxEII60cPPAmYjfK5OvLZygWszqcOgLIggFGQGwDzWB0dKw/R8/CcgCtEd/jduS81jyfURNhRHojH+hhBaD7dBSezAkEuJLEzrg== 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=XnGsrkVVMqV1KMJdP9tisj9vGiOk5M8tb+zWEZdFth0=; b=LAPEystHuOY7C9p19ONSfhr5xqKHBI1bdn0UTHKGb3zHS1fNO/iKJVXnClUT2Afb3c0h+0YaViKgCDV3SGeWXqmaEwj1lV9UxsQPyNnCFZL1mTEJMMSrFMsGTh7RXzJ48Mp01xyGaTS/+O2BQo1+7xEBIZfyX4V9bnOhnrQKUHKDNf/aRF2yfSFasAsuECzwZfjfJ+MTfHTzvxAvu8ozFaINAbikSJOaRbPt22PwYQugC1x/Q/szutcr/q4MXAgQM5R22ZMA6qqgD6aKsoEz5ZB8O3nXQNBIe2hCynmNgeBAVUvBZzauyCNzhS1mKKOzAIGEXG/x+B+paibF/wDVRQ== 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=XnGsrkVVMqV1KMJdP9tisj9vGiOk5M8tb+zWEZdFth0=; b=pJd9bnAAWerg727xKVl8IjMpnwWJSDx6gOJahaIcMry3KhWNtMxf5Nf5+JAMOsjkbX4U5XA/kiAGgTvdfF1UPjdwdxG7VLbtMKIcMmbeKUGNFTstGJ22OPpxHD25/lDd3xMMIqmPcDzSXxAC9aZdmZZhCYYu6oJcdsH65JYPswA= Received: from BN8PR15CA0045.namprd15.prod.outlook.com (2603:10b6:408:80::22) by PH7PR19MB6505.namprd19.prod.outlook.com (2603:10b6:510:1fb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Mon, 23 Oct 2023 18:30:42 +0000 Received: from BN8NAM04FT004.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:80:cafe::96) by BN8PR15CA0045.outlook.office365.com (2603:10b6:408:80::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 18:30:42 +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 BN8NAM04FT004.mail.protection.outlook.com (10.13.161.176) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.16 via Frontend Transport; Mon, 23 Oct 2023 18:30:42 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 778A220C684C; Mon, 23 Oct 2023 12:31:46 -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 , Amir Goldstein , Al Viro Subject: [PATCH v10 4/8] [RFC] Allow atomic_open() on positive dentry (w/o O_CREAT) Date: Mon, 23 Oct 2023 20:30:31 +0200 Message-Id: <20231023183035.11035-5-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT004:EE_|PH7PR19MB6505:EE_ X-MS-Office365-Filtering-Correlation-Id: 4032c68d-5cce-403a-10fb-08dbd3f62a21 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ON/CzRpJdoXCVtFMF5gG4gPjLjziT49x+Fk5oa+e8MH0hYqF12gWcCSG4AtNoi9S+tzd3wdLXIzdyqkV+T0eTyFDz4sPpP95g3QQGkMiiGUhaTuySXa6hKm2ukbK9kZScZAYkrEOLANO136veqcPlELABTMiL64T9sUxwZO5vAV3K2OqDOtXkpPOyj+3a0kazXt2okVs0jHvXwf0w9njeyQVEFFcxZsVaXWZ8T+bDyrXt6CKUneZjOy3ngeovVPC4RWIsJ4AOPVBg1D5VJWNS/A4lrg6KIKNcVHBRoeB93oqfE9SsWduwNZyY5zyhmX8mqJvXy5LuO1lT36v7ETjeHt1F117taQRFyvT22XJN+PoUyhDLle2rnBT+MsqBR/XTXCoZY67H/WcheuKe3mW1n2CMelQ2j0pFFfv+8tzvrPiBh1ypWIlexAAZM6orDoTGXDaA7FulJBwrvmy2MnLd4Cc7E6rZsQ6amc+yRgr6PCDPHKcPQ2XEIZMaob/7RQE5E6vnJKaEFh2YkxcYNXAzqVl4gSe3+R+iVT90MpuWzSc5mbxP3ssOzORmRh6jGljCjwNo+5UOwvc42TruPFXBJRGXaEjaCDgEXW9f5Syd7LRoBZfsKWhV27KxpQsFp9SyN8Re0Bca+E8ysjNBCnAqU2sm6B/4MUT9/KHrkYDoR/P0SbTlyDe2A8u/wzQDfARb29y4ArBZS8PPLzgeyZlbwMSHdvmIayjSlhM7vXEYkqWljNyLU1IkwInZSJxzSHn 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)(39850400004)(396003)(376002)(230922051799003)(64100799003)(82310400011)(186009)(451199024)(1800799009)(46966006)(36840700001)(40480700001)(41300700001)(6666004)(2906002)(86362001)(478600001)(4326008)(8936002)(8676002)(70206006)(6916009)(5660300002)(316002)(70586007)(54906003)(83380400001)(47076005)(6266002)(356005)(82740400003)(336012)(81166007)(26005)(36756003)(36860700001)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: uf8xiSYwCW4NOgsF4do/HnV7DOv4SXRH7FMNyK0e2X75EEw6K1xg4dUvxDtvcbYUEPnon0AVlGCP4916V5GbXA8a2bPbHTFlwxCiyJwaK8qAhGhXDYgytVwcSY2pQO9ZZf+nPrElEk09t6fvF0HOLoobHd1EAZUNAfjNaCvDnA3vDc118q17EJvxqXoS1jkWQJOaGz21KHJeJSDmko0bjba76OE082rzxB/B4fQIKVHdZ3UsgVdUI0VJFwaSKRPAvUZA2AFkaP4qKq6MPfh4b4eRoaO2tGMQWyM98AtU7JbA2xFrb9/Z/iJKUqy2bFr0iGzb8/Z3hmThZEV3a38Sxtq+RkaFzkQLQu7Bd7o35my9yLFO1tkWzljkNSemiYYyfaB2A/38yxAV0E7UqK5MG3vgwo2ygUCsJ5knCFc35PwyC7Dc565fS629LxNZyRU1BW9nowIhUAw4bgso+YsvjTUInzQZTEMw6JFSB+HCajmphv4CkF4+4lxGBhXT+A/Rn0IlI5NoMATzR38E6g99u4KVx6y4YfKMwDtu9qlZh43sD6ehSnafvCeoFznxuUMvnUU2ISHihym4SFTojTfr9mQqaNNa0sp0m/oeh8mFQ6TYn7cRPk7CLOmVdf/e7imFr22TnObTz56Re0g7/+MLxDv2BcQTny2cEzTP403WPpwstGfVrT064QaMSnCbooJ4iQlNUprKk1mM/sGj7z3cAUQaRb6HGE61ZvxW0OED5CexvPd3J+JBnvCF5sndVMKjedxlngMiuQQP+LNOXcVGG9hYHQq1tBpEh4/AvcvdvRQpBHSWBm936piqp+oc2HxvZgOuairTErFUh/XsVsp+54wtaiaovehdui+94D/hwULSGyi/fuEDMLQ1b59uXpoFacUBJnKolRXn9XFoEap3g3Jzs/IN9EAshlCakta44cg566sZkA13TBoxvSXR72v5DGSQ6/ftrk3dOCnmeX/zFA== X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:42.3876 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4032c68d-5cce-403a-10fb-08dbd3f62a21 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: BN8NAM04FT004.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR19MB6505 X-BESS-ID: 1698085847-102733-30922-1853-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.66.41 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKViZmFpZAVgZQMMXSwDzRJNEsxd zExMjA2NgkKSXV3BjIMUhJMzRPNFaqjQUAgbqBT0EAAAA= X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan18-205.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 Previous patch allowed atomic-open on a positive dentry when O_CREAT was set (in lookup_open). This adds in atomic-open when O_CREAT is not set. Code wise it would be possible to just drop the dentry in open_last_lookups and then fall through to lookup_open. But then this would add some overhead for dentry drop, re-lookup and actually also call into d_revalidate. So as suggested by Miklos, this adds a helper function (atomic_revalidate_open) to immediately open the dentry with atomic_open. Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: Christian Brauner Cc: Amir Goldstein Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org --- fs/namei.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index ff913e6b12b4..5e2d569ffe38 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1614,10 +1614,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 @@ -1659,6 +1660,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; } @@ -1984,6 +1989,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 @@ -1994,7 +2000,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)) { @@ -2002,6 +2008,9 @@ static const char *walk_component(struct nameidata *nd, int flags) if (IS_ERR(dentry)) return ERR_CAST(dentry); } + + WARN_ON_ONCE(atomic_revalidate); + if (!(flags & WALK_MORE) && nd->depth) put_link(nd); return step_into(nd, flags, dentry); @@ -3383,6 +3392,42 @@ 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 (WARN_ON_ONCE(open_flag & O_CREAT)) + 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. * @@ -3527,12 +3572,26 @@ 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)) { + /* The file system shall not claim to support atomic + * revalidate in RCU mode + */ + if (WARN_ON_ONCE(nd->flags & LOOKUP_RCU)) { + dput(dentry); + return ERR_PTR(-ECHILD); + } + dentry = atomic_revalidate_open(dentry, nd, file, op, + &got_write); + goto drop_write; + } if (likely(dentry)) goto finish_lookup; @@ -3569,6 +3628,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 Mon Oct 23 18:30:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433389 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3002224C1 for ; Mon, 23 Oct 2023 18:31:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="eqfNpYLh" Received: from outbound-ip179b.ess.barracuda.com (outbound-ip179b.ess.barracuda.com [209.222.82.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21D3C9B for ; Mon, 23 Oct 2023 11:31:14 -0700 (PDT) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by mx-outbound41-169.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:31:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jhAxJmgx8HfN6pCLUb7lYk3rNkWIvPCuDv9q3gCXNNhtsTYx36VMtJeIPA8S32zSF8ThGi5TELQyxEYULR6SdBIQJuUNgu6yyDHVGzfCZjAM2/dio8538s89J/NXHI4LlNsi5kbfka/fR1qTuLwKsCH6twZiVg04ughvHvbLoRODtLp1o0vgN+ZKlg/1GLZuivv4jqpX58CAzqsOeXqKzxuuOcvcvb8SXFipY+jIJE7xuByXsd03SU+V/rNLPgtATh2eww5YtXwGu0AQdH2mDt4GNCDLzSmzIudFfqxVlIM3gxlTAd3GGjCQfpK2ebP4/c2P4AdwZCR4vs1Y7rt9Jw== 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=hIh5nX/ob8vu1qPPNB9A3kuJvEzF9x+jhIRj+X2HxjA=; b=XWEuLGhiDbCZRrjPpK6yt7r1l6XbohbCZGA0lAT3NxDYN/qfJFlncNHmTmcfMa1Hb66tLgTq1BKnak6PmBGTAFU0lhxpiyPS8qoTVArw7dr334enTkrh1teZqQ3JWqrWgFyh3MqDrFRbZwAk5vKqoWwxrc3272whLsg4Nidor2tkXeK4OJ09th9EAhJTmYL5LN8KuGOaIFLamOdBLQ+v7LuoCeq3Fj9nVqDR9sDDgZwpP6/4+Lz8Zry4EHeMVtENveZ6FO9U6fV8Nl+UAoLp81KSuLRyZzHYLo4QXPMolOPxGWYMilvwynb45OXvHkwhz+ItgnhbajQvoFpPX0On4w== 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=hIh5nX/ob8vu1qPPNB9A3kuJvEzF9x+jhIRj+X2HxjA=; b=eqfNpYLh5BE2AK+nisApJoRu+NBtCG7JWErHwRVyr1Vdjg2kbQfikR4PEFqv2L1rgHbFziSCXe3SrJlZKfwK+mqVjSmTf51Vg5MawyVErHdtze6T2zGtDqD18l0shanIhsAr6r0w466PMPXUUnOV61/ykKpcsrgz+Jwv/rvp42E= Received: from SJ2PR07CA0011.namprd07.prod.outlook.com (2603:10b6:a03:505::20) by PH8PR19MB6665.namprd19.prod.outlook.com (2603:10b6:510:1c4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Mon, 23 Oct 2023 18:30:43 +0000 Received: from MW2NAM04FT036.eop-NAM04.prod.protection.outlook.com (2603:10b6:a03:505:cafe::6f) by SJ2PR07CA0011.outlook.office365.com (2603:10b6:a03:505::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 18:30:43 +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 MW2NAM04FT036.mail.protection.outlook.com (10.13.31.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.18 via Frontend Transport; Mon, 23 Oct 2023 18:30:43 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 7114620C684E; Mon, 23 Oct 2023 12:31:47 -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 v10 5/8] fuse: Revalidate positive entries in fuse_atomic_open Date: Mon, 23 Oct 2023 20:30:32 +0200 Message-Id: <20231023183035.11035-6-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT036:EE_|PH8PR19MB6665:EE_ X-MS-Office365-Filtering-Correlation-Id: 3bb46d88-1cbc-47ad-8dc5-08dbd3f62a98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /Fm7nxlvNsFK3XTQc+aSIX7C4y0jWxKBF6T/SAYnIxfNpf3obDXjuAaHQush1pvaj8s3gxQW231Qb/C5Dht+Im+7/jN6TAhjgKDQI5rHrmXlQ+FCNHv5926d8ptnrLQtbulQ+ePyCHwyjPHAKjPDe8D1PqIunkzDqCiyPKD3JO8+agrCaqYf/74ZeSDXWAYAW/FGfE9JYWNSU1V7uMnceRwL0hFBw9XNyhxs5h7+T+JAaF21tG6v5zd9m27Y0efD0DSyospbvVIv3ADhzDt5lS6h+nyLTzyNJAktcJBDImLIu0Fqze70IKcRylqslMy3luKHhTfeIklLJ4GHlPrhad89ffzT1kg5vrL0uKDD+jdDt5tCv9gQULHlrbmCNCYVRVPKQq/oVB5o8LHxuA+odgBxDRmOez8o+gQB4a9IziNTiKpsZ/vq0rSDbvPAvBDjcEGObdY3pWE5kvItv9MgFJj+R/bBMFFi0WbXLI1xNV4Yki8awtDgnZ4tnaOwDWRq22FVfrmrqkYnRYd8V28wZHYp/A0kqgKPxokocNJaskM0Df7GCFnNTTDZnUhwhw1FzZa4yKfMfgmB3bkgQdP+RWHGkmgqIboEztLCrcME+Lhu6zg0ljIkw7QjTpshmi/TjXND37mmwnOnlCnl6hiW907SQVsS/6Vfa+oUc50Eqk2CyfPh1XuMccn0Do/Sw2Tagj1/Ku9vBCMNxnQuFEKtVOHJKbyMDIbzNidfuYiqWg9cpAr60zF6DceWcVv91IbPfQ1NX5yl7sQDXfuGZN50BZobbQD46kEmzw0ukJduT3E= 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)(346002)(39850400004)(136003)(376002)(230922051799003)(186009)(1800799009)(82310400011)(451199024)(64100799003)(36840700001)(46966006)(36860700001)(2906002)(41300700001)(81166007)(356005)(54906003)(82740400003)(316002)(6916009)(2616005)(70206006)(70586007)(1076003)(6666004)(478600001)(336012)(40480700001)(47076005)(6266002)(83380400001)(86362001)(5660300002)(36756003)(4326008)(8676002)(8936002)(26005)(21314003)(36900700001)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: S+9dRRhwMlhWRNwQTmGBFR674CXuhK+FigzDsknr7WWtbxmAUneMbrQqGutcVkV02BI3+smFNe/nH/jE2I/Eil9GULqEsoojqgKzLs/tWia7RBM+RvYa24gfPBtwZjchVJxrs+fEwOy23cr/0XzCs6Dc/kdeUTYk8jjmyURF5PjHU47HPybgVsPHfIPYnOVxrb7VE0IN2gXvkUkVFt61g2fdUXsWzx6paSz5tHTk7dSBlkzmOj6JkqsIzhb7fx8ev8arKUGbCMgO7jzRvfe0RDMgCpNfcZRqj4aNw66rNQd3cq2zbmm3Ax8xXS3kuDhLHaPu7w5D1Pnr+K5curJ7KQBIC2W7iFulxnNUZPGQ2JZglPiTggSgcQom90TKVtObJeKh00TIxHW7Q1PfEiTjoHMaw1eIVJVMQUk79r/8IelLiKyQeyEC6Gu8GHPKDWbAAEKbkLpXuFRQ6cDdIUtICGm5fgdYLfAUT2lTMbo9sfcjg0X+inOhTSrC+OpgWwGVWFFDEPJ8m6NKR+yHxOiFVWjKkVNdbobFui/FArPEvpN2vS+qkNSvqu8RclHJ3OiDZXon/KHX1pKZI87STameLmdMyox2UIjjvBMrMmMjZVqzxqzzrYdNVRfkZJ8V9tj5EWW9rI+35XXYLQOGJQl+oLhPyGZhln/tD+T0bWiWzUvg0S9RUeEnDk2WAI5kLgTdJ/UZHQoJPMjb6U6zY8gfV2d8Y2Gs8y/XH/PNTJ/fOnjuFzjLJmh5OQCqnol0wQA/I+H0+5JVKETQs8MuA8OQGa9qEOzOtMEqjj4ipi8r2u4tMm8+UHTotC5nlxqGPgoxqTXA7eixzT5X6beR708uKFTC0WAM9Dp8/uw2LXM2U1yqQDS8+h1Cu39Tjo5tgr+s9xhflOCGRTNsLCw6sZWV8k+0Yii+yG5fRvOvu12Jm8EcTVsL9tOoedYXjSKnyaq3 X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:43.2332 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3bb46d88-1cbc-47ad-8dc5-08dbd3f62a98 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: MW2NAM04FT036.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR19MB6665 X-BESS-ID: 1698085868-110665-12449-715-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.56.169 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVpamxgZAVgZQMDnRNNnEzMjIID XZItHYxCglMdnI3MjCwsgkxdTUItlCqTYWALQfqnpBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan22-113.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 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: Bernd Schubert Signed-off-by: Dharmendra Singh Signed-off-by: Horst Birthelmer Cc: Miklos Szeredi Cc: Christian Brauner Cc: Al Viro Cc: Dharmendra Singh Cc: linux-fsdevel@vger.kernel.org --- fs/fuse/dir.c | 202 ++++++++++++++++++++++++++++++++++++++++------- fs/fuse/fuse_i.h | 3 + 2 files changed, 176 insertions(+), 29 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 61cdb8e5f68e..17ae788776db 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -220,6 +220,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) @@ -270,12 +283,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; } @@ -763,12 +776,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, NULL, + 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 int flags, umode_t mode) { int err; - struct inode *inode; + struct inode *inode = d_inode(entry); FUSE_ARGS(args); struct fuse_mount *fm = get_fuse_mount(dir); struct fuse_conn *fc = fm->fc; @@ -780,10 +865,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) @@ -835,36 +917,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 || err == -ELOOP) { - if (unlikely(err == -ENOSYS)) - fc->no_open_atomic = 1; - goto free_and_fallback; - } if (!err && !outentry.nodeid) err = -ENOENT; - if (err) - goto out_free_ff; + if (err) { + if (unlikely(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 (WARN_ON_ONCE(d_really_is_positive(entry))) { + err = -EIO; + goto out_free_ff; + } + goto free_and_fallback; + } else if (err == -ELOOP) { + /* likely a symlink */ + goto free_and_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, 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, @@ -879,10 +981,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, 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 af69578763ef..80a1fc6aa103 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -680,6 +680,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 Mon Oct 23 18:30:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433384 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 603D0219FC for ; Mon, 23 Oct 2023 18:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="DBh37n3i" Received: from outbound-ip201a.ess.barracuda.com (outbound-ip201a.ess.barracuda.com [209.222.82.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19F6CB7 for ; Mon, 23 Oct 2023 11:30:53 -0700 (PDT) Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2168.outbound.protection.outlook.com [104.47.73.168]) by mx-outbound9-90.us-east-2a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:30:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OPWM6guhdrVIQUulLMdDXI5ZhOWGg/FtyvMTGiiCORfSlJBH89j/F4gC2hf8U9YGbCdg9slNik/+7nn1GVCyRZV/HOv9/ZiVGDohiSSwMv3l/pFzaE5Le31Ngo8bRJFBFSXzxFAY/blRZh66D7SUjxosL+Nj8FB182lSrfDa+7juhlrWH+LXmHCJksoyFqLSEWxq0euOBcivt41IOsrqn5VViy83/eU9ToCiQSuTseR0nq4ABfByGwGiivfFfB8wmGfZBv47I8uv3ek6bgpuin/YVP9WuFrzzs5Ysox5UCURhAn5kftZ0iNMIq+bhH2bMFDa2TffWlSoA0itTPYUCQ== 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=7WWczKfaRQhshgqOcBZ665ss0z+UHAPvodp3cbFjRNE=; b=O9L+VAY5fxaLbZM2fQOMQZSAwofQF/8UG6JsxTFIisML/Qn5dYF3UvwfcJ/VzojBTFxUNra0bLzMGeTLy5gQDiOwwO1416+BmOiGEOl6V8KcjczJt94ZSDVvuwFpoNwW5CecgULRG16LEAIhvq6VRV5gJjKQv+fJrISFl301Xq6CnVSWVtuBVXlB3f8Qw22F1I8NOTDFTZ7WbS8XF0Rd5l7jRZSpUv029CF3skSDddAKT8sg7jqCg0evd1joBHJXlixhl2cy3YMyot/OaEnZIVzhlIRjB1+0q7Nv7/AHBowfpFz/jzyJ5hLtSSFSmt8JY6aC7Z6TofGRRC0WKOaWiQ== 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=7WWczKfaRQhshgqOcBZ665ss0z+UHAPvodp3cbFjRNE=; b=DBh37n3ilA4Q4EfHTbzWUL39GvKCWY4zlFN4Z06Al6ZdnbNLHkNq9ZOT6j1qkWk+rL3KED9PuCOujs7cMq3f7kWFkKJvon7kaom8kt1b6Z/5G9rrc9K7AqV7NWNfS5MKOpNQk99n8eYGWcOz3YHh/M1ooY0Pe8AmDsqmSQH+KM0= Received: from BN9PR03CA0495.namprd03.prod.outlook.com (2603:10b6:408:130::20) by MW4PR19MB6983.namprd19.prod.outlook.com (2603:10b6:303:225::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.24; Mon, 23 Oct 2023 18:30:45 +0000 Received: from BN8NAM04FT028.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:130:cafe::32) by BN9PR03CA0495.outlook.office365.com (2603:10b6:408:130::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 18:30:44 +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 BN8NAM04FT028.mail.protection.outlook.com (10.13.160.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.16 via Frontend Transport; Mon, 23 Oct 2023 18:30:44 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 6A95A20C684B; Mon, 23 Oct 2023 12:31:48 -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 v10 6/8] fuse: Return D_REVALIDATE_ATOMIC for cached dentries Date: Mon, 23 Oct 2023 20:30:33 +0200 Message-Id: <20231023183035.11035-7-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM04FT028:EE_|MW4PR19MB6983:EE_ X-MS-Office365-Filtering-Correlation-Id: 12a4c581-e4d0-45dc-0093-08dbd3f62b64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PscQ1QkpkjsiSx4pXJKkEHwJt83f+uGacsFKDL6eYpoeX4LdUjwAN8EEG03G/ospXBkBkODb14meET1hgwx+FqBzBJ4Sngw2nXzuo6BQdhoYs2kQb/fNKhwIKJauQADXZS1mTh/b79TEzzLwtBcrtbryL4vaNiqi/UXodViq8p1SYu+/pppwlL+W1GutSxRd0rhu9KOsasgIVRntx7OTBUXm3GUZ9IsdZBwv9h2ayj2EQxSO4XQFc3aWKdcpYb9NguZ+33gqKDO/IKw+e7tcB7URHJ6QWvNxXgVksGXuqv058mOWihsgSMqvL45dZcUG4DyMorz1SWAZDkIF/r+pvX4gwXaKD3IQsVcQjaui73QPRobwlvdGMbQweaSvAw3BJaxx50OLlTJtuIqjFCJ3KtmvOFnZnN0CY2q73Crkli2wJ/zXDwDfGvqewGr/PPE6qXPmDOo7QcwHvkjhOtShs/xA/CV/Qj78bfb2JOFf3QFJX+fYGMeFMcPfaTK9beUhIOmJ0VY+M3jj6eITw+2aqVv1km9TrDNE6wIXjhZQA6AIrFmmoHfejrFYrqDGnN9x25jhx1JU7x5TKmnuzpTIdFaK9EDESO111XHSzOO6n8Hcvzqwnvm3zzy9R55RiVioOczkIFpAMIhHFBF6yc/DdVKJYX1IB3BC6wnjhrS3nVnFFXIyG2OW/Udcqo7z6PBGuJS1waGkC8amklv3z5nBPRqRFdkoQFmQn8gwyDEZbYk= 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)(39850400004)(396003)(136003)(346002)(230922051799003)(186009)(82310400011)(1800799009)(451199024)(64100799003)(46966006)(36840700001)(83380400001)(41300700001)(40480700001)(2616005)(36756003)(81166007)(70206006)(86362001)(316002)(6916009)(4326008)(1076003)(70586007)(5660300002)(8676002)(2906002)(6666004)(478600001)(8936002)(54906003)(336012)(6266002)(82740400003)(356005)(26005)(36860700001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: BuhMOqOfx1/ebfyScJtchf6VS8Aw2YPmaRzKXp+VvY70rBOKJXNKWe+7HVI/rfFVS7HrxOPmpggE0m2pFglBDOT3tc9W9xJoE7rvoCsaajLTxZHpoUwDgQ2QKHsTU1hdvtIF7I2oeDK0g7x0+1znOobO1PE0LFj3MTtBtA1PQmQUXj76vm2apYdSSsbXiAHX8Y09k0j4IR1vYeXrve3GksycUcmM4MQlPJxneCVSWOsVGzn2pedmGvX+9tftzOoxRiCB0d9UyIswKyHL7s7K31J50VKvL5qdgSJ2L/pyQkyt6HFDoX6HL5Ore5UaP//guDWcUCXXBrFYVKbZ6gmMgeWFn9MdNf3C1hKWyD6FjoNw29E/3F2H4o9maCwTx1YFyEuBlz27KFEfpUHRYVs897dVvBvhGcM7t5kI8ocsk7o37A6OzbO70fNnetP3UvexC7mkNA6gJMKUzkhLIUh5VXhOF9rgAvu6DO8a1X06fselcU+3zHnPXeXGJc2z2iT0uJIFu8RBdTpcyRz2biinzAtb7ZZSDYuTttlHUgJTX44SROla/+V1ltb4ZLery5/Adv4CLuI4mioqrt75Vbl1sv4OMPAlsl7VjNE4Bta8O2vhdWQfcAgHE/PmI5Qk1ZOY5Zh6t/0LzkqfRK8sOxll42Ce+ewCzHCP0YBhj2WxBEs6zDxgFNurDMo/L+fBYkjqsfXb48JuLYUci38akyfLHFCNVUMq2tmPakcAd3NTi+aX39uebV9AOSNVt5b2z183vQ26OLMoQjjJSLnmdujQIMXqH8adLpsF1ZnwD1T2avQZ4PzdqVQeD/MTahJXsZ6BCpeMmjMltv8gpl11ubf5vG9HVQXunLCNmtwaxBUxAdg= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:44.4884 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 12a4c581-e4d0-45dc-0093-08dbd3f62b64 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: BN8NAM04FT028.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR19MB6983 X-BESS-ID: 1698085849-102394-31907-2236-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.73.168 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVsaWxpZAVgZQ0NzI3MwizTjZyD LVwMzYMDXZKNXCzDwt2cLU1NzAwsJIqTYWAOQoa2pBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan18-208.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 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 17ae788776db..a770c0a6e022 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -183,6 +183,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 * @@ -220,19 +236,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) @@ -275,6 +282,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)) { @@ -282,6 +299,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 Mon Oct 23 18:30:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433383 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6EFD219F1 for ; Mon, 23 Oct 2023 18:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="gF+0t4lk" Received: from outbound-ip7a.ess.barracuda.com (outbound-ip7a.ess.barracuda.com [209.222.82.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 281EC8E for ; Mon, 23 Oct 2023 11:30:52 -0700 (PDT) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2100.outbound.protection.outlook.com [104.47.70.100]) by mx-outbound47-12.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:30:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MwesQhna9Dq9aEg9YW8Ps+zoloZJGn0nOsIoEbbTbIy2N3iSARivk93VrOMIAfXP0yzPXM8ktOYmWaHWPu8D3o1IDGI6fMvRXtJZNXB+Mnh91YHdQXNiUDEQs+71a6+oims+0cy/cFb4CGzUCgpOgKehFYj9UiCoAAHl8FkQfa3OhDiBhMbIHUHlvYlZLHfJ2s2HavcGZEqrxDoRbv9SrP5m7l4OOqzECypNVSBL6JYXK1JfYRzdHL5ut66BykWWNYpqV59EctWfPbD/VDkDELeSPd+tkLPcFsxHcavMFlaw8lGJnCF1ALxVV0/a6TK9KRIM6C+YeB2EL24Rqhqv3g== 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=NMNnSvyz+X7/FGvxqmDw9AMN0exwQanNEnLSs7cxqpg=; b=YE5ZW6pZe8GAxZRdxEIOUp0GgbPnsXZwX9+ogc8X1TtekgZos8asWYESaYMm7D7fx2sSZ2GZ7Cv5t52y4ZUGE4tJTmmbLihF1TykZGuLUpbWcKV9c320BX8swBQFCQnj5YHA7Mw66fTEFngc34wcz0dzlFQy5+hianW+fC7lNPjhFFI/S7a2+ksniSNsatYJ+zYQlyiv6nhdEZmYtmyF4z3wVLSXcWsVVWrcG0kWTbpaFC+/z/6WBVDIb3wGUoFfP+KoytleF4D23EOXwERPa+cyPxjH/5yQvQQiPbmLegVcPsWJbzjYZZzxNr2WuOl1D4vycihiQ8FLM3YwmWAfMA== 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 (0) 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=NMNnSvyz+X7/FGvxqmDw9AMN0exwQanNEnLSs7cxqpg=; b=gF+0t4lkntptt6JAyJosvwWq9gmnKyzWNZHq+xGqtIqpSJsEMDvEmy0CHWnpz4z+HO8XZlUVGmIl65WBdCOLI6JK6BiowRs1B2Yz7FV1W/9LepzYp6cupg5nTd+PbjC4D9FEXcGoEPuF+g/JZzUWH2Ax5kWbA7O2naoTEqWUofo= Received: from SJ0PR13CA0162.namprd13.prod.outlook.com (2603:10b6:a03:2c7::17) by SN7PR19MB6784.namprd19.prod.outlook.com (2603:10b6:806:260::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Mon, 23 Oct 2023 18:30:45 +0000 Received: from MW2NAM04FT045.eop-NAM04.prod.protection.outlook.com (2603:10b6:a03:2c7:cafe::76) by SJ0PR13CA0162.outlook.office365.com (2603:10b6:a03:2c7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.15 via Frontend Transport; Mon, 23 Oct 2023 18:30:45 +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 MW2NAM04FT045.mail.protection.outlook.com (10.13.30.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.18 via Frontend Transport; Mon, 23 Oct 2023 18:30:45 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 698D020C684C; Mon, 23 Oct 2023 12:31:49 -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 v10 7/8] fuse: Avoid code duplication in atomic open Date: Mon, 23 Oct 2023 20:30:34 +0200 Message-Id: <20231023183035.11035-8-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT045:EE_|SN7PR19MB6784:EE_ X-MS-Office365-Filtering-Correlation-Id: 35745315-6715-45a6-f0d2-08dbd3f62bc2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +/pyDDxPoeJZtxoA18JMIPPveay7Cll+hFEUqrWiPOB+Co3ccYmwW4CE8X7iLTgtyg06Bwx2rtWX4Ms6oRvhG2pQ7qy6fsXZO9xhmK0htC60JEWs2lFEC/1Pq/u6z7EFbiWg6aOmAtaxhwvQBqe+++jX6pVsz2UVaem6kKg4OVsx4/7W8YwEFxPiLYsZ1Dl70/pY7Xlh5c2TCqUQcq4oP2D7EdcbfNXuMHCv09y4C69JTNNpM0GQVREPIs/OEckg/on7vpY4CIErtbxJVcoKiKNt4fWosgs5qzqNPdQBn1vfkFlD3ynp5wUMDSTk34lH98941rFofE+PumCrHyObwwB1q/nOeZVKv5gszXotXbrtIJaO1MU3A4AaN5UYhLJE0T6cClsivQaA3uSblkpbvCVYSPhU8pvex2/tyEqwuDDCV7cMt66OCNVPZdYZpqBLSVepET7psq19auAtN8qCVwOhFm7LumJiFU67gmkKYx9qtS33HvBENxI7C8qAkw9z0OCb7KVJYMWrNb4Kdd8s8Di/fUg6FCb2nghecdZJm3R4wB0geWngm6JwRAmJcHOsBSuR/KSccSvqCsWO0OdJEbxLfnkMUHFRvouFEh4zoNCuXWSussWjLueRJx++K0lhIWZ+1Enc+QtX3V1PMoxTb+0yDFsvDfl2oI73k0aJ7UtSEDHE+W/E/pDxccRUP3BWYrlOdr4YoNYeKRJmR6RYeWsa63dBaY0o/C0veebWf/Ebg/CZTDZfmGV0s00/YsgD65ZQ8n3VMCUGJ/ywVJToiw== 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)(39850400004)(346002)(396003)(230922051799003)(64100799003)(1800799009)(186009)(82310400011)(451199024)(46966006)(36840700001)(36860700001)(47076005)(83380400001)(6666004)(478600001)(26005)(54906003)(70206006)(316002)(6916009)(70586007)(2616005)(86362001)(336012)(1076003)(6266002)(82740400003)(36756003)(81166007)(356005)(8676002)(8936002)(4326008)(41300700001)(40480700001)(2906002)(5660300002)(21314003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ssePut79hxgzQYTHrTU+AFuWGp/05K+hHloxJcuDrEtToeN7qwqp+2HX8ah88dzyajDDeyUajmWnNad/re4TmIcO/oVyhH0wBwsulO8HMLDoMAqfEehX+X0fXHq6zm/Nk+393ZfEgm23fcSgiHF3ntJ5xPs10ERuasVRKO0hb3JdqytdJYVbmFws8X/2rmChTGlUW1CANjqaczfvGvf9+odM589rg3hkbk8Jx9pCL+/Oyjpoihh6ruOlAsmcRF1chdCnDijjDJh6jP5vTgiEA7Ub4MgjMRVUFKK4/9n4Zbdocl+XTgYrFTHV30ewQ6lQP86GLyeKR3DTsG7x+MoOTxXKdHk3NH9ezw1xu76+Mjt2eGwOgBSuKzpFv40CeBIt1IyqVIy48U6WJ57w0XaUjCEb10yUjm9K7au1lIDzdHcnn9yav7Jfkm19cajACFAcoyhDHa5CCazZZobi0Zg9SgOOOmYsie4WZpjUKtE/HZuLNXt9+zm3+m/Gtz0FRXCS1sLCS893qJWzgmsVpZRDQcA+bPPgAgmozmE4lkt2YC0ZPZIN+p0XIlVy/Z8iceMm5Hqnwpw9/51jqLUUc0kJsI/vsYRSq1WbSYbqzVgY427/byMQn2qsylG0HTOT1ATbR3DgijmCMBYeZ/E2nekN+G2eezxoNTKjOzmuZjbG1wqZ27x7YtKQsyIdlsUhOaWaGdQs4bQcjXFRKcJUWU5AzzROzTUJ5HAlTYsfE75KjllrUpukdmW16EWqQUg/OQtbyq6C+UeliZavwRWDn31ni7NJUEVTIHjZyq47D1Wd8Abnf1PNC1MovB+vAWaCRKHAYZJwKp8jpWw7DMf0UFMZ9N1AANU2RP7euS/mehfqQ88= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:45.1887 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35745315-6715-45a6-f0d2-08dbd3f62bc2 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: MW2NAM04FT045.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR19MB6784 X-BESS-ID: 1698085848-112044-12589-1010-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.70.100 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkYWRiZAVgZQ0MzczMw4OTHFwM QsLTHNzMzAIMnQ1NI8KSUpydjY0DBZqTYWAA6O2O1BAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan10-35.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 The same code was used in fuse_atomic_open_revalidate() _fuse_atomic_open(). Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: Horst Birthelmer Cc: linux-fsdevel@vger.kernel.org --- (If preferred, this could be merged into the main fuse atomic revalidate patch). Or adding the function could be moved up in the series. --- fs/fuse/dir.c | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index a770c0a6e022..c4564831af3c 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -801,6 +801,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 @@ -829,17 +848,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); @@ -993,27 +1004,15 @@ 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); - switched_entry = NULL; - goto out_free_ff; - } - - if (unlikely(!d_in_lookup(switched_entry))) { - /* fall back */ - dput(switched_entry); - switched_entry = NULL; - if (!inode) { + switched_entry = NULL; 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); + switched_entry = NULL; goto out_free_ff; } } From patchwork Mon Oct 23 18:30:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13433391 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B7CC219FA for ; Mon, 23 Oct 2023 18:31:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="06SUQ9aW" Received: from outbound-ip179b.ess.barracuda.com (outbound-ip179b.ess.barracuda.com [209.222.82.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CB628E for ; Mon, 23 Oct 2023 11:31:42 -0700 (PDT) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by mx-outbound16-95.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 Oct 2023 18:30:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YVIdVGMh8ANZXIHC37XOtAFZXPiIz2TYN7GCxxJjl3hS8bpbVTcPgfDMHkRu5oXWSmSsxtUD95a0FvuhvDuUn8TruMTRMHZSElIUHBy7i9KrTixYI8psBERV5RVaFQuPm7NOwGfXdt6JCfZr+JqZLBSBa8GI8P57OCzDMpjfRNT1cj2XlyIo5e/iU3sLJMBUKBhLgO7FZdwZ9ZGH8mFmR0EroN5Xztqdi4+9Z9ZiDlqSVBes6kMZzhyCwY1MQZCM+nNyBOeQcPKwg7HnWswn4uMzp8HLc/DlJd+kGfaXjA7QP5I0hj325HVzjqqOWjm68bIjhvVrFu3fWPl2qrB4Yw== 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=ipuKun7AIUFJAX/g3UZKKugchS/1PCdFI2z3kNT3oRM=; b=hCH1OqbUOECPaQzwXsy5yaS+cbhk28FGbdcgL7jazFasZDumvTBLZNoYPeLNTBZrbpZP4HtTNSGluZU++KWUG4h8hDu+LmfXp9gkgx8/W4LWfwC1yF32unJ+tPFpMh7XWuef+f7ABuZqFjQUyMOQVG8MaBaizeObxFiYmCsAdKx25oxEXvN751Uo+mAbM/CC4rkH2D59XrzjAfq5IgoJKuOyV+jF/x1wgNPEamQ78K0o66eswyWYWFwq+96HsixZVNQY9UO1U8VPRhwMKu9jDBeGP+1ubAE4Z93EztKuFQ9tJFcEKHbtjZLsZAykgeuEdxTYhW4DeNY5YuKtTzz0OA== 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 (0) 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=ipuKun7AIUFJAX/g3UZKKugchS/1PCdFI2z3kNT3oRM=; b=06SUQ9aWUQnejPD2LsdZRs1l0yvDsxFHXdiguM7vPg+sCD2J34Sy/rD9NXANflt4/oOej1Q9SIyzS56MLBsNlS2Q0fpbDU484RotsivX2Eunsk51UV6MkKOZyarFsb5UD6wK4gXviugXvofhbdnUGtkzVg+1Yq9PH/5uq+ZmwDs= Received: from MW4PR02CA0021.namprd02.prod.outlook.com (2603:10b6:303:16d::31) by SJ0PR19MB6900.namprd19.prod.outlook.com (2603:10b6:a03:4ae::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Mon, 23 Oct 2023 18:30:46 +0000 Received: from MW2NAM04FT028.eop-NAM04.prod.protection.outlook.com (2603:10b6:303:16d:cafe::5b) by MW4PR02CA0021.outlook.office365.com (2603:10b6:303:16d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Mon, 23 Oct 2023 18:30:46 +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 MW2NAM04FT028.mail.protection.outlook.com (10.13.31.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.18 via Frontend Transport; Mon, 23 Oct 2023 18:30:46 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 61AF320C684D; Mon, 23 Oct 2023 12:31:50 -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 v10 8/8] fuse atomic open: No fallback for symlinks, just call finish_no_open Date: Mon, 23 Oct 2023 20:30:35 +0200 Message-Id: <20231023183035.11035-9-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231023183035.11035-1-bschubert@ddn.com> References: <20231023183035.11035-1-bschubert@ddn.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW2NAM04FT028:EE_|SJ0PR19MB6900:EE_ X-MS-Office365-Filtering-Correlation-Id: bc89b397-98bf-4e69-8772-08dbd3f62c5b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TRhEZ+ZR+eNuN82XBxesXI1YMAGXBMXO/JBAyQrVmuu4wPHljPcttPnVtOd8tLn6Qw7D/NZIIhNQtrhUAAO3jTFsYBo+kipBs9sYPVuv8D2otnj/l1pLKwIm5DfFvfAGZqVYXQEJyGDa/TzvB8SRZH1zUnio77ViGYuykA4MJZ91Q84Z0TJ55LlqaJtk3Ft2Wn1qBnC+XdD4pg9h5Jh4WNyCzC4JH8+6roLkHvQ/UkyxAHQGsG4sqr5HwgPaI4yWizwCX8miny+5RL4TmZ1SdLS2s/c0a3Q61vuOkb1SLsEGq6HeWMx5Fx7LErfbLDLkac8afRxwTo1tkZl7BQCl/mz0fmvLEVRKfsuIYSkHyfiemLNtp0rqGl5cHsjg1rHlqEfKvhzrUqq2jDNZPKUY3lg8aJauVtly3i7ZXVZEcsa3Q9sHJkY3/bPa/WWduqo+aqWQv34dEbpcKmHSoFGfpQo2a2FGaNB3obDXxzAC2mP8JBoG8ACIIDPaqG4vHxBTYVNi3Xx1lwm6rX275w95H5wzPMCglxb1D0d6AmL4IO3aJ0HDDZTL1yd2B0jjdsHQ+RxK9MiQhL/VjOz9w96t3OTuKGdHsqudpIZ8g3xsmKkjQe1fqIzTexZdCZAqx90Z52JFgvSUKgUO0Jgprrxh+kIt2MFXav+b7SLD0+1J28xfZoEqn179vd/wbbappSBtsw5DU6WfwjBRNkWVMpHN5PG8Ai7iPa0TgDROwVxx/AqC9l+iv3Wtux+09dlSRVYFtVIY2uo8VAoRGRSE1EATny2mFXvN+jcMB7MsagujU2I= 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)(346002)(396003)(136003)(376002)(230922051799003)(82310400011)(451199024)(1800799009)(186009)(64100799003)(46966006)(36840700001)(40480700001)(36756003)(8936002)(8676002)(5660300002)(2906002)(66899024)(86362001)(6666004)(41300700001)(26005)(336012)(478600001)(6266002)(81166007)(1076003)(2616005)(82740400003)(356005)(4326008)(36860700001)(83380400001)(47076005)(70206006)(70586007)(54906003)(316002)(6916009)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: PDHz22V8gp+/XKgsrt0+FSu/y4Ri8kv21zhh1jcst6i2ZWbJTLQZaleBGh+s+XZ/ye6OEgjo58UeljxzfqRloQvdIBLiMk/EGk9nM8pNR+RJn0aekR1ozE/9nHyVLG4QtceeGgech6BnZBcz7rOR0i8XN6IjdF77kzR1zvj4WzbEm2mZJPh0sYGwTaPdvEzSXWl8gASBKuFvvfkWDVeFnkckHbAddEwlIoXvEbX0vH3qsBpoPyuRNOtwC0R4d0zR4AyiZsIGwHZN7kWwDVRmmY9rxpUSCduyTJmGDVrhy5S6014T1tKh/l4DgJObgcVisVTi5Mk7OahvucmsIGB4r7mKSMQk+rko7zQg32dZF8jPM4pPsHIJUiWPzpGg2NRJlBLinRAJN9GmIGHwzed7wnuntoldA/CuNR7Nw4HfYZoctoO6W2St665Ygf8YaMveUBADSDc6t01WHF2ROa4SGH6/1i4312An3zeSyYuJEs0/mpbwTxTVl9hoN4s+MW1sFkc9mgPInrA1EfyNw5b4MyApkWsXMeOJeRpl5YAmzCdlH+TlQvRJhwyuPmsUcMD0yTs+yMq5bxpCgJD7USuXZrMeBYdtW/K1k0JLvNpe9tOIfHcCm8EfLk5kClHaeTuhLSnLzDh7qYhKZM/+ktQ4bnVDqD9xSPwwB3N4vM24Oggi9hfsV+QZ4zGpfAEhMHbYsr1yVh+UoJuRi3S59/avdUOKCQZW8r5ZhFb5ysYbIWJf1GLOWg1yy12Bpc7AUgCYITaWXWV5qKENjmfbsBKL44nL+7Xl9Qgx+D50lPQmnQDU/TeIMX9KoivR+lHXNakRG/ESH3A5hz4KBVKMKU0aRD+OQCac9bG6z7NQRDKiFbA= X-OriginatorOrg: ddn.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2023 18:30:46.1887 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bc89b397-98bf-4e69-8772-08dbd3f62c5b 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: MW2NAM04FT028.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR19MB6900 X-BESS-ID: 1698085850-104191-32505-327-1 X-BESS-VER: 2019.1_20231020.1656 X-BESS-Apparent-Source-IP: 104.47.66.41 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkYmBoZAVgZQ0DzNwjIxOTEt0d LCMMnU3MggOdXU1CzRzCzV2NIoxcRUqTYWACcUPJhBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.251639 [from cloudscan-ea17-231.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 Symlinks must not be opened as it would result in ELOOP, but fallback to fuse_create_open is also not ideal, as it would result in atomic-open + lookup for symlinks. Atomic-open already carries all information lookup provides, so just use that and then call finish_no_open instead of finish_open. Codewise, as finish_no_open consumes a reference, compared to finish_open, dput(alias) must not be called for symlinks. Obviously, if we don't have an additional alias reference yet, we need to get one for symlinks. Signed-off-by: Bernd Schubert Cc: Miklos Szeredi Cc: Dharmendra Singh Cc: Horst Birthelmer Cc: linux-fsdevel@vger.kernel.org --- (If preferred, this could be merged into the main fuse atomic revalidate patch). Or adding the function could be moved up in the series. --- fs/fuse/dir.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index c4564831af3c..e8cc33a8b3a2 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -978,9 +978,6 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, goto out_free_ff; } goto free_and_fallback; - } else if (err == -ELOOP) { - /* likely a symlink */ - goto free_and_fallback; } else { if (d_really_is_positive(entry)) { if (err != -EINTR && err != -ENOMEM) @@ -1090,15 +1087,23 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, } } - if (S_ISDIR(mode)) + if (S_ISDIR(mode) || S_ISDIR(outentry.attr.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); + + if (S_ISLNK(outentry.attr.mode)) { + err = finish_no_open(file, entry); + if (!alias) + dget(entry); + } else { + 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); + } + dput(alias); } kfree(forget); @@ -1108,8 +1113,6 @@ static int _fuse_atomic_open(struct inode *dir, struct dentry *entry, dput(switched_entry); } - dput(alias); - return err; out_free_ff: