From patchwork Fri Oct 4 13:16: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: 13822295 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 370692101B5; Fri, 4 Oct 2024 13:18:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047890; cv=none; b=ilvw4SXa9167BmOtYTD34nX5T6O2wB2x7s3/O02q/1Urey/aAsqjO+WVbzbZK569GpwYLLIHxAcykd+vMqvg7UgDQxm6ZayJ14JC16WUulYirXNi4Z7bZOO5PdegdPVnUSRfxMSIjTZREh1lY5+u/J6U/Vaw/6lhlLjioc4CIEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047890; c=relaxed/simple; bh=NAATopYIOPduQBNTxLfi+EHB1Ci0TeOIoS56BM7/U3k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sWnL6y+F/VEk6A8vRKYWCiXMFxzs2tB02HDEWMjeXoEBmcTgXZTIqMsWd4DzXRWQGRp8Gns+DPBsJVGJZVjw0uL2UlJgOKP2kvHohO+FFqS8s9MjKyAy/NHatBMzxnZseMzwHOT/mhYj9orKtmwVDrNzWrEyysTtVU6Ye7IaQo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HtG+lLgo; 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="HtG+lLgo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5919EC4CED0; Fri, 4 Oct 2024 13:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047889; bh=NAATopYIOPduQBNTxLfi+EHB1Ci0TeOIoS56BM7/U3k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HtG+lLgo/vSP7HwPYt+5PREzSL2b3S6PYaklGd9Gkpu46i2F9JCnpQg3N5dqivlvA 86NOjvWNWar+jQQfvRb8G0sIxR26vMveatRCrtpfvKwgk8VWGV7IhBb5w0wjF0W1CX Oc2iS99nFf9eHUXhRumDwI0M/ALmEDjtUYsFk/xCIqPMu1S/baQISt2xkl/K+zeguV doTkWsoGDUIEEu6fIKFvv56Z9NDs76Bqp5TsrI7PMyGf/0M4tKaaeRUPj6BtePuQlJ q2uV57MSIup2qCCiEQnmdc7+xVvpypZpNQYQoLA6pLc8UvIXExrTnfPVD/1TTHztmf 62eANlt4Q+0Aw== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:44 -0400 Subject: [PATCH v4 1/9] nfsd: drop the ncf_cb_bmap field Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-1-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2231; i=jlayton@kernel.org; h=from:subject:message-id; bh=NAATopYIOPduQBNTxLfi+EHB1Ci0TeOIoS56BM7/U3k=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sMVldmBO5NmkJSm+fMJElQf7itYmBKHPHJj PtSDbY0GfaJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDAAKCRAADmhBGVaC FWFBD/0UgGRyM+F6eLw6mjm1bAKd9u9h2yom4ORySYtgEXDJtJ9997yqqGt6k+PiT2L9qlxGY8I /eFAU7C6Kw2SKYOYtf5cIAGWJULvv5fZYgD+FXpOmZTFpYXm4J3HOlRCk/av9YayBZ3Zb9gv099 PdqNJrfKJV9fSsyx4cfRtrXKU/gHmtyNbd3aTvm+X0267bdbE3M7sV6EKsDGCfX4rCZffvbp42H PrwFuCjpRFsB7MNpqSNgyd7N+DuoBvjXwhEQ/6cUCAOPWfpZG392VBxRmvzb+gxIgh5AX2lGApA 4yrRO45JV/jrDWRBKzIUHRY2BehDt/NdMzc/KpTFiys5mhfsaIC9P5thQkE2O5cGpchAMlA92L4 xe+cPYd8Qi9VhRP5wbH9YLDCD+EiJyLfH/9UY96Lpl7Nyyv1PJcjuiT4JcThQ8BFszWcJYC7hdU +oq6MW+H1LazrlhPDi6WM7/q/xUzZKYpaNdfzhc+uScZnmpxoubiZ0mRcEDV3SsxC4YGjuPddvc XeEilVa34PgJ3+4kzamP4og0TZ41ABYy+8bB9cO7p7zrG/4Fx0TUGQ+Z7Ira3DhaVbXDrwF8Xu6 ScalzRBP/4WcSGr62k4R7/i13oOXUC0B8Gof+d6z7Vk11cZGY+l6lTJFOHOTM+X0dDX0x3FTtGu J7PidrnH5kvts2g== 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 478b548f4147f6966aa578fca73925ee456a0cbc..f5ba9be917700b6d16aba41e70de1ddd86f09a95 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 ac1859c7cc9dc7684eb47f4ce025c3fc56e02701..1cb09daa7dc2033af37e4e5b2c6d500217d67cf3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1184,7 +1184,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 79c743c01a47bb1d91130708b65b75b92c697aae..ac3a29224806498fb84bacf2bf046ae78cbfac82 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 Fri Oct 4 13:16: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: 13822296 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 E7B5E212EFC; Fri, 4 Oct 2024 13:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047892; cv=none; b=fyCHL1aOMREGcNG83ZgqZZ3Dc9gHN+OvfS8KZc8JW2GlgSRpq2Mn0juFOzt1gQdR96MLACz+qaJduaw/lHe3JYhofBY19Os5JVWP3HiKbL4o8RlsiPnZMVPtE9/4vR50GfMAOclP62SK/gwoKCMzzprfTg1zj5PxjyuWpgASO0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047892; c=relaxed/simple; bh=qIcIEGGQ/FpGTUfquS8hLgwdNhcUXdbN2aVRHezbZRI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e/CqeaBTcBecG+H1gVQ1OygwfWdnCHDkug3zDlLsh3LmnhbPxYkVwqfMZymzSmTxv4O/KJGVVAbid3mDSZ6Be/3mOUwMkldBafk7bJvpAlIppigC/pKgN2bk5C/gzKhQHcHg6Gerwhh6A1ALpKjjs+PapvyxOs69NonkqoxFA9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jzS9FIQc; 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="jzS9FIQc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 099A5C4CED3; Fri, 4 Oct 2024 13:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047891; bh=qIcIEGGQ/FpGTUfquS8hLgwdNhcUXdbN2aVRHezbZRI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jzS9FIQcYAxMBL8nwDZTCrfXpUKlGAEplQVfHqUj+zkkDXeARo+8SXKhN8gMNhqNz LfyUck5zOhQD8bl2gE+6fisRf9IIVTlsAwiASyhz6RxeLYA0inOdLKUAmLSGq1aJd8 8W9Mtg79ChTG+6bwDXH2LtME5fSlczkuHX+MkMSOGYR1TpBCxOSkPqIrK4WvuXfw7x zcJUd+Ys5lNnE5++2Nj0Wp0mr10uF8s3qpi07oZ/WhlIpD2rC5gcxXvAKTpX5CbEJd FkmDPDPT8IA8w2glKNTHBKfL4LBMpYiZ1Qv5pjb/BUpT8GFyH8rI6wpJumJRf4ycpD alLhKdieOcsRA== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:45 -0400 Subject: [PATCH v4 2/9] nfsd: drop the nfsd4_fattr_args "size" field Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-2-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1714; i=jlayton@kernel.org; h=from:subject:message-id; bh=qIcIEGGQ/FpGTUfquS8hLgwdNhcUXdbN2aVRHezbZRI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sMZ4gR1zcUzpTeD3TgT/Oj6O9ZyhZuiWsjA tvWwfoGPU6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDAAKCRAADmhBGVaC FcPLEACUvXG1+U2RC684ZlDf4RYmNSLaGfiPRnQNdy0OXqBXXwuXh2p18R5pKo2hD6XbxZmnIxK yVOWiDfhNHTOddaZCwzGM0yljUomtZieF53VhMTNzMNeOu5bM8LQ+63ZTQKJJBh7a3oTAzfNNPS j1bYiKAWEgoASK5ZI2h+Vq1E1zrz7i3T9d9N3LnooUHv606dLOOyao5bxVTDQO/002/HceeSms+ 1orqBCdhHTZYFga2KR76HkaI0qMldoebXjw9rl1EuvLYzqHkUxa2yFAFeW4mPCoAlEWWuLiEDFP LwZ5yepNMHlkrEPJ2yaKJumyDMIkp+/y4SjCUb9l1rd3Ru6uEGiNlw9u3GcAAqfFMqSbW4SC14n RDHVdz1VeUGzhDQZnDaIi0lWB+wRcV5LJRzVMju41GzN6c0yNl74Dfv61hYURgsAihDgYX+vCGr F2gXbtGGRgQH8xHnL6AIvzb4bWByKRRXG0RSeXmx5NTsVLIkxPRSbEC70af9J8hmksdRAXwDTch Wi77yaoOsr4rG9kF706m4CHqBhp+YxCS7qqraTIknvRnl/v52x5RpQZ1J/NwCuRT47HEBXw/MzE 6bSi9VfJ6vJRiR5MEXCS3pOZiHstcDQspM/IeSXuF7u9AxeCNbZeVusAg5uVdQwiyfPzB5hLnSK FNQrP7qU4Cm9ZVQ== 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 f118921250c3163ea45b77a53dc57ef364eec32b..d028daf77549c75ba1bb5e4b7c11ffd9896ff320 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 Fri Oct 4 13:16: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: 13822297 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 81ED12139CB; Fri, 4 Oct 2024 13:18:13 +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=1728047893; cv=none; b=F8hGUW/0Rtdqg7p/FHMN24ibJ6hziKoj8cGA5ftWbkZoudBaFLEMFoBoWb3KZeHzW560Ut5/cG8KZDKG0k+lZ7o7GF/f4DpipUQDHrJ2aw4tEj8OtUI0hoDByQopKx88p+Tf6Rd56ob49xUtGZd1JBOagIozWA95vLV3h0noJPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047893; c=relaxed/simple; bh=wdyYzZq0+G9ux3/rTIfsXgQJrGKaLW5LmDc1q+J42rc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EA4bhU4gX+xWcOGZzxGXrWao35DCgzO8a3e2wNZitl5WihiwLGouJsQsssp24++iwPjQ6IVrheCTxDb/gA1hH7+wajljlR/sRf5H9T/4Y7vc17kSVZyt49CC1j2aCnag7pF172Q3cXTs32rkbg46P/EMRRTzajT9ZJnvA1zFsrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O4ElXL6z; 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="O4ElXL6z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1076C4CECF; Fri, 4 Oct 2024 13:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047893; bh=wdyYzZq0+G9ux3/rTIfsXgQJrGKaLW5LmDc1q+J42rc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=O4ElXL6zhPGPLtMH/7UytZRdX/vhodfBlLVvvA5lT3NAjBVquML/uHW8nsCKz/wqc irlv38n413ws8sQmqtngGEwxtviLMQchb3CQTovbJqhChOoCdYXDpuHOz9nDbL0f+X amnRIkBldgjwFsmWDeyGr2pq3gO3GinLsHombSZhSSW9iALpsrWeDD08/rfbMQ2RD5 DrMtbfMjUTlP46kurCrHOBWB6yBYGvxPGqU/2P54uFdc2+gwnt7ix+lUYYUk8BJRqe UlTrH868U8weZ/QoVuq9OfYLH/4cJwd9XkMf9AvJGFEr6fb+ziy8tfTsX6gozR2pW4 PwCqE0gzwWWIg== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:46 -0400 Subject: [PATCH v4 3/9] nfsd: have nfsd4_deleg_getattr_conflict pass back write deleg pointer Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-3-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4873; i=jlayton@kernel.org; h=from:subject:message-id; bh=wdyYzZq0+G9ux3/rTIfsXgQJrGKaLW5LmDc1q+J42rc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sNw3fB1vxMaL4GxIKXO2DXC7BVNXG2Y5bD5 nQIHhxNROmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDQAKCRAADmhBGVaC FSTKD/421tVlQzGBDN4CZ5TMFPBHb6Fc1aDfaux1BSHaqcTJja0Q6ptEJSMXJVcXBDdHH2uQg2P 4J8SM6VzeFwbmYXiuAhBIvLkCv0ytT07DFUBXR+cHrzWWBgtYG+j6ODS5to/CENMEVkg3N0lTHH IdOEJ+JpZxPyH6mTNRdL2QY55UM7heS4XY3XP6eUpiPu/8epgxqFnf/CAoZ7Qsu/nYxTxYyRzd1 7QlpSUG/Si7OYT5VZm6xexQOc9ldHolPDIpo4dTGJVXfcJv4hvv8oErZ/YW0AqraeZFLNIDXbOO m1PtEQ/uGwi8oxicHv92epcrDpwYh1GbebL3FH6df3pT5ULgh4MrdqLoCAFOzrYA81NcO0Tge06 ecFG6Sd5GqwS78ENkegPAVtVm/GmB7o3enmPijPDIypWprvT3DtEgk46bBVTite1/AD/pP8ZB7I hi3JUCquT9U2DKQutP4PzqYRBV3peuMDGphug7f60LEvie9tmHtp/wTkhcwWoOe5zuxDoycs9zg teGXCjKvN5mp+X62qt78IS63WF68jIDkXjFMh/34vUd9+owsaxZ7x55721tzbdyPXpUGxXuSeWt x83iINHSiVWKtvB5fPtuvtup27JEvy8ZY7ql0jX/yvUd0DjNSSaFdz0+I9QVwnjNRj6Rro8Iozs 4T1mDIESSf78AZQ== 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 1cb09daa7dc2033af37e4e5b2c6d500217d67cf3..ecf02badf598d147feb5133cb43225e3611d6d8e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8831,8 +8831,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 @@ -8842,11 +8841,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); @@ -8857,10 +8857,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) @@ -8926,10 +8925,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 d028daf77549c75ba1bb5e4b7c11ffd9896ff320..ccaee73de72bfd85b6b1ff595708a99e9bd5b8a4 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 ac3a29224806498fb84bacf2bf046ae78cbfac82..c7c7ec21e5104761221bd78b31110d902df1dc9b 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 Fri Oct 4 13:16: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: 13822298 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 EC2682141D2; Fri, 4 Oct 2024 13:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047895; cv=none; b=AOLKAd2elgiDRdWjkCVQQWisGZ++lA36xRRXZXFlY7i3H8FZ/gnD4treMODrnEPvwjcbdUhZtYQmFCLbQbS2NHNooXblIUQip/e5goRlSVCIQ8y1NO6hLoU7JBLp/PezLdlMzFtZk7re1Wg6QUdz65fXHVkjT1tkHu9VXkbfIs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047895; c=relaxed/simple; bh=BEaZjmZrCFn46g9RKbQEfujpsBeZomOYq1yB4uwHK68=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b8uEG4Lkp+MXZHQfaohlhiYFsSy8JlRmEkLqPDDr15d55JKBygxoc0ejva3nFwIk3rEoftI2O4ty2NBZN0pqaVzuKsiT/xg6JL16IRyB4+wxcvMK4fxcl6reiUEWfFJ8YEQ3sc+KHEC6ifvB5I6kFKAI7jeD6UbnSJJv9xxdqyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tFVyVRXW; 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="tFVyVRXW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62565C4CED2; Fri, 4 Oct 2024 13:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047894; bh=BEaZjmZrCFn46g9RKbQEfujpsBeZomOYq1yB4uwHK68=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tFVyVRXWIC5qFQa3WVmSWb0ZdW1D3aPkm+BYMJeW5pTaUeJkKCmrBA5cUkqqFzEH+ bhF+kkmgLicqC4xOeMmNcq/Scu/t89UdGde53Q/Wp7U/ugC8+2ULmcUUkl07T/lE6F 4+OO5ISiIPQN4mA3Vc1usZclHD5Hzw9FHCvLtkrEcEiRBsvVUfotlvariRnVb9uz7S wiiXxf3oqxnFGUZZ7y+UWKgA+yPstKcj6CH9vWyqXawlg70Wjjb6GUFWu6E/1LJz2h t1GefltaZJphucRujszur2UKAyN2Jsgop1Cz0aMIHlKaxL6gIQUvTs+zzvXrVNIPmz rVN2C6IwouuTw== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:47 -0400 Subject: [PATCH v4 4/9] nfsd: fix handling of delegated change attr in CB_GETATTR Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-4-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3315; i=jlayton@kernel.org; h=from:subject:message-id; bh=BEaZjmZrCFn46g9RKbQEfujpsBeZomOYq1yB4uwHK68=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sNRkkUvwW6qB98GfYn+EhlO6olwKyXxgBrP uSVlBOwNsqJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDQAKCRAADmhBGVaC Fcu1EACzsboSPSdeurjY/trrae+ybstyR25Q2mUzsNQy9nZqcG7o/O8OgTYJFucv8uPKbFQ/2do T1alSUz228Gnfd+vBHjAx4VXIDsBGk40I4Ik+M7ylVde64J5ZqDCZ1TPiYxcnmtD/+DDVPknoNR jat1bSPR7fz84N0E9Jv0ntRNw04du8gcmHBWFzohjPJWdkctV9yVfLA+LtQUWC3HKrYOEUNKMhH XmlWhQ1BkjZDVf1rMKdHRcEx756TUwIEzeyFZUSvPalTheiXvbbTNoJPhnUqglSW3ZE4j1uSIre NyimZEsn3NyfTKRjgmkUjajWE8nWo36eDrxiDLTJ6MuhXZBsp+e+bjyMIq39ees8i8CmCEUBhaF 8njrKVRhsKsYmxMegVwsvoqCY5a7umVAFFSivMyavYChX3zitMYRc6bz5zLI379cTiJ675kB87Y HpTeQEBeL09viL5Lg/v6EKaIsGzzFBayWBzLpSFYkpnKgdJVLhprV2uetxxCCDEXlJEkmQJ+FWG 5Cs/nd5Tj0ZsUZqAaZE7CW7LIlcfuKjr5zZmLigzhLStTaq0xxIaKi0JMc7qYuPC1k0+Kg+bcig BXB5qkeZQmKmFrSymR0ur0tZUEMzrB3+Sthc3wHfwVE+64gaKz5L+ZIrd9JyOcfv6wDEo6+O9AL Zs4YT4sQ+xcticQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 RFC8881, section 10.4.3 has some specific guidance as to how the delegated change attribute should be handled. We currently don't follow that guidance properly. In particular, when the file is modified, the server always reports the initial change attribute + 1. Section 10.4.3 however indicates that it should be incremented on every GETATTR request from other clients. Only request the change attribute until the file has been modified. If there is an outstanding delegation, then increment the cached change attribute on every GETATTR. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4callback.c | 8 +++++--- fs/nfsd/nfs4xdr.c | 15 +++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index f5ba9be917700b6d16aba41e70de1ddd86f09a95..776838bb83e6b707a4df76326cdc68f32daf1755 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -361,12 +361,14 @@ static void encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr, struct nfs4_cb_fattr *fattr) { - struct nfs4_delegation *dp = - container_of(fattr, struct nfs4_delegation, dl_cb_fattr); + struct nfs4_delegation *dp = container_of(fattr, struct nfs4_delegation, dl_cb_fattr); struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle; + struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; u32 bmap[1]; - bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE; + bmap[0] = FATTR4_WORD0_SIZE; + if (!ncf->ncf_file_modified) + bmap[0] |= FATTR4_WORD0_CHANGE; encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR); encode_nfs_fh4(xdr, fh); diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index ccaee73de72bfd85b6b1ff595708a99e9bd5b8a4..c5a716aa9f79060828eedcc41366e32970dea042 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, @@ -3565,11 +3563,16 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (dp) { struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; - if (ncf->ncf_file_modified) + if (ncf->ncf_file_modified) { + ++ncf->ncf_initial_cinfo; args.stat.size = ncf->ncf_cur_fsize; - + } + args.change_attr = ncf->ncf_initial_cinfo; nfs4_put_stid(&dp->dl_stid); + } else { + args.change_attr = nfsd4_change_attribute(&args.stat, d_inode(dentry)); } + if (err) goto out_nfserr; From patchwork Fri Oct 4 13:16: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: 13822299 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 AEC8D215F60; Fri, 4 Oct 2024 13:18:16 +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=1728047896; cv=none; b=ELd/pKkvG2us+lYUTqbx4aeynLuGjFVfLYzXYkuwAKPp0xi40wf/l1e6k5boDxzwidyYOy4x9rqWcpdIejxOPNsRmv7f3lYsizGwnU5LN35UgVhAO8a4+PD/4I7V5m94qKt7Tcf3r7c0XtCt/3ANezsVAqthXTy/cIPsOwg9eUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047896; c=relaxed/simple; bh=DauhQaF1OAWq0DfDhQ+QqY1qQnmk0ScTlDFH/YL1d68=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S2zNrOg8w4GvPCNYvDtZnWSE1s5UNAMS1XHn6/N/Zq6IPIhfU7xr0EGzhk96xYZ3IpuJguJ38cZOWgtGr98eL2H0m8DLMw5chaPRf0GDzYLWl1BepZKV0upTrb7oT9jg59+4c1Cr83FxXItf+AIgp9rhTCRHFgMDa4LnkZhu/n8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KAQVSWlR; 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="KAQVSWlR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13B10C4CEC6; Fri, 4 Oct 2024 13:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047896; bh=DauhQaF1OAWq0DfDhQ+QqY1qQnmk0ScTlDFH/YL1d68=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KAQVSWlRlgsP3AD0RLK8udpfPZK/yorC9fW5vPX3gyJhrgcrQJ5rSUyXGLhebIVcs CXo4SV/nZLZQB2xmtuJYE2qOamKF1V7aBYS5vGiRv3Uhe+3WPvHBLQBQGwwANfjrnr 5JrzH/nqXZ+C4kuclONJARUBfI65X9RypBCNzw9hJhBnL7az6Oljxhn1Jq4UJmqmv7 4kz8Tk2LR/HEjnJasSRC29SMuLhMDA6y9VPXc3SUrwmYVkb1MAPQwKXQJ5w9PnzKr0 jbH5wiCQ8ZTk25z4xkthXrLl3B9F6IG71SqtEEdWpH8H8PooB6gPE30NquRzv/tTre 7Z957p/t/TsZQ== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:48 -0400 Subject: [PATCH v4 5/9] nfs_common: make include/linux/nfs4.h include generated nfs4_1.h Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-5-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=21227; i=jlayton@kernel.org; h=from:subject:message-id; bh=DauhQaF1OAWq0DfDhQ+QqY1qQnmk0ScTlDFH/YL1d68=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sNVyhLVrwangU3C/bp5Y3DEFjvdxwHtYAS+ Z//S1rlTjiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDQAKCRAADmhBGVaC FadgEADLgX6toFFY+yV7I3/Su+0YxAkvCNn224/THXfwXCSn6/TDqoknpxjwVcD71MyikMITFVe y76bE+a/KdLU+OIWP0P5XKOhg0T0Gb2WRNvewOh0KZowekViO00E3+ive6cZn039xm1ngCpqao7 Jc1C03T65WvmaR6FduqVSiQQMxLMUSG0AWnWNHm9nP/GA+VnVyFK9piz6YtOg8noXFd5jEfFacG xHLXB04i8MKNMe0OjwKoQCcTN+OfS1Lt1lljDUG1C3hbOUp8s98L7Rnsndm7CBeiKesxiZ/wVfa tv6jiNIeYrMuUUHwIUm468BChieMagTvpAbs0Q2NkoHLzO9WyqdXExbFopxUj+YY9wfSrTfPw+n Hqz8LJURlT6ffR0qm1Zq9c0/4VXswXpQgwWc4XlgV+3WSVddMe7DMcmnak0MluNF0lpBSh1rTRr oI0fnFkOXQZxqKD32J03DiMdRAurY6FF3PtkrANC27JoAXyocIrXS556FoAAYhLi2cNkbVWdp1K bmKVf8r4casesGqT+YWWhW1bqjGBsjwrWotloEM/5v6djuxH3Dq1GiOJyZw/YjKPGrWOXEv0Xl8 gTk+veb6DjlIY0HfWXAY7FCFfnRKOcqo1djK7G0yeuB9c/6tXL9tkwWSfVUtZbd3YZGw8dRNFzc MVuC8V6sa7qn7Yg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In the long run, the NFS development community intends to autogenerate a lot of the XDR handling code. Both the NFS client and server include "include/linux/nfs4.hi". That file was hand-rolled, and some of the symbols in it conflict with the autogenerated symbols. Add a small nfs4_1.x to Documentation that currently just has the necessary definitions for the delstid draft, and generate the relevant header and source files. Make include/linux/nfs4.h include the generated include/linux/sunrpc/xdrgen/nfs4_1.h and remove the conflicting definitions from it and nfs_xdr.h. Signed-off-by: Jeff Layton --- Documentation/sunrpc/xdr/nfs4_1.x | 166 ++++++++++++++++++++++++ fs/nfsd/Makefile | 17 ++- fs/nfsd/nfs4xdr_gen.c | 239 +++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr_gen.h | 25 ++++ include/linux/nfs4.h | 7 +- include/linux/nfs_xdr.h | 5 - include/linux/sunrpc/xdrgen/nfs4_1.h | 124 ++++++++++++++++++ 7 files changed, 571 insertions(+), 12 deletions(-) diff --git a/Documentation/sunrpc/xdr/nfs4_1.x b/Documentation/sunrpc/xdr/nfs4_1.x new file mode 100644 index 0000000000000000000000000000000000000000..fc37d1ecba0f40e46c6986df90d07a0e6e6ae9b2 --- /dev/null +++ b/Documentation/sunrpc/xdr/nfs4_1.x @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2010 IETF Trust and the persons identified + * as the document authors. All rights reserved. + * + * The document authors are identified in RFC 3530 and + * RFC 5661. + * + * Redistribution and use in source and binary forms, with + * or without modification, are permitted provided that the + * following conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * - Neither the name of Internet Society, IETF or IETF + * Trust, nor the names of specific contributors, may be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS + * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +pragma header nfs4; + +/* + * Basic typedefs for RFC 1832 data type definitions + */ +typedef hyper int64_t; +typedef unsigned int uint32_t; + +/* + * Basic data types + */ +typedef uint32_t bitmap4<>; + +/* + * Timeval + */ +struct nfstime4 { + int64_t seconds; + uint32_t nseconds; +}; + + +/* + * The following content was extracted from draft-ietf-nfsv4-delstid + */ + +typedef bool fattr4_offline; + + +const FATTR4_OFFLINE = 83; + + +struct open_arguments4 { + bitmap4 oa_share_access; + bitmap4 oa_share_deny; + bitmap4 oa_share_access_want; + bitmap4 oa_open_claim; + bitmap4 oa_create_mode; +}; + + +enum open_args_share_access4 { + OPEN_ARGS_SHARE_ACCESS_READ = 1, + OPEN_ARGS_SHARE_ACCESS_WRITE = 2, + OPEN_ARGS_SHARE_ACCESS_BOTH = 3 +}; + + +enum open_args_share_deny4 { + OPEN_ARGS_SHARE_DENY_NONE = 0, + OPEN_ARGS_SHARE_DENY_READ = 1, + OPEN_ARGS_SHARE_DENY_WRITE = 2, + OPEN_ARGS_SHARE_DENY_BOTH = 3 +}; + + +enum open_args_share_access_want4 { + OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG = 3, + OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG = 4, + OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL = 5, + OPEN_ARGS_SHARE_ACCESS_WANT_SIGNAL_DELEG_WHEN_RESRC_AVAIL + = 17, + OPEN_ARGS_SHARE_ACCESS_WANT_PUSH_DELEG_WHEN_UNCONTENDED + = 18, + OPEN_ARGS_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 20, + OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 21 +}; + + +enum open_args_open_claim4 { + OPEN_ARGS_OPEN_CLAIM_NULL = 0, + OPEN_ARGS_OPEN_CLAIM_PREVIOUS = 1, + OPEN_ARGS_OPEN_CLAIM_DELEGATE_CUR = 2, + OPEN_ARGS_OPEN_CLAIM_DELEGATE_PREV = 3, + OPEN_ARGS_OPEN_CLAIM_FH = 4, + OPEN_ARGS_OPEN_CLAIM_DELEG_CUR_FH = 5, + OPEN_ARGS_OPEN_CLAIM_DELEG_PREV_FH = 6 +}; + + +enum open_args_createmode4 { + OPEN_ARGS_CREATEMODE_UNCHECKED4 = 0, + OPEN_ARGS_CREATE_MODE_GUARDED = 1, + OPEN_ARGS_CREATEMODE_EXCLUSIVE4 = 2, + OPEN_ARGS_CREATE_MODE_EXCLUSIVE4_1 = 3 +}; + + +typedef open_arguments4 fattr4_open_arguments; +pragma public fattr4_open_arguments; + + +%/* +% * Determine what OPEN supports. +% */ +const FATTR4_OPEN_ARGUMENTS = 86; + + +const OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000; + + +const OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010; + + +/* + * attributes for the delegation times being + * cached and served by the "client" + */ +typedef nfstime4 fattr4_time_deleg_access; +typedef nfstime4 fattr4_time_deleg_modify; +pragma public fattr4_time_deleg_access; +pragma public fattr4_time_deleg_modify; + + +%/* +% * New RECOMMENDED Attribute for +% * delegation caching of times +% */ +const FATTR4_TIME_DELEG_ACCESS = 84; +const FATTR4_TIME_DELEG_MODIFY = 85; + + +const OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000; + diff --git a/fs/nfsd/Makefile b/fs/nfsd/Makefile index 18cbd3fa7691a27b39a3b1264637b9422aeb42ba..7cf31c5a17597428cc27f8f1c95732f5221c2daa 100644 --- a/fs/nfsd/Makefile +++ b/fs/nfsd/Makefile @@ -18,9 +18,24 @@ 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 nfsd-$(CONFIG_NFSD_FLEXFILELAYOUT) += flexfilelayout.o flexfilelayoutxdr.o nfsd-$(CONFIG_NFS_LOCALIO) += localio.o + + +.PHONY: xdrgen + +xdrgen: ../../include/linux/sunrpc/xdrgen/nfs4_1.h nfs4xdr_gen.h nfs4xdr_gen.c + +../../include/linux/sunrpc/xdrgen/nfs4_1.h: ../../Documentation/sunrpc/xdr/nfs4_1.x + ../../tools/net/sunrpc/xdrgen/xdrgen definitions $< > $@ + +nfs4xdr_gen.h: ../../Documentation/sunrpc/xdr/nfs4_1.x + ../../tools/net/sunrpc/xdrgen/xdrgen declarations $< > $@ + +nfs4xdr_gen.c: ../../Documentation/sunrpc/xdr/nfs4_1.x + ../../tools/net/sunrpc/xdrgen/xdrgen source $< > $@ + diff --git a/fs/nfsd/nfs4xdr_gen.c b/fs/nfsd/nfs4xdr_gen.c new file mode 100644 index 0000000000000000000000000000000000000000..e5d34f9a3147d9d51fb3b9db4c29b048b1083cbf --- /dev/null +++ b/fs/nfsd/nfs4xdr_gen.c @@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0 +// Generated by xdrgen. Manual edits will be lost. +// XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x +// XDR specification modification time: Thu Oct 3 11:30:59 2024 + +#include + +#include "nfs4xdr_gen.h" + +static bool __maybe_unused +xdrgen_decode_int64_t(struct xdr_stream *xdr, int64_t *ptr) +{ + return xdrgen_decode_hyper(xdr, ptr); +}; + +static bool __maybe_unused +xdrgen_decode_uint32_t(struct xdr_stream *xdr, uint32_t *ptr) +{ + return xdrgen_decode_unsigned_int(xdr, ptr); +}; + +static bool __maybe_unused +xdrgen_decode_bitmap4(struct xdr_stream *xdr, bitmap4 *ptr) +{ + if (xdr_stream_decode_u32(xdr, &ptr->count) < 0) + return false; + for (u32 i = 0; i < ptr->count; i++) + if (!xdrgen_decode_uint32_t(xdr, &ptr->element[i])) + return false; + return true; +}; + +static bool __maybe_unused +xdrgen_decode_nfstime4(struct xdr_stream *xdr, struct nfstime4 *ptr) +{ + if (!xdrgen_decode_int64_t(xdr, &ptr->seconds)) + return false; + if (!xdrgen_decode_uint32_t(xdr, &ptr->nseconds)) + return false; + return true; +}; + +static bool __maybe_unused +xdrgen_decode_fattr4_offline(struct xdr_stream *xdr, fattr4_offline *ptr) +{ + return xdrgen_decode_bool(xdr, ptr); +}; + +static bool __maybe_unused +xdrgen_decode_open_arguments4(struct xdr_stream *xdr, struct open_arguments4 *ptr) +{ + if (!xdrgen_decode_bitmap4(xdr, &ptr->oa_share_access)) + return false; + if (!xdrgen_decode_bitmap4(xdr, &ptr->oa_share_deny)) + return false; + if (!xdrgen_decode_bitmap4(xdr, &ptr->oa_share_access_want)) + return false; + if (!xdrgen_decode_bitmap4(xdr, &ptr->oa_open_claim)) + return false; + if (!xdrgen_decode_bitmap4(xdr, &ptr->oa_create_mode)) + return false; + return true; +}; + +static bool __maybe_unused +xdrgen_decode_open_args_share_access4(struct xdr_stream *xdr, open_args_share_access4 *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + *ptr = val; + return true; +} + +static bool __maybe_unused +xdrgen_decode_open_args_share_deny4(struct xdr_stream *xdr, open_args_share_deny4 *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + *ptr = val; + return true; +} + +static bool __maybe_unused +xdrgen_decode_open_args_share_access_want4(struct xdr_stream *xdr, open_args_share_access_want4 *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + *ptr = val; + return true; +} + +static bool __maybe_unused +xdrgen_decode_open_args_open_claim4(struct xdr_stream *xdr, open_args_open_claim4 *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + *ptr = val; + return true; +} + +static bool __maybe_unused +xdrgen_decode_open_args_createmode4(struct xdr_stream *xdr, open_args_createmode4 *ptr) +{ + u32 val; + + if (xdr_stream_decode_u32(xdr, &val) < 0) + return false; + *ptr = val; + return true; +} + +bool +xdrgen_decode_fattr4_open_arguments(struct xdr_stream *xdr, fattr4_open_arguments *ptr) +{ + return xdrgen_decode_open_arguments4(xdr, ptr); +}; + +bool +xdrgen_decode_fattr4_time_deleg_access(struct xdr_stream *xdr, fattr4_time_deleg_access *ptr) +{ + return xdrgen_decode_nfstime4(xdr, ptr); +}; + +bool +xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg_modify *ptr) +{ + return xdrgen_decode_nfstime4(xdr, ptr); +}; + +static bool __maybe_unused +xdrgen_encode_int64_t(struct xdr_stream *xdr, const int64_t value) +{ + return xdrgen_encode_hyper(xdr, value); +}; + +static bool __maybe_unused +xdrgen_encode_uint32_t(struct xdr_stream *xdr, const uint32_t value) +{ + return xdrgen_encode_unsigned_int(xdr, value); +}; + +static bool __maybe_unused +xdrgen_encode_bitmap4(struct xdr_stream *xdr, const bitmap4 value) +{ + if (xdr_stream_encode_u32(xdr, value.count) != XDR_UNIT) + return false; + for (u32 i = 0; i < value.count; i++) + if (!xdrgen_encode_uint32_t(xdr, value.element[i])) + return false; + return true; +}; + +static bool __maybe_unused +xdrgen_encode_nfstime4(struct xdr_stream *xdr, const struct nfstime4 *value) +{ + if (!xdrgen_encode_int64_t(xdr, value->seconds)) + return false; + if (!xdrgen_encode_uint32_t(xdr, value->nseconds)) + return false; + return true; +}; + +static bool __maybe_unused +xdrgen_encode_fattr4_offline(struct xdr_stream *xdr, const fattr4_offline value) +{ + return xdrgen_encode_bool(xdr, value); +}; + +static bool __maybe_unused +xdrgen_encode_open_arguments4(struct xdr_stream *xdr, const struct open_arguments4 *value) +{ + if (!xdrgen_encode_bitmap4(xdr, value->oa_share_access)) + return false; + if (!xdrgen_encode_bitmap4(xdr, value->oa_share_deny)) + return false; + if (!xdrgen_encode_bitmap4(xdr, value->oa_share_access_want)) + return false; + if (!xdrgen_encode_bitmap4(xdr, value->oa_open_claim)) + return false; + if (!xdrgen_encode_bitmap4(xdr, value->oa_create_mode)) + return false; + return true; +}; + +static bool __maybe_unused +xdrgen_encode_open_args_share_access4(struct xdr_stream *xdr, open_args_share_access4 value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} + +static bool __maybe_unused +xdrgen_encode_open_args_share_deny4(struct xdr_stream *xdr, open_args_share_deny4 value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} + +static bool __maybe_unused +xdrgen_encode_open_args_share_access_want4(struct xdr_stream *xdr, open_args_share_access_want4 value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} + +static bool __maybe_unused +xdrgen_encode_open_args_open_claim4(struct xdr_stream *xdr, open_args_open_claim4 value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} + +static bool __maybe_unused +xdrgen_encode_open_args_createmode4(struct xdr_stream *xdr, open_args_createmode4 value) +{ + return xdr_stream_encode_u32(xdr, value) == XDR_UNIT; +} + +bool +xdrgen_encode_fattr4_open_arguments(struct xdr_stream *xdr, const fattr4_open_arguments *value) +{ + return xdrgen_encode_open_arguments4(xdr, value); +}; + +bool +xdrgen_encode_fattr4_time_deleg_access(struct xdr_stream *xdr, const fattr4_time_deleg_access *value) +{ + return xdrgen_encode_nfstime4(xdr, value); +}; + +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 new file mode 100644 index 0000000000000000000000000000000000000000..c4c6a5075b17be3f931e2a20e282e33dc6e10ef1 --- /dev/null +++ b/fs/nfsd/nfs4xdr_gen.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Generated by xdrgen. Manual edits will be lost. */ +/* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */ +/* XDR specification modification time: Thu Oct 3 11:30:59 2024 */ + +#ifndef _LINUX_XDRGEN_NFS4_1_DECL_H +#define _LINUX_XDRGEN_NFS4_1_DECL_H + +#include + +#include +#include +#include +#include + +bool xdrgen_decode_fattr4_open_arguments(struct xdr_stream *xdr, fattr4_open_arguments *ptr); +bool xdrgen_encode_fattr4_open_arguments(struct xdr_stream *xdr, const fattr4_open_arguments *value); + +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); + +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); + +#endif /* _LINUX_XDRGEN_NFS4_1_DECL_H */ diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 8d7430d9f2183f08fc995b12370d0ddddf0bffba..b907192447755a614289554a01928c1ebb61c3dc 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 12d8e47bc5a38863b2831fb16056f742fa81612e..e0ae0a14257f21f212e439dde1ce66ac301eb86c 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/include/linux/sunrpc/xdrgen/nfs4_1.h b/include/linux/sunrpc/xdrgen/nfs4_1.h new file mode 100644 index 0000000000000000000000000000000000000000..6025ab6b739833aad33567102e216c162003f408 --- /dev/null +++ b/include/linux/sunrpc/xdrgen/nfs4_1.h @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Generated by xdrgen. Manual edits will be lost. */ +/* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */ +/* XDR specification modification time: Thu Oct 3 11:30:59 2024 */ + +#ifndef _LINUX_XDRGEN_NFS4_1_DEF_H +#define _LINUX_XDRGEN_NFS4_1_DEF_H + +#include +#include + +typedef s64 int64_t; + +typedef u32 uint32_t; + +typedef struct { + u32 count; + uint32_t *element; +} bitmap4; + +struct nfstime4 { + int64_t seconds; + uint32_t nseconds; +}; + +typedef bool fattr4_offline; + +enum { FATTR4_OFFLINE = 83 }; + +struct open_arguments4 { + bitmap4 oa_share_access; + bitmap4 oa_share_deny; + bitmap4 oa_share_access_want; + bitmap4 oa_open_claim; + bitmap4 oa_create_mode; +}; + +enum open_args_share_access4 { + OPEN_ARGS_SHARE_ACCESS_READ = 1, + OPEN_ARGS_SHARE_ACCESS_WRITE = 2, + OPEN_ARGS_SHARE_ACCESS_BOTH = 3, +}; +typedef enum open_args_share_access4 open_args_share_access4; + +enum open_args_share_deny4 { + OPEN_ARGS_SHARE_DENY_NONE = 0, + OPEN_ARGS_SHARE_DENY_READ = 1, + OPEN_ARGS_SHARE_DENY_WRITE = 2, + OPEN_ARGS_SHARE_DENY_BOTH = 3, +}; +typedef enum open_args_share_deny4 open_args_share_deny4; + +enum open_args_share_access_want4 { + OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG = 3, + OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG = 4, + OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL = 5, + OPEN_ARGS_SHARE_ACCESS_WANT_SIGNAL_DELEG_WHEN_RESRC_AVAIL = 17, + OPEN_ARGS_SHARE_ACCESS_WANT_PUSH_DELEG_WHEN_UNCONTENDED = 18, + OPEN_ARGS_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 20, + OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 21, +}; +typedef enum open_args_share_access_want4 open_args_share_access_want4; + +enum open_args_open_claim4 { + OPEN_ARGS_OPEN_CLAIM_NULL = 0, + OPEN_ARGS_OPEN_CLAIM_PREVIOUS = 1, + OPEN_ARGS_OPEN_CLAIM_DELEGATE_CUR = 2, + OPEN_ARGS_OPEN_CLAIM_DELEGATE_PREV = 3, + OPEN_ARGS_OPEN_CLAIM_FH = 4, + OPEN_ARGS_OPEN_CLAIM_DELEG_CUR_FH = 5, + OPEN_ARGS_OPEN_CLAIM_DELEG_PREV_FH = 6, +}; +typedef enum open_args_open_claim4 open_args_open_claim4; + +enum open_args_createmode4 { + OPEN_ARGS_CREATEMODE_UNCHECKED4 = 0, + OPEN_ARGS_CREATE_MODE_GUARDED = 1, + OPEN_ARGS_CREATEMODE_EXCLUSIVE4 = 2, + OPEN_ARGS_CREATE_MODE_EXCLUSIVE4_1 = 3, +}; +typedef enum open_args_createmode4 open_args_createmode4; + +typedef struct open_arguments4 fattr4_open_arguments; + +enum { FATTR4_OPEN_ARGUMENTS = 86 }; + +enum { OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000 }; + +enum { OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010 }; + +typedef struct nfstime4 fattr4_time_deleg_access; + +typedef struct nfstime4 fattr4_time_deleg_modify; + +enum { FATTR4_TIME_DELEG_ACCESS = 84 }; + +enum { FATTR4_TIME_DELEG_MODIFY = 85 }; + +enum { OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000 }; + +#define NFS4_int64_t_sz \ + (XDR_hyper) +#define NFS4_uint32_t_sz \ + (XDR_unsigned_int) +#define NFS4_bitmap4_sz (XDR_unsigned_int) +#define NFS4_nfstime4_sz \ + (NFS4_int64_t_sz + NFS4_uint32_t_sz) +#define NFS4_fattr4_offline_sz \ + (XDR_bool) +#define NFS4_open_arguments4_sz \ + (NFS4_bitmap4_sz + NFS4_bitmap4_sz + NFS4_bitmap4_sz + NFS4_bitmap4_sz + NFS4_bitmap4_sz) +#define NFS4_open_args_share_access4_sz (XDR_int) +#define NFS4_open_args_share_deny4_sz (XDR_int) +#define NFS4_open_args_share_access_want4_sz (XDR_int) +#define NFS4_open_args_open_claim4_sz (XDR_int) +#define NFS4_open_args_createmode4_sz (XDR_int) +#define NFS4_fattr4_open_arguments_sz \ + (NFS4_open_arguments4_sz) +#define NFS4_fattr4_time_deleg_access_sz \ + (NFS4_nfstime4_sz) +#define NFS4_fattr4_time_deleg_modify_sz \ + (NFS4_nfstime4_sz) + +#endif /* _LINUX_XDRGEN_NFS4_1_DEF_H */ From patchwork Fri Oct 4 13:16: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: 13822300 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 67F97216A31; Fri, 4 Oct 2024 13:18:18 +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=1728047898; cv=none; b=cGIjkcfS6yS9V6lPwiKb1JbPdDsAlW/AQUY+QcjSXW982mj890JXBIJKBwpycH8S0e7HXcnVtSq3vBRO3OjSIrthX+nImSm9o9CWTJ5MpVyjG+DFlYJLqAz7HgAVVxsLpnEQ3mi9a5sn3DU0RPhdY57wrFSef6HUaVPnK+JMCxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047898; c=relaxed/simple; bh=whTl98z0wl8xepmuzh8oTLlhqj3nth1umWXiJ96EUWc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fh1zlWGpcDwM4LMg9Ll4EuHeSVIraGKNTPc0k5drekW1WHNty4MEe5s/H0tCaxUhrSi79MdeSK21IPbEUbEoXJZhHOlFR0u9sR/purKl3plLPdFheg69R6ei/TvsMqORb6Gnbo6lyQCpk/fPqSO8alEZ06VXgYgnG3THBxLSjzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uDxvQo21; 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="uDxvQo21" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC0EEC4CED4; Fri, 4 Oct 2024 13:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047898; bh=whTl98z0wl8xepmuzh8oTLlhqj3nth1umWXiJ96EUWc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uDxvQo21MltWw7fUJTSL5MnjDfMDcTHMd80lnH9jOLPQWJ9A5ERsQsxbJQlshpzZB KavbZAshTsLyUPpuSLCsDFy00UEr3jFRW+XgSeu/sUasHyQCKNl+Eix1nvItMvKocl yscIY934Hi477KA98ngS2BwSlqqHJWAH1PR9KhnsXd7meLu70rlvG5+GBc1AdZ/dHr 0S9Cx2VQRK6q15vcdqshK5xXL/CUo13cpsYd+MhJkg2gBDHaps0NOp0fU7Y/c7AIKp Hjq3P6gfhOGcUUIQzJiNmvOnPWSgb53Q6T7yd+M+DSmLHbscFv94nit3A82AORId/e bRMCMRbKkmaDQ== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:49 -0400 Subject: [PATCH v4 6/9] nfsd: add support for FATTR4_OPEN_ARGUMENTS Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-6-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3826; i=jlayton@kernel.org; h=from:subject:message-id; bh=whTl98z0wl8xepmuzh8oTLlhqj3nth1umWXiJ96EUWc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sNu1eXZvqukcr2tGYHPovBSZByEKfyLx+lG dPbW8IovriJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDQAKCRAADmhBGVaC FSWKEACR8pMTk6mpsHGWVdABnoBTp2gsKl1FY6XKB5WkOEnOU9QBXoF/+muJ+RhHPat4j9p3ISM Hywq19MCeJmTBcpxqzzIGCfYQSxPrM6Ho7IXoh6UQbPPV4B7nR008Sq0/f0jrTt4pDp9Oe4IwCP Rc8cxBhhtZw8mjL7rGdbrzNt+p7EUg7ESyaK4EtqnKTdetAo7XMSI+ITeH4QT3iqjPXJqb7zasb heh4wc6P66wryOm8l6hXdLVTFyyLkx1xWIffDbYCdzTuA8EooH0YvFunD62egBxRFDikWNWSGIQ XzRGzp16Djg/20qvfA9CdWT6rr/7SY9wvKJJNIZ2VJyzTohOfPP0LygJLP4kyu0K0cSOQVVwUWN g8ORrmjSQpNM/qfHwd0dFgEBpFNcn2izIUCYFK7CyNOVo/Yz+KqyFHeDpjjPrsP1HdYTDAjG2cF 6xm4kAyGVHlpFqEBVH/lN9IKnCUWhAtXah/myfutkmHlkt4icozNun76QdBuq+FqsI/xKvUFiD9 eopyC7zI3DbZxGSk8nNdrbmx0KosMhXjVVgeVJTF7br8Vt2vLjvkTR8I9It6bRpAh4LmQRK3UMS x4B3MexnFNLOHKg1cCv5x42+0lROErnS8fUn93i3cVpiG1iAKbCMkNaZ2BvyRQKwdumjwF67ZyR ZzKYMoMONcQ53Rg== 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/nfs4xdr.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfsd.h | 3 ++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index c5a716aa9f79060828eedcc41366e32970dea042..9fb7764924240a8c584517bcdf682fea1b417180 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -55,6 +55,7 @@ #include "netns.h" #include "pnfs.h" #include "filecache.h" +#include "nfs4xdr_gen.h" #include "trace.h" @@ -3396,6 +3397,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 +3545,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 4b56ba1e8e48d08c4e3e52f378822c311193c3d4..1955c8e9c4c793728fa75dd136cadc735245483f 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -458,7 +458,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 Fri Oct 4 13:16: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: 13822301 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 690742139CB; Fri, 4 Oct 2024 13:18:20 +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=1728047900; cv=none; b=q6CNh2TeNLSA6iwxIXtk2kYpZGv5tBl6Ih9glWN+8l8mmNbCgR3Y0eCgJns9SyKM/5pgZUssyIrIHHcyM8QbgYK5RdOlminLaPUMlyk7JB7pTJOTFnLIt2bvj5pueJQki79CtGDL0eWZZ2aQtF71Kk2bVP5NzvFLHbzlQpPJtWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047900; c=relaxed/simple; bh=8C0WXBw+0DM2VhbEOKcao7vK3WlMnq5GsT1YUwXNjek=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KjP6O8vQT6JHCgClvnXPdGYXtSnmEMSVt8WuPULXfX98KKVZsstMbD5uRqubiKkoRCjZQLpLj/MI34VLwvYpaddd9IJp4xCOWlQBNBTM+51fOv04272JaiJuEobD+kZm1dLnqS0oDaqm5kuZxRdNMwdbts2XcmnoyIyScd2UdZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dhD7DEn7; 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="dhD7DEn7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 844C3C4CECE; Fri, 4 Oct 2024 13:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047900; bh=8C0WXBw+0DM2VhbEOKcao7vK3WlMnq5GsT1YUwXNjek=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dhD7DEn7TBpVMBmAARvMFLKcxeNSzx8/mAuO4NVs7AHv/68WnI155MhttRa7xUWoJ 3WPl7Nw5HZ1pQqdLUivKj0QZLJTymBcsEUI9gkR6YgKU9c4OZjhFiiKK4C2jRLdan2 szB4SlS9/g3dgEY7ly73brtyDwOpe4ElzDE70uLVclxGf8WuMAQLvDm6WQ4l+DBAdV pZrQfd2LJVrrSiTIRu3NyzrSBCPH7MMdY/e0gHfGW/u79FLbjtYRxx6aUxRViwNRKe iDgK3aGRdu8pLMLX9DXGW/7GxfWyW919ahdP74kysv6KqbHUheS0epfXLYnwW8Cpnd jJnROWbOhyafQ== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:50 -0400 Subject: [PATCH v4 7/9] nfsd: implement OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-7-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5955; i=jlayton@kernel.org; h=from:subject:message-id; bh=8C0WXBw+0DM2VhbEOKcao7vK3WlMnq5GsT1YUwXNjek=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sNwyzgobOEc8vGs6Ng36cwNf28fuDrK2odC w+WSbWldL6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDQAKCRAADmhBGVaC FS8eEACm2UrpCEwGXvBdt58OchIefzFh5CC1/e0ZvRe+ly1jK1H+zcpWgLEdvR2wNJDah3+EKTy puv7Wcu2dZzyPI9H4ourWJMmVPV0Hf+/0GKh6GFFc7Sud6VUNsA1niOAR4RHiZ/xuNVDYUHMzsP GPNKXf9VjHwJHj1smOswNlcWNWbKjUyW3WiMjuTEl2r7wvvFn5YqTkfRDC/z0N0xMrp4fy26BL2 ts3Uv76B8JU3AQW5zIZKhh7UE8nL2vX4ByLj1vGK3vE4C0kYgZP6xzICJKmekqXqO40Oiyu+/ty 7l04OnWKml8+EbR/NRSYJzpZwYP0QTSIwedhrhMCBOkmr/2KiMcam+E8pJEQVdVdx6Tw2BKSXmb IoLZ+kFndUA55IKzxRn7H1ajFZG0kZP4IZ2zyohF2vRZ34tWbNZgqi2Pb3CT8VyhJtYQAhl9acW TAGJRaJ/fkVwx63l9tHlPVqyLN6kZqBoYn2YKLN1p7e79kq89G/+zhdrIIs/jm2i8x7XoEQgbSZ f8Ar+khcsr3xyhRHbkgADodr+cxzS10UGuoZbpAOEDLEVd7z2TUbVKn+kzeUO+uN45KOg1DDQ0u aJ+O5CFD0Lm04VmaOkZrRjDRRnEsFZeqekJnli9HcMS1pTd++7pxFmC3tRXsJy0Q4NJH0HBUSn1 58qHBXlle8jbVGQ== 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 | 33 +++++++++++++++++++++++++++++---- fs/nfsd/nfs4xdr.c | 5 +++-- include/uapi/linux/nfs4.h | 7 +++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index ecf02badf598d147feb5133cb43225e3611d6d8e..a9eb7cf9fd7e74a648170c60bf031fdc32533dd3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6054,6 +6054,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 @@ -6076,6 +6087,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, @@ -6130,9 +6142,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; @@ -6146,7 +6155,23 @@ 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); + + /* + * If there is an existing open stateid, it must be updated and + * returned. Only respect WANT_OPEN_XOR_DELEGATION when a new + * open stateid would have to be created. + */ + deleg_only = new_stp && 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; + 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: @@ -6162,7 +6187,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 9fb7764924240a8c584517bcdf682fea1b417180..dad6875aa17eb99759cdbacb814b7988848a961b 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -1067,7 +1067,7 @@ static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *sh return nfs_ok; if (!argp->minorversion) return nfserr_bad_xdr; - switch (w & NFS4_SHARE_WANT_MASK) { + switch (w & NFS4_SHARE_WANT_TYPE_MASK) { case NFS4_SHARE_WANT_NO_PREFERENCE: case NFS4_SHARE_WANT_READ_DELEG: case NFS4_SHARE_WANT_WRITE_DELEG: @@ -3408,7 +3408,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 caf4db2fcbb94686631ec2232a8ff189c97c8617..4273e0249fcbb54996f5642f9920826b9d68b7b9 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 Fri Oct 4 13:16: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: 13822302 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 1C981216A31; Fri, 4 Oct 2024 13:18:21 +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=1728047902; cv=none; b=uj81iSBzcvpXzQmx08jxWYJBZs2gw1fDA2dcQTNN2TUpjLAdIxjaP19xuul7u+7RoZ2alOTb0bYs2ma75hFlunklUY+5YzYBZoESi0ELTfvi84mhKB0bNsbhhhak01GKXp2hVa9j5+AmdgPShoMvvMlHeGxqcW1BWGpG1TK2qOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047902; c=relaxed/simple; bh=idYW2JQck3N1v1eUkrY8KA4zGPHRRQmY2wTqAK8T0iI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fCTBnY6pqrTqknx+NbEr+vKAvcxFJ8qCVsdF6pF1OayIVUOuCNdksvhtb14iFL0HpBmHz85VXO4Y6CKqk2p0+hjwFXW02A6xAcrTXMz+Ej92cHVHyfY5NoZoAIgCYzi0XgqkKR1pwkYd1deHo7Y/T0665WEmUD5XE3SsOA0UNE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YOJ0wuYw; 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="YOJ0wuYw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 367FBC4CECF; Fri, 4 Oct 2024 13:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047901; bh=idYW2JQck3N1v1eUkrY8KA4zGPHRRQmY2wTqAK8T0iI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YOJ0wuYwgAfnfPz1CAmO8Gl01/eLJmhVoyG6DWFL+1LzRM6ovrbJ1sCr4kbEqQO+G axNshxOgcGh3Vw0SqtiRfx1rZ4A606FlIeOl2se67rAyW41obyU+xKzrCVro3TZXUG 5WCnIxCojdRbCf3HEIoJjzpV3viE7VSYKhHbqke8YeM6VPpC4hP/DMHYhw6gB5Eb/O T2x7IQck9CrSGbf8++DogJUnXjuuqX3MNoW4XN9JZMtmgQMXHtFr7izAhwNaF61q1C PUMOa+5bKpfKrMwr14GrAJAuZjRhJH6XnQJ2O5CkaxlWZ7OiWRiz7bHirv5mmQV0/y nWAlt8qM0L1yA== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:51 -0400 Subject: [PATCH v4 8/9] nfsd: add support for delegated timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-8-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=12598; i=jlayton@kernel.org; h=from:subject:message-id; bh=idYW2JQck3N1v1eUkrY8KA4zGPHRRQmY2wTqAK8T0iI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sO6iJW0VxEbWj5DI1ZeQtM5zeWZCImufIu0 3Tm1+S17zGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDgAKCRAADmhBGVaC FUb+EACKhw2kXSkiB9IcxFRd9Y+8Y7Oj7xDJTzQWD5OmNaRQtBj4a5C0qlYzUCS9Viv8pMjxY6h KhDrMnf3dGn/+rJEKbxf9elQnd8RbI3k1pTAnD77UQJ7QWWkyO3ebV+FkxWjYHSKAuwNxtJpWHt ah4VNNCHV5QaJDxeYKPiOjBUeeUzU3RHAm1MetX9u3uQtfS4OZeVlP0OoTHfpZ+hmHknaDPurDt lEFiIljR3heIbNpZGK922HnTzC32EgObZCPYEaXgusaRrD5jhEh4pb2FCc6pNQDblU/vfEfVHwO vlFCvj9xy/VhrNy6HCnYh9+biTZkT8H9Zgo2oKLsMu8gZl3fOZxYbHqlV8R23K7AXnl2VekSJ0u SI6Z7ubVZRMUXTRL6ZNZcrKnpEHgkfOTAAtQgcphk9F8AY1cKNlDRr7FCUWDUMRW2ZUOeQ46Tcc 6jrHjO5pvJCIVGDjkcH3FzN+WnjSmbm+aoeUUy0tbtjqWsKcSMXOLPmTgPmLxMJwKHBu1epxRtV Efg7w7YLnSh35mbwjuFSKP/jtTuHExpa2lMxPOj41pZVfn0T1gdYjjT9l1y5W3Sm9cgb/hAu++T r3uwCGIPVzb/ZbUEpMqLdLe0jNHAui5b+zFd0Abt3IFQEtkyb6PONRhF+K+zP/Q37HdbFbZ6cjv YQeZrUtB8M+5SwA== 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, 142 insertions(+), 14 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 776838bb83e6b707a4df76326cdc68f32daf1755..d86a7b98378549b6c8dbcb6c937dd109d6f50b34 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -42,6 +42,7 @@ #include "trace.h" #include "xdr4cb.h" #include "xdr4.h" +#include "nfs4xdr_gen.h" #define NFSDDBG_FACILITY NFSDDBG_PROC @@ -93,12 +94,35 @@ static int decode_cb_fattr4(struct xdr_stream *xdr, uint32_t *bitmap, { fattr->ncf_cb_change = 0; fattr->ncf_cb_fsize = 0; + fattr->ncf_cb_atime.tv_sec = 0; + fattr->ncf_cb_atime.tv_nsec = 0; + fattr->ncf_cb_mtime.tv_sec = 0; + fattr->ncf_cb_mtime.tv_nsec = 0; + if (bitmap[0] & FATTR4_WORD0_CHANGE) if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_change) < 0) return -NFSERR_BAD_XDR; if (bitmap[0] & FATTR4_WORD0_SIZE) if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_fsize) < 0) return -NFSERR_BAD_XDR; + if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) { + fattr4_time_deleg_access access; + + if (!xdrgen_decode_fattr4_time_deleg_access(xdr, &access)) + return -NFSERR_BAD_XDR; + fattr->ncf_cb_atime.tv_sec = access.seconds; + fattr->ncf_cb_atime.tv_nsec = access.nseconds; + + } + if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { + fattr4_time_deleg_modify modify; + + if (!xdrgen_decode_fattr4_time_deleg_modify(xdr, &modify)) + return -NFSERR_BAD_XDR; + fattr->ncf_cb_mtime.tv_sec = modify.seconds; + fattr->ncf_cb_mtime.tv_nsec = modify.nseconds; + + } return 0; } @@ -364,15 +388,21 @@ encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr, struct nfs4_delegation *dp = container_of(fattr, struct nfs4_delegation, dl_cb_fattr); struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle; struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr; - u32 bmap[1]; + u32 bmap_size = 1; + u32 bmap[3]; bmap[0] = FATTR4_WORD0_SIZE; if (!ncf->ncf_file_modified) bmap[0] |= FATTR4_WORD0_CHANGE; + if (dp->dl_deleg_ts) { + bmap[1] = 0; + bmap[2] = FATTR4_WORD2_TIME_DELEG_ACCESS | FATTR4_WORD2_TIME_DELEG_MODIFY; + bmap_size = 3; + } encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR); encode_nfs_fh4(xdr, fh); - encode_bitmap4(xdr, bmap, ARRAY_SIZE(bmap)); + encode_bitmap4(xdr, bmap, bmap_size); hdr->nops++; } @@ -597,7 +627,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); @@ -616,7 +646,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 a9eb7cf9fd7e74a648170c60bf031fdc32533dd3..de6d8cfc975726be2cf3e80678d587e62ed61d76 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6005,6 +6005,8 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid)); + if (open->op_deleg_want & NFS4_SHARE_WANT_DELEG_TIMESTAMPS) + dp->dl_deleg_ts = true; if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) { if (!nfs4_delegation_stat(dp, currentfh, &stat)) { nfs4_put_stid(&dp->dl_stid); @@ -8852,6 +8854,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 @@ -8878,7 +8952,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); @@ -8940,11 +9013,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 dad6875aa17eb99759cdbacb814b7988848a961b..6241e93e9e13410b4fa926c0992127b1cc757b5e 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3409,6 +3409,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) | \ @@ -3602,7 +3603,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; @@ -3617,8 +3622,14 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, if (ncf->ncf_file_modified) { ++ncf->ncf_initial_cinfo; args.stat.size = ncf->ncf_cur_fsize; + if (!timespec64_is_epoch(&ncf->ncf_cb_mtime)) + args.stat.mtime = ncf->ncf_cb_mtime; } args.change_attr = ncf->ncf_initial_cinfo; + + if (!timespec64_is_epoch(&ncf->ncf_cb_atime)) + args.stat.atime = ncf->ncf_cb_atime; + nfs4_put_stid(&dp->dl_stid); } else { args.change_attr = nfsd4_change_attribute(&args.stat, d_inode(dentry)); diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 1955c8e9c4c793728fa75dd136cadc735245483f..004415651295891b3440f52a4c986e3a668a48cb 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -459,6 +459,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 c7c7ec21e5104761221bd78b31110d902df1dc9b..874fcab2b18381a442b651c3d6eb3742f501b4a5 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 e8b00309c449fe2667f7d48cda88ec0cff924f93..f1a315cd31b74f73f1d52702ae7b5c93d51ddf82 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 f1bcea8c124a361b6c1e3c98ef915840c22a8413..9934331c7b86b7fb981c7aec0494ac2f5e72977e 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 Fri Oct 4 13:16:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13822303 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 7EA75217919; Fri, 4 Oct 2024 13:18:23 +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=1728047903; cv=none; b=iuOqIRn30vQgykfCUnqaLdXQvqHPcPs5ORYU8PNIRsY9DcZe9sPW+cSjRlGdl70+U9RxmuZwLr8IDvi3XwQccJCuh683mQGc1QnERL0wE0xJXT9hPG7vLhGP/gvLb3FekotptuS09Exyw8vY8qd7iPauWbBLsd5dsjq7Q/PDhKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728047903; c=relaxed/simple; bh=9CCT4emkgZ4aNhjimaMLoft7waX5qJm3j1Zwi+hAwSw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RoTA4ChBSkpXeU0PGj72MtMljL/nsH90xVj+VEi8M8HVW4i0+KH1ZToIsKN34F9Se82A3Gz2cLLMizlNef+Pi4pAak51hUyYsZnjapyYtNav9vkI0O/17yj+75MyWU+XuET9pOmqBbFInRfo69JcujVdZtUPIOT5tmh0RK9XyOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SJeOmtbi; 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="SJeOmtbi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFFA0C4CED2; Fri, 4 Oct 2024 13:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728047903; bh=9CCT4emkgZ4aNhjimaMLoft7waX5qJm3j1Zwi+hAwSw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SJeOmtbiwFM5KNFReOpcRr58z6Vv32jKCXkme8V5nD9wRXfYUlPqZ44zfyYHt22Sn FGJ5Ubj7IXI6cj+bRTwhFXtZ1xKITx1s+b3dTOVvEUYsTTZ5xygVBn6ZnvS8e0dPzQ M+nx0ginjF6gVSfsh3crMvrlDm0ECoOb0e9T8EAe/Yke+x+dscjYTtGuOEuKCYknF6 e7+6BKUHg0dYZ5o42NZh9yqD+udz28l9wdwzpLcVTtFNc2KAGNK2AXoavaW6Z3doz8 Qf2jyLEopuNRQUhU77DnXZtLn6Dgxa0mDiOeJmMksURHgVkU9wQG3d32086APchGb7 gfeLQDqiO6glw== From: Jeff Layton Date: Fri, 04 Oct 2024 09:16:52 -0400 Subject: [PATCH v4 9/9] nfsd: handle delegated timestamps in SETATTR Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241004-delstid-v4-9-62ac29c49c2e@kernel.org> References: <20241004-delstid-v4-0-62ac29c49c2e@kernel.org> In-Reply-To: <20241004-delstid-v4-0-62ac29c49c2e@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3267; i=jlayton@kernel.org; h=from:subject:message-id; bh=9CCT4emkgZ4aNhjimaMLoft7waX5qJm3j1Zwi+hAwSw=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/+sOxNR5js1OIdEyD1VBjMkxCXAGZG1EmjsFO +rnBCNLV1GJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv/rDgAKCRAADmhBGVaC FS/UEADWn9vKI2kmakUnaeIm9XrD2SgscYnwNiaR7ogtsv1R1SqMwSTFrACpzpmcL8clOH42T0d bBOAbNMqKR3Q5J+CAh6uNzxUWMOm450tRDf14pJTI2fOVh2IqPGG3NlTJAFrpLTKxVI36Q77ycI Q+byF+DC0+Sl3GNeV/XVhAe2BwCiuOetx5Zi1nXZGRV13+hboIUNN0L/thANIdbxQjjg3Jg7SNm eJZTf8sM9yEAbFy7Fmb1S4bEHtTBgvLaa2QTAxq3gzLAm6tCVpd2IXdHBF5GpMczeYl2C5/BLUe garxMC4Fc9ISxLWkonuA0U6tORJpW7QDsVglUVrj7s1zlg+lKrvBRHz8zbCoS2HKbeUka3GYNdT 8gnAjX6yI09cZH7mn322IzX+gCj06MdvNDGzvY1mQSip/9oNcxksOD++tPMptXATsAk/hT5ef+Y FQ40XOjy8bGnqaEklyYqABL8tB+lyV8wJGQk5QzgZW0zbUfsZLsjAp711rtetkk1oL17oOHQn80 RVx1FRMbjUneqdMU3SQYuT1C6BEU4WI4iubfoEGKpPJ1G8djt7TXiyDLXJJU1tez8/k8+PG64zq vQWcTbE2PGf7Td+mxz5odPRGWfPukadhykK3SKCCwv9lFsM9fM2Fc5wxji8fturpa/MdPteBDEv 66w8RymIK3+hhkA== 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 b5a6bf4f459fb2309a0ccc9f585c5d6318ceedf1..7f874943583c86dcfe686d38e69949e86b2a723e 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1133,18 +1133,41 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, .na_iattr = &setattr->sa_iattr, .na_seclabel = &setattr->sa_label, }; + struct nfs4_stid *st = NULL; struct inode *inode; __be32 status = nfs_ok; - bool save_no_wcc; + bool save_no_wcc, deleg_attrs; int err; - if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { + deleg_attrs = setattr->sa_bmval[2] & (FATTR4_WORD2_TIME_DELEG_ACCESS | + FATTR4_WORD2_TIME_DELEG_MODIFY); + + if (deleg_attrs || (setattr->sa_iattr.ia_valid & ATTR_SIZE)) { status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, &setattr->sa_stateid, - WR_STATE, NULL, NULL); + WR_STATE, NULL, &st); if (status) return status; } + + /* + * If client is trying to set delegated timestamps, ensure that the + * stateid refers to a write delegation. + */ + if (deleg_attrs) { + status = nfserr_bad_stateid; + if (st->sc_type & SC_TYPE_DELEG) { + struct nfs4_delegation *dp = delegstateid(st); + + if (dp->dl_type == NFS4_OPEN_DELEGATE_WRITE) + status = nfs_ok; + } + } + if (st) + nfs4_put_stid(st); + if (status) + return status; + err = fh_want_write(&cstate->current_fh); if (err) return nfserrno(err); diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 6241e93e9e13410b4fa926c0992127b1cc757b5e..bad75451d18f6d60faf33d6317a79011247ed7e6 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -521,6 +521,26 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, *umask = mask & S_IRWXUGO; iattr->ia_valid |= ATTR_MODE; } + if (bmval[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) { + fattr4_time_deleg_access access; + + if (!xdrgen_decode_fattr4_time_deleg_access(argp->xdr, &access)) + return nfserr_bad_xdr; + iattr->ia_atime.tv_sec = access.seconds; + iattr->ia_atime.tv_nsec = access.nseconds; + iattr->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET | ATTR_DELEG; + } + if (bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) { + fattr4_time_deleg_modify modify; + + if (!xdrgen_decode_fattr4_time_deleg_modify(argp->xdr, &modify)) + return nfserr_bad_xdr; + iattr->ia_mtime.tv_sec = modify.seconds; + iattr->ia_mtime.tv_nsec = modify.nseconds; + iattr->ia_ctime.tv_sec = modify.seconds; + iattr->ia_ctime.tv_nsec = modify.seconds; + iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME | ATTR_MTIME_SET | ATTR_DELEG; + } /* request sanity: did attrlist4 contain the expected number of words? */ if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos)