From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [RFC][PATH 2/4] vfs: introduce delete trylock/unlock
Date: Fri, 11 Nov 2016 00:44:41 +0200 [thread overview]
Message-ID: <1478817883-27662-3-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1478817883-27662-1-git-send-email-amir73il@gmail.com>
A delete lock prevents a dentry from being unlinked and renamed,
for as long as the dentry remains in cache.
Introduce the helpers delete_trylock() and delete_unlock(), which
use test_and_set and test_and_clear semantics to ser/clear a delete
lock on a dentry.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
include/linux/dcache.h | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 94cd40c..90584b9 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -356,11 +356,33 @@ static inline int cant_delete(const struct dentry *dentry)
return (dentry->d_flags & DCACHE_DELETE_LOCK);
}
-static inline void dont_delete(struct dentry *dentry)
+static inline int delete_trylock(struct dentry *dentry)
{
+ int locked;
+
spin_lock(&dentry->d_lock);
+ locked = likely(!cant_delete(dentry));
dentry->d_flags |= DCACHE_DELETE_LOCK;
spin_unlock(&dentry->d_lock);
+
+ return locked;
+}
+
+static inline void dont_delete(struct dentry *dentry)
+{
+ delete_trylock(dentry);
+}
+
+static inline int delete_unlock(struct dentry *dentry)
+{
+ int unlocked;
+
+ spin_lock(&dentry->d_lock);
+ unlocked = likely(cant_delete(dentry));
+ dentry->d_flags &= ~DCACHE_DELETE_LOCK;
+ spin_unlock(&dentry->d_lock);
+
+ return unlocked;
}
extern void __d_lookup_done(struct dentry *);
--
2.7.4
next prev parent reply other threads:[~2016-11-10 22:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 22:44 [RFC][PATH 0/4] Reduce excessive use of lock_rename() in overlayfs Amir Goldstein
2016-11-10 22:44 ` [RFC][PATH 1/4] vfs: reinterpret sillyrename flag as delete lock Amir Goldstein
2016-11-10 22:44 ` Amir Goldstein [this message]
2016-11-10 22:44 ` [RFC][PATH 3/4] ovl: delete lock upper dir and work dir Amir Goldstein
2016-11-10 22:44 ` [RFC][PATH 4/4] ovl: relax lock_rename when moving files between work and upper dir Amir Goldstein
2016-11-10 23:02 ` Al Viro
2016-11-10 23:05 ` Al Viro
2016-11-10 23:11 ` Amir Goldstein
2016-11-10 23:17 ` Al Viro
2016-11-10 23:33 ` Amir Goldstein
2016-11-10 23:54 ` Al Viro
2016-11-11 0:11 ` Amir Goldstein
2016-11-11 0:27 ` Al Viro
2016-11-11 14:43 ` Amir Goldstein
2016-11-11 15:40 ` Al Viro
2016-11-11 16:17 ` Amir Goldstein
2016-11-11 17:27 ` Al Viro
2016-11-11 17:44 ` Miklos Szeredi
2017-01-12 5:42 ` Amir Goldstein
2017-01-12 10:00 ` Miklos Szeredi
2017-01-12 18:18 ` Amir Goldstein
2016-11-11 18:07 ` Amir Goldstein
2016-11-12 19:45 ` Amir Goldstein
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=1478817883-27662-3-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=koct9i@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--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).