Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5470302rwi; Mon, 17 Oct 2022 22:39:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6UGDm+sRr7hzLXu/V8LTHr3FmCo8BwGp0yeLr70fli65c0B6UBnOhXib/ScklqPUJvHfIT X-Received: by 2002:a17:903:1c3:b0:185:46d3:8cde with SMTP id e3-20020a17090301c300b0018546d38cdemr1542666plh.141.1666071565681; Mon, 17 Oct 2022 22:39:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666071565; cv=none; d=google.com; s=arc-20160816; b=c13oFpOmaWsapuZfUiIFCsLiW1NnDkDuC4JXjCMcFZWbSQB4+Tp+YDY+EAh5nwI8RK 2/gdlbvB3OXi5Ot8xzWe9BG1HcOu455KrNDaf30HYxEdCQKk8BRiX7gZBOkx+Bf0snM0 tpQlnUIbYgu0sOjEhksxYowWKwiiSqxCG52ruAlCkv9g0MHhYGiBwr2j3E8FBJyhD3px jTemT1cKlQhAAhe33aCHyFYjcS8iO4JQZNu168uhubQchsk1jrWJyMWIKsEvHJpWRoYS JViMQv5iUpYF6XqOsR/xbQ3tAnI26sM3bRi+TB3ptv19dZuZZWOFYWd7nivDTu7VowBL puTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=GceeZYkl20KUlegGIRh8jEIrPlgu5szWrEE8raqg0UQ=; b=fDPnhKnSmRkjBR3tiea9s/tBCO1YwkcjsoKXWHvREd91ifQRqzGjw33IGASOEJwCkD gblXHhDgYN6wD/DVLZmqfHL9FKOJQfJ6CK75AwcYq07m33x4DEvwZLvMdN2Pn2YJUugW oVLiJuQlq6owjK4c7uKWFI32JQL1aUJsxVJeQVAA6ZOfK4uEH0fvb0IleYHCsQ/0ArfY Lm6H3liLIO6zWbIPYktwz1A1+gcFs49/GsbhwyPC/v5T/hl6v9mP89jP5HSuuvSZ1REV Ftl1/a55Cckx4hlvnZOdVQ5BjJ4P9C7pjPJ+7D9ILl7UgI9a2IXCYlbtxlED2Dmm2nrz FvNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=B98bbtI1; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m6-20020a056a00164600b0055fe250267dsi12218264pfc.124.2022.10.17.22.39.13; Mon, 17 Oct 2022 22:39:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=B98bbtI1; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbiJRFPz (ORCPT + 99 others); Tue, 18 Oct 2022 01:15:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbiJRFPz (ORCPT ); Tue, 18 Oct 2022 01:15:55 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0AE09413B for ; Mon, 17 Oct 2022 22:15:53 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29HNYRL4028823 for ; Tue, 18 Oct 2022 05:15:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=GceeZYkl20KUlegGIRh8jEIrPlgu5szWrEE8raqg0UQ=; b=B98bbtI1l74vwPO3taDQM2LzBGt0pIdIOSAvFFpiBUSWhxuFOk08rWkYUGNgyLBAM1rl JsSijSwu2JtAV9NiHv6OHqOS40DnQAn/o3lnOOF49IML7L/LTxxHQwbE4q9OPrqWWN7C b/jVTKgiOZ3LeBowFgImxZkZlMryVRh7gtuamoWVwRonz9F11aNWdYJtg77MOYOju0y4 9uAKIgkn3xhrVU/bfKV5dtJRgGyKX6i+McX/Ia3k+Im6MBcUYbaHCE7p7xMVCQyvvHaz fyyuhi+ttEfRf62UYkpDD0GGctTE4ZjFWm/HNzbPIxPDgDcFpldODTEG59h/2P8MpNNz fQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3k99nt9pkw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Oct 2022 05:15:53 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29I1iwdD017446 for ; Tue, 18 Oct 2022 05:15:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3k8hu6rg0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Oct 2022 05:15:52 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29I5Fpl6031322 for ; Tue, 18 Oct 2022 05:15:51 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3k8hu6rg01-2; Tue, 18 Oct 2022 05:15:51 +0000 From: Dai Ngo To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] NFSD: add support for sending CB_RECALL_ANY Date: Mon, 17 Oct 2022 22:15:38 -0700 Message-Id: <1666070139-18843-2-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666070139-18843-1-git-send-email-dai.ngo@oracle.com> References: <1666070139-18843-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_13,2022-10-17_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210180029 X-Proofpoint-ORIG-GUID: odeWWaa65V01eLivMebPHDfjnnh2d4mU X-Proofpoint-GUID: odeWWaa65V01eLivMebPHDfjnnh2d4mU X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org There is only one nfsd4_callback, cl_recall_any, added for each nfs4_client. Access to it must be serialized. For now it's done by the cl_recall_any_busy flag since it's used only by the delegation shrinker. If there is another consumer of CB_RECALL_ANY then a spinlock must be used. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4callback.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfs4state.c | 27 +++++++++++++++++++++ fs/nfsd/state.h | 8 +++++++ fs/nfsd/xdr4cb.h | 6 +++++ 4 files changed, 105 insertions(+) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index f0e69edf5f0f..03587e1397f4 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -329,6 +329,29 @@ static void encode_cb_recall4args(struct xdr_stream *xdr, } /* + * CB_RECALLANY4args + * + * struct CB_RECALLANY4args { + * uint32_t craa_objects_to_keep; + * bitmap4 craa_type_mask; + * }; + */ +static void +encode_cb_recallany4args(struct xdr_stream *xdr, + struct nfs4_cb_compound_hdr *hdr, uint32_t bmval) +{ + __be32 *p; + + encode_nfs_cb_opnum4(xdr, OP_CB_RECALL_ANY); + p = xdr_reserve_space(xdr, 4); + *p++ = xdr_zero; /* craa_objects_to_keep */ + p = xdr_reserve_space(xdr, 8); + *p++ = cpu_to_be32(1); + *p++ = cpu_to_be32(bmval); + hdr->nops++; +} + +/* * CB_SEQUENCE4args * * struct CB_SEQUENCE4args { @@ -482,6 +505,24 @@ static void nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, struct xdr_stream *xdr, encode_cb_nops(&hdr); } +/* + * 20.6. Operation 8: CB_RECALL_ANY - Keep Any N Recallable Objects + */ +static void +nfs4_xdr_enc_cb_recall_any(struct rpc_rqst *req, + struct xdr_stream *xdr, const void *data) +{ + const struct nfsd4_callback *cb = data; + struct nfs4_cb_compound_hdr hdr = { + .ident = cb->cb_clp->cl_cb_ident, + .minorversion = cb->cb_clp->cl_minorversion, + }; + + encode_cb_compound4args(xdr, &hdr); + encode_cb_sequence4args(xdr, cb, &hdr); + encode_cb_recallany4args(xdr, &hdr, cb->cb_clp->cl_recall_any_bm); + encode_cb_nops(&hdr); +} /* * NFSv4.0 and NFSv4.1 XDR decode functions @@ -520,6 +561,28 @@ static int nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, return decode_cb_op_status(xdr, OP_CB_RECALL, &cb->cb_status); } +/* + * 20.6. Operation 8: CB_RECALL_ANY - Keep Any N Recallable Objects + */ +static int +nfs4_xdr_dec_cb_recall_any(struct rpc_rqst *rqstp, + struct xdr_stream *xdr, + void *data) +{ + struct nfsd4_callback *cb = data; + struct nfs4_cb_compound_hdr hdr; + int status; + + status = decode_cb_compound4res(xdr, &hdr); + if (unlikely(status)) + return status; + status = decode_cb_sequence4res(xdr, cb); + if (unlikely(status || cb->cb_seq_status)) + return status; + status = decode_cb_op_status(xdr, OP_CB_RECALL_ANY, &cb->cb_status); + return status; +} + #ifdef CONFIG_NFSD_PNFS /* * CB_LAYOUTRECALL4args @@ -783,6 +846,7 @@ static const struct rpc_procinfo nfs4_cb_procedures[] = { #endif PROC(CB_NOTIFY_LOCK, COMPOUND, cb_notify_lock, cb_notify_lock), PROC(CB_OFFLOAD, COMPOUND, cb_offload, cb_offload), + PROC(CB_RECALL_ANY, COMPOUND, cb_recall_any, cb_recall_any), }; static unsigned int nfs4_cb_counts[ARRAY_SIZE(nfs4_cb_procedures)]; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 4e718500a00c..c60c937dece6 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2854,6 +2854,31 @@ static const struct tree_descr client_files[] = { [3] = {""}, }; +static int +nfsd4_cb_recall_any_done(struct nfsd4_callback *cb, + struct rpc_task *task) +{ + switch (task->tk_status) { + case -NFS4ERR_DELAY: + rpc_delay(task, 2 * HZ); + return 0; + default: + return 1; + } +} + +static void +nfsd4_cb_recall_any_release(struct nfsd4_callback *cb) +{ + cb->cb_clp->cl_recall_any_busy = false; + atomic_dec(&cb->cb_clp->cl_rpc_users); +} + +static const struct nfsd4_callback_ops nfsd4_cb_recall_any_ops = { + .done = nfsd4_cb_recall_any_done, + .release = nfsd4_cb_recall_any_release, +}; + static struct nfs4_client *create_client(struct xdr_netobj name, struct svc_rqst *rqstp, nfs4_verifier *verf) { @@ -2891,6 +2916,8 @@ static struct nfs4_client *create_client(struct xdr_netobj name, free_client(clp); return NULL; } + nfsd4_init_cb(&clp->cl_recall_any, clp, &nfsd4_cb_recall_any_ops, + NFSPROC4_CLNT_CB_RECALL_ANY); return clp; } diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index e2daef3cc003..49ca06169642 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -411,6 +411,10 @@ struct nfs4_client { unsigned int cl_state; atomic_t cl_delegs_in_recall; + + bool cl_recall_any_busy; + uint32_t cl_recall_any_bm; + struct nfsd4_callback cl_recall_any; }; /* struct nfs4_client_reset @@ -639,8 +643,12 @@ enum nfsd4_cb_op { NFSPROC4_CLNT_CB_OFFLOAD, NFSPROC4_CLNT_CB_SEQUENCE, NFSPROC4_CLNT_CB_NOTIFY_LOCK, + NFSPROC4_CLNT_CB_RECALL_ANY, }; +#define RCA4_TYPE_MASK_RDATA_DLG 0 +#define RCA4_TYPE_MASK_WDATA_DLG 1 + /* Returns true iff a is later than b: */ static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b) { diff --git a/fs/nfsd/xdr4cb.h b/fs/nfsd/xdr4cb.h index 547cf07cf4e0..0d39af1b00a0 100644 --- a/fs/nfsd/xdr4cb.h +++ b/fs/nfsd/xdr4cb.h @@ -48,3 +48,9 @@ #define NFS4_dec_cb_offload_sz (cb_compound_dec_hdr_sz + \ cb_sequence_dec_sz + \ op_dec_sz) +#define NFS4_enc_cb_recall_any_sz (cb_compound_enc_hdr_sz + \ + cb_sequence_enc_sz + \ + 1 + 1 + 1) +#define NFS4_dec_cb_recall_any_sz (cb_compound_dec_hdr_sz + \ + cb_sequence_dec_sz + \ + op_dec_sz) -- 2.9.5