From patchwork Thu Sep 5 12:41:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792273 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 59B4619D880; Thu, 5 Sep 2024 12:42: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=1725540121; cv=none; b=TUvX+y2hgQ3z4njAgOdCFzRIDAxrz4Io1m3G/nAVgxaeggCgA4+pLzBviJ/0G9q7ZEhDdqHtNOZsDh4/kDvlya2ikwM82v5mUW2jgTurjfCl5f/G5sIPIBBdAonzeVp9bFKyCEKDGKgyntGsJHPU3nosOeBAl3362/D2noYQ/E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540121; c=relaxed/simple; bh=lo5fg8EfTLkVA9DYVM0X/8i1HjBrQtIclBbgHsn2k30=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=up945z83ueGEs7rM9wTQASWEyNExEBebNiG/bv2hS/uqX9qVZ4Ln4W0tMh1KhP43GuB7UZigFjbX9NdIu2sCTsc3c6Fk3wTmwy9Px6Tki4STnE8AaVcAKkAVAzhfU0e1EfqufiWA9HFyVPD2CJYqoqJyV+wlfDFc65YDuU37LIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FTYGGTAx; 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="FTYGGTAx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6303C4CECB; Thu, 5 Sep 2024 12:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540121; bh=lo5fg8EfTLkVA9DYVM0X/8i1HjBrQtIclBbgHsn2k30=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FTYGGTAxoHoCPEIC3ePPUEzzHO2Uz46fygxHTjufpZC1lLgdvmbf8OsOmkYYsYHGQ F0ny3dBRAgrPyCCfWXrwNPX3Gt0Suz4GuKvdkaDzfBy0t9L0whhhuQ8n9AGDDERiGw 9BO/AuXnJq8+5p02v8KAei3jw67B/TpkkV1L+Sr904eIFIWwNeXjyspSSkB0YBdZZE dL8dTuhlMmjqWf7nmy3j/iiasOhZxbXEy5n7LnjcRQOtr4wtKO73on5gZUnoas77fK 4U7ovlW9vauRquFbIIUC7orLMu9U/wtNPXQfiu/KLb0KrdRLBGxXwaUT5/JYC1MDtz uv0D+wJnyTomg== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:45 -0400 Subject: [PATCH v4 01/11] nfsd: fix initial getattr on write delegation Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-1-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2631; i=jlayton@kernel.org; h=from:subject:message-id; bh=lo5fg8EfTLkVA9DYVM0X/8i1HjBrQtIclBbgHsn2k30=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acUUInFhjUD9KJZQi9BTLZT2glTH01mvschh E0kto7gztiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFAAKCRAADmhBGVaC Fb94D/9bRFaO0c1Pv0U2QXAo1IrMLijhH3a4gFrX2/7fILEoXRqSCp5u00vJs02OjB7pQlWENpC zB2a1yr/nSuxqgZn4hazwnliWMsFAq7butwQSha7iTO526Za6gvWsdTPHwltBD+v5Z8EL1oAG2o 7eKHOu6GsaKMrghUpnu9QWaMAsXfjQyvz2ghIHbI8YcHG/KAkPuD0PMHQb+Mf9xL3zi3VQr0XnY bvrqMa4q23E9V8gtMxyQsQSYpltEvV41h1S/p96bv13zGV+mspbf70Z4h/8ERh5DbJpb/jOagIW n1kZLtiwfEIQ5FAItYNdmjGi9Wbw88uiwr1SAbcXRMhQk8cO3fTEWcGnAWps4Z10+gUM4vy4fUq Ne1YFrodG0ksrSt2wX0vaLk11FHy429m7yP67YTAsgBwlqVS8mj/51uAy8s9KKbBtbv7Ff5JC04 ugu7N24+X3RHcTujJKYJjnrQYJZc+9gutCFW57cGD5ztSApL2H4yx8ESly4QataTAnpNWLnpTEn /FwKVmnRES3JrzBqNOzR6uwoqerm/fZjq3sbBGjdmS41j48HESbXnH62K0PVPBS0EsO+QjoSlST oP/8q8w+Vh9ggcOxJ1r4/LCTFFztljl8wU2k0mdm3MGFad1+TtO2MJqnN0B1VJvVXjBYcnGWH1l 5+2wtdja4lT5/rg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 At this point in compound processing, currentfh refers to the parent of the file, not the file itself. Get the correct dentry from the delegation stateid instead. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index df69dc6af467..db90677fc016 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5914,6 +5914,26 @@ static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status) } } +static bool +nfs4_delegation_stat(struct nfs4_delegation *dp, struct svc_fh *currentfh, + struct kstat *stat) +{ + struct nfsd_file *nf = find_rw_file(dp->dl_stid.sc_file); + struct path path; + + if (!nf) + return false; + + path.mnt = currentfh->fh_export->ex_path.mnt; + path.dentry = file_dentry(nf->nf_file); + + if (vfs_getattr(&path, stat, + (STATX_INO | STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE), + AT_STATX_SYNC_AS_STAT)) + return false; + return true; +} + /* * The Linux NFS server does not offer write delegations to NFSv4.0 * clients in order to avoid conflicts between write delegations and @@ -5949,7 +5969,6 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, int cb_up; int status = 0; struct kstat stat; - struct path path; cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); open->op_recall = false; @@ -5985,20 +6004,16 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { - open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; - trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); - path.mnt = currentfh->fh_export->ex_path.mnt; - path.dentry = currentfh->fh_dentry; - if (vfs_getattr(&path, &stat, - (STATX_SIZE | STATX_CTIME | STATX_CHANGE_COOKIE), - AT_STATX_SYNC_AS_STAT)) { + if (!nfs4_delegation_stat(dp, currentfh, &stat)) { nfs4_put_stid(&dp->dl_stid); destroy_delegation(dp); goto out_no_deleg; } + open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; dp->dl_cb_fattr.ncf_cur_fsize = stat.size; dp->dl_cb_fattr.ncf_initial_cinfo = nfsd4_change_attribute(&stat, d_inode(currentfh->fh_dentry)); + trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); } else { open->op_delegate_type = NFS4_OPEN_DELEGATE_READ; trace_nfsd_deleg_read(&dp->dl_stid.sc_stateid); From patchwork Thu Sep 5 12:41:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792274 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 D9FD919DF44; Thu, 5 Sep 2024 12:42:02 +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=1725540123; cv=none; b=HdkjcnsS7KICi+wP27uSIYWC2O4jzbQ8RwzomxbSkzLoB4/9KB1rilQ7nP7+DJEqCzmxvUOs8Tir0S5zBDjJneorVdE+d89i+1pYw50dpU+VtLPhgL6g2BX37G4d4YDgfK6/jKsskuFhvcEHzhM16X8aLXtW/S0Swrei6kMfIgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540123; c=relaxed/simple; bh=FIK3Y9tz3cbUOr5XRDm+FIEfZDaJjjFX1ey7q2aWYXk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A6a9UdrlKknTRvteA/E6C6PCcHPqVZnJA8vLmcutMaGHwMhkmrVFdd6NS1r/1GCIBmwWYdVfxaKxiexcRxb2M3fRPbaZWPpVR7qWqltVk7/welfhje5O4HRbofwbtkiieUDgGpMdx/dsjNN+G93xFjuFGk0wZdyS6NkL6LfJ5UM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gA3kSe1j; 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="gA3kSe1j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35954C4CEC7; Thu, 5 Sep 2024 12:42:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540122; bh=FIK3Y9tz3cbUOr5XRDm+FIEfZDaJjjFX1ey7q2aWYXk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gA3kSe1j0pt31UDYanRbPJzP3ebO8VOevTMt5twagYrKZiklthI4ZDUsqdKnK8zmm 3kUE9q2PBzwZZ28yHBgjoWihaIPVXihQHL6gZCB0rxlUnUky9xN2Auz2Aj+APEXbvQ G9tlHk76OQmnkOHrKNWwHX7dFJqZcxiVz181cVdjywvF/agRt68lTolpji4qDc9nwY w5DN0qWuol6bzirNmlvrHAIyUg1pE1nB1NQI7nzNBbXMvUKjBR05Vaa/n1+JS03mMa vpADLlKnRjGCOh4QmMwFVuJYgzKzMZV1bWHoGyxF6+pyJYq5PZHQAN62UyCJjJxPNb nvHnYQt1AI7Eg== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:46 -0400 Subject: [PATCH v4 02/11] nfsd: drop the ncf_cb_bmap field Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-2-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2063; i=jlayton@kernel.org; h=from:subject:message-id; bh=FIK3Y9tz3cbUOr5XRDm+FIEfZDaJjjFX1ey7q2aWYXk=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acU5X6KnGyeUbgw3A4LruEEwVtbGTv2j0E4W ZigCUmbM/uJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFAAKCRAADmhBGVaC FUYjD/9L4iwJ5Z12YrPWTlFpTaQqyKGu3YB2aeKzk+/R6CRzrbaOx1OToZdCVaS6Ltcm4rd84gR b8VpPBLnEJCGlXAJ0m5CwB2rGtodHcC3nulHI6GF5Hci4gGL04taqMqfDiS7dNBjHM09rdJh+ti jrNJNAY/FHBfZZHbSXY0dAisBtUrSHoTt6TowXmue8ZdrWosjpKj8+PoS5nJu7Xkj1IBHHMfqBp cw6rBt1dxeMkqG2PNYMc5XzQyIGM7SOHjHka1c1NVl6g8g72ljN2rV3FaElNb3DOlfhpic+pKjd PrWQDo3JB3MsedlEQChwRNkNfl7ljN/sFYo0L0OdQ5QA2AXMj8XiU5UbXvfYd6mNLR6c4VcgWI/ mxf+hdh3BknILBWgsT8hoIZdyROLvtRJZp4VHIOEuKW3wsJPd+qdL4twDn8ZFu/IXo6EEGpE/5l QUmbs6z7Mv70IIcVuQn9FrY/CUqzxUvMMuXYt72goTWXyk5ew4iAKSCaucq4/o44s3HQUfGPQPt LJbFo6NgOqM2pcurSsuEftMa0kwygJYvjyEh2BO7jwXd7XkcFEcfNnCRrIJrM6dhdo3H/4TNBJd y3VgHLgWbCTw2JvqM/GXkwD8g/H/mT0NHLAE4+gYBYxH5/kz+juBjt36MuCYMKDpwLVUXVo2nrW SbfwRYXpy2+KHEQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 This is always the same value, and in a later patch we're going to need to set bits in WORD2. We can simplify this code and save a little space in the delegation too. Just hardcode the bitmap in the callback encode function. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4callback.c | 5 ++++- fs/nfsd/nfs4state.c | 1 - fs/nfsd/state.h | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index b5b3ab9d719a..0c49e31d4350 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -364,10 +364,13 @@ encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr, struct nfs4_delegation *dp = container_of(fattr, struct nfs4_delegation, dl_cb_fattr); struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle; + u32 bmap[1]; + + bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE; encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR); encode_nfs_fh4(xdr, fh); - encode_bitmap4(xdr, fattr->ncf_cb_bmap, ARRAY_SIZE(fattr->ncf_cb_bmap)); + encode_bitmap4(xdr, bmap, ARRAY_SIZE(bmap)); hdr->nops++; } diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index db90677fc016..63b7d271cc4a 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1183,7 +1183,6 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_file *fp, nfsd4_init_cb(&dp->dl_cb_fattr.ncf_getattr, dp->dl_stid.sc_client, &nfsd4_cb_getattr_ops, NFSPROC4_CLNT_CB_GETATTR); dp->dl_cb_fattr.ncf_file_modified = false; - dp->dl_cb_fattr.ncf_cb_bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE; get_nfs4_file(fp); dp->dl_stid.sc_file = fp; return dp; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 79c743c01a47..ac3a29224806 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -138,7 +138,6 @@ struct nfs4_cpntf_state { struct nfs4_cb_fattr { struct nfsd4_callback ncf_getattr; u32 ncf_cb_status; - u32 ncf_cb_bmap[1]; /* from CB_GETATTR reply */ u64 ncf_cb_change; From patchwork Thu Sep 5 12:41:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792275 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 5A89C19DF9C; Thu, 5 Sep 2024 12:42: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=1725540124; cv=none; b=i2cLRMcaZD34aX1WKcrZmqP9h2p23sGcw4ClcYWO2rpKvPhngjgvB5Kp/BM9Qc2PpXOfvd+hsBYOW6YjJwRP8zJh0IcEJ2YSFHyYqShuB8n8dHKF0duAqLgX0agQNvst9L2zjUK7OVg3RGJNJEF4gA1D8IgMg7CEtQexmE1caOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540124; c=relaxed/simple; bh=ja6J3Vp2ddc2U55EFScY1qPB5F48NlxqKvOZsuJ5COo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jd7dox81d22SpKgW7aSVBOutf0JqdR9Ky1iXADtneDSJiF93VBox/N/pN4B1i+KXY2mUBy7ndXKjxuIPZz2uvuyIneLD0AdFGnNJrQ7Zg9npn1GH81qU1qkIcwKkzdXiAB/MqDmcy8/z8pYQuoL/KFbqMVPMazRoxh49w3FSYbE= 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/Tkv9kc; 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/Tkv9kc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADD37C4CECD; Thu, 5 Sep 2024 12:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540123; bh=ja6J3Vp2ddc2U55EFScY1qPB5F48NlxqKvOZsuJ5COo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m/Tkv9kcwtJEZujm2rhrRQiLWllVZGGUraTDPZ/OwMRXLPbt5gPuN2Vv9YNu42xuG fD5d3tQmITk7lpBNP7ewL5Dyfq7F7tIMHwR2c2/fqMF7B9VjxN5u9o0CF2ykFXjWfq UryLX+lGsAZVQlS8mppDhHpmhuDvCV7DW/ocvD9TOkcb0eEpDAHt7lf86H2rRh6uRW enoDNLdA4cNGW4ilbjsaGXN6WoN+9pKRk0ThsM0MVj1kIVbz7cFOXszS4xEwTuKf/J qUIQotcA8V322Kvy2Bry8jCl/qfPc03U2PHPSr7voPfVheB9NdaJjlcrqpHj9YSynI v/+7RieiF314A== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:47 -0400 Subject: [PATCH v4 03/11] nfsd: don't request change attr in CB_GETATTR once file is modified Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-3-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1238; i=jlayton@kernel.org; h=from:subject:message-id; bh=ja6J3Vp2ddc2U55EFScY1qPB5F48NlxqKvOZsuJ5COo=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acUXKobUDSBcwL+WPraGoU5+tL78vkkaCHuO /i5FOT5UQyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFAAKCRAADmhBGVaC FUi4D/4/jIn9fln3SGA9SKRabVZf9GATgB+hqUjlnPHDHsiAAk+qs0WqWqW2evnnB0ws71IC21/ VyBrm77gXAtnWZ17kFbmZpDTOfsqyS8gepbHGhAt4JvgJO/cVH/2ODeomL/EamlquVtoOFjwy6d OE3PayROPVAtFtJdoJKZQGSPcJatEFoHtwdb0GlgqIp8wYTF/YdIwv9wW/DapjfeLrWa0OERd6r 9iwgv+6fsSgFUIGhqFAzl7yB1VL+IZx5PHMiFCbgbgEwOSZB0lMFlABR4DLi3peb1Pzih98mIBA O7j4gPas7LBCNq8kvERuxYuIIYqNA4loz4YQB2yyQ9+oIqovhwOcLtVEZ7TD/GAPRvpcKlE0+oI r1dqpUKs+0PMSb05pz5tyl8Pu8OwVSw7ptTflew7SlbY4dr4qx2iDyReSFPXEIXMY+2areRCwiD Gh3LxULEyeKsRVbruh3B53X+4hYl8cxsaZ8guP5aHJbO0F6VuFGgRmzs7hgZHu/iUM9N4LVnAg7 9sk7rLqjg5/5tDomIuNH6hYJs0793INH/lm1NQzPdfIfISkmSyoNKpBV45aBCJIB20vcsx92HP1 tSK3l16fSF7fTfHJ/8HSP5Kdb8TVtiKxHvJpSfCAWPfd46xmpMVv3EJqG5/molJcPDbGYJOWdiM SD8Oc6vfaUnOiRA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 RFC8881, section 10.4.3 explains that states that once the server recognizes that the file has been modified on the client, it needn't request the change attribute. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4callback.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 0c49e31d4350..f88d4cfe9b38 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -361,13 +361,14 @@ static void encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr, struct nfs4_cb_fattr *fattr) { - struct nfs4_delegation *dp = - container_of(fattr, struct nfs4_delegation, dl_cb_fattr); + struct nfs4_delegation *dp = container_of(fattr, struct nfs4_delegation, dl_cb_fattr); struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle; + struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; u32 bmap[1]; - bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE; - + bmap[0] = FATTR4_WORD0_SIZE; + if (!ncf->ncf_file_modified) + bmap[0] |= FATTR4_WORD0_CHANGE; encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR); encode_nfs_fh4(xdr, fh); encode_bitmap4(xdr, bmap, ARRAY_SIZE(bmap)); From patchwork Thu Sep 5 12:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792276 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 C4D5D19E7FB; Thu, 5 Sep 2024 12:42:05 +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=1725540125; cv=none; b=k5kdV8xL5NABx3b///tC1/Sj26ZtQgq9vTJ4qZrBW54W/TkGAjqTj28poLpiJJCplNQODqVSG6YqiwKzMNVGAAlHQCvkvKHqanyIv+/hVQTRxKewIHC0VkH1SWs//u2TLCc1zaOQw7J3NWIM142v4RCr/qtlNkXLm37gsP+gO04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540125; c=relaxed/simple; bh=MaWMQrP354gSUdJLpaSky0LlkGF4b0/cV4bjc3uboH8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sDByds+QGwsWRyYZNfoCKtvylj12mImVQpEQKq7kcLUsV8V/f5VKD/A0q++hIecuF+hAaMA+Rj70DHIoahogEVA3HR5kMZzo9ocoyXiIwoe1M/R6byuyodbot4aAoAoFWro1iSPbUk155DRZH6cpo3q9d2aYHAIGjp2mHk3w34A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KyNI13fX; 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="KyNI13fX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 300E2C4CEC4; Thu, 5 Sep 2024 12:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540125; bh=MaWMQrP354gSUdJLpaSky0LlkGF4b0/cV4bjc3uboH8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KyNI13fXQtjZCPWWXW0Qzk8et/zqgQzb1i4z9IiQBmL6v0zaClOH9hDho/zFnNbHA 9w2r3IMMk0E4YRnIU3jJOuz69Wdw8Z8YjcCLfxXAuwLTUOwxiioDE4VMxVD4wamfcY BaI8zL9Dy+X7T8QOr8JE5Mo1Nq90GuRsDI/iNPqUeucRAhkVwQB9l78GozlIG4BZvV 6uJLCZuAXnDJGMG+ewzhqxGI6HQAnPhNc19Jsk2AkMnjn1Pv0crl9XIAG9U6pK1joE Y4lsY3nwl1wIKOEO1MrwdA2YZlxdF/dRJ+Fx+7cLSr7hlcyK3j+x+N4tec9OVcAaLn ElvfT+IpdsC3g== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:48 -0400 Subject: [PATCH v4 04/11] nfsd: drop the nfsd4_fattr_args "size" field Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-4-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1658; i=jlayton@kernel.org; h=from:subject:message-id; bh=MaWMQrP354gSUdJLpaSky0LlkGF4b0/cV4bjc3uboH8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acVCIMIGyjM1zCDK0UPnLYIyF2MWfBgDvecQ bjMCSfrVUiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FQufD/9gL87HUtvYMDq9H4u2zqnZH6zh3XyMFxQEd3up5FlE7V2pESURes+l8sb6x+KDK0o/Q1i qWzOLAowRbb+lYGQSaQvXkNEOmKFZH25nrSJax1iEuKaWV7vmVmlwCgCqSZhSOpry8tnYKnLYuX S56o5kqCHRJZV0D/UTdEl1nEicavWn8Ix1LujEL95vKVGD0hvilWRiQ2iNmvqD5ouaZoEzWHXmd B94hI69jd7Uo5EBmF5gNey9/0ARVfFAfmEEbCD6QfaED37MBookHIG7ZAHE5C8lru3S7Pa3+YcK Oxqdu4jzUIj7b4f1vm63vEr9hZZLd2hvqNLzbX19pdIi9HzMvv6gcWA6cPGmRNAIKFYbnS4i3lh d/DMpRKPBwg+XgjKMarspZ4BzW6g+axKnTfg6Sqocc0k91/2MydHXBrLB0VC8wbxxLUhqMgS6dm 7Ag1qkUrdY6sJoi4jiBhtFzw8EZsbEwuihoLsEUcorH1F+mjHE8VfoBjzxARhKRb4LfN/8sr7w3 6UMJdY7gN4u7vyLRWsI/DYoWBrkXWUu6B0QDPilGiNG6Kw0doV9Zk1PtY8WR2FdXIfnsxgb5BW2 /QFQ5RVnNFiQz1cUOXJsjmnvucWmC9/GBvio11amLPzbkCWweQx/ZqbUYjvi4h9lWT7edrxug/m HziWpV9txlentHg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 We already have a slot for this in the kstat structure. Just overwrite that instead of keeping a copy. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4xdr.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index f118921250c3..d028daf77549 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2928,7 +2928,6 @@ struct nfsd4_fattr_args { struct kstat stat; struct kstatfs statfs; struct nfs4_acl *acl; - u64 size; #ifdef CONFIG_NFSD_V4_SECURITY_LABEL void *context; int contextlen; @@ -3047,7 +3046,7 @@ static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr, static __be32 nfsd4_encode_fattr4_size(struct xdr_stream *xdr, const struct nfsd4_fattr_args *args) { - return nfsd4_encode_uint64_t(xdr, args->size); + return nfsd4_encode_uint64_t(xdr, args->stat.size); } static __be32 nfsd4_encode_fattr4_fsid(struct xdr_stream *xdr, @@ -3555,7 +3554,6 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (status) goto out; } - args.size = 0; if (attrmask[0] & (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE)) { status = nfsd4_deleg_getattr_conflict(rqstp, dentry, &file_modified, &size); @@ -3569,9 +3567,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (err) goto out_nfserr; if (file_modified) - args.size = size; - else - args.size = args.stat.size; + args.stat.size = size; if (!(args.stat.result_mask & STATX_BTIME)) /* underlying FS does not offer btime so we can't share it */ From patchwork Thu Sep 5 12:41:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792277 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 0901019EEC2; Thu, 5 Sep 2024 12:42: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=1725540127; cv=none; b=FKldkn2WWqv9vBMShg8vYlGRC4dlRidjU6ji8LTHE/vf0uRo3GrUki+gD+TzNvedAr8tqdgKEXNkjtMpWgrOcdCq4GDhzVI4GpFaQko0IQdWsCL12LZpXH5LXRwWu28k/33upcNvmPztDTnaSoBWerdoOG7VOu3DxRwbLzZonCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540127; c=relaxed/simple; bh=/O5QB/qKD1kg5ilzN/rliLPoIbBIkPfWn/BsccJGI4o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bkq1yaSgNv7noo3CCTiTr1lpyGHzzqUIUPJ9Sm0vIYDfZtqzYbrV4xnqHLzZ3ZVF3mfpSyJYi+qSgADd6hQ3AqxTd1xdNP40Aa/NDQBfLbDyzgoC2ANody1MO7K9YUFvb3vuZcnkVx8KosR+YwHsy5NoHlpyGmip9Kt/CrNsucM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mhyvkmqn; 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="Mhyvkmqn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5680C4CECB; Thu, 5 Sep 2024 12:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540126; bh=/O5QB/qKD1kg5ilzN/rliLPoIbBIkPfWn/BsccJGI4o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Mhyvkmqn7Glxo9KX63xv8iKn0A0j6VodC1Zmvrha8D8EhAsYAX43/jVguI87NIqQR ZZU3jADDb8WyFKHkwTuYN/Iwj/BHiU+b7n8tu1KAEhjHUaReKNA0DNOLuoDcbuF+Ta 8ocDlDbaeDrEVZ3ije5Q0Vs1lK1dPOg2LmujOqxJufT10AbgyEITC2GYp0ynBm4ebl oo+1gxTPa8tSx+J9NshNhE6eOodo4oKYRSE5AuvicuCzkXNksN3zMY1KT6eFuvebEc xEKs5ly+PVPIMYLvIjKggGUfUW8SenGWwXVtbXm2iohmknH2ALOgsWhAVeWcDjR3Iy 8IBhPu3Sr2tFA== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:49 -0400 Subject: [PATCH v4 05/11] nfsd: have nfsd4_deleg_getattr_conflict pass back write deleg pointer Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-5-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4705; i=jlayton@kernel.org; h=from:subject:message-id; bh=/O5QB/qKD1kg5ilzN/rliLPoIbBIkPfWn/BsccJGI4o=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acV/irklEo/q5s+mOVAr99WpMXX08w49oWDO hMr3iKXLl+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FXwGD/48hcUQ3Uz1yXQDX/x+plH0OttYpdm/7Oq/Wqb40r1GlSrSNUPrY2x4fxWzpiOZP8EZ8qb gBxt+ESXPEAT7kE7vMSRFDSXiYq3Asaz6RB4yDPQv9uwFxX0QIgR2ofcGqKCxfkgmGMhObVcg7A uaDtjdR4NDn4rBpXBOibU212tAimZe+ymMgwiKHhuT5RQG1P640GDAGHO6fdd0cSqXVf7i3Kz3P sz/SNpcW/0U+brFaNNXeeKEyZGh9OHS6rnp9Nrl6wgOpRbQfjhuq/+e14ioTMemNIPpi/OXOVUq Oz0r/TqR1JazcqNBoIZCh7P1I09nz9Yz20egD3RtdKpGPdqJLuUPjy656od1k3CIEvGu0vSEQo0 7vVShUhokTcYjrmvUddNRFSH1uuE4NLczNRGki9r5h0k5MKSXfwCqfIz4ZIFj2PKscGItBw6lKv ANPmC78JRnZdy8xm4t29x18OvLqmboNNs9MzCFhpDAUxnBgg0r0oH/2es6x2ZoEjKa9lGX71Urx +pmiWFu9Q6uh6n45Aho2SpW1Y5ZRWrz7OVRfA8lZSJZp6jlChtm5/VRACbLIzAxxUt56RenLCVC bTuSVX5DoT1Z0YV0pVM9uHkzTwNuej9GMZgKliMXfqllsvSWnvpXl1nxRPoINdZWft2/Mvqers8 JqXhQdUq3u7BD0Q== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Currently we pass back the size and whether it has been modified, but those just mirror values tracked inside the delegation. In a later patch, we'll need to get at the timestamps in the delegation too, so just pass back a reference to the write delegation, and use that to properly override values in the iattr. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 17 ++++++++--------- fs/nfsd/nfs4xdr.c | 16 ++++++++++------ fs/nfsd/state.h | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 63b7d271cc4a..8851fc69f5c6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8828,8 +8828,7 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate, * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict * @rqstp: RPC transaction context * @dentry: dentry of inode to be checked for a conflict - * @modified: return true if file was modified - * @size: new size of file if modified is true + * @pdp: returned WRITE delegation, if one was found * * This function is called when there is a conflict between a write * delegation and a change/size GETATTR from another client. The server @@ -8839,11 +8838,12 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate, * 18.7.4. * * Returns 0 if there is no conflict; otherwise an nfs_stat - * code is returned. + * code is returned. If @pdp is set to a non-NULL value, then the + * caller must put the reference. */ __be32 nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, - bool *modified, u64 *size) + struct nfs4_delegation **pdp) { __be32 status; struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); @@ -8854,10 +8854,9 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, struct nfs4_cb_fattr *ncf; struct inode *inode = d_inode(dentry); - *modified = false; ctx = locks_inode_context(inode); if (!ctx) - return 0; + return nfs_ok; #define NON_NFSD_LEASE ((void *)1) @@ -8923,10 +8922,10 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, goto out_status; } ncf->ncf_cur_fsize = ncf->ncf_cb_fsize; - *size = ncf->ncf_cur_fsize; - *modified = true; + *pdp = dp; + return nfs_ok; } - status = 0; + status = nfs_ok; out_status: nfs4_put_stid(&dp->dl_stid); return status; diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index d028daf77549..ccaee73de72b 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3511,6 +3511,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, int ignore_crossmnt) { DECLARE_BITMAP(attr_bitmap, ARRAY_SIZE(nfsd4_enc_fattr4_encode_ops)); + struct nfs4_delegation *dp = NULL; struct nfsd4_fattr_args args; struct svc_fh *tempfh = NULL; int starting_len = xdr->buf->len; @@ -3525,8 +3526,6 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, .dentry = dentry, }; unsigned long bit; - bool file_modified = false; - u64 size = 0; WARN_ON_ONCE(bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1); WARN_ON_ONCE(!nfsd_attrs_supported(minorversion, bmval)); @@ -3555,8 +3554,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, goto out; } if (attrmask[0] & (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE)) { - status = nfsd4_deleg_getattr_conflict(rqstp, dentry, - &file_modified, &size); + status = nfsd4_deleg_getattr_conflict(rqstp, dentry, &dp); if (status) goto out; } @@ -3564,10 +3562,16 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, err = vfs_getattr(&path, &args.stat, STATX_BASIC_STATS | STATX_BTIME | STATX_CHANGE_COOKIE, AT_STATX_SYNC_AS_STAT); + if (dp) { + struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; + + if (ncf->ncf_file_modified) + args.stat.size = ncf->ncf_cur_fsize; + + nfs4_put_stid(&dp->dl_stid); + } if (err) goto out_nfserr; - if (file_modified) - args.stat.size = size; if (!(args.stat.result_mask & STATX_BTIME)) /* underlying FS does not offer btime so we can't share it */ diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index ac3a29224806..c7c7ec21e510 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -781,5 +781,5 @@ static inline bool try_to_expire_client(struct nfs4_client *clp) } extern __be32 nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, - struct dentry *dentry, bool *file_modified, u64 *size); + struct dentry *dentry, struct nfs4_delegation **pdp); #endif /* NFSD4_STATE_H */ From patchwork Thu Sep 5 12:41:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792278 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 C632A19F489; Thu, 5 Sep 2024 12:42:08 +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=1725540128; cv=none; b=PqHOSiOwVfm/AgSDzQsZonm6+YaV1HfUP1XJfx9RHdV/uVeuruerJwn6gIPMmyTDnwvh9RC/uOs4WjOMOt8jWWSJtfTeHhCQqhM8SojnjZSnY5qeP+tmML6Q9/A59rBtdf3UdqVZQ2P4SY6KgLPjzeIStHaAOL6adziOiDTfOeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540128; c=relaxed/simple; bh=Bn9/DidrtPQAS60NFDloJmzniywAlNDr2BLuh/aSHD8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EUOuxwUWs3QK+cps8nhniu5yfQIaQFUuY/3w9RL5lDeorT06sMSkuhr94lFLNrfdmKmtDs+FihP5QXLHnxBdsSFBT4HZUu6ieCDY2AizvOdB7HxDvm1c62qWESZVT8cx7Udhc2G3c4ftmRF1al5G0h2LOdqwMSv0kgi/P+yjiuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XQaWluBO; 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="XQaWluBO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 253E5C4CECA; Thu, 5 Sep 2024 12:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540128; bh=Bn9/DidrtPQAS60NFDloJmzniywAlNDr2BLuh/aSHD8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XQaWluBO3WT8tafHrdk0IhYVzqH8+1lIBhIQphRcOc24kOBaoqilSXn3f7czA+mxG rrQC3K661p+/qCh5VWCfYoizDODC3t9sQEur8RXdBeE1ZI08uTgunfy9QwDf1njKL3 BpQPKYTMT4pFQFDz1TgdZn5EM5ZQBDetcmxSJMlXxEM5nUQ+W6BBYOAfMZ3DEes3kP L+mtqBKrZti5D75H4ZAcr/09C4OHrfugC5XnGINGc3HR21uCI+9ntNxmRVW9hXPUcP zOM6+BT9m8Km/KSDAnzanrdkfcwxGmB4kJFRktIOLqnmv3q7x2v8oWXpIHAVisgNUm P8yk4CuFMtCDw== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:50 -0400 Subject: [PATCH v4 06/11] nfs_common: make include/linux/nfs4.h include generated nfs4.h Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-6-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1639; i=jlayton@kernel.org; h=from:subject:message-id; bh=Bn9/DidrtPQAS60NFDloJmzniywAlNDr2BLuh/aSHD8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acVCzods9TF2abYmLrqcQeLr31NRqxYN+o77 RqckLFdppyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FVH0D/4mJ2IqJBk+7PrujthZrAwN98BP8d/fr8276fs6h3ezY8P68O1vgFpdsqTvpIG4LbtlGwF BmnnB+0qnIcBipVByhx3dHdxQMHIl8Jy3Qh+4qTdChpmGh0LxNCFRkKA/LPCJ/Rd9L4QIHvn/zA A51kHUwjgR/im6/N54/m+6KLp4Q9++PF8IW0P0UwaAMU7Mt3Tb5UJ4OeH6pDRrTzYqU9GM0B6k/ J6VvmONBUjUstADtyywNIb/SDWzglQFe7Z1ciEfhy1+wh+lk/c8uJn00BHVpn6IjkiyzBam9UPf v+OFa21mv8mkizk4grcL4NmkQFUdsp9FpjtscLW/4HNxMRk+0tPpwi5Ftt/0ej1OvLSfqRY3iCd 0f5VwTE62VO3Fd67hMIfUfVj48yMPFXTzcXEYau6flaspWII9bRrAndlNcxJopYaCjqnPLqVTde Y7THVbSUaQC8kyuCJ7XX4jXAfcoZ6I8RRfPIFbZDxheYmhI/I1sC3Baa7wjfz/wiIIHYFqvCglc mJbeanLSByZkabxtSeS6jXlFQjo1Rr3v7yazYZMtqqav8kn/C5O9w7cuBKDgwr4wRM4QmnXiOe/ SF9jjqJPE/ll75VpF8/gTMdsxPVLKInj6hudLeJrxAM+0lCoXtSZkcCnTjYDwyY15ykNFVt48R5 Bc8Za8CkIynNkSw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Long term, we'd like to move to autogenerating a lot of our XDR code. Both the client and server include include/linux/nfs4.h. That file is hand-rolled, and some of the symbols in it conflict with the autogenerated symbols from xdrgen. Have include/linux/nfs4.h include the generated include/linux/sunrpc/xdrgen/nfs4.h and remove the conflicting definitions from it and nfs_xdr.h. Signed-off-by: Jeff Layton --- include/linux/nfs4.h | 7 +------ include/linux/nfs_xdr.h | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 8d7430d9f218..87454d5d3365 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -17,6 +17,7 @@ #include #include #include +#include enum nfs4_acl_whotype { NFS4_ACL_WHO_NAMED = 0, @@ -512,12 +513,6 @@ enum { FATTR4_XATTR_SUPPORT = 82, }; -enum { - FATTR4_TIME_DELEG_ACCESS = 84, - FATTR4_TIME_DELEG_MODIFY = 85, - FATTR4_OPEN_ARGUMENTS = 86, -}; - /* * The following internal definitions enable processing the above * attribute bits within 32-bit word boundaries. diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index 45623af3e7b8..d3fe47baf110 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1315,11 +1315,6 @@ struct nfs4_fsid_present_res { #endif /* CONFIG_NFS_V4 */ -struct nfstime4 { - u64 seconds; - u32 nseconds; -}; - #ifdef CONFIG_NFS_V4_1 struct pnfs_commit_bucket { From patchwork Thu Sep 5 12:41:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792279 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 37DF919FA9F; Thu, 5 Sep 2024 12:42: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=1725540130; cv=none; b=RwFHmco8QP1qbDNz+vKrtntaeJwF7CmgUsyd0JlOdm+arkanjuE8zZPSBTaMBa6ppQO7ESht/RF/MmDNk1rhJPGRgoDmKd5dyxOdMPrzx6mpT3UMRT/xqdKxg6WNVFM6lW90fx3+3XATowXhb3+IifwsfajsoIWL/vHobPmxev0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540130; c=relaxed/simple; bh=kpELDEFTy1D47hjM4/MCx13/I9LcpRbQfLN1rgDDfE4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EZPQ0EnTz/XTsU3Nn4YmEvbE3Qf9d8VjJBEk7rb2isFO/Rd244l6XpSr8S/EMvQnWqgNh7F+ZVl3PIOwpiBgk1LvE5AmerF3wsqHgalOo5DGYa3GPYL6qSg1PhIu3kjcJ/1JE5cleu8zHWMcnObh+i9IWURv8z3erPBn/coz7u8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V5xtVzfO; 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="V5xtVzfO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B216C4CEC4; Thu, 5 Sep 2024 12:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540129; bh=kpELDEFTy1D47hjM4/MCx13/I9LcpRbQfLN1rgDDfE4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=V5xtVzfOiGstIKXw75qVH8BC/K5IgzAayMdl++LRYYWI4A5W9oWF97tQGY/NWoBez xrXyV0J9yFxtAOiboLsVadGMPDpKYyeNfXX8SaA78jEkL8T6nLEZzRVNekvTaZbBZt lwLu36RmoqZ1PBP2DghBdjUhFgl8VGfgDiNtYmnE97Yvm8ObQYRyEzUC/Py4ON8noA 33aP1+qeRJdqipKCNChtWsRVBbFIo5AZ7YIfl5CNyXJiejzoDggYd6UueQSuQ7od7K mEb4XOgvql5Nef27szm21i8btCuO5BNSPA6NEPLrZHrI/rhLMRAPpGdxJDvprBfL+6 xQ4VkWNvlLdAg== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:51 -0400 Subject: [PATCH v4 07/11] nfsd: add support for FATTR4_OPEN_ARGUMENTS Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-7-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4392; i=jlayton@kernel.org; h=from:subject:message-id; bh=kpELDEFTy1D47hjM4/MCx13/I9LcpRbQfLN1rgDDfE4=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acVzA7dBQNEEQ6EPQRPXv9CyTkyr5TeH8ZPw AELqv2xxJWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FZvwEACMFBhG5OquAPTxRqrKbsdseRVbYBiXePjrMHSir6Zxsq91W4Ci6xePfLdRkjNGlMAUGx6 f56FCb1MUivjA1AAcBmV3Nu84BJJ2aPlcrodz3tlaOUTqwIPWih7ZUFSWwqu2IRG1FIU8Pu+iK6 dK3b7ZNtTOoF7Zg/UYrrw5ZpzSrucwjN5/mfc/rh9U5uk96lYyCfB17cT8figXblnVCGudem53G 4+VsuIRLKdnBY+X+tFj5rz0KJQ3o5lYBVq4UvP8HrYzKKR5837ay2vh9b/3Mgpkp9+03cgSJmis TDBRCDXiu8HGgJgd6KrBRIZY+jxPlbfutBY2r04wYeX3NNB2rnDdvquQns/E6FQDbRzC2bH3Tsx Tgw1k2yIohpRAUfap7m/53SpK3sxACibB+jNRDqa+ZFY6mOxBkZ9k9KyZYrBTMsoK4ekklTeuLs 1km5jAsKUQJJpThwqg6NQMN6InScyYgjrMK32+26l/upkVIJLqRcXs12Nj63sAguJeZxJ8Ga/4L yKTJuuyVtmx/UtNIfXcLCUOz1j7T1t7ZpB15cxZ3HXJ/3mgovZxsbhn8VzQLwIomozcPGq2x2m7 ob0bMwUqKZ+VkMuOWpxW05Y7kmPaxDGYbQkAwPiArMvIm77DbLSXPdejbUAjJCZ4GRFcPxRg1WG Y7SVbjYT3cEdjPQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add support for FATTR4_OPEN_ARGUMENTS. This a new mechanism for the client to discover what OPEN features the server supports. Signed-off-by: Jeff Layton --- fs/nfsd/Makefile | 2 +- fs/nfsd/nfs4xdr.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfsd.h | 3 ++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/Makefile b/fs/nfsd/Makefile index b8736a82e57c..d6ab3ae7d0a0 100644 --- a/fs/nfsd/Makefile +++ b/fs/nfsd/Makefile @@ -18,7 +18,7 @@ nfsd-$(CONFIG_NFSD_V2) += nfsproc.o nfsxdr.o nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o nfsd-$(CONFIG_NFSD_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4idmap.o \ - nfs4acl.o nfs4callback.o nfs4recover.o + nfs4acl.o nfs4callback.o nfs4recover.o nfs4xdr_gen.o nfsd-$(CONFIG_NFSD_PNFS) += nfs4layouts.o nfsd-$(CONFIG_NFSD_BLOCKLAYOUT) += blocklayout.o blocklayoutxdr.o nfsd-$(CONFIG_NFSD_SCSILAYOUT) += blocklayout.o blocklayoutxdr.o diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index ccaee73de72b..4cedcb252aa1 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -55,6 +55,7 @@ #include "netns.h" #include "pnfs.h" #include "filecache.h" +#include "nfs4xdr_gen.h" #include "trace.h" @@ -3398,6 +3399,54 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr, return nfsd4_encode_bool(xdr, err == 0); } +#define NFSD_OA_SHARE_ACCESS (BIT(OPEN_ARGS_SHARE_ACCESS_READ) | \ + BIT(OPEN_ARGS_SHARE_ACCESS_WRITE) | \ + BIT(OPEN_ARGS_SHARE_ACCESS_BOTH)) + +#define NFSD_OA_SHARE_DENY (BIT(OPEN_ARGS_SHARE_DENY_NONE) | \ + BIT(OPEN_ARGS_SHARE_DENY_READ) | \ + BIT(OPEN_ARGS_SHARE_DENY_WRITE) | \ + BIT(OPEN_ARGS_SHARE_DENY_BOTH)) + +#define NFSD_OA_SHARE_ACCESS_WANT (BIT(OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG) | \ + BIT(OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG) | \ + BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL)) + +#define NFSD_OA_OPEN_CLAIM (BIT(OPEN_ARGS_OPEN_CLAIM_NULL) | \ + BIT(OPEN_ARGS_OPEN_CLAIM_PREVIOUS) | \ + BIT(OPEN_ARGS_OPEN_CLAIM_DELEGATE_CUR) | \ + BIT(OPEN_ARGS_OPEN_CLAIM_DELEGATE_PREV)| \ + BIT(OPEN_ARGS_OPEN_CLAIM_FH) | \ + BIT(OPEN_ARGS_OPEN_CLAIM_DELEG_CUR_FH) | \ + BIT(OPEN_ARGS_OPEN_CLAIM_DELEG_PREV_FH)) + +#define NFSD_OA_CREATE_MODE (BIT(OPEN_ARGS_CREATEMODE_UNCHECKED4) | \ + BIT(OPEN_ARGS_CREATE_MODE_GUARDED) | \ + BIT(OPEN_ARGS_CREATEMODE_EXCLUSIVE4) | \ + BIT(OPEN_ARGS_CREATE_MODE_EXCLUSIVE4_1)) + +static uint32_t oa_share_access = NFSD_OA_SHARE_ACCESS; +static uint32_t oa_share_deny = NFSD_OA_SHARE_DENY; +static uint32_t oa_share_access_want = NFSD_OA_SHARE_ACCESS_WANT; +static uint32_t oa_open_claim = NFSD_OA_OPEN_CLAIM; +static uint32_t oa_create_mode = NFSD_OA_CREATE_MODE; + +static const struct open_arguments4 nfsd_open_arguments = { + .oa_share_access = { .count = 1, .element = &oa_share_access }, + .oa_share_deny = { .count = 1, .element = &oa_share_deny }, + .oa_share_access_want = { .count = 1, .element = &oa_share_access_want }, + .oa_open_claim = { .count = 1, .element = &oa_open_claim }, + .oa_create_mode = { .count = 1, .element = &oa_create_mode }, +}; + +static __be32 nfsd4_encode_fattr4_open_arguments(struct xdr_stream *xdr, + const struct nfsd4_fattr_args *args) +{ + if (!xdrgen_encode_fattr4_open_arguments(xdr, &nfsd_open_arguments)) + return nfserr_resource; + return nfs_ok; +} + static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = { [FATTR4_SUPPORTED_ATTRS] = nfsd4_encode_fattr4_supported_attrs, [FATTR4_TYPE] = nfsd4_encode_fattr4_type, @@ -3498,6 +3547,7 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = { [FATTR4_MODE_UMASK] = nfsd4_encode_fattr4__noop, [FATTR4_XATTR_SUPPORT] = nfsd4_encode_fattr4_xattr_support, + [FATTR4_OPEN_ARGUMENTS] = nfsd4_encode_fattr4_open_arguments, }; /* diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 4ccbf014a2c7..c98fb104ba7d 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -454,7 +454,8 @@ enum { (NFSD4_1_SUPPORTED_ATTRS_WORD2 | \ FATTR4_WORD2_MODE_UMASK | \ NFSD4_2_SECURITY_ATTRS | \ - FATTR4_WORD2_XATTR_SUPPORT) + FATTR4_WORD2_XATTR_SUPPORT | \ + FATTR4_WORD2_OPEN_ARGUMENTS) extern const u32 nfsd_suppattrs[3][3]; From patchwork Thu Sep 5 12:41:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792280 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 723691A01B8; Thu, 5 Sep 2024 12:42:11 +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=1725540131; cv=none; b=AO6ax2MRCRXu8fEFBMwgTBMaXrTuFSnVhf3goB8ga+xwYX9iskImrit6n6GUUz9AvlfJxhpot9O1FoI+e0K6QUn767ou4DuiXr+3sAiuxaqBzMjFjGbHPL9mWQbkr77KVO3qpbFIvqPdyLzBnIuGl5yFwmHKjiNbQX9CRBcPC7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540131; c=relaxed/simple; bh=MxOPfiLDr3waUK1Qzm+p8NQ94i5UzU3rpW+2ExXilF8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LytsNbDBYG0RUMAmtcc/eFbycZRzB5uKtyV20iLC/ZUYvUPsDYuOcSyT2IsLwncRvEZ9Y3GoGdMeHiQEUvBkA6df5+cWFi+bxubROiikmCj8AbML7A7I9kbn7kqu8xSLJZPrDOmLfAhBes3S/wq4FYSBGM79ZYi7xZ/TybX918o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bcJyyKC1; 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="bcJyyKC1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C88EC4CEC3; Thu, 5 Sep 2024 12:42:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540131; bh=MxOPfiLDr3waUK1Qzm+p8NQ94i5UzU3rpW+2ExXilF8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bcJyyKC17cH20bvo3xTK5rLqOsEb+ikyYZk/2aQPYZkiLH8ELq37IIb42+Br8FtcK zZTRf0g2sYPpx49B3MXRtxvfOyJSvfYTwjbio/sYoPA1H5qw8C3taCxNbQoYAzDO0X hAvkIAifuir8TU/sfcZMeWeT1uQ16PUUURN53BA8DLJlMbOuJTdo6Z9bqvnudl4+TB FINDc+Ki2e6TmC2ybFV3/6CegbXUFqSQZUb5frGqHzr5r/1oIw7T49pbR4+dXWhxOj J2JCUJXDJt8nM+T4QK3IkiiI9eUxv63DRnXBq2DUHxxt1ZvpPphaDPPjMWjxdQzsKN AAr4o9o7bFISg== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:52 -0400 Subject: [PATCH v4 08/11] nfsd: implement OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-8-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=5596; i=jlayton@kernel.org; h=from:subject:message-id; bh=MxOPfiLDr3waUK1Qzm+p8NQ94i5UzU3rpW+2ExXilF8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acVsF3KFmSerRwJYZKYFXS+1VmFkJASg1rHi 6uXtNokxLeJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FWxaEACvl/RbPhKbYcEzlFxvODRVPKn8fErUduxQjgFFnTBXV1MSqm22ONNttxoZDXryxw5AFVL IBMdO6OKS7NTdOjxg5hLiujBJKxjJ9yM/mOJkZOBgfhGhkHRjyR6U0b5362cvcLajzNGAORhhuq ZAxk47csBq27hbQentyysUXICE1ax5qRfYRabUINvaNFiSByg+tdOeNpkIqxwjpkGaKYAg1t1Es 4v5wrDM4zGA9QWf/tLnmU2auyXkRdBxgiRQLW/RsQpVryU2fUcYEbdP+5RG1vX7UwuUCydxQvzc QVIbtw9eClz4kuKoLugsecHsHC5AKnNDGcJy9C5GM9yILKizak9T1M7EEMOr3cociF0HrH0hA6z OQCCUwL93RjWfhO6+nHhbddeu4HTBLcwVYN1CQXmXXietO/C7uHVju9TuPUkHIMIrvT3DQ+lsfn WHlT4d3y7acM3hkiHWt3+tqRew2YXzE9Cw6po/yappffVJreHdw3Jm+AsmTeeKLkpWNotIj+LMu esOQeFNAv3vuGLbkC8uTKc6pgIHiU1YLuI9XUliwQcxBE0KIpemtSrk65ihnxf/drOfHDRBmONT RASx7hMe1E21YAiVZoHmmnxDxlLOToRSw+Lj7jOaGjyj9Ag1muc4xGCWkdpUL42YzSaq0MVCeUQ bAsn75R8mNFNTXA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Allow clients to request getting a delegation xor an open stateid if a delegation isn't available. This allows the client to avoid sending a final CLOSE for the (useless) open stateid, when it is granted a delegation. This is done by moving the increment of the open stateid and unlocking of the st_mutex until after we acquire a delegation. If we get a delegation, we zero out the op_stateid field and set the NO_OPEN_STATEID flag. If the open stateid was brand new, then unhash it too in this case since it won't be needed. If we can't get a delegation or the new flag wasn't requested, then just increment and copy the open stateid as usual. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 28 ++++++++++++++++++++++++---- fs/nfsd/nfs4xdr.c | 5 +++-- include/uapi/linux/nfs4.h | 7 +++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 8851fc69f5c6..40e0c9b0ef71 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6051,6 +6051,17 @@ static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open, */ } +/* Are we only returning a delegation stateid? */ +static bool open_xor_delegation(struct nfsd4_open *open) +{ + if (!(open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION)) + return false; + if (open->op_delegate_type != NFS4_OPEN_DELEGATE_READ && + open->op_delegate_type != NFS4_OPEN_DELEGATE_WRITE) + return false; + return true; +} + /** * nfsd4_process_open2 - finish open processing * @rqstp: the RPC transaction being executed @@ -6073,6 +6084,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf struct nfs4_delegation *dp = NULL; __be32 status; bool new_stp = false; + bool deleg_only = false; /* * Lookup file; if found, lookup stateid and check open request, @@ -6127,9 +6139,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf open->op_odstate = NULL; } - nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid); - mutex_unlock(&stp->st_mutex); - if (nfsd4_has_session(&resp->cstate)) { if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) { open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT; @@ -6143,7 +6152,18 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf * OPEN succeeds even if we fail. */ nfs4_open_delegation(open, stp, &resp->cstate.current_fh); + deleg_only = open_xor_delegation(open); nodeleg: + if (deleg_only) { + memcpy(&open->op_stateid, &zero_stateid, sizeof(open->op_stateid)); + open->op_rflags |= OPEN4_RESULT_NO_OPEN_STATEID; + if (new_stp) + release_open_stateid(stp); + } else { + nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid); + } + mutex_unlock(&stp->st_mutex); + status = nfs_ok; trace_nfsd_open(&stp->st_stid.sc_stateid); out: @@ -6159,7 +6179,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf /* * To finish the open response, we just need to set the rflags. */ - open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX; + open->op_rflags |= NFS4_OPEN_RESULT_LOCKTYPE_POSIX; if (nfsd4_has_session(&resp->cstate)) open->op_rflags |= NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK; else if (!(open->op_openowner->oo_flags & NFS4_OO_CONFIRMED)) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 4cedcb252aa1..08d9421cd90e 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -1067,7 +1067,7 @@ static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *sh return nfs_ok; if (!argp->minorversion) return nfserr_bad_xdr; - switch (w & NFS4_SHARE_WANT_MASK) { + switch (w & NFS4_SHARE_WANT_TYPE_MASK) { case NFS4_SHARE_WANT_NO_PREFERENCE: case NFS4_SHARE_WANT_READ_DELEG: case NFS4_SHARE_WANT_WRITE_DELEG: @@ -3410,7 +3410,8 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr, #define NFSD_OA_SHARE_ACCESS_WANT (BIT(OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG) | \ BIT(OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG) | \ - BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL)) + BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL) | \ + BIT(OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION)) #define NFSD_OA_OPEN_CLAIM (BIT(OPEN_ARGS_OPEN_CLAIM_NULL) | \ BIT(OPEN_ARGS_OPEN_CLAIM_PREVIOUS) | \ diff --git a/include/uapi/linux/nfs4.h b/include/uapi/linux/nfs4.h index caf4db2fcbb9..4273e0249fcb 100644 --- a/include/uapi/linux/nfs4.h +++ b/include/uapi/linux/nfs4.h @@ -58,7 +58,7 @@ #define NFS4_SHARE_DENY_BOTH 0x0003 /* nfs41 */ -#define NFS4_SHARE_WANT_MASK 0xFF00 +#define NFS4_SHARE_WANT_TYPE_MASK 0xFF00 #define NFS4_SHARE_WANT_NO_PREFERENCE 0x0000 #define NFS4_SHARE_WANT_READ_DELEG 0x0100 #define NFS4_SHARE_WANT_WRITE_DELEG 0x0200 @@ -66,13 +66,16 @@ #define NFS4_SHARE_WANT_NO_DELEG 0x0400 #define NFS4_SHARE_WANT_CANCEL 0x0500 -#define NFS4_SHARE_WHEN_MASK 0xF0000 +#define NFS4_SHARE_WHEN_MASK 0xF0000 #define NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL 0x10000 #define NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED 0x20000 +#define NFS4_SHARE_WANT_MOD_MASK 0xF00000 #define NFS4_SHARE_WANT_DELEG_TIMESTAMPS 0x100000 #define NFS4_SHARE_WANT_OPEN_XOR_DELEGATION 0x200000 +#define NFS4_SHARE_WANT_MASK (NFS4_SHARE_WANT_TYPE_MASK | NFS4_SHARE_WANT_MOD_MASK) + #define NFS4_CDFC4_FORE 0x1 #define NFS4_CDFC4_BACK 0x2 #define NFS4_CDFC4_BOTH 0x3 From patchwork Thu Sep 5 12:41:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792281 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 477171A071A; Thu, 5 Sep 2024 12:42:12 +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=1725540133; cv=none; b=ehQXQ6VuQJ3Vg65v76gpGazQEptX6/HAPzR3GtQ8192qcrJDtSNMJI0azOvUVdXn13uKXpO0NksIvpPBeIejnLqwKjPmMUeORLyHZIrI3ymgqNulgiRzu15CbAXjpT9ZcRKUPSUO7KAz0g/SRwh6i1d+UUwMdK2d9xqV34TlC+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540133; c=relaxed/simple; bh=LiV0clf9L6NQX5LxYkFyOmngi4CQOovdgBWSLgxIFp8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qXeboa+1lC0oylwTKnSnIgCyMevuZpRVDzDUkDQbHs+CUV5giNh8QUWG0MEj5atETpW5ymXxiNcWnzi4mGncS7mVkMQzhgcQ2R4TKjyeTQZuM9TU9W5q/FrDXLI9I54iuZgv6a4bbZgKTOmXZwFEcx438K9rdZt8yj+7GrIzL2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UPjMfY4g; 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="UPjMfY4g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9012CC4CECA; Thu, 5 Sep 2024 12:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540132; bh=LiV0clf9L6NQX5LxYkFyOmngi4CQOovdgBWSLgxIFp8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UPjMfY4gBQ/Lin4WBYi6iW0UAHBMLJR8ncqfrru1kIVeUrRrUc5W/YmR5He6AJlkO mWvSs/3eqCj35ZGATV2+ZbGPRWQ5kmz7cMtSu9JXi05iVr0VImA4csIPE+uw4r3mj/ C94K3P9zTOjATkx1FraBiQVqqK1/eiAkK2GyLmRNW+zsMqR9kSrR7992j30EtxLAfI 0s8evmCwq7tykl3DFnuVJtzglv1OaAwxc8TF8fES57agPlnrzHUIrSqCGbGMCTIIdq uqkOKbaCrrAjTU0kS2S+Hge4ROvRtkv4dr5y+4Iaixld/z41Bsv0XF9lPXwsnzaaRl awe1Rusp+Y9ZA== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:53 -0400 Subject: [PATCH v4 09/11] fs: handle delegated timestamps in setattr_copy_mgtime Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-9-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=6296; i=jlayton@kernel.org; h=from:subject:message-id; bh=LiV0clf9L6NQX5LxYkFyOmngi4CQOovdgBWSLgxIFp8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acVxmRxlKc2nczzBdKjuAeqrBthaSyeahB9x 280UJXE10uJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FX/gD/4rFScHDd8r5gSdDDT0ZDTLV05DTPvMrlTsWFJuiY13NJi7q7W3bRue8E/842HppVyuihQ 9/rCf/vakl1qhiK4CjkE1DDwaUJP/vHUbU6lLe7MHSKqrTrZuiicTZqAMfw/ciex8tBBTDIy6hs h56ryuSIoAkqz9z1CUxh4qloQX6NZ/qPDLEoafQ/0d/hDhyQGyfxuJr2NF+dvbLQg04fyWAbayp h798dWgfzuCOeYSNtYQfdQQbLZUR0drBQi8gPz6s+jscaMXZ/4FS0ZJhpWpnTQNIugIMrfvSCD6 reNRBRrDuJg5y61PJn3E0GSioVik+99YIy3AFobq/CP8nvAX7qwt2VyX+26qytIZpg1Z15wFFlO BVBEbQfJUaV9/7ksV8Mm7EY6AEqfomqcEMEHI7BEnxoKTwbdK28i6x8E9s/CS2ynJ10kKwaMd3g +MlXfOfp3kuxwmeS6u8T5Eyr/tM+o4HFdiKhqZD5OiRAFq+xAi4csuf2oPdrC5/sNLCgsM/eozZ hUxWpZX2MiIewYoNgvsbi/RhqEBGYrJjAO638SFKG068dANiVmlqnVU5as2lJoI/O7yFyB2YxWz igs9kkMmqnNuaGv0aBT/4lUyM1BQg1uzruGUkJuluudhheq5zjW4LZZrhuCzTBJK2qthIkVq5Ds vbDmgCPYVmy4MAQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 When updating the ctime on an inode for a SETATTR with a multigrain filesystem, we usually want to take the latest time we can get for the ctime. The exception to this rule is when there is a nfsd write delegation and the server is proxying timestamps from the client. When nfsd gets a CB_GETATTR response, we want to update the timestamp value in the inode to the values that the client is tracking. The client doesn't send a ctime value (since that's always determined by the exported filesystem), but it can send a mtime value. In the case where it does, then we may need to update the ctime to a value commensurate with that instead of the current time. If ATTR_DELEG is set, then use ia_ctime value instead of setting the timestamp to the current time. With the addition of delegated timestamps we can also receive a request to update only the atime, but we may not need to set the ctime. Trust the ATTR_CTIME flag in the update and only update the ctime when it's set. Signed-off-by: Jeff Layton --- fs/attr.c | 28 +++++++++++++-------- fs/inode.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 3 files changed, 94 insertions(+), 10 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 3bcbc45708a3..392eb62aa609 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -286,16 +286,20 @@ static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr) unsigned int ia_valid = attr->ia_valid; struct timespec64 now; - /* - * If the ctime isn't being updated then nothing else should be - * either. - */ - if (!(ia_valid & ATTR_CTIME)) { - WARN_ON_ONCE(ia_valid & (ATTR_ATIME|ATTR_MTIME)); - return; + 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 = inode_set_ctime_deleg(inode, attr->ia_ctime); + else + now = 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); } - now = inode_set_ctime_current(inode); if (ia_valid & ATTR_ATIME_SET) inode_set_atime_to_ts(inode, attr->ia_atime); else if (ia_valid & ATTR_ATIME) @@ -354,8 +358,12 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *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) - inode_set_ctime_to_ts(inode, attr->ia_ctime); + 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); + } } EXPORT_SYMBOL(setattr_copy); diff --git a/fs/inode.c b/fs/inode.c index 01f7df1973bd..f0fbfd470d8e 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2835,6 +2835,80 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) } EXPORT_SYMBOL(inode_set_ctime_current); +/** + * inode_set_ctime_deleg - try to update the ctime on a delegated inode + * @inode: inode to update + * @update: timespec64 to set the ctime + * + * Attempt to atomically update the ctime on behalf of a delegation holder. + * + * The nfs server can call back the holder of a delegation to get updated + * inode attributes, including the mtime. When updating the mtime we may + * need to update the ctime to a value at least equal to that. + * + * This can race with concurrent updates to the inode, in which + * case we just don't do the update. + * + * Note that this works even when multigrain timestamps are not enabled, + * so use it in either case. + */ +struct timespec64 inode_set_ctime_deleg(struct inode *inode, struct timespec64 update) +{ + ktime_t now, floor = atomic64_read(&ctime_floor); + struct timespec64 now_ts, cur_ts; + u32 cur, old; + + /* pairs with try_cmpxchg below */ + cur = smp_load_acquire(&inode->i_ctime_nsec); + cur_ts.tv_nsec = cur & ~I_CTIME_QUERIED; + cur_ts.tv_sec = inode->i_ctime_sec; + + /* If the update is older than the existing value, skip it. */ + if (timespec64_compare(&update, &cur_ts) <= 0) + return cur_ts; + + now = coarse_ctime(floor); + now_ts = ktime_to_timespec64(now); + + /* Clamp the update to "now" if it's in the future */ + if (timespec64_compare(&update, &now_ts) > 0) + update = now_ts; + + update = timestamp_truncate(update, inode); + + /* No need to update if the values are already the same */ + if (timespec64_equal(&update, &cur_ts)) + return cur_ts; + + /* + * Try to swap the nsec value into place. If it fails, that means + * we raced with an update due to a write or similar activity. That + * stamp takes precedence, so just skip the update. + */ +retry: + old = cur; + if (try_cmpxchg(&inode->i_ctime_nsec, &cur, update.tv_nsec)) { + inode->i_ctime_sec = update.tv_sec; + mgtime_counter_inc(mg_ctime_swaps); + return update; + } + + /* + * Was the change due to someone marking the old ctime QUERIED? + * If so then retry the swap. This can only happen once since + * the only way to clear I_CTIME_QUERIED is to stamp the inode + * with a new ctime. + */ + if (!(old & I_CTIME_QUERIED) && (cur == (old | I_CTIME_QUERIED))) + goto retry; + + /* Otherwise, it was a new timestamp. */ + cur_ts.tv_sec = inode->i_ctime_sec; + cur_ts.tv_nsec = cur & ~I_CTIME_QUERIED; + return cur_ts; +} +EXPORT_SYMBOL(inode_set_ctime_deleg); + /** * in_group_or_capable - check whether caller is CAP_FSETID privileged * @idmap: idmap of the mount @inode was found from diff --git a/include/linux/fs.h b/include/linux/fs.h index eff688e75f2f..ea7ed437d2b1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1544,6 +1544,8 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb, struct timespec64 current_time(struct inode *inode); struct timespec64 inode_set_ctime_current(struct inode *inode); +struct timespec64 inode_set_ctime_deleg(struct inode *inode, + struct timespec64 update); static inline time64_t inode_get_atime_sec(const struct inode *inode) { From patchwork Thu Sep 5 12:41:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792282 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 D1D551A0739; Thu, 5 Sep 2024 12:42:14 +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=1725540134; cv=none; b=bzSAjQb/aADf6UH1bybU4+bdbElkOSh0snciHfdVnApJnk6FqfY4ep82bF2R7VqA+XAsUfFkHXk8jrCxT4A0w+8YQ6lEBQIJZQ1wlTa3ZyyVI5kSeM1KHZe6Wm98HUuvi+wsoAtyBrdK2q/JXA5UYT0FaKWVS2CzeY9rd7U8rWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540134; c=relaxed/simple; bh=pSj04UkQR35Y15vtLG/RjdqEiyJ2ZENZlNjDssJYmtU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rj+X1RFqhh7egOshJ6zWB4CrQzCoGuA/zLd6/GDuPNu5B3PXR3q+HfO5EB/jcLS+kmRnx6jcRUUeOb1O78LK7vQWy6ZEoOFapMUXjR66K1xU7m2wCQbsaEjNz6kV4xUeoDdxKPBH+UFQizlbhMRHCBa0Dvb9iOhA7gQG82N6xDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e7+fIonL; 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="e7+fIonL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 152ABC4CECB; Thu, 5 Sep 2024 12:42:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540134; bh=pSj04UkQR35Y15vtLG/RjdqEiyJ2ZENZlNjDssJYmtU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=e7+fIonLCUXYSYDhpcuUCzF8yAwC06H4zgrlU/GlhKyBSd/vRGyHrC4PkzdsLAXgA Ncdtc01NnIfVkYUN2erFRQAiwsym583vPMp0KIGWJ9RCLfckMzKu7Ktm9AU9eKn0Zk BNU7YDlRiJ3fLlBKzDG9mMRaEXncu2o/kpwvdMf9Y4dVryM1iZrbTHuZcmkWgtjlPF oYyudQUCg7qPe0ksVsI1aSzeJkSH7AVuU+YnlsAHoviDPDY/2OHfQehdrQq3FWGaiY 8TM7a8woq1E1gIlKV0OFNsGi7CUEGDqSRUa6pCdQlbm18z/v91MCbxVYYpBwxhsgJ4 wjMruorKif4xQ== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:54 -0400 Subject: [PATCH v4 10/11] nfsd: add support for delegated timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-10-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=12142; i=jlayton@kernel.org; h=from:subject:message-id; bh=pSj04UkQR35Y15vtLG/RjdqEiyJ2ZENZlNjDssJYmtU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acVgmIkuzCrqS+ua3otfUtKFJQH1BBy1wfXI mfi2Yh8F7WJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FUuDEACnm5mBpV4jP1Hq+Ej5by32s+mt1KsFZGgS3LBqf2bk3dcZuYxhPvrr3ts2A3RnXl6Bj5r Op3I9GoSuulgRbalN//5R7SFkX0cU63fTghCv/6lDPotiMFLrtR5cJbG/03VXjsQD1GVkRxaH7n uzlvUrY3V3iJkrzPgEeyxtWsYXeju97dnvWQiSqlqurPXO/XZCslhBG66XENF+VkpOU5VGRbdwM FFdzwmQS1ktGuOMOidPEc/mrjfFBY9qcCWkeBSTtF/fjeM8U1OUXoc1UmFMWSPq8m/gd3AeVI8w fEJ810Xug6eXdlx/Y4P199N9s4GRipKwdNX0DvjL2c9RSinvvrr4mEl4aiE8NJ6lXFfzWUK7x/D sjtizfImZ7Ybi5yWb6e5zwE1mngHd6izMnnpX87tFEKgkZu9igoZDKr5iNhmrNiS7iR6q7LMA3R WhLabBIVemgwzZd5Mfn+qUl2CKg6ZM2q9tV/0zNXZHqOW3fexRza4GgSLJZap1qciDB/nmfuEc0 i13TKE45q/wBkhF/RlqeqqHzIugdYRp7XntgGF91HmsODNg+trTDla4S0+T7u3OnUD0iy2NS7b0 WQm8hGvGKv/t/ZHxlZ8wJr4s4uRBV01Ib/zPM+sR9C0AG22ew0KYfictgqY0xeagH+un2p6u+xO NtnPd7HTryfSFeA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add support for the delegated timestamps on write delegations. This allows the server to proxy timestamps from the delegation holder to other clients that are doing GETATTRs vs. the same inode. Add a new flag to nfs4_delegation for indicating that the client can provide timestamps in the CB_GETATTR response. Set that when the client sets the appropriate flag in the open request. Add timespec64 fields to nfs4_cb_fattr and decode the timestamps into those. Vet those timestamps according to the delstid spec and update the inode attrs if necessary. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4callback.c | 42 +++++++++++++++++++++++--- fs/nfsd/nfs4state.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++---- fs/nfsd/nfs4xdr.c | 15 ++++++++-- fs/nfsd/nfsd.h | 2 ++ fs/nfsd/state.h | 3 ++ fs/nfsd/xdr4cb.h | 10 +++++-- include/linux/time64.h | 5 ++++ 7 files changed, 143 insertions(+), 15 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index f88d4cfe9b38..43b8320c8255 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -42,6 +42,7 @@ #include "trace.h" #include "xdr4cb.h" #include "xdr4.h" +#include "nfs4xdr_gen.h" #define NFSDDBG_FACILITY NFSDDBG_PROC @@ -93,12 +94,35 @@ static int decode_cb_fattr4(struct xdr_stream *xdr, uint32_t *bitmap, { fattr->ncf_cb_change = 0; fattr->ncf_cb_fsize = 0; + fattr->ncf_cb_atime.tv_sec = 0; + fattr->ncf_cb_atime.tv_nsec = 0; + fattr->ncf_cb_mtime.tv_sec = 0; + fattr->ncf_cb_mtime.tv_nsec = 0; + if (bitmap[0] & FATTR4_WORD0_CHANGE) if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_change) < 0) return -NFSERR_BAD_XDR; if (bitmap[0] & FATTR4_WORD0_SIZE) if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_fsize) < 0) return -NFSERR_BAD_XDR; + if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) { + fattr4_time_deleg_access access; + + if (!xdrgen_decode_fattr4_time_deleg_access(xdr, &access)) + return -NFSERR_BAD_XDR; + fattr->ncf_cb_atime.tv_sec = access.seconds; + fattr->ncf_cb_atime.tv_nsec = access.nseconds; + + } + if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { + fattr4_time_deleg_modify modify; + + if (!xdrgen_decode_fattr4_time_deleg_modify(xdr, &modify)) + return -NFSERR_BAD_XDR; + fattr->ncf_cb_mtime.tv_sec = modify.seconds; + fattr->ncf_cb_mtime.tv_nsec = modify.nseconds; + + } return 0; } @@ -364,14 +388,20 @@ encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr, struct nfs4_delegation *dp = container_of(fattr, struct nfs4_delegation, dl_cb_fattr); struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle; struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; - u32 bmap[1]; + u32 bmap_size = 1; + u32 bmap[3]; bmap[0] = FATTR4_WORD0_SIZE; if (!ncf->ncf_file_modified) bmap[0] |= FATTR4_WORD0_CHANGE; + if (dp->dl_deleg_ts) { + bmap[1] = 0; + bmap[2] = FATTR4_WORD2_TIME_DELEG_ACCESS | FATTR4_WORD2_TIME_DELEG_MODIFY; + bmap_size = 3; + } encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR); encode_nfs_fh4(xdr, fh); - encode_bitmap4(xdr, bmap, ARRAY_SIZE(bmap)); + encode_bitmap4(xdr, bmap, bmap_size); hdr->nops++; } @@ -596,7 +626,7 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp, struct nfs4_cb_compound_hdr hdr; int status; u32 bitmap[3] = {0}; - u32 attrlen; + u32 attrlen, maxlen; struct nfs4_cb_fattr *ncf = container_of(cb, struct nfs4_cb_fattr, ncf_getattr); @@ -615,7 +645,11 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp, return -NFSERR_BAD_XDR; if (xdr_stream_decode_u32(xdr, &attrlen) < 0) return -NFSERR_BAD_XDR; - if (attrlen > (sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize))) + maxlen = sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize); + if (bitmap[2] != 0) + maxlen += (sizeof(ncf->ncf_cb_mtime.tv_sec) + + sizeof(ncf->ncf_cb_mtime.tv_nsec)) * 2; + if (attrlen > maxlen) return -NFSERR_BAD_XDR; status = decode_cb_fattr4(xdr, bitmap, ncf); return status; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 40e0c9b0ef71..5e1d25624961 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6002,6 +6002,8 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); + if (open->op_deleg_want & NFS4_SHARE_WANT_DELEG_TIMESTAMPS) + dp->dl_deleg_ts = true; if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { if (!nfs4_delegation_stat(dp, currentfh, &stat)) { nfs4_put_stid(&dp->dl_stid); @@ -8844,6 +8846,78 @@ nfsd4_get_writestateid(struct nfsd4_compound_state *cstate, get_stateid(cstate, &u->write.wr_stateid); } +/** + * set_cb_time - vet and set the timespec for a cb_getattr update + * @cb: timestamp from the CB_GETATTR response + * @orig: original timestamp in the inode + * @now: current time + * + * Given a timestamp in a CB_GETATTR 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. + */ +static bool set_cb_time(struct timespec64 *cb, const struct timespec64 *orig, + const struct timespec64 *now) +{ + + /* + * "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) <= 0) + return false; + + /* + * "When the time presented is in the future, the server can either + * 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 = *now; + } + + return true; +} + +static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation *dp) +{ + struct inode *inode = d_inode(dentry); + struct timespec64 now = current_time(inode); + struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; + struct iattr attrs = { }; + int ret; + + if (dp->dl_deleg_ts) { + struct timespec64 atime = inode_get_atime(inode); + struct timespec64 mtime = inode_get_mtime(inode); + + attrs.ia_atime = ncf->ncf_cb_atime; + attrs.ia_mtime = ncf->ncf_cb_mtime; + + if (set_cb_time(&attrs.ia_atime, &atime, &now)) + attrs.ia_valid |= ATTR_ATIME | ATTR_ATIME_SET; + + if (set_cb_time(&attrs.ia_mtime, &mtime, &now)) { + attrs.ia_valid |= ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET; + attrs.ia_ctime = attrs.ia_mtime; + } + } else { + attrs.ia_valid |= ATTR_MTIME | ATTR_CTIME; + attrs.ia_mtime = attrs.ia_ctime = now; + } + + if (!attrs.ia_valid) + return 0; + + attrs.ia_valid |= ATTR_DELEG; + inode_lock(inode); + ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL); + inode_unlock(inode); + return ret; +} + /** * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict * @rqstp: RPC transaction context @@ -8870,7 +8944,6 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, struct file_lock_context *ctx; struct nfs4_delegation *dp = NULL; struct file_lease *fl; - struct iattr attrs; struct nfs4_cb_fattr *ncf; struct inode *inode = d_inode(dentry); @@ -8932,11 +9005,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, * not update the file's metadata with the client's * modified size */ - attrs.ia_mtime = attrs.ia_ctime = current_time(inode); - attrs.ia_valid = ATTR_MTIME | ATTR_CTIME | ATTR_DELEG; - inode_lock(inode); - err = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL); - inode_unlock(inode); + err = cb_getattr_update_times(dentry, dp); if (err) { status = nfserrno(err); goto out_status; diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 08d9421cd90e..b11d75f483de 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3411,6 +3411,7 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr, #define NFSD_OA_SHARE_ACCESS_WANT (BIT(OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG) | \ BIT(OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG) | \ BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL) | \ + BIT(OPEN_ARGS_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS) | \ BIT(OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION)) #define NFSD_OA_OPEN_CLAIM (BIT(OPEN_ARGS_OPEN_CLAIM_NULL) | \ @@ -3604,7 +3605,11 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (status) goto out; } - if (attrmask[0] & (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE)) { + if ((attrmask[0] & (FATTR4_WORD0_CHANGE | + FATTR4_WORD0_SIZE)) || + (attrmask[1] & (FATTR4_WORD1_TIME_ACCESS | + FATTR4_WORD1_TIME_MODIFY | + FATTR4_WORD1_TIME_METADATA))) { status = nfsd4_deleg_getattr_conflict(rqstp, dentry, &dp); if (status) goto out; @@ -3616,8 +3621,14 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (dp) { struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; - if (ncf->ncf_file_modified) + if (ncf->ncf_file_modified) { args.stat.size = ncf->ncf_cur_fsize; + if (!timespec64_is_epoch(&ncf->ncf_cb_mtime)) + args.stat.mtime = ncf->ncf_cb_mtime; + } + + if (!timespec64_is_epoch(&ncf->ncf_cb_atime)) + args.stat.atime = ncf->ncf_cb_atime; nfs4_put_stid(&dp->dl_stid); } diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index c98fb104ba7d..18b8d383f73a 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -455,6 +455,8 @@ enum { FATTR4_WORD2_MODE_UMASK | \ NFSD4_2_SECURITY_ATTRS | \ FATTR4_WORD2_XATTR_SUPPORT | \ + FATTR4_WORD2_TIME_DELEG_ACCESS | \ + FATTR4_WORD2_TIME_DELEG_MODIFY | \ FATTR4_WORD2_OPEN_ARGUMENTS) extern const u32 nfsd_suppattrs[3][3]; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index c7c7ec21e510..874fcab2b183 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -142,6 +142,8 @@ struct nfs4_cb_fattr { /* from CB_GETATTR reply */ u64 ncf_cb_change; u64 ncf_cb_fsize; + struct timespec64 ncf_cb_mtime; + struct timespec64 ncf_cb_atime; unsigned long ncf_cb_flags; bool ncf_file_modified; @@ -185,6 +187,7 @@ struct nfs4_delegation { int dl_retries; struct nfsd4_callback dl_recall; bool dl_recalled; + bool dl_deleg_ts; /* for CB_GETATTR */ struct nfs4_cb_fattr dl_cb_fattr; diff --git a/fs/nfsd/xdr4cb.h b/fs/nfsd/xdr4cb.h index e8b00309c449..f1a315cd31b7 100644 --- a/fs/nfsd/xdr4cb.h +++ b/fs/nfsd/xdr4cb.h @@ -59,16 +59,20 @@ * 1: CB_GETATTR opcode (32-bit) * N: file_handle * 1: number of entry in attribute array (32-bit) - * 1: entry 0 in attribute array (32-bit) + * 3: entry 0-2 in attribute array (32-bit * 3) */ #define NFS4_enc_cb_getattr_sz (cb_compound_enc_hdr_sz + \ cb_sequence_enc_sz + \ - 1 + enc_nfs4_fh_sz + 1 + 1) + 1 + enc_nfs4_fh_sz + 1 + 3) /* * 4: fattr_bitmap_maxsz * 1: attribute array len * 2: change attr (64-bit) * 2: size (64-bit) + * 2: atime.seconds (64-bit) + * 1: atime.nanoseconds (32-bit) + * 2: mtime.seconds (64-bit) + * 1: mtime.nanoseconds (32-bit) */ #define NFS4_dec_cb_getattr_sz (cb_compound_dec_hdr_sz + \ - cb_sequence_dec_sz + 4 + 1 + 2 + 2 + op_dec_sz) + cb_sequence_dec_sz + 4 + 1 + 2 + 2 + 2 + 1 + 2 + 1 + op_dec_sz) diff --git a/include/linux/time64.h b/include/linux/time64.h index f1bcea8c124a..9934331c7b86 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -49,6 +49,11 @@ static inline int timespec64_equal(const struct timespec64 *a, return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); } +static inline bool timespec64_is_epoch(const struct timespec64 *ts) +{ + return ts->tv_sec == 0 && ts->tv_nsec == 0; +} + /* * lhs < rhs: return <0 * lhs == rhs: return 0 From patchwork Thu Sep 5 12:41:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13792283 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 DF7E51A0AEC; Thu, 5 Sep 2024 12:42:15 +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=1725540136; cv=none; b=CrSQuLDyneae/uX35y9kZp/nDqv4cQzK6dtQUu6sBFsMLT83NrCX8dp0GzOCO0chBmXKQ327ZbpAxWMz8g7ZZcYoZrh1LgMv/ADJBBlkZMPEbuMyDCfDntH+ugSkKNwEnkeXYP3X9F21m833D7iwdznHvXS0D/U/oY5vZ3HMj4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725540136; c=relaxed/simple; bh=1en6ZoS+J2BtKYvFYTFNSg/wJUd69yW/1zWBLFXUlpU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bJI6R8dwr4DHtwX8gSaBHd0DEmcUdhswxiSHHoeaBZEv9KpnGOHYC+PotXPFJxizj2qklPz15tDsyWKikDod2Rj98emRsv1VLyCJMuA9A/MpV3pWIhyAAtrxKnHpaMOgT5L4enAwOq/L0HINv6L369khqW+dn8lqv8kT6XkSyRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UK3ZC7BJ; 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="UK3ZC7BJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A90EC4CECA; Thu, 5 Sep 2024 12:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725540135; bh=1en6ZoS+J2BtKYvFYTFNSg/wJUd69yW/1zWBLFXUlpU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UK3ZC7BJgoDoijdjpTdtfUh9bpJTWHbRd4WMJNOQj6+MgRPcVQ3xwlu6omKQ7NLgb 8y5FZWXK/wrWL8FaOEbpJ7yfHrzzKTimmRIX3025aM5piWbHqvpw8UqjM2wh+KMm5H l9xnpLQ5VS8TPsr1U2FL8unSKhbEBm57GBLk9poNwHVAMihLalvWwPgZcFc1IGzYfP PXGZJg38aZCmzP3qDpov/Xe/WsXwgt1GI8gbRT7mwG4/epOnSPyb9mkVbwaYMX3m6l p5ZYP0m+mk3lNxUxQaLzW72XB3eaFLPTS9jiukU5zHKW0AmuY9hAondZiAk41Znejk 6R/mHH45ZteRw== From: Jeff Layton Date: Thu, 05 Sep 2024 08:41:55 -0400 Subject: [PATCH v4 11/11] nfsd: handle delegated timestamps in SETATTR Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-delstid-v4-11-d3e5fd34d107@kernel.org> References: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> In-Reply-To: <20240905-delstid-v4-0-d3e5fd34d107@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Alexander Viro , Christian Brauner , Jan Kara Cc: Tom Haynes , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3155; i=jlayton@kernel.org; h=from:subject:message-id; bh=1en6ZoS+J2BtKYvFYTFNSg/wJUd69yW/1zWBLFXUlpU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm2acVXSn3MSZg8iTU1GbT8KuKUTM9fJk8cNmyR VdtH0Gk5yuJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtmnFQAKCRAADmhBGVaC FSP8D/0fLtIHut1uWgzEMa5a2ixd9F+YUKgy468//gkfbbjzHGvIjr6OUTwJKIqeJnfP3+n4vTZ OqV5c5fkqGEp08d8YerMOmurwNrlDaoRAUhrtRJvwCUyj7b4bxqWAYZc0r55cWnpRVIjb8rpgam i7t/yWnDyFOaDPimzwFbWIyJKR+yZlJfH/c+Kmz3EL6LiiKBUs//T3Bbbc0RNxej2oVIih5TXJZ vNY6zfylLnQhy6YNGqjUoePA4g7jE2S5sdj1Otl3VecKvs/N33hrANlcAuCYC8NnalVD4jHqUw4 0lqK1Z6hKr4NHK+2FfdAMnPBwqYQZEUNf3GAm6GdSVbwGCYlKTHsaH9XzmrQO50dTo9kQgHL1oL xN7w9Ipx/7RJNPc8wZzKgqJbz5cjWwN8Tf8S8EcwWSZgCFJHGHWPA6oJeKJbQJLc4XmbABFg2e5 L8TTK7Q3G2OGT4Ab24t6X1/3ZwS3TGmmwmcPHymfpg8+FgO9yrwsMsEpHQ3r0KgCH/x6xvEXus5 xx7/D6dyCr0FH9rN9YguUbmbDangTa5XpoIIzGn/MWWSOEq6feoyxuIRqLniJHQaeltiFUtSA1h zxIate65nuUL5uYn+V+xz1ukWk9GCvXwGvoN1iCTq5fDPqHrcNlbkKkztcXCNSWioy73VJ59wuI LDhz5kuMpvDZUVA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Allow SETATTR to handle delegated timestamps. This patch assumes that only the delegation holder has the ability to set the timestamps in this way, so we only allow this if the SETATTR stateid refers to the delegation. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4proc.c | 29 ++++++++++++++++++++++++++--- fs/nfsd/nfs4xdr.c | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index b5a6bf4f459f..7f874943583c 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1133,18 +1133,41 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, .na_iattr = &setattr->sa_iattr, .na_seclabel = &setattr->sa_label, }; + struct nfs4_stid *st = NULL; struct inode *inode; __be32 status = nfs_ok; - bool save_no_wcc; + bool save_no_wcc, deleg_attrs; int err; - if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { + deleg_attrs = setattr->sa_bmval[2] & (FATTR4_WORD2_TIME_DELEG_ACCESS | + FATTR4_WORD2_TIME_DELEG_MODIFY); + + if (deleg_attrs || (setattr->sa_iattr.ia_valid & ATTR_SIZE)) { status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, &setattr->sa_stateid, - WR_STATE, NULL, NULL); + WR_STATE, NULL, &st); if (status) return status; } + + /* + * If client is trying to set delegated timestamps, ensure that the + * stateid refers to a write delegation. + */ + if (deleg_attrs) { + status = nfserr_bad_stateid; + if (st->sc_type & SC_TYPE_DELEG) { + struct nfs4_delegation *dp = delegstateid(st); + + if (dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) + status = nfs_ok; + } + } + if (st) + nfs4_put_stid(st); + if (status) + return status; + err = fh_want_write(&cstate->current_fh); if (err) return nfserrno(err); diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index b11d75f483de..0dea4ee8b19e 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -521,6 +521,26 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, *umask = mask & S_IRWXUGO; iattr->ia_valid |= ATTR_MODE; } + if (bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) { + fattr4_time_deleg_access access; + + if (!xdrgen_decode_fattr4_time_deleg_access(argp->xdr, &access)) + return nfserr_bad_xdr; + iattr->ia_atime.tv_sec = access.seconds; + iattr->ia_atime.tv_nsec = access.nseconds; + iattr->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET | ATTR_DELEG; + } + if (bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { + fattr4_time_deleg_modify modify; + + if (!xdrgen_decode_fattr4_time_deleg_modify(argp->xdr, &modify)) + return nfserr_bad_xdr; + iattr->ia_mtime.tv_sec = modify.seconds; + iattr->ia_mtime.tv_nsec = modify.nseconds; + iattr->ia_ctime.tv_sec = modify.seconds; + iattr->ia_ctime.tv_nsec = modify.seconds; + iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET | ATTR_DELEG; + } /* request sanity: did attrlist4 contain the expected number of words? */ if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos)