From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E895C1586C6; Tue, 18 Jun 2024 13:07:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718716065; cv=none; b=W9GEvMkE8FTv1zg/6JB8OhZtEE/vvGSmCHTTcvfB/JpxO4fYPkk6pCZwQ+2g4dxUPEZM0LznHRE8AdwfWPxpY3dcUfsWb4wJlVWjBm/+6VKY2KUTudelihjhb0gXAxKn2Ck4MOTOmXE1JDdaZh+d4a/KrDyXvrqOi4Vr0NCfnYA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718716065; c=relaxed/simple; bh=R/QomR3YB1Ust5oLN48o3Peb8obZ0yA2KUWC8uziWWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=miYXZdPLd1KLpdigQgTyfZxCfW42kaNVFB+4ztV7H/6tiK7yKwNIFgkyzBe83zYRw1YQNPwUDpePmpen66DhaqsGNrkXLZUFbZImRI4EYcfzeb1+mtkA5S0kR78DR8EOGgg4QEtDnLCC3I9y+FCjHFt6OwcvCkadMf/2HEmsfNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZNhXUF0O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZNhXUF0O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB56C3277B; Tue, 18 Jun 2024 13:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718716064; bh=R/QomR3YB1Ust5oLN48o3Peb8obZ0yA2KUWC8uziWWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNhXUF0O6JR7FWJPSkpG/HtUCGl/D0ATIiNIUdb0/Fr4PdyqqIp1L/eM+uagkdRkz 3alPwmd49i0YcI47OPkPmcsITivgnGqnFeUAk9h3Qx0e4+l24BQrjsVJgz4cv2y5tw Y3EAKtyiTCzR6sIhU4f/UsfCs/ZznC+c8pQ+clQw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "J. Bruce Fields" , Dai Ngo , Chuck Lever , Jeff Layton , Sasha Levin Subject: [PATCH 5.10 513/770] fs/lock: add helper locks_owner_has_blockers to check for blockers Date: Tue, 18 Jun 2024 14:36:06 +0200 Message-ID: <20240618123427.112695709@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618123407.280171066@linuxfoundation.org> References: <20240618123407.280171066@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dai Ngo [ Upstream commit 591502c5cb325b1c6ec59ab161927d606b918aa0 ] Add helper locks_owner_has_blockers to check if there is any blockers for a given lockowner. Reviewed-by: J. Bruce Fields Signed-off-by: Dai Ngo Signed-off-by: Chuck Lever Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- 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 101867933e4d3..118df2812f8aa 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -376,6 +376,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 c0459446e1440..17dc1ee8c6cb2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1163,6 +1163,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) @@ -1303,6 +1305,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) -- 2.43.0