From patchwork Wed Apr 6 22:45:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804156 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 DE42EC4332F for ; Wed, 6 Apr 2022 22:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237224AbiDFWru (ORCPT ); Wed, 6 Apr 2022 18:47:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237344AbiDFWrm (ORCPT ); Wed, 6 Apr 2022 18:47:42 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C96817941E for ; Wed, 6 Apr 2022 15:45:42 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236LdvcO006381; Wed, 6 Apr 2022 22:45:41 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-2021-07-09; bh=ggIXVGT9l8eJfTtRVhpwQVfYgFowHViLiSH6Kn5NsjU=; b=rlNZ6b6OmetkzzMc6Uz4Y4HijDMr1GCCuaR+2lzqhkQkSREhKO5SrSxRV+Wl/RSmVSm4 XZbXtOm0Oym9LrDuXfSzj6N/XaJ+l2kpu9uOgIKLhfRxczCYwIVALvVtmmre7k4I+JS/ 0x3xjx46r7hmSNokRlp5fgoW3igK51wb7ciDIsuI9Av9Fc3a/w6Zb9OA6MfZybI9iTPK pGzpYlJS5yCWR/YswB/gZsx/isJDf7eVNbtRI7fA3QcdRBaCU+CO04FZBKeFY+n1bFTn 3iAjmHs/6e70Y3+DjvLprMRHT7Y+PbOIMoDuHm9p2FUMORB2l0t7stShifyYDHI4pGeZ 5Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6d31jd7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:41 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeYDG011627; Wed, 6 Apr 2022 22:45:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5n2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:40 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236MjcbY021908; Wed, 6 Apr 2022 22:45:39 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-2; Wed, 06 Apr 2022 22:45:39 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 01/10] NFSD: Add courtesy client state, macro and spinlock to support courteous server Date: Wed, 6 Apr 2022 15:45:24 -0700 Message-Id: <1649285133-16765-2-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: tPOtoU9fv8I0hCWFL9nB2WE5czJimyOf X-Proofpoint-ORIG-GUID: tPOtoU9fv8I0hCWFL9nB2WE5czJimyOf Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update nfs4_client to add: . cl_cs_client_state: courtesy client state . cl_cs_lock: spinlock to synchronize access to cl_cs_client_state . cl_cs_list: list used by laundromat to process courtesy clients Modify alloc_client to initialize these fields. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 2 ++ fs/nfsd/nfsd.h | 1 + fs/nfsd/state.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 234e852fcdfa..a65d59510681 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2009,12 +2009,14 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name) INIT_LIST_HEAD(&clp->cl_delegations); INIT_LIST_HEAD(&clp->cl_lru); INIT_LIST_HEAD(&clp->cl_revoked); + INIT_LIST_HEAD(&clp->cl_cs_list); #ifdef CONFIG_NFSD_PNFS INIT_LIST_HEAD(&clp->cl_lo_states); #endif INIT_LIST_HEAD(&clp->async_copies); spin_lock_init(&clp->async_lock); spin_lock_init(&clp->cl_lock); + spin_lock_init(&clp->cl_cs_lock); rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); return clp; err_no_hashtbl: diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 4fc1fd639527..23996c6ca75e 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void); #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */ #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */ +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */ /* * The following attributes are currently not supported by the NFSv4 server: diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 95457cfd37fc..7f78da5d1408 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -283,6 +283,35 @@ struct nfsd4_sessionid { #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */ /* + * State Meaning Where set + * -------------------------------------------------------------------------- + * | CLIENT_ACTIVE | Confirmed, active | Default | + * |------------------- ----------------------------------------------------| + * | CLIENT_COURTESY | Courtesy state. | nfs4_get_client_reaplist | + * | | Lease/lock/share | | + * | | reservation conflict | | + * | | can cause Courtesy | | + * | | client to be expired | | + * |------------------------------------------------------------------------| + * | CLIENT_EXPIRED | Courtesy client to be| nfs4_laundromat | + * | | expired by Laundromat| nfsd4_lm_lock_expired | + * | | due to conflict | nfsd4_discard_courtesy_clnt | + * | | | nfsd4_expire_courtesy_clnt | + * |------------------------------------------------------------------------| + * | CLIENT_RECONNECT | Courtesy client | nfsd4_courtesy_clnt_expired | + * | | reconnected, | | + * | | becoming active | | + * -------------------------------------------------------------------------- + */ + +enum courtesy_client_state { + NFSD4_CLIENT_ACTIVE = 0, + NFSD4_CLIENT_COURTESY, + NFSD4_CLIENT_EXPIRED, + NFSD4_CLIENT_RECONNECTED, +}; + +/* * struct nfs4_client - one per client. Clientids live here. * * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0) @@ -385,6 +414,10 @@ struct nfs4_client { struct list_head async_copies; /* list of async copies */ spinlock_t async_lock; /* lock for async copies */ atomic_t cl_cb_inflight; /* Outstanding callbacks */ + + enum courtesy_client_state cl_cs_client_state; + spinlock_t cl_cs_lock; + struct list_head cl_cs_list; }; /* struct nfs4_client_reset From patchwork Wed Apr 6 22:45:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804151 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 21555C433F5 for ; Wed, 6 Apr 2022 22:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233133AbiDFWrq (ORCPT ); Wed, 6 Apr 2022 18:47:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237341AbiDFWrm (ORCPT ); Wed, 6 Apr 2022 18:47:42 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C82F177D2A for ; Wed, 6 Apr 2022 15:45:43 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236Jihh5014690; Wed, 6 Apr 2022 22:45:42 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-2021-07-09; bh=9zXBUnXiKF+VqRq8fk8LNIdhG+VXmNB6K4p7mldr7g4=; b=VaQx0Z/rZHfsinfUMmsK/qj/EUNrjsskmhWeQS/iwcTFJTVtNgrEWbuxqisll1vLzfsM qrxhWnnKwVxopdx6W0YbqCwSSwvzlFH3A/FFUWcW8VNEwIdSLJCmonD99XAYFj3duX/P iGWBpFi/ptaDN0EVKYtfzU4K1Rie5RGBaoO8qltaPXq3qHvBkwFeVj5E3MBLI57epFvF uNsdFMGrCh7ZBannvQR5qWi7KrZd6LMaR2+t1DOJgz8JxJO12Q6xDr+XbnOK9s+8dl7r 9gXs1BV6ry/S6LITlFkEX08yDlEFQiaG1Oo63FX3i5x/4YjFD9EoMi6CnOX2HXTMtGgm fw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6ec9t3rk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:42 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeZJI011641; Wed, 6 Apr 2022 22:45:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5ne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:40 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcba021908; Wed, 6 Apr 2022 22:45:40 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-3; Wed, 06 Apr 2022 22:45:40 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 02/10] NFSD: Add lm_lock_expired call out Date: Wed, 6 Apr 2022 15:45:25 -0700 Message-Id: <1649285133-16765-3-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: 1KDKDFYP5YzGBw_FeHcv5PPQ8akpaiCe X-Proofpoint-ORIG-GUID: 1KDKDFYP5YzGBw_FeHcv5PPQ8akpaiCe Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add callout function nfsd4_lm_lock_expired for lm_lock_expired. If lock request has conflict with courtesy client then expire the courtesy client and return no conflict to caller. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 22 ++++++++++++++++++++++ fs/nfsd/state.h | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index a65d59510681..80772662236b 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6578,10 +6578,32 @@ nfsd4_lm_notify(struct file_lock *fl) } } +/** + * nfsd4_lm_lock_expired - check if lock conflict can be resolved. + * + * @fl: pointer to file_lock with a potential conflict + * Return values: + * %false: real conflict, lock conflict can not be resolved. + * %true: no conflict, lock conflict was resolved. + * + * Note that this function is called while the flc_lock is held. + */ +static bool +nfsd4_lm_lock_expired(struct file_lock *fl) +{ + struct nfs4_lockowner *lo; + + if (!fl) + return false; + lo = (struct nfs4_lockowner *)fl->fl_owner; + return nfsd4_expire_courtesy_clnt(lo->lo_owner.so_client); +} + static const struct lock_manager_operations nfsd_posix_mng_ops = { .lm_notify = nfsd4_lm_notify, .lm_get_owner = nfsd4_lm_get_owner, .lm_put_owner = nfsd4_lm_put_owner, + .lm_lock_expired = nfsd4_lm_lock_expired, }; static inline void diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 7f78da5d1408..8b81493ee48a 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -735,4 +735,18 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp); extern int nfsd4_client_record_check(struct nfs4_client *clp); extern void nfsd4_record_grace_done(struct nfsd_net *nn); +static inline bool +nfsd4_expire_courtesy_clnt(struct nfs4_client *clp) +{ + bool rc = false; + + spin_lock(&clp->cl_cs_lock); + if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY) + clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED; + if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED) + rc = true; + spin_unlock(&clp->cl_cs_lock); + return rc; +} + #endif /* NFSD4_STATE_H */ From patchwork Wed Apr 6 22:45:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804154 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 13484C433EF for ; Wed, 6 Apr 2022 22:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237219AbiDFWrs (ORCPT ); Wed, 6 Apr 2022 18:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237345AbiDFWrm (ORCPT ); Wed, 6 Apr 2022 18:47:42 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D0CC179422 for ; Wed, 6 Apr 2022 15:45:43 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236KgkhR012570; Wed, 6 Apr 2022 22:45:42 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-2021-07-09; bh=0EQOOOdY4EGMVPmEDzzSC8tjUGihm8PKNfnZJ9IAmRs=; b=nIgYMfsFet+K0m10mxseZld80jQmLB0gQMKNY4BzwY5rE48/TWBrnu68K9HU4PCd73me FoqMAzMMwf3syQyfXUG4Z1BLh0DJsgx1FDdS7BNNpnCdeahJLTDvzoelR0rQbOZ6YhbF RBrtbO4bCuADx875XHLlT2qNfB2DuXh0ldJxm7DfFgNR+nVQqzQ15th4IqT0tXQ0sQ80 Z9deWQW7Dsr1zBfzrdz733yxP+LzlAu9bHA7G3WauFxPgb0pvHxsIi0cKrzveCcbrl/G ZNXXeF8uiWOT3z/O9lSOSTVPb2vNSmr35dDRPgW9taF+8jh08f8J/HWD2cTyg69sOoGm SA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6cwcj1k1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:42 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeY3m011594; Wed, 6 Apr 2022 22:45:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5np-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:41 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbc021908; Wed, 6 Apr 2022 22:45:41 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-4; Wed, 06 Apr 2022 22:45:41 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 03/10] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy client Date: Wed, 6 Apr 2022 15:45:26 -0700 Message-Id: <1649285133-16765-4-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: nJZ0-yZGQk6wQjmJaiLfrVV89aIQ6TQK X-Proofpoint-GUID: nJZ0-yZGQk6wQjmJaiLfrVV89aIQ6TQK Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update nfsd_breaker_owns_lease() to handle delegation conflict with courtesy client by calling nfsd4_expire_courtesy_clnt. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 80772662236b..f20c75890594 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4727,6 +4727,9 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl) struct svc_rqst *rqst; struct nfs4_client *clp; + if (nfsd4_expire_courtesy_clnt(dl->dl_stid.sc_client)) + return true; + if (!i_am_nfsd()) return false; rqst = kthread_data(current); From patchwork Wed Apr 6 22:45:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804155 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 519A1C433FE for ; Wed, 6 Apr 2022 22:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237222AbiDFWrt (ORCPT ); Wed, 6 Apr 2022 18:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237342AbiDFWrm (ORCPT ); Wed, 6 Apr 2022 18:47:42 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE6017666C for ; Wed, 6 Apr 2022 15:45:44 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236MCZBO001019; Wed, 6 Apr 2022 22:45:43 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-2021-07-09; bh=7m5VLcqBEMVCYwIs+MEvIHvY/see9DZZ11OwFVzEYfM=; b=1EEu0qK8kHFmS7x7KBPE3OF4AF5MbhjVgaNWt5KUoW/d57tvOzG9SuQQ1JXnnIaR4ZtU 120s+lyjDhInwQKPqjsD+AHbcYBf7Y9uJt7nvo8qwk0HbW00oyYkgEvOxcWcxKXRxUej osmjT4PGZ3rdGYLhc/bSFUdupdT7pbnv1ynBdKpZxwaoRDj1OFEECIjuaavO4MUr5PiX z4JElnxkHaNG4otE7qNPZFnFs1SmOyNd+gnz8Xy3p3A7Hliz8p01pq3jaGwzl9zKIcvr a46ftGZm1yfxB6rLC5rmXbDEgGfBM98UU44MtVkPjHqsxGX+ZlK1r/EsFz9RB/VhnXvy yQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6e3st989-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:42 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeZKD011642; Wed, 6 Apr 2022 22:45:42 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5p4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:42 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbe021908; Wed, 6 Apr 2022 22:45:41 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-5; Wed, 06 Apr 2022 22:45:41 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 04/10] NFSD: Update nfs4_get_vfs_file() to handle courtesy client Date: Wed, 6 Apr 2022 15:45:27 -0700 Message-Id: <1649285133-16765-5-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: CTq_nzrmuWhVqrCOKNzGm6IJn7Tudpe7 X-Proofpoint-GUID: CTq_nzrmuWhVqrCOKNzGm6IJn7Tudpe7 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share reservation conflict with courtesy client. Update nfs4_get_vfs_file and nfs4_upgrade_open to handle share reservation conflict with courtesy client. When we have deny/access conflict we walk the fi_stateids of the file in question, looking for open stateid and check the deny/access of that stateid against the one from the open request. If there is a conflict then we check if the client that owns that stateid is a courtesy client. If it is then we set the client state to CLIENT_EXPIRED and allow the open request to continue. We have to scan all the stateid's of the file since the conflict can be caused by multiple open stateid's. Client with CLIENT_EXPIRED is expired by the laundromat. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 85 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index f20c75890594..fe8969ba94b3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -701,9 +701,56 @@ __nfs4_file_get_access(struct nfs4_file *fp, u32 access) atomic_inc(&fp->fi_access[O_RDONLY]); } +/* + * Check if courtesy clients have conflicting access and resolve it if possible + * + * access: is op_share_access if share_access is true. + * Check if access mode, op_share_access, would conflict with + * the current deny mode of the file 'fp'. + * access: is op_share_deny if share_access is false. + * Check if the deny mode, op_share_deny, would conflict with + * current access of the file 'fp'. + * stp: skip checking this entry. + * new_stp: normal open, not open upgrade. + * + * Function returns: + * false - access/deny mode conflict with normal client. + * true - no conflict or conflict with courtesy client(s) is resolved. + */ +static bool +nfs4_resolve_deny_conflicts_locked(struct nfs4_file *fp, bool new_stp, + struct nfs4_ol_stateid *stp, u32 access, bool share_access) +{ + struct nfs4_ol_stateid *st; + struct nfs4_client *clp; + bool conflict = true; + unsigned char bmap; + + lockdep_assert_held(&fp->fi_lock); + list_for_each_entry(st, &fp->fi_stateids, st_perfile) { + /* ignore lock stateid */ + if (st->st_openstp) + continue; + if (st == stp && new_stp) + continue; + /* check file access against deny mode or vice versa */ + bmap = share_access ? st->st_deny_bmap : st->st_access_bmap; + if (!(access & bmap_to_share_mode(bmap))) + continue; + clp = st->st_stid.sc_client; + if (nfsd4_expire_courtesy_clnt(clp)) + continue; + conflict = false; + break; + } + return conflict; +} + static __be32 -nfs4_file_get_access(struct nfs4_file *fp, u32 access) +nfs4_file_get_access(struct nfs4_file *fp, u32 access, + struct nfs4_ol_stateid *stp, bool new_stp) { + lockdep_assert_held(&fp->fi_lock); /* Does this access mode make sense? */ @@ -711,15 +758,21 @@ nfs4_file_get_access(struct nfs4_file *fp, u32 access) return nfserr_inval; /* Does it conflict with a deny mode already set? */ - if ((access & fp->fi_share_deny) != 0) - return nfserr_share_denied; + if ((access & fp->fi_share_deny) != 0) { + if (!nfs4_resolve_deny_conflicts_locked(fp, new_stp, + stp, access, true)) + return nfserr_share_denied; + } __nfs4_file_get_access(fp, access); return nfs_ok; } -static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny) +static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny, + struct nfs4_ol_stateid *stp, bool new_stp) { + __be32 rc = nfs_ok; + /* Common case is that there is no deny mode. */ if (deny) { /* Does this deny mode make sense? */ @@ -728,13 +781,19 @@ static __be32 nfs4_file_check_deny(struct nfs4_file *fp, u32 deny) if ((deny & NFS4_SHARE_DENY_READ) && atomic_read(&fp->fi_access[O_RDONLY])) - return nfserr_share_denied; + rc = nfserr_share_denied; if ((deny & NFS4_SHARE_DENY_WRITE) && atomic_read(&fp->fi_access[O_WRONLY])) - return nfserr_share_denied; + rc = nfserr_share_denied; + + if (rc == nfserr_share_denied) { + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp, + stp, deny, false)) + rc = nfs_ok; + } } - return nfs_ok; + return rc; } static void __nfs4_file_put_access(struct nfs4_file *fp, int oflag) @@ -4952,7 +5011,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh, static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp, - struct nfsd4_open *open) + struct nfsd4_open *open, bool new_stp) { struct nfsd_file *nf = NULL; __be32 status; @@ -4966,14 +5025,14 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp, * Are we trying to set a deny mode that would conflict with * current access? */ - status = nfs4_file_check_deny(fp, open->op_share_deny); + status = nfs4_file_check_deny(fp, open->op_share_deny, stp, new_stp); if (status != nfs_ok) { spin_unlock(&fp->fi_lock); goto out; } /* set access to the file */ - status = nfs4_file_get_access(fp, open->op_share_access); + status = nfs4_file_get_access(fp, open->op_share_access, stp, new_stp); if (status != nfs_ok) { spin_unlock(&fp->fi_lock); goto out; @@ -5027,11 +5086,11 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c unsigned char old_deny_bmap = stp->st_deny_bmap; if (!test_access(open->op_share_access, stp)) - return nfs4_get_vfs_file(rqstp, fp, cur_fh, stp, open); + return nfs4_get_vfs_file(rqstp, fp, cur_fh, stp, open, false); /* test and set deny mode */ spin_lock(&fp->fi_lock); - status = nfs4_file_check_deny(fp, open->op_share_deny); + status = nfs4_file_check_deny(fp, open->op_share_deny, stp, false); if (status == nfs_ok) { set_deny(open->op_share_deny, stp); fp->fi_share_deny |= @@ -5376,7 +5435,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf goto out; } } else { - status = nfs4_get_vfs_file(rqstp, fp, current_fh, stp, open); + status = nfs4_get_vfs_file(rqstp, fp, current_fh, stp, open, true); if (status) { stp->st_stid.sc_type = NFS4_CLOSED_STID; release_open_stateid(stp); From patchwork Wed Apr 6 22:45:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804153 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 193E0C433F5 for ; Wed, 6 Apr 2022 22:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237217AbiDFWrr (ORCPT ); Wed, 6 Apr 2022 18:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237352AbiDFWrn (ORCPT ); Wed, 6 Apr 2022 18:47:43 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94C9F198EE8 for ; Wed, 6 Apr 2022 15:45:45 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236JV8QD014716; Wed, 6 Apr 2022 22:45:44 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-2021-07-09; bh=dTenKcU8PpnAqDdAJyYJ7vdmgRE/7uhM1oGSN99Liyg=; b=KvfJ0WiVABlO6/EN5KkChqZqt3cfncWtSUh3aViWCn4bZcKeCw49ZZKpaDuBB5kLXKLf tUWPWk8U85+D5yFtVKlRrbc+VXglsSlO/MdM35GSe4h4bZCOq/rnoUdBA+4JgxGcpFeC rq62Zj2whV6wTRF6g/NNvsBoT9Ltm6ugkZx/ZOPD1Pqvt/fefxH1nbrHM9vskwo4SONP Dj7A5w7yuoMrazsHrUwfDqZXNf/R8+wz7lCAR/gSP0xxxdHFkm/zrvYeesugHMNWWiZg mNZytsaEz9ULX5kfm95P0/P2wROkQtkhuen8ASHlxnR4rLNJnA9Ls3u4XpbkF2ZAaY4p 2w== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6ec9t3rn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:44 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeZXc011713; Wed, 6 Apr 2022 22:45:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5pb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:43 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbg021908; Wed, 6 Apr 2022 22:45:42 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-6; Wed, 06 Apr 2022 22:45:42 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 05/10] NFSD: Update find_clp_in_name_tree() to handle courtesy client Date: Wed, 6 Apr 2022 15:45:28 -0700 Message-Id: <1649285133-16765-6-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: gNbxruvvVfBxalhUsUlrXnF2pCm-H4Bq X-Proofpoint-ORIG-GUID: gNbxruvvVfBxalhUsUlrXnF2pCm-H4Bq Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update find_clp_in_name_tree to check and expire courtesy client. Update find_confirmed_client_by_name to discard the courtesy client by setting CLIENT_EXPIRED. Update nfsd4_setclientid to expire client with CLIENT_EXPIRED state to prevent multiple confirmed clients with the same name on the conf_name_tree. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 25 ++++++++++++++++++++++--- fs/nfsd/state.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index fe8969ba94b3..d14cea763511 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2893,8 +2893,11 @@ find_clp_in_name_tree(struct xdr_netobj *name, struct rb_root *root) node = node->rb_left; else if (cmp < 0) node = node->rb_right; - else + else { + if (nfsd4_courtesy_clnt_expired(clp)) + return NULL; return clp; + } } return NULL; } @@ -2973,8 +2976,13 @@ static bool clp_used_exchangeid(struct nfs4_client *clp) static struct nfs4_client * find_confirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn) { + struct nfs4_client *clp; + lockdep_assert_held(&nn->client_lock); - return find_clp_in_name_tree(name, &nn->conf_name_tree); + clp = find_clp_in_name_tree(name, &nn->conf_name_tree); + if (clp && nfsd4_discard_reconnect_clnt(clp)) + clp = NULL; + return clp; } static struct nfs4_client * @@ -4091,12 +4099,19 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfs4_client *unconf = NULL; __be32 status; struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); + struct nfs4_client *cclient = NULL; new = create_client(clname, rqstp, &clverifier); if (new == NULL) return nfserr_jukebox; spin_lock(&nn->client_lock); - conf = find_confirmed_client_by_name(&clname, nn); + /* find confirmed client by name */ + conf = find_clp_in_name_tree(&clname, &nn->conf_name_tree); + if (conf && conf->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) { + cclient = conf; + conf = NULL; + } + if (conf && client_has_state(conf)) { status = nfserr_clid_inuse; if (clp_used_exchangeid(conf)) @@ -4127,7 +4142,11 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, new = NULL; status = nfs_ok; out: + if (cclient) + unhash_client_locked(cclient); spin_unlock(&nn->client_lock); + if (cclient) + expire_client(cclient); if (new) free_client(new); if (unconf) { diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 8b81493ee48a..16167f223353 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -735,6 +735,7 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp); extern int nfsd4_client_record_check(struct nfs4_client *clp); extern void nfsd4_record_grace_done(struct nfsd_net *nn); +/* courteous server */ static inline bool nfsd4_expire_courtesy_clnt(struct nfs4_client *clp) { @@ -749,4 +750,31 @@ nfsd4_expire_courtesy_clnt(struct nfs4_client *clp) return rc; } +static inline bool +nfsd4_discard_reconnect_clnt(struct nfs4_client *clp) +{ + bool ret = false; + + spin_lock(&clp->cl_cs_lock); + if (clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) { + clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED; + ret = true; + } + spin_unlock(&clp->cl_cs_lock); + return ret; +} + +static inline bool +nfsd4_courtesy_clnt_expired(struct nfs4_client *clp) +{ + bool rc = false; + + spin_lock(&clp->cl_cs_lock); + if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED) + rc = true; + if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY) + clp->cl_cs_client_state = NFSD4_CLIENT_RECONNECTED; + spin_unlock(&clp->cl_cs_lock); + return rc; +} #endif /* NFSD4_STATE_H */ From patchwork Wed Apr 6 22:45:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804152 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 98152C433EF for ; Wed, 6 Apr 2022 22:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237191AbiDFWrr (ORCPT ); Wed, 6 Apr 2022 18:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237355AbiDFWro (ORCPT ); Wed, 6 Apr 2022 18:47:44 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F4881A1290 for ; Wed, 6 Apr 2022 15:45:45 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236LH0q6004957; Wed, 6 Apr 2022 22:45:44 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-2021-07-09; bh=dHYCaShwFxFLB8tjHr4vbO2Mv/vdoxUJRq05kqQGkm0=; b=SX78RZn0UOnK8QIcPQdgg3tHoo7oQDXEyQG5ogNEY72uTOo6qWmy0AMj4dcpgldBSVrl iRjoAbWBRFX+0cq67JnyNKmrUZk0u3Peg8Obk4XTcNtqRqfZ8kzibWlPtjw2YTL0Ux4C fJdm/D/yTbEVbCR+YMKgV/8tGvh/GMnhRio2mWueIdNRleB5KuR1wBwf/26BbJqwJhLV 1Rw3EE9GzPPwLW7Zd2Ki5Kg/vQNNKb3fGwZhNG/y9lLubuQR7QJN4GpReGoN171VWovg Xjf2ZtgJVAj/dsbGjwaM36oOZ8ClDaJaCz+HoZCUcAawGMRe0ZwGf5iieqWX/ybTFNC2 OQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6d932bq4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:44 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236Meb2E011769; Wed, 6 Apr 2022 22:45:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5pn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:43 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbi021908; Wed, 6 Apr 2022 22:45:43 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-7; Wed, 06 Apr 2022 22:45:43 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 06/10] NFSD: Update find_in_sessionid_hashtbl() to handle courtesy client Date: Wed, 6 Apr 2022 15:45:29 -0700 Message-Id: <1649285133-16765-7-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: CDVrZbvGyUJw-iivxIIqIFVXdAjenOec X-Proofpoint-GUID: CDVrZbvGyUJw-iivxIIqIFVXdAjenOec Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update find_in_sessionid_hashtbl to: . skip client with CLIENT_EXPIRED state; discarded courtesy client. . if courtesy client was found then set CLIENT_RECONNECTED so caller can take appropriate action. Update nfsd4_sequence and nfsd4_bind_conn_to_session to create client record for courtesy client with CLIENT_RECONNECTED state. Update nfsd4_destroy_session to discard courtesy client with CLIENT_RECONNECTED state. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index d14cea763511..0fd058826e85 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -701,6 +701,22 @@ __nfs4_file_get_access(struct nfs4_file *fp, u32 access) atomic_inc(&fp->fi_access[O_RDONLY]); } +static void +nfsd4_reactivate_courtesy_client(struct nfs4_client *clp, __be32 status) +{ + spin_lock(&clp->cl_cs_lock); + if (clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) { + if (status == nfs_ok) { + clp->cl_cs_client_state = NFSD4_CLIENT_ACTIVE; + spin_unlock(&clp->cl_cs_lock); + nfsd4_client_record_create(clp); + return; + } + clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED; + } + spin_unlock(&clp->cl_cs_lock); +} + /* * Check if courtesy clients have conflicting access and resolve it if possible * @@ -1994,13 +2010,21 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, { struct nfsd4_session *session; __be32 status = nfserr_badsession; + struct nfs4_client *clp; session = __find_in_sessionid_hashtbl(sessionid, net); if (!session) goto out; + clp = session->se_client; + if (nfsd4_courtesy_clnt_expired(clp)) { + session = NULL; + goto out; + } status = nfsd4_get_session_locked(session); - if (status) + if (status) { session = NULL; + nfsd4_discard_reconnect_clnt(clp); + } out: *ret = status; return session; @@ -3700,6 +3724,7 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp, struct nfsd4_session *session; struct net *net = SVC_NET(rqstp); struct nfsd_net *nn = net_generic(net, nfsd_net_id); + struct nfs4_client *clp; if (!nfsd4_last_compound_op(rqstp)) return nfserr_not_only_op; @@ -3732,6 +3757,8 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp, nfsd4_init_conn(rqstp, conn, session); status = nfs_ok; out: + clp = session->se_client; + nfsd4_reactivate_courtesy_client(clp, status); nfsd4_put_session(session); out_no_session: return status; @@ -3754,6 +3781,7 @@ nfsd4_destroy_session(struct svc_rqst *r, struct nfsd4_compound_state *cstate, int ref_held_by_me = 0; struct net *net = SVC_NET(r); struct nfsd_net *nn = net_generic(net, nfsd_net_id); + struct nfs4_client *clp; status = nfserr_not_only_op; if (nfsd4_compound_in_session(cstate, sessionid)) { @@ -3766,6 +3794,11 @@ nfsd4_destroy_session(struct svc_rqst *r, struct nfsd4_compound_state *cstate, ses = find_in_sessionid_hashtbl(sessionid, net, &status); if (!ses) goto out_client_lock; + clp = ses->se_client; + if (nfsd4_discard_reconnect_clnt(clp)) { + status = nfserr_badsession; + goto out_put_session; + } status = nfserr_wrong_cred; if (!nfsd4_mach_creds_match(ses->se_client, r)) goto out_put_session; @@ -3870,7 +3903,7 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_compoundres *resp = rqstp->rq_resp; struct xdr_stream *xdr = resp->xdr; struct nfsd4_session *session; - struct nfs4_client *clp; + struct nfs4_client *clp = NULL; struct nfsd4_slot *slot; struct nfsd4_conn *conn; __be32 status; @@ -3980,6 +4013,8 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, if (conn) free_conn(conn); spin_unlock(&nn->client_lock); + if (clp) + nfsd4_reactivate_courtesy_client(clp, status); return status; out_put_session: nfsd4_put_session_locked(session); From patchwork Wed Apr 6 22:45:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804158 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 24209C433F5 for ; Wed, 6 Apr 2022 22:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237226AbiDFWrv (ORCPT ); Wed, 6 Apr 2022 18:47:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237369AbiDFWro (ORCPT ); Wed, 6 Apr 2022 18:47:44 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1326442A3D for ; Wed, 6 Apr 2022 15:45:46 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236KGjw7012451; Wed, 6 Apr 2022 22:45:45 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-2021-07-09; bh=Ie641ePHUhK+My5tElENcwJXDoLk4zAMcalKxgc5z9w=; b=aP3HE1fvG+ZKEE9WKyEQHbpBP9QsG2pGrRF82pkbauamYjOVPZZpMP8sJdYWzebE1H2z IEXhRZoDlAqS9SR6TfJWJDgfA75gOMeCkZERT3m9lACAJhjqOaYuWXG7XALRt2v9FjiB 3qH+pPeWqtfxZy5EWw/HRaQhIRIXd+WYAgkw4Qx2q2itdVS7guzQ3WCd3z1296ekwpOs UWngvVtPac7NuYHBBB3qpiFVLklnkCDYrv/fayicp7u9DZsHrGKXcpOgVasiUucJf5/Q cFl5hzH6+Bpgq7MCTWPTv5hyRgD4sSBPZdjyGMu/fV8idt0fDMVqX+Nocty8FsuENiYB PQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6cwcj1k3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:45 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeYDH011627; Wed, 6 Apr 2022 22:45:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5q5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:44 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbk021908; Wed, 6 Apr 2022 22:45:44 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-8; Wed, 06 Apr 2022 22:45:44 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 07/10] NFSD: Update find_client_in_id_table() to handle courtesy client Date: Wed, 6 Apr 2022 15:45:30 -0700 Message-Id: <1649285133-16765-8-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: 8A5fGtM0NtgalLFU1Fm3_iitL9AXvErB X-Proofpoint-GUID: 8A5fGtM0NtgalLFU1Fm3_iitL9AXvErB Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update find_client_in_id_table to: . skip client with CLIENT_EXPIRED; discarded courtesy client . if courtesy client was found then set CLIENT_RECONNECTED state so caller can take appropriate action. Update find_confirmed_client to discard courtesy client. Update lookup_clientid to call find_client_in_id_table directly. Update set_client to create client record for courtesy client. Update find_cpntf_state to discard courtesy client. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 0fd058826e85..241d6a509994 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2967,6 +2967,8 @@ find_client_in_id_table(struct list_head *tbl, clientid_t *clid, bool sessions) if (same_clid(&clp->cl_clientid, clid)) { if ((bool)clp->cl_minorversion != sessions) return NULL; + if (nfsd4_courtesy_clnt_expired(clp)) + continue; renew_client_locked(clp); return clp; } @@ -2978,9 +2980,13 @@ static struct nfs4_client * find_confirmed_client(clientid_t *clid, bool sessions, struct nfsd_net *nn) { struct list_head *tbl = nn->conf_id_hashtbl; + struct nfs4_client *clp; lockdep_assert_held(&nn->client_lock); - return find_client_in_id_table(tbl, clid, sessions); + clp = find_client_in_id_table(tbl, clid, sessions); + if (clp && nfsd4_discard_reconnect_clnt(clp)) + clp = NULL; + return clp; } static struct nfs4_client * @@ -4884,9 +4890,10 @@ static struct nfs4_client *lookup_clientid(clientid_t *clid, bool sessions, struct nfsd_net *nn) { struct nfs4_client *found; + struct list_head *tbl = nn->conf_id_hashtbl; spin_lock(&nn->client_lock); - found = find_confirmed_client(clid, sessions, nn); + found = find_client_in_id_table(tbl, clid, sessions); if (found) atomic_inc(&found->cl_rpc_users); spin_unlock(&nn->client_lock); @@ -4911,6 +4918,7 @@ static __be32 set_client(clientid_t *clid, cstate->clp = lookup_clientid(clid, false, nn); if (!cstate->clp) return nfserr_expired; + nfsd4_reactivate_courtesy_client(cstate->clp, nfs_ok); return nfs_ok; } @@ -6147,7 +6155,12 @@ static __be32 find_cpntf_state(struct nfsd_net *nn, stateid_t *st, found = lookup_clientid(&cps->cp_p_clid, true, nn); if (!found) goto out; - + if (nfsd4_discard_reconnect_clnt(found)) { + if (atomic_dec_and_lock(&found->cl_rpc_users, + &nn->client_lock)) + spin_unlock(&nn->client_lock); + goto out; + } *stid = find_stateid_by_type(found, &cps->cp_p_stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID); if (*stid) From patchwork Wed Apr 6 22:45:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804159 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 7FAF8C433FE for ; Wed, 6 Apr 2022 22:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237234AbiDFWrw (ORCPT ); Wed, 6 Apr 2022 18:47:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237371AbiDFWrp (ORCPT ); Wed, 6 Apr 2022 18:47:45 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262EF22BDD for ; Wed, 6 Apr 2022 15:45:48 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236JcKTZ014702; Wed, 6 Apr 2022 22:45:47 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-2021-07-09; bh=HofPZyCFo+qPkdAczK9qbnAgpGLeIysK1cm+H9cmhx4=; b=yimjvfm2fet4dO1z+zETasrClzy9BsfE9LuXncchYV+BAmrHL/KCQSwV4HmDnb2uTs9W upMwoRQzbVp+7HYE38ayjUqcuMcBQVKshrNIkQbfh0fSm/IOtU72kyUwLXvP5UxKHX7P XymVa44Shj0aPmhZfj6t6+ve+DTrIfl72ATpAKSv7YywdaZ3JOxSXKSrjlGDGPLAw9LS iTSPMXMD2YKVtg3rbJ+2jnLWUVlJmtRf7KFPO9UbLFZpnxncW7DLBMzsQ9+rxQ7s/JfK 5/RAJlcJjOzImUwucR5xLjfn5giuNyIa69DUJx1MDYo6bYbU94Cz3/EHZE84Ek+ORAEb jQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6ec9t3rp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:46 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeZHf011681; Wed, 6 Apr 2022 22:45:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5qj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:45 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbm021908; Wed, 6 Apr 2022 22:45:45 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-9; Wed, 06 Apr 2022 22:45:44 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 08/10] NFSD: Refactor nfsd4_laundromat() Date: Wed, 6 Apr 2022 15:45:31 -0700 Message-Id: <1649285133-16765-9-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: D8_RDIOW5QQSykP68jAbZxuWorry-eLp X-Proofpoint-ORIG-GUID: D8_RDIOW5QQSykP68jAbZxuWorry-eLp Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Extract a bit of logic that is about to be expanded to handle courtesy clients. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 241d6a509994..4278b2078606 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5731,6 +5731,26 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn) } #endif +static void +nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist, + struct laundry_time *lt) +{ + struct list_head *pos, *next; + struct nfs4_client *clp; + + INIT_LIST_HEAD(reaplist); + spin_lock(&nn->client_lock); + list_for_each_safe(pos, next, &nn->client_lru) { + clp = list_entry(pos, struct nfs4_client, cl_lru); + if (!state_expired(lt, clp->cl_time)) + break; + if (mark_client_expired_locked(clp)) + continue; + list_add(&clp->cl_lru, reaplist); + } + spin_unlock(&nn->client_lock); +} + static time64_t nfs4_laundromat(struct nfsd_net *nn) { @@ -5753,7 +5773,6 @@ nfs4_laundromat(struct nfsd_net *nn) goto out; } nfsd4_end_grace(nn); - INIT_LIST_HEAD(&reaplist); spin_lock(&nn->s2s_cp_lock); idr_for_each_entry(&nn->s2s_cp_stateids, cps_t, i) { @@ -5763,17 +5782,7 @@ nfs4_laundromat(struct nfsd_net *nn) _free_cpntf_state_locked(nn, cps); } spin_unlock(&nn->s2s_cp_lock); - - spin_lock(&nn->client_lock); - list_for_each_safe(pos, next, &nn->client_lru) { - clp = list_entry(pos, struct nfs4_client, cl_lru); - if (!state_expired(<, clp->cl_time)) - break; - if (mark_client_expired_locked(clp)) - continue; - list_add(&clp->cl_lru, &reaplist); - } - spin_unlock(&nn->client_lock); + nfs4_get_client_reaplist(nn, &reaplist, <); list_for_each_safe(pos, next, &reaplist) { clp = list_entry(pos, struct nfs4_client, cl_lru); trace_nfsd_clid_purged(&clp->cl_clientid); From patchwork Wed Apr 6 22:45:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804161 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 619B1C4332F for ; Wed, 6 Apr 2022 22:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236465AbiDFWrx (ORCPT ); Wed, 6 Apr 2022 18:47:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237206AbiDFWrr (ORCPT ); Wed, 6 Apr 2022 18:47:47 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBAA812ABE for ; Wed, 6 Apr 2022 15:45:48 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236JwObV024505; Wed, 6 Apr 2022 22:45:47 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-2021-07-09; bh=nDwDIgrcv/dHvjE7U2Ea2NjjkDKZGVKNiRDXBWHixxI=; b=eb7S1bJp+Qjr9klSdtm8cdN9k5uZRQHDhm9wy0ToKxXxicp0EDF6Hh8fAezxPY41t9vb BJd3lpg3nAXvKMoxXLDRDt+oynSDsWrHk9vZlmzyT4T6TkI85Dx4Bp/27NZLh8YLxcxX DXTzPQt4jfR1WlthhinONwvAkv1FOtLG6t8yvraLqSzJThecJ88WeVHOgHvh3gcM/4zr f2VcxWqi9Yw5cRtMkT1ksyKIo0b+Q7wOKu1EP/3cUcx/xS9dzZSpQ1I1HbjxYZG6Wetv HSBN42C0zyrTvzIP6Q0cQdLfC/3dls+KkbkBI+cv4o2TZAbIaNR7HdHSAZswL/RctxMP ww== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6f1taf9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:47 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeYQP011633; Wed, 6 Apr 2022 22:45:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5qy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:46 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbo021908; Wed, 6 Apr 2022 22:45:45 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-10; Wed, 06 Apr 2022 22:45:45 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 09/10] NFSD: Update laundromat to handle courtesy client Date: Wed, 6 Apr 2022 15:45:32 -0700 Message-Id: <1649285133-16765-10-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: xTXph2JlNo4Z_sJ6CArjOd2lP13Q3tl3 X-Proofpoint-GUID: xTXph2JlNo4Z_sJ6CArjOd2lP13Q3tl3 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add nfs4_anylock_blocker and nfs4_lockowner_has_blockers to check if an expired client has any lock blockers Update nfs4_get_client_reaplist to: . add courtesy client in CLIENT_EXPIRED state to reaplist. . detect if expired client still has state and no blockers then transit it to courtesy client by setting CLIENT_COURTESY state and removing the client record. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 4278b2078606..edd50a4485aa 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5731,24 +5731,106 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn) } #endif +/* Check if any lock belonging to this lockowner has any blockers */ +static bool +nfs4_lockowner_has_blockers(struct nfs4_lockowner *lo) +{ + struct file_lock_context *ctx; + struct nfs4_ol_stateid *stp; + struct nfs4_file *nf; + + list_for_each_entry(stp, &lo->lo_owner.so_stateids, st_perstateowner) { + nf = stp->st_stid.sc_file; + ctx = nf->fi_inode->i_flctx; + if (!ctx) + continue; + if (locks_owner_has_blockers(ctx, lo)) + return true; + } + return false; +} + +static bool +nfs4_anylock_blockers(struct nfs4_client *clp) +{ + int i; + struct nfs4_stateowner *so; + struct nfs4_lockowner *lo; + + spin_lock(&clp->cl_lock); + for (i = 0; i < OWNER_HASH_SIZE; i++) { + list_for_each_entry(so, &clp->cl_ownerstr_hashtbl[i], + so_strhash) { + if (so->so_is_open_owner) + continue; + lo = lockowner(so); + if (nfs4_lockowner_has_blockers(lo)) { + spin_unlock(&clp->cl_lock); + return true; + } + } + } + spin_unlock(&clp->cl_lock); + return false; +} + static void nfs4_get_client_reaplist(struct nfsd_net *nn, struct list_head *reaplist, struct laundry_time *lt) { struct list_head *pos, *next; struct nfs4_client *clp; + bool cour; + struct list_head cslist; INIT_LIST_HEAD(reaplist); + INIT_LIST_HEAD(&cslist); spin_lock(&nn->client_lock); list_for_each_safe(pos, next, &nn->client_lru) { clp = list_entry(pos, struct nfs4_client, cl_lru); if (!state_expired(lt, clp->cl_time)) break; - if (mark_client_expired_locked(clp)) + + if (!client_has_state(clp)) + goto exp_client; + + if (clp->cl_cs_client_state == NFSD4_CLIENT_EXPIRED) + goto exp_client; + cour = (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY); + if (cour && ktime_get_boottime_seconds() >= + (clp->cl_time + NFSD_COURTESY_CLIENT_TIMEOUT)) + goto exp_client; + if (nfs4_anylock_blockers(clp)) { +exp_client: + if (mark_client_expired_locked(clp)) + continue; + list_add(&clp->cl_lru, reaplist); continue; - list_add(&clp->cl_lru, reaplist); + } + if (!cour) { + spin_lock(&clp->cl_cs_lock); + clp->cl_cs_client_state = NFSD4_CLIENT_COURTESY; + spin_unlock(&clp->cl_cs_lock); + list_add(&clp->cl_cs_list, &cslist); + } } spin_unlock(&nn->client_lock); + + while (!list_empty(&cslist)) { + clp = list_first_entry(&cslist, struct nfs4_client, cl_cs_list); + list_del_init(&clp->cl_cs_list); + spin_lock(&clp->cl_cs_lock); + /* + * Client might have re-connected. Make sure it's + * still in courtesy state before removing its record. + */ + if (clp->cl_cs_client_state != NFSD4_CLIENT_COURTESY) { + spin_unlock(&clp->cl_cs_lock); + continue; + } + spin_unlock(&clp->cl_cs_lock); + nfsd4_client_record_remove(clp); + } } static time64_t @@ -5794,6 +5876,13 @@ nfs4_laundromat(struct nfsd_net *nn) dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); if (!state_expired(<, dp->dl_time)) break; + spin_lock(&clp->cl_cs_lock); + if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY) { + clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED; + spin_unlock(&clp->cl_cs_lock); + continue; + } + spin_unlock(&clp->cl_cs_lock); WARN_ON(!unhash_delegation_locked(dp)); list_add(&dp->dl_recall_lru, &reaplist); } From patchwork Wed Apr 6 22:45:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12804160 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 B837BC433EF for ; Wed, 6 Apr 2022 22:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237235AbiDFWrx (ORCPT ); Wed, 6 Apr 2022 18:47:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236465AbiDFWrr (ORCPT ); Wed, 6 Apr 2022 18:47:47 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD920E084 for ; Wed, 6 Apr 2022 15:45:48 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 236MCZBQ001019; Wed, 6 Apr 2022 22:45:47 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-2021-07-09; bh=QXVWANou7ZWiutZXPYyIgl8RMRoo/YWrGB5TlqDUWLI=; b=nLhGpZyQmFzffn8o54icy2Qzu4wieKfAzNVckfR6BXeCGWc/Ugh0FC5cpheWTy7jSsnU Y13GxWCjlyNF1oV8STTiD63XCLyzt2/VVz4Wc4tPiFL62YlrkXuLABjw6j5pGMkr7Tm9 Mdhx4uUKh+tXL6ZflUUABeJDlsFtnp9WbrKIgLe/2B+fszGowfrtKmue3q4JlMdEC1wM 7I2mfWP9FUi59ZJzgLO2DLsGbwR/FVU4Lb1D2LoMo3pBRvwXcBdwR8Dcp4q9AAUbljfB RXvPPPd+AWEQxd0kXG0+sebCQDrlom15b5uaGSikuNqppdGYzpbRU9MvfeQkGctf+GjP Yg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f6e3st98c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:47 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 236MeZKF011650; Wed, 6 Apr 2022 22:45:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5ra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Apr 2022 22:45:47 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 236Mjcbq021908; Wed, 6 Apr 2022 22:45:46 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f9803d5mk-11; Wed, 06 Apr 2022 22:45:46 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v20 10/10] NFSD: Show state of courtesy client in client info Date: Wed, 6 Apr 2022 15:45:33 -0700 Message-Id: <1649285133-16765-11-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> References: <1649285133-16765-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: UuJFbQ4jVZTLOuVWLmJjvMzNElTzJUd_ X-Proofpoint-GUID: UuJFbQ4jVZTLOuVWLmJjvMzNElTzJUd_ Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update client_info_show to show state of courtesy client and time since last renew. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index edd50a4485aa..98557031c1ed 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2485,7 +2485,8 @@ static int client_info_show(struct seq_file *m, void *v) { struct inode *inode = m->private; struct nfs4_client *clp; - u64 clid; + u64 clid, hrs; + u32 mins, secs; clp = get_nfsdfs_clp(inode); if (!clp) @@ -2493,10 +2494,17 @@ static int client_info_show(struct seq_file *m, void *v) memcpy(&clid, &clp->cl_clientid, sizeof(clid)); seq_printf(m, "clientid: 0x%llx\n", clid); seq_printf(m, "address: \"%pISpc\"\n", (struct sockaddr *)&clp->cl_addr); - if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) + + if (clp->cl_cs_client_state == NFSD4_CLIENT_COURTESY) + seq_puts(m, "status: courtesy\n"); + else if (clp->cl_cs_client_state == NFSD4_CLIENT_CONFIRMED) seq_puts(m, "status: confirmed\n"); else seq_puts(m, "status: unconfirmed\n"); + hrs = div_u64_rem(ktime_get_boottime_seconds() - clp->cl_time, + 3600, &secs); + mins = div_u64_rem((u64)secs, 60, &secs); + seq_printf(m, "time since last renew: %llu:%02u:%02u\n", hrs, mins, secs); seq_printf(m, "name: "); seq_quote_mem(m, clp->cl_name.data, clp->cl_name.len); seq_printf(m, "\nminor version: %d\n", clp->cl_minorversion);