From patchwork Fri Sep 29 13:58:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13404278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB6C1E71D3A for ; Fri, 29 Sep 2023 13:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232779AbjI2N64 (ORCPT ); Fri, 29 Sep 2023 09:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232748AbjI2N6z (ORCPT ); Fri, 29 Sep 2023 09:58:55 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FD411B0 for ; Fri, 29 Sep 2023 06:58:54 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BED0C433C8; Fri, 29 Sep 2023 13:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695995934; bh=DUPbf/xlMIpfvHuuYT+QR/z03K4DtvB2bU5gqBWPjvc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=NS01UTXxZMO4gNpSS1PLSEr1wynU3/tLPF7heNzGHSieoz3CTu8NGgf/DmZJkWZCq 1gcCfXHqykVjhk63kVcZRDCUi9jI2uQlOqTN4gBRl1nR4TrcWV1mA6+lKv2nPCZf0Z CvPeEnZJyNLDAP679YRc9LZMD+M83ysWxLnLFKQP3KXEbbrHl2xaPxkZ7Esm6JWkMf FFnNJgXE+WSXq9RNhMY7JgiwNZyl1Y6Ye/k+cGH9DJYa6PJLsdg0/Yy33ccyZHdlFC NTUvJSeCYAsUBGqD58Q7dEikrgnZ8jFFJWqzwLRfa8QycBQDW/PpDQQWxkcsVRWbVS brUZA2iE2QaxA== Subject: [PATCH v1 1/7] NFSD: Add nfsd4_encode_lock_owner4() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Fri, 29 Sep 2023 09:58:53 -0400 Message-ID: <169599593304.5622.7690388304950965120.stgit@manet.1015granger.net> In-Reply-To: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> References: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever To improve readability and better align the LOCK encoders with the XDR specification, add an explicit encoder named for the lock_owner4 type. In particular, to avoid code duplication, use nfsd4_encode_clientid4() to encode the clientid in the lock owner rather than open-coding it. It looks to me like nfs4_set_lock_denied() already clears the clientid if it won't return an owner (cf: the nevermind: label). The code in the XDR encoder appears to be redundant and can safely be removed. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index d21aaa56c49a..9f7a6924ef5f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3976,6 +3976,20 @@ nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, return nfsd4_encode_nfs_fh4(xdr, &fhp->fh_handle); } +static __be32 +nfsd4_encode_lock_owner4(struct xdr_stream *xdr, const clientid_t *clientid, + const struct xdr_netobj *owner) +{ + __be32 status; + + /* clientid */ + status = nfsd4_encode_clientid4(xdr, clientid); + if (status != nfs_ok) + return status; + /* owner */ + return nfsd4_encode_opaque(xdr, owner->data, owner->len); +} + /* * Including all fields other than the name, a LOCK4denied structure requires * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. @@ -3984,10 +3998,10 @@ static __be32 nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld) { struct xdr_netobj *conf = &ld->ld_owner; - __be32 *p; + __be32 *p, status; again: - p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); + p = xdr_reserve_space(xdr, XDR_UNIT * 5); if (!p) { /* * Don't fail to return the result just because we can't @@ -4004,14 +4018,11 @@ nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld) p = xdr_encode_hyper(p, ld->ld_start); p = xdr_encode_hyper(p, ld->ld_length); *p++ = cpu_to_be32(ld->ld_type); - if (conf->len) { - p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8); - p = xdr_encode_opaque(p, conf->data, conf->len); - kfree(conf->data); - } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ - p = xdr_encode_hyper(p, (u64)0); /* clientid */ - *p++ = cpu_to_be32(0); /* length of owner name */ - } + status = nfsd4_encode_lock_owner4(xdr, &ld->ld_clientid, + &ld->ld_owner); + if (status != nfs_ok) + return status; + return nfserr_denied; } From patchwork Fri Sep 29 13:58:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13404279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C12E2E71D3D for ; Fri, 29 Sep 2023 13:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232911AbjI2N7E (ORCPT ); Fri, 29 Sep 2023 09:59:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232954AbjI2N7D (ORCPT ); Fri, 29 Sep 2023 09:59:03 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07F711B0 for ; Fri, 29 Sep 2023 06:59:01 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78F25C433C8; Fri, 29 Sep 2023 13:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695995940; bh=yPahKrR9TAHt9lHlZNVcdj/Q6M2DJ2Hdtm+1ETErYxo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XZ8sh3lIa7hWThVs8jRym3snQwaCA6v+1ttM70IsgIM8KqV4lViPbQ8a3TtA6l9un JkHMBPqJ+0z6NsOreuhLaZMEiuKYO6ChNp0U/I/1CxmEVEg/84ybacf6uulSh+TXJZ lj7E+FdJcX51qt622ntN1fjTBmFnsPc6r1Q2afakevTW5bPN75AGlXqfRvXYdVsfS2 k8J7y4QPbIFFM+sBrGTsldik6kZuMZzGPfZwXDnbgFJYHEQwdGMcPxR3ilLyyzxtW9 q2woKF8jSo/nkjRYNGPQqs5SudQwk7sx3Yl6gY5w0KjkDAUZji6Ll9jHlApz4Azb2F ZN/mEw89dh0/A== Subject: [PATCH v1 2/7] NFSD: Refactor nfsd4_encode_lock_denied() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Fri, 29 Sep 2023 09:58:59 -0400 Message-ID: <169599593949.5622.9721527655525429301.stgit@manet.1015granger.net> In-Reply-To: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> References: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Use the modern XDR utility functions. The LOCK and LOCKT encoder functions need to return nfserr_denied when a lock is denied, but nfsd4_encode_lock4denied() should return a status code that is consistent with other XDR encoders. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 73 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 9f7a6924ef5f..ee8a7989f54f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3990,40 +3990,26 @@ nfsd4_encode_lock_owner4(struct xdr_stream *xdr, const clientid_t *clientid, return nfsd4_encode_opaque(xdr, owner->data, owner->len); } -/* -* Including all fields other than the name, a LOCK4denied structure requires -* 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. -*/ static __be32 -nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld) +nfsd4_encode_lock4denied(struct xdr_stream *xdr, + const struct nfsd4_lock_denied *ld) { - struct xdr_netobj *conf = &ld->ld_owner; - __be32 *p, status; + __be32 status; -again: - p = xdr_reserve_space(xdr, XDR_UNIT * 5); - if (!p) { - /* - * Don't fail to return the result just because we can't - * return the conflicting open: - */ - if (conf->len) { - kfree(conf->data); - conf->len = 0; - conf->data = NULL; - goto again; - } - return nfserr_resource; - } - p = xdr_encode_hyper(p, ld->ld_start); - p = xdr_encode_hyper(p, ld->ld_length); - *p++ = cpu_to_be32(ld->ld_type); - status = nfsd4_encode_lock_owner4(xdr, &ld->ld_clientid, - &ld->ld_owner); + /* offset */ + status = nfsd4_encode_offset4(xdr, ld->ld_start); if (status != nfs_ok) return status; - - return nfserr_denied; + /* length */ + status = nfsd4_encode_length4(xdr, ld->ld_length); + if (status != nfs_ok) + return status; + /* locktype */ + if (xdr_stream_encode_u32(xdr, ld->ld_type) != XDR_UNIT) + return nfserr_resource; + /* owner */ + return nfsd4_encode_lock_owner4(xdr, &ld->ld_clientid, + &ld->ld_owner); } static __be32 @@ -4032,13 +4018,21 @@ nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, { struct nfsd4_lock *lock = &u->lock; struct xdr_stream *xdr = resp->xdr; + __be32 status; - if (!nfserr) - nfserr = nfsd4_encode_stateid4(xdr, &lock->lk_resp_stateid); - else if (nfserr == nfserr_denied) - nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied); - - return nfserr; + switch (nfserr) { + case nfs_ok: + /* resok4 */ + status = nfsd4_encode_stateid4(xdr, &lock->lk_resp_stateid); + break; + case nfserr_denied: + /* denied */ + status = nfsd4_encode_lock4denied(xdr, &lock->lk_denied); + break; + default: + return nfserr; + } + return status != nfs_ok ? status : nfserr; } static __be32 @@ -4047,9 +4041,14 @@ nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, { struct nfsd4_lockt *lockt = &u->lockt; struct xdr_stream *xdr = resp->xdr; + __be32 status; - if (nfserr == nfserr_denied) - nfsd4_encode_lock_denied(xdr, &lockt->lt_denied); + if (nfserr == nfserr_denied) { + /* denied */ + status = nfsd4_encode_lock4denied(xdr, &lockt->lt_denied); + if (status != nfs_ok) + return status; + } return nfserr; } From patchwork Fri Sep 29 13:59:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13404280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4A0DE71D3A for ; Fri, 29 Sep 2023 13:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232732AbjI2N7K (ORCPT ); Fri, 29 Sep 2023 09:59:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232748AbjI2N7J (ORCPT ); Fri, 29 Sep 2023 09:59:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A23DB for ; Fri, 29 Sep 2023 06:59:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D64D1C433CB; Fri, 29 Sep 2023 13:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695995947; bh=O6JAotND+8gteUF8xnnr7PwIjoK7phrfdZziEun4m04=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=o/qzNUzFaAwsEvKRLYlWx8oTcMPgWoWR7vflH+KoRR1YUK+Bkst517yQ7+wW4kRYz kEBftZ6ntEIhlBiDcJHapzE48el5o+me1f9gLS0b+9qquU2XNKKp7mCfRaw2swjm8n Xnli4QzZmlofbwM60INsu/l/hJrCnWF3+NmlU10nw2wGf+Oox09jr4houaSI46cKZ9 QoLiQr9ZSfVayb4C6bKesCM6Q7eWT6I3lH60K3Pu5TRgNxAvMXjEtVdLjFu1M051Zn +I9JMBXEEabT7LG+qrmt0ciGZlYmeIGyZp7VWQikSUc51EyNivFXnzBI6/5OOCIY8n +XIEn96bP6J/g== Subject: [PATCH v1 3/7] NFSD: Add nfsd4_encode_open_read_delegation4() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Fri, 29 Sep 2023 09:59:05 -0400 Message-ID: <169599594587.5622.94747681619250190.stgit@manet.1015granger.net> In-Reply-To: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> References: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Refactor nfsd4_encode_open() so the open_read_delegation4 type is encoded in a separate function. This makes it more straightforward to later add support for returning an nfsace4 in OPEN responses that offer a delegation. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4state.c | 6 +++-- fs/nfsd/nfs4xdr.c | 61 ++++++++++++++++++++++++++++++++++++++------------- fs/nfsd/xdr4.h | 2 +- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 22e95b9ae82f..b1118050ff52 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5688,11 +5688,11 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, struct path path; cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client); - open->op_recall = 0; + open->op_recall = false; switch (open->op_claim_type) { case NFS4_OPEN_CLAIM_PREVIOUS: if (!cb_up) - open->op_recall = 1; + open->op_recall = true; break; case NFS4_OPEN_CLAIM_NULL: parent = currentfh; @@ -5746,7 +5746,7 @@ nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS && open->op_delegate_type != NFS4_OPEN_DELEGATE_NONE) { dprintk("NFSD: WARNING: refusing delegation reclaim\n"); - open->op_recall = 1; + open->op_recall = true; } /* 4.1 client asking for a delegation? */ diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index ee8a7989f54f..f411fcc435f6 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4074,6 +4074,49 @@ nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, return nfsd4_encode_change_info4(xdr, &link->li_cinfo); } +/* + * This implementation does not yet support returning an ACE in an + * OPEN that offers a delegation. + */ +static __be32 +nfsd4_encode_open_nfsace4(struct xdr_stream *xdr) +{ + __be32 status; + + /* type */ + status = nfsd4_encode_acetype4(xdr, NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); + if (status != nfs_ok) + return nfserr_resource; + /* flag */ + status = nfsd4_encode_aceflag4(xdr, 0); + if (status != nfs_ok) + return nfserr_resource; + /* access mask */ + status = nfsd4_encode_acemask4(xdr, 0); + if (status != nfs_ok) + return nfserr_resource; + /* who - empty for now */ + if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT) + return nfserr_resource; + return nfs_ok; +} + +static __be32 +nfsd4_encode_open_read_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open) +{ + __be32 status; + + /* stateid */ + status = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid); + if (status != nfs_ok) + return status; + /* recall */ + status = nfsd4_encode_bool(xdr, open->op_recall); + if (status != nfs_ok) + return status; + /* permissions */ + return nfsd4_encode_open_nfsace4(xdr); +} static __be32 nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, @@ -4106,22 +4149,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, case NFS4_OPEN_DELEGATE_NONE: break; case NFS4_OPEN_DELEGATE_READ: - nfserr = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid); - if (nfserr) - return nfserr; - p = xdr_reserve_space(xdr, 20); - if (!p) - return nfserr_resource; - *p++ = cpu_to_be32(open->op_recall); - - /* - * TODO: ACE's in delegations - */ - *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); - *p++ = cpu_to_be32(0); - *p++ = cpu_to_be32(0); - *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ - break; + /* read */ + return nfsd4_encode_open_read_delegation4(xdr, open); case NFS4_OPEN_DELEGATE_WRITE: nfserr = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid); if (nfserr) diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index aba07d5378fc..c142a9b5ab98 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -389,7 +389,7 @@ struct nfsd4_open { u32 op_deleg_want; /* request */ stateid_t op_stateid; /* response */ __be32 op_xdr_error; /* see nfsd4_open_omfg() */ - u32 op_recall; /* recall */ + bool op_recall; /* response */ struct nfsd4_change_info op_cinfo; /* response */ u32 op_rflags; /* response */ bool op_truncate; /* used during processing */ From patchwork Fri Sep 29 13:59:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13404281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66C69E71D3E for ; Fri, 29 Sep 2023 13:59:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232859AbjI2N7Q (ORCPT ); Fri, 29 Sep 2023 09:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232630AbjI2N7P (ORCPT ); Fri, 29 Sep 2023 09:59:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF7F6DB for ; Fri, 29 Sep 2023 06:59:13 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E722C433C7; Fri, 29 Sep 2023 13:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695995953; bh=5OcLGyi8ZK+P310haybX1H+5u659zCcIaFCGHdeV/RM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Srtcgo8rhjwzVAc+gSf/4isxjMLtWPQZi3rp/rxHkRL7AXzg++56Ur4caJ+DkclJx hsfFFnNVkP6E3MAERGr+nOx6WpH6xgxOt3VBYETdRcytzUfEEM1Xzze5gYQS8mf6kB IRY2KRqfPqr+lHr0sIq/R6O/FrWk/+OJOni0H3w8MVzOS/3NWdVWHNo6uoA3+hqRbv THtmrrRlr8uxnA0f7pDwBPmzWuB4RPteXNx2pzHuMjmA4C238RqRAa/hoDqAJ9z83q CKCBu1K42Nm5q5YgwykXz0rgIubtWRU892XOanWerIyqY0/wsWD/d4PT6/fWv49bhZ 2BTfEmJl65yqw== Subject: [PATCH v1 4/7] NFSD: Add nfsd4_encode_open_write_delegation4() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Fri, 29 Sep 2023 09:59:12 -0400 Message-ID: <169599595225.5622.1769103727125659736.stgit@manet.1015granger.net> In-Reply-To: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> References: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Make it easier to adjust the XDR encoder to handle new features related to write delegations. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 59 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index f411fcc435f6..f7e5f54fda00 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4118,6 +4118,37 @@ nfsd4_encode_open_read_delegation4(struct xdr_stream *xdr, struct nfsd4_open *op return nfsd4_encode_open_nfsace4(xdr); } +static __be32 +nfsd4_encode_nfs_space_limit4(struct xdr_stream *xdr, u64 filesize) +{ + /* limitby */ + if (xdr_stream_encode_u32(xdr, NFS4_LIMIT_SIZE) != XDR_UNIT) + return nfserr_resource; + /* filesize */ + return nfsd4_encode_uint64_t(xdr, filesize); +} + +static __be32 +nfsd4_encode_open_write_delegation4(struct xdr_stream *xdr, + struct nfsd4_open *open) +{ + __be32 status; + + /* stateid */ + status = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid); + if (status != nfs_ok) + return status; + /* recall */ + status = nfsd4_encode_bool(xdr, open->op_recall); + if (status != nfs_ok) + return status; + /* space_limit */ + status = nfsd4_encode_nfs_space_limit4(xdr, 0); + if (status != nfs_ok) + return status; + return nfsd4_encode_open_nfsace4(xdr); +} + static __be32 nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, union nfsd4_op_u *u) @@ -4152,32 +4183,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, /* read */ return nfsd4_encode_open_read_delegation4(xdr, open); case NFS4_OPEN_DELEGATE_WRITE: - nfserr = nfsd4_encode_stateid4(xdr, &open->op_delegate_stateid); - if (nfserr) - return nfserr; - - p = xdr_reserve_space(xdr, XDR_UNIT * 8); - if (!p) - return nfserr_resource; - *p++ = cpu_to_be32(open->op_recall); - - /* - * Always flush on close - * - * TODO: space_limit's in delegations - */ - *p++ = cpu_to_be32(NFS4_LIMIT_SIZE); - *p++ = xdr_zero; - *p++ = xdr_zero; - - /* - * TODO: ACE's in delegations - */ - *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); - *p++ = cpu_to_be32(0); - *p++ = cpu_to_be32(0); - *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ - break; + /* write */ + return nfsd4_encode_open_write_delegation4(xdr, open); case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ switch (open->op_why_no_deleg) { case WND4_CONTENTION: From patchwork Fri Sep 29 13:59:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13404282 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBBABE71D3A for ; Fri, 29 Sep 2023 13:59:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232878AbjI2N7W (ORCPT ); Fri, 29 Sep 2023 09:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232630AbjI2N7W (ORCPT ); Fri, 29 Sep 2023 09:59:22 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18BE8DB for ; Fri, 29 Sep 2023 06:59:20 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A7BAC433C8; Fri, 29 Sep 2023 13:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695995959; bh=fEBBG4q4GozGuS1hCXvCLt/QF3UHt39MO0o77fthVGg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=A6fHInVWrRmAkBGc7ULOiMSLBB/ebcBUeUfdWBfPywekh+7b6vGihQogHa26WoOJJ Se7rTC/2+7m0vAcwf0369r2lnclMCvL7wWG2VNBWainwdIcNUHfiu0kG7nCWBI/Kq+ fCcocZ9/S3NF1SR4eXSaZGVdf9sw7UmSYvu8LkUUVwGPQz5o/9QqiQXwTHR+z5PxuV vb+zPozxT3nkgFak8o4LXiTebTKpW6mrqEOqe37kvL51/LKPy+OIYY1mMPkzMPHXw6 eYT5LwIJoHeXhfRpV1mjKSeDM6nMFPiPKQBVOGRcNlogXagpsnD3sUk/wY+iqefxu8 HszY897u0AxGQ== Subject: [PATCH v1 5/7] NFSD: Add nfsd4_encode_open_none_delegation4() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Fri, 29 Sep 2023 09:59:18 -0400 Message-ID: <169599595863.5622.6210947146670583905.stgit@manet.1015granger.net> In-Reply-To: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> References: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever To better align our implementation with the XDR specification, refactor the part of nfsd4_encode_open() that encodes the open_none_delegation4 type. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index f7e5f54fda00..b6c5ccb9351f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4149,6 +4149,27 @@ nfsd4_encode_open_write_delegation4(struct xdr_stream *xdr, return nfsd4_encode_open_nfsace4(xdr); } +static __be32 +nfsd4_encode_open_none_delegation4(struct xdr_stream *xdr, + struct nfsd4_open *open) +{ + __be32 status = nfs_ok; + + /* ond_why */ + if (xdr_stream_encode_u32(xdr, open->op_why_no_deleg) != XDR_UNIT) + return nfserr_resource; + switch (open->op_why_no_deleg) { + case WND4_CONTENTION: + /* ond_server_will_push_deleg */ + status = nfsd4_encode_bool(xdr, false); + break; + case WND4_RESOURCE: + /* ond_server_will_signal_avail */ + status = nfsd4_encode_bool(xdr, false); + } + return status; +} + static __be32 nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, union nfsd4_op_u *u) @@ -4185,24 +4206,9 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, case NFS4_OPEN_DELEGATE_WRITE: /* write */ return nfsd4_encode_open_write_delegation4(xdr, open); - case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ - switch (open->op_why_no_deleg) { - case WND4_CONTENTION: - case WND4_RESOURCE: - p = xdr_reserve_space(xdr, 8); - if (!p) - return nfserr_resource; - *p++ = cpu_to_be32(open->op_why_no_deleg); - /* deleg signaling not supported yet: */ - *p++ = cpu_to_be32(0); - break; - default: - p = xdr_reserve_space(xdr, 4); - if (!p) - return nfserr_resource; - *p++ = cpu_to_be32(open->op_why_no_deleg); - } - break; + case NFS4_OPEN_DELEGATE_NONE_EXT: + /* od_whynone */ + return nfsd4_encode_open_none_delegation4(xdr, open); default: BUG(); } From patchwork Fri Sep 29 13:59:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13404284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 041A3E71D3A for ; Fri, 29 Sep 2023 13:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232748AbjI2N73 (ORCPT ); Fri, 29 Sep 2023 09:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232630AbjI2N72 (ORCPT ); Fri, 29 Sep 2023 09:59:28 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C3081AA for ; Fri, 29 Sep 2023 06:59:26 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE9E2C433C8; Fri, 29 Sep 2023 13:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695995966; bh=wxzSbW218QG/F18fT5HyA7G5D9u74+BhVpjngnoJGWA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=YyeMthW61xnqg9V5Qtmf9oLtJsQJqZxYinOdhDpQvWSZG3uVG3qepjG0n60f69+MH TaQodrJF5O5cfB0HkT6anBUW+uUm30uboP7pNw7A5XWC7WbO8wlEaiSV6c/IL2ZlFL t30VdcPY9HUoPexvpk0l8rebuY8nzEa8Y7MTv/ZrS4BqoUi15Q98Vut7gULhSMqWBz J8rRfsSll7UbvS6IuIqlyXNKJBtOkULKwOpVhebQFnBy5tfIfEZfx0T5+CMBeWqR4Z nAxmspLyLdHgymHiC4ZEISLGweKy0Ebb4UCWLRPxhRl7BPvUfYCuSOrxlhJzbtgPuD RoLAk7MUju2bw== Subject: [PATCH v1 6/7] NFSD: Add nfsd4_encode_open_delegation4() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Fri, 29 Sep 2023 09:59:24 -0400 Message-ID: <169599596495.5622.4730901021436965726.stgit@manet.1015granger.net> In-Reply-To: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> References: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever To better align our implementation with the XDR specification, refactor the part of nfsd4_encode_open() that encodes delegation metadata. As part of that refactor, remove an unnecessary BUG() call site and a comment that appears to be stale. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 56 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index b6c5ccb9351f..f37c370ceded 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4170,13 +4170,43 @@ nfsd4_encode_open_none_delegation4(struct xdr_stream *xdr, return status; } +static __be32 +nfsd4_encode_open_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open) +{ + __be32 status; + + /* delegation_type */ + if (xdr_stream_encode_u32(xdr, open->op_delegate_type) != XDR_UNIT) + return nfserr_resource; + switch (open->op_delegate_type) { + case NFS4_OPEN_DELEGATE_NONE: + status = nfs_ok; + break; + case NFS4_OPEN_DELEGATE_READ: + /* read */ + status = nfsd4_encode_open_read_delegation4(xdr, open); + break; + case NFS4_OPEN_DELEGATE_WRITE: + /* write */ + status = nfsd4_encode_open_write_delegation4(xdr, open); + break; + case NFS4_OPEN_DELEGATE_NONE_EXT: + /* od_whynone */ + status = nfsd4_encode_open_none_delegation4(xdr, open); + break; + default: + status = nfserr_serverfault; + } + + return status; +} + static __be32 nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, union nfsd4_op_u *u) { struct nfsd4_open *open = &u->open; struct xdr_stream *xdr = resp->xdr; - __be32 *p; nfserr = nfsd4_encode_stateid4(xdr, &open->op_stateid); if (nfserr) @@ -4192,28 +4222,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, if (nfserr) return nfserr; - p = xdr_reserve_space(xdr, 4); - if (!p) - return nfserr_resource; - - *p++ = cpu_to_be32(open->op_delegate_type); - switch (open->op_delegate_type) { - case NFS4_OPEN_DELEGATE_NONE: - break; - case NFS4_OPEN_DELEGATE_READ: - /* read */ - return nfsd4_encode_open_read_delegation4(xdr, open); - case NFS4_OPEN_DELEGATE_WRITE: - /* write */ - return nfsd4_encode_open_write_delegation4(xdr, open); - case NFS4_OPEN_DELEGATE_NONE_EXT: - /* od_whynone */ - return nfsd4_encode_open_none_delegation4(xdr, open); - default: - BUG(); - } - /* XXX save filehandle here */ - return 0; + /* delegation */ + return nfsd4_encode_open_delegation4(xdr, open); } static __be32 From patchwork Fri Sep 29 13:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13404285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76813E71D3A for ; Fri, 29 Sep 2023 13:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232916AbjI2N7f (ORCPT ); Fri, 29 Sep 2023 09:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232630AbjI2N7f (ORCPT ); Fri, 29 Sep 2023 09:59:35 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB58D1AA for ; Fri, 29 Sep 2023 06:59:32 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C068C433C8; Fri, 29 Sep 2023 13:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695995972; bh=NJp3dAaM03Cr5ke8bbeyFNzuK+FgYsXTuo57muJ6o/s=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jQieTRjm/21dXtHVCY6VUYv1pjDbS9fia+C3THo6jtPwqZQpq0H/AZ4RZ8LP+CzA9 0LjIdwiWVh3yH0JILre7CSoizMGLQRLTGGRceivILY4T/NKPp3cou7u+/qC5J7Sb59 4vKkqZJXKt3zb1NdEbvyYz2bC8SBvRG3tVtoXJpGee7uhnRsD8Udgt/EwARpmv0Nh1 CaXBhkFQxLqooc5fwrRbkI5xMr3bp3BpzTIz4FJdPasZKsUfvGqsqGba+k4XK75Hw6 0VAuLyrqiQDHJiQt2hpXjK4qd8zk0APtVFEa00FER9g+oWNEbsmWa9si3NPbrC/kwl qkxUZmlwWuZdw== Subject: [PATCH v1 7/7] NFSD: Clean up nfsd4_encode_open() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Fri, 29 Sep 2023 09:59:31 -0400 Message-ID: <169599597122.5622.10402091945865573518.stgit@manet.1015granger.net> In-Reply-To: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> References: <169599581942.5622.15965175797823365235.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Finish cleaning up nfsd4_encode_open(). Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index f37c370ceded..143efc24551d 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4208,20 +4208,23 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open = &u->open; struct xdr_stream *xdr = resp->xdr; + /* stateid */ nfserr = nfsd4_encode_stateid4(xdr, &open->op_stateid); - if (nfserr) + if (nfserr != nfs_ok) return nfserr; + /* cinfo */ nfserr = nfsd4_encode_change_info4(xdr, &open->op_cinfo); - if (nfserr) + if (nfserr != nfs_ok) return nfserr; - if (xdr_stream_encode_u32(xdr, open->op_rflags) < 0) - return nfserr_resource; - + /* rflags */ + nfserr = nfsd4_encode_uint32_t(xdr, open->op_rflags); + if (nfserr != nfs_ok) + return nfserr; + /* attrset */ nfserr = nfsd4_encode_bitmap4(xdr, open->op_bmval[0], open->op_bmval[1], open->op_bmval[2]); - if (nfserr) + if (nfserr != nfs_ok) return nfserr; - /* delegation */ return nfsd4_encode_open_delegation4(xdr, open); }