From patchwork Thu Mar 17 07:43:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dai Ngo X-Patchwork-Id: 12783629 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 42713C4332F for ; Thu, 17 Mar 2022 07:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230306AbiCQHpM (ORCPT ); Thu, 17 Mar 2022 03:45:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiCQHpL (ORCPT ); Thu, 17 Mar 2022 03:45:11 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E475BBE21; Thu, 17 Mar 2022 00:43:55 -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 22H3SxoE012057; Thu, 17 Mar 2022 07:43:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=xTY1D5IP/+x3DLOrYIDdP7OqXLFh1tM6rTp3CdlOMGs=; b=LBX0trdsQJ+88jmwv46+kBJ513YDGO6mGm7ph2hffAV6I/y2ut5lGY7GGaLXX0mGnktl ZPpN70/OpVuP6RRiNVrT6E1FKrt2Y2tdt3rIgLT5qHFk0TCfa64thfmXW9rzALFI1P0B rm424nRqZ8J6d4finEB/yTA7bbRj5PSuhs+TjKT0FHexZff5/5Jpxocb/qvwl+biUlyp IQ9FeE9kRYzb0oY5mA2Gj8WXIBOsFoJIP/GQEkzVJxN/ayzUnJlHifk9Mjg/gAEFp2Py 8w19BGbXM+/WeQ/9ZJr7/iiSie7Pfq6rff/UgmNsSBe5tDbn7DU7Jx/VbjKOTG3sWx2O Iw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com with ESMTP id 3et60rg6yu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Mar 2022 07:43:52 +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 22H7fnDC034964; Thu, 17 Mar 2022 07:43:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3erhy2wqw2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Mar 2022 07:43:52 +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 22H7hoGd038783; Thu, 17 Mar 2022 07:43:51 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3erhy2wqv5-2; Thu, 17 Mar 2022 07:43:51 +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 01/11] fs/lock: add helper locks_owner_has_blockers to check for blockers Date: Thu, 17 Mar 2022 00:43:38 -0700 Message-Id: <1647503028-11966-2-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-GUID: 2P0ExGDn3K5no15fcVZ-KDXo8Ppg3hVh X-Proofpoint-ORIG-GUID: 2P0ExGDn3K5no15fcVZ-KDXo8Ppg3hVh Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 Reviewed-by: Jeff Layton --- 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..2057a9df790f 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) {} +static inline 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)