From patchwork Wed Jan 31 23:08:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13540485 Received: from outbound-ip191a.ess.barracuda.com (outbound-ip191a.ess.barracuda.com [209.222.82.58]) (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 268C13C465; Wed, 31 Jan 2024 23:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=209.222.82.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744517; cv=fail; b=DXZPLf+MgloiGxOgxvvbw700+DMmFEUbbEJ6iNI6hEeNBVs4lASZ30vvAjVet9mxf5haF1XkzRMjCfIQAZm1FJSX5y/p77BAsfXTussmXfh/goLvFSj2c3CAxapz5LAodZCmJEQhy7yDgTriaLgUuWpMEL3cE4yFc72o4+IVux8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744517; c=relaxed/simple; bh=w/qdrlQHUQFRXSYKDNwfuBKSHHOpOzbvT7jUkwdXmuo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=qsHaGzXTpQtEMrpr8YDQxMSMywy2xzHI/LY/kFvPaOZ4z6XiZfcS/+ho2tTYyM4d+DhmfZMdBJcLWatJQ48v7F9lB/oD8hhIsiKi8bAX6RcrftVDQqVVt5lxEaCzlImNG2HbjZ9o9djDSxFCX7tX0v6NQOaHQhoQredHUwY7SPg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com; spf=pass smtp.mailfrom=ddn.com; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b=BDg5a++l; arc=fail smtp.client-ip=209.222.82.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ddn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="BDg5a++l" Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by mx-outbound42-190.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 31 Jan 2024 23:41:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i0XmWcLHpwKZYqbs7mO34n1RKX04gL8+bEkkX7O3k4cniLoAT5PitAqmuYUjL0qxoxvDN4e4CrCCgwRtuLKiSbrlc9R1z8JoIaeXvVF+6ySIKZ2slU9GnPxLfDlssVI4R+EZKSan068wbvJoWZjuS3PZfZIthOsnWfuUIGBE3mp4sPNAT1sQqZWgQJ7eZlkOmKUflUL+v08sfsVpTxcnHO6ibPeKzUl70YFwcVXHg7LbgzWfbfPXAivzWu8qFEw8PsobMagwJXQzZPwNpRAYGferQA7j6HyYfXtYUkDqXbs2oYkNGVmxa5BMF2vi3Yb5jkYhtfe2g5mnapMO/LFB4w== 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=SlwMgrrYyb+E0Cc11FVK6rPXIMLM7rK/vKb6FfSFyjY=; b=HY0B2vP8HIufRxym/n8tD0vhv0KCDDKPfND72JWX1SkRU9n5ODA1+NT69XdANgxcE1odxIEJiHwqOnGs+440njkJ5pttkwdy0JPFlGR6vIecmx+6nBV5omIlHFCrG4KqVrts9tXGaZ4ReyeIRZ+v2C7EoPzs30a4H9yWG/9xdsSCJKqkQLd21BP14R70+8W5kaQbCO6RDg5bX136/v+RG+7obCNoqXOcof0HJk8HiJnfdqlmPZzXN67y4eMo3Kl1G7q38bXANbuEralbuW5N+OC1AZQ3VAxooqtJ375JgMGijy7UKU1A5jYqCI82pWgyIoC7v/09QJ30NjB5BtPXZg== 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=SlwMgrrYyb+E0Cc11FVK6rPXIMLM7rK/vKb6FfSFyjY=; b=BDg5a++l/ZJ9NSY6l+SEY8Xwi+wfIBE717gNmmOUNTSk5JdZZekKhaIWnXhjCpJfNZMRg6nkw8GOitE4dGsejf7dRnr24gIabGgQPwSa2mNtL7z4FeZDIjV8ARbU7FvBUL8YObJYTwHFK9M+DfXz9drnGzhsCAy+r55YDPng+q0= Received: from BN9P221CA0025.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::22) by DM4PR19MB5908.namprd19.prod.outlook.com (2603:10b6:8:6b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24; Wed, 31 Jan 2024 23:08:55 +0000 Received: from BN8NAM04FT056.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:10a:cafe::f1) by BN9P221CA0025.outlook.office365.com (2603:10b6:408:10a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.22 via Frontend Transport; Wed, 31 Jan 2024 23:08:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 50.222.100.11) smtp.mailfrom=ddn.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ddn.com; Received-SPF: Pass (protection.outlook.com: domain of ddn.com designates 50.222.100.11 as permitted sender) receiver=protection.outlook.com; client-ip=50.222.100.11; helo=uww-mx01.datadirectnet.com; pr=C Received: from uww-mx01.datadirectnet.com (50.222.100.11) by BN8NAM04FT056.mail.protection.outlook.com (10.13.161.127) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7249.24 via Frontend Transport; Wed, 31 Jan 2024 23:08:54 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 661C820C684B; Wed, 31 Jan 2024 16:09:55 -0700 (MST) From: Bernd Schubert To: miklos@szeredi.hu Cc: linux-fsdevel@vger.kernel.org, dsingh@ddn.com, Bernd Schubert , Hao Xu , stable@vger.kernel.org, Amir Goldstein Subject: [PATCH v2 1/5] fuse: Fix VM_MAYSHARE and direct_io_allow_mmap Date: Thu, 1 Feb 2024 00:08:23 +0100 Message-Id: <20240131230827.207552-2-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131230827.207552-1-bschubert@ddn.com> References: <20240131230827.207552-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: BN8NAM04FT056:EE_|DM4PR19MB5908:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e347a6d-9fb6-4ab2-efc2-08dc22b198a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rt6Z1jiLDmtKKylBmhdhBXlHQNyzdWJ/prO4z4ugN4gJ3q8I6gBFrzm99pp1pGrWu1UDQxvk/+c2UJ1JHhq8pdoqzDGHYv6ILdGSsk8ONgILfSXf6eSoGJsvd48USp/XCNFwvrrUIV5xkj/G0MaDWT/3rGrOuB6sS2og+Nf4jDB4PYq6JrylSE4NkVSjbmwyCx+aKaIbPRjMaH5xCMycmFNAw5nGBuBV5GcHuaI5AE/JmrzINxCssVNldjlE5zSsBEkiue5YHe24mVlgKLPC/KYEOuRoDPsUxChNVzilbzii0+gRngZgNlqtP7CS91xqi7yL2ZTOSOvJA0228qntNFPJFhSGEmT+HGlXv5/JFIQoPhDyOtO2AbmmT7zN088h4AKC6hgOY5AoDlRneziRbOZhmfrOlycs7JoSMvrarD5wHOlzx4fu1rlDEdQAHQ3apa0QP8AdbEVN0gRdemwnxv7E9gWeHCjeDffkuxJsG5LoIptmqduifxqlacF1FE2eKcEIK95HsZ7i3dml6p6Nrj8nnM35NiiUx+SEpTp6+Cxi8mn+xiK5TIpBJU79avRi2NN3JShvZjaJtBDGjcDCQft4SEdLZ9mWGhehmDu/RbqkEvE5qvUv6Zjfd+sMrQMuuYqakR3CGENxYB8S5vq2beK2Yh92iH+4lCvT/UO+8VB8qjyTY/KQqzptM+1bG0hIVt0+nwsLd7MBps0JEgPG8R+aAOPP3VMdxU2XzYQ24qp+zmhezP1Ro375pbrbBUlUu9oRvS//6po1Y1R3+/AuhyFCYDmmlU+9bN2+/x2Ixbg= 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)(376002)(136003)(39850400004)(396003)(230922051799003)(230273577357003)(230173577357003)(82310400011)(451199024)(1800799012)(64100799003)(186009)(46966006)(36840700001)(1076003)(26005)(5660300002)(2616005)(4326008)(8676002)(47076005)(336012)(2906002)(83380400001)(6266002)(70586007)(70206006)(54906003)(478600001)(6916009)(316002)(8936002)(6666004)(81166007)(36860700001)(356005)(82740400003)(41300700001)(36756003)(86362001)(40480700001)(36900700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: R1cig1SojKK0AyR43AOwpoBLr4lg3Isi5jt1G0KJcOq24oNyCzLdjll+hxA8pQxhn8Ckyfre26KImKCbtX/YnHMdI1QeTp1MRHa0rNzQsolj9cdSVz3lTCrug9Wbe8zmRjES1dqGK6sk5vHe+hPQDOPr8kIvUgo1z7KFqwcxvyK0gQ2NFd4Z6n9bdz0bfoo+r5jeyHZj6BlipywEmEv13KyYGMhOD7cuneGv+W9qH45rclDaBnUvee6QkVljA3WZ7lvGua1nlFopkf+fblsda1IvnFBfAw9wVRlxtGYFJltJQdU2B5bRprVdJOhW33pRIVgUYGwFwkFeQe4hstEsdTnwgT7UDeFOcRxkQhoLcup1MZ5ddbauM+uZmhjIXXi4qzBYlk7psegCxcG8kr1VjKrWij0IPOA8py25VlOacE+gmTLy077JO+c//sEMoyoIrCU3hFg8vk+SyfrvaBQCVbwuWqtfRWEkMc1SHTmqvy7YIFDYM8qWJtaI8etZkwxARjDmlYPa/4wu/hTQZiwe+kGZoc5LDfbRd7cRktpnqbfcMMmsjIIUsSIa65Dk/gXQk/lP18NteQlOt4kTEanUQyHnGEjbRyDzUlr3MrcxeHofwMubDze8GHlhbKRdsGR7RFx1s9g95SNzR5SrVWj6Wg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 23:08:54.3576 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e347a6d-9fb6-4ab2-efc2-08dc22b198a2 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: BN8NAM04FT056.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR19MB5908 X-OriginatorOrg: ddn.com X-BESS-ID: 1706744514-110942-12526-2818-1 X-BESS-VER: 2019.1_20240130.2130 X-BESS-Apparent-Source-IP: 104.47.58.169 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoamxoZAVgZQ0NAoxTjJwtLYIN U0JdXYIsXS1MTYICXFwCA5NTHZyCBFqTYWALdr1FtBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.253897 [from cloudscan8-162.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 There were multiple issues with direct_io_allow_mmap: - fuse_link_write_file() was missing, resulting in warnings in fuse_write_file_get() and EIO from msync() - "vma->vm_ops = &fuse_file_vm_ops" was not set, but especially fuse_page_mkwrite is needed. The semantics of invalidate_inode_pages2() is so far not clearly defined in fuse_file_mmap. It dates back to commit 3121bfe76311 ("fuse: fix "direct_io" private mmap") Though, as direct_io_allow_mmap is a new feature, that was for MAP_PRIVATE only. As invalidate_inode_pages2() is calling into fuse_launder_folio() and writes out dirty pages, it should be safe to call invalidate_inode_pages2 for MAP_PRIVATE and MAP_SHARED as well. Cc: Hao Xu Cc: stable@vger.kernel.org Fixes: e78662e818f9 ("fuse: add a new fuse init flag to relax restrictions in no cache mode") Signed-off-by: Bernd Schubert Reviewed-by: Amir Goldstein --- fs/fuse/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 148a71b8b4d0..243f469cac07 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2476,7 +2476,10 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) invalidate_inode_pages2(file->f_mapping); - return generic_file_mmap(file, vma); + if (!(vma->vm_flags & VM_MAYSHARE)) { + /* MAP_PRIVATE */ + return generic_file_mmap(file, vma); + } } if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) From patchwork Wed Jan 31 23:08:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13540486 Received: from outbound-ip191b.ess.barracuda.com (outbound-ip191b.ess.barracuda.com [209.222.82.124]) (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 E4D1F3A8C2 for ; Wed, 31 Jan 2024 23:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=209.222.82.124 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744556; cv=fail; b=k8KOmv0hjn4EBs0sekR6WfneT2VDAiYb2iPOVuA9DgTKtcfmJ6791Hc3xnQyeW62WeNLaeT8+ysKCmg8+r2mznT7FGvFhWhUH88Oq9cvVwvRigsuzgVPGKDCjmhiXbIepEUPO/kgPNlB8uAKhaeiwMlNM/mQeHA7jEMAy6A4KD4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744556; c=relaxed/simple; bh=Skwtf1LwuDirieqOOjqTfwrJX+i7JNPO7ZoCmIflvG8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MRctbLo7LmEI21myaPloetK/GLj3lDofEBnpvXUnTnHovhLzlRuvDhpFn0Xyir5VKkRFwChmv3OqHV0coqEIqLGWg/ynkXkm6/wmDpnPoNWMgONkeCZHHtCzKksJuRXeGSF/hPgQ9Ng8rGkeOiVjM6KiVZjjf9RTZXyubfu7qOU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com; spf=pass smtp.mailfrom=ddn.com; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b=Vy0LFGZV; arc=fail smtp.client-ip=209.222.82.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ddn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="Vy0LFGZV" Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by mx-outbound-ea17-82.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 31 Jan 2024 23:42:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VZ7M0oGcp7fniyn5XDY+F3v0imobA6xv7CLoLe0ulq/u8utBjpe0dQ3iCwn8TVLWP5nhJ9mn6mZBL9NAhAoYeLbNkcls1QcAlawNfTsWrOgaTCoNnIzv1Bkf5S6M8O5Sbo8mAj6EiUU1AfhfBHHoxOLAo0oBdVZOe2qh7nwvLwIJnE7VgGAQWy+X10JT/Gf6OQ0w6MdHRhqgz+wnLG8zHrV/NT1ZKq9PR94Dn27Bgclt4EANILm1vC2/1Z0W6/6GSUi+h8JP8B+yc1C5VIu0aSj/v6bgv4QlJpJyTKxxsap08rni+te1/9PxGuLyi65z43UpwiQJ2vL4Jxrbzeciog== 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=I3JAsM2e0eb+N55RRiFXReAc/QgCODbEHDEh1Yf7CgY=; b=HITNFJ6D33ykzujsmoK+15WFEDLbpI7igu3UQ8yFmt0PZCEsa+jfg9MVVvzxd+lWvXtnBK+XALhF3B+StgPwFFsqbnh4AvHYU8IT2s8lH57k/i5JBfpMrgAjx3qHldDunvS3OyFcQZHlPFB+Tl3aOFVMqEJCVVC/FpghjDsUK6uH/FeOv3Eh/eOg90M4LH3bEwX4/3T4Mo8Xa6cizgX9yJo2xgWiLjDWCy6ZlhihFijoyK7dTuUvLWJwmy/9zuPUjYOnShsMy2798g4AnK59/31m7A8SvWjkIp43+QqhOrqUhFjAxMXHleRgacXL4nH/l0HabZf3Sx8TFs4KWwl2NA== 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=I3JAsM2e0eb+N55RRiFXReAc/QgCODbEHDEh1Yf7CgY=; b=Vy0LFGZVRbIxteLqIo19oPGop5Q5sLSa1JFGGDuNsgZ1lp5/pZolbTUNhK2xtvW7nJHb9xhA2kVNyY0kr3vX4Nfs1zChz0PCjufLL7ew8U6PBaf2RD7XAQfbvt7+Fg9ebjn6jWZ4YlQvRBSoSLwBZ6oCwrHvsLh7udUACV0ue7s= Received: from MW4PR04CA0064.namprd04.prod.outlook.com (2603:10b6:303:6b::9) by DS0PR19MB7958.namprd19.prod.outlook.com (2603:10b6:8:166::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34; Wed, 31 Jan 2024 23:08:58 +0000 Received: from MW2NAM04FT024.eop-NAM04.prod.protection.outlook.com (2603:10b6:303:6b:cafe::46) by MW4PR04CA0064.outlook.office365.com (2603:10b6:303:6b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.23 via Frontend Transport; Wed, 31 Jan 2024 23:08:58 +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_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7249.24 via Frontend Transport; Wed, 31 Jan 2024 23:08:58 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 50D7E20C684B; Wed, 31 Jan 2024 16:09:59 -0700 (MST) From: Bernd Schubert To: miklos@szeredi.hu Cc: linux-fsdevel@vger.kernel.org, dsingh@ddn.com, Bernd Schubert , Amir Goldstein Subject: [PATCH v2 2/5] fuse: Create helper function if DIO write needs exclusive lock Date: Thu, 1 Feb 2024 00:08:24 +0100 Message-Id: <20240131230827.207552-3-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131230827.207552-1-bschubert@ddn.com> References: <20240131230827.207552-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_|DS0PR19MB7958:EE_ X-MS-Office365-Filtering-Correlation-Id: 15bbfae9-bb9a-4c28-fadc-08dc22b19ad0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wqafroAcZjq2AQFFntISKmZIuMrRG2K1snz9xpK1i3dFYTGu9uNugd3IQiOaTulJfIQ2skKkHyePQn//6PDY56bS2HSvOnnwYavgiNzoe9JVjInUz91zi22YNkwaJPhtllFrqtX/ESFpv/RiqXcn7QS+/UEpo1J3GZPyuLz7uN7qwJeeP9kSWS+llVaPedgtOVzcPUAeda7pObvbcykGyqHBmuQtHWUfGvka99JZJAOG0U+BReVhFmOI4EemcxI84rgX4zNCJLBTb+th24xFHlJVqNaO8Gtp9arQnee4MMMKPk2E9+5wObLBIIF4lwmBemC444TJml6oBcn26gNCg8XCjcW1hZNKKtRYSohg2Vf8n60IxzZ9ReQksdvmJ8svvIdjW0rlL5RAd+73x1zS4V2ZWayfskGgbX57osjSX2/G2FCacgFdg1PMRt13RzY6LHxYy0yDIpmHvtRaQhpEHoJuCAOqxqSM8+IUYa6g2aFIDSWvNrGdYloBucOx0e+TOU5rNhJqz2aiZf17j6ad0PlichsvlgU5ffEzs5Nna0wScmmlfI1FsOqLNChbYGCfaTJGGp6QI0LLgERYPzB37gcQhdh3RthvWEeJ+MIh+YG3/ps2aUD1YEs/t4RjbIL7wuZTjnY62NGNzHgzsKE04+NnwN+Om92aDKTN3pKJPDW79Ohsq8zl+PV2cVlPDOdYtgnpgO1DV5JVuG9QnUTbDu9Cc3iV3M2k3vRVthuUTs4t2LjC5GvwvH2m/k7KqA3c 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)(64100799003)(1800799012)(451199024)(186009)(82310400011)(36840700001)(46966006)(40480700001)(6266002)(336012)(83380400001)(26005)(47076005)(6666004)(1076003)(82740400003)(2616005)(356005)(36860700001)(81166007)(36756003)(478600001)(6916009)(316002)(54906003)(70206006)(8676002)(70586007)(4326008)(8936002)(41300700001)(2906002)(5660300002)(86362001)(36900700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /b5gMVerKfGGpNokjqNQ+7OVzIkUf2iXqrnZPvJ0yqV5kuvj6bEW0CjBN5TNry3jQlHvhOntycYlE9PJiEfki9karq5nx8HrRyHlu8P42YX4LX2rnd593XFvbCwL/GniPcPC54JkMrRS8olZVb44exdUDzUKC3rm96pIPYckr0Wy3v4kB/c0VT8zXHj7xOfBGU7ZTmiTWnUFfV6lmJuTA4FVB6onU2fGvgn250rm9/DvDro+xW15RsgEuDErDllFugd6T+kk3u661f5uxVej2AL6S1zpp40jKL5J+zwR1yegGmdEbmlQ/wG0xdBa15h/LkCgZhpT3mjAORNKe+6A3bu+QLNjeOWPWDM2CNIXM13A77yPtG2Ds1S07ZHn+YkpXUIpwedTOv1sCBGATEKCt8zaY2u0WfrmbEdfMpBu+u12/dB6fhkdltSFE3mryN/H8TJOONT8APT44GZzmMikd0fMz3+thdTHeZM4lUzrGqhMZk4qO5M0wsZ8WHW376fc9tEYTtrwyRrOok2HuwhZn/xc6mbXnhQ/yAgLZPEVauEPhKKcOPsZCbItEPySsQT01U6yugrJ8MbsuKituPhuhpkgxD57k+8PtkrtBXI3r16C0xjIJVtXjywcIikGW3L9Laiw1D+qutGGtBi1FQYWQQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 23:08:58.0773 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 15bbfae9-bb9a-4c28-fadc-08dc22b19ad0 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: DS0PR19MB7958 X-OriginatorOrg: ddn.com X-BESS-ID: 1706744553-104434-2504-42069-1 X-BESS-VER: 2019.3_20240130.1849 X-BESS-Apparent-Source-IP: 104.47.58.101 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVsbmJmZAVgZQ0NLYzDzF1DItKT UtydLCJDHZ0sI40djS0CLFLMnQwshAqTYWABF+CNtBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.253897 [from cloudscan10-213.us-east-2a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound 0.00 BSF_SC0_MISMATCH_TO META: Envelope rcpt doesn't match header X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND, BSF_SC0_MISMATCH_TO X-BESS-BRTS-Status: 1 This makes the code a bit easier to read and allows to more easily add more conditions when an exclusive lock is needed. Signed-off-by: Bernd Schubert Reviewed-by: Amir Goldstein --- fs/fuse/file.c | 64 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 243f469cac07..0c4d93293eac 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1299,6 +1299,45 @@ static ssize_t fuse_perform_write(struct kiocb *iocb, struct iov_iter *ii) return res; } +static bool fuse_io_past_eof(struct kiocb *iocb, struct iov_iter *iter) +{ + struct inode *inode = file_inode(iocb->ki_filp); + + return iocb->ki_pos + iov_iter_count(iter) > i_size_read(inode); +} + +/* + * @return true if an exclusive lock for direct IO writes is needed + */ +static bool fuse_dio_wr_exclusive_lock(struct kiocb *iocb, struct iov_iter *from) +{ + struct file *file = iocb->ki_filp; + struct fuse_file *ff = file->private_data; + struct inode *inode = file_inode(iocb->ki_filp); + + /* server side has to advise that it supports parallel dio writes */ + if (!(ff->open_flags & FOPEN_PARALLEL_DIRECT_WRITES)) + return true; + + /* append will need to know the eventual eof - always needs an + * exclusive lock + */ + if (iocb->ki_flags & IOCB_APPEND) + return true; + + /* combination opf page access and direct-io difficult, shared + * locks actually introduce a conflict. + */ + if (get_fuse_conn(inode)->direct_io_allow_mmap) + return true; + + /* parallel dio beyond eof is at least for now not supported */ + if (fuse_io_past_eof(iocb, from)) + return true; + + return false; +} + static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; @@ -1558,26 +1597,12 @@ static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to) return res; } -static bool fuse_direct_write_extending_i_size(struct kiocb *iocb, - struct iov_iter *iter) -{ - struct inode *inode = file_inode(iocb->ki_filp); - - return iocb->ki_pos + iov_iter_count(iter) > i_size_read(inode); -} - static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct inode *inode = file_inode(iocb->ki_filp); - struct file *file = iocb->ki_filp; - struct fuse_file *ff = file->private_data; struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb); ssize_t res; - bool exclusive_lock = - !(ff->open_flags & FOPEN_PARALLEL_DIRECT_WRITES) || - get_fuse_conn(inode)->direct_io_allow_mmap || - iocb->ki_flags & IOCB_APPEND || - fuse_direct_write_extending_i_size(iocb, from); + bool exclusive_lock = fuse_dio_wr_exclusive_lock(iocb, from); /* * Take exclusive lock if @@ -1591,10 +1616,10 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) else { inode_lock_shared(inode); - /* A race with truncate might have come up as the decision for - * the lock type was done without holding the lock, check again. + /* + * Previous check was without any lock and might have raced. */ - if (fuse_direct_write_extending_i_size(iocb, from)) { + if (fuse_dio_wr_exclusive_lock(iocb, from)) { inode_unlock_shared(inode); inode_lock(inode); exclusive_lock = true; @@ -2468,7 +2493,8 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) return fuse_dax_mmap(file, vma); if (ff->open_flags & FOPEN_DIRECT_IO) { - /* Can't provide the coherency needed for MAP_SHARED + /* + * Can't provide the coherency needed for MAP_SHARED * if FUSE_DIRECT_IO_ALLOW_MMAP isn't set. */ if ((vma->vm_flags & VM_MAYSHARE) && !fc->direct_io_allow_mmap) From patchwork Wed Jan 31 23:08:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13540508 Received: from outbound-ip191a.ess.barracuda.com (outbound-ip191a.ess.barracuda.com [209.222.82.58]) (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 636BC1878 for ; Thu, 1 Feb 2024 00:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=209.222.82.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706748166; cv=fail; b=jMp1cPnSEz5Y28ibiUyuWSCVdsPaMYgsFl5j4AHY1zL4HlpCeomzcDQKJrbW+oy0R7+qMfVYlub+ysX7Q98qWohV2ZGte6HOdskyvRtBRy+BcIi3yCUPqwfhnmNYhs0vd7W2uJ2aKTuJts0Qrhc+XPBqr5ACB7WcTya47qtbBPE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706748166; c=relaxed/simple; bh=m/ptzPoH5yL1A/0N7KGTp4a9RJaQ9FAfnMbOGrhBTd8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=madFMffOts2O/Ob1UaQEueoqZo0+uw0GOSwokhrAItCCOSP3yniXyKYBBC3ByQ0xUmQA/cuEQVpjlIjN1dV0ja715tJfgMpzH64T66mJktE7dj+l90KlOLNgngIykIK4OxPFfLxaSLzCM3PwADxFXAXwMCBS6ovOGuYcekmxQfM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com; spf=pass smtp.mailfrom=ddn.com; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b=ivWAaKn/; arc=fail smtp.client-ip=209.222.82.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ddn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="ivWAaKn/" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by mx-outbound40-194.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 01 Feb 2024 00:42:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VbSLEpVnFHP+RKOm+MXqtHkA8mlfFNrBTFz7F9wvZoNLTtFXw3zz+UO0pTb2UDiVTLuPmeiSTDSwZCaWOJOIlEJcSSQRQoiMPKVHiZ13NTnQqPxo78xaCHYc9gtpJZn+C3nO08gLCkqp2FjrLHq01GUJc23O6JiKWvHArG8/tJIGKlm6poE+hR9SesB9xXlxXygUV0HzWiysPXpbbITeWQ2yES17NOQ1Q0cL+rOQxvxoW046FcW+Vf7hUoKRpHuIlFh/nDfXN+CDoKGo9UeQsJR/W7cfgTD10h5iCTC2rIwUlHGni7Dj+zGKx0NMNV1u0JNij5y8fXiJluc//a3dqA== 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=xm0x08FNnubnuMYiWxs7UcOljgY8p0uxUy5CVTAsBlc=; b=GwzwOwJ4GW6U4vPQQkINMKUPBDFfJWBMzeWh0dA2km3auRSemeYP6j8v5pWdmNjmvU3K113iKMP32wpnbqG1eHZscfOl7GvcuoxyimPg7dj80SAxSTomgl2mm/0gDubBNWOqwUM0jMuCeCvlDtEIGoRvDWFKK6aUwKfYGd/7cKcN3G2iyWuOKxFjJdRLWH1HgTxJgLYPYTcYUdstAfGnkvtwaLasj8g4k5cjF8HRAjBp4SH6DPQWijXdi1D9z36NcOB2jRR0Sf/SBUIDDDYoq/FaAGYfM+oIr6b+2SzzlfOp+I3uPZ6R7DB2pDxdozWHXYPNF1lteON0KRqMnfRlsw== 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=xm0x08FNnubnuMYiWxs7UcOljgY8p0uxUy5CVTAsBlc=; b=ivWAaKn/IVSABp9fBnv9lb98UyOcK3g4lXoyYuzDfGkzs+ino7nrjtd/HXdM/MmmbhKSOUDowy53AEJVzW55IGSSQyhF8ZZd8ZBz92KjY6ooYVDkqfRXe0Ib5BUAphwrnUcNER9FayIkPK65eKmuFGfUJpkctzEEKplcuHGTph0= Received: from MW4P220CA0024.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::29) by SN7PR19MB7163.namprd19.prod.outlook.com (2603:10b6:806:29a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.28; Wed, 31 Jan 2024 23:09:00 +0000 Received: from MW2NAM04FT047.eop-NAM04.prod.protection.outlook.com (2603:10b6:303:115:cafe::e2) by MW4P220CA0024.outlook.office365.com (2603:10b6:303:115::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24 via Frontend Transport; Wed, 31 Jan 2024 23:09:00 +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 MW2NAM04FT047.mail.protection.outlook.com (10.13.31.185) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7249.26 via Frontend Transport; Wed, 31 Jan 2024 23:09:00 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 8918520C684B; Wed, 31 Jan 2024 16:10:01 -0700 (MST) From: Bernd Schubert To: miklos@szeredi.hu Cc: linux-fsdevel@vger.kernel.org, dsingh@ddn.com, Bernd Schubert , Amir Goldstein Subject: [PATCH v2 3/5] fuse: Add fuse_dio_lock/unlock helper functions Date: Thu, 1 Feb 2024 00:08:25 +0100 Message-Id: <20240131230827.207552-4-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131230827.207552-1-bschubert@ddn.com> References: <20240131230827.207552-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: MW2NAM04FT047:EE_|SN7PR19MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 333f4383-0189-4536-d8b7-08dc22b19c24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1qEVp6DJ3i9pomQ0toC3bgfV5Uleet3uE9b8ferQVMKuu0MYqHnS1gjwSL/Wc3SLhfjwabltfgffiAHIFrUgp305taIWzhkbSdSWdwSY0JyWS8LvECr5Z3AkRN4nurbtrnLDVU2oU+KX13hOCf9GY3MP6ayaPCayhpxsw777IR+gE/M7wX5TwGmEDJ+mVwdoSomuExsdquZHQA/BkheMtsp3FdHAYEQM6dK/ysziAjvmEh/4GE8cY6mlGm0T7ky81DghXBE3aU16O7pDoGXmDgea7gIEVKHP+qs/8oV0slfhwavY9uRDIsX1mjeeUK/yMiwzOxGghMX/c4j8dzT+DJ5RG1O85JpHgXQMVzoW0immt8xMzYzgB7qlGBQjpJxXvhV1B5dzgOe7fpjLeBUtaiYOPIGJy0dEzzdqjyngFwsDtGRxG96Gh0Ke2d7M8rZSgF8bsXofVX3CV1Zd3tcDOPdQDQQyO6FQRN17+z/tJVOmr3LcTmvG1R6RfZWIompoYxAuICoiGCipfaGDqqihYyYESLUNbMLZX0dgiXMTQe0+ohOqXAWuReDc2vapVdaxlNijnX2+3PVwJrOH6CEy/o2nlQm/nBCD4nSNXLtSxj2ZljE3NDqwBA69SafW1BSpUIJVq0sXOoluqOmJHhkwl6Z0bEI5/W4p5mxy77ADFXQ/I6mk2o7TJBuadUhBQXI/A3luKuh+U2tspNDA30wtA8eQ/0gZHLaTCln2qzCxh350XqkA+bK57rXIkfXHs8Fb 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)(136003)(39850400004)(376002)(346002)(230922051799003)(186009)(451199024)(82310400011)(64100799003)(1800799012)(46966006)(36840700001)(40480700001)(83380400001)(36756003)(86362001)(356005)(82740400003)(81166007)(41300700001)(36860700001)(6266002)(26005)(1076003)(47076005)(2616005)(6666004)(5660300002)(336012)(70206006)(8676002)(316002)(70586007)(6916009)(54906003)(4326008)(8936002)(478600001)(2906002)(36900700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: cAtWfQvT0C+5ffXjfcXrhBisTIzh5sjAijuYZ3LdqLBaJx60ktoa8LrPXl4SdmFyaIWQFC0WQ8Q9hk3E80BIprRYUFEfN/EG9iMHwEetMiaNHQt+p2OgRC8jm1CQ44yRC1m6eFLEQrcLItOJmWW91WcHxyrtTjZJjSs5rSjnwIl2iRDXdMSOobz8MgEN1psrvlx/gFgcNi/5v86sZBXcBUJiZz18LAz3Z/EcXW0zIKx2DamfQXpLYA+shuoDK+Pp9MpI00g55LWEYCvOEVWRpFby02DbaDqXX23ICGLpQcGZIBJisZNmCqGw9DCkD1XgLqb+qiL7UslZ+PsqMAHCsf0KBYVsk9mMUYDxSzJIcGRnFOP8tXzMfhqH7fv8dCzZpxuyUqMjq1Ji92gsyNMhIOMSIkzJWfNkJ1R/uLiqAPCrZX0RpH1P4lN9z7RHfrRN3FbT3/DgyNxmORTAc09xZ4XPV8TAY7CHaT6xqOn5w6k+y7aQ54s3TLQDSMQqRbLfFfdFLgQk6lx4Hkor1k7P7v+pwN6qjHveyqHL+4tHjFABSWeAiMz8rSgvUoUgP8fACqSUk88xI3XKh8zzNF2w8HexgXJdylTD+jFAlKYGCPA0GAZlDhR/scL69fampSyC3gw1e53ikBjClqCXH7TaVw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 23:09:00.3046 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 333f4383-0189-4536-d8b7-08dc22b19c24 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: MW2NAM04FT047.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR19MB7163 X-OriginatorOrg: ddn.com X-BESS-ID: 1706748162-110434-19561-31556-1 X-BESS-VER: 2019.1_20240130.2130 X-BESS-Apparent-Source-IP: 104.47.66.40 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVkaWRmZAVgZQ0DQxzcIgMdHc0C LNIs3AODHV3Mgw2cA02cjCNM3CzMJEqTYWAIytgcpBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.253898 [from cloudscan17-181.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound 0.00 BSF_SC0_MISMATCH_TO META: Envelope rcpt doesn't match header X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND, BSF_SC0_MISMATCH_TO X-BESS-BRTS-Status: 1 So far this is just a helper to remove complex locking logic out of fuse_direct_write_iter. Especially needed by the next patch in the series to that adds the fuse inode cache IO mode and adds in even more locking complexity. Signed-off-by: Bernd Schubert Reviewed-by: Amir Goldstein --- fs/fuse/file.c | 61 ++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 0c4d93293eac..3062f4b5a34b 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1338,6 +1338,37 @@ static bool fuse_dio_wr_exclusive_lock(struct kiocb *iocb, struct iov_iter *from return false; } +static void fuse_dio_lock(struct kiocb *iocb, struct iov_iter *from, + bool *exclusive) +{ + struct inode *inode = file_inode(iocb->ki_filp); + + *exclusive = fuse_dio_wr_exclusive_lock(iocb, from); + if (*exclusive) { + inode_lock(inode); + } else { + inode_lock_shared(inode); + /* + * Previous check was without inode lock and might have raced, + * check again. + */ + if (fuse_io_past_eof(iocb, from)) { + inode_unlock_shared(inode); + inode_lock(inode); + *exclusive = true; + } + } +} + +static void fuse_dio_unlock(struct inode *inode, bool exclusive) +{ + if (exclusive) { + inode_unlock(inode); + } else { + inode_unlock_shared(inode); + } +} + static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; @@ -1602,30 +1633,9 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) struct inode *inode = file_inode(iocb->ki_filp); struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb); ssize_t res; - bool exclusive_lock = fuse_dio_wr_exclusive_lock(iocb, from); - - /* - * Take exclusive lock if - * - Parallel direct writes are disabled - a user space decision - * - Parallel direct writes are enabled and i_size is being extended. - * - Shared mmap on direct_io file is supported (FUSE_DIRECT_IO_ALLOW_MMAP). - * This might not be needed at all, but needs further investigation. - */ - if (exclusive_lock) - inode_lock(inode); - else { - inode_lock_shared(inode); - - /* - * Previous check was without any lock and might have raced. - */ - if (fuse_dio_wr_exclusive_lock(iocb, from)) { - inode_unlock_shared(inode); - inode_lock(inode); - exclusive_lock = true; - } - } + bool exclusive; + fuse_dio_lock(iocb, from, &exclusive); res = generic_write_checks(iocb, from); if (res > 0) { if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) { @@ -1636,10 +1646,7 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) fuse_write_update_attr(inode, iocb->ki_pos, res); } } - if (exclusive_lock) - inode_unlock(inode); - else - inode_unlock_shared(inode); + fuse_dio_unlock(inode, exclusive); return res; } From patchwork Wed Jan 31 23:08:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13540484 Received: from outbound-ip168b.ess.barracuda.com (outbound-ip168b.ess.barracuda.com [209.222.82.102]) (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 B5A3140BE4 for ; Wed, 31 Jan 2024 23:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=209.222.82.102 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744478; cv=fail; b=moW0T11iqhmgC6gOJPKvOZelXbhNjJT6+8/86zrCLBJ/nG6avth2pGrKuwtXG5P5Xg5cC52hW9OYRGWrotjaBbGFT3xGUzGkSt6FK5DALe+fdKf+Yh5uNCeqyR4cVBCUSicHZ0iCeSZ7R3OgY5Za8fpU9FQjgEXtbTa3C1LxLBY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706744478; c=relaxed/simple; bh=Xe596WaC0Y89ZXYmXphs0D23GkRkF/f5sr6YirTyrgo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=DZ1SeyjkrgVOcbdLhZarIuONnBmOLrXZTLji35Sz2QD2w/BG5QDAbyS8kDI4YE3XzAxVwI6nFLIMkkesR+d8MsKC0Ia5YksOURnpCiUHkv43xV/xOoc/RoeCjAJsdEI1yc4UlQF1JfAD8GwHOQjs6pii7cqNI2cDLsc7fs3WkJc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com; spf=pass smtp.mailfrom=ddn.com; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b=FnIT7Gzc; arc=fail smtp.client-ip=209.222.82.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ddn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="FnIT7Gzc" Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by mx-outbound-ea17-82.us-east-2b.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 31 Jan 2024 23:41:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LFUVKkekNETcHSf4TQ/EZwSe0RGViOwxnKmVUQxDSCrKftZhaeSTuMSiHqRLiPL/Ptc370bgqI4d/sLdD76YynB1pCJhhps9NzmcEFsWtfTiF0PzfMGj5uBASEmKRWXsUt6OAdF7zZopPMJuW9DXyH23p9wiDKmpKpZiCeWhkRgyaM1Rfkd2bwevOZKyOkiH6haOlVVotzRW9ys9MujcDY1q7b6b9yn6nDXl76JZC/Q9sOXDtS/IRkDPHzhIMbCOp+aW5HXywgbPBewWD9+sDngAvxgs6fA0wmkNu3yMEDiyF7yW1xNIJ7x2UOr9pq3AuzwA7JnQ98b99NnC23QPcw== 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=Spf5g18EsZaMwbK19fxXqD042Cc/p366E8I6AG/76+U=; b=IfkwN7oC7l+sKINV/R0xYJWNpjsMe73eLICs6xBnXVOWEFY2oQiIrLRfYHZzGTYfTpcOJfK5loXM8+PDJHWzlgoTUPoJgit5CYssDAFiKAI96ZwROVce0RGJGLuhy43rqntSRHBkSu/yHdGb4McHhckQj4jYRLDWv3pgTLxrpQuhRkmbhYq+3VHC1Alh++4uOd9MuHUkRen1saHyqFKkBkuNsWMaWqIrNG3jcBoMTr3q9fLHi28+tmUvCkbr09vQZ6/ALirAVEMPGViXc4axkuJruUWKlwLI6mftxi4otCNTjdzBgQvjfs42bCF0O6FHPjWfsgjARzPTRxRpQmQAJg== 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=Spf5g18EsZaMwbK19fxXqD042Cc/p366E8I6AG/76+U=; b=FnIT7GzctarNKmd6gONeWlr80aFOyEYP1yJ7zSvleqKjQhmKCaS+ZKvjLivIprDXc+6LX3sGVrjbi+KkM6LWj35EwidrrHm1F/n3RQ+gOwfeL7Q17CHWFOI10lsnQFuufZ27/dzxz1zPxDBufg64A4+BQ9Ir6aK7z9Ld8UHCRDA= Received: from BN9PR03CA0950.namprd03.prod.outlook.com (2603:10b6:408:108::25) by CYYPR19MB8104.namprd19.prod.outlook.com (2603:10b6:930:c3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24; Wed, 31 Jan 2024 23:09:03 +0000 Received: from BN8NAM04FT065.eop-NAM04.prod.protection.outlook.com (2603:10b6:408:108:cafe::b1) by BN9PR03CA0950.outlook.office365.com (2603:10b6:408:108::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34 via Frontend Transport; Wed, 31 Jan 2024 23:09:02 +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 BN8NAM04FT065.mail.protection.outlook.com (10.13.160.195) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7249.22 via Frontend Transport; Wed, 31 Jan 2024 23:09:02 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id B858420C684B; Wed, 31 Jan 2024 16:10:03 -0700 (MST) From: Bernd Schubert To: miklos@szeredi.hu Cc: linux-fsdevel@vger.kernel.org, dsingh@ddn.com, Amir Goldstein , Bernd Schubert Subject: [PATCH v2 4/5] fuse: prepare for failing open response Date: Thu, 1 Feb 2024 00:08:26 +0100 Message-Id: <20240131230827.207552-5-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131230827.207552-1-bschubert@ddn.com> References: <20240131230827.207552-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: BN8NAM04FT065:EE_|CYYPR19MB8104:EE_ X-MS-Office365-Filtering-Correlation-Id: 60a00612-f37d-4018-955c-08dc22b19d8e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /MP8tkMCmOFEP0/U7zJhqzocsVI7NWn7iV/KL2xoQl/r76ipkGBfhL+xB9Ex/2OG6zmnIqcdEGwcAIgeUVTId4Ux+TBTLiU9YfsFlhLRhi11Yy/B6ncKY0cISSAB4KH/u3UoCoa53awWcik/KO2xHbAS/l9RyaBKAXtRcUKu5ysXY15DmcjRAYcC3QlNphBth7OGMaRUyDQu9nNU/DqBNAQZOB4ydibGdpc7L0cBs2sZbuLj087wEIcv3FFr9qJmHcem9uzEVHwpxHoYvZ5tj7fL7QBuOoKjkiHQ5MQ8AFUwp+/fhbVDJ0WFuz0c/KMvGdpQKR0hugJgJUbJQPC1f0TexlBTWM7kM5BEv28K6Ks1LuWGCtUi0ROBwJqWctN+wwZE9dyQWVGG4THPS1oskZbv9U+tdB0Mk7yhdo92OWR7pkJF1mGB7ZY6RScKaLur3PQu3Fm9zfcDZTDGei/EdQAH3hsgkticW6XCKwDXedmoK8or10sbI72w8mLj6ORB6i9hiFJBKuX36/uygkrwx/EEKT0qF4rKySkRnFT4jPRUzQNuJZSSLjfcTBeK3Z47TqgqDG4swzXwbgoHCvuH3nn5H/UP3WhmKB4o1R5MJa214UzVkJ/M63ucp4BNyrzmHSzqZisIj4+of1mRfBnrkH68sM7ETOkdoapJ0tmK1V53RzHzIYrCSpDz9x3uNXR9/rGsN583Ewo65JvlA+YfZ6uKB3YTf3r0ajJeuHBtNteIzjCWNtH2bFCjDtrzSqwN X-Forefront-Antispam-Report: CIP:50.222.100.11;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:uww-mx01.datadirectnet.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(396003)(346002)(376002)(39850400004)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(82310400011)(46966006)(36840700001)(41300700001)(83380400001)(47076005)(2616005)(6266002)(1076003)(82740400003)(336012)(81166007)(356005)(70586007)(316002)(8936002)(4326008)(5660300002)(8676002)(478600001)(70206006)(6666004)(54906003)(2906002)(6916009)(36860700001)(26005)(36756003)(86362001)(40480700001)(36900700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 4l7LfbSkOHpxILU6XqzwBDCEmTWXM5DBJOk8pTVNhSTR4I0efxIjmGid+P+lxkUsy9jH4lfkvYC/0HoENgq6ARHlYv+W+Q6DLdWIUWiC5glZknXHm/cihZ+0s5wSNo8WIFmzf/K4fCp1ZGScXzdq1bi33MG5ZxYuFB6h5gCPtENnNtnh/lHaljnov/7H/47fmQLjjlLyc5JZvH4y93i3aULA+1h4S0fp5rSNvJq7r0p54gtMc7Fvq+j1qxOh8gYVxMupl+2yUMicMAJ/TefG7AyMl07LI3RhFcvLrzzXybAg/8/gZoY7mOeaeANGsQFWXjpoOt4RGmq8feb1TTihS0sQnggy8PMYevFmn0MIjV1IqAj6wJpKCMRLdaXz7YU5UPyknapH7Inlw4gCdJ4CHUPXn+3w3BY3CXjnfnFlxUQ75ejY0yD/YZJh4WzALKJbi3J3W5PLQ6F7pfjaWR1CoBR8/ziBizRIG3+eSihcYS21Lb9GICNvp8vRnmD1WDm02f0XLmfnCxw8HZjW2l/Z0Yw3oRaxMH2IlfNWbe+3zKki8IXMwEimwgB9qD846kEjT5/dIR0L32i0ei6tZapsa81c81Qgwt0XK+ZwiQAVMZ4C5P2K4JOKTcxaPyPzICp+gkxA4a/ZlvGIYHux6FdlHQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 23:09:02.6284 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60a00612-f37d-4018-955c-08dc22b19d8e 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: BN8NAM04FT065.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR19MB8104 X-OriginatorOrg: ddn.com X-BESS-ID: 1706744469-104434-2501-41580-1 X-BESS-VER: 2019.3_20240130.1849 X-BESS-Apparent-Source-IP: 104.47.59.169 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKViYGpoZAVgZQMNXM0NAgySTNxN LAzNLI0sLIPCXZzCTZyCDJIC3JMilRqTYWAIvn6BZBAAAA X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.253897 [from cloudscan18-66.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 0.00 BSF_SC0_MISMATCH_TO META: Envelope rcpt doesn't match header X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_BESS_OUTBOUND, BSF_SC0_MISMATCH_TO X-BESS-BRTS-Status: 1 From: Amir Goldstein In preparation for inode io modes, a server open response could fail due to conflicting inode io modes. Allow returning an error from fuse_finish_open() and handle the error in the callers. fuse_dir_open() can now call fuse_sync_release(), so handle the isdir case correctly. fuse_finish_open() is used as the callback of finish_open(), so that FMODE_OPENED will not be set if fuse_finish_open() fails. Signed-off-by: Amir Goldstein Reviewed-by: Bernd Schubert --- fs/fuse/dir.c | 8 +++++--- fs/fuse/file.c | 18 ++++++++++++------ fs/fuse/fuse_i.h | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index d19cbf34c634..d45d4a678351 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -692,13 +692,15 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, d_instantiate(entry, inode); fuse_change_entry_timeout(entry, &outentry); fuse_dir_changed(dir); - err = finish_open(file, entry, generic_file_open); + err = generic_file_open(inode, file); + if (!err) { + file->private_data = ff; + err = finish_open(file, entry, fuse_finish_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 (fm->fc->atomic_o_trunc && trunc) truncate_pagecache(inode, 0); else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 3062f4b5a34b..7d2f4b0eb36a 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -195,7 +195,7 @@ static void fuse_link_write_file(struct file *file) spin_unlock(&fi->lock); } -void fuse_finish_open(struct inode *inode, struct file *file) +int fuse_finish_open(struct inode *inode, struct file *file) { struct fuse_file *ff = file->private_data; struct fuse_conn *fc = get_fuse_conn(inode); @@ -217,12 +217,16 @@ void fuse_finish_open(struct inode *inode, struct file *file) } if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache) fuse_link_write_file(file); + + return 0; } int fuse_open_common(struct inode *inode, struct file *file, bool isdir) { struct fuse_mount *fm = get_fuse_mount(inode); + struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_conn *fc = fm->fc; + struct fuse_file *ff; int err; bool is_wb_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc && @@ -251,14 +255,16 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir) fuse_set_nowrite(inode); err = fuse_do_open(fm, get_node_id(inode), file, isdir); - if (!err) - fuse_finish_open(inode, file); + if (!err) { + ff = file->private_data; + err = fuse_finish_open(inode, file); + if (err) + fuse_sync_release(fi, ff, file->f_flags); + } if (is_wb_truncate || dax_truncate) fuse_release_nowrite(inode); if (!err) { - struct fuse_file *ff = file->private_data; - if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) truncate_pagecache(inode, 0); else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) @@ -368,7 +374,7 @@ void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, * iput(NULL) is a no-op and since the refcount is 1 and everything's * synchronous, we are fine with not doing igrab() here" */ - fuse_file_put(ff, true, false); + fuse_file_put(ff, true, fi && S_ISDIR(fi->inode.i_mode)); } EXPORT_SYMBOL_GPL(fuse_sync_release); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 1df83eebda92..1c0cde4022f0 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1038,7 +1038,7 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir); struct fuse_file *fuse_file_alloc(struct fuse_mount *fm); void fuse_file_free(struct fuse_file *ff); -void fuse_finish_open(struct inode *inode, struct file *file); +int fuse_finish_open(struct inode *inode, struct file *file); void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, unsigned int flags); From patchwork Wed Jan 31 23:08:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schubert X-Patchwork-Id: 13540511 Received: from outbound-ip168a.ess.barracuda.com (outbound-ip168a.ess.barracuda.com [209.222.82.36]) (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 D30621FD7 for ; Thu, 1 Feb 2024 00:43:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=209.222.82.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706748228; cv=fail; b=OsKczcJSyumW8TGyr9l8kGzPk3xmy9QZgIMuAH1mS1p5+9hjn3e/1CgTx0v+QKx1hHTVpndihvkRatWMXmH9RPyZhcNSiL1hCT208B937PQYABudFuE6VP1+Ui4bdBOJgtqUPutyJ/0cQrZG19XAaBW0IRKANWSi+rYfriSIA70= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706748228; c=relaxed/simple; bh=0VzdJ28emMTLPg6aPRsXx32/cWFNUsPOgJrCCbnlg1E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=IDTPstMb6bT2sJpjwsAokUqHHTjdxtqwhbDBxVc6D3sWRbDTl2Vx5FXRf1Wq65Vuv91t/JNmtNdwoMbJbv8fNXUrDt5uV82G4muAtAbxRmXd8cuZH1K4B0NBpg6SdQWZN7gP1NukKKjM2ogc6YOOtKPS1/8uPYEx0Go9TSkvYi8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com; spf=pass smtp.mailfrom=ddn.com; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b=uyaDx33S; arc=fail smtp.client-ip=209.222.82.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ddn.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ddn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ddn.com header.i=@ddn.com header.b="uyaDx33S" Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by mx-outbound44-50.us-east-2c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 01 Feb 2024 00:43:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jCPpv/pWhokTm71ViXtmMyfltIWldV1wW34OuARgL0fwH9mmg2aYYltZLMnR8Maz2mVgvFCFNBonqts5rCWGPYzEGp5z36f9p0p/bvZ10eLDHV4Q8gcrYaUSRrleaTzXN9cDGs89hYpqCUbzJwWL/0epjieqPjxf1JDjG/S3P9TP7A3GE5cYVH//wKzPu6rI/HLvD4MjOKOUl2Tw26ctIWK2R8eXm1QU/DHcUqIn0RsgEEpQ/Koq7nUqR641pYaHC39k3DbkDMdhla8AZIxgO3uS8D7zwn8XEGV2Rr/0DUC3fdqWaX01BxCGYPR3bhzIcejJXMkt2M3BLL1O5e9kIg== 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=/6n85FmdIula6gJNHdcp3TFqjNS7XqJaYqQaxgVNY/w=; b=Vxo+EMwA7/UIwkInjQkl4NBNzJ8XgrMH+KonQoweiXEe5LmS2B/BFt5Zr5sMVyEBls8jevWQ9yjfs4NnavI3589lppD55UOOzyvaz2K8T+iGSqF6frHM2EMlA9xYB+3oii/uwQ8q690Nl4zQwhV+WIsuMwy0UK85Ek+6ZS7ATOToIgjqwaTKjgE/zhOwbUZnAGB/dsD8pbH3OmrlyKNKTZxc3MNpfKcHzHi0m4HHnOFU/03ObsbzJOQt7HTKKgM7Lf8zVPplbhXbKBzN60a1lqDgN4UtMUKR31PjTVdHhxyr38MJObo24Bcz3kFFofTLW7+3+n0kQEdsHyQr1rVppg== 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=/6n85FmdIula6gJNHdcp3TFqjNS7XqJaYqQaxgVNY/w=; b=uyaDx33SIOgimA+Trb6OLSXbNxOnGQwxnbbH53A5OQBnVDMAWd3thfh6Mmf5oI65/VxrVOV4JDiPON3eYkd1EfzYSpLsIwRkZrwZt8uZQlQXscphT91ySlpkd31OILTleKNCCrryqWgwML4+pnaKgx9FeuVeOieLu+E/X/mrCt0= Received: from DS0PR17CA0014.namprd17.prod.outlook.com (2603:10b6:8:191::10) by BLAPR19MB4481.namprd19.prod.outlook.com (2603:10b6:208:292::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.24; Wed, 31 Jan 2024 23:09:05 +0000 Received: from DM6NAM04FT039.eop-NAM04.prod.protection.outlook.com (2603:10b6:8:191:cafe::84) by DS0PR17CA0014.outlook.office365.com (2603:10b6:8:191::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34 via Frontend Transport; Wed, 31 Jan 2024 23:09:05 +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 DM6NAM04FT039.mail.protection.outlook.com (10.13.159.54) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7249.26 via Frontend Transport; Wed, 31 Jan 2024 23:09:05 +0000 Received: from localhost (unknown [10.68.0.8]) by uww-mx01.datadirectnet.com (Postfix) with ESMTP id 837C820C684B; Wed, 31 Jan 2024 16:10:05 -0700 (MST) From: Bernd Schubert To: miklos@szeredi.hu Cc: linux-fsdevel@vger.kernel.org, dsingh@ddn.com, Amir Goldstein , Bernd Schubert Subject: [PATCH v2 5/5] fuse: introduce inode io modes Date: Thu, 1 Feb 2024 00:08:27 +0100 Message-Id: <20240131230827.207552-6-bschubert@ddn.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131230827.207552-1-bschubert@ddn.com> References: <20240131230827.207552-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: DM6NAM04FT039:EE_|BLAPR19MB4481:EE_ X-MS-Office365-Filtering-Correlation-Id: 11be8d44-8086-40a5-bc53-08dc22b19f09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3DdCX9YTDOV8/UIkN0vZAPBclquss2hQw6TbBfvok8BeYzdnNfsrhrozjXNEXSA6hGrLlOs4ZA4/dAOv5OnOpH6m2mmX4WBdvnMtu0LavsWJ0XlUqgszL32FBClZQj32bZ+iKU3IiuduD/BlLzvUmSSF+26Ht8Y+vwtKnHIesJfDO5ZilrLaCeWiaVbeSsoQRB4hr519V+3fkjmDRZndVm7tWJLD46gxWuZRHs5jqvQ73JgKUeWOZOChwGFyEwNVyYWOqFVZYaNuqK+KpPU2zwb6bVoNJGQ6D/H/aW7CtHYKUKa64GlHQvfI/PdlU+bUeQCyq9q4wWtBBOk9DYdl4vPbMBte+XZHSe85H7nosG+Wm1J1Grl8NCAc9pbT/tNdsTJyDfb7utKPes7WcToJBXvUZ/ST0IjRQJdqCiJf7k4vglTljCImzgsYYFmffpfxRJ+KdGM/+UhqoWbPJSfsYE9r9Lt06rj2MpUILkDqlILSDg9v3ApasZZEGDyJjQ3korqPcLik8r8sqBu+4MuoXg+onCHIk3GIFENpk2CJeaBx4E25cJNjoZ4YJuEss739rLtW1i254Nn2VJzsOazEh2ajyaNptmv3ATccGfDxoxwtRxUyeOft3OHnRDpMs8TG8Le70/9C2IL4FAN52y0oie8B5+6AA9l+zi+T4eovuPrcJEe7BSlo7JnampCCaSYYd7WJX47hq6Zpu4WK3HEzQvnndF5brTbDhbYTjLDL/WqyLxtQs39vAi/lqtY7hIY8 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)(396003)(136003)(376002)(39850400004)(230922051799003)(82310400011)(451199024)(186009)(64100799003)(1800799012)(36840700001)(46966006)(41300700001)(30864003)(4326008)(8936002)(2906002)(8676002)(5660300002)(86362001)(70586007)(70206006)(54906003)(316002)(47076005)(36756003)(6916009)(36860700001)(82740400003)(81166007)(356005)(83380400001)(478600001)(6666004)(26005)(2616005)(1076003)(6266002)(336012)(40480700001)(36900700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: TR71tRY3IoDw9EZJCZ31BE5N/ZvEF2Hu4M5wwwMKML1BCrwDpFhtjc7R9wmdqCx/rRyuOuw0XEQNI7ulg0g6avLzHM5kldhjBhsmsnthko7/pFUXRwnhulRnA03Iy1Xhcl4Cea/phINuT/o4Xf4wn7s/t3dj3ODb/omaUvZTDfaWlW+VYbAajoVfV3PNPbmWbu7MWWMSf3zdG81jVwopc7KB8AKQ5hNnpEiTYxLJ6kSVvfyvf9staBFUHgCBLCKZq3x9WJwB+hEcGixvuWuHnIi9Jcx2KynSOgBqiWz8FE6ZLnRQGjlTIP9fzcdgKt/nXedqkEhQXN8XHgibk/GhWn8yZhtA183pXI3HoPssqLYZL0qq5P3Ujtjz28TVqiNEcaLN0LPs42dsf7d0MEoG2kaaOH00HOOroo1x3YcZRdRUv25Oijbn3apDInra6WU+ixFI1WqrFQLrTSD12oIBI3Q5aCAJRd0vgOHX3GG9hXPyBd7jVVv+twV/DtZEn+VMLXB+CO/+1YOzID6TDkqn2v1RqZwbK21MwtQBMpOuJOkBzPYapRnwzuBslNNCyC/81v9aC4VwCf2zZ8yjfJ4dN61B9l0kb0zEtrIEsTbJE4aAcLAUSXixGehGcwn7zN1iU0KqWBipUbubRtjjFJYKNA== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 23:09:05.1757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 11be8d44-8086-40a5-bc53-08dc22b19f09 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: DM6NAM04FT039.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR19MB4481 X-OriginatorOrg: ddn.com X-BESS-ID: 1706748224-111314-15996-12552-1 X-BESS-VER: 2019.1_20240130.2130 X-BESS-Apparent-Source-IP: 104.47.55.169 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVoYmxiaGQGYGUNTC3MLINNHQ1C jVMskw0cgs2dzcMNHQINXCwDQpMTU5Rak2FgB7Ze49QgAAAA== X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.253898 [from cloudscan15-103.us-east-2a.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound 0.00 BSF_SC0_MISMATCH_TO META: Envelope rcpt doesn't match header X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS124931 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_BESS_OUTBOUND, BSF_SC0_MISMATCH_TO X-BESS-BRTS-Status: 1 From: Amir Goldstein The fuse inode io mode is determined by the mode of its open files/mmaps and parallel dio. - caching io mode - files open in caching mode or mmap on direct_io file - direct io mode - no files open in caching mode and no files mmaped - parallel dio mode - direct io mode with parallel dio in progress We use a new FOPEN_CACHE_IO flag to explicitly mark a file that was open in caching mode. direct_io mmap uses page cache, so first mmap will mark the file as FOPEN_DIRECT_IO|FOPEN_CACHE_IO (i.e. mixed mode) and inode will enter the caching io mode. If the server opens the file with flags FOPEN_DIRECT_IO|FOPEN_CACHE_IO, the inode enters caching io mode already on open. This allows executing parallel dio when inode is not in caching mode even if shared mmap is allowed, but no mmaps have been performed on the inode in question. An open in caching mode and mmap on direct_io file now waits for all in-progress parallel dio writes to complete, so paralle dio writes together with FUSE_DIRECT_IO_ALLOW_MMAP is enabled by this commit. Signed-off-by: Bernd Schubert Signed-off-by: Amir Goldstein --- fs/fuse/file.c | 215 ++++++++++++++++++++++++++++++++++++-- fs/fuse/fuse_i.h | 79 +++++++++++++- include/uapi/linux/fuse.h | 2 + 3 files changed, 286 insertions(+), 10 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 7d2f4b0eb36a..eb9929ff9f60 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -105,10 +105,177 @@ static void fuse_release_end(struct fuse_mount *fm, struct fuse_args *args, kfree(ra); } +static bool fuse_file_is_direct_io(struct file *file) +{ + struct fuse_file *ff = file->private_data; + + return ff->open_flags & FOPEN_DIRECT_IO || file->f_flags & O_DIRECT; +} + +/* + * Wait for cached io to be allowed - + * Blocks new parallel dio writes and waits for the in-progress parallel dio + * writes to complete. + */ +static int fuse_inode_wait_for_cached_io(struct fuse_inode *fi) +{ + int err = 0; + + assert_spin_locked(&fi->lock); + + while (!err && !fuse_inode_get_io_cache(fi)) { + /* + * Setting the bit advises new direct-io writes + * to use an exclusive lock - without it the wait below + * might be forever. + */ + set_bit(FUSE_I_CACHE_IO_MODE, &fi->state); + spin_unlock(&fi->lock); + err = wait_event_killable(fi->direct_io_waitq, + fuse_is_io_cache_allowed(fi)); + spin_lock(&fi->lock); + } + /* Clear FUSE_I_CACHE_IO_MODE flag if failed to enter caching mode */ + if (err && fi->iocachectr <= 0) + clear_bit(FUSE_I_CACHE_IO_MODE, &fi->state); + + return err; +} + +/* Start cached io mode where parallel dio writes are not allowed */ +static int fuse_file_cached_io_start(struct inode *inode) +{ + struct fuse_inode *fi = get_fuse_inode(inode); + int err; + + spin_lock(&fi->lock); + err = fuse_inode_wait_for_cached_io(fi); + spin_unlock(&fi->lock); + return err; +} + +static void fuse_file_cached_io_end(struct inode *inode) +{ + struct fuse_inode *fi = get_fuse_inode(inode); + + spin_lock(&fi->lock); + fuse_inode_put_io_cache(get_fuse_inode(inode)); + spin_unlock(&fi->lock); +} + +/* Start strictly uncached io mode where cache access is not allowed */ +static int fuse_file_uncached_io_start(struct inode *inode) +{ + struct fuse_inode *fi = get_fuse_inode(inode); + bool ok; + + spin_lock(&fi->lock); + ok = fuse_inode_deny_io_cache(fi); + spin_unlock(&fi->lock); + return ok ? 0 : -ETXTBSY; +} + +static void fuse_file_uncached_io_end(struct inode *inode) +{ + struct fuse_inode *fi = get_fuse_inode(inode); + bool allow_cached_io; + + spin_lock(&fi->lock); + allow_cached_io = fuse_inode_allow_io_cache(fi); + spin_unlock(&fi->lock); + if (allow_cached_io) + wake_up(&fi->direct_io_waitq); +} + +/* Open flags to determine regular file io mode */ +#define FOPEN_IO_MODE_MASK \ + (FOPEN_DIRECT_IO | FOPEN_CACHE_IO) + +/* Request access to submit new io to inode via open file */ +static int fuse_file_io_open(struct file *file, struct inode *inode) +{ + struct fuse_file *ff = file->private_data; + int iomode_flags = ff->open_flags & FOPEN_IO_MODE_MASK; + int err; + + err = -EBUSY; + if (WARN_ON(ff->io_opened)) + goto fail; + + if (!S_ISREG(inode->i_mode) || FUSE_IS_DAX(inode)) { + err = -EINVAL; + if (iomode_flags) + goto fail; + return 0; + } + + /* Set explicit FOPEN_CACHE_IO flag for file open in caching mode */ + if (!fuse_file_is_direct_io(file)) + ff->open_flags |= FOPEN_CACHE_IO; + + /* First caching file open enters caching inode io mode */ + if (ff->open_flags & FOPEN_CACHE_IO) { + err = fuse_file_cached_io_start(inode); + if (err) + goto fail; + } + + ff->io_opened = true; + return 0; + +fail: + pr_debug("failed to open file in requested io mode (open_flags=0x%x, err=%i).\n", + ff->open_flags, err); + /* + * The file open mode determines the inode io mode. + * Using incorrect open mode is a server mistake, which results in + * user visible failure of open() with EIO error. + */ + return -EIO; +} + +/* Request access to submit new io to inode via mmap */ +static int fuse_file_io_mmap(struct fuse_file *ff, struct inode *inode) +{ + struct fuse_inode *fi = get_fuse_inode(inode); + int err = 0; + + if (WARN_ON(!ff->io_opened)) + return -ENODEV; + + spin_lock(&fi->lock); + /* First mmap of direct_io file enters caching inode io mode */ + if (!(ff->open_flags & FOPEN_CACHE_IO)) { + err = fuse_inode_wait_for_cached_io(fi); + if (!err) + ff->open_flags |= FOPEN_CACHE_IO; + } + spin_unlock(&fi->lock); + + return err; +} + +/* No more pending io and no new io possible to inode via open/mmapped file */ +static void fuse_file_io_release(struct fuse_file *ff, struct inode *inode) +{ + if (!ff->io_opened) + return; + + /* Last caching file close exits caching inode io mode */ + if (ff->open_flags & FOPEN_CACHE_IO) + fuse_file_cached_io_end(inode); + + ff->io_opened = false; +} + static void fuse_file_put(struct fuse_file *ff, bool sync, bool isdir) { if (refcount_dec_and_test(&ff->count)) { struct fuse_args *args = &ff->release_args->args; + struct inode *inode = ff->release_args->inode; + + if (inode) + fuse_file_io_release(ff, inode); if (isdir ? ff->fm->fc->no_opendir : ff->fm->fc->no_open) { /* Do nothing when client does not implement 'open' */ @@ -161,7 +328,7 @@ struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid, } if (isdir) - ff->open_flags &= ~FOPEN_DIRECT_IO; + ff->open_flags &= ~(FOPEN_DIRECT_IO | FOPEN_CACHE_IO); ff->nodeid = nodeid; @@ -199,6 +366,11 @@ int fuse_finish_open(struct inode *inode, struct file *file) { struct fuse_file *ff = file->private_data; struct fuse_conn *fc = get_fuse_conn(inode); + int err; + + err = fuse_file_io_open(file, inode); + if (err) + return err; if (ff->open_flags & FOPEN_STREAM) stream_open(inode, file); @@ -1320,6 +1492,7 @@ static bool fuse_dio_wr_exclusive_lock(struct kiocb *iocb, struct iov_iter *from struct file *file = iocb->ki_filp; struct fuse_file *ff = file->private_data; struct inode *inode = file_inode(iocb->ki_filp); + struct fuse_inode *fi = get_fuse_inode(inode); /* server side has to advise that it supports parallel dio writes */ if (!(ff->open_flags & FOPEN_PARALLEL_DIRECT_WRITES)) @@ -1331,11 +1504,9 @@ static bool fuse_dio_wr_exclusive_lock(struct kiocb *iocb, struct iov_iter *from if (iocb->ki_flags & IOCB_APPEND) return true; - /* combination opf page access and direct-io difficult, shared - * locks actually introduce a conflict. - */ - if (get_fuse_conn(inode)->direct_io_allow_mmap) - return true; + /* shared locks are not allowed with parallel page cache IO */ + if (test_bit(FUSE_I_CACHE_IO_MODE, &fi->state)) + return false; /* parallel dio beyond eof is at least for now not supported */ if (fuse_io_past_eof(iocb, from)) @@ -1355,10 +1526,14 @@ static void fuse_dio_lock(struct kiocb *iocb, struct iov_iter *from, } else { inode_lock_shared(inode); /* - * Previous check was without inode lock and might have raced, - * check again. + * New parallal dio allowed only if inode is not in caching + * mode and denies new opens in caching mode. This check + * should be performed only after taking shared inode lock. + * Previous past eof check was without inode lock and might + * have raced, so check it again. */ - if (fuse_io_past_eof(iocb, from)) { + if (fuse_io_past_eof(iocb, from) || + fuse_file_uncached_io_start(inode) != 0) { inode_unlock_shared(inode); inode_lock(inode); *exclusive = true; @@ -1371,6 +1546,8 @@ static void fuse_dio_unlock(struct inode *inode, bool exclusive) if (exclusive) { inode_unlock(inode); } else { + /* Allow opens in caching mode after last parallel dio end */ + fuse_file_uncached_io_end(inode); inode_unlock_shared(inode); } } @@ -2500,11 +2677,16 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) { struct fuse_file *ff = file->private_data; struct fuse_conn *fc = ff->fm->fc; + int rc; /* DAX mmap is superior to direct_io mmap */ if (FUSE_IS_DAX(file_inode(file))) return fuse_dax_mmap(file, vma); + /* + * FOPEN_DIRECT_IO handling is special compared to O_DIRECT, + * as does not allow MAP_SHARED mmap without FUSE_DIRECT_IO_ALLOW_MMAP. + */ if (ff->open_flags & FOPEN_DIRECT_IO) { /* * Can't provide the coherency needed for MAP_SHARED @@ -2515,10 +2697,23 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) invalidate_inode_pages2(file->f_mapping); + /* + * First mmap of direct_io file enters caching inode io mode. + * Also waits for parallel dio writers to go into serial mode + * (exclusive instead of shared lock). + */ + rc = fuse_file_io_mmap(ff, file_inode(file)); + if (rc) + return rc; + if (!(vma->vm_flags & VM_MAYSHARE)) { /* MAP_PRIVATE */ return generic_file_mmap(file, vma); } + } else if (file->f_flags & O_DIRECT) { + rc = fuse_file_io_mmap(ff, file_inode(file)); + if (rc) + return rc; } if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) @@ -3287,7 +3482,9 @@ void fuse_init_file_inode(struct inode *inode, unsigned int flags) INIT_LIST_HEAD(&fi->write_files); INIT_LIST_HEAD(&fi->queued_writes); fi->writectr = 0; + fi->iocachectr = 0; init_waitqueue_head(&fi->page_waitq); + init_waitqueue_head(&fi->direct_io_waitq); fi->writepages = RB_ROOT; if (IS_ENABLED(CONFIG_FUSE_DAX)) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 1c0cde4022f0..cb961f9a13c3 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -111,7 +111,7 @@ struct fuse_inode { u64 attr_version; union { - /* Write related fields (regular file only) */ + /* read/write io cache (regular file only) */ struct { /* Files usable in writepage. Protected by fi->lock */ struct list_head write_files; @@ -123,9 +123,15 @@ struct fuse_inode { * (FUSE_NOWRITE) means more writes are blocked */ int writectr; + /** Number of files/maps using page cache */ + int iocachectr; + /* Waitq for writepage completion */ wait_queue_head_t page_waitq; + /* waitq for direct-io completion */ + wait_queue_head_t direct_io_waitq; + /* List of writepage requestst (pending or sent) */ struct rb_root writepages; }; @@ -187,6 +193,8 @@ enum { FUSE_I_BAD, /* Has btime */ FUSE_I_BTIME, + /* Wants or already has page cache IO */ + FUSE_I_CACHE_IO_MODE, }; struct fuse_conn; @@ -246,6 +254,9 @@ struct fuse_file { /** Has flock been performed on this file? */ bool flock:1; + + /** Was file opened for io? */ + bool io_opened:1; }; /** One input argument of a request */ @@ -1349,6 +1360,72 @@ int fuse_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, struct fileattr *fa); /* file.c */ +/* + * Request an open in caching mode. + * Return true if in caching mode. + */ +static inline bool fuse_inode_get_io_cache(struct fuse_inode *fi) +{ + assert_spin_locked(&fi->lock); + if (fi->iocachectr < 0) + return false; + fi->iocachectr++; + if (fi->iocachectr == 1) + set_bit(FUSE_I_CACHE_IO_MODE, &fi->state); + + return true; +} + +/* + * Release an open in caching mode. + * Return true if no more files open in caching mode. + */ +static inline bool fuse_inode_put_io_cache(struct fuse_inode *fi) +{ + assert_spin_locked(&fi->lock); + if (WARN_ON(fi->iocachectr <= 0)) + return false; + + if (--fi->iocachectr == 0) { + clear_bit(FUSE_I_CACHE_IO_MODE, &fi->state); + return true; + } + + return false; +} + +/* + * Requets to deny new opens in caching mode. + * Return true if denying new opens in caching mode. + */ +static inline bool fuse_inode_deny_io_cache(struct fuse_inode *fi) +{ + assert_spin_locked(&fi->lock); + if (fi->iocachectr > 0) + return false; + fi->iocachectr--; + return true; +} + +/* + * Release a request to deny open in caching mode. + * Return true if allowing new opens in caching mode. + */ +static inline bool fuse_inode_allow_io_cache(struct fuse_inode *fi) +{ + assert_spin_locked(&fi->lock); + if (WARN_ON(fi->iocachectr >= 0)) + return false; + return ++(fi->iocachectr) == 0; +} + +/* + * Return true if allowing new opens in caching mode. + */ +static inline bool fuse_is_io_cache_allowed(struct fuse_inode *fi) +{ + return READ_ONCE(fi->iocachectr) >= 0; +} struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid, unsigned int open_flags, bool isdir); diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index e7418d15fe39..66a4bd8d767d 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_CACHE_IO: using cache for this open file (incl. mmap on direct_io) */ #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_CACHE_IO (1 << 7) /** * INIT request/reply flags