Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1217998rdh; Mon, 25 Sep 2023 06:40:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7s7EYhn8o4332ekOD3e6cGATYDBIJc1/Jskw4aEDtb8QgkD0FL0qdiJo2u/VXqaM8RV+7 X-Received: by 2002:a05:6808:1927:b0:3a7:46d2:5203 with SMTP id bf39-20020a056808192700b003a746d25203mr11186999oib.51.1695649236887; Mon, 25 Sep 2023 06:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695649236; cv=none; d=google.com; s=arc-20160816; b=xG6O9fI/LEPGMpiHO4Qx9Hrsa98hjZAXqMbX4o4lh9raBaYHzAQ/gv4aK5uqDxtsD+ wH3v12H6mAaxsCv+GSOKfRzrYMfxKZ65w/ltSfZvUjV/lXQbFBzo49NUt0gseJHpepDm zgCXnQdp7l5MaH8Bck0F6SHTsM6uVafHLmRS7l+gsGnDlhtbR0+9BFXx3UPLxim7ZjzA I4Rma4xB+6NUufCq1Be+W1HAKm74uvPylsjowvY1pqHD164y20/8rGdfvK47kSYhHrrY AkPJGt9+K+qEg4M/YCxKeSLlOC7qWhcCtPNxUQ6nSbWJDjV1KM1sOkXOUrrhojs8H+je CkqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=jUYN0pxHEIyRWga5iyQSnqB4mnyEwVLUulj90TcPJIw=; fh=v8a13lpFSZWlL4AptTEJnmXnlqoWXhGCGCgvrcnCT9I=; b=jFd5cU1+QZ2hFcidMgFwtJCHfgonkhhTvC6BXE1Eo33kb8j5L4OfbrAOZKecnAjtm7 r805LAVhjfe9sNlnKANLRFwvtUDH+ONO9fqOLXlul1kGm8FPKGgJL5qMrUhoWyPUS9eP QWKBeVPHwVRgUzVQFmbThIc+d6cMLZOmZcrinGc6QoRvsqQMHa/bnAbFlM8sWRWQvCdn zANiGG3+jg0o2SBEz77NTOF72UXd8kEGAKAGy1pq0PsyllLNQhQRA7hXsvQRVsSn+HAg ABPGn65oeBw2m/suQJlMJKsFAIOJG42aiL+G8LgDTdzxWDdDJoRs8d838s6uJn06tnAQ OxMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LTm/eh2P"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id y21-20020a056a00191500b0068fbbef7909si10647678pfi.256.2023.09.25.06.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 06:40:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LTm/eh2P"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D97628242F51; Mon, 25 Sep 2023 06:28:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230448AbjIYN2c (ORCPT + 99 others); Mon, 25 Sep 2023 09:28:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231700AbjIYN2b (ORCPT ); Mon, 25 Sep 2023 09:28:31 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF5F0B8 for ; Mon, 25 Sep 2023 06:28:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68218C433C8; Mon, 25 Sep 2023 13:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695648504; bh=G/bXoA9mKPp9YLw+SvEAo0eiZMYNcLkppZYWlcWGEhw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=LTm/eh2PhM8Tq8wEJ3oRSDB17QCs89tk1Z0E3uLXKGyMCk7vXOHCUwbjIrSUSyNhq qGo5CIEp+SFe9xmoYeavAqtBH6LA5KttbtzOqQnt3N9tZgQlBFMwrjYNI83DJVFufS /m5z65sgpS8UkBOyGy0QczXHQ8ooatdCAlHzrQguRniwFXzMuTh+r0GUpeSynyFRHT qZfpd/T80I2Hv7H7nt/wfNfX1DOX1a0OBgsW8bOrZaLgEpHBeQjWluqWMuqLkkhQ+M 8tG0rVJg5p/EzJP5a9fyQg6xKlIrLvKF14Ai60m9CuOIRo+LY6PuTcy83PMjfMe41w 1PKRxQcVcY83Q== Subject: [PATCH v1 8/8] NFSD: Clean up nfsd4_encode_getdeviceinfo() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Mon, 25 Sep 2023 09:28:23 -0400 Message-ID: <169564850350.6013.3077886286377364961.stgit@klimt.1015granger.net> In-Reply-To: <169564827064.6013.5014460767978657478.stgit@klimt.1015granger.net> References: <169564827064.6013.5014460767978657478.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 06:28:28 -0700 (PDT) From: Chuck Lever Adopt the conventional XDR utility functions. Also, restructure to make the function align more closely with the spec -- there doesn't seem to be a performance need for speciality code, so prioritize readability. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 72 ++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 38217ac74b01..d21aaa56c49a 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4807,59 +4807,57 @@ nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, #ifdef CONFIG_NFSD_PNFS static __be32 -nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, - union nfsd4_op_u *u) +nfsd4_encode_device_addr4(struct xdr_stream *xdr, + const struct nfsd4_getdeviceinfo *gdev) { - struct nfsd4_getdeviceinfo *gdev = &u->getdeviceinfo; - struct xdr_stream *xdr = resp->xdr; + u32 needed_len, starting_len = xdr->buf->len; const struct nfsd4_layout_ops *ops; - u32 starting_len = xdr->buf->len, needed_len; - __be32 *p; + __be32 status; - p = xdr_reserve_space(xdr, 4); - if (!p) + /* da_layout_type */ + if (xdr_stream_encode_u32(xdr, gdev->gd_layout_type) != XDR_UNIT) return nfserr_resource; - - *p++ = cpu_to_be32(gdev->gd_layout_type); - + /* da_addr_body */ ops = nfsd4_layout_ops[gdev->gd_layout_type]; - nfserr = ops->encode_getdeviceinfo(xdr, gdev); - if (nfserr) { + status = ops->encode_getdeviceinfo(xdr, gdev); + if (status != nfs_ok) { /* - * We don't bother to burden the layout drivers with - * enforcing gd_maxcount, just tell the client to - * come back with a bigger buffer if it's not enough. + * Don't burden the layout drivers with enforcing + * gd_maxcount. Just tell the client to come back + * with a bigger buffer if it's not enough. */ - if (xdr->buf->len + 4 > gdev->gd_maxcount) + if (xdr->buf->len + XDR_UNIT > gdev->gd_maxcount) goto toosmall; - return nfserr; + return status; } - if (gdev->gd_notify_types) { - p = xdr_reserve_space(xdr, 4 + 4); - if (!p) - return nfserr_resource; - *p++ = cpu_to_be32(1); /* bitmap length */ - *p++ = cpu_to_be32(gdev->gd_notify_types); - } else { - p = xdr_reserve_space(xdr, 4); - if (!p) - return nfserr_resource; - *p++ = 0; - } + return nfs_ok; - return 0; toosmall: - dprintk("%s: maxcount too small\n", __func__); - needed_len = xdr->buf->len + 4 /* notifications */; + needed_len = xdr->buf->len + XDR_UNIT; /* notifications */ xdr_truncate_encode(xdr, starting_len); - p = xdr_reserve_space(xdr, 4); - if (!p) - return nfserr_resource; - *p++ = cpu_to_be32(needed_len); + + status = nfsd4_encode_count4(xdr, needed_len); + if (status != nfs_ok) + return status; return nfserr_toosmall; } +static __be32 +nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, + union nfsd4_op_u *u) +{ + struct nfsd4_getdeviceinfo *gdev = &u->getdeviceinfo; + struct xdr_stream *xdr = resp->xdr; + + /* gdir_device_addr */ + nfserr = nfsd4_encode_device_addr4(xdr, gdev); + if (nfserr) + return nfserr; + /* gdir_notification */ + return nfsd4_encode_bitmap4(xdr, gdev->gd_notify_types, 0, 0); +} + static __be32 nfsd4_encode_layout4(struct xdr_stream *xdr, const struct nfsd4_layoutget *lgp) {