From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 35A2929AAF3; Wed, 30 Jul 2025 13:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881900; cv=none; b=je2+9D96tAjTcWIMOhF2L8qm4Pd2mMA5X77C9uwsbyVqCSwTaMaYs+Fks53Ei+Z/8k8xVM2kZwVRqdO8uR4fO/AZZZeTDTJ74ikQis1UBkBlbGjIel+/ksdmYy7pQ85EkwyqwY2azau/HvHhd4zG4LNBa08RArE4Q0tU/4MSy84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881900; c=relaxed/simple; bh=wX+jZhM05ADBnfHIbs04wC7/mLDtqIQ+H+KgWBk6ve0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TAURBgRDBOhAEor/jolVZJF+jjfG7polx/QuepjLHFffHwuMFZKNKqAUFVuPNAZ9+Rx9PY03CzdPWtZUDAf4ptc0D8l8VU18QLQhwVeJt1NCJHCuZ4WA3zPq2hw6JBxAQTSH8TNQbwOY1W1/U+L+hJ7LB4gHXU+fTf5YfCV6pDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HwrnLotv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HwrnLotv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 809AFC4CEF9; Wed, 30 Jul 2025 13:24:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881899; bh=wX+jZhM05ADBnfHIbs04wC7/mLDtqIQ+H+KgWBk6ve0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HwrnLotvAbiroqMdrmH9wxfZ8UwqMKbP0JzN1uIc2s3v6cjOhWvEP33jFR8LauYAe ypfSXm4Izqp6L2ZgVjZAQ1VI46W+Ri8yKhX7EG5tmmtsn9zj9v/1RmW+dpm/lvjZQV XIaJnl9ZKXjO+Sdt5/WKNsTAN/PyUg/mp1OgOgCdtybpnHxT7XdeT1/Qimq+ESYXF7 Q7NoHx+zxFWtWUCCX7Tv8je1tidweWSGo1GubLmPoWfygF36ouln3ROh6iZiANuceo 9yG9MJWsu1nvIh+LkHcYGnB2l8C4mWrImsaWaxXFGwTmP3JrLY1RDYN6r/nqdzYh5H nwwCKBrSd4aVQ== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:30 -0400 Subject: [PATCH v4 1/8] nfsd: fix assignment of ia_ctime.tv_nsec on delegated mtime update Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-1-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=892; i=jlayton@kernel.org; h=from:subject:message-id; bh=wX+jZhM05ADBnfHIbs04wC7/mLDtqIQ+H+KgWBk6ve0=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBoih0nVi5foMtUBA2+R641YJDWrZfKZbxje82aU ZVtbvTqLcKJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaIodJwAKCRAADmhBGVaC FWrnD/9JBYZ1l7YYEHwKJznIB7O2LFzhfkxMN5BRF5akaTaBMPMHcO7Ez9eH1fZ5/bML1TH2XrL bcsjLpZqt3W+bRU1dCO4N2lSZu7DYgFyw4GSYwoid8nb23KwKWYBSTbUSYjz+HX6C66KQgArT4Q s7M7awGQXZXx3dSxT89lwVQYcHiwPXIioDpgporfgF3SyrlQcrzwo61oFvU6j9r0yCUgYAW/tMN QfcNUdadfGoBJw6h21t496JLXBMhCN23qSGKGkZ7wkQdf2afG27vdavmqJDI4OXBE0hBLt81jbz +zCC7P80FY6Uh1aGmyDRPedJN2/h7Ihqk1EWRTTpTbYVav5Kvb/QoTU5JFggKV0Q+PLpScvUcyk V/nb7PevC5hYXDqmJKN/1rGsZ0HeQHpKMaR+yDCUCR+P26Rdjs4/Ep104aLlrHtEY7e27h+ZQtn zGfeapsymnOWxxLmQqQQPU0Grq5BnGDCbQ3YDP901xN1yAO1rmJxKSpnHI/zowCcvsTe3RKWFwr /iEQhoI+thdqiJcwzFRTfYyzLDfiUGrTf0cCea4BUx1fnH8j4122URFogO9CbruKSYXmwNvVyQa 5Gyi5xyCoQYE7sJIpkdoMsjGLZAYLnbJU6RFt8AtJvFqE7gzMnpPJz8HBtO6vwmCA+u277X/hNl e31dYbQcY3lSZ6A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The ia_ctime.tv_nsec field should be set to modify.nseconds. Fixes: 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR") Signed-off-by: Jeff Layton --- fs/nfsd/nfs4xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 8b68f74a8cf08c6aa1305a2a3093467656085e4a..52033e2d603eb545dda781df545= 8da7d9805a373 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -538,7 +538,7 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u3= 2 *bmval, u32 bmlen, iattr->ia_mtime.tv_sec =3D modify.seconds; iattr->ia_mtime.tv_nsec =3D modify.nseconds; iattr->ia_ctime.tv_sec =3D modify.seconds; - iattr->ia_ctime.tv_nsec =3D modify.seconds; + iattr->ia_ctime.tv_nsec =3D modify.nseconds; iattr->ia_valid |=3D ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET | ATTR_DEL= EG; } =20 --=20 2.50.1 From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CD6B629B226; Wed, 30 Jul 2025 13:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881901; cv=none; b=b7tUd0kz5gwTucdokv4IJluxBBFfp++YV2ee7EIFiyEavCQaYYUX/zorKOHqrCD7rgxWequdcJQn0ZVLmQgzj77vt04/d07sEG4OrCwCb7yNiEzOaOuPhrwKX0mNhP4D/g1TUOv7vmZgJ/1gTLUpYC7T20o6aBVYgXuZA4JrtK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881901; c=relaxed/simple; bh=XDfX4u5DGDNsbxUiLltzn/YVAvj+NJLvOFItEakukpE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rdpUlI6PLrT7tqsSS3MVYZ+B7F0MM833JQzse4aFBao1voTcT2Zm8JtFixxzZIehxSqbOFObiOI+9ZYinPT3/+DumwyDJLTImPTgnTK8s+t/96Vz14aihxKV05Q74fwinGQUPQImtFpD2U42NcJS+ddH/05cOrg+jCNW3faMmN8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jvtoRu35; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jvtoRu35" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15934C4CEE7; Wed, 30 Jul 2025 13:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881901; bh=XDfX4u5DGDNsbxUiLltzn/YVAvj+NJLvOFItEakukpE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jvtoRu356/ynVAUlXQcxRjIe5RaslfNZWKPfk/Sh5HEckQ4lHeVpg9Uy6m5TcJ7/6 0QqnQdOnt7K5z4Y6RDjS3fVlElqu3NQwAwo5Ek2XRSZ7AKYxvVcKCV8SRw/+26dT/K aPqYpSKGjgtG0rzaqSs7VsZ8K7hCFNGW8VDtfR8AtwixMXL6/TBoWflhOyN9a1nMrF BYzUzF7lefUalMIqjnq5ZD6KZhWGYeGFKJXi5Gl3Yljvq3FZg/Q6DzY9/6X/EKJPbL gWbcysCMN3/0VP/mwLIb/7cLrcXICX+8HrSVHUOorxBo+AadWiWYf9rrqdrazfZc0E fQ0gEsh5u7HFw== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:31 -0400 Subject: [PATCH v4 2/8] nfsd: ignore ATTR_DELEG when checking ia_valid before notify_change() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-2-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=675; i=jlayton@kernel.org; h=from:subject:message-id; bh=XDfX4u5DGDNsbxUiLltzn/YVAvj+NJLvOFItEakukpE=; b=kA0DAAoBAA5oQRlWghUByyZiAGiKHSeidVPkw+iRv5K30CeSW0OmrRUGM6TmaKlwkClrlOsvD IkCMwQAAQoAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJoih0nAAoJEAAOaEEZVoIV3ZYP/jES yRqPrCXsdAQU3Rge4ThncTlthN5K2VGIwTZsTAHmPa7KwlUIeP2w00AuL3OJehEfBbYQZhKbNIw jM5r6lKYJ83/m5B6a4uUoKbuCxKeMuT47Zm8RpjO6dttzBZIRr7dvYRt4WcrnRCNIQGI4L1ZVtg ITrMWzQBkHhU/hltrMK+ZYgTJ3i4MWZAP2vVuZ9HXtkQqSrTp8D5oxpZVvA2wFvwB3mKWoTzgl+ bZXYw1TjKVm5ONdJ7G98nG9UAzh37ybyBEVGuheU+4Cl/f0YuS5D7afzSsx0hu1h8XUeO2s/54M +cyIqXsOJNvxJwTdlM4duHsA7EEqZ5EhqB/h6cPgxxXfoyxtJPPt7gHOMFunX1qTJ5zGZljdxau /VmjdjYnWICNqCI3No9my2MOMT0rf7PG8l2Rs748cGZocrbPnNIKgujURLpNF5wpTIyrXl36kUs QQsncy1XpOUKD/pmO7UFHJEoPaY5A4mXG3O9yqEbaV1nBxxDfaZku7EwQoZoNuOTKbc+qzWQ+Lt OM81lGFUfTWJBgcfTeDA8+mZVK4nN7vYEVyzAw3IzLe5wYsqtIt1LHnMqSj1NAvaWY+UbUFeS2R VVii5d+j2upuwtScCGPXgRHfBRNi08zdls/kCGcMhyYm3DWR7A/kE6uhEfGbralWhSEiiO01/le Rg9+i X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 If the only flag left is ATTR_DELEG, then there are no changes to be made. Fixes: 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR") Signed-off-by: Jeff Layton --- fs/nfsd/vfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index eaf04751d07fe9be4d1dd08477bc5a38ac99be3a..68d42fc5504d8750174b9a2aef1= 0886ed92f528b 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -467,7 +467,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct= iattr *iap) return 0; } =20 - if (!iap->ia_valid) + if ((iap->ia_valid & ~ATTR_DELEG) =3D=3D 0) return 0; =20 /* --=20 2.50.1 From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6C08B29B8C7; Wed, 30 Jul 2025 13:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881903; cv=none; b=O94mHfw43LOVP9dYz53Y0gHCppELe3T63FVjWmGEh/l7G2Kz0/Fu84yN5PNSxRDZ7D33wRK5NxjuslL6L/f/4FxonYv/hq2q9ui1J8wPOVjK9yo7Gha814tS+RPBlaVeyexIkCqgK10+DKB+BJ0HDrwis8hNZHaZEMebBiBvM7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881903; c=relaxed/simple; bh=D6Xk7cn+dUV5CrFWyLhNEZEfnQS3I5r0LFUPIwKxpUo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dkapSBqv4VJgBzFebqu7FPBJ2sLYZw65QroD8a4UYiyCoFRNOmtizuRGmnc4WGMaFEw5r2VwkthPOUTJaKzmEBt/kUevCymx5svBRNInLWLlvryEqJloxhnUUxHg+fA2YZ23M8PUaCIKsmz11b3+BnD5tKksUXCcwK6CeUmqV/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uk1kb3R3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uk1kb3R3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D799C4CEEB; Wed, 30 Jul 2025 13:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881903; bh=D6Xk7cn+dUV5CrFWyLhNEZEfnQS3I5r0LFUPIwKxpUo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uk1kb3R30UQu2lY0efGS0dztFSlqBz2fZdhPk8oHhqokQ+KeHBm5hokzm5Npceh6c z4jq9LUUyhttmio+fXrDU43uCgre5Il2uWmznzYpk+gQJZLUARCqg3KYBRigTz7vAJ PDzSdTAf9O+BnNOh700kaP9dORl2WgQcG/7jltHmxlzY4pQYqWxQ+MpuDz9I9Rwwyl ZQ5Mkh2QCIllkKygq7JPNqlby5RkIsnihxyWMmQZ90OuxXLkGMzB6AX5ksHPVAEmxZ mqfd7wmWwiv/E/eJlCCKJyVEYK8TAEXOUuyUpriF04u8XlOsWe0CetsfoGuTcANube 62A30RHTgClkw== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:32 -0400 Subject: [PATCH v4 3/8] vfs: add ATTR_CTIME_SET flag Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-3-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3845; i=jlayton@kernel.org; h=from:subject:message-id; bh=D6Xk7cn+dUV5CrFWyLhNEZEfnQS3I5r0LFUPIwKxpUo=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBoih0nRzSwihwapJKgk4mLNsYH/l6BTSPqvX1dr P+0628pYWyJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaIodJwAKCRAADmhBGVaC FR7RD/4ma/rj5Drpc8mgvteRSdUbtRYsu1DmL9xn3VKrQdRZISvT+XnFrGF4RBPU+903PqdxWDT o+BXJUov/C5TlB04Ua/SL1eL/2K4jHO3oRaMJkb6ZBMqFYD/ytM2WAv2vhY7O9TV69gy+gSv7gf nvIWPYaZJrqHKcjx+NFJubuhuIdp/zIpfU/woSDrjahYwh24XYhhK56EcJrxRM9Fht9p5zMlnoa ClEBVfDGzs1DAoe/9S4/RtrZOqT3c6qrz37GIHUbDxfuBDHCRtC7sgFuPQBptBN9WTvqw9n20S2 5vS7beqK8BfQeqnDOXlBdI0Mjk/V8gp5xCejBMLhDVGKN8OQIN/8sGje05T+7EOXFaTBDu+y/jU gQ7x7H/6Flva653hv+wqGMXJsLp9fsh/PXGPqC6ctH48P7MO4alYG0ejgPxValLbbXsYn+P2yAc 4SybPlOZXHzQLQAsAKYAL6RAcFI6cnOdJYEv4XLPAB2D3nCz3FMvqUzowyrBKQoqCm6ZFbed9bV 6gid06pxt55YDBhrv8H7RrFgkTJGFjCFbhjqJdHkC2XSEqrwsoAAwqOTGRjJiWTIMEg6L0c/F0k t5YLVYweFtIbMG+ZUx0gexgQjq4UgFCvRuhIxORVAveTHg0K1hq3eV1yrpxyf8Vuf1iDU37M1uk ivp/stbG1/co+rQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 When ATTR_ATIME_SET and ATTR_MTIME_SET are set in the ia_valid mask, the notify_change() logic takes that to mean that the request should set those values explicitly, and not override them with "now". With the advent of delegated timestamps, similar functionality is needed for the ctime. Add a ATTR_CTIME_SET flag, and use that to indicate that the ctime should be accepted as-is. Also, clean up the if statements to eliminate the extra negatives. In setattr_copy() and setattr_copy_mgtime() use inode_set_ctime_deleg() when ATTR_CTIME_SET is set, instead of basing the decision on ATTR_DELEG. Signed-off-by: Jeff Layton --- fs/attr.c | 44 +++++++++++++++++++------------------------- include/linux/fs.h | 1 + 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 9caf63d20d03e86c535e9c8c91d49c2a34d34b7a..f8bb2b6011ca87243765bb44485= 0b3b4bb91e275 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -286,20 +286,12 @@ static void setattr_copy_mgtime(struct inode *inode, = const struct iattr *attr) unsigned int ia_valid =3D attr->ia_valid; struct timespec64 now; =20 - if (ia_valid & ATTR_CTIME) { - /* - * In the case of an update for a write delegation, we must respect - * the value in ia_ctime and not use the current time. - */ - if (ia_valid & ATTR_DELEG) - now =3D inode_set_ctime_deleg(inode, attr->ia_ctime); - else - now =3D inode_set_ctime_current(inode); - } else { - /* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */ - WARN_ON_ONCE(ia_valid & ATTR_MTIME); + if (ia_valid & ATTR_CTIME_SET) + now =3D inode_set_ctime_deleg(inode, attr->ia_ctime); + else if (ia_valid & ATTR_CTIME) + now =3D inode_set_ctime_current(inode); + else now =3D current_time(inode); - } =20 if (ia_valid & ATTR_ATIME_SET) inode_set_atime_to_ts(inode, attr->ia_atime); @@ -359,12 +351,11 @@ void setattr_copy(struct mnt_idmap *idmap, struct ino= de *inode, inode_set_atime_to_ts(inode, attr->ia_atime); if (ia_valid & ATTR_MTIME) inode_set_mtime_to_ts(inode, attr->ia_mtime); - if (ia_valid & ATTR_CTIME) { - if (ia_valid & ATTR_DELEG) - inode_set_ctime_deleg(inode, attr->ia_ctime); - else - inode_set_ctime_to_ts(inode, attr->ia_ctime); - } + + if (ia_valid & ATTR_CTIME_SET) + inode_set_ctime_deleg(inode, attr->ia_ctime); + else if (ia_valid & ATTR_CTIME) + inode_set_ctime_to_ts(inode, attr->ia_ctime); } EXPORT_SYMBOL(setattr_copy); =20 @@ -463,15 +454,18 @@ int notify_change(struct mnt_idmap *idmap, struct den= try *dentry, =20 now =3D current_time(inode); =20 - attr->ia_ctime =3D now; - if (!(ia_valid & ATTR_ATIME_SET)) - attr->ia_atime =3D now; - else + if (ia_valid & ATTR_ATIME_SET) attr->ia_atime =3D timestamp_truncate(attr->ia_atime, inode); - if (!(ia_valid & ATTR_MTIME_SET)) - attr->ia_mtime =3D now; else + attr->ia_atime =3D now; + if (ia_valid & ATTR_CTIME_SET) + attr->ia_ctime =3D timestamp_truncate(attr->ia_ctime, inode); + else + attr->ia_ctime =3D now; + if (ia_valid & ATTR_MTIME_SET) attr->ia_mtime =3D timestamp_truncate(attr->ia_mtime, inode); + else + attr->ia_mtime =3D now; =20 if (ia_valid & ATTR_KILL_PRIV) { error =3D security_inode_need_killpriv(dentry); diff --git a/include/linux/fs.h b/include/linux/fs.h index 040c0036320fdf87a2379d494ab408a7991875bd..f18f45e88545c39716b917b1378= fb7248367b41d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -237,6 +237,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t o= ffset, #define ATTR_ATIME_SET (1 << 7) #define ATTR_MTIME_SET (1 << 8) #define ATTR_FORCE (1 << 9) /* Not a change, but a change it */ +#define ATTR_CTIME_SET (1 << 10) #define ATTR_KILL_SUID (1 << 11) #define ATTR_KILL_SGID (1 << 12) #define ATTR_FILE (1 << 13) --=20 2.50.1 From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 00DAB29C34B; Wed, 30 Jul 2025 13:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881905; cv=none; b=CU0k7mOY5Mmex/bynl/Sr/uE75YUjRydCP7dba7qnGHhGOK6uahjz2p6G2lgX3v9V/KtLRBYh+taNHrwe63wetuvubq706bNRjw8hgjbWVKAzQyc9kIZN55z82/MQCT9RXnTkVfUoEC1dGb0HajhUCFWpGGoVlz9nFpPM7KRqYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881905; c=relaxed/simple; bh=tB28A7UEW/1kAwxOpup/7X4hmWe1RoJvUGt2RZpGRko=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mYh0X84nhujBvmXeQqn31PtuwdEZnkeSmrAsVR3LS34QI/4Q5nA3pBcAs9gAWJow9qxM3v1Ix6ZaauMj1NhaFCL4JjC02bmg9OG1W+UZuCCnO2MX8D58vMm6OUXkO0tV5da24pShB4zmrSqZ3PfaRfrv5M1J6W8ZD+20VLh3edo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NhBkoUw9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NhBkoUw9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3183CC4CEFC; Wed, 30 Jul 2025 13:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881904; bh=tB28A7UEW/1kAwxOpup/7X4hmWe1RoJvUGt2RZpGRko=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NhBkoUw9wLmkYcMIvvWjwWh/XQjoigI2SSjBl4DhzvF7icIEuE8klhY7B47IEjaWD pzB2ov9mRXbvxI4pWjfQCuGfOtQvCLD5nMji7WxJ5EYGJlKRa070/EsHOHvSSl5JAN y8lQBSoZTq80RgdSLwHjII5dk83zAGcyAaG/GaPfvbqS2k6+ThDpLV9Oe+AHcNR74Z irorm7aOPwl825UAytDcdsObDt0QsWy1PhvToIndf+t1OmeYWpjvF3Bijj63JBcuO8 joGykFppGnS6phaox52xaEWjhENmyvcMA9OnyUJo7EANdsWy0GA67EQZi7o1KaX4WH alLxUQp2MxBOQ== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:33 -0400 Subject: [PATCH v4 4/8] nfsd: use ATTR_CTIME_SET for delegated ctime updates Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-4-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2742; i=jlayton@kernel.org; h=from:subject:message-id; bh=tB28A7UEW/1kAwxOpup/7X4hmWe1RoJvUGt2RZpGRko=; b=owEBbAKT/ZANAwAKAQAOaEEZVoIVAcsmYgBoih0ngBLUqXHCJyEICLnOeZqPtjb7bf9xnIxNa qy2ohAXa1iJAjIEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaIodJwAKCRAADmhBGVaC FfLzD/isgA9VmMDTr6dEPY202PlRxS3TzdJKRoe0sQnt5mnTLr2X1jCJOsVGYqZL/9PPyC4+ItL vQkmVGRCZ4L2ipNpsNynSRgro4VCy/tkokYAJN0XLm4bOeGmMfcILY2OY4DjmYzcnwEtt0WF8r0 C0N2l44GbMANrP6B2bVCt1TaNdnvlpd7dxF1CS2yC6/668/w7x9nrGOlJMUJ55uQGNxufxzl9CR 4ci5uxb9zXEXmmB3q32J+oyNJ4FcK+hPMkuXEUBwd/TjfKbrQy4MPW9d2DuiscdSHfT7VOeBvyr JkhgcV8jJEj18JEqsnCJwJoNQ//nwlhwREEd0vToAeonzWzchus75IxULN1ty3lj+q/+KGHtg1x oGDlBgkWFiDA+XKXDjOcP+Zvr2PKVsqkB2QhMwDO8Ok14Ry0VXch/i5lDXKylEBlkmu2X/g3qaK wb1gLGLH/bEDbgPMKSzdZf7CRflYipL2hTnW2ZLB/C7CVv2gUpkU3wR0vOKgFsc6H+CI3/95W4n XZyI7d/xwweuuBu0zk70VybH/bS3NaVChTbJH4YSiIPOZp5kEdaMcLH1otpeFjQL7Wm/enPfgxv BQAmCwMgB++kw8dnOqwkOEx1leZriMn+9Wo0GSnToZXgrD5Lul9dEMXl3Sv1mUyRqqH3yZp5eNx tA958PYDhtwIS X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Ensure that notify_change() doesn't clobber a delegated ctime update with current_time() by setting ATTR_CTIME_SET for those updates. Don't bother setting the timestamps in cb_getattr_update_times() in the non-delegated case. notify_change() will do that itself. Fixes: 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR") Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 6 +++--- fs/nfsd/nfs4xdr.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 88c347957da5b8f352be63f84f207d2225f81cb9..77eea2ad93cc07939f045fc4b98= 3b1ac00d068b8 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -9167,7 +9167,6 @@ static bool set_cb_time(struct timespec64 *cb, const = struct timespec64 *orig, static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_dele= gation *dp) { struct inode *inode =3D d_inode(dentry); - struct timespec64 now =3D current_time(inode); struct nfs4_cb_fattr *ncf =3D &dp->dl_cb_fattr; struct iattr attrs =3D { }; int ret; @@ -9175,6 +9174,7 @@ static int cb_getattr_update_times(struct dentry *den= try, struct nfs4_delegation if (deleg_attrs_deleg(dp->dl_type)) { struct timespec64 atime =3D inode_get_atime(inode); struct timespec64 mtime =3D inode_get_mtime(inode); + struct timespec64 now =3D current_time(inode); =20 attrs.ia_atime =3D ncf->ncf_cb_atime; attrs.ia_mtime =3D ncf->ncf_cb_mtime; @@ -9183,12 +9183,12 @@ static int cb_getattr_update_times(struct dentry *d= entry, struct nfs4_delegation attrs.ia_valid |=3D ATTR_ATIME | ATTR_ATIME_SET; =20 if (set_cb_time(&attrs.ia_mtime, &mtime, &now)) { - attrs.ia_valid |=3D ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET; + attrs.ia_valid |=3D ATTR_CTIME | ATTR_CTIME_SET | + ATTR_MTIME | ATTR_MTIME_SET; attrs.ia_ctime =3D attrs.ia_mtime; } } else { attrs.ia_valid |=3D ATTR_MTIME | ATTR_CTIME; - attrs.ia_mtime =3D attrs.ia_ctime =3D now; } =20 if (!attrs.ia_valid) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 52033e2d603eb545dda781df5458da7d9805a373..c0a3c6a7c8bb70d62940115c310= 1e9f897401456 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -539,7 +539,8 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u3= 2 *bmval, u32 bmlen, iattr->ia_mtime.tv_nsec =3D modify.nseconds; iattr->ia_ctime.tv_sec =3D modify.seconds; iattr->ia_ctime.tv_nsec =3D modify.nseconds; - iattr->ia_valid |=3D ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET | ATTR_DEL= EG; + iattr->ia_valid |=3D ATTR_CTIME | ATTR_CTIME_SET | + ATTR_MTIME | ATTR_MTIME_SET | ATTR_DELEG; } =20 /* request sanity: did attrlist4 contain the expected number of words? */ --=20 2.50.1 From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 321E429CB58; Wed, 30 Jul 2025 13:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881906; cv=none; b=PHxon4oMv/T+70kE1cxm8DxrwMZ7DCbjJ/IgDm4U/+myqMNqmAjCWiDjC8Io0cbVeU+nfohzHoSGQCaUUcudQAruPD2yhNDbC0Cwij8+Hes21+9tO4eoxhGEpCPi4eDgmBN0yfj8z5k0PmHCChm3X2PzEss3nWxd9z3jkT1kbW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881906; c=relaxed/simple; bh=fdO6f13p1GTQnu6FzwkdZ4uJxgGOC3acS3Ht0AFuvgE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mZS/AZTGgK3jW4gv6R8tpgfbY2kq1bEYEjbR/maPkvo9tKe6tBlhC5n3+fzUU+ATnJXsprWwtKF/sSXzYwuXs5+nHJJvrOA42Kf7Lr6LcQp0Dh5xwUp3Cck3HJS+4yV9iOBkLQvOEKMGeW3wR7yvcTSvwLAAJwyNBp/8570Ucak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m/wJu5Bs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m/wJu5Bs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B92F7C4CEF7; Wed, 30 Jul 2025 13:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881906; bh=fdO6f13p1GTQnu6FzwkdZ4uJxgGOC3acS3Ht0AFuvgE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m/wJu5BspaQ9sh+h+bK9GcUP0ajqJB8qrL1e0ULPyclPU8qL1L73jHCpYwDmuf4b6 G/7IBpGUI5VUw3WxfWZOTRrYFxVB5kayqycEaVjcZZcJvsrM+fDJFw7+NJwV/42rEt 703oBBRnfcpvVwW654daUjF+2wDe6emjZMcvpN5Vwb08QHci89huytnHDvkpMeaBoJ 97j4ErxW+ScqKH5KNIjHqWp49EVbjUGySLUrCvKVSYZYUfo41v+4R5kHjnpYvZkzOu maTLbWCrd+1eI7gkFnBi08PzuBGZXlOlsPeE2ycufsuhDQ/ab6bUPRDUA+CHIqwRkp mZuNHoyCo67Rg== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:34 -0400 Subject: [PATCH v4 5/8] nfsd: track original timestamps in nfs4_delegation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-5-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2805; i=jlayton@kernel.org; h=from:subject:message-id; bh=fdO6f13p1GTQnu6FzwkdZ4uJxgGOC3acS3Ht0AFuvgE=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBoih0oG+lic4zFr8udIEAYZwrO6rCEfUtc+wReY MXZVYJY4LWJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaIodKAAKCRAADmhBGVaC FZklD/4wGAl9Fu+8Gb/lDEcmw0cYrxIK9BB7ToRpMBdOyXb15sskNc7HXQe0WV7DG9mUIAvRfju mhIr+xWNpndSlipcGs2874TzcSZCtkBF/JC3v8FbV05idjoLQMTabgir4fNi7NKw/bOMyXAlpk3 XkwsmOFXd0SqwL1YRHK4W1U2pleiJH4AynIB5xnSG4eLoxb7ztFrSiAuFCsK7eZNTHjWq4RQkLw sP+tihM0tr2dk3HrvCaXSFo3U7jL0ATuuuBlexNElrOCMchufvbYSoCPtv8WtRpsR9FH8RmAFV0 DrSRKc1oZHeyhPbp+p8YnModeABGtpDfcHgr1qwWIJR0oMnsj3HLyxbWaE4W+6XBoN1GQAzn3Qu B8ZsnNJv/M47Su96nzmInfjRdr5iDysYNuJQ36bi7ib7180Q2e85WgiSeFpzOHIc0Vq/TLl+5DH XAMfARbsTshClcjFk35g3LwYsOqyzzSxvO/rVh6XSGmOoL8s0ayu6Tc2AWK/1BFdnR9AySLjrAI tGF2akKIH/om06TP+oUtiVaz808JJUB9/1w9XRxdKdv+bVJdpBdxG8MCXt7PtG35r+Fx6tShD8l 6CSx47j1dNmLA9R+LYh5hMH2U02Ca3FGQ2kq+DGFSz1wa0ST/qc6YprfsjGVmnEIFELIjfpnj3J HCBSwyjOXEotpDw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 As Trond points out [1], the "original time" mentioned in RFC 9754 refers to the timestamps on the files at the time that the delegation was granted, and not the current timestamp of the file on the server. Store the current timestamps for the file in the nfs4_delegation when granting one. Add STATX_ATIME and STATX_MTIME to the request mask in nfs4_delegation_stat(). When granting OPEN_DELEGATE_READ_ATTRS_DELEG, do a nfs4_delegation_stat() and save the correct atime. If the stat() fails for any reason, fall back to granting a normal read deleg. [1]: https://lore.kernel.org/linux-nfs/47a4e40310e797f21b5137e847b06bb203d9= 9e66.camel@kernel.org/ Fixes: 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR") Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 11 ++++++++--- fs/nfsd/state.h | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 77eea2ad93cc07939f045fc4b983b1ac00d068b8..8737b721daf3433bab46065e751= 175a4dcdd1c89 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6157,7 +6157,8 @@ nfs4_delegation_stat(struct nfs4_delegation *dp, stru= ct svc_fh *currentfh, path.dentry =3D file_dentry(nf->nf_file); =20 rc =3D vfs_getattr(&path, stat, - (STATX_MODE | STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE), + STATX_MODE | STATX_SIZE | STATX_ATIME | + STATX_MTIME | STATX_CTIME | STATX_CHANGE_COOKIE, AT_STATX_SYNC_AS_STAT); =20 nfsd_file_put(nf); @@ -6274,10 +6275,14 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct= nfsd4_open *open, OPEN_DELEGATE_WRITE; dp->dl_cb_fattr.ncf_cur_fsize =3D stat.size; dp->dl_cb_fattr.ncf_initial_cinfo =3D nfsd4_change_attribute(&stat); + dp->dl_atime =3D stat.atime; + dp->dl_ctime =3D stat.ctime; + dp->dl_mtime =3D stat.mtime; trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); } else { - open->op_delegate_type =3D deleg_ts ? OPEN_DELEGATE_READ_ATTRS_DELEG : - OPEN_DELEGATE_READ; + open->op_delegate_type =3D deleg_ts && nfs4_delegation_stat(dp, currentf= h, &stat) ? + OPEN_DELEGATE_READ_ATTRS_DELEG : OPEN_DELEGATE_READ; + dp->dl_atime =3D stat.atime; trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); } nfs4_put_stid(&dp->dl_stid); diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 8adc2550129e67a4e6646395fa2811e1c2acb98e..ce7c0d129ba338e1269ed163266= e1ee192cd02c5 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -224,6 +224,11 @@ struct nfs4_delegation { =20 /* for CB_GETATTR */ struct nfs4_cb_fattr dl_cb_fattr; + + /* For delegated timestamps */ + struct timespec64 dl_atime; + struct timespec64 dl_mtime; + struct timespec64 dl_ctime; }; =20 static inline bool deleg_is_read(u32 dl_type) --=20 2.50.1 From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0420A29E0F7; Wed, 30 Jul 2025 13:25:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881908; cv=none; b=U8jGme4SJO3kZAQzQ5JRqq0IXIKAhiIUSAkspzF33rG6RcsX2ZfQU9KVjD7yNBNaC52fFyh0bgHp1nQzgoDKvO7DgBcwI0Poo4JsSr3puS+7o/rS9jMc5zD8g5Ag76UEnMjBteD6XRE16HEC/0jEYfoHzvmC2JbEfnNXiTfsgoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881908; c=relaxed/simple; bh=GnTr/aETvE3ymkWSwJqsiI1LzQh8lephKpOFz0kWFvQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RD1qvRnLj4swA022nvT7iAJX/9BAVAjKQ3R0SfMir8YDLdigTmwoMR9hX9qsGjDlZdAKwZWb1T5oeadfaPpfa57ofci7lzBr6Elm9mDQ2RlZ3C2Pl96adpRu2MrBXMTWEP+C7YbM9JA6hwleWEzAi/hvEYQcm3rkTNPqga/RuSw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ji7B9p4t; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ji7B9p4t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C32FC4CEE7; Wed, 30 Jul 2025 13:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881907; bh=GnTr/aETvE3ymkWSwJqsiI1LzQh8lephKpOFz0kWFvQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ji7B9p4t+rBJFCqiXuNdiar/F35zfpbSET6Oa7Zhz0RITVayXdFiQv6TeeuIY4sdU aBnRT+B+0HV2SFDT9Hvast4u1zM02i6SLyu4gN1Y764TbliZReruu4voAZXxo3zS0z Ffa/wZRS2TvenvWa9lDRJdKgb4ljJV16IYh989kOwPgaNg/m3o/M4GL2doDH8KmwIq Xk5GB2Ar8w3eJg3g3MIzK8UJG45tAMLUspdxg/M7VGqwdI1ZniTmwLGg9+fKyKDxQ6 MJwrN2JrxnVKJyCVSsougWMXmtdgIm+Y+oagDqRRF/8zApJiyMu8stIvNPyyFW2TFr BKGcRcWX6m/ZQ== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:35 -0400 Subject: [PATCH v4 6/8] nfsd: fix SETATTR updates for delegated timestamps Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-6-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5835; i=jlayton@kernel.org; h=from:subject:message-id; bh=GnTr/aETvE3ymkWSwJqsiI1LzQh8lephKpOFz0kWFvQ=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBoih0oR4ih+0+i9RTgUeu+qCgcrdmMhZDqLDWCR k+2L4fqZnKJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaIodKAAKCRAADmhBGVaC FV+jD/4x2nVkGliO9+GYOIt7oHZoxKFXYsh42mw8yRFAsGsGHPrf68WILh3JcbUAxMUjjWUDs3G OTaSfZSVhfYa5Y7b8Yv6ImDAKnW4+Fc7lDF8MJ4F15RSgPMS7UGi9PJlHozW2S35REwOhRPAnQF JyElv2+5v0WyPSTXnQalqOohNLYy3vqdGnC4y6/pcnfrMb0oiE0Y34towyjKeEnBHvHkRbBHjX2 BUT1tehoEV3BJGzH+JE5KYQcUvqli5+1KYecqr+4ITXHG01uIT7xEFY2Tcery3MI4VxSlwjXcL6 IRdpCojvPBdty/MURNAi87d5c00o9THInOSnZj8ijtUGO56FgFM2U6n+NW8O0jlMPk12q4kZeF+ pvR9JEVrwj2K5bq5jdi/s/r8NxEcabLC0CVS1/dqR/cYE8egOAslB0FD7wUfY66l4E4DFXX++lt O/F8NOO4dYNAsEBv8mBS+zlyIAHBVR7YdTJSir217EEVcXgyMB1bN+nkkfhH4jSuAu6O4RFZEs2 WHI4A08NVDEUznhB2ghiWcPFUSfhtIXWoEvoakCKbutC1u0NCM0yIYAmF7WJ+UTXAYoVsKkDhwZ Rw8u8lfIKgUDuSBTc35O0bluTe9Hq702bI+QGmHZQSEic7aDk8mB45m+Ej4eskIk9aNZd8bzkPi 3gatxFKaMTdLCpw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 SETATTRs containing delegated timestamp updates are currently not being vetted properly. Since we no longer need to compare the timestamps vs. the current timestamps, move the vetting of delegated timestamps wholly into nfsd. Rename the set_cb_time() helper to nfsd4_vet_deleg_time(), and make it non-static. Add a new vet_deleg_attrs() helper that is called from nfsd4_setattr that uses nfsd4_vet_deleg_time() to properly validate the all the timestamps. If the validation indicates that the update should be skipped, unset the appropriate flags in ia_valid. Fixes: 7e13f4f8d27d ("nfsd: handle delegated timestamps in SETATTR") Signed-off-by: Jeff Layton --- fs/nfsd/nfs4proc.c | 31 ++++++++++++++++++++++++++++++- fs/nfsd/nfs4state.c | 24 +++++++++++------------- fs/nfsd/state.h | 3 +++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 7043fc475458d3b602010b47f489a3caba85e3ca..aacd912a5fbe29ba5ccac206d13= 243308f36b7fa 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1133,6 +1133,33 @@ nfsd4_secinfo_no_name_release(union nfsd4_op_u *u) exp_put(u->secinfo_no_name.sin_exp); } =20 +/* + * Validate that the requested timestamps are within the acceptable range.= If + * timestamp appears to be in the future, then it will be clamped to + * current_time(). + */ +static void +vet_deleg_attrs(struct nfsd4_setattr *setattr, struct nfs4_delegation *dp) +{ + struct timespec64 now =3D current_time(dp->dl_stid.sc_file->fi_inode); + struct iattr *iattr =3D &setattr->sa_iattr; + + if ((setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) && + !nfsd4_vet_deleg_time(&iattr->ia_atime, &dp->dl_atime, &now)) + iattr->ia_valid &=3D ~(ATTR_ATIME | ATTR_ATIME_SET); + + if (setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { + if (nfsd4_vet_deleg_time(&iattr->ia_mtime, &dp->dl_mtime, &now)) { + iattr->ia_ctime =3D iattr->ia_mtime; + if (!nfsd4_vet_deleg_time(&iattr->ia_ctime, &dp->dl_ctime, &now)) + iattr->ia_valid &=3D ~(ATTR_CTIME | ATTR_CTIME_SET); + } else { + iattr->ia_valid &=3D ~(ATTR_CTIME | ATTR_CTIME_SET | + ATTR_MTIME | ATTR_MTIME_SET); + } + } +} + static __be32 nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) @@ -1170,8 +1197,10 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_c= ompound_state *cstate, struct nfs4_delegation *dp =3D delegstateid(st); =20 /* Only for *_ATTRS_DELEG flavors */ - if (deleg_attrs_deleg(dp->dl_type)) + if (deleg_attrs_deleg(dp->dl_type)) { + vet_deleg_attrs(setattr, dp); status =3D nfs_ok; + } } } if (st) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 8737b721daf3433bab46065e751175a4dcdd1c89..f2fd0cbe256b9519eaa5cb0cc18= 872e08020edd3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -9135,25 +9135,25 @@ nfsd4_get_writestateid(struct nfsd4_compound_state = *cstate, } =20 /** - * set_cb_time - vet and set the timespec for a cb_getattr update - * @cb: timestamp from the CB_GETATTR response + * nfsd4_vet_deleg_time - vet and set the timespec for a delegated timesta= mp update + * @req: timestamp from the client * @orig: original timestamp in the inode * @now: current time * - * Given a timestamp in a CB_GETATTR response, check it against the + * Given a timestamp from the client response, check it against the * current timestamp in the inode and the current time. Returns true * if the inode's timestamp needs to be updated, and false otherwise. - * @cb may also be changed if the timestamp needs to be clamped. + * @req may also be changed if the timestamp needs to be clamped. */ -static bool set_cb_time(struct timespec64 *cb, const struct timespec64 *or= ig, - const struct timespec64 *now) +bool nfsd4_vet_deleg_time(struct timespec64 *req, const struct timespec64 = *orig, + const struct timespec64 *now) { =20 /* * "When the time presented is before the original time, then the * update is ignored." Also no need to update if there is no change. */ - if (timespec64_compare(cb, orig) <=3D 0) + if (timespec64_compare(req, orig) <=3D 0) return false; =20 /* @@ -9161,10 +9161,8 @@ static bool set_cb_time(struct timespec64 *cb, const= struct timespec64 *orig, * clamp the new time to the current time, or it may * return NFS4ERR_DELAY to the client, allowing it to retry." */ - if (timespec64_compare(cb, now) > 0) { - /* clamp it */ - *cb =3D *now; - } + if (timespec64_compare(req, now) > 0) + *req =3D *now; =20 return true; } @@ -9184,10 +9182,10 @@ static int cb_getattr_update_times(struct dentry *d= entry, struct nfs4_delegation attrs.ia_atime =3D ncf->ncf_cb_atime; attrs.ia_mtime =3D ncf->ncf_cb_mtime; =20 - if (set_cb_time(&attrs.ia_atime, &atime, &now)) + if (nfsd4_vet_deleg_time(&attrs.ia_atime, &atime, &now)) attrs.ia_valid |=3D ATTR_ATIME | ATTR_ATIME_SET; =20 - if (set_cb_time(&attrs.ia_mtime, &mtime, &now)) { + if (nfsd4_vet_deleg_time(&attrs.ia_mtime, &mtime, &now)) { attrs.ia_valid |=3D ATTR_CTIME | ATTR_CTIME_SET | ATTR_MTIME | ATTR_MTIME_SET; attrs.ia_ctime =3D attrs.ia_mtime; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index ce7c0d129ba338e1269ed163266e1ee192cd02c5..bf9436cdb93c5dd5502ecf83433= ea311e3678711 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -247,6 +247,9 @@ static inline bool deleg_attrs_deleg(u32 dl_type) dl_type =3D=3D OPEN_DELEGATE_WRITE_ATTRS_DELEG; } =20 +bool nfsd4_vet_deleg_time(struct timespec64 *cb, const struct timespec64 *= orig, + const struct timespec64 *now); + #define cb_to_delegation(cb) \ container_of(cb, struct nfs4_delegation, dl_recall) =20 --=20 2.50.1 From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8A8C32BCF51; Wed, 30 Jul 2025 13:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881909; cv=none; b=TsxL9s0E7BQfOfpzs4QIo5RxwV23skCmCarVIypDrtBW3grgt3Bm1DicsE9JuynuupsUgSJ1YyG6nYGD+wv6jyaoSiuLP3DT9pNfkpgikYC/HPRlM9oKCVxowJ7qIYWhVamzsAPjWzdwQgc8kzlMd5SfT2XyR/HyEF29fFCz4O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881909; c=relaxed/simple; bh=+rAzc5qvjz0FCD5vq5bKYPfZ4fICvaRMvsO7vDhd3jo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NH4PtYa3BSHaq4ZRRBLQJIxx1/BCmc3c6/eeOe65w0LCHalQ6ZA1+sJXTiQhpeL49aYEEaQe9Gi5cMyXqYJfQFmcL2tLsM9afLhFPNJF/MEU0zq8drf/+e/PmXZaZaAQOFjrwKRgQx9qG0EKBVg91bx0BRyxS4dzI7B42IDufsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lUsB0HL+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lUsB0HL+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D396DC4CEF6; Wed, 30 Jul 2025 13:25:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881909; bh=+rAzc5qvjz0FCD5vq5bKYPfZ4fICvaRMvsO7vDhd3jo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lUsB0HL+ryaxgWhnK0hehy8FZ29dYok29L2frmn3NJsK1x2Selj8WMtgcRBjiQOwy 2O7C7JwOmZgNa25ti6YJB4N9VW4ZjmP+gEM1lQ51mMOMyfGsdynQD9D7X6+9GVX/k0 iQaaxT8UYW4y6bcne5pM/aNSgVoruYewjfUTFP9OxWbpu/wPO2om65bebfOl2YcPh3 grs5w81VGPFl6wSckTUjtfxhOVkPupCnZwYZpn31HtLnRrXLV/toMQE1ohKJkzEkj7 I2C95wbDX/GAOOOs0JUoCRheIzCbCVY5ukzRctl0QdtbNlwptgaVgJNfvpTiYUSZaR XEmFllDYraVXQ== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:36 -0400 Subject: [PATCH v4 7/8] nfsd: fix timestamp updates in CB_GETATTR Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-7-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1814; i=jlayton@kernel.org; h=from:subject:message-id; bh=+rAzc5qvjz0FCD5vq5bKYPfZ4fICvaRMvsO7vDhd3jo=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBoih0ozCZMvsY/QigN4CpbOu48VpvIAL2kTVRDC jUPMEwLmzWJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaIodKAAKCRAADmhBGVaC FUJgD/wNh7Hmn5bfpdWIRcoMZrV0ukGz4e9p3wBx5n4aWvICu+EKxxBUewz3fcfH2G1twF2oiuf g+W7A/8Y09vpc24XSAG6B6g1aWOJRBxZJDb43nurZOL4Z7fwsu+vcM4mWvxorXJE7fGbzCvx7CZ 49VEgxbzFQSVJG7YCHVbLvYPN40qBi0g7xN4HWdV10asvwTldCxB2YDrSlHHj41r2c7U6lUL4Ls lh/z51e5J/TvQDp/EPS4HNG15lLTk1hAWN+Dl34OlKb2bqSdxKJxMlKKtPjrMm9l0QPuGEEMEYD h2yHsG7gMBW5T1524qSwgRqYa6tbjtgPflL1At5VHQsU5j7OwIa/FLPx5L4US8bTQ7CtMF4ricd 6YsxSWc2gp8e8DeddKM0UWX7gIs/ZbKauPZGrm1/2K2FUHd1Wes3qpEqqvuaS/Bkkjc8hQ8XuJt zvQ21IRB5abeW8YiL49XR8dbMXTPEp0ZnuwsqeQ8gYILJV/JvHHGe4MfewfKzUSNnUXGtavJsa5 /CpChHs0TA+Q8cwZctCqp0xhsMj+wDZzlAnuwNH9U71aYPlCnE+DyrSMQaRQF2N22HeVGHLpHgF 2Bcr+7T2RBmisA8Z2qX9QBYIUfBc371vVPIKBQnfg32pR3o7KyloC4PlC+b9lLVb9I54NYIhL3b u1PQx198KX0oD7Q== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 When updating the local timestamps from CB_GETATTR, the updated values are not being properly vetted. Compare the update times vs. the saved times in the delegation rather than the current times in the inode. Also, ensure that the ctime is properly vetted vs. its original value. Fixes: 6ae30d6eb26b ("nfsd: add support for delegated timestamps") Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index f2fd0cbe256b9519eaa5cb0cc18872e08020edd3..205ee8cc6fa2b9f74d08f7938b3= 23d03bdf8286c 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -9175,20 +9175,19 @@ static int cb_getattr_update_times(struct dentry *d= entry, struct nfs4_delegation int ret; =20 if (deleg_attrs_deleg(dp->dl_type)) { - struct timespec64 atime =3D inode_get_atime(inode); - struct timespec64 mtime =3D inode_get_mtime(inode); struct timespec64 now =3D current_time(inode); =20 attrs.ia_atime =3D ncf->ncf_cb_atime; attrs.ia_mtime =3D ncf->ncf_cb_mtime; =20 - if (nfsd4_vet_deleg_time(&attrs.ia_atime, &atime, &now)) + if (nfsd4_vet_deleg_time(&attrs.ia_atime, &dp->dl_atime, &now)) attrs.ia_valid |=3D ATTR_ATIME | ATTR_ATIME_SET; =20 - if (nfsd4_vet_deleg_time(&attrs.ia_mtime, &mtime, &now)) { - attrs.ia_valid |=3D ATTR_CTIME | ATTR_CTIME_SET | - ATTR_MTIME | ATTR_MTIME_SET; + if (nfsd4_vet_deleg_time(&attrs.ia_mtime, &dp->dl_mtime, &now)) { + attrs.ia_valid |=3D ATTR_MTIME | ATTR_MTIME_SET; attrs.ia_ctime =3D attrs.ia_mtime; + if (nfsd4_vet_deleg_time(&attrs.ia_ctime, &dp->dl_ctime, &now)) + attrs.ia_valid |=3D ATTR_CTIME | ATTR_CTIME_SET; } } else { attrs.ia_valid |=3D ATTR_MTIME | ATTR_CTIME; --=20 2.50.1 From nobody Sun Oct 5 20:17:12 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 269362BCF4C; Wed, 30 Jul 2025 13:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881911; cv=none; b=AhVF+BCE/1OmlADXrQcXJEY63+Y2DfuT6ZVSNvvP9LbmlMB4xi0RYuxzVkHP12jzP7zzZrCSH93AwaEQ1xOJe0fCTN/7PuH4nwpFPttIOLhx7gdIF+Ql2RZCEAHRLXWzIpqIy1DJLL6+oDrAnreNn67wye6B+gVRBwEdMgvvEzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753881911; c=relaxed/simple; bh=ISrKgET4NpOpfmn2MuleOE6e3bVTq1FJQoGUMNqYgbE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DU2IS8wc4mkJ2jo4oeA6EkDquAVowAJgbVq1nFswiqA7JDfOOYVVXKr6ApxMyxpf7c/62N6KcdGyHMolsHBQTwOGunlrKiV/ahwX6BWQZeEPLDDeFrGK5w+dacS2HAF3nbFYJ33Pi9NS8qxexa4ATIKIYdYXfeaTiUsbQvkWc4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q7OGUU0Y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q7OGUU0Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65E3CC4CEEB; Wed, 30 Jul 2025 13:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753881910; bh=ISrKgET4NpOpfmn2MuleOE6e3bVTq1FJQoGUMNqYgbE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Q7OGUU0YCM7FQooxSQnK8TNOzYrCpPhclF7yDGTPaE0J2z1kKIqjWmu5F6zSduMcY 875L1xKa4WEcw71D7wrlCIh6fTTY/5bHuywkhhtJ5BXzzq3DHOooAYu5dq/m4t/6b/ aT3sDWX9TLWw6kPSkmOjMYthVsVso4gStMnvq5ZJfEI8vJRwQRitpXfS77ZawMmU+q eBdUE/5l6s+0xQgbC7P65tKkA/1ntFau0xI3ieytM7Y7F8GGkopgO4T4zkkpsE/i24 TL1VxRbnuCYi/eikzEfcMBZbeJU9WjGaNDAl5hSpKPDSeZ0nFIQFCj2t8p3kiKhI7o 2TSQwJr5lWVhA== From: Jeff Layton Date: Wed, 30 Jul 2025 09:24:37 -0400 Subject: [PATCH v4 8/8] nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-nfsd-testing-v4-8-7f5730570a52@kernel.org> References: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> In-Reply-To: <20250730-nfsd-testing-v4-0-7f5730570a52@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6819; i=jlayton@kernel.org; h=from:subject:message-id; bh=ISrKgET4NpOpfmn2MuleOE6e3bVTq1FJQoGUMNqYgbE=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBoih0og1N698dK6ZFCVZt672W1JKoOllLpqXl1V +AgdaXj79OJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaIodKAAKCRAADmhBGVaC Fbx3D/0VyweYADN22GxHgVNSPqY+dlvRP3/doTFl7Eyd88Yz+DDqX9pU4Uj2MgW5C/OzRL7A+2r GyGVIMZeFvo90iXmU26vVN782zXyD7TclC3rHV3i5aIlcHOQ6nJGkZFuTPkIcXOIo3kP0bFB712 /3G8XkfQVYVKWaPp1jMaBD1r82FzqhVjaFWlN7M4lwDxwM63ccW1DJqyyTKqw/TsdAMSDrn+r4J N5j6/7U6icJiFTBC8mDFD8at9oFeVUA4hJYrs8QTiXmpVhRAoj+u9YdlepWveMl27hBF3zBJJ3x 4o1gle+2hLBgWaVyd0XWUZ9MNNCEDy3crmAow9bnnQtHWPcXqOfQjtP4YXGy68dYf5hEBlcXqdk RZjeyLZVXOYDdP3gI7xhlsnW1/+bk24Cdx/eOVPkRm49Frohhk94VgTQZTq7DoPYxolSUEPSaTe MfCTz6OFZfbtNmQ0ZOUH2tH+zB/nmSTdukl8/k9CE9aJj0U9iK4kLo1ZQzXzsMIjQ+1cuHhl/qI nvcoMgAvZrolivt0yW2eyIS9z2LAQ9GdjlfuyRMPb7Mut7EiWpoe4grUgXZ2GMKzNSPTx4V3K++ VOQa0t17+PzxID9GcndbZ0SoIEtaEOsVdOQlR2G7FJaaj/EiwnSEULaPQwVD9mN+T7Nr9ZRt0rX xCn6atRaeK/v3Fw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Instead of allowing the ctime to roll backward with a WRITE_ATTRS delegation, set FMODE_NOCMTIME on the file and have it skip mtime and ctime updates. It is possible that the client will never send a SETATTR to set the times before returning the delegation. Add two new bools to struct nfs4_delegation: dl_written: tracks whether the file has been written since the delegation was granted. This is set in the WRITE and LAYOUTCOMMIT handlers. dl_setattr: tracks whether the client has sent at least one valid mtime that can also update the ctime in a SETATTR. When unlocking the lease for the delegation, clear FMODE_NOCMTIME. If the file has been written, but no setattr for the delegated mtime and ctime has been done, update the timestamps to current_time(). Suggested-by: NeilBrown Signed-off-by: Jeff Layton --- fs/nfsd/nfs4proc.c | 26 ++++++++++++++++++++++++-- fs/nfsd/nfs4state.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/state.h | 4 +++- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index aacd912a5fbe29ba5ccac206d13243308f36b7fa..bfebe6e25638a76d3607bb79a23= 9bdc92e42e7b5 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1151,7 +1151,9 @@ vet_deleg_attrs(struct nfsd4_setattr *setattr, struct= nfs4_delegation *dp) if (setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { if (nfsd4_vet_deleg_time(&iattr->ia_mtime, &dp->dl_mtime, &now)) { iattr->ia_ctime =3D iattr->ia_mtime; - if (!nfsd4_vet_deleg_time(&iattr->ia_ctime, &dp->dl_ctime, &now)) + if (nfsd4_vet_deleg_time(&iattr->ia_ctime, &dp->dl_ctime, &now)) + dp->dl_setattr =3D true; + else iattr->ia_valid &=3D ~(ATTR_CTIME | ATTR_CTIME_SET); } else { iattr->ia_valid &=3D ~(ATTR_CTIME | ATTR_CTIME_SET | @@ -1238,12 +1240,26 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_= compound_state *cstate, return status; } =20 +static void nfsd4_file_mark_deleg_written(struct nfs4_file *fi) +{ + spin_lock(&fi->fi_lock); + if (!list_empty(&fi->fi_delegations)) { + struct nfs4_delegation *dp =3D list_first_entry(&fi->fi_delegations, + struct nfs4_delegation, dl_perfile); + + if (dp->dl_type =3D=3D OPEN_DELEGATE_WRITE_ATTRS_DELEG) + dp->dl_written =3D true; + } + spin_unlock(&fi->fi_lock); +} + static __be32 nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) { struct nfsd4_write *write =3D &u->write; stateid_t *stateid =3D &write->wr_stateid; + struct nfs4_stid *stid =3D NULL; struct nfsd_file *nf =3D NULL; __be32 status =3D nfs_ok; unsigned long cnt; @@ -1256,10 +1272,15 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_co= mpound_state *cstate, trace_nfsd_write_start(rqstp, &cstate->current_fh, write->wr_offset, cnt); status =3D nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, - stateid, WR_STATE, &nf, NULL); + stateid, WR_STATE, &nf, &stid); if (status) return status; =20 + if (stid) { + nfsd4_file_mark_deleg_written(stid->sc_file); + nfs4_put_stid(stid); + } + write->wr_how_written =3D write->wr_stable_how; status =3D nfsd_vfs_write(rqstp, &cstate->current_fh, nf, write->wr_offset, &write->wr_payload, @@ -2550,6 +2571,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp, mutex_unlock(&ls->ls_mutex); =20 nfserr =3D ops->proc_layoutcommit(inode, rqstp, lcp); + nfsd4_file_mark_deleg_written(ls->ls_stid.sc_file); nfs4_put_stid(&ls->ls_stid); out: return nfserr; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 205ee8cc6fa2b9f74d08f7938b323d03bdf8286c..81fa7cc6c77b3cdc5ff22bc60ab= 0654f95dc258d 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1222,6 +1222,42 @@ static void put_deleg_file(struct nfs4_file *fp) nfs4_file_put_access(fp, NFS4_SHARE_ACCESS_READ); } =20 +static void nfsd4_finalize_deleg_timestamps(struct nfs4_delegation *dp, st= ruct file *f) +{ + struct iattr ia =3D { .ia_valid =3D ATTR_ATIME | ATTR_CTIME | ATTR_MTIME = }; + struct inode *inode =3D file_inode(f); + int ret; + + /* don't do anything if FMODE_NOCMTIME isn't set */ + if ((READ_ONCE(f->f_mode) & FMODE_NOCMTIME) =3D=3D 0) + return; + + spin_lock(&f->f_lock); + f->f_mode &=3D ~FMODE_NOCMTIME; + spin_unlock(&f->f_lock); + + /* was it never written? */ + if (!dp->dl_written) + return; + + /* did it get a setattr for the timestamps at some point? */ + if (dp->dl_setattr) + return; + + /* Stamp everything to "now" */ + inode_lock(inode); + ret =3D notify_change(&nop_mnt_idmap, f->f_path.dentry, &ia, NULL); + inode_unlock(inode); + if (ret) { + struct inode *inode =3D file_inode(f); + + pr_notice_ratelimited("Unable to update timestamps on inode %02x:%02x:%l= u: %d\n", + MAJOR(inode->i_sb->s_dev), + MINOR(inode->i_sb->s_dev), + inode->i_ino, ret); + } +} + static void nfs4_unlock_deleg_lease(struct nfs4_delegation *dp) { struct nfs4_file *fp =3D dp->dl_stid.sc_file; @@ -1229,6 +1265,7 @@ static void nfs4_unlock_deleg_lease(struct nfs4_deleg= ation *dp) =20 WARN_ON_ONCE(!fp->fi_delegees); =20 + nfsd4_finalize_deleg_timestamps(dp, nf->nf_file); kernel_setlease(nf->nf_file, F_UNLCK, NULL, (void **)&dp); put_deleg_file(fp); } @@ -6265,6 +6302,8 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct n= fsd4_open *open, memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl= _stid.sc_stateid)); =20 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { + struct file *f =3D dp->dl_stid.sc_file->fi_deleg_file->nf_file; + if (!nfsd4_add_rdaccess_to_wrdeleg(rqstp, open, fh, stp) || !nfs4_delegation_stat(dp, currentfh, &stat)) { nfs4_put_stid(&dp->dl_stid); @@ -6278,6 +6317,9 @@ nfs4_open_delegation(struct svc_rqst *rqstp, struct n= fsd4_open *open, dp->dl_atime =3D stat.atime; dp->dl_ctime =3D stat.ctime; dp->dl_mtime =3D stat.mtime; + spin_lock(&f->f_lock); + f->f_mode |=3D FMODE_NOCMTIME; + spin_unlock(&f->f_lock); trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); } else { open->op_delegate_type =3D deleg_ts && nfs4_delegation_stat(dp, currentf= h, &stat) ? diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index bf9436cdb93c5dd5502ecf83433ea311e3678711..b6ac0f37e9cdfcfddde5861c8c0= c51bad60101b7 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -217,10 +217,12 @@ struct nfs4_delegation { struct nfs4_clnt_odstate *dl_clnt_odstate; time64_t dl_time; u32 dl_type; -/* For recall: */ + /* For recall: */ int dl_retries; struct nfsd4_callback dl_recall; bool dl_recalled; + bool dl_written; + bool dl_setattr; =20 /* for CB_GETATTR */ struct nfs4_cb_fattr dl_cb_fattr; --=20 2.50.1