From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAAACC49360 for ; Thu, 15 Jul 2021 13:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5B2C613D4 for ; Thu, 15 Jul 2021 13:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237969AbhGONnk (ORCPT ); Thu, 15 Jul 2021 09:43:40 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:55808 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237744AbhGONnf (ORCPT ); Thu, 15 Jul 2021 09:43:35 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7C7E422A7C; Thu, 15 Jul 2021 13:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1626356433; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UrWJRrmmZoeFsiXlatgXAwopNmimQ93wkzrLwvaNN0=; b=Vq6zyVi+TmKxjG4E2bDVHqilU05s3T3gkdYPFN9QWrpWbR+GxR6RlxitkuKJ3wa9JjXBuW B4Yb9uaFht7dlYpcJNWLyjXhvkw+6KOQKSuP6DeYLOKvo1MNYISBdsLoRQdzI81/UdPhqM I2TTzsRXYlE9ba20mfbsmM5cP1F37sQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1626356433; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UrWJRrmmZoeFsiXlatgXAwopNmimQ93wkzrLwvaNN0=; b=vPvQaBLdn4nF8xM+5K5KEGC/ouomYZFRiTn6m+gZfuSx9Er+5mBus+S5jB9AEbFudY6Ula sWwkbcKSe2BV1QBQ== Received: from quack2.suse.cz (unknown [10.100.200.198]) by relay2.suse.de (Postfix) with ESMTP id 680CEA3B9D; Thu, 15 Jul 2021 13:40:33 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 1B42A1E0C05; Thu, 15 Jul 2021 15:40:33 +0200 (CEST) From: Jan Kara To: Cc: , Christoph Hellwig , "Darrick J. Wong" , Ted Tso , Dave Chinner , Matthew Wilcox , , , linux-f2fs-devel@lists.sourceforge.net, linux-cifs@vger.kernel.org, ceph-devel@vger.kernel.org, Pavel Reichl , Dave Chinner , Eric Sandeen , "Darrick J . Wong" , Christoph Hellwig , Jan Kara Subject: [PATCH 07/14] xfs: Refactor xfs_isilocked() Date: Thu, 15 Jul 2021 15:40:17 +0200 Message-Id: <20210715134032.24868-7-jack@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210715133202.5975-1-jack@suse.cz> References: <20210715133202.5975-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2663; i=jack@suse.cz; h=from:subject; bh=YmQSkQse9NO9b0qrNLfWFR/SLfIwnVnRgr/nYQ5R0lY=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBg8DrBhJIq6dexPtRN0mRaJPDIgpTC8p8HxaHKF5yv BEL61CyJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYPA6wQAKCRCcnaoHP2RA2UAQB/ 9rg5NL72FfnXClKh6c0yAIPqCwy+FeNY+kyI9sfxL6MLpfwdAKEG051FlsOzEbC57n9xult0L9NK+a SKIpZNIXKtzDo1mJnXVzFit3q9KrWSykWOR2A6XKyL5yrPuZOQbSj9//39Vukg1Xi9tKW0rln8dsKl DlCCZLnN/Tqou0F0alPiI5z8Ydvx8yvtmYqYg4v+IwtaPWIClc9Cye80/06rUdQ6x12dW0niqMs6zh BJy9iasKMKa4aQ57hQGrUMn05CUfnZVD9qSJnCAMDnJ2aj/BtR1MSwl+UelmZE8EN0xnhbB9RfyV41 3mXYwJHybMymKmoj5OERJOjQ2/asDD X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Pavel Reichl Introduce a new __xfs_rwsem_islocked predicate to encapsulate checking the state of a rw_semaphore, then refactor xfs_isilocked to use it. Signed-off-by: Pavel Reichl Suggested-by: Dave Chinner Suggested-by: Eric Sandeen Suggested-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Jan Kara --- fs/xfs/xfs_inode.c | 34 ++++++++++++++++++++++++++-------- fs/xfs/xfs_inode.h | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index a835ceb79ba5..359e2cd44ad7 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -343,9 +343,29 @@ xfs_ilock_demote( } #if defined(DEBUG) || defined(XFS_WARN) -int +static inline bool +__xfs_rwsem_islocked( + struct rw_semaphore *rwsem, + bool shared) +{ + if (!debug_locks) + return rwsem_is_locked(rwsem); + + if (!shared) + return lockdep_is_held_type(rwsem, 0); + + /* + * We are checking that the lock is held at least in shared + * mode but don't care that it might be held exclusively + * (i.e. shared | excl). Hence we check if the lock is held + * in any mode rather than an explicit shared mode. + */ + return lockdep_is_held_type(rwsem, -1); +} + +bool xfs_isilocked( - xfs_inode_t *ip, + struct xfs_inode *ip, uint lock_flags) { if (lock_flags & (XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)) { @@ -360,15 +380,13 @@ xfs_isilocked( return rwsem_is_locked(&ip->i_mmaplock.mr_lock); } - if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) { - if (!(lock_flags & XFS_IOLOCK_SHARED)) - return !debug_locks || - lockdep_is_held_type(&VFS_I(ip)->i_rwsem, 0); - return rwsem_is_locked(&VFS_I(ip)->i_rwsem); + if (lock_flags & (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED)) { + return __xfs_rwsem_islocked(&VFS_I(ip)->i_rwsem, + (lock_flags & XFS_IOLOCK_SHARED)); } ASSERT(0); - return 0; + return false; } #endif diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 4b6703dbffb8..4b5202ae8ebb 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -410,7 +410,7 @@ void xfs_ilock(xfs_inode_t *, uint); int xfs_ilock_nowait(xfs_inode_t *, uint); void xfs_iunlock(xfs_inode_t *, uint); void xfs_ilock_demote(xfs_inode_t *, uint); -int xfs_isilocked(xfs_inode_t *, uint); +bool xfs_isilocked(struct xfs_inode *, uint); uint xfs_ilock_data_map_shared(struct xfs_inode *); uint xfs_ilock_attr_map_shared(struct xfs_inode *); -- 2.26.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 676C2C47E4B for ; Thu, 15 Jul 2021 13:46:26 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21553611AB; Thu, 15 Jul 2021 13:46:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21553611AB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1m41h3-0006up-QZ; Thu, 15 Jul 2021 13:46:25 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m41bt-0005pe-Om for linux-f2fs-devel@lists.sourceforge.net; Thu, 15 Jul 2021 13:41:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=3UrWJRrmmZoeFsiXlatgXAwopNmimQ93wkzrLwvaNN0=; b=gsiXxoQKnRujKXFZpCvTxD1L9r XjKLR9jlfDc+HhGOnQkfY9ZDLza05u8PAbUJgb0IaSk5mma9Ftd/vk9D4Ga1q3Q4iiWB7/g1ZLrsz fRsdbU0JYazfWU4kQrNUw2Fl+2uv59+WFEoL+tnLtjuneapxAwhbCOQsyoUjzkWkDRpE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=3UrWJRrmmZoeFsiXlatgXAwopNmimQ93wkzrLwvaNN0=; b=GlbwSyq9TYzWlROOT7Zf69/KW2 J/D4Fc6ez6JnMFuR1dVXbatWOrja00JCfhQJ8BTzx6Aqov1ZKWZT4BinrvYaWHv0RLO+yeVNX4Egg lYQF5s7MtchtMeOfqTY1wV9BZbqRqTKT1ykdlvjS/5TruItfSEK8R0k3w6/yZH/F9AOk=; Received: from smtp-out1.suse.de ([195.135.220.28]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) id 1m41bn-009HVb-Au for linux-f2fs-devel@lists.sourceforge.net; Thu, 15 Jul 2021 13:41:05 +0000 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7C7E422A7C; Thu, 15 Jul 2021 13:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1626356433; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UrWJRrmmZoeFsiXlatgXAwopNmimQ93wkzrLwvaNN0=; b=Vq6zyVi+TmKxjG4E2bDVHqilU05s3T3gkdYPFN9QWrpWbR+GxR6RlxitkuKJ3wa9JjXBuW B4Yb9uaFht7dlYpcJNWLyjXhvkw+6KOQKSuP6DeYLOKvo1MNYISBdsLoRQdzI81/UdPhqM I2TTzsRXYlE9ba20mfbsmM5cP1F37sQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1626356433; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3UrWJRrmmZoeFsiXlatgXAwopNmimQ93wkzrLwvaNN0=; b=vPvQaBLdn4nF8xM+5K5KEGC/ouomYZFRiTn6m+gZfuSx9Er+5mBus+S5jB9AEbFudY6Ula sWwkbcKSe2BV1QBQ== Received: from quack2.suse.cz (unknown [10.100.200.198]) by relay2.suse.de (Postfix) with ESMTP id 680CEA3B9D; Thu, 15 Jul 2021 13:40:33 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 1B42A1E0C05; Thu, 15 Jul 2021 15:40:33 +0200 (CEST) From: Jan Kara To: Date: Thu, 15 Jul 2021 15:40:17 +0200 Message-Id: <20210715134032.24868-7-jack@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210715133202.5975-1-jack@suse.cz> References: <20210715133202.5975-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2663; i=jack@suse.cz; h=from:subject; bh=YmQSkQse9NO9b0qrNLfWFR/SLfIwnVnRgr/nYQ5R0lY=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBg8DrBhJIq6dexPtRN0mRaJPDIgpTC8p8HxaHKF5yv BEL61CyJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYPA6wQAKCRCcnaoHP2RA2UAQB/ 9rg5NL72FfnXClKh6c0yAIPqCwy+FeNY+kyI9sfxL6MLpfwdAKEG051FlsOzEbC57n9xult0L9NK+a SKIpZNIXKtzDo1mJnXVzFit3q9KrWSykWOR2A6XKyL5yrPuZOQbSj9//39Vukg1Xi9tKW0rln8dsKl DlCCZLnN/Tqou0F0alPiI5z8Ydvx8yvtmYqYg4v+IwtaPWIClc9Cye80/06rUdQ6x12dW0niqMs6zh BJy9iasKMKa4aQ57hQGrUMn05CUfnZVD9qSJnCAMDnJ2aj/BtR1MSwl+UelmZE8EN0xnhbB9RfyV41 3mXYwJHybMymKmoj5OERJOjQ2/asDD X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Headers-End: 1m41bn-009HVb-Au Subject: [f2fs-dev] [PATCH 07/14] xfs: Refactor xfs_isilocked() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-xfs@vger.kernel.org, Ted Tso , Eric Sandeen , linux-cifs@vger.kernel.org, "Darrick J. Wong" , "Darrick J . Wong" , Dave Chinner , Matthew Wilcox , linux-f2fs-devel@lists.sourceforge.net, Christoph Hellwig , linux-mm@kvack.org, Dave Chinner , Jan Kara , ceph-devel@vger.kernel.org, linux-ext4@vger.kernel.org, Christoph Hellwig , Pavel Reichl Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Pavel Reichl Introduce a new __xfs_rwsem_islocked predicate to encapsulate checking the state of a rw_semaphore, then refactor xfs_isilocked to use it. Signed-off-by: Pavel Reichl Suggested-by: Dave Chinner Suggested-by: Eric Sandeen Suggested-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Jan Kara --- fs/xfs/xfs_inode.c | 34 ++++++++++++++++++++++++++-------- fs/xfs/xfs_inode.h | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index a835ceb79ba5..359e2cd44ad7 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -343,9 +343,29 @@ xfs_ilock_demote( } #if defined(DEBUG) || defined(XFS_WARN) -int +static inline bool +__xfs_rwsem_islocked( + struct rw_semaphore *rwsem, + bool shared) +{ + if (!debug_locks) + return rwsem_is_locked(rwsem); + + if (!shared) + return lockdep_is_held_type(rwsem, 0); + + /* + * We are checking that the lock is held at least in shared + * mode but don't care that it might be held exclusively + * (i.e. shared | excl). Hence we check if the lock is held + * in any mode rather than an explicit shared mode. + */ + return lockdep_is_held_type(rwsem, -1); +} + +bool xfs_isilocked( - xfs_inode_t *ip, + struct xfs_inode *ip, uint lock_flags) { if (lock_flags & (XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)) { @@ -360,15 +380,13 @@ xfs_isilocked( return rwsem_is_locked(&ip->i_mmaplock.mr_lock); } - if (lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) { - if (!(lock_flags & XFS_IOLOCK_SHARED)) - return !debug_locks || - lockdep_is_held_type(&VFS_I(ip)->i_rwsem, 0); - return rwsem_is_locked(&VFS_I(ip)->i_rwsem); + if (lock_flags & (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED)) { + return __xfs_rwsem_islocked(&VFS_I(ip)->i_rwsem, + (lock_flags & XFS_IOLOCK_SHARED)); } ASSERT(0); - return 0; + return false; } #endif diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 4b6703dbffb8..4b5202ae8ebb 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -410,7 +410,7 @@ void xfs_ilock(xfs_inode_t *, uint); int xfs_ilock_nowait(xfs_inode_t *, uint); void xfs_iunlock(xfs_inode_t *, uint); void xfs_ilock_demote(xfs_inode_t *, uint); -int xfs_isilocked(xfs_inode_t *, uint); +bool xfs_isilocked(struct xfs_inode *, uint); uint xfs_ilock_data_map_shared(struct xfs_inode *); uint xfs_ilock_attr_map_shared(struct xfs_inode *); -- 2.26.2 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel