Commit 06fb4736 authored by Imran Khan's avatar Imran Khan Committed by Greg Kroah-Hartman

kernfs: change kernfs_rename_lock into a read-write lock.

kernfs_rename_lock protects a node's ->parent and thus kernfs topology.
Thus it can be used in cases that rely on a stable kernfs topology.
Change it to a read-write lock for better scalability.

Suggested by: Al Viro <viro@zeniv.linux.org.uk>
Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarImran Khan <imran.f.khan@oracle.com>
Link: https://lore.kernel.org/r/20230309110932.2889010-4-imran.f.khan@oracle.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c9f2dfb7
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "kernfs-internal.h" #include "kernfs-internal.h"
static DEFINE_SPINLOCK(kernfs_rename_lock); /* kn->parent and ->name */ static DEFINE_RWLOCK(kernfs_rename_lock); /* kn->parent and ->name */
/* /*
* Don't use rename_lock to piggy back on pr_cont_buf. We don't want to * Don't use rename_lock to piggy back on pr_cont_buf. We don't want to
* call pr_cont() while holding rename_lock. Because sometimes pr_cont() * call pr_cont() while holding rename_lock. Because sometimes pr_cont()
...@@ -196,9 +196,9 @@ int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) ...@@ -196,9 +196,9 @@ int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
unsigned long flags; unsigned long flags;
int ret; int ret;
spin_lock_irqsave(&kernfs_rename_lock, flags); read_lock_irqsave(&kernfs_rename_lock, flags);
ret = kernfs_name_locked(kn, buf, buflen); ret = kernfs_name_locked(kn, buf, buflen);
spin_unlock_irqrestore(&kernfs_rename_lock, flags); read_unlock_irqrestore(&kernfs_rename_lock, flags);
return ret; return ret;
} }
...@@ -224,9 +224,9 @@ int kernfs_path_from_node(struct kernfs_node *to, struct kernfs_node *from, ...@@ -224,9 +224,9 @@ int kernfs_path_from_node(struct kernfs_node *to, struct kernfs_node *from,
unsigned long flags; unsigned long flags;
int ret; int ret;
spin_lock_irqsave(&kernfs_rename_lock, flags); read_lock_irqsave(&kernfs_rename_lock, flags);
ret = kernfs_path_from_node_locked(to, from, buf, buflen); ret = kernfs_path_from_node_locked(to, from, buf, buflen);
spin_unlock_irqrestore(&kernfs_rename_lock, flags); read_unlock_irqrestore(&kernfs_rename_lock, flags);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(kernfs_path_from_node); EXPORT_SYMBOL_GPL(kernfs_path_from_node);
...@@ -294,10 +294,10 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn) ...@@ -294,10 +294,10 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
struct kernfs_node *parent; struct kernfs_node *parent;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&kernfs_rename_lock, flags); read_lock_irqsave(&kernfs_rename_lock, flags);
parent = kn->parent; parent = kn->parent;
kernfs_get(parent); kernfs_get(parent);
spin_unlock_irqrestore(&kernfs_rename_lock, flags); read_unlock_irqrestore(&kernfs_rename_lock, flags);
return parent; return parent;
} }
...@@ -1731,7 +1731,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, ...@@ -1731,7 +1731,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
kernfs_get(new_parent); kernfs_get(new_parent);
/* rename_lock protects ->parent and ->name accessors */ /* rename_lock protects ->parent and ->name accessors */
spin_lock_irq(&kernfs_rename_lock); write_lock_irq(&kernfs_rename_lock);
old_parent = kn->parent; old_parent = kn->parent;
kn->parent = new_parent; kn->parent = new_parent;
...@@ -1742,7 +1742,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, ...@@ -1742,7 +1742,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
kn->name = new_name; kn->name = new_name;
} }
spin_unlock_irq(&kernfs_rename_lock); write_unlock_irq(&kernfs_rename_lock);
kn->hash = kernfs_name_hash(kn->name, kn->ns); kn->hash = kernfs_name_hash(kn->name, kn->ns);
kernfs_link_sibling(kn); kernfs_link_sibling(kn);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment