linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Waiman Long <longman@redhat.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Chandan Babu R <chandan.babu@oracle.com>,
	"Darrick J . Wong" <djwong@kernel.org>,
	linux-xfs@vger.kernel.org, Mateusz Guzik <mjguzik@gmail.com>
Subject: [PATCH v2 5/5] fs: Add inode_assert_locked() and inode_assert_locked_excl()
Date: Sat,  7 Oct 2023 21:35:43 +0100	[thread overview]
Message-ID: <20231007203543.1377452-6-willy@infradead.org> (raw)
In-Reply-To: <20231007203543.1377452-1-willy@infradead.org>

Use the new rwsem_assert_held functions to implement these new
assertions.  Convert the inode_is_locked() callers in the VFS to
use them.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/attr.c          |  2 +-
 fs/namei.c         |  6 +++---
 include/linux/fs.h | 10 ++++++++++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/attr.c b/fs/attr.c
index a8ae5f6d9b16..5e32b0a4f8c2 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -387,7 +387,7 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
 	struct timespec64 now;
 	unsigned int ia_valid = attr->ia_valid;
 
-	WARN_ON_ONCE(!inode_is_locked(inode));
+	inode_assert_locked_excl(inode);
 
 	error = may_setattr(idmap, inode, ia_valid);
 	if (error)
diff --git a/fs/namei.c b/fs/namei.c
index 567ee547492b..6b595ad4318d 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2708,7 +2708,7 @@ struct dentry *try_lookup_one_len(const char *name, struct dentry *base, int len
 	struct qstr this;
 	int err;
 
-	WARN_ON_ONCE(!inode_is_locked(base->d_inode));
+	inode_assert_locked(base->d_inode);
 
 	err = lookup_one_common(&nop_mnt_idmap, name, base, len, &this);
 	if (err)
@@ -2735,7 +2735,7 @@ struct dentry *lookup_one_len(const char *name, struct dentry *base, int len)
 	struct qstr this;
 	int err;
 
-	WARN_ON_ONCE(!inode_is_locked(base->d_inode));
+	inode_assert_locked(base->d_inode);
 
 	err = lookup_one_common(&nop_mnt_idmap, name, base, len, &this);
 	if (err)
@@ -2765,7 +2765,7 @@ struct dentry *lookup_one(struct mnt_idmap *idmap, const char *name,
 	struct qstr this;
 	int err;
 
-	WARN_ON_ONCE(!inode_is_locked(base->d_inode));
+	inode_assert_locked(base->d_inode);
 
 	err = lookup_one_common(idmap, name, base, len, &this);
 	if (err)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b528f063e8ff..e01e041c102b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -832,6 +832,16 @@ static inline int inode_is_locked(struct inode *inode)
 	return rwsem_is_locked(&inode->i_rwsem);
 }
 
+static inline void inode_assert_locked(const struct inode *inode)
+{
+	rwsem_assert_held(&inode->i_rwsem);
+}
+
+static inline void inode_assert_locked_excl(const struct inode *inode)
+{
+	rwsem_assert_held_write(&inode->i_rwsem);
+}
+
 static inline void inode_lock_nested(struct inode *inode, unsigned subclass)
 {
 	down_write_nested(&inode->i_rwsem, subclass);
-- 
2.40.1



  parent reply	other threads:[~2023-10-07 20:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-07 20:35 [PATCH v2 0/5] Remove the XFS mrlock Matthew Wilcox (Oracle)
2023-10-07 20:35 ` [PATCH v2 1/5] locking: Add rwsem_assert_held() and rwsem_assert_held_write() Matthew Wilcox (Oracle)
2023-10-08 21:54   ` Dave Chinner
2023-10-07 20:35 ` [PATCH v2 2/5] mm: Use rwsem assertion macros for mmap_lock Matthew Wilcox (Oracle)
2023-10-07 20:35 ` [PATCH v2 3/5] xfs: Replace xfs_isilocked with xfs_assert_locked Matthew Wilcox (Oracle)
2023-10-08 21:59   ` Dave Chinner
2023-10-09 18:27   ` Darrick J. Wong
2023-10-07 20:35 ` [PATCH v2 4/5] xfs: Remove mrlock wrapper Matthew Wilcox (Oracle)
2023-10-08 22:17   ` Dave Chinner
2023-10-07 20:35 ` Matthew Wilcox (Oracle) [this message]
2023-10-08 20:26   ` [PATCH v2 5/5] fs: Add inode_assert_locked() and inode_assert_locked_excl() Mateusz Guzik
2023-10-08 21:05     ` Matthew Wilcox
2023-10-08 21:21       ` Mateusz Guzik
2023-10-08 20:31 ` [PATCH v2 0/5] Remove the XFS mrlock Mateusz Guzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231007203543.1377452-6-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=chandan.babu@oracle.com \
    --cc=djwong@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=mjguzik@gmail.com \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).