Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3326102pxb; Mon, 1 Mar 2021 07:19:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJx96cxHuY43etNeFGuWfwDgp8i7lTNLb4VkHtHK+zCz8r+bTrbNA/DEKKGpJA9tqIpybkkJ X-Received: by 2002:a17:906:128e:: with SMTP id k14mr16110843ejb.427.1614611941448; Mon, 01 Mar 2021 07:19:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614611941; cv=none; d=google.com; s=arc-20160816; b=exqyWLceq2QQSSeOEcKIjJ0UZ8K4CXi18a2g0nOxlEEv+7cOF0WGLVGKl961nGrRaT prGNBJ0q9PmlgkJPq1pu3R8SZ98RcNHuCPMp62eksqf2K8VGFfPGEt5UkNSl+ZZzYYR5 C1P2yATVndhuEGZWZTTCF17nsV7ewRZ0CMCybRtfqtpTGk9zOtoDJlH6K/iUZ9Uxlywc jCCr4nIkhWOMsOHppEs9UUCtgZ4uqmQAlhthXCix1/zZhaIjv8isyTyw30BtgH9B7KS6 Vaz58a9uaVu9V+PqSD8Z9eyxxh77o60V5A8zZEfW5ClNYpFgNDh6NRijX1GvmVmY3EJI ZiyA== 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:to:from:subject; bh=4tZDoVU8UeVYB9oEAZvqLW5l5JHpmS1N4XeWAIgCvb0=; b=V+VqW/BTDG1vQjJ45FkbVpYErO5kBc1/DipaGWFufoDZWTzxn7zaFJvuYD6y2TYcDC R3/SaV59CEVJAsmzg4qCtoL7lqneMYPBzUv8lSresQ9dGwlER+8P8ILZpiK+dOBlu1ux WIhpTS9MOdnaQAT2PP+D78XVlKX/FP19XPk/DBbnTHcGHSMb2A73MIZLO+Tbn5aGOR0m k7BYk8Toge5tNtBLqQGp+4/+hSTYu5Tbw9GBzVVLDDXNbsmQ6VIbrnhBy9jQ24MKxqQA ODeTnPp/xMebOHrODq6J3RFrienLY2k2srmjzT5HcqS4mSwhlep/OIMq4uXyqfFHpfFA jvcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si10796688ejm.178.2021.03.01.07.18.38; Mon, 01 Mar 2021 07:19:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237020AbhCAPRj (ORCPT + 99 others); Mon, 1 Mar 2021 10:17:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:40672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237039AbhCAPRc (ORCPT ); Mon, 1 Mar 2021 10:17:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C7A7664E12 for ; Mon, 1 Mar 2021 15:16:55 +0000 (UTC) Subject: [PATCH v1 16/42] NFSD: Add a helper that encodes NFSv3 directory offset cookies From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Mon, 01 Mar 2021 10:16:55 -0500 Message-ID: <161461181507.8508.7185607597181053733.stgit@klimt.1015granger.net> In-Reply-To: <161461145466.8508.13379815439337754427.stgit@klimt.1015granger.net> References: <161461145466.8508.13379815439337754427.stgit@klimt.1015granger.net> User-Agent: StGit/1.0-5-g755c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Refactor: De-duplicate identical code that handles encoding of directory offset cookies across page boundaries. Signed-off-by: Chuck Lever --- fs/nfsd/nfs3proc.c | 24 ++---------------------- fs/nfsd/nfs3xdr.c | 36 +++++++++++++++++++++++------------- fs/nfsd/xdr3.h | 2 ++ 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index 93d196752f87..90566cd01bdc 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -495,17 +495,7 @@ nfsd3_proc_readdir(struct svc_rqst *rqstp) count += PAGE_SIZE; } resp->count = count >> 2; - if (resp->offset) { - if (unlikely(resp->offset1)) { - /* we ended up with offset on a page boundary */ - *resp->offset = htonl(offset >> 32); - *resp->offset1 = htonl(offset & 0xffffffff); - resp->offset1 = NULL; - } else { - xdr_encode_hyper(resp->offset, offset); - } - resp->offset = NULL; - } + nfs3svc_encode_cookie3(resp, offset); return rpc_success; } @@ -560,17 +550,7 @@ nfsd3_proc_readdirplus(struct svc_rqst *rqstp) count += PAGE_SIZE; } resp->count = count >> 2; - if (resp->offset) { - if (unlikely(resp->offset1)) { - /* we ended up with offset on a page boundary */ - *resp->offset = htonl(offset >> 32); - *resp->offset1 = htonl(offset & 0xffffffff); - resp->offset1 = NULL; - } else { - xdr_encode_hyper(resp->offset, offset); - } - resp->offset = NULL; - } + nfs3svc_encode_cookie3(resp, offset); out: return rpc_success; diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c index 034e18d9b040..aef72d00d5a9 100644 --- a/fs/nfsd/nfs3xdr.c +++ b/fs/nfsd/nfs3xdr.c @@ -1219,6 +1219,28 @@ static __be32 *encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p, return p; } +/** + * nfs3svc_encode_cookie3 - Encode a directory offset cookie + * @resp: readdir result context + * @offset: offset cookie to encode + * + */ +void nfs3svc_encode_cookie3(struct nfsd3_readdirres *resp, u64 offset) +{ + if (!resp->offset) + return; + + if (resp->offset1) { + /* we ended up with offset on a page boundary */ + *resp->offset = cpu_to_be32(offset >> 32); + *resp->offset1 = cpu_to_be32(offset & 0xffffffff); + resp->offset1 = NULL; + } else { + xdr_encode_hyper(resp->offset, offset); + } + resp->offset = NULL; +} + /* * Encode a directory entry. This one works for both normal readdir * and readdirplus. @@ -1244,19 +1266,7 @@ encode_entry(struct readdir_cd *ccd, const char *name, int namlen, int elen; /* estimated entry length in words */ int num_entry_words = 0; /* actual number of words */ - if (cd->offset) { - u64 offset64 = offset; - - if (unlikely(cd->offset1)) { - /* we ended up with offset on a page boundary */ - *cd->offset = htonl(offset64 >> 32); - *cd->offset1 = htonl(offset64 & 0xffffffff); - cd->offset1 = NULL; - } else { - xdr_encode_hyper(cd->offset, offset64); - } - cd->offset = NULL; - } + nfs3svc_encode_cookie3(cd, offset); /* dprintk("encode_entry(%.*s @%ld%s)\n", diff --git a/fs/nfsd/xdr3.h b/fs/nfsd/xdr3.h index 8073350418ae..e76e9230827e 100644 --- a/fs/nfsd/xdr3.h +++ b/fs/nfsd/xdr3.h @@ -300,6 +300,8 @@ int nfs3svc_encode_commitres(struct svc_rqst *, __be32 *); void nfs3svc_release_fhandle(struct svc_rqst *); void nfs3svc_release_fhandle2(struct svc_rqst *); + +void nfs3svc_encode_cookie3(struct nfsd3_readdirres *resp, u64 offset); int nfs3svc_encode_entry(void *, const char *name, int namlen, loff_t offset, u64 ino, unsigned int);