From patchwork Thu Aug 29 13:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13783248 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 6DD231ABED0; Thu, 29 Aug 2024 13:26:52 +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=1724938012; cv=none; b=d4LweUMkPecIltJW+l8udMu8Ili9Z8bVhfBt0VgbRUdlnioeFKcEkL4ZCCpCYwLdKBmTTY0NZiEdloNoOdEP4oO0nUAD9yEeKwwU4+R2HzCqHe1o6l3IdaTgitoiRW3GdkM+ZARJbX10k/DmojXvxqr98OxjXOM6kVpgqTrtib4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938012; c=relaxed/simple; bh=DOAO3+oC6YizpcQwSETjUEGRUke0nZ2pfAyJX5iZLVY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f9fFBaK6RBg1k4aLX5CcFf54h2he+Wm/TCAmj6JqVsZ29uiMNWDDAG7TGIVr6C1LJ4pPV+7MVjaCcMAxtBRm+x0y8Yk1PSP50F20told1UFklY73OF2ag0d0JFGhKC94AM6fFSRyBGLjnkb8FiLp3cdeu9xJWI6CBZDEZF53cCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bAN+pHie; 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="bAN+pHie" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7548EC4CEC8; Thu, 29 Aug 2024 13:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938011; bh=DOAO3+oC6YizpcQwSETjUEGRUke0nZ2pfAyJX5iZLVY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bAN+pHiev2LNcdP8X6duFV3VlR4HqUm796B/13ePTAwP3os9ZnmSX67xpIC2jc4v+ W7sZDG7Bn0bwmPna1aU1wGE59B7VeeU+inNt0QjLK0J+f6aBqD6FExbKFy+sUL/6to P7jIK7S0pWF5wKH8QByj99m9XEY0Va7BVe8trUuT93JT2yoGhoupiS++STjmXYL4Tj h02TJ+o6GV5RcE9XOxhzNIw0EwA1f9Sp4Fh3/y1+jMZ+wYBGjWCu3Xi7fClth3PNfj 0Rdaqhhj/HJ9K5XDhSO3pGvhS+54kO45XStQ417XyKsgYvb9ijcoE+RgDhjawanQ89 YhhCstwhcgOFg== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:39 -0400 Subject: [PATCH v3 01/13] nfsd: fix nfsd4_deleg_getattr_conflict in presence of third party lease Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-1-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1715; i=jlayton@kernel.org; h=from:subject:message-id; bh=X+VzQ5tWBrDRZPw5yaXZK1DNCjxb4s7t+AB6ZzGGecE=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcWfUhvZZfPYuxUNidZ2yRhdmSg0l9misQKZ HmRZZ1q4qOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FgAKCRAADmhBGVaC Fdr8D/sHYlFA0RM32n+zoZfn98GsMBaGGgNqfPftRQ6grKWRSrZQEZ3erbCKi7bq4E1RYGuLzpY j0ph0hsFa+UDpmMqr95fnMr8/3kquGmBZZNKtMmeAI3PPhp5uU4vzXpA3MtWQx6+yIf0+Xck2dG L5p4Qg5cSdvlwrPv74GKgM1C1pcV7lp3zpFYX154ObNe8zbJZCKqVz61ggJnNS2FufUiSYHuaUg 9qhk5vmYuryMEbmsRXK5kgAE7Cb1Ulj7dpd51vgZxE66V7jD7VwFXtzg6s9QvgSuP/3zh5tSOqD MFCVwLwBfIRWwKixPgv266SDkMxzDQuzGnG5LHb0agBjqg0bZ2dtEbEoexaEZ0Dpd54Ejuf1egc MaxVaDEB1hG4uRVIt1jKmNBabz/osbBOAjjM4fevnZKMuiBB6QKlNI27rS62XbPPpbMB1cRsD93 QUU2n58x2FK7PrtqS69m0ubAhfBeILrLKB5X9DE1zYgDU7zW+1uFrGC1c9Br39jgHDFQdk2JSAV dQOwVlpZ/yjM9cbwWp/aAm/KftkCC+MNzUdVGgwIF6dW0OA1laQVONWXtCctLpc8UTrJU3AcveO j/HAb6mDyOzKyYQ5ti5U2M20M4EFZhtEQTjxc+EyWB89sLQkavLLdYWiI1rPiiu305y6orhwT+6 jKf2u1idIarP5tQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 From: NeilBrown It is not safe to dereference fl->c.flc_owner without first confirming fl->fl_lmops is the expected manager. nfsd4_deleg_getattr_conflict() tests fl_lmops but largely ignores the result and assumes that flc_owner is an nfs4_delegation anyway. This is wrong. With this patch we restore the "!= &nfsd_lease_mng_ops" case to behave as it did before the changed mentioned below. This the same as the current code, but without any reference to a possible delegation. Fixes: c5967721e106 ("NFSD: handle GETATTR conflict with write delegation") Signed-off-by: NeilBrown Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index b6bf39c64d78..eaa11d42d1b1 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8854,7 +8854,15 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, */ if (type == F_RDLCK) break; - goto break_lease; + + nfsd_stats_wdeleg_getattr_inc(nn); + spin_unlock(&ctx->flc_lock); + + status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ)); + if (status != nfserr_jukebox || + !nfsd_wait_for_delegreturn(rqstp, inode)) + return status; + return 0; } if (type == F_WRLCK) { struct nfs4_delegation *dp = fl->c.flc_owner; @@ -8863,7 +8871,6 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, spin_unlock(&ctx->flc_lock); return 0; } -break_lease: nfsd_stats_wdeleg_getattr_inc(nn); dp = fl->c.flc_owner; refcount_inc(&dp->dl_stid.sc_count); From patchwork Thu Aug 29 13:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13783249 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 1463C1AD9D2; Thu, 29 Aug 2024 13:26:53 +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=1724938014; cv=none; b=edT6MCLbcesXBsEc75TJCuMNh9XjWFohlA0eD1WmyyHYVYBsow3E/s9GLMqzQOD4LD4LscZtK4vrzP+6h3zStqSX6DCUuk7yZdoHCw7a6xPV9e2fmOlHa+dPPm9BnN2eFoW6y+6hUOs7MunHp6+KUKIF0QAybQ9PlRNFkTcul8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938014; c=relaxed/simple; bh=PwIFk2dK5q6tuUFzoYh/qnAqes8i0hXAQB3+QDH+hyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JL6EUpaZ1NB2dRX0tfI60OfFp4ayXyQr/xxiaOsgrlIeu0xzUBxN7cH/O/iK4EFw0MfEcIyszuDQCfzPxy1bAGOIVW5mn9Kh6jgMDjDfspJLYYcnunbwLRCxKeVOkD7s1jAf+0jT7ZwCVmlZrxvaz1WUxbi8Ld3JmENCgp0CiFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AQlfhofW; 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="AQlfhofW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AF0AC4CEC1; Thu, 29 Aug 2024 13:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938013; bh=PwIFk2dK5q6tuUFzoYh/qnAqes8i0hXAQB3+QDH+hyU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AQlfhofW5+r4WL2ixr0aCzI+DisyPr+42Y6bqxCjh426SLMYPNyaIJyrnzbER4Okj BJzf1SzyCI8lUFEJu86bIM2ykK+gGAbmQ2XWGhm3iYEvi67hzVdn2XXrQXImXrfarr 9UyibVJb7WdbeHZ/4i1lzwshtYfoQjqEuGzxDL7JvM85p8DBnBfFr+u3XpUYmBNVo2 +vcPJKq2C+73LtFomEyfkc9Z9TQaEV1rIcH3INuz71HQh2ROqUrDjXCE5dW9ddOsIM PbRwv8XcF69f8vf1QXCBJosMFyLg9AheESioU5OabUJMVvAVoivI6MAuXqUb0H9qsi eDWGsyLizbKQw== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:40 -0400 Subject: [PATCH v3 02/13] nfsd: untangle code in nfsd4_deleg_getattr_conflict() Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-2-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=5851; i=jlayton@kernel.org; h=from:subject:message-id; bh=CZ+WRwWj+mXsqzim3Z0h9WP+zRKw7PARB6vUTbQEEIc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcXw9IIyWz/zkGgfp2tt5r7oXNPGxULgQO2J zQliE9FQBSJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC FYKqEAC4pnNmwmjHA53D7AN8RGe0wKwbULA7e9QIYiZaWJxujWdBdjM2PiND5Nr0+2AaQyTX2uw yewh1n2y6nns5yMGW2zT2wn70jM46pKBEFsKZqDE9CoCbSF1QZWydZF4rswqBjwPIS8tWn4abBz 6hzevRkg05I9N3Czvo//zhJxO9+WFAhWnE342X0Xl6fapDYI01u89Skx9Jn1Es/07NAGvWTgrzx ydx/+AU4yi4e1tC9tu6GED9XoU9zQIsM0RKa0qDfCPYLkDyL0JaqX6R+O5WiWsdnipVX8zt00y0 dtXOtiT/WUaIqdLLHLVbxpg1Kr/PmEP1mzf9fnuxazudJcCg0YGwynqryiYlyN+fUWIfmh1g9Pc tapl3AziIE4sK3rt2v1GBOQw62ScQ+y69AzRPW2rTIrk2Jcgp3TVRtyMAnn0cSO8LmhodUDy30X Yp/FBgr5u1sNcm1wCkIWrePFbmzppJjqelPAiCk7mz8nc+VeKDvPLT68E2I3al46+Bp4EfcizRd B0AmEzpG+fD933PhVMc96V5u0SFWXZIjyyFEVRTWrP/YvlrPMqV9pm208/OVa3z5Oo823Hi+F9P LfpdGdN0k55sSLmEETg6Rx4DRL91BFid5Y6lyNLjDLHEqtnh8gDCQDNkZhYtNvC11TpdGx5aIDL lUj2z7pU1KLi+lg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 From: NeilBrown The code in nfsd4_deleg_getattr_conflict() is convoluted and buggy. With this patch we: - properly handle non-nfsd leases. We must not assume flc_owner is a delegation unless fl_lmops == &nfsd_lease_mng_ops - move the main code out of the for loop - have a single exit which calls nfs4_put_stid() (and other exits which don't need to call that) [ jlayton: refactored on top of Neil's other patch: nfsd: fix nfsd4_deleg_getattr_conflict in presence of third party lease ] Fixes: c5967721e106 ("NFSD: handle GETATTR conflict with write delegation") Signed-off-by: NeilBrown Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 131 +++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 69 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index eaa11d42d1b1..8835930ecee6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8831,6 +8831,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, __be32 status; struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); struct file_lock_context *ctx; + struct nfs4_delegation *dp = NULL; struct file_lease *fl; struct iattr attrs; struct nfs4_cb_fattr *ncf; @@ -8840,84 +8841,76 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry, ctx = locks_inode_context(inode); if (!ctx) return 0; + +#define NON_NFSD_LEASE ((void *)1) + spin_lock(&ctx->flc_lock); for_each_file_lock(fl, &ctx->flc_lease) { - unsigned char type = fl->c.flc_type; - if (fl->c.flc_flags == FL_LAYOUT) continue; - if (fl->fl_lmops != &nfsd_lease_mng_ops) { - /* - * non-nfs lease, if it's a lease with F_RDLCK then - * we are done; there isn't any write delegation - * on this inode - */ - if (type == F_RDLCK) - break; - - nfsd_stats_wdeleg_getattr_inc(nn); - spin_unlock(&ctx->flc_lock); - - status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ)); + if (fl->c.flc_type == F_WRLCK) { + if (fl->fl_lmops == &nfsd_lease_mng_ops) + dp = fl->c.flc_owner; + else + dp = NON_NFSD_LEASE; + } + break; + } + if (dp == NULL || dp == NON_NFSD_LEASE || + dp->dl_recall.cb_clp == *(rqstp->rq_lease_breaker)) { + spin_unlock(&ctx->flc_lock); + if (dp == NON_NFSD_LEASE) { + status = nfserrno(nfsd_open_break_lease(inode, + NFSD_MAY_READ)); if (status != nfserr_jukebox || !nfsd_wait_for_delegreturn(rqstp, inode)) return status; - return 0; } - if (type == F_WRLCK) { - struct nfs4_delegation *dp = fl->c.flc_owner; + return 0; + } - if (dp->dl_recall.cb_clp == *(rqstp->rq_lease_breaker)) { - spin_unlock(&ctx->flc_lock); - return 0; - } - nfsd_stats_wdeleg_getattr_inc(nn); - dp = fl->c.flc_owner; - refcount_inc(&dp->dl_stid.sc_count); - ncf = &dp->dl_cb_fattr; - nfs4_cb_getattr(&dp->dl_cb_fattr); - spin_unlock(&ctx->flc_lock); - wait_on_bit_timeout(&ncf->ncf_cb_flags, CB_GETATTR_BUSY, - TASK_INTERRUPTIBLE, NFSD_CB_GETATTR_TIMEOUT); - if (ncf->ncf_cb_status) { - /* Recall delegation only if client didn't respond */ - status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ)); - if (status != nfserr_jukebox || - !nfsd_wait_for_delegreturn(rqstp, inode)) { - nfs4_put_stid(&dp->dl_stid); - return status; - } - } - if (!ncf->ncf_file_modified && - (ncf->ncf_initial_cinfo != ncf->ncf_cb_change || - ncf->ncf_cur_fsize != ncf->ncf_cb_fsize)) - ncf->ncf_file_modified = true; - if (ncf->ncf_file_modified) { - int err; - - /* - * Per section 10.4.3 of RFC 8881, the server would - * 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); - if (err) { - nfs4_put_stid(&dp->dl_stid); - return nfserrno(err); - } - ncf->ncf_cur_fsize = ncf->ncf_cb_fsize; - *size = ncf->ncf_cur_fsize; - *modified = true; - } - nfs4_put_stid(&dp->dl_stid); - return 0; + nfsd_stats_wdeleg_getattr_inc(nn); + refcount_inc(&dp->dl_stid.sc_count); + ncf = &dp->dl_cb_fattr; + nfs4_cb_getattr(&dp->dl_cb_fattr); + spin_unlock(&ctx->flc_lock); + + wait_on_bit_timeout(&ncf->ncf_cb_flags, CB_GETATTR_BUSY, + TASK_INTERRUPTIBLE, NFSD_CB_GETATTR_TIMEOUT); + if (ncf->ncf_cb_status) { + /* Recall delegation only if client didn't respond */ + status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ)); + if (status != nfserr_jukebox || + !nfsd_wait_for_delegreturn(rqstp, inode)) + goto out_status; + } + if (!ncf->ncf_file_modified && + (ncf->ncf_initial_cinfo != ncf->ncf_cb_change || + ncf->ncf_cur_fsize != ncf->ncf_cb_fsize)) + ncf->ncf_file_modified = true; + if (ncf->ncf_file_modified) { + int err; + + /* + * Per section 10.4.3 of RFC 8881, the server would + * 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); + if (err) { + status = nfserrno(err); + goto out_status; } - break; + ncf->ncf_cur_fsize = ncf->ncf_cb_fsize; + *size = ncf->ncf_cur_fsize; + *modified = true; } - spin_unlock(&ctx->flc_lock); - return 0; + status = 0; +out_status: + nfs4_put_stid(&dp->dl_stid); + return status; } From patchwork Thu Aug 29 13:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13783250 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 748DE1AE86C; Thu, 29 Aug 2024 13:26:55 +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=1724938015; cv=none; b=Oz/KS4YZefa4aWxIf87G3/Drm6UZ5OAtWqZBv5Q7quaU5GOTpebVXzzlfIwPfFnbKhBmS/Jk352UV5XxHfossxwTpbjVfhCOyCj8o3PLDaE2rLvX7voo/MmkPBfSdN46C1Aqn1fS3xGcqpyAscgaw3CW+iKtuJ3bjU/OH56Hjq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938015; c=relaxed/simple; bh=5hx89BSkzY2v98uuzPWE6uI+Zngs30R5FeV2oiZEv7M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SNmms5vQBiQ5vRbVUGJzsku4jF0b9b8THM/jV1bKuwl8HWqYfhzmdgNJT7pnKUrEGKUgHmksrc7mMD1atRKhzAqguR0Yrk1A813eLf78cABI3tzGvP06ATu9KpnNelG8CuvBHyfTj3yyfP1q24YfPrPKouiNcpWOuZtD5GS/j3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RwvkorRG; 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="RwvkorRG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D34DAC4CEC5; Thu, 29 Aug 2024 13:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938015; bh=5hx89BSkzY2v98uuzPWE6uI+Zngs30R5FeV2oiZEv7M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RwvkorRGd2nGVJbt21mr5+JABeiWqAnlAsybD7EfTagnYWmoXkLR8gTK8CQ6huw4k k44b6mEfe9IXTzBF7Tw+EbzeV7SPSE+lhPCzErrpogK92tUO4MMxESLYoDU58y88Jn uIBF3tlbKahwEGnrEzR1Si9iFMfyfFqTmY4Nm27Xa18gKsYrxtSB/xLWnAYqpiJfNu +juoTFNXkjL1N0pTCv0sx3px/fs7t3aWQmRoFRyWLs5J2Zgx1SuORh33DcrGp31JsC Qb6EfdfzB4ItFRSL2LYxKqGue7vcwp7zgPH7MsZnKsrW23VLno8iagMrLpeedcQYFe S5WDmUEOBFA8A== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:41 -0400 Subject: [PATCH v3 03/13] nfsd: drop the ncf_cb_bmap field Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-3-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@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=5hx89BSkzY2v98uuzPWE6uI+Zngs30R5FeV2oiZEv7M=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcXgRt5iqRUFIPkDOQ/8Fb9xRa8rrTQ+nF6g EasIHNH6QOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC FfKgD/9Zq/fe4P5KAgyafYTINIurvAhFJMg5C8DpXcAY0dt5IwqiN+MMaWK6ZMhMTLA+il1qPtz N/o7hfVzmmxCe3bQZj/6/gzGXkIQfeUOS6+Rq6AU/Az7PAvM9kSACADsJ9jFPnIYDFlrtr2FYQg g5fQtKUPq5AbVge/zmsExCujXmZp3adhm434bnRsJXWzMnwfaaZG0vv19GCYIuNyBK0uzdkUfEL 114CR+ryL6/iKPzpEWAmrDqJgPs0u+tnAjuVTx0kehTjBrIWqLIf1lQ83HsH1T9x+QZydSmEIuR GLywXyP4IJha21C/18KE9cH3+cE0Qv//P/YXillEcCUuZTk5x37A63lG4ThJiM6bnjvdLicIpdg iNzoSP5b/vbLHHC6LDFf3HR82ZEQwrpy9276arcX/Mz4FfwSF8bRS+KUx3hq9dx/pWdJS2lscWU Mvb8xVjliVLx7pUzvzY93+pPfW4ZpDd+6eEaEXmS/LHh9QaWCAIyTV7N201DPZ44yN2FfsQUT9/ UVVMGHu0YaMehGYmo9X4dGjyw1Jy+JTz9AlxZ2FBeex6wPfjBvGzmWkf3IBXy0yv+ujoomSwzwA P56LAFln7nXEupSxmgohWQgwm28s3M3pbduef0XXE4Q6I6uwoAw2v2SiIlW5Q7LkAJ4nhQ1UEVO dSU5AHKLzwhbjBg== 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 8835930ecee6..6844ae9ea350 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 Aug 29 13:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13783251 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 6895C1B010C; Thu, 29 Aug 2024 13:26:57 +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=1724938017; cv=none; b=DyAzbkax+MYpSIXMOjHhd4g1+0Y368ZwbHP7vTP5STLCJO5xTq92vvqeiLmxzZkIKohxn81VEGgT6p2pKc//3d/Owfy3iuEEU2XMd8BXiPVQQ+hJrJ/wpyzLCz4X2Qz6g0E1knZ+gjedyaohl752rSDnOnRIYJnIptAUxZFJVO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938017; c=relaxed/simple; bh=MaWMQrP354gSUdJLpaSky0LlkGF4b0/cV4bjc3uboH8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eE0/sP3hm7nFCkZ5YBgu8vJ/6xIBunmjxHPseLWDQOwmqip4rKwejSwqjy0nB9qHmiOrsUTS/dBzsOPnorPHShQRtcLu5jC5vMNwNb6HrJLLSPQto0lhe+wY5AbBwhKWMUtM5MnxRZ7p/mUK6rrx7je+LRK/pBjwiDDEb4Yk3mE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cb4KzafM; 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="Cb4KzafM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88830C4CECA; Thu, 29 Aug 2024 13:26:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938017; bh=MaWMQrP354gSUdJLpaSky0LlkGF4b0/cV4bjc3uboH8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Cb4KzafM1tnmU6Ky3PFc2+nIpGAdE1MvHF2vQ+j+5WcfTWGqTAGWhWZtWowNB4Ppt pkWPC6OspqF9KRBoofvpxTX9bXeipHwVGrXMa4HIU4wmMCoknZSLQZx6TuUxzSOGhG uIdc4VhpK8mpM/reWzOCn9trqw18TlGyaAotYKLc/f+k2QmdLk4zv3GscCLZ9Vu71p iEe5wDPW6mjIgnQD/ewbU4myD4q3x7dVjcM0LXFvieKHRgjOjYwk01vf+d1Z4hVATj 0bVNpaI+itQoYGgqaQk15xS4CvSKM3f6+B88llEz7C/LsHuapHQ8hLYW00/g/KHDfp IGhgr47y06/qQ== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:42 -0400 Subject: [PATCH v3 04/13] nfsd: drop the nfsd4_fattr_args "size" field Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-4-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@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/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcXp7eEVqWw9rNJfgR+aDv5hXH8B/9mDXh6+ GpPWUAxqSKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC Fa/JD/4r7w+jyYm3ge5G+roPkaKwtSgsDJi5/mlsIaKhiNYLCHgoKaK5qC+lG2OPxwrBLUmj689 gQHeG9BRI8bhsMw+PnMgT5DFfo3v4w2R2jZv2tKzL+fravAb8HiHWhqOmj6ZsJBEI+knRG1ZGAf iY2+74GUt1x1QEgg6o2WXfVY6p4GHFk6SpFaiRhKBKNiyPfyQNToRIQNi5IOkKj3W4+3s8aGHq0 Fhy7HSgijngT+Tav/s3DcSjFojVWfCkKgikguD6Pqb4d/lMStDu/bVfH1PhnyHCDKHbZIDPKI7k PngKpQ/Ho08iveBrf1fc8z38vmbeIVCcuBs5d+6oqN65DFuF+OcPZRHkIWvG8qtrJqp34rON70x uD+emCOXX6quaB1qy6WqdR/e/lhCRB7+N7oqHmKTohNVqz9f/pNVrOr/HBoY098s6gqf93P53lH 4aBYkQUi5sl/P9ElqBpVJM9uFI0VqzccdZxMXcOFtbzRbpeUy+4eF+k9xxWdQHQ8gaKcAiXrSte N3C2ob/fcWY4vkcnGInykKYtiEOlvhoYyRRArQ0bfRE5X2o3PLlNMlzs1BSDWAEBEbbFJ64wvUa fmQaevKnxYQhGxFkLjfmNmFj/nGKHN/Q8aNU/a70PWIDGrbyWroO7arEu5MpeZPRYkx/vIQ4xqJ rlm2gtkIjIuYxPQ== 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 Aug 29 13:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13783252 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 330F11B1414; Thu, 29 Aug 2024 13:26:58 +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=1724938019; cv=none; b=Hchz0Yf9eMAxet6HxzeazHGFvUNQJofeQSbZOBOQnR7eUElquHG8Q4Y62PSId/fg7QKLubiIPcoEwM0sExdL7J72YUYm+CS7LGs3exBEB9ului1WQd0Q+bzo2JQLJIky6Hl9U9v9ltMP8okGinPv2EUgO5SCTrv7fNZlRJk1Uoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938019; c=relaxed/simple; bh=Py7V2TezOV5i6M8TumjM3litrx+m92p6vW6sSsvwfIo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nYcEIrKLxnseVvg0/XMDV0Z7qWm8nNCBFe/dc5QsKGlFQm/UIAljpfhibdgFkfxNu398Xms0XSppWTh27eVqjhyPvv9Bi4V742bVfXF/h44LhUUbxExnxjNyyCXSDO9r7Tr8pXX/SLgn/U1NaYw2Aee+c8Wb3b0HtvIrVA/owJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r6SiqbJQ; 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="r6SiqbJQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ABD1C4CEC7; Thu, 29 Aug 2024 13:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938018; bh=Py7V2TezOV5i6M8TumjM3litrx+m92p6vW6sSsvwfIo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=r6SiqbJQL7SkEqYpuWjRzKn/O2DSMVJbbB9oY62C7V92HXE+ZJELLqMmdahqdmPHw LYpDEqLR0riplZjvfMFPf2os875uNgQQsDpsJb/tjbF+N1LmYz4MDUeYYKrI9DEAJl pLbn4FyO8ChVPjC1eVTnPYpHmDhV1+KuRRqs8Cym0yHAJBP0x4y+u/2NsNnAqxgwBt 7wVKXQ1d9rS9+k+2hmvxoFW5l3Hq5B5PaY8GhS73jf8y2HZWd2vQ+ovJEVCpnnvIgn QQMJsBWzJebum4Cn8U1WH3OmE1LFxd6Hm0lbCcpXwIwpyJJS0DPBNhkHEaqrwI0Zv7 rNCcllj12UQrQ== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:43 -0400 Subject: [PATCH v3 05/13] nfsd: have nfsd4_deleg_getattr_conflict pass back write deleg pointer Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-5-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@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=Py7V2TezOV5i6M8TumjM3litrx+m92p6vW6sSsvwfIo=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcXBGB3QGlLF9cFPT1o9pNMsrfkB0OE+86Ox A4X/QMlageJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC FQjdD/9TBRqObrgimJSopCjAxnb7v+ULm6jz2S0ugsqFUpVp2OPSs5q1cN77YDlGzKiN8wJfuxR XuNz8kHIGAeZN8N7eDOs1EHKfVHKlphgCjnIp+I0irx51rN576iEVVyiFi2pOI5uzbvpEQotxO+ Fnl7zJwd51w+x4+iOLWc9hwPxY30foguvSW2PQ9DsMlEqeqblt4uFxYZ/6PRu1x5DUpfHi/VLBW JYsJJAKdus6BVQtM9EUAxleBQ/1wgPTceGomR6fhJtOu9Pd2YZgBZsbnwu9sUAhgqjJQldGdMYB liDk9+3UsLs24XHZo/4funvj7qwe8os1KOCncL4osoWPc0OrTSD0QQhtZTmZd4et5xv08XIX3X2 W0T9B4Rvoro3rC1utwgLyL9yGSXI2ZslYiutBauiLULk78IuHAfLdTeVvBOnSTs10TM4utHMY/l wLCPebf7PncXheUeT0VN9TEKbnmcwthOknccYcGiLATBu+h50/hugJ1bTok31m58QIuozuXmxzx s/tc3fW/8XHyX2uKG9xgcIhjAseNVDwPQrNzihKjuh4nu7qg4y6hs67wWNbMB8ElKsvCtrw3V0H pLo2lKAigTtAVS/fdsf513xLpWGVyqispqp32l9nvIBN40SDgPVTYVTL9hL3WuZYP5HPANHDZnP vkXfqjX57VNNtpQ== 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 6844ae9ea350..dce27420ae31 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8810,8 +8810,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 @@ -8821,11 +8820,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); @@ -8836,10 +8836,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) @@ -8905,10 +8904,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 Aug 29 13:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13783253 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 7D1451B14EF; Thu, 29 Aug 2024 13:27:00 +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=1724938020; cv=none; b=k60/qYLGy68g6sq5p8l7NZ1q6XwyhaJItv0JXPoqOtmeQIPIV423s65MknvB5y8Q+9hF7OkS8TaJi3SF+bGsNDlFGvTLt08GPLM4vBiTKFY5QxX/i/cznfbry06zgBMppHQMXBHLeTN6VDKTz1EWw/xMk26BmJql7ACzh0Yc4PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938020; c=relaxed/simple; bh=GQfTyF/AcARwsbzaU/KY0v6hOHNiP7v1dRbh+dwXikA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qnjJmvuw47TUziwJFe+xgrAtFKXW6I2QE09A3vN4OYyusK44oDkotfhXHRHnyt3pNKbrHrejZcrCbEjIibqKBONzQ1e4Jb9OJUvIwVVqcQ2egN4kKZaNsTLPBCxz1yIAgPzidb7u7I2izYo3lxwvaWRWo+VM70VQddwosicb2pw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a8kgqg1/; 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="a8kgqg1/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3CB4C4CEC5; Thu, 29 Aug 2024 13:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938020; bh=GQfTyF/AcARwsbzaU/KY0v6hOHNiP7v1dRbh+dwXikA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=a8kgqg1/tnDu/gVg4Axwb68NgOqMOCgZ0lPQ2cfB9QfW4finULuz7AArTVF69zplu FNKm/vTHJeV9XgdfDzo52xiZiOvg46kJIwTeKKmGFrj+SHRMaZpn8IeLu/gdQuZuiD Hr2FbN9sloZu5WvEEA5M7APSRVPEOb0Uttu7whIsJVpQ845385V0AxDUQhwbYBa0xv wjaLXVzEHPNat8Cs9uKyJBoHVjBhZMFniRIlTICwdkCcMwJVA2IEOEFntAB7PjMtNf lNmNztC7snKpKRNK1DJSogI9ysSLeYJLlW7YlTQNUWVzmTjXAGC8vu1USyHMpNlyhN po2ncTzagvRVg== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:44 -0400 Subject: [PATCH v3 06/13] nfsd: add pragma public to delegated timestamp types Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-6-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3577; i=jlayton@kernel.org; h=from:subject:message-id; bh=GQfTyF/AcARwsbzaU/KY0v6hOHNiP7v1dRbh+dwXikA=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcX4rCy9GHuSvDRZgq4W6AGu8yb9mN8W0Yz2 g8UBSXdM0KJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC FY7yEACvt3wKQELfcV82pU/7XcmpfkMIXpUi8FnJIFedhZGDVOws3OfqupeFuppwe/1yNTj5ccI omTmY5o24Ki+yTatvNJ8oaUs9lyy6R5F2Xu+PV1dMNeBW3+/107pPMglaaQ+pFxRAdEvrZAPGLr cFqddPmomMljAcQhUOQbYtDUbjmdOUZuaeiCJqxkmsSqcRTPT1zkgwc17OFeh1VqXXbDxl0K+kd RAn944dPSfqFO6DC6w0hXK417sx/5pXglf7KsoeN0UK+bThgqT3AEF3nxzEwqEzAyYfIXk+oyTg 3PnrPJmZUxl8ZhLzx77zsdnAvrbsxJHRNhFlv7fBg7EEPmQQ0/pS/3RcwC57T1BM1uST/HAo/Lu GZuqvmycnItH4GJeO+XYf8xGqx6MY2AQA676K7+iPMjKSt798H21Xmb/+U6SjWmHCf82WT6+IsP 2O3BgrO34mdxziFyswOIVBNqUIRwxS9VNF0wiDH8SccamVaf4VDGjAwzr2lRbSR388P2Yt/A2CW y/2kMmCKL+gELnfBPtIIrlwH36ldw36+zNhco++RbQbe4gDxxZ8UkJP+nghKHPSHIfXRWxxDssr gvO1fpIExnlzXusGJKUSuG4Yf+and4crW8vuj1wBXU3Nkz0vBjS/xudEtoIQr+Vftx5m+mEOQ3E CNRtiY2Z1lDpeGw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In a later patch we're going to need the ability to decode the delegated timestamp fields. Make the decoders available for the delgated timestamp types, and regenerate the source and header files. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4_1.x | 2 ++ fs/nfsd/nfs4xdr_gen.c | 10 +++++----- fs/nfsd/nfs4xdr_gen.h | 8 +++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4_1.x b/fs/nfsd/nfs4_1.x index d2fde450de5e..fc37d1ecba0f 100644 --- a/fs/nfsd/nfs4_1.x +++ b/fs/nfsd/nfs4_1.x @@ -150,6 +150,8 @@ const OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010; */ typedef nfstime4 fattr4_time_deleg_access; typedef nfstime4 fattr4_time_deleg_modify; +pragma public fattr4_time_deleg_access; +pragma public fattr4_time_deleg_modify; %/* diff --git a/fs/nfsd/nfs4xdr_gen.c b/fs/nfsd/nfs4xdr_gen.c index 2503f58f2f47..6833d0ad35a8 100644 --- a/fs/nfsd/nfs4xdr_gen.c +++ b/fs/nfsd/nfs4xdr_gen.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 // Generated by xdrgen. Manual edits will be lost. -// XDR specification modification time: Tue Aug 27 12:10:19 2024 +// XDR specification modification time: Wed Aug 28 09:57:28 2024 #include "nfs4xdr_gen.h" @@ -120,13 +120,13 @@ xdrgen_decode_fattr4_open_arguments(struct xdr_stream *xdr, fattr4_open_argument return xdrgen_decode_open_arguments4(xdr, ptr); }; -static bool __maybe_unused +bool xdrgen_decode_fattr4_time_deleg_access(struct xdr_stream *xdr, fattr4_time_deleg_access *ptr) { return xdrgen_decode_nfstime4(xdr, ptr); }; -static bool __maybe_unused +bool xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg_modify *ptr) { return xdrgen_decode_nfstime4(xdr, ptr); @@ -223,13 +223,13 @@ xdrgen_encode_fattr4_open_arguments(struct xdr_stream *xdr, const fattr4_open_ar return xdrgen_encode_open_arguments4(xdr, value); }; -static bool __maybe_unused +bool xdrgen_encode_fattr4_time_deleg_access(struct xdr_stream *xdr, const fattr4_time_deleg_access *value) { return xdrgen_encode_nfstime4(xdr, value); }; -static bool __maybe_unused +bool xdrgen_encode_fattr4_time_deleg_modify(struct xdr_stream *xdr, const fattr4_time_deleg_modify *value) { return xdrgen_encode_nfstime4(xdr, value); diff --git a/fs/nfsd/nfs4xdr_gen.h b/fs/nfsd/nfs4xdr_gen.h index edcc052626de..5465db4fb32b 100644 --- a/fs/nfsd/nfs4xdr_gen.h +++ b/fs/nfsd/nfs4xdr_gen.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ -/* XDR specification modification time: Tue Aug 27 12:10:19 2024 */ +/* XDR specification modification time: Wed Aug 28 09:57:28 2024 */ #ifndef _LINUX_NFS4_XDRGEN_H #define _LINUX_NFS4_XDRGEN_H @@ -88,8 +88,14 @@ enum { OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000 }; enum { OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010 }; typedef struct nfstime4 fattr4_time_deleg_access; +bool xdrgen_decode_fattr4_time_deleg_access(struct xdr_stream *xdr, fattr4_time_deleg_access *ptr); +bool xdrgen_encode_fattr4_time_deleg_access(struct xdr_stream *xdr, const fattr4_time_deleg_access *value); + typedef struct nfstime4 fattr4_time_deleg_modify; +bool xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg_modify *ptr); +bool xdrgen_encode_fattr4_time_deleg_modify(struct xdr_stream *xdr, const fattr4_time_deleg_modify *value); + enum { FATTR4_TIME_DELEG_ACCESS = 84 }; From patchwork Thu Aug 29 13:26: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: 13783254 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 7BDFE1B1D7E; Thu, 29 Aug 2024 13:27: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=1724938022; cv=none; b=RBlRq7HU1LOsL58PxIZLpUhT9ahaKpE8Xc+gUoogPJlADdQtgxaP3b8AizG8Eu5MKixkedHMqCzoyhvc0YIuzpIExb2tloN8VEU1UcBEFzINRkkxKPb9aKzmLhMfmqZWIMg2BqNTswZXDGirVsRNAqgHKs3EuD/07QZwG/jVCT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938022; c=relaxed/simple; bh=pVaH1LHqhdQGUFEAQ7AUGt94Yn7itEwch5SjAslcLWU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IBrTDNPiBjHpHALimGjiPOctVke7JHWCZv4AQ3h1ftSfDrT8ynFhi7lqAnlPWe1WYPIgTx6LnEUbFd0e2DySrOmthbOR47OmZ1NNkBwjY2+O7YDoCGYO1M+kLlq9NMkUDWE+lCSogW/gjlEQKgHSlnwz3dfeReGbkYaZVHDCMxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZXSQTtAM; 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="ZXSQTtAM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 973D5C4CECA; Thu, 29 Aug 2024 13:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938022; bh=pVaH1LHqhdQGUFEAQ7AUGt94Yn7itEwch5SjAslcLWU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZXSQTtAMW3s3v5hD8FpaNzbUYsx6fnCvUqsWjOI8yeDmMaasYr6wIVrWLFAHXJ6ub vUlMFV/tZfgYV+5f1zMdHSdZNYQUkPb4lXUDysxM0gkNYXcEoKkjrD+jwHI+5FQDGi 9ltPiC4iV4yt1ckxLccm287cgqIarLD0qgBJ+AL7IfmtPh2IkKNnDbyv2xNG+YHHqO xWiRa/8yDzPp/iraGRkilpo6VPXVeaP1OnCB+vkb2EUha4dPc2yTT0lNohPmPpa0s9 /NxvYBSKGG27z41MIDQhx+b3J30tVyAoSMCXsST6b7R7Oehjz2RwGo/jQWvDBeTx46 yYGQxWj8vsskw== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:45 -0400 Subject: [PATCH v3 07/13] nfsd: fix reported change attr on a write delegation Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-7-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2425; i=jlayton@kernel.org; h=from:subject:message-id; bh=pVaH1LHqhdQGUFEAQ7AUGt94Yn7itEwch5SjAslcLWU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcXlKGLUObjKw7MftfDofvktAwCy2viFC5hn YwULaJq1umJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC FWHPD/4iUbrED2lUz4EZc+7rrCLF0oz1vmu3SmI2Cv398d5UaPXw2JMOy9jNhIsYDqGWXezHMB3 CJzAQe0zzdlUrNKoXxS4khOSdOaYM2Yzg/CWKN0zc1MaxCmw8UaARPC6FCFjVJYYBxI5eWI13WD QSYwuHnwxE5O7kW4QK9TTsu6UXGpW83w2pQpzrJFsT6iS8Hgl1+viG6OZZxIvHAPUd/LOafBil/ cSvLjQ9JZ61EVgE5DU0NfEcKw9udMJENKnREDJfq4FFk12zxDIQ4pqfK4nsA3QIRHtbub6s5fzT aEjkRfptwVGOhzOEeR0SS0fjZE04cUfcOgxtY7XxGRCRV5jyyNIXpD3QDntIVWmFhEhfZ519ddG Or4JowxCUYDqJZrwvEkCYwT3fRDh4xjfXNwBKYn2hINcumHB0ugt3P3xfQPd3XORxBVWhcJaVpY exB+uiSrk9CSnBU7+l4JOZDlQQT5YO2XrUSuqa15nztsUz3xQ6TpkeFRICFfzPgEe9K2gP3OYEG NDPVadUtTFGLaGCXrmSrF2oIJrgMVLwSxpCyCb3Ool4qnwLDhh6aYbLY8VScuJfSt4DS6ugxa/J VKwiN9V3bbOh9B981Rqde9BtCrWooUu0ax83rXy8XUgx1myyO1E0Urgg7Behtjmyj4cJtLp/cop JK7emeqGkmG0Mdg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 If there's a write deleg outstanding and there are no writes yet from the client, we'll currently just report the old, original change attr. RFC 8881, section 10.4.3 describes a way to report the change attribute. When there are no writes from the client yet, but the reported change attribute in a CB_GETATTR indicates that the file has been modified, then report the initial change attr + 1. Once there have been writes from the client, use the value in the inode instead. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4xdr.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index ccaee73de72b..a9827bb8a2f0 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2928,6 +2928,7 @@ struct nfsd4_fattr_args { struct kstat stat; struct kstatfs statfs; struct nfs4_acl *acl; + u64 change_attr; #ifdef CONFIG_NFSD_V4_SECURITY_LABEL void *context; int contextlen; @@ -3027,7 +3028,6 @@ static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr, const struct nfsd4_fattr_args *args) { const struct svc_export *exp = args->exp; - u64 c; if (unlikely(exp->ex_flags & NFSEXP_V4ROOT)) { u32 flush_time = convert_to_wallclock(exp->cd->flush_time); @@ -3038,9 +3038,7 @@ static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr, return nfserr_resource; return nfs_ok; } - - c = nfsd4_change_attribute(&args->stat, d_inode(args->dentry)); - return nfsd4_encode_changeid4(xdr, c); + return nfsd4_encode_changeid4(xdr, args->change_attr); } static __be32 nfsd4_encode_fattr4_size(struct xdr_stream *xdr, @@ -3562,12 +3560,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); + args.change_attr = nfsd4_change_attribute(&args.stat, d_inode(dentry)); 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 there have been no changes, report the initial cinfo + 1 */ + if (args.change_attr == ncf->ncf_initial_cinfo) + args.change_attr = ncf->ncf_initial_cinfo + 1; + } nfs4_put_stid(&dp->dl_stid); } if (err) From patchwork Thu Aug 29 13:26: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: 13783255 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 3E72B1B29CC; Thu, 29 Aug 2024 13:27: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=1724938024; cv=none; b=lLEOdfJinunSyo8yBbSf0MhlbibRsG18kMDlVO32aCT8ijhpUQlCSWj/isB+OjyrokGvQONkM62Sz/GrLhiSzH+7B7SW2PyqMFLTEHwFHEHPqGbw7hkMaGECYpKB9zmUNTL7c1cdFYeCr26ZRAcS93gu7/ChQyCqZb1qezns+xE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938024; c=relaxed/simple; bh=RTtljvwynX93vIDKZhhaEQYmk0aezhi8afLpT+S0rFI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IbhVr+P60wpMkS/LF++70I919P8aViQzQPS9ARq4eJVz0lbV/BCq0W8lYvdszrXPkqiuKad2CJcbH2DtIz7p8QAYgFJbrv/3gyW8Wz+2EgLK6uMqEOXboYP3/ZmrMeuSPyHBx/1jSgeEYfCs7bVCAKKRBzCh0WtytzRLddNE/kQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ijFnXcba; 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="ijFnXcba" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DE6FC4CEC5; Thu, 29 Aug 2024 13:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938023; bh=RTtljvwynX93vIDKZhhaEQYmk0aezhi8afLpT+S0rFI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ijFnXcbaLe9xUgRZXn0NOa0SzFQKt/WjUpGBHvVRwl7/MuVfvzWpONgmT+q6gQ2w0 qb8i4UMUb6u4X3E7hVrJ3W84+oEIJOfRc3O/it6bv0bGeEH3/7X+DeT920Ap6bscGZ +F9plPpglqKYpa385hj7peoW/cuqpdcm2Vk2swW+8BE9sYgeZNsLJEZaJ14H8ucuvL aPb8mq8Q2Sqyd5sYYTWPHelhaixnsskWV0jrcm9JRIsWqfY2TdkxY3ThqcDMNQ/IFb s770S1B1HJYhUrOcNWqetcbp/ZWDEx625cfgeei01Eun5usm0SeukB96GBzEw9RHrQ rG2NoaRizR01Q== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:46 -0400 Subject: [PATCH v3 08/13] nfs_common: make nfs4.h include generated nfs4_1.h Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-8-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4231; i=jlayton@kernel.org; h=from:subject:message-id; bh=RTtljvwynX93vIDKZhhaEQYmk0aezhi8afLpT+S0rFI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcXzwy82fkbxUqUvVZm2GvvVf6Xy5kCoy7EE mCgJqZLY3mJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC FbBQEACIPavoJ3prq+7lSABLfVtVxwzS8UZJMVBl6Cv+DfN29EtytU2JS0CGTy4eAO82Rn+hCnz FFaUU79tsmLWZc1dr7cSb2ucw7KIJX/PYCATzoAF+O2p6z1gTO7uTauGkQSpezS0fOxjboO9DDo chbf3C/h1lur7Ke3tl+gCSco2xiUqvenJ3GQNdHzBM2TMS8OctrHutOZFk8h2Ww4jA6ABt518Sa AiUNNNKR6jdG5bYtpTNjDnyhS9DS+FKvY9CJ2geQx3BGRkyYDSGikf9wxmZYnG5kbV58NBeOIwB y8WwgJLU9OX1XQ34NIRipH9+9J3nq3IsUIgHf7cofIhA1DzUShPIM3aTJ6ZhxXnO1cFcqviYvjX MHJdsQnrKCS9NEZN8XRBx6lMqEfsHJfNkmxgpCnfY2yCXMGLleBUNfx2CV/QJSvuowEHybiWzsZ QEsaaWA3y1OXfCTo8WqacfkhEr6LHEoz7d4Q4LicSqPaqTAcYEdNkKp2hMslx7El2AFHRI1UBsx qXqgkgHe/SbnwbFtZEOMp5LD9eqiqxABmfZIlHZS75bXq4k9Jbu+txSvuM8WZB1uldES3jTLYGY JzGOHvDI937JrGqRM4xelekoXqcqLjJpDhbgPUOMfkjXedX6XScNncaA2UI8TB9WcQ7euHylozH GCGuVbJukv5R6eQ== 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 the spec. Move nfs4_1.x to Documentation/sunrpc/xdr. Create a new include/linux/sunrpc/xdrgen directory in which we can keep autogenerated header files. Move the new, generated nfs4xdr_gen.h file to nfs4_1.h in that directory. Have include/linux/nfs4.h include the newly renamed file and then remove conflicting definitions from it and nfs_xdr.h. For now, the .x file from which we're generating the header is fairly small and just covers the delstid draft, but we can expand that in the future and just remove conflicting definitions as we go. Signed-off-by: Jeff Layton --- {fs/nfsd => Documentation/sunrpc/xdr}/nfs4_1.x | 0 MAINTAINERS | 1 + fs/nfsd/nfs4xdr_gen.c | 2 +- include/linux/nfs4.h | 7 +------ include/linux/nfs_xdr.h | 5 ----- fs/nfsd/nfs4xdr_gen.h => include/linux/sunrpc/xdrgen/nfs4_1.h | 6 +++--- 6 files changed, 6 insertions(+), 15 deletions(-) diff --git a/fs/nfsd/nfs4_1.x b/Documentation/sunrpc/xdr/nfs4_1.x similarity index 100% rename from fs/nfsd/nfs4_1.x rename to Documentation/sunrpc/xdr/nfs4_1.x diff --git a/MAINTAINERS b/MAINTAINERS index a70b7c9c3533..e85114273238 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12175,6 +12175,7 @@ S: Supported B: https://bugzilla.kernel.org T: git git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git F: Documentation/filesystems/nfs/ +F: Documentation/sunrpc/xdr/ F: fs/lockd/ F: fs/nfs_common/ F: fs/nfsd/ diff --git a/fs/nfsd/nfs4xdr_gen.c b/fs/nfsd/nfs4xdr_gen.c index 6833d0ad35a8..00e803781c87 100644 --- a/fs/nfsd/nfs4xdr_gen.c +++ b/fs/nfsd/nfs4xdr_gen.c @@ -2,7 +2,7 @@ // Generated by xdrgen. Manual edits will be lost. // XDR specification modification time: Wed Aug 28 09:57:28 2024 -#include "nfs4xdr_gen.h" +#include static bool __maybe_unused xdrgen_decode_int64_t(struct xdr_stream *xdr, int64_t *ptr) diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 8d7430d9f218..b90719244775 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 { diff --git a/fs/nfsd/nfs4xdr_gen.h b/include/linux/sunrpc/xdrgen/nfs4_1.h similarity index 96% rename from fs/nfsd/nfs4xdr_gen.h rename to include/linux/sunrpc/xdrgen/nfs4_1.h index 5465db4fb32b..5faee67281b8 100644 --- a/fs/nfsd/nfs4xdr_gen.h +++ b/include/linux/sunrpc/xdrgen/nfs4_1.h @@ -2,8 +2,8 @@ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification modification time: Wed Aug 28 09:57:28 2024 */ -#ifndef _LINUX_NFS4_XDRGEN_H -#define _LINUX_NFS4_XDRGEN_H +#ifndef _LINUX_XDRGEN_NFS4_H +#define _LINUX_XDRGEN_NFS4_H #include #include @@ -103,4 +103,4 @@ enum { FATTR4_TIME_DELEG_MODIFY = 85 }; enum { OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000 }; -#endif /* _LINUX_NFS4_XDRGEN_H */ +#endif /* _LINUX_XDRGEN_NFS4_H */ From patchwork Thu Aug 29 13:26: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: 13783256 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 97E721B372D; Thu, 29 Aug 2024 13:27: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=1724938025; cv=none; b=rWuYGS4iiCA9rJM0ib5wh2jopdUCrp3Mbed5sHxn3o4acl15U/N2p6vnzTYBmLzRKMrj6/p3H20JGVStYJ7tL7fCKnZZvm/sOO0CnPWfNWxvi+J7TS3Y4CjEvRg1TR6OcvJjTWI0lyTRIw3+TyLmJ7bvf+QT8pEATWjUDI3gn2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938025; c=relaxed/simple; bh=XP3eG6tLbFwyyAoMBoeZ16l1O/uJyxUNuU3OGpmKOUo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pa0OD5Ri6ZF0guIJWO820KXLBIekBtOWT/oAWxKoyZUtnm5GftxdNH8OLLP6SGAVyL6ucgaXxwjZZg99Rn6Rm45LTPC3xJ2yMhRt1Q7aq9Ljdb4WOfSk2K+zEBERK1pFtn7GgaILT9WNVKQs2mMaEKBxZs1/k0qS8jIP+AkFW2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D4aYEzfp; 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="D4aYEzfp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02F37C4CEC1; Thu, 29 Aug 2024 13:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938025; bh=XP3eG6tLbFwyyAoMBoeZ16l1O/uJyxUNuU3OGpmKOUo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=D4aYEzfpsQEhyUqp8xRTiU/Ah8DewiE78gVUusimWWmJGmfx7gYDiPhTP8EAJXyGv gWmJNfflKE++5e3eBFQ75lOu/uUKQmIYcNP3QKD1tAxBnWXYu97mrAC1p19GELjnyr s53TFNwHdMtoRDpD59WLITzsylQ4FE2u7/NkLanZjj+wB7BtSJjbX1NQyXXZsa3Z6N sjAsWhPpgbGQH4goZRcC67dqS9kQcYqQITCZUiFRiBVsyvQU+ZBDOua6ngWSTNzBOx nL6qnwPpxqwFaDiB0vk1H1jBrE5rbs/BwZpxp5XP/6huEi+q8ZhnmHzHRbBx1E0UfP Dd1vEUDO8iqpg== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:47 -0400 Subject: [PATCH v3 09/13] nfsd: add support for FATTR4_OPEN_ARGUMENTS Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-9-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4252; i=jlayton@kernel.org; h=from:subject:message-id; bh=XP3eG6tLbFwyyAoMBoeZ16l1O/uJyxUNuU3OGpmKOUo=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcX+dGMtmCsZPu8ruvvIKoC3em3P4CAzooaP JWAdZKja0+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3FwAKCRAADmhBGVaC FRMSEACkUBa3QcnY+rgXlU3ROyUqw95mUT64Jihfk/ocnXO59a4IJ8/yVKF/UqlQmYVKDCv8CpZ X6zu2bVMSAHJF1LZNaNqQ3rpUG6ETG3yY/brWPidruDTFfgM/NaoM/GqzK2pcLpeKAnM7o53YUc DVPA6S8JNr2PwyipjrjD4fZ6/H7O4c+NQIr2qGMeKcuPuHvhkGeqmUGbtwHlzkyjBSnAjIAcLcw EJqtHSyY73/q+XTZU/TeZIN+NlogdF79qrazAXUFAYHH0I2t6F/mH9lnrrN8gRphfHrRKarYbt9 F2XpRs2/yhw7tooaDrsrS6G3ggUFIptFxWdMpsPeMEjcflL+PuAKCmiDh3KGvj7VViPst9kBi+S OUIFqBEVSS4iag0wfJCMD6PNgQRTB4SliKmx3khL79tamdxkI28FhTkp73/7wMzJshmYTrSZGrx +4F0/TzbQDNF6DpLkJmTyqducOKvlbE31f/dQ2L0IU22IihZ9meLXewuqtUF6ulylq5Axrwfmyf brQDtDUFOuQPFE6y6ZO9jttCKeu1g4hQLtdRvGi5HayooKsnRPG2+19IdZhR90DwOS/HZLKE5qY v10MAfeiSOHULB8Pyae2iziEfiHlPry0p/e2eJsbIKtomnpRk4VpB58TPsyKue5/CL4iflcH1Ow MIiY2EtST1tl3sg== 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 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfsd.h | 3 ++- 3 files changed, 52 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 a9827bb8a2f0..c25dbfa0e7ea 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3396,6 +3396,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, @@ -3496,6 +3544,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 Aug 29 13:26: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: 13783257 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 40D261B3B06; Thu, 29 Aug 2024 13:27: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=1724938027; cv=none; b=I29RlZPLrCKFr63SrVNBhqnrfTkRHFKurbgDUDQQ0MjKlOK4NsGMv4Yt28Zb+fmiH4Xtvgr5TDdwZxTOHOoOgO/4zAOp6Gqnrj/WLaJyYYyQCfMxuwRGjIkyLeWs7yTAYHWQHE9YncG32p0oa33c89TXw02XsaqMqKYdqBHhIjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938027; c=relaxed/simple; bh=JfSKC4ZiR8VXhh79ygO1NACM2pqc9kL0Q+Pv7T9qm5w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YvLF9ESnwbjDCOQf6UEQ8fyKb9rREwOf6HN3dKAc7WL+08j0GkhHJGyYuthQPZxedAfW6G0PSeDCEOLuzBAHMetFp4//BvIKJD4GYLELOrirXPuYB50WbTzy6fzK4HctY49NCt1lECWXlBboitnMX49NxO5xbR8/GdTdICJ8vLM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SBMcz1CB; 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="SBMcz1CB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAADFC4CECA; Thu, 29 Aug 2024 13:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938027; bh=JfSKC4ZiR8VXhh79ygO1NACM2pqc9kL0Q+Pv7T9qm5w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SBMcz1CB3cDw68kftO6jXjH6N2H12TgJnWSp10fJ/3PgC3QqF65XlNQETjGxuE0UN HN28t7Q8TNA0PtZtsR4Y9q1zGC3xvBfzMgGV0U4dbgSyGcuz0PEHr9ByTbq3RdLx4L I9rvmUimMob9UzXltTvGp51B1ia+1YhIHD3+zLXwtC+BBgfBM3zCLTSMsS7nwTr1ao fQFQ5lUI2jl0T4s72wt1K1sTaT+IADI3ih9Mvk4y7dx04+iULctxKLzRNAC/opLv/v i9oYQsikM8MEA5uBrqPA8Y4mUSR7sEMCSnctjvlMYfl671LTZiwiwFeQLP0R5/yBmL y2lHp1R42nMkA== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:48 -0400 Subject: [PATCH v3 10/13] nfsd: implement OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-10-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@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=JfSKC4ZiR8VXhh79ygO1NACM2pqc9kL0Q+Pv7T9qm5w=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcY3VmreDvMgGpOswDK+ElxO7fff+tZqeY/+ DhA8R82516JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3GAAKCRAADmhBGVaC FeEKD/wM7NUk4k/t0RaUvKNn/hkPN9YRxAJXGw8fJ1uOviu+XGyaLBTWVL5Cv5GBj0PjrRgkoEf hDqV/2R1O5KdYLShyzQ5snhLuBzmQoA6n73bJJp+uG2VnqbTzoOquXT1Jip0EMzomu916XAy0Gy XIOL+q5hSOKBFzW7Cu17usocQQjHDe+qQpBKcHtvrr2zJHct/r74lglrbOnzkbTyr9G+eTxBEjZ xnXIkwVyk+ta5ANVqrlhmU/hEu5x3lqyQ3q0nEJZzFtTYKJHruxJyAkKPfPypYqKrIKbdk22d4R uwFPRGIolRBHa3wvUOBGuux6yAaLxT6H6GxOTFoQywL85KXuNTUcVfB02vqHb9x0YF7a7HEakf0 2DHccfB/KaIE6CZCgCwiyx8URli0m90rKTBWQQyLu68VfWrIFxxd7SZ3hX2Xs/CoCMEWpEY+KfV y0+ViAe1UEB3t6bXKWVSn0CG58ySaZbaB6J/jo8H3Jr3Xbi+jU23VmlbbiEYKxp7Fs3DUWT3sV2 Ypt9Jud4SYVRMs9Ih/lglahkBxvQ+h2AC+UTPaLfGno7u1QEnyFfx9xcteeJk0oZpQkniJtu+lS ru0GD5KbeZ74y391TERE5iWDHJZhZZOELvENHIq+iyc7ukRTRZZpAc/rGnQ46Cknr2He3yG6QuW 8Zi0tfZ5oPrTTuA== 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 dce27420ae31..c4e76427af92 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6035,6 +6035,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 @@ -6057,6 +6068,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, @@ -6111,9 +6123,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; @@ -6127,7 +6136,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: @@ -6143,7 +6163,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 c25dbfa0e7ea..11c6079e7dea 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -1066,7 +1066,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: @@ -3407,7 +3407,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 Aug 29 13:26: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: 13783258 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 E90DA1B3F1C; Thu, 29 Aug 2024 13:27: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=1724938029; cv=none; b=UNZehtgZodj1IuQjReOaSV4y7gwSsaNl70rnY7IPSumK7QpvGbf6KzuiqGzjG2PenWMiaB4jP7oc6YwVahDNmxHt0VuaoNKIzojPTEwwVJ3C8bWjkQqJcIAC+ChyHLOlp/q0VnvDPCIxGsnh238YDByvFQwvgHRCBxry4xDfdKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938029; c=relaxed/simple; bh=LiV0clf9L6NQX5LxYkFyOmngi4CQOovdgBWSLgxIFp8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RzMtILGDWneaZE24nknLa/8MWYR963+pTbn/96SxzJ1GuRTAqtuym1gsBsUG6f2QzXEpWM0jrE3xq15chBL30sB5MLZnyTac4bUmrGl8lYBPeYbmVA6JM774Z1DDxoK0TCgIE9jntGIVkHN+6QMl1yX6QukC+gYYyucv7WI4PAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YrHQVTng; 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="YrHQVTng" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D276C4CEC7; Thu, 29 Aug 2024 13:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938028; bh=LiV0clf9L6NQX5LxYkFyOmngi4CQOovdgBWSLgxIFp8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YrHQVTngZZ/1IQ9bDXBLFXR0iubrYHxp6Y4eN6pm/EISlBsHQGwJNxXAG73KAB4eY qbsxXu3Bqs9be5gPNnJT+Z+WFNfoqUCXUEvcQOeDiliDoXSi+rcaxCdbEXW/Q7n44g /wFpSYgD9GzCTLV2J+zFIZsiXoHpS3dNVFegWoNuQXflSLCQxrIyaLbZZ45njh9uEo N0u2G/9j3wTIz+LcuR+vk+V1RTq4Vp3Zw07xWE3CF2TTCQ/eDdXN/H+0pYjM21b38y fuVrCiUSis0DW0RSBOG2Jq4JoG7VYRyPENyuDbZRovVwg5OAOAE4imk0TvCpwL2nug LC+Q3agfPktbg== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:49 -0400 Subject: [PATCH v3 11/13] fs: handle delegated timestamps in setattr_copy_mgtime Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-11-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@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/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcYsGRT/Hg0/UhwWErfUgDndlc9/qEX7oIEH W+bEv3QoW6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3GAAKCRAADmhBGVaC FXdRD/96A29Ruw6BLNUsoLlPcOC5dsqJ7itF/Nxm+ExHHgKpXK02eFmxzq/3sorQHZj+uvIg3N1 rnIZBFls4lOv1sCv3DrzHAnXBx+2H6LE/ZbNr2m+Uthqd/5tZC0rSLnswJ7uVkueo08TrXho9aH nu2tclMvx+eSu7DLkH4QD/VJxTh1HQRkF+QDI+LdLrKohGaLKFs670xcoFIUabhRy9wDBJp9nC6 oPB1ZCYtMDI5rHi5XGCyZ2Wpscfc3JzdQ8uCByv8QHiLGdQ6/6Dlp0KRcusEOABBf95qE7nUyhr HYpJBSq+6DFZtM7mhS1ey0QXTY+bVXTjByuH2dl8F439ye1oMc6BsSJ0tWUP2DVQBRtM1XNBEvB Z674XdGDwKp2N1F746lCblBqjA1mryK6ZClqJ4VebdUFY2l6KLFvBfDqMvbFP4QKhw8rs33L0QZ 98wAGVBGI0g9dQmN9L3Cp3+icGSVkdt6zBlWrbiwymuw+XQKsDKWEnFS+xwcJy+XkC+eegQySmR 5GmqDYeGTlMWgPlWfiBHkTxJnq9pQAI9Tbpa6OTGoyxzPgKIDqz+ZLrN0VfJy036W1lPRPuGlY4 RaV2N+HSQTCOvA/DInAqH3EJ6CoOmZaZkSqmmuXqSERihPx6v5NiLfFfPfxmn5trcuSoNOBIn2I wy1SHvTdob2CTiQ== 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 Reviewed-by: Jan Kara --- 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 Aug 29 13:26: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: 13783259 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 9AAC41B4C3C; Thu, 29 Aug 2024 13:27: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=1724938030; cv=none; b=PrID5VerKUvjA/4T/vCSon/tIdtwJcjngbkXVA513x4OEI09/5MqQ0u+8V4y8ph1QcZLF6lOebkVCaN7eRlPKJDVq8Jlui+cNLUELwL6i1k1K/IkyXztg/PcV4lTqzGSPjPhbEHmrlJ0IGdH8jORUvBLCCqrTZuhmp6hbYBJzog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938030; c=relaxed/simple; bh=q4G/KFRqS/1IAOt8tP8YVw4o6RDhY+bh95uMblQQo1E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ULerjC/mulOEzQKCHiVmw72dgpX7UJ+812Fna1+HHr53zSYbYJc8ZF8ySByL+2PJISgCT0VOownZY3O9ArXAmCnYO/sfNodRzmY1Yx/bTDNkwjFyfUqWR2Hb/bCck1T2bRgDvR0aYxd45GmNwDePLfI5MT4eB/MxI+RYSPVh9zg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mFA/vFJ9; 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="mFA/vFJ9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4F4C4CECB; Thu, 29 Aug 2024 13:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938030; bh=q4G/KFRqS/1IAOt8tP8YVw4o6RDhY+bh95uMblQQo1E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mFA/vFJ9X1KCmf12CO52g+a4quwtam1fBoWQowvMjG6x936eZqC0z2DYRbTDKnWk2 uJMwfmzhQfbYmab//clt5Hz8/DLDjN5ySSwiMHihKdRaWTfgYmw1fLU+VRirF65lXJ 58u0ZNh0O+AzfXHwJBIPBL5yvemEmUzSRQfO20cFjBs8tdof/x7fGccnKYo9XPrcIK OCASg73a21iiIMYuFqg3v0zQmj1xdVT28UEquLbiryuCZ65P6FsRkIVTaBCAR/jSCq l2RWV9DtH+35ezqCdOE/V5TB/W9zHQoRK3nWcxe0AHj8Js7CTUtdVXvXyCYC2N5wUY e9XBKcGvtEnBQ== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:50 -0400 Subject: [PATCH v3 12/13] nfsd: add support for delegated timestamps Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-12-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=11916; i=jlayton@kernel.org; h=from:subject:message-id; bh=q4G/KFRqS/1IAOt8tP8YVw4o6RDhY+bh95uMblQQo1E=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcYKTYq7xyI/pCXxoXquNcssfniGOMteYyVb URTsumMxweJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3GAAKCRAADmhBGVaC FcrUD/9no7zvcsTLlfUrshMnKHaSBLInAPOe183W1sujhKpzs/cwH4o/JSn0UWChsxHb1KwF0bU dC1GQ4Jd/06OM19ejqTKKT+kY1n7wu4Q45odKoFBavEkQL4QChwmmW3oIitu8feLqCG+jdS3+05 5xy4PLqAI4BuwQgagBkaAY4V7KvBZk5GgK9A7Wre+xmc6A5qZ6sryP/Up82uCTkSuma4tRXzldj G/3wnQW51cIfobY1yiQ2WW1zM/Aj8RYXCrBgou8G/2Pbt1wx7UfAzllPe0LHyC6JRUyJbhstlSk 8DScnlUWQ5jDHEjx01Ri5ope/LCfgq9eFRWxbLGvCro5EHPCpflDAvl29Sgvnj2pW5SqgWF/l2B li+opJd49o/XGIbsZ5PpO7aIkEgWpEAjH+TrQhoniKocpBkxuOYVUCDa6YYK1Wxtkz75NUYGpZ9 nlx1eFNi+3kAfp+/An1O9Oaz0IRaMTMDcRred0j+1WvDU6dzmooAatHLNlzHKfk7wOJF7ar+aPq f6/nmMQjIHPe1WYQCJsrtzppvRnj/c2Wp8fsCR4WTJPxSmv0pcm4Yk4t0TzVf7RwIwR3SzHlYma MWSoY4WWCrumJgRff782xThDEXKL8hlmFYZn79Dg0NK7eSsX5Z+kaT2TohgUW5vgAvdqzBGupHW UMwvuzdUmj+nhbg== 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 | 13 +++++++- fs/nfsd/nfsd.h | 2 ++ fs/nfsd/state.h | 3 ++ fs/nfsd/xdr4cb.h | 10 +++++-- include/linux/time64.h | 5 ++++ 7 files changed, 141 insertions(+), 15 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 0c49e31d4350..11bf7439a253 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -93,12 +93,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,13 +387,18 @@ 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]; + u32 bmap[3]; + u32 bmap_size = 1; bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE; - + 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++; } @@ -595,7 +623,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); @@ -614,7 +642,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 c4e76427af92..06dff11c3e51 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5982,6 +5982,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) { open->op_delegate_type = NFS4_OPEN_DELEGATE_WRITE; trace_nfsd_deleg_write(&dp->dl_stid.sc_stateid); @@ -8826,6 +8828,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 @@ -8852,7 +8926,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); @@ -8914,11 +8987,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 11c6079e7dea..557f4c8767ff 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3408,6 +3408,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) | \ @@ -3601,7 +3602,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; @@ -3619,7 +3624,13 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, /* If there have been no changes, report the initial cinfo + 1 */ if (args.change_attr == ncf->ncf_initial_cinfo) args.change_attr = ncf->ncf_initial_cinfo + 1; + 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); } if (err) 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 Aug 29 13:26: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: 13783260 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 A525F1B5319; Thu, 29 Aug 2024 13:27: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=1724938032; cv=none; b=kKEKrmTPgSwjXR7KMR64MyMyfhYrioXmQpNBOa7gR30ruQSCXiurl/teZVgDooBPWGl2rmjqZYYmWyVNvwcwYTfgThN4m0nW1UY3Ova5gbS4woIzT6AcwkDGoI2ilb/bwzisHlrLLH11Gbvf3XHihgQKiJxZHwGUcktOngSmXew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938032; c=relaxed/simple; bh=a/6GHoinSuuHqpamKEatlNRJQO7PI65R0nWt2LL7iyQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qf6fVMutOVgGGte76VoPKKRWDaLyKf1PjH341Zn7q3tPnPs2eFx2TS8/KPGuDF9UDxLpjHjdY73V9N6CQH4yg6py4Ag1YA8ULQixSXAmyuUCiJRBZyem9IDqqk1o4lfnA44BnLeS2+LiRiZPgPRgO5u27WvdbwSfFKDONX/bmvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HpjaACkc; 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="HpjaACkc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B69A6C4CEC9; Thu, 29 Aug 2024 13:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724938032; bh=a/6GHoinSuuHqpamKEatlNRJQO7PI65R0nWt2LL7iyQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HpjaACkc603d9161YTH7Z8dnRAdC6Vz2cZaoqyMJIrDkuypGWGW2FXPU0avcY1qkF cq2r4vIBSpH5+fPg4A8r0bNI+POc1st5LY/BFFo3Ya3hMdlCYS3iSs+Hy0JHjsOkTb 8dBqrlQMVaG3BUJFjbE1LdITL35+7H8fV0hbFMx/vCveKsbJteyaX9YJlVyBQ9ebfs H9mt7jdUfe8u3uR6aFhix+qRymJcXr3mk27NDMM9NyzkTcX+rQt1LUFm59fEFB3ccB iAIBCOkAVOoY5TTW1TPAUww4sHHirYBjbJv1rK4BhY01NYvqc/2drZO79J2Ba4TZ7C IA9rODlr45Gcg== From: Jeff Layton Date: Thu, 29 Aug 2024 09:26:51 -0400 Subject: [PATCH v3 13/13] nfsd: handle delegated timestamps in SETATTR Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240829-delstid-v3-13-271c60806c5d@kernel.org> References: <20240829-delstid-v3-0-271c60806c5d@kernel.org> In-Reply-To: <20240829-delstid-v3-0-271c60806c5d@kernel.org> To: Chuck Lever , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Olga Kornievskaia , Alexander Viro , Christian Brauner , Jan Kara , Jonathan Corbet Cc: Tom Haynes , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@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=a/6GHoinSuuHqpamKEatlNRJQO7PI65R0nWt2LL7iyQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm0HcY9eVwk975rjF/C75K4qCFyhZtQjmbn7Zpo 8QiJ5ZX9bGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZtB3GAAKCRAADmhBGVaC FbUWEAC55y2Xah4VYLt/PzlskKD9lXUM+0OdWE1lc2rFqtFHwRZUfLHWtB4rqsmu4YhCCvW0SFi cLgA3NFhXBfSuOC4mJ8643YAQ45qR3+klyBeaAICoOatoO8Hjfx1XxtsV/dvTt6a+wZzwp1pngt zGyV3dSL1ZDCEbspBu1PfB3nzI0sMZEZ33nU5+0vqE7Lv0ug/GK34sVST+BmZhCgFCXdy2UTwC9 eocPmpO5ou/DfocbXSg0wJ1DqrsYqpZedL3Pkw5Hbxg1JNp6ZEzW4gLhjJz5SoAFuaT2s+Z2Mgq +62EqImb/bGPefUK1fxa5lX/M96/dKV5/OKUGtwej0ZGBip6aQtWkg6L3jQxQjaE2ajW5QchSHC jaDbaiWd9bcYIbK9/vpvnsiLA61q/JtlR0wWwSN8noqci4ElAf1jSZSBuQaVY9vhj2Id53hYk12 nI1HPvBLgaH3EemJUEIhZ9VKC8nJiLu2RAurJYePAJWi5CQjInY/jJ58+ZlGzUgFbrMGnsfSzs9 aCcUPF60OKT7ZFMSZu3YqSKBihyFgr2bFiZHUu7IzDNWVj016AE/1ch5BA7GY/lQRIvJ9JXIEmx C0vQ1E9tiRZT1khgp+QwF5+bksFbeeKy6t9XDnty+xB1EnX84Tj8rEznyjzsc7bZqjtYexCAmam DaYhyt7l8/GmCJA== 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 963a02e179a0..f715dd29de60 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1142,18 +1142,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 557f4c8767ff..3b46014f911b 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -520,6 +520,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)