From patchwork Thu Mar 17 07:43:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12783619 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 53AC8C433FE for ; Thu, 17 Mar 2022 07:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbiCQHpS (ORCPT ); Thu, 17 Mar 2022 03:45:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbiCQHpO (ORCPT ); Thu, 17 Mar 2022 03:45:14 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 218A4BF51F; Thu, 17 Mar 2022 00:43:58 -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 22H3UMdV018260; Thu, 17 Mar 2022 07:43: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=GCCYTjtEURvqHpfBP1bRepULzX12vgrHNRQxR5jmc0E=; b=Gh+Wtf6LJI35J2OjHkGybDb6Guuze0iTbRJEyvvI404zvL4uyPwKb/dIZsG5SFqHwvHI tHiealvMhq/+sAlp/kfa9iUgSt284jcB3bclmA1L7mVzn1i4q6sIhGU0D483ATo7j+JM Ytn56xZCvUFKqN82nAUGD2wgjRikoYnhpY60+NutNUGfN2YzuoxcNviye/KRrHOEvuZo 2r2o4MVTyH0DgZlQO0zpgMItBTsfsvNEMnPVL5Wt9STTjgtEJxzsHGLysF/6JKynbTEp 263Yy+L6WzwrqTfSMpSpS8Kk38B/7M1O4fzoAJS6zSFaKX37WkXbatniYMyFuA1YKhnf iw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com with ESMTP id 3et60rrehh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Mar 2022 07:43:54 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 22H7fnNk034962; Thu, 17 Mar 2022 07:43:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3erhy2wqwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Mar 2022 07:43:54 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 22H7hoGh038783; Thu, 17 Mar 2022 07:43:53 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3erhy2wqv5-4; Thu, 17 Mar 2022 07:43:53 +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 v17 03/11] NFSD: Add lm_lock_expired call out Date: Thu, 17 Mar 2022 00:43:40 -0700 Message-Id: <1647503028-11966-4-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1647503028-11966-1-git-send-email-dai.ngo@oracle.com> References: <1647503028-11966-1-git-send-email-dai.ngo@oracle.com> X-Proofpoint-ORIG-GUID: mjHJDhAAWEYxNr18za5IxN1n0CMqFRf7 X-Proofpoint-GUID: mjHJDhAAWEYxNr18za5IxN1n0CMqFRf7 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 40e390abc842..d156ae3ab46c 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 */