diff mbox

[RFC,PATH,2/4] vfs: introduce delete trylock/unlock

Message ID 1478817883-27662-3-git-send-email-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Amir Goldstein Nov. 10, 2016, 10:44 p.m. UTC
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 mbox

Patch

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 *);