summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
324a56e)
kernfs has just been separated out from sysfs and we're already in
full conflict mode. Nothing can make the situation any worse. Let's
take the chance to name things properly.
s_ prefix for kernfs members is used inconsistently and a misnomer
now. It's not like kernfs_node is used widely across the kernel
making the ability to grep for the members particularly useful. Let's
just drop the prefix.
This patch is strictly rename only and doesn't introduce any
functional difference.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
DEFINE_MUTEX(sysfs_mutex);
DEFINE_MUTEX(sysfs_mutex);
-#define rb_to_kn(X) rb_entry((X), struct kernfs_node, s_rb)
+#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb)
static int sysfs_name_compare(unsigned int hash, const char *name,
const void *ns, const struct kernfs_node *kn)
{
static int sysfs_name_compare(unsigned int hash, const char *name,
const void *ns, const struct kernfs_node *kn)
{
- if (hash != kn->s_hash)
- return hash - kn->s_hash;
- if (ns != kn->s_ns)
- return ns - kn->s_ns;
- return strcmp(name, kn->s_name);
+ if (hash != kn->hash)
+ return hash - kn->hash;
+ if (ns != kn->ns)
+ return ns - kn->ns;
+ return strcmp(name, kn->name);
}
static int sysfs_sd_compare(const struct kernfs_node *left,
const struct kernfs_node *right)
{
}
static int sysfs_sd_compare(const struct kernfs_node *left,
const struct kernfs_node *right)
{
- return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns,
- right);
+ return sysfs_name_compare(left->hash, left->name, left->ns, right);
* @kn: kernfs_node of interest
*
* Link @kn into its sibling rbtree which starts from
* @kn: kernfs_node of interest
*
* Link @kn into its sibling rbtree which starts from
- * @kn->s_parent->s_dir.children.
+ * @kn->parent->dir.children.
*
* Locking:
* mutex_lock(sysfs_mutex)
*
* Locking:
* mutex_lock(sysfs_mutex)
*/
static int sysfs_link_sibling(struct kernfs_node *kn)
{
*/
static int sysfs_link_sibling(struct kernfs_node *kn)
{
- struct rb_node **node = &kn->s_parent->s_dir.children.rb_node;
+ struct rb_node **node = &kn->parent->dir.children.rb_node;
struct rb_node *parent = NULL;
if (sysfs_type(kn) == SYSFS_DIR)
struct rb_node *parent = NULL;
if (sysfs_type(kn) == SYSFS_DIR)
- kn->s_parent->s_dir.subdirs++;
+ kn->parent->dir.subdirs++;
while (*node) {
struct kernfs_node *pos;
while (*node) {
struct kernfs_node *pos;
parent = *node;
result = sysfs_sd_compare(kn, pos);
if (result < 0)
parent = *node;
result = sysfs_sd_compare(kn, pos);
if (result < 0)
- node = &pos->s_rb.rb_left;
+ node = &pos->rb.rb_left;
- node = &pos->s_rb.rb_right;
+ node = &pos->rb.rb_right;
else
return -EEXIST;
}
/* add new node and rebalance the tree */
else
return -EEXIST;
}
/* add new node and rebalance the tree */
- rb_link_node(&kn->s_rb, parent, node);
- rb_insert_color(&kn->s_rb, &kn->s_parent->s_dir.children);
+ rb_link_node(&kn->rb, parent, node);
+ rb_insert_color(&kn->rb, &kn->parent->dir.children);
* @kn: kernfs_node of interest
*
* Unlink @kn from its sibling rbtree which starts from
* @kn: kernfs_node of interest
*
* Unlink @kn from its sibling rbtree which starts from
- * kn->s_parent->s_dir.children.
+ * kn->parent->dir.children.
*
* Locking:
* mutex_lock(sysfs_mutex)
*
* Locking:
* mutex_lock(sysfs_mutex)
static void sysfs_unlink_sibling(struct kernfs_node *kn)
{
if (sysfs_type(kn) == SYSFS_DIR)
static void sysfs_unlink_sibling(struct kernfs_node *kn)
{
if (sysfs_type(kn) == SYSFS_DIR)
- kn->s_parent->s_dir.subdirs--;
+ kn->parent->dir.subdirs--;
- rb_erase(&kn->s_rb, &kn->s_parent->s_dir.children);
+ rb_erase(&kn->rb, &kn->parent->dir.children);
if (unlikely(!kn))
return NULL;
if (unlikely(!kn))
return NULL;
- if (!atomic_inc_unless_negative(&kn->s_active))
+ if (!atomic_inc_unless_negative(&kn->active))
- if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & SYSFS_FLAG_LOCKDEP)
rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_);
return kn;
}
rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_);
return kn;
}
if (unlikely(!kn))
return;
if (unlikely(!kn))
return;
- if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & SYSFS_FLAG_LOCKDEP)
rwsem_release(&kn->dep_map, 1, _RET_IP_);
rwsem_release(&kn->dep_map, 1, _RET_IP_);
- v = atomic_dec_return(&kn->s_active);
+ v = atomic_dec_return(&kn->active);
if (likely(v != SD_DEACTIVATED_BIAS))
return;
if (likely(v != SD_DEACTIVATED_BIAS))
return;
DECLARE_COMPLETION_ONSTACK(wait);
int v;
DECLARE_COMPLETION_ONSTACK(wait);
int v;
- BUG_ON(!(kn->s_flags & SYSFS_FLAG_REMOVED));
+ BUG_ON(!(kn->flags & SYSFS_FLAG_REMOVED));
if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF))
return;
if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF))
return;
/* atomic_add_return() is a mb(), put_active() will always see
* the updated kn->u.completion.
*/
/* atomic_add_return() is a mb(), put_active() will always see
* the updated kn->u.completion.
*/
- v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->s_active);
+ v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->active);
if (v != SD_DEACTIVATED_BIAS) {
lock_contended(&kn->dep_map, _RET_IP_);
if (v != SD_DEACTIVATED_BIAS) {
lock_contended(&kn->dep_map, _RET_IP_);
void kernfs_get(struct kernfs_node *kn)
{
if (kn) {
void kernfs_get(struct kernfs_node *kn)
{
if (kn) {
- WARN_ON(!atomic_read(&kn->s_count));
- atomic_inc(&kn->s_count);
+ WARN_ON(!atomic_read(&kn->count));
+ atomic_inc(&kn->count);
}
}
EXPORT_SYMBOL_GPL(kernfs_get);
}
}
EXPORT_SYMBOL_GPL(kernfs_get);
struct kernfs_node *parent;
struct kernfs_root *root;
struct kernfs_node *parent;
struct kernfs_root *root;
- if (!kn || !atomic_dec_and_test(&kn->s_count))
+ if (!kn || !atomic_dec_and_test(&kn->count))
return;
root = kernfs_root(kn);
repeat:
/* Moving/renaming is always done while holding reference.
return;
root = kernfs_root(kn);
repeat:
/* Moving/renaming is always done while holding reference.
- * kn->s_parent won't change beneath us.
+ * kn->parent won't change beneath us.
- WARN(!(kn->s_flags & SYSFS_FLAG_REMOVED),
+ WARN(!(kn->flags & SYSFS_FLAG_REMOVED),
"sysfs: free using entry: %s/%s\n",
"sysfs: free using entry: %s/%s\n",
- parent ? parent->s_name : "", kn->s_name);
+ parent ? parent->name : "", kn->name);
if (sysfs_type(kn) == SYSFS_KOBJ_LINK)
if (sysfs_type(kn) == SYSFS_KOBJ_LINK)
- kernfs_put(kn->s_symlink.target_kn);
+ kernfs_put(kn->symlink.target_kn);
if (sysfs_type(kn) & SYSFS_COPY_NAME)
if (sysfs_type(kn) & SYSFS_COPY_NAME)
- kfree(kn->s_name);
- if (kn->s_iattr) {
- if (kn->s_iattr->ia_secdata)
- security_release_secctx(kn->s_iattr->ia_secdata,
- kn->s_iattr->ia_secdata_len);
- simple_xattrs_free(&kn->s_iattr->xattrs);
+ kfree(kn->name);
+ if (kn->iattr) {
+ if (kn->iattr->ia_secdata)
+ security_release_secctx(kn->iattr->ia_secdata,
+ kn->iattr->ia_secdata_len);
+ simple_xattrs_free(&kn->iattr->xattrs);
- kfree(kn->s_iattr);
- ida_simple_remove(&root->ino_ida, kn->s_ino);
+ kfree(kn->iattr);
+ ida_simple_remove(&root->ino_ida, kn->ino);
kmem_cache_free(sysfs_dir_cachep, kn);
kn = parent;
if (kn) {
kmem_cache_free(sysfs_dir_cachep, kn);
kn = parent;
if (kn) {
- if (atomic_dec_and_test(&kn->s_count))
+ if (atomic_dec_and_test(&kn->count))
goto repeat;
} else {
/* just released the root kn, free @root too */
goto repeat;
} else {
/* just released the root kn, free @root too */
static int sysfs_dentry_delete(const struct dentry *dentry)
{
struct kernfs_node *kn = dentry->d_fsdata;
static int sysfs_dentry_delete(const struct dentry *dentry)
{
struct kernfs_node *kn = dentry->d_fsdata;
- return !(kn && !(kn->s_flags & SYSFS_FLAG_REMOVED));
+ return !(kn && !(kn->flags & SYSFS_FLAG_REMOVED));
}
static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
}
static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
mutex_lock(&sysfs_mutex);
/* The sysfs dirent has been deleted */
mutex_lock(&sysfs_mutex);
/* The sysfs dirent has been deleted */
- if (kn->s_flags & SYSFS_FLAG_REMOVED)
+ if (kn->flags & SYSFS_FLAG_REMOVED)
goto out_bad;
/* The sysfs dirent has been moved? */
goto out_bad;
/* The sysfs dirent has been moved? */
- if (dentry->d_parent->d_fsdata != kn->s_parent)
+ if (dentry->d_parent->d_fsdata != kn->parent)
goto out_bad;
/* The sysfs dirent has been renamed */
goto out_bad;
/* The sysfs dirent has been renamed */
- if (strcmp(dentry->d_name.name, kn->s_name) != 0)
+ if (strcmp(dentry->d_name.name, kn->name) != 0)
goto out_bad;
/* The sysfs dirent has been moved to a different namespace */
goto out_bad;
/* The sysfs dirent has been moved to a different namespace */
- if (kn->s_parent && kernfs_ns_enabled(kn->s_parent) &&
- sysfs_info(dentry->d_sb)->ns != kn->s_ns)
+ if (kn->parent && kernfs_ns_enabled(kn->parent) &&
+ sysfs_info(dentry->d_sb)->ns != kn->ns)
goto out_bad;
mutex_unlock(&sysfs_mutex);
goto out_bad;
mutex_unlock(&sysfs_mutex);
ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL);
if (ret < 0)
goto err_out2;
ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL);
if (ret < 0)
goto err_out2;
- atomic_set(&kn->s_count, 1);
- atomic_set(&kn->s_active, 0);
+ atomic_set(&kn->count, 1);
+ atomic_set(&kn->active, 0);
- kn->s_name = name;
- kn->s_mode = mode;
- kn->s_flags = type | SYSFS_FLAG_REMOVED;
+ kn->name = name;
+ kn->mode = mode;
+ kn->flags = type | SYSFS_FLAG_REMOVED;
* @kn: kernfs_node to be added
* @parent: the parent kernfs_node to add @kn to
*
* @kn: kernfs_node to be added
* @parent: the parent kernfs_node to add @kn to
*
- * Get @parent and set @kn->s_parent to it and increment nlink of
- * the parent inode if @kn is a directory and link into the children
- * list of the parent.
+ * Get @parent and set @kn->parent to it and increment nlink of the
+ * parent inode if @kn is a directory and link into the children list
+ * of the parent.
*
* This function should be called between calls to
* sysfs_addrm_start() and sysfs_addrm_finish() and should be
*
* This function should be called between calls to
* sysfs_addrm_start() and sysfs_addrm_finish() and should be
struct sysfs_inode_attrs *ps_iattr;
int ret;
struct sysfs_inode_attrs *ps_iattr;
int ret;
- if (has_ns != (bool)kn->s_ns) {
+ if (has_ns != (bool)kn->ns) {
WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
- has_ns ? "required" : "invalid",
- parent->s_name, kn->s_name);
+ has_ns ? "required" : "invalid", parent->name, kn->name);
return -EINVAL;
}
if (sysfs_type(parent) != SYSFS_DIR)
return -EINVAL;
return -EINVAL;
}
if (sysfs_type(parent) != SYSFS_DIR)
return -EINVAL;
- kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
- kn->s_parent = parent;
+ kn->hash = sysfs_name_hash(kn->name, kn->ns);
+ kn->parent = parent;
kernfs_get(parent);
ret = sysfs_link_sibling(kn);
kernfs_get(parent);
ret = sysfs_link_sibling(kn);
return ret;
/* Update timestamps on the parent */
return ret;
/* Update timestamps on the parent */
- ps_iattr = parent->s_iattr;
+ ps_iattr = parent->iattr;
if (ps_iattr) {
struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
}
/* Mark the entry added into directory tree */
if (ps_iattr) {
struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
}
/* Mark the entry added into directory tree */
- kn->s_flags &= ~SYSFS_FLAG_REMOVED;
+ kn->flags &= ~SYSFS_FLAG_REMOVED;
* Removal can be called multiple times on the same node. Only the
* first invocation is effective and puts the base ref.
*/
* Removal can be called multiple times on the same node. Only the
* first invocation is effective and puts the base ref.
*/
- if (kn->s_flags & SYSFS_FLAG_REMOVED)
+ if (kn->flags & SYSFS_FLAG_REMOVED)
sysfs_unlink_sibling(kn);
/* Update timestamps on the parent */
sysfs_unlink_sibling(kn);
/* Update timestamps on the parent */
- ps_iattr = kn->s_parent->s_iattr;
+ ps_iattr = kn->parent->iattr;
if (ps_iattr) {
ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME;
ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME;
}
}
if (ps_iattr) {
ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME;
ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME;
}
}
- kn->s_flags |= SYSFS_FLAG_REMOVED;
+ kn->flags |= SYSFS_FLAG_REMOVED;
kn->u.removed_list = acxt->removed;
acxt->removed = kn;
}
kn->u.removed_list = acxt->removed;
acxt->removed = kn;
}
const unsigned char *name,
const void *ns)
{
const unsigned char *name,
const void *ns)
{
- struct rb_node *node = parent->s_dir.children.rb_node;
+ struct rb_node *node = parent->dir.children.rb_node;
bool has_ns = kernfs_ns_enabled(parent);
unsigned int hash;
bool has_ns = kernfs_ns_enabled(parent);
unsigned int hash;
if (has_ns != (bool)ns) {
WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
if (has_ns != (bool)ns) {
WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
- has_ns ? "required" : "invalid",
- parent->s_name, name);
+ has_ns ? "required" : "invalid", parent->name, name);
return ERR_PTR(-ENOMEM);
}
return ERR_PTR(-ENOMEM);
}
- kn->s_flags &= ~SYSFS_FLAG_REMOVED;
+ kn->flags &= ~SYSFS_FLAG_REMOVED;
if (!kn)
return ERR_PTR(-ENOMEM);
if (!kn)
return ERR_PTR(-ENOMEM);
- kn->s_dir.root = parent->s_dir.root;
- kn->s_ns = ns;
+ kn->dir.root = parent->dir.root;
+ kn->ns = ns;
kn->priv = priv;
/* link in */
kn->priv = priv;
/* link in */
if (sysfs_type(pos) != SYSFS_DIR)
break;
if (sysfs_type(pos) != SYSFS_DIR)
break;
- rbn = rb_first(&pos->s_dir.children);
+ rbn = rb_first(&pos->dir.children);
return NULL;
/* if there's an unvisited sibling, visit its leftmost descendant */
return NULL;
/* if there's an unvisited sibling, visit its leftmost descendant */
- rbn = rb_next(&pos->s_rb);
+ rbn = rb_next(&pos->rb);
if (rbn)
return sysfs_leftmost_descendant(rb_to_kn(rbn));
/* no sibling left, visit parent */
if (rbn)
return sysfs_leftmost_descendant(rb_to_kn(rbn));
/* no sibling left, visit parent */
}
static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
}
static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
- pr_debug("sysfs %s: removing\n", kn->s_name);
+ pr_debug("sysfs %s: removing\n", kn->name);
mutex_lock(&sysfs_mutex);
error = 0;
mutex_lock(&sysfs_mutex);
error = 0;
- if ((kn->s_parent == new_parent) && (kn->s_ns == new_ns) &&
- (strcmp(kn->s_name, new_name) == 0))
+ if ((kn->parent == new_parent) && (kn->ns == new_ns) &&
+ (strcmp(kn->name, new_name) == 0))
goto out; /* nothing to rename */
error = -EEXIST;
goto out; /* nothing to rename */
error = -EEXIST;
goto out;
/* rename kernfs_node */
goto out;
/* rename kernfs_node */
- if (strcmp(kn->s_name, new_name) != 0) {
+ if (strcmp(kn->name, new_name) != 0) {
error = -ENOMEM;
new_name = kstrdup(new_name, GFP_KERNEL);
if (!new_name)
goto out;
error = -ENOMEM;
new_name = kstrdup(new_name, GFP_KERNEL);
if (!new_name)
goto out;
- kfree(kn->s_name);
- kn->s_name = new_name;
+ kfree(kn->name);
+ kn->name = new_name;
*/
sysfs_unlink_sibling(kn);
kernfs_get(new_parent);
*/
sysfs_unlink_sibling(kn);
kernfs_get(new_parent);
- kernfs_put(kn->s_parent);
- kn->s_ns = new_ns;
- kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
- kn->s_parent = new_parent;
+ kernfs_put(kn->parent);
+ kn->ns = new_ns;
+ kn->hash = sysfs_name_hash(kn->name, kn->ns);
+ kn->parent = new_parent;
sysfs_link_sibling(kn);
error = 0;
sysfs_link_sibling(kn);
error = 0;
/* Relationship between s_mode and the DT_xxx types */
static inline unsigned char dt_type(struct kernfs_node *kn)
{
/* Relationship between s_mode and the DT_xxx types */
static inline unsigned char dt_type(struct kernfs_node *kn)
{
- return (kn->s_mode >> 12) & 15;
+ return (kn->mode >> 12) & 15;
}
static int sysfs_dir_release(struct inode *inode, struct file *filp)
}
static int sysfs_dir_release(struct inode *inode, struct file *filp)
struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
{
if (pos) {
struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
{
if (pos) {
- int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
- pos->s_parent == parent &&
- hash == pos->s_hash;
+ int valid = !(pos->flags & SYSFS_FLAG_REMOVED) &&
+ pos->parent == parent && hash == pos->hash;
kernfs_put(pos);
if (!valid)
pos = NULL;
}
if (!pos && (hash > 1) && (hash < INT_MAX)) {
kernfs_put(pos);
if (!valid)
pos = NULL;
}
if (!pos && (hash > 1) && (hash < INT_MAX)) {
- struct rb_node *node = parent->s_dir.children.rb_node;
+ struct rb_node *node = parent->dir.children.rb_node;
while (node) {
pos = rb_to_kn(node);
while (node) {
pos = rb_to_kn(node);
- if (hash < pos->s_hash)
- else if (hash > pos->s_hash)
+ else if (hash > pos->hash)
node = node->rb_right;
else
break;
}
}
/* Skip over entries in the wrong namespace */
node = node->rb_right;
else
break;
}
}
/* Skip over entries in the wrong namespace */
- while (pos && pos->s_ns != ns) {
- struct rb_node *node = rb_next(&pos->s_rb);
+ while (pos && pos->ns != ns) {
+ struct rb_node *node = rb_next(&pos->rb);
if (!node)
pos = NULL;
else
if (!node)
pos = NULL;
else
pos = sysfs_dir_pos(ns, parent, ino, pos);
if (pos)
do {
pos = sysfs_dir_pos(ns, parent, ino, pos);
if (pos)
do {
- struct rb_node *node = rb_next(&pos->s_rb);
+ struct rb_node *node = rb_next(&pos->rb);
if (!node)
pos = NULL;
else
pos = rb_to_kn(node);
if (!node)
pos = NULL;
else
pos = rb_to_kn(node);
- } while (pos && pos->s_ns != ns);
+ } while (pos && pos->ns != ns);
for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos);
pos;
pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos);
pos;
pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
- const char *name = pos->s_name;
+ const char *name = pos->name;
unsigned int type = dt_type(pos);
int len = strlen(name);
unsigned int type = dt_type(pos);
int len = strlen(name);
- ino_t ino = pos->s_ino;
- ctx->pos = pos->s_hash;
file->private_data = pos;
kernfs_get(pos);
file->private_data = pos;
kernfs_get(pos);
* There's one sysfs_open_file for each open file and one sysfs_open_dirent
* for each kernfs_node with one or more open files.
*
* There's one sysfs_open_file for each open file and one sysfs_open_dirent
* for each kernfs_node with one or more open files.
*
- * kernfs_node->s_attr.open points to sysfs_open_dirent. s_attr.open is
+ * kernfs_node->attr.open points to sysfs_open_dirent. attr.open is
* protected by sysfs_open_dirent_lock.
*
* filp->private_data points to seq_file whose ->private points to
* protected by sysfs_open_dirent_lock.
*
* filp->private_data points to seq_file whose ->private points to
*/
static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn)
{
*/
static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn)
{
- if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & SYSFS_FLAG_LOCKDEP)
}
static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
}
static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
{
struct sysfs_open_file *of = sf->private;
{
struct sysfs_open_file *of = sf->private;
- of->event = atomic_read(&of->kn->s_attr.open->event);
+ of->event = atomic_read(&of->kn->attr.open->event);
- return of->kn->s_attr.ops->seq_show(sf, v);
+ return of->kn->attr.ops->seq_show(sf, v);
}
static const struct seq_operations kernfs_seq_ops = {
}
static const struct seq_operations kernfs_seq_ops = {
{
struct sysfs_open_file *of = sysfs_of(file);
{
struct sysfs_open_file *of = sysfs_of(file);
- if (of->kn->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW)
+ if (of->kn->flags & SYSFS_FLAG_HAS_SEQ_SHOW)
return seq_read(file, user_buf, count, ppos);
else
return kernfs_file_direct_read(of, user_buf, count, ppos);
return seq_read(file, user_buf, count, ppos);
else
return kernfs_file_direct_read(of, user_buf, count, ppos);
* without grabbing @of->mutex by testing HAS_MMAP flag. See the
* comment in kernfs_file_open() for more details.
*/
* without grabbing @of->mutex by testing HAS_MMAP flag. See the
* comment in kernfs_file_open() for more details.
*/
- if (!(of->kn->s_flags & SYSFS_FLAG_HAS_MMAP))
+ if (!(of->kn->flags & SYSFS_FLAG_HAS_MMAP))
return -ENODEV;
mutex_lock(&of->mutex);
return -ENODEV;
mutex_lock(&of->mutex);
* @kn: target kernfs_node
* @of: sysfs_open_file for this instance of open
*
* @kn: target kernfs_node
* @of: sysfs_open_file for this instance of open
*
- * If @kn->s_attr.open exists, increment its reference count;
- * otherwise, create one. @of is chained to the files list.
+ * If @kn->attr.open exists, increment its reference count; otherwise,
+ * create one. @of is chained to the files list.
*
* LOCKING:
* Kernel thread context (may sleep).
*
* LOCKING:
* Kernel thread context (may sleep).
mutex_lock(&sysfs_open_file_mutex);
spin_lock_irq(&sysfs_open_dirent_lock);
mutex_lock(&sysfs_open_file_mutex);
spin_lock_irq(&sysfs_open_dirent_lock);
- if (!kn->s_attr.open && new_od) {
- kn->s_attr.open = new_od;
+ if (!kn->attr.open && new_od) {
+ kn->attr.open = new_od;
if (od) {
atomic_inc(&od->refcnt);
list_add_tail(&of->list, &od->files);
if (od) {
atomic_inc(&od->refcnt);
list_add_tail(&of->list, &od->files);
* @kn: target kernfs_nodet
* @of: associated sysfs_open_file
*
* @kn: target kernfs_nodet
* @of: associated sysfs_open_file
*
- * Put @kn->s_attr.open and unlink @of from the files list. If
+ * Put @kn->attr.open and unlink @of from the files list. If
* reference count reaches zero, disassociate and free it.
*
* LOCKING:
* reference count reaches zero, disassociate and free it.
*
* LOCKING:
static void sysfs_put_open_dirent(struct kernfs_node *kn,
struct sysfs_open_file *of)
{
static void sysfs_put_open_dirent(struct kernfs_node *kn,
struct sysfs_open_file *of)
{
- struct sysfs_open_dirent *od = kn->s_attr.open;
+ struct sysfs_open_dirent *od = kn->attr.open;
unsigned long flags;
mutex_lock(&sysfs_open_file_mutex);
unsigned long flags;
mutex_lock(&sysfs_open_file_mutex);
list_del(&of->list);
if (atomic_dec_and_test(&od->refcnt))
list_del(&of->list);
if (atomic_dec_and_test(&od->refcnt))
- kn->s_attr.open = NULL;
struct sysfs_open_dirent *od;
struct sysfs_open_file *of;
struct sysfs_open_dirent *od;
struct sysfs_open_file *of;
- if (!(kn->s_flags & SYSFS_FLAG_HAS_MMAP))
+ if (!(kn->flags & SYSFS_FLAG_HAS_MMAP))
return;
spin_lock_irq(&sysfs_open_dirent_lock);
return;
spin_lock_irq(&sysfs_open_dirent_lock);
if (od)
atomic_inc(&od->refcnt);
spin_unlock_irq(&sysfs_open_dirent_lock);
if (od)
atomic_inc(&od->refcnt);
spin_unlock_irq(&sysfs_open_dirent_lock);
{
struct sysfs_open_file *of = sysfs_of(filp);
struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
{
struct sysfs_open_file *of = sysfs_of(filp);
struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
- struct sysfs_open_dirent *od = kn->s_attr.open;
+ struct sysfs_open_dirent *od = kn->attr.open;
/* need parent for the kobj, grab both */
if (!sysfs_get_active(kn))
/* need parent for the kobj, grab both */
if (!sysfs_get_active(kn))
spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) {
spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) {
if (od) {
atomic_inc(&od->event);
wake_up_interruptible(&od->poll);
if (od) {
atomic_inc(&od->event);
wake_up_interruptible(&od->poll);
if (!kn)
return ERR_PTR(-ENOMEM);
if (!kn)
return ERR_PTR(-ENOMEM);
- kn->s_attr.ops = ops;
- kn->s_attr.size = size;
- kn->s_ns = ns;
+ kn->attr.ops = ops;
+ kn->attr.size = size;
+ kn->ns = ns;
kn->priv = priv;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
if (key) {
lockdep_init_map(&kn->dep_map, "s_active", key, 0);
kn->priv = priv;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
if (key) {
lockdep_init_map(&kn->dep_map, "s_active", key, 0);
- kn->s_flags |= SYSFS_FLAG_LOCKDEP;
+ kn->flags |= SYSFS_FLAG_LOCKDEP;
- * kn->s_attr.ops is accesible only while holding active ref. We
+ * kn->attr.ops is accesible only while holding active ref. We
* need to know whether some ops are implemented outside active
* ref. Cache their existence in flags.
*/
if (ops->seq_show)
* need to know whether some ops are implemented outside active
* ref. Cache their existence in flags.
*/
if (ops->seq_show)
- kn->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW;
+ kn->flags |= SYSFS_FLAG_HAS_SEQ_SHOW;
- kn->s_flags |= SYSFS_FLAG_HAS_MMAP;
+ kn->flags |= SYSFS_FLAG_HAS_MMAP;
sysfs_addrm_start(&acxt);
rc = sysfs_add_one(&acxt, kn, parent);
sysfs_addrm_start(&acxt);
rc = sysfs_add_one(&acxt, kn, parent);
- if (kn->s_iattr)
- return kn->s_iattr;
+ if (kn->iattr)
+ return kn->iattr;
- kn->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL);
- if (!kn->s_iattr)
+ kn->iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL);
+ if (!kn->iattr)
- iattrs = &kn->s_iattr->ia_iattr;
+ iattrs = &kn->iattr->ia_iattr;
/* assign default attributes */
/* assign default attributes */
- iattrs->ia_mode = kn->s_mode;
+ iattrs->ia_mode = kn->mode;
iattrs->ia_uid = GLOBAL_ROOT_UID;
iattrs->ia_gid = GLOBAL_ROOT_GID;
iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME;
iattrs->ia_uid = GLOBAL_ROOT_UID;
iattrs->ia_gid = GLOBAL_ROOT_GID;
iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME;
- simple_xattrs_init(&kn->s_iattr->xattrs);
+ simple_xattrs_init(&kn->iattr->xattrs);
}
static int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
}
static int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
iattrs->ia_ctime = iattr->ia_ctime;
if (ia_valid & ATTR_MODE) {
umode_t mode = iattr->ia_mode;
iattrs->ia_ctime = iattr->ia_ctime;
if (ia_valid & ATTR_MODE) {
umode_t mode = iattr->ia_mode;
- iattrs->ia_mode = kn->s_mode = mode;
+ iattrs->ia_mode = kn->mode = mode;
static void sysfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
{
static void sysfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
{
- struct sysfs_inode_attrs *attrs = kn->s_iattr;
+ struct sysfs_inode_attrs *attrs = kn->iattr;
- inode->i_mode = kn->s_mode;
+ inode->i_mode = kn->mode;
if (attrs) {
/*
* kernfs_node has non-default attributes get them from
if (attrs) {
/*
* kernfs_node has non-default attributes get them from
}
if (sysfs_type(kn) == SYSFS_DIR)
}
if (sysfs_type(kn) == SYSFS_DIR)
- set_nlink(inode, kn->s_dir.subdirs + 2);
+ set_nlink(inode, kn->dir.subdirs + 2);
}
int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
}
int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
inode->i_op = &sysfs_inode_operations;
inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
inode->i_op = &sysfs_inode_operations;
- set_default_inode_attr(inode, kn->s_mode);
+ set_default_inode_attr(inode, kn->mode);
sysfs_refresh_inode(kn, inode);
/* initialize inode according to type */
sysfs_refresh_inode(kn, inode);
/* initialize inode according to type */
inode->i_fop = &sysfs_dir_operations;
break;
case SYSFS_KOBJ_ATTR:
inode->i_fop = &sysfs_dir_operations;
break;
case SYSFS_KOBJ_ATTR:
- inode->i_size = kn->s_attr.size;
+ inode->i_size = kn->attr.size;
inode->i_fop = &kernfs_file_operations;
break;
case SYSFS_KOBJ_LINK:
inode->i_fop = &kernfs_file_operations;
break;
case SYSFS_KOBJ_LINK:
- inode = iget_locked(sb, kn->s_ino);
+ inode = iget_locked(sb, kn->ino);
if (inode && (inode->i_state & I_NEW))
sysfs_init_inode(kn, inode);
if (inode && (inode->i_state & I_NEW))
sysfs_init_inode(kn, inode);
static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
{
/* if parent exists, it's always a dir; otherwise, @sd is a dir */
static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
{
/* if parent exists, it's always a dir; otherwise, @sd is a dir */
- if (kn->s_parent)
- kn = kn->s_parent;
- return kn->s_dir.root;
+ if (kn->parent)
+ kn = kn->parent;
+ return kn->dir.root;
return ERR_PTR(-ENOMEM);
if (kernfs_ns_enabled(parent))
return ERR_PTR(-ENOMEM);
if (kernfs_ns_enabled(parent))
- kn->s_ns = target->s_ns;
- kn->s_symlink.target_kn = target;
+ kn->ns = target->ns;
+ kn->symlink.target_kn = target;
kernfs_get(target); /* ref owned by symlink */
sysfs_addrm_start(&acxt);
kernfs_get(target); /* ref owned by symlink */
sysfs_addrm_start(&acxt);
/* go up to the root, stop at the base */
base = parent;
/* go up to the root, stop at the base */
base = parent;
- while (base->s_parent) {
- kn = target->s_parent;
- while (kn->s_parent && base != kn)
- kn = kn->s_parent;
+ while (base->parent) {
+ kn = target->parent;
+ while (kn->parent && base != kn)
+ kn = kn->parent;
if (base == kn)
break;
strcpy(s, "../");
s += 3;
if (base == kn)
break;
strcpy(s, "../");
s += 3;
}
/* determine end of target string for reverse fillup */
kn = target;
}
/* determine end of target string for reverse fillup */
kn = target;
- while (kn->s_parent && kn != base) {
- len += strlen(kn->s_name) + 1;
- kn = kn->s_parent;
+ while (kn->parent && kn != base) {
+ len += strlen(kn->name) + 1;
+ kn = kn->parent;
/* reverse fillup of target string from target to base */
kn = target;
/* reverse fillup of target string from target to base */
kn = target;
- while (kn->s_parent && kn != base) {
- int slen = strlen(kn->s_name);
+ while (kn->parent && kn != base) {
+ int slen = strlen(kn->name);
- strncpy(s + len, kn->s_name, slen);
+ strncpy(s + len, kn->name, slen);
static int sysfs_getlink(struct dentry *dentry, char *path)
{
struct kernfs_node *kn = dentry->d_fsdata;
static int sysfs_getlink(struct dentry *dentry, char *path)
{
struct kernfs_node *kn = dentry->d_fsdata;
- struct kernfs_node *parent = kn->s_parent;
- struct kernfs_node *target = kn->s_symlink.target_kn;
+ struct kernfs_node *parent = kn->parent;
+ struct kernfs_node *target = kn->symlink.target_kn;
int error;
mutex_lock(&sysfs_mutex);
int error;
mutex_lock(&sysfs_mutex);
*/
static char *sysfs_pathname(struct kernfs_node *kn, char *path)
{
*/
static char *sysfs_pathname(struct kernfs_node *kn, char *path)
{
- if (kn->s_parent) {
- sysfs_pathname(kn->s_parent, path);
+ if (kn->parent) {
+ sysfs_pathname(kn->parent, path);
strlcat(path, "/", PATH_MAX);
}
strlcat(path, "/", PATH_MAX);
}
- strlcat(path, kn->s_name, PATH_MAX);
+ strlcat(path, kn->name, PATH_MAX);
int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
const void *new_ns)
{
int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
const void *new_ns)
{
- struct kernfs_node *parent = kobj->sd->s_parent;
+ struct kernfs_node *parent = kobj->sd->parent;
return kernfs_rename_ns(kobj->sd, parent, new_name, new_ns);
}
return kernfs_rename_ns(kobj->sd, parent, new_name, new_ns);
}
struct kernfs_node *kn = kobj->sd;
struct kernfs_node *new_parent;
struct kernfs_node *kn = kobj->sd;
struct kernfs_node *new_parent;
new_parent = new_parent_kobj && new_parent_kobj->sd ?
new_parent_kobj->sd : sysfs_root_kn;
new_parent = new_parent_kobj && new_parent_kobj->sd ?
new_parent_kobj->sd : sysfs_root_kn;
- return kernfs_rename_ns(kn, new_parent, kn->s_name, new_ns);
+ return kernfs_rename_ns(kn, new_parent, kn->name, new_ns);
*/
static const struct sysfs_ops *sysfs_file_ops(struct kernfs_node *kn)
{
*/
static const struct sysfs_ops *sysfs_file_ops(struct kernfs_node *kn)
{
- struct kobject *kobj = kn->s_parent->priv;
+ struct kobject *kobj = kn->parent->priv;
- if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & SYSFS_FLAG_LOCKDEP)
lockdep_assert_held(kn);
return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
}
lockdep_assert_held(kn);
return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
}
static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
{
struct sysfs_open_file *of = sf->private;
static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
{
struct sysfs_open_file *of = sf->private;
- struct kobject *kobj = of->kn->s_parent->priv;
+ struct kobject *kobj = of->kn->parent->priv;
const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
ssize_t count;
char *buf;
const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
ssize_t count;
char *buf;
size_t count, loff_t pos)
{
struct bin_attribute *battr = of->kn->priv;
size_t count, loff_t pos)
{
struct bin_attribute *battr = of->kn->priv;
- struct kobject *kobj = of->kn->s_parent->priv;
+ struct kobject *kobj = of->kn->parent->priv;
loff_t size = file_inode(of->file)->i_size;
if (!count)
loff_t size = file_inode(of->file)->i_size;
if (!count)
size_t count, loff_t pos)
{
const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
size_t count, loff_t pos)
{
const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
- struct kobject *kobj = of->kn->s_parent->priv;
+ struct kobject *kobj = of->kn->parent->priv;
size_t count, loff_t pos)
{
struct bin_attribute *battr = of->kn->priv;
size_t count, loff_t pos)
{
struct bin_attribute *battr = of->kn->priv;
- struct kobject *kobj = of->kn->s_parent->priv;
+ struct kobject *kobj = of->kn->parent->priv;
loff_t size = file_inode(of->file)->i_size;
if (size) {
loff_t size = file_inode(of->file)->i_size;
if (size) {
struct vm_area_struct *vma)
{
struct bin_attribute *battr = of->kn->priv;
struct vm_area_struct *vma)
{
struct bin_attribute *battr = of->kn->priv;
- struct kobject *kobj = of->kn->s_parent->priv;
+ struct kobject *kobj = of->kn->parent->priv;
return battr->mmap(of->file, kobj, battr, vma);
}
return battr->mmap(of->file, kobj, battr, vma);
}
- newattrs.ia_mode = (mode & S_IALLUGO) | (kn->s_mode & ~S_IALLUGO);
+ newattrs.ia_mode = (mode & S_IALLUGO) | (kn->mode & ~S_IALLUGO);
newattrs.ia_valid = ATTR_MODE;
rc = kernfs_setattr(kn, &newattrs);
newattrs.ia_valid = ATTR_MODE;
rc = kernfs_setattr(kn, &newattrs);
*/
spin_lock(&sysfs_symlink_target_lock);
if (targ->sd && kernfs_ns_enabled(kobj->sd))
*/
spin_lock(&sysfs_symlink_target_lock);
if (targ->sd && kernfs_ns_enabled(kobj->sd))
spin_unlock(&sysfs_symlink_target_lock);
kernfs_remove_by_name_ns(kobj->sd, name, ns);
}
spin_unlock(&sysfs_symlink_target_lock);
kernfs_remove_by_name_ns(kobj->sd, name, ns);
}
parent = kobj->sd;
if (targ->sd)
parent = kobj->sd;
if (targ->sd)
- old_ns = targ->sd->s_ns;
result = -ENOENT;
kn = kernfs_find_and_get_ns(parent, old, old_ns);
result = -ENOENT;
kn = kernfs_find_and_get_ns(parent, old, old_ns);
result = -EINVAL;
if (sysfs_type(kn) != SYSFS_KOBJ_LINK)
goto out;
result = -EINVAL;
if (sysfs_type(kn) != SYSFS_KOBJ_LINK)
goto out;
- if (kn->s_symlink.target_kn->priv != targ)
+ if (kn->symlink.target_kn->priv != targ)
goto out;
result = kernfs_rename_ns(kn, parent, new, new_ns);
goto out;
result = kernfs_rename_ns(kn, parent, new, new_ns);
/* type-specific structures for kernfs_node union members */
struct kernfs_elem_dir {
unsigned long subdirs;
/* type-specific structures for kernfs_node union members */
struct kernfs_elem_dir {
unsigned long subdirs;
- /* children rbtree starts here and goes through kn->s_rb */
+ /* children rbtree starts here and goes through kn->rb */
struct rb_root children;
/*
struct rb_root children;
/*
* active reference.
*/
struct kernfs_node {
* active reference.
*/
struct kernfs_node {
- atomic_t s_count;
- atomic_t s_active;
+ atomic_t count;
+ atomic_t active;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
/* the following two fields are published */
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
/* the following two fields are published */
- struct kernfs_node *s_parent;
- const char *s_name;
+ struct kernfs_node *parent;
+ const char *name;
union {
struct completion *completion;
struct kernfs_node *removed_list;
} u;
union {
struct completion *completion;
struct kernfs_node *removed_list;
} u;
- const void *s_ns; /* namespace tag */
- unsigned int s_hash; /* ns + name hash */
+ const void *ns; /* namespace tag */
+ unsigned int hash; /* ns + name hash */
- struct kernfs_elem_dir s_dir;
- struct kernfs_elem_symlink s_symlink;
- struct kernfs_elem_attr s_attr;
+ struct kernfs_elem_dir dir;
+ struct kernfs_elem_symlink symlink;
+ struct kernfs_elem_attr attr;
- unsigned short s_flags;
- umode_t s_mode;
- unsigned int s_ino;
- struct sysfs_inode_attrs *s_iattr;
+ unsigned short flags;
+ umode_t mode;
+ unsigned int ino;
+ struct sysfs_inode_attrs *iattr;
static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
{
static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
{
- return kn->s_flags & SYSFS_TYPE_MASK;
+ return kn->flags & SYSFS_TYPE_MASK;
static inline void kernfs_enable_ns(struct kernfs_node *kn)
{
WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
static inline void kernfs_enable_ns(struct kernfs_node *kn)
{
WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
- WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->s_dir.children));
- kn->s_flags |= SYSFS_FLAG_NS;
+ WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children));
+ kn->flags |= SYSFS_FLAG_NS;
*/
static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
{
*/
static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
{
- return kn->s_flags & SYSFS_FLAG_NS;
+ return kn->flags & SYSFS_FLAG_NS;
}
struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
}
struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,