From patchwork Sat Mar 12 02:13: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: 12778694 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 B9BD2C433FE for ; Sat, 12 Mar 2022 02:13:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229477AbiCLCOw (ORCPT ); Fri, 11 Mar 2022 21:14:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230028AbiCLCOv (ORCPT ); Fri, 11 Mar 2022 21:14:51 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B6E51945ED; Fri, 11 Mar 2022 18:13:47 -0800 (PST) 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 22BN1vxI011895; Sat, 12 Mar 2022 02:13: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=AwpXRCZkY8QYpJhUegFeWznbe39s+u1FE01qP8lP6jA=; b=cs3aj2jeiTlYCpnGqo46tCGdz/kCOWx1wuK+wA1S3M6U2CQgjux/Jur3B6QqdGmXUC1P tmA4Hi13gJMf8kjH2sLOydfG7KWR3eWHikvGyqfWmyv/DhgOW3/f5lM1GUiEtVztQipR zL8wkey1ENTFw9SlUdnIHovKvDkHMPFYPJ6rpNVpFmnU3z1saAlm47trzg1t+so0IWQz flen0jgq8ztza8dgfeBfRb4lFZyqwmmJleYMr/NXEiIfkTXq3d1Uir01eyyv7lngxvcT AtpQmA3Uig/liKu2F7OX5uLCo9lXR48DsRIr7UOc9xAYOF3/IwqcRbXd58kE5kCOtrj6 8A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyfstka5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:44 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2C4C0084308; Sat, 12 Mar 2022 02:13:43 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qfj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:43 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMR086332; Sat, 12 Mar 2022 02:13:43 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-2; Sat, 12 Mar 2022 02:13:43 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 01/11] fs/lock: add helper locks_owner_has_blockers to check for blockers Date: Fri, 11 Mar 2022 18:13:25 -0800 Message-Id: <1647051215-2873-2-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: ziE3Pj06inWOKfnXXBPJAPd4JKLCN-BN X-Proofpoint-ORIG-GUID: ziE3Pj06inWOKfnXXBPJAPd4JKLCN-BN Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add helper locks_owner_has_blockers to check if there is any blockers for a given lockowner. Signed-off-by: Dai Ngo --- fs/locks.c | 28 ++++++++++++++++++++++++++++ include/linux/fs.h | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index 050acf8b5110..53864eb99dc5 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -300,6 +300,34 @@ void locks_release_private(struct file_lock *fl) } EXPORT_SYMBOL_GPL(locks_release_private); +/** + * locks_owner_has_blockers - Check for blocking lock requests + * @flctx: file lock context + * @owner: lock owner + * + * Return values: + * %true: @owner has at least one blocker + * %false: @owner has no blockers + */ +bool locks_owner_has_blockers(struct file_lock_context *flctx, + fl_owner_t owner) +{ + struct file_lock *fl; + + spin_lock(&flctx->flc_lock); + list_for_each_entry(fl, &flctx->flc_posix, fl_list) { + if (fl->fl_owner != owner) + continue; + if (!list_empty(&fl->fl_blocked_requests)) { + spin_unlock(&flctx->flc_lock); + return true; + } + } + spin_unlock(&flctx->flc_lock); + return false; +} +EXPORT_SYMBOL_GPL(locks_owner_has_blockers); + /* Free a lock which is not in use. */ void locks_free_lock(struct file_lock *fl) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 831b20430d6e..da8ae38f471c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1200,6 +1200,8 @@ extern void lease_unregister_notifier(struct notifier_block *); struct files_struct; extern void show_fd_locks(struct seq_file *f, struct file *filp, struct files_struct *files); +extern bool locks_owner_has_blockers(struct file_lock_context *flctx, + fl_owner_t owner); #else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk(struct file *file, unsigned int cmd, struct flock __user *user) @@ -1335,6 +1337,11 @@ static inline int lease_modify(struct file_lock *fl, int arg, struct files_struct; static inline void show_fd_locks(struct seq_file *f, struct file *filp, struct files_struct *files) {} +extern bool locks_owner_has_blockers(struct file_lock_context *flctx, + fl_owner_t owner) +{ + return false; +} #endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode(const struct file *f) From patchwork Sat Mar 12 02:13: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: 12778697 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 E7145C433FE for ; Sat, 12 Mar 2022 02:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbiCLCPE (ORCPT ); Fri, 11 Mar 2022 21:15:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbiCLCOy (ORCPT ); Fri, 11 Mar 2022 21:14:54 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58C911A39D5; Fri, 11 Mar 2022 18:13:48 -0800 (PST) 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 22BNDNJM026238; Sat, 12 Mar 2022 02:13: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=Ihk0tYTdTEWYxhZWaIlpMX9jo6hpzAbF6yZWs0jNw74=; b=YRoCY12ouMDT0d+Ubc7or1URsZqaaP/TAPCXF1cwrCdGji+6aEVV6GBVb5JkmSP95hs5 TYpkzGaM2q06/ko/Vmk2XH3almFkHoVpWjFx3m4NIlMIHuFjHTlGv8idbHLPFOlnSw2J g1syXoaM2UmlChEKzNOnDKAiEVvaJZVBXBqH8a6NzSKAvaBF3wk/QGsRZT4kittsyeyY DxbRpz6RfHMipgiJTkAdm302F1BFU7TYN7JRqC0VTKJ+eS4kZ83AvLWHJU1MQg1N1Ofl 6NmXFaPcDqHFD6Qcz+n/Z8Jq/OyhAMPfrDQ0Tp0f3ktkmGsi/D45GB4yORM+tgz/cLyC iA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyrb1f7g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:45 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2C0Xf084288; Sat, 12 Mar 2022 02:13:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qfn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:44 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMT086332; Sat, 12 Mar 2022 02:13:43 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-3; Sat, 12 Mar 2022 02:13:43 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 02/11] NFSD: Add client flags, macro and spinlock to support courteous server Date: Fri, 11 Mar 2022 18:13:26 -0800 Message-Id: <1647051215-2873-3-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: 1vTQ1X5TiLprCC-2wsfOhnifB7bSZoZC X-Proofpoint-ORIG-GUID: 1vTQ1X5TiLprCC-2wsfOhnifB7bSZoZC Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add flags to track a client's lease state after the client fails to renew its lease. Add macro for courtesy client expire time. Add spinlock to synchronize access to these flags. 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 | 6 ++++++ 3 files changed, 9 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..8cbd3b69a584 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -343,6 +343,9 @@ struct nfs4_client { #define NFSD4_CLIENT_RECLAIM_COMPLETE (3) /* reclaim_complete done */ #define NFSD4_CLIENT_CONFIRMED (4) /* client is confirmed */ #define NFSD4_CLIENT_UPCALL_LOCK (5) /* upcall serialization */ +#define NFSD4_CLIENT_COURTESY (6) +#define NFSD4_CLIENT_EXPIRED (7) +#define NFSD4_CLIENT_RECONNECTED (8) #define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \ 1 << NFSD4_CLIENT_CB_KILL) unsigned long cl_flags; @@ -385,6 +388,9 @@ 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 */ + + spinlock_t cl_cs_lock; + struct list_head cl_cs_list; }; /* struct nfs4_client_reset From patchwork Sat Mar 12 02:13: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: 12778695 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 E89ADC43217 for ; Sat, 12 Mar 2022 02:13:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbiCLCOx (ORCPT ); Fri, 11 Mar 2022 21:14:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbiCLCOv (ORCPT ); Fri, 11 Mar 2022 21:14:51 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4AB01A2708; Fri, 11 Mar 2022 18:13:47 -0800 (PST) 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 22C1Vdws023826; Sat, 12 Mar 2022 02:13: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=zr2GuroqkQCEJUAkHaSF7PaiddkbHo5TKIjBVWhg/24=; b=hlaDWH7y5bnAB6PPjxcAIc032U8tWoHGP+66NO15ZoU8+Mvzj1gTOkT1IjSqj62ossv/ /8YvQCSYyH7W0c17C9hO89MPJtZ6oM6E4/HhdWAYaHBrDZ0axYqjhaUM1kKMOIkbbYY4 YRl0GUDSNOJjn1ZngR7MKcIWa0wvh+goGqLjVhQNk+Ipx/JVZyFq0Na6WjL+DihfQaNW 16FBeaGZXmG69ftjrcQEAwsRJvkisq3cnFRSKi8w/UXLwtLxJeF5kZqJL8fFoNmUfwO5 KobzxJxePIf4n6aKGQ7aV9Ng/LoAKeqldSFp3ROj1jjPjlc3py3QcTs7c0xiEf5XCsOC +w== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3erhxcg0v9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:45 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2CA0U084327; Sat, 12 Mar 2022 02:13:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qfr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:44 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMV086332; Sat, 12 Mar 2022 02:13:44 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-4; Sat, 12 Mar 2022 02:13:44 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 03/11] NFSD: Add lm_lock_expired call out Date: Fri, 11 Mar 2022 18:13:27 -0800 Message-Id: <1647051215-2873-4-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: da4MgeTcuShorU52jRrTTB57iloxtXGL X-Proofpoint-ORIG-GUID: da4MgeTcuShorU52jRrTTB57iloxtXGL 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 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index a65d59510681..583ac807e98d 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6578,10 +6578,47 @@ 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; + struct nfs4_client *clp; + bool rc = false; + + if (!fl) + return false; + lo = (struct nfs4_lockowner *)fl->fl_owner; + clp = lo->lo_owner.so_client; + + /* need to sync with courtesy client trying to reconnect */ + spin_lock(&clp->cl_cs_lock); + if (test_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags)) + rc = true; + else { + if (test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)) { + set_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags); + rc = true; + } + } + spin_unlock(&clp->cl_cs_lock); + return rc; +} + 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 From patchwork Sat Mar 12 02:13: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: 12778700 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 28645C4167D for ; Sat, 12 Mar 2022 02:14:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbiCLCPF (ORCPT ); Fri, 11 Mar 2022 21:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbiCLCPC (ORCPT ); Fri, 11 Mar 2022 21:15:02 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25F61ACA2B; Fri, 11 Mar 2022 18:13:52 -0800 (PST) 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 22C1uV1q026138; Sat, 12 Mar 2022 02:13:50 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=tyRLBCh3NbKIArnmzfrYITUVnwOeaTnA8mjbcXadmmM=; b=J8QT4vUSrDZDBxTvKBeBGl3bgXOjMaGVLBiklpAcozVWZPYJQGE1hEdG6fbWDyOkrRz/ k+SiAH2+4RnIA5a4fsSCnQcgGP7K4ROY4kJiNTcBC8gtzwmNO0RiwK3f/yh4XWoqH1Nw +MDgZ6vjWnmbG4RSJDuAfjRgGkSc5tQ1ntEzJBkP0XMGA80rUSu6TLcs1GkFR9zffXxJ Eq+3pszhZVXPTshB/GPHPOM9jIIF1iEnGcBAd9ijnPMOx6Enmi8BYUYWxdYlXwIqGBsn uS89/LejBVk4cYdr+9soAIfflzXvZ/rKGI39t89fu1nh5+NafnBWC1PeENzkwyZwh9PA qw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3erja280c3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:50 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2C0wo084285; Sat, 12 Mar 2022 02:13:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qfw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:45 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMX086332; Sat, 12 Mar 2022 02:13:45 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-5; Sat, 12 Mar 2022 02:13:45 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 04/11] NFSD: Update nfsd_breaker_owns_lease() to handle courtesy clients Date: Fri, 11 Mar 2022 18:13:28 -0800 Message-Id: <1647051215-2873-5-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: A0hD2s2qHgBXIMEeLuHSu7nOg3b0pRWu X-Proofpoint-GUID: A0hD2s2qHgBXIMEeLuHSu7nOg3b0pRWu Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update nfsd_breaker_owns_lease() to handle delegation conflict with courtesy clients. If conflict was caused by courtesy client then discard the courtesy client by setting CLIENT_EXPIRED and return conflict resolved. Client with CLIENT_EXPIRED is expired by the laundromat. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 583ac807e98d..2beb0972de88 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4713,6 +4713,28 @@ nfsd_break_deleg_cb(struct file_lock *fl) return ret; } +static bool +nfs4_check_and_expire_courtesy_client(struct nfs4_client *clp) +{ + /* + * need to sync with courtesy client trying to reconnect using + * the cl_cs_lock, nn->client_lock can not be used since this + * function is called with the fl_lck held. + */ + spin_lock(&clp->cl_cs_lock); + if (test_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags)) { + spin_unlock(&clp->cl_cs_lock); + return true; + } + if (test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)) { + set_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags); + spin_unlock(&clp->cl_cs_lock); + return true; + } + spin_unlock(&clp->cl_cs_lock); + return false; +} + /** * nfsd_breaker_owns_lease - Check if lease conflict was resolved * @fl: Lock state to check @@ -4727,6 +4749,10 @@ static bool nfsd_breaker_owns_lease(struct file_lock *fl) struct svc_rqst *rqst; struct nfs4_client *clp; + clp = dl->dl_stid.sc_client; + if (nfs4_check_and_expire_courtesy_client(clp)) + return true; + if (!i_am_nfsd()) return false; rqst = kthread_data(current); From patchwork Sat Mar 12 02:13: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: 12778699 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 71A21C4321E for ; Sat, 12 Mar 2022 02:14:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbiCLCPF (ORCPT ); Fri, 11 Mar 2022 21:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbiCLCOy (ORCPT ); Fri, 11 Mar 2022 21:14:54 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99AF419FF54; Fri, 11 Mar 2022 18:13:49 -0800 (PST) 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 22C1VWmF023622; Sat, 12 Mar 2022 02:13: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=H7hELKcCgA7YUBq9nu2bzUP3npH3mbMXpiNcdztksmg=; b=Mh/VmwcrcGxf9S8A/dLFXPHgJmWociX6GYFUElY+ICfjAlwwL4w7vNtcBLyEvUFTHfwp L4+tdXIXO6k8AOVVVws03DjNaI1naaIqb2oWzB3mSj8QlIElghrdfsU6H/fyN5qJLPam A9o/5ZApqqaXBzHneQEvmXiZYY1qsDCkGLB5TT5PxzweAhjGn+kC3zGquUkCHbqyEkpP 5bCJLZaGFJe9+Q0y1jNc03pb1rruUu+7t/AeDUGkqfbmPFWE5aOAFakxocB5dRUaYjoc 4wQ1eFpR+GOQcz4gQ+3V620teR6REdDaSMPQxtXOBOlsN/Ga8ogJhmjKAZMnLztIU4BB XQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3erhxcg0va-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:47 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2Cbwg085387; Sat, 12 Mar 2022 02:13:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:46 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMZ086332; Sat, 12 Mar 2022 02:13:45 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-6; Sat, 12 Mar 2022 02:13:45 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 05/11] NFSD: Update nfs4_get_vfs_file() to handle courtesy clients Date: Fri, 11 Mar 2022 18:13:29 -0800 Message-Id: <1647051215-2873-6-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: Q_lupJJliMeOJ6y7C3yzXVWdAQAyBtYc X-Proofpoint-ORIG-GUID: Q_lupJJliMeOJ6y7C3yzXVWdAQAyBtYc 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. If share/access check fails with share denied then check if the the conflict was caused by courtesy clients. If that's the case then set CLIENT_EXPIRED flag to expire the courtesy clients and allow nfs4_get_vfs_file to continue. Client with CLIENT_EXPIRED is expired by the laundromat. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 2beb0972de88..b16f689f34c3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4973,9 +4973,75 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh, return nfsd_setattr(rqstp, fh, &iattr, 0, (time64_t)0); } +static bool +nfs4_check_access_deny_bmap(struct nfs4_ol_stateid *stp, u32 access, + bool share_access) +{ + if (share_access) { + if (!stp->st_deny_bmap) + return false; + + if ((stp->st_deny_bmap & (1 << NFS4_SHARE_DENY_BOTH)) || + (access & NFS4_SHARE_ACCESS_READ && + stp->st_deny_bmap & (1 << NFS4_SHARE_DENY_READ)) || + (access & NFS4_SHARE_ACCESS_WRITE && + stp->st_deny_bmap & (1 << NFS4_SHARE_DENY_WRITE))) { + return true; + } + return false; + } + if ((access & NFS4_SHARE_DENY_BOTH) || + (access & NFS4_SHARE_DENY_READ && + stp->st_access_bmap & (1 << NFS4_SHARE_ACCESS_READ)) || + (access & NFS4_SHARE_DENY_WRITE && + stp->st_access_bmap & (1 << NFS4_SHARE_ACCESS_WRITE))) { + return true; + } + return false; +} + +/* + * Check whether courtesy clients have conflicting access + * + * 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: + * true - access/deny mode conflict with normal client. + * false - 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 = false; + + lockdep_assert_held(&fp->fi_lock); + list_for_each_entry(st, &fp->fi_stateids, st_perfile) { + if (st->st_openstp || (st == stp && new_stp) || + (!nfs4_check_access_deny_bmap(st, + access, share_access))) + continue; + clp = st->st_stid.sc_client; + if (nfs4_check_and_expire_courtesy_client(clp)) + continue; + conflict = true; + break; + } + return conflict; +} + 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; @@ -4991,15 +5057,29 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp, */ status = nfs4_file_check_deny(fp, open->op_share_deny); if (status != nfs_ok) { - spin_unlock(&fp->fi_lock); - goto out; + if (status != nfserr_share_denied) { + spin_unlock(&fp->fi_lock); + goto out; + } + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp, + stp, open->op_share_deny, false)) { + spin_unlock(&fp->fi_lock); + goto out; + } } /* set access to the file */ status = nfs4_file_get_access(fp, open->op_share_access); if (status != nfs_ok) { - spin_unlock(&fp->fi_lock); - goto out; + if (status != nfserr_share_denied) { + spin_unlock(&fp->fi_lock); + goto out; + } + if (nfs4_resolve_deny_conflicts_locked(fp, new_stp, + stp, open->op_share_access, true)) { + spin_unlock(&fp->fi_lock); + goto out; + } } /* Set access bits in stateid */ @@ -5050,7 +5130,7 @@ 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); @@ -5059,7 +5139,10 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c set_deny(open->op_share_deny, stp); fp->fi_share_deny |= (open->op_share_deny & NFS4_SHARE_DENY_BOTH); - } + } else if (status == nfserr_share_denied && + !nfs4_resolve_deny_conflicts_locked(fp, false, stp, + open->op_share_deny, false)) + status = nfs_ok; spin_unlock(&fp->fi_lock); if (status != nfs_ok) @@ -5399,7 +5482,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 Sat Mar 12 02:13: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: 12778698 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 C82BEC43217 for ; Sat, 12 Mar 2022 02:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbiCLCPD (ORCPT ); Fri, 11 Mar 2022 21:15:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbiCLCOy (ORCPT ); Fri, 11 Mar 2022 21:14:54 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44F451AA048; Fri, 11 Mar 2022 18:13:50 -0800 (PST) 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 22C1hxI0013559; Sat, 12 Mar 2022 02:13: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=XHhtyopXZzpFEOphEdO15NR9aYcZXYqcEdZ8ZRWkJMc=; b=d3OpftaPLYdDsg1HJFxCZVU5oV7KcsAzoVxR9tsS2AWrSgtXOKURPNm8l13nbdremvSq nWcehMgjU6lw0fg8vb3KwUr9DaEDZJmGjElSPsuaIPuVQ064Phd8B3ddrR5jRouo+YQS ETEswsm5D5Z03fP4gnIzzfECa84JMdE2L/Dl0df1XpezBS7qW9UfLhUZ8RVPnoTYp4+m g4jyk2Vh6URlqkEsgk9Zps2WTV54aVnn5a62wq0r8y16S0uEgCStrJaph2P6b4nGSgzc Oi8EPEohlhPdEmISnA0VOULqbiZEHStLTAP6f4CFGHHgSQJ49OG4aLmFr7k3sg8yy8/s DA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3erj4200j1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:47 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2BvaA084272; Sat, 12 Mar 2022 02:13:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qg1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:46 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMb086332; Sat, 12 Mar 2022 02:13:46 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-7; Sat, 12 Mar 2022 02:13:46 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 06/11] NFSD: Update find_clp_in_name_tree() to handle courtesy clients Date: Fri, 11 Mar 2022 18:13:30 -0800 Message-Id: <1647051215-2873-7-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: d7uYHyo1LHvv08sOuGPKCAt2rUCFTEWT X-Proofpoint-ORIG-GUID: d7uYHyo1LHvv08sOuGPKCAt2rUCFTEWT Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update find_clp_in_name_tree: . skip client with CLIENT_EXPIRED flag; discarded courtesy client. . if courtesy client was found then clear CLIENT_COURTESY and set CLIENT_RECONNECTED so callers can take appropriate action. Update find_confirmed_client_by_name to discard the courtesy client; set CLIENT_EXPIRED. Update nfsd4_setclientid to expire the confirmed courtesy client to prevent multiple confirmed clients with the same name on the the conf_id_hashtbl list. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index b16f689f34c3..2f19aaaf6a66 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1929,6 +1929,33 @@ __find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net) return NULL; } +static void +nfsd4_discard_courtesy_clnt(struct nfs4_client *clp) +{ + spin_lock(&clp->cl_cs_lock); + set_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags); + spin_unlock(&clp->cl_cs_lock); +} + +static bool +nfs4_is_courtesy_client_expired(struct nfs4_client *clp) +{ + spin_lock(&clp->cl_cs_lock); + clear_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags); + if (test_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags)) { + spin_unlock(&clp->cl_cs_lock); + return true; + } + /* + * clear CLIENT_COURTESY flag to prevent it from being + * destroyed by thread trying to resolve conflicts. + */ + if (test_and_clear_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)) + set_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags); + spin_unlock(&clp->cl_cs_lock); + return false; +} + static struct nfsd4_session * find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net, __be32 *ret) @@ -2834,8 +2861,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 (nfs4_is_courtesy_client_expired(clp)) + return NULL; return clp; + } } return NULL; } @@ -2914,8 +2944,15 @@ 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 && test_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags)) { + nfsd4_discard_courtesy_clnt(clp); + clp = NULL; + } + return clp; } static struct nfs4_client * @@ -4032,12 +4069,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 && test_bit(NFSD4_CLIENT_RECONNECTED, &conf->cl_flags)) { + cclient = conf; + conf = NULL; + } + if (conf && client_has_state(conf)) { status = nfserr_clid_inuse; if (clp_used_exchangeid(conf)) @@ -4068,7 +4112,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) { From patchwork Sat Mar 12 02:13: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: 12778702 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 1F239C4332F for ; Sat, 12 Mar 2022 02:14:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbiCLCPG (ORCPT ); Fri, 11 Mar 2022 21:15:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbiCLCPC (ORCPT ); Fri, 11 Mar 2022 21:15:02 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D215A1AD38E; Fri, 11 Mar 2022 18:13:52 -0800 (PST) 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 22C1uSqK026133; Sat, 12 Mar 2022 02:13:50 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=ezSTnj9SySiEp/8lSQ8jPbzfcZ3YyT+GbYNgMaIlcsg=; b=BipWaB1zxVf8jlvAz96QsFJgUIEBwjC3O/t5dE96LSN8XtLO51AHTs8FSZPVDyjOZkbJ q2ABfVKJ+ei0nXM6FqNm4qJb3Repi2fdKfIGqLFh4tyZhh2zUaVnD6KyCj/Sd3YG6xsN HfCfYGQ41Vie6mkXmpffX46zUiktJmAv586MFNgg0r948u9eoTlxzuhINlj2ZBXmjdYR NB5YBBznb+R4cj/A7fYxoqD/GeJKk7MWyY3Q7I8cNIwQr5US5Eo1pGpB64vLCS1O2Jnb Fv5JXGzTMNayFG/phwAUlfHFNVoUs+Hhf1hbSx7Utw2SWxWPTzSFxBi1WrSH2tuSpVZ8 FA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3erja280c4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:50 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2DUUT085856; Sat, 12 Mar 2022 02:13:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qg4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:47 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMd086332; Sat, 12 Mar 2022 02:13:47 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-8; Sat, 12 Mar 2022 02:13:46 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 07/11] NFSD: Update find_in_sessionid_hashtbl() to handle courtesy clients Date: Fri, 11 Mar 2022 18:13:31 -0800 Message-Id: <1647051215-2873-8-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: sMJoT2IMdh5SZF8dNq_QEvk5AOL590Ds X-Proofpoint-GUID: sMJoT2IMdh5SZF8dNq_QEvk5AOL590Ds Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update find_in_sessionid_hashtbl to: . skip client with CLIENT_EXPIRED flag; discarded courtesy client. . if courtesy client was found then clear CLIENT_COURTESY and set CLIENT_RECONNECTED so callers can take appropriate action. Update nfsd4_sequence and nfsd4_bind_conn_to_session to create client record for client with CLIENT_RECONNECTED set. Update nfsd4_destroy_session to discard client with CLIENT_RECONNECTED set. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 2f19aaaf6a66..c917b6372a92 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1962,13 +1962,22 @@ 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 (nfs4_is_courtesy_client_expired(clp)) { + session = NULL; + goto out; + } status = nfsd4_get_session_locked(session); - if (status) + if (status) { session = NULL; + if (test_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags)) + nfsd4_discard_courtesy_clnt(clp); + } out: *ret = status; return session; @@ -3670,6 +3679,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; @@ -3702,6 +3712,13 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp, nfsd4_init_conn(rqstp, conn, session); status = nfs_ok; out: + clp = session->se_client; + if (test_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags)) { + if (status == nfs_ok) + nfsd4_client_record_create(clp); + else + nfsd4_discard_courtesy_clnt(clp); + } nfsd4_put_session(session); out_no_session: return status; @@ -3724,6 +3741,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)) { @@ -3736,6 +3754,12 @@ 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 (test_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags)) { + status = nfserr_badsession; + nfsd4_discard_courtesy_clnt(clp); + goto out_put_session; + } status = nfserr_wrong_cred; if (!nfsd4_mach_creds_match(ses->se_client, r)) goto out_put_session; @@ -3840,7 +3864,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; @@ -3950,6 +3974,12 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, if (conn) free_conn(conn); spin_unlock(&nn->client_lock); + if (clp && test_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags)) { + if (status == nfs_ok) + nfsd4_client_record_create(clp); + else + nfsd4_discard_courtesy_clnt(clp); + } return status; out_put_session: nfsd4_put_session_locked(session); From patchwork Sat Mar 12 02:13: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: 12778696 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 5F3B3C433F5 for ; Sat, 12 Mar 2022 02:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230028AbiCLCPD (ORCPT ); Fri, 11 Mar 2022 21:15:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbiCLCPC (ORCPT ); Fri, 11 Mar 2022 21:15:02 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A535C1AA4A2; Fri, 11 Mar 2022 18:13:51 -0800 (PST) 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 22BMfaJb021532; Sat, 12 Mar 2022 02:13:49 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=4gOxYT4f7zFlRFcnr3sx86+cwHgIt8w5U9mOfpuIv+c=; b=OxYjYf+6GK6udTzVDxrYTfWhCGQzGeCHQwMRyHI20DmGa3+ZeEb+HZkjIlECPn33Kqho fn5oZE82zrtnuCYyD+DFMCxy7YzCKj97Z/bJp4tfaGxhHrIrXaRl7hOnOlLbzy1M4a2T fOIrWj/84zPGi/DLdnInxOSftqY0DvudxaqO2e6VhuMhKEvO8hjaHQVdVkj7cWk2kYPw QFBkdkC5qrc7Ihbps+hp8diM8epAciwncWnmCLj/Lw1aA3wENNKMWJau7ppVD8gTQTm/ HgQXX8fLp5Tfh9Mwl4bxhxMETvM0lmA+i/mjRN0soHRj54zxcSE4FCvwgqtD0ImeedUn rg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3em0duahr8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:49 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2CXR6085352; Sat, 12 Mar 2022 02:13:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:48 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMf086332; Sat, 12 Mar 2022 02:13:47 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-9; Sat, 12 Mar 2022 02:13:47 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 08/11] NFSD: Update find_client_in_id_table() to handle courtesy clients Date: Fri, 11 Mar 2022 18:13:32 -0800 Message-Id: <1647051215-2873-9-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: dRB9mD4FOjiVu_1ciHZUL9R3JbQdp4HH X-Proofpoint-GUID: dRB9mD4FOjiVu_1ciHZUL9R3JbQdp4HH 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 clear CLIENT_COURTESY and set CLIENT_RECONNECTED flag so callers 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 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index c917b6372a92..2ff80999b243 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2920,6 +2920,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 (nfs4_is_courtesy_client_expired(clp)) + continue; renew_client_locked(clp); return clp; } @@ -2931,9 +2933,15 @@ 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 && test_bit(NFSD4_CLIENT_RECONNECTED, &clp->cl_flags)) { + nfsd4_discard_courtesy_clnt(clp); + clp = NULL; + } + return clp; } static struct nfs4_client * @@ -4872,9 +4880,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); @@ -4899,6 +4908,8 @@ static __be32 set_client(clientid_t *clid, cstate->clp = lookup_clientid(clid, false, nn); if (!cstate->clp) return nfserr_expired; + if (test_bit(NFSD4_CLIENT_RECONNECTED, &cstate->clp->cl_flags)) + nfsd4_client_record_create(cstate->clp); return nfs_ok; } @@ -6218,6 +6229,13 @@ 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 (test_bit(NFSD4_CLIENT_RECONNECTED, &found->cl_flags)) { + nfsd4_discard_courtesy_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); From patchwork Sat Mar 12 02:13: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: 12778715 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 CBDAAC433EF for ; Sat, 12 Mar 2022 02:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbiCLCPJ (ORCPT ); Fri, 11 Mar 2022 21:15:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230062AbiCLCPC (ORCPT ); Fri, 11 Mar 2022 21:15:02 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 548E61B84CA; Fri, 11 Mar 2022 18:13:57 -0800 (PST) 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 22BNEUlt011899; Sat, 12 Mar 2022 02:13:55 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=NAFoVzd9smCnK1gQpyKocadq16OaaIMgxxFBKYnc8yY=; b=LPLoMl3JVZucKS0JWMLqq6ulrOBjbahzi3G3I4m9qZetj2sNqNkGGTb0KVkw7V2ycqti mact6imcHork68U+P2NIOGG4xx93jU2Ue/YTi8rpOUv3ZupqNPKLNsIOXqUvZlAgQTlP DXEUBB+HR4wi4w2fccI6/063B2dVJFQUo93E+/4hf3J6ynGyvRzZt5xQ7iO1FbMPu0wy LuWYMpAjpetyhYtpvLen1KlCDAMxNTdWERSH0GdN8FZrxfmmGRNvslejCf/w1Wk0tmlk r7oQKi3+yfq6eJy4Myf2BRuq879QXYfCdn4hcczlLNJrJWvtInsc64oRqYTZ0UCDhkPG Ew== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyfstka7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:55 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2BkWp084209; Sat, 12 Mar 2022 02:13:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qgb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:48 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMh086332; Sat, 12 Mar 2022 02:13:48 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-10; Sat, 12 Mar 2022 02:13:48 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 09/11] NFSD: Refactor nfsd4_laundromat() Date: Fri, 11 Mar 2022 18:13:33 -0800 Message-Id: <1647051215-2873-10-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: xvxLrbWR0gbhAngnaSuKG7541AV4CPHe X-Proofpoint-ORIG-GUID: xvxLrbWR0gbhAngnaSuKG7541AV4CPHe 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 2ff80999b243..034161a28bd1 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5805,6 +5805,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) { @@ -5827,7 +5847,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) { @@ -5837,17 +5856,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 Sat Mar 12 02:13:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12778716 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 5F718C4332F for ; Sat, 12 Mar 2022 02:14:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbiCLCPJ (ORCPT ); Fri, 11 Mar 2022 21:15:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbiCLCPC (ORCPT ); Fri, 11 Mar 2022 21:15:02 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6D5B1BA913; Fri, 11 Mar 2022 18:13:57 -0800 (PST) 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 22BNhPnW011902; Sat, 12 Mar 2022 02:13:55 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=NXevyfZpVdLCUl1yFafMUxf1v8z+EOGIx2XhWHwbz5I=; b=Bsk8RykT9cjgV0wHkNsD6Zfb6MixlsXGl+ugd7EOwURwxymCFPNYb5ijv36KChB13Xqh 2P+IZ5B8sjFqPDmoBH9JZbwMcvAbG3cJjyWSdM0XnExNK4HpLcd7F4NJZr1IHZj+QDZD GdnTyiNKm1I4KYG1eV/5IPH+JnQLZ8O7ODw56D4ivMMD8nhzehDeBMkVAXknLtoncnbZ on68Z+QGjdPnf9wZ6BQdH6AGmauAo8tyD/MOA7c6J6Tzgk1keiyqPn06a61JwVCIEx+x vwm7jZjrwVc7bPaH2oGsiIHVG7WII5L/Q3ElDI8Xblc82YMX2WQdnz7GHJXPdq06uhZR 4g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3ekyfstka9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:55 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2BkdW084210; Sat, 12 Mar 2022 02:13:49 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qgd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:49 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMj086332; Sat, 12 Mar 2022 02:13:48 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-11; Sat, 12 Mar 2022 02:13:48 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 10/11] NFSD: Update laundromat to handle courtesy clients Date: Fri, 11 Mar 2022 18:13:34 -0800 Message-Id: <1647051215-2873-11-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: THp2bVEYM0K59g_O_jetCUOlEah1LKhg X-Proofpoint-ORIG-GUID: THp2bVEYM0K59g_O_jetCUOlEah1LKhg 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 discarded courtesy client; client marked with CLIENT_EXPIRED, to reaplist. . detect if expired client still has state and no blockers then transit it to courtesy client by setting CLIENT_COURTESY flag and removing the client record. Signed-off-by: Dai Ngo --- fs/nfsd/nfs4state.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 034161a28bd1..17b5d5b202c1 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5805,24 +5805,107 @@ 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 (test_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags)) + goto exp_client; + cour = test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags); + 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); + set_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags); + 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 (test_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags) || + !test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)) { + spin_unlock(&clp->cl_cs_lock); + continue; + } + spin_unlock(&clp->cl_cs_lock); + nfsd4_client_record_remove(clp); + } } static time64_t @@ -5868,6 +5951,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 (test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)) { + set_bit(NFSD4_CLIENT_EXPIRED, &clp->cl_flags); + 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 Sat Mar 12 02:13:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12778701 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 4758AC433EF for ; Sat, 12 Mar 2022 02:14:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230073AbiCLCPG (ORCPT ); Fri, 11 Mar 2022 21:15:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230057AbiCLCPC (ORCPT ); Fri, 11 Mar 2022 21:15:02 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2511C1AD942; Fri, 11 Mar 2022 18:13:53 -0800 (PST) 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 22C1Vdwt023826; Sat, 12 Mar 2022 02:13:50 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=ancRsNJ/fXVbrikDCqx4d3U/VLdR68Xz3Mugzj1HFQA=; b=PEd6Ggss685mhgrQO6MA41G/TDzyKrwdsgPlkjaRPQKSo/HEMECMF5hKWK75eiBqNLX9 x5iCemgqdO9ixnjaKHhO4KRpkhDjDKM2Y8x5/VHt5HWwoQjnszSmI5VbWB/zWSvd+xcS Cr9g0t+ZdQCgT7c7jM4enwHxUOrNQoCChXqn9F2T0gmF7wiLAl8pzZq73i5CstzVY5x5 ux58yd99jEW9J4OwScjaWL0l1Gg/3c7axZzns887g+ij4HTK4pbDZKjPBTlCqyiaQcS0 2GmI6RuLRSvkWSzrMYMCWZ8bIJ29siE1U4B9JqtkAojeVZ4jrHcaHUs0i+tbzLo/VQpb rg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3erhxcg0vb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:50 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 22C2CA0V084327; Sat, 12 Mar 2022 02:13:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3030.oracle.com with ESMTP id 3erhj88qgh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 12 Mar 2022 02:13:50 +0000 Received: from aserp3030.oracle.com (aserp3030.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22C2DgMl086332; Sat, 12 Mar 2022 02:13:49 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by aserp3030.oracle.com with ESMTP id 3erhj88qfe-12; Sat, 12 Mar 2022 02:13:49 +0000 From: Dai Ngo To: chuck.lever@oracle.com, bfields@fieldses.org Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH RFC v16 11/11] NFSD: Show state of courtesy clients in client info Date: Fri, 11 Mar 2022 18:13:35 -0800 Message-Id: <1647051215-2873-12-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> References: <1647051215-2873-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-GUID: Q9B1b3rdXbWYzd5YvWpUdYtKF2Sr41zB X-Proofpoint-ORIG-GUID: Q9B1b3rdXbWYzd5YvWpUdYtKF2Sr41zB 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 17b5d5b202c1..79f60bb7be76 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2438,7 +2438,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) @@ -2446,10 +2447,16 @@ 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 (test_bit(NFSD4_CLIENT_COURTESY, &clp->cl_flags)) + seq_puts(m, "status: courtesy\n"); + else if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags)) 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);