From: David Howells <dhowells@redhat.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
linux-unionfs@vger.kernel.org, linux-cachefs@redhat.com,
dhowells@redhat.com, Christoph Hellwig <hch@infradead.org>,
Miklos Szeredi <miklos@szeredi.hu>,
Jeff Layton <jlayton@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
torvalds@linux-foundation.org, linux-unionfs@vger.kernel.org,
linux-cachefs@redhat.com, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] vfs: Add tracepoints for inode_excl_inuse_trylock/unlock
Date: Mon, 31 Jan 2022 15:13:43 +0000 [thread overview]
Message-ID: <164364202369.1476539.452557132083658522.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <164364196407.1476539.8450117784231043601.stgit@warthog.procyon.org.uk>
Add tracepoints for inode_excl_inuse_trylock/unlock() to record successful
and lock, failed lock, successful unlock and unlock when it wasn't locked.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Amir Goldstein <amir73il@gmail.com>
cc: Miklos Szeredi <miklos@szeredi.hu>
cc: linux-unionfs@vger.kernel.org
cc: linux-cachefs@redhat.com
---
fs/inode.c | 21 +++++++++++++++++----
fs/overlayfs/super.c | 10 ++++++----
include/linux/fs.h | 9 +++++++--
3 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index 954719f66113..61b93a89853f 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -22,6 +22,8 @@
#include <linux/iversion.h>
#include <trace/events/writeback.h>
#include "internal.h"
+#define CREATE_TRACE_POINTS
+#include <trace/events/vfs.h>
/*
* Inode locking rules:
@@ -2409,11 +2411,14 @@ EXPORT_SYMBOL(current_time);
/**
* inode_excl_inuse_trylock - Try to exclusively lock an inode for kernel access
* @dentry: Reference to the inode to be locked
+ * @o: Private reference for the kernel service
+ * @who: Which kernel service is trying to gain the lock
*
* Try to gain exclusive access to an inode for a kernel service, returning
* true if successful.
*/
-bool inode_excl_inuse_trylock(struct dentry *dentry)
+bool inode_excl_inuse_trylock(struct dentry *dentry, unsigned int o,
+ enum inode_excl_inuse_by who)
{
struct inode *inode = d_inode(dentry);
bool locked = false;
@@ -2421,7 +2426,10 @@ bool inode_excl_inuse_trylock(struct dentry *dentry)
spin_lock(&inode->i_lock);
if (!(inode->i_state & I_EXCL_INUSE)) {
inode->i_state |= I_EXCL_INUSE;
+ trace_inode_excl_inuse_lock(inode, o, who);
locked = true;
+ } else {
+ trace_inode_excl_inuse_lock_failed(inode, o, who);
}
spin_unlock(&inode->i_lock);
@@ -2432,18 +2440,23 @@ EXPORT_SYMBOL(inode_excl_inuse_trylock);
/**
* inode_excl_inuse_unlock - Unlock exclusive kernel access to an inode
* @dentry: Reference to the inode to be unlocked
+ * @o: Private reference for the kernel service
*
* Drop exclusive access to an inode for a kernel service. A warning is given
* if the inode was not marked for exclusive access.
*/
-void inode_excl_inuse_unlock(struct dentry *dentry)
+void inode_excl_inuse_unlock(struct dentry *dentry, unsigned int o)
{
if (dentry) {
struct inode *inode = d_inode(dentry);
spin_lock(&inode->i_lock);
- WARN_ON(!(inode->i_state & I_EXCL_INUSE));
- inode->i_state &= ~I_EXCL_INUSE;
+ if (WARN_ON(!(inode->i_state & I_EXCL_INUSE))) {
+ trace_inode_excl_inuse_unlock_bad(inode, o);
+ } else {
+ inode->i_state &= ~I_EXCL_INUSE;
+ trace_inode_excl_inuse_unlock(inode, o);
+ }
spin_unlock(&inode->i_lock);
}
}
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 5c3361a2dc7c..6434ae11496d 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -224,10 +224,10 @@ static void ovl_free_fs(struct ovl_fs *ofs)
dput(ofs->indexdir);
dput(ofs->workdir);
if (ofs->workdir_locked)
- inode_excl_inuse_unlock(ofs->workbasedir);
+ inode_excl_inuse_unlock(ofs->workbasedir, 0);
dput(ofs->workbasedir);
if (ofs->upperdir_locked)
- inode_excl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root);
+ inode_excl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root, 0);
/* Hack! Reuse ofs->layers as a vfsmount array before freeing it */
mounts = (struct vfsmount **) ofs->layers;
@@ -1239,7 +1239,8 @@ static int ovl_get_upper(struct super_block *sb, struct ovl_fs *ofs,
if (upper_mnt->mnt_sb->s_flags & SB_NOSEC)
sb->s_flags |= SB_NOSEC;
- if (inode_excl_inuse_trylock(ovl_upper_mnt(ofs)->mnt_root)) {
+ if (inode_excl_inuse_trylock(ovl_upper_mnt(ofs)->mnt_root, 0,
+ inode_excl_inuse_by_overlayfs)) {
ofs->upperdir_locked = true;
} else {
err = ovl_report_in_use(ofs, "upperdir");
@@ -1499,7 +1500,8 @@ static int ovl_get_workdir(struct super_block *sb, struct ovl_fs *ofs,
ofs->workbasedir = dget(workpath.dentry);
- if (inode_excl_inuse_trylock(ofs->workbasedir)) {
+ if (inode_excl_inuse_trylock(ofs->workbasedir, 0,
+ inode_excl_inuse_by_overlayfs)) {
ofs->workdir_locked = true;
} else {
err = ovl_report_in_use(ofs, "workdir");
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 4c15e270f1ac..f461883d66a8 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2389,8 +2389,13 @@ static inline bool inode_is_dirtytime_only(struct inode *inode)
I_FREEING | I_WILL_FREE)) == I_DIRTY_TIME;
}
-bool inode_excl_inuse_trylock(struct dentry *dentry);
-void inode_excl_inuse_unlock(struct dentry *dentry);
+enum inode_excl_inuse_by {
+ inode_excl_inuse_by_overlayfs,
+};
+
+bool inode_excl_inuse_trylock(struct dentry *dentry, unsigned int o,
+ enum inode_excl_inuse_by who);
+void inode_excl_inuse_unlock(struct dentry *dentry, unsigned int o);
static inline bool inode_is_excl_inuse(struct dentry *dentry)
{
next prev parent reply other threads:[~2022-01-31 15:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-31 15:12 [RFC][PATCH 0/5] vfs, overlayfs, cachefiles: Combine I_OVL_INUSE and S_KERNEL_FILE and split out no-remove David Howells
2022-01-31 15:12 ` [PATCH 1/5] vfs, overlayfs, cachefiles: Turn I_OVL_INUSE into something generic David Howells
2022-01-31 15:29 ` Amir Goldstein
2022-01-31 15:32 ` David Howells
2022-01-31 16:20 ` Amir Goldstein
2022-01-31 15:13 ` David Howells [this message]
2022-01-31 15:32 ` [PATCH 2/5] vfs: Add tracepoints for inode_excl_inuse_trylock/unlock Amir Goldstein
2022-01-31 15:13 ` [PATCH 3/5] cachefiles: Split removal-prevention from S_KERNEL_FILE and extend effects David Howells
2022-01-31 15:14 ` [PATCH 4/5] cachefiles: Use I_EXCL_INUSE instead of S_KERNEL_FILE David Howells
2022-01-31 15:14 ` [PATCH 5/5] cachefiles: Remove the now-unused mark-inode-in-use tracepoints David Howells
2022-01-31 16:28 ` [RFC][PATCH 0/5] vfs, overlayfs, cachefiles: Combine I_OVL_INUSE and S_KERNEL_FILE and split out no-remove Amir Goldstein
2022-02-01 10:44 ` [PATCH 2/5] vfs: Add tracepoints for inode_excl_inuse_trylock/unlock David Howells
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=164364202369.1476539.452557132083658522.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=amir73il@gmail.com \
--cc=hch@infradead.org \
--cc=jlayton@kernel.org \
--cc=linux-cachefs@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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).