Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp75840rdb; Mon, 18 Sep 2023 08:36:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsXovuSgqGF8Go/SY1udotd9vZ0RJQK7z9qw3xUs2usmmoHfRDy30xnd05cgVM+w/JzHRk X-Received: by 2002:a17:902:ce8a:b0:1c3:a215:a9ba with SMTP id f10-20020a170902ce8a00b001c3a215a9bamr11996318plg.33.1695051404580; Mon, 18 Sep 2023 08:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695051404; cv=none; d=google.com; s=arc-20160816; b=n8tG9Y9QVijJSohOyIM8rwy3/fYj44t5yi+FKqwe+WQa0o/U+hqoWmsQ6EMTuWeGw6 GdWMe1Bz65PnMfa2q8Wzb2KldlvEG0tlqUHRcfchS6mOCLuujpeNVLu5m98gCDLr5+2y GuVhQeHLdP5/6ceWyZSARXY2qqFvtG9CxaUPSp3z4Ib2anhWMloVbvpnriwYIkBgIgAN Q/Z7E1dvTzXFfLJ7LJhamjOoeIeTB5Rgdx86xL0V9L4FPac5hc0wn83zVj1wGahn+Pgi UiSbmDgok8fSq2TiGvqHPS2ATSa1pYvhkXUvbSxtbhFDkyVr9SwzVSUyydPm7CdTdxCq ZByg== 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=cSyah6pKGpX20XT2faCzDajMO8hkk6uWtOlnPjXBplc=; fh=v8a13lpFSZWlL4AptTEJnmXnlqoWXhGCGCgvrcnCT9I=; b=MoJkxqRToU3DWYZoNhah91VoZl8qyol+QPmUDOtakkGq5QIsXStRLK1tp39ny2lCQB WoX2vOdvF3znq/q8LBL5MWmQGEz0LDdr20NvPygzbsgI4IHVEwhEc2IlLBjWcrJl+xZH ylIUB4tzPagyIA0/WqLCMTdaK1NGujg1Qc/yG9WybCilLKnjplzsPKk/GBYOHeszRhti /7kBSu+oPmDc+o3rzWwynGNqMVPd8V2FyiHmJ438DGKD1b5sW1mm2NXuTe5N/nmUeK5w i2jjxQ61/851GC/+3wnS2gEAzI2m01smDHMY37xlDTvGUG9UX4AoLMrP0I1f1Fac4om5 pYKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="b3SM/ChN"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id d15-20020a170903230f00b001c3a2f46800si8651553plh.332.2023.09.18.08.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 08:36:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="b3SM/ChN"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id F180380BB1CA; Mon, 18 Sep 2023 08:28:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229454AbjIRP1u (ORCPT + 99 others); Mon, 18 Sep 2023 11:27:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjIRP1T (ORCPT ); Mon, 18 Sep 2023 11:27:19 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B02EE19BA for ; Mon, 18 Sep 2023 08:24:23 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CCE2C116D6; Mon, 18 Sep 2023 14:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695045695; bh=E8m7IBAU38rUn/tzgzdGVKAGGb/FUXzES+W+Yuv2ErU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=b3SM/ChNoVguyh4RGdM3852LQuRWb0imjkWqYU+oMAio2xeoisKhEJZ+aU5+grLx1 +Mus/6EadyADISGbLDc71vJmvjwBnzzwwzTmWbLryNoFW5frxmrFir32XOqqu3W4UQ 7BlJ+cCh0GQVtBl0hGAB3/eL+oG5u3AOV0olrVNRCoRZUy4aFA9iShxUKs0DS98kCw HqJhOEvfwYNHS3qYHQZau3ZSrt9CNOSu387yl1BNBmJ4x5kY659BYskGfBCdC53Kpa 61iUq5x/1P60AltrRC5HLITGh40ewNpm1mfS1jXMs6KARwNe06Oevg9WI+mzkQ0Ltf Vk9gwzFGLFCNw== Subject: [PATCH v1 45/52] NFSD: Add nfsd4_encode_fattr4_layout_types() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Mon, 18 Sep 2023 10:01:34 -0400 Message-ID: <169504569453.133720.12458816197833544713.stgit@manet.1015granger.net> In-Reply-To: <169504501081.133720.4162400017732492854.stgit@manet.1015granger.net> References: <169504501081.133720.4162400017732492854.stgit@manet.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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 08:28:18 -0700 (PDT) From: Chuck Lever Refactor the encoder for FATTR4_LAYOUT_TYPES into a helper. In a subsequent patch, this helper will be called from a bitmask loop. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index d67fa4b2a2f6..bc0b5bc3e655 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2784,25 +2784,6 @@ static __be32 nfsd4_encode_nfsace4(struct xdr_stream *xdr, struct svc_rqst *rqst return nfsd4_encode_user(xdr, rqstp, ace->who_uid); } -static inline __be32 -nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) -{ - __be32 *p; - unsigned long i = hweight_long(layout_types); - - p = xdr_reserve_space(xdr, 4 + 4 * i); - if (!p) - return nfserr_resource; - - *p++ = cpu_to_be32(i); - - for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) - if (layout_types & (1 << i)) - *p++ = cpu_to_be32(i); - - return 0; -} - #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ FATTR4_WORD0_RDATTR_ERROR) #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID @@ -3312,6 +3293,24 @@ static __be32 nfsd4_encode_fattr4_fs_layout_types(struct xdr_stream *xdr, return nfs_ok; } +static __be32 nfsd4_encode_fattr4_layout_types(struct xdr_stream *xdr, + const struct nfsd4_fattr_args *args) +{ + unsigned long mask = args->exp->ex_layout_types; + int i; + + /* Hamming weight of @mask is the number of layout types to return */ + if (xdr_stream_encode_u32(xdr, hweight_long(mask)) != XDR_UNIT) + return nfserr_resource; + for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) + if (mask & BIT(i)) { + /* layouttype4 */ + if (xdr_stream_encode_u32(xdr, i) != XDR_UNIT) + return nfserr_resource; + } + return nfs_ok; +} + #endif /* @@ -3675,7 +3674,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, } if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) { - status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); + status = nfsd4_encode_fattr4_layout_types(xdr, &args); if (status) goto out; }