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)