Commit 324a56e1 authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman

kernfs: s/sysfs_dirent/kernfs_node/ and rename its friends accordingly

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.

This patch performs the following renames.

* s/sysfs_elem_dir/kernfs_elem_dir/
* s/sysfs_elem_symlink/kernfs_elem_symlink/
* s/sysfs_elem_attr/kernfs_elem_file/
* s/sysfs_dirent/kernfs_node/
* s/sd/kn/ in kernfs proper
* s/parent_sd/parent/
* s/target_sd/target/
* s/dir_sd/parent/
* s/to_sysfs_dirent()/rb_to_kn()/
* misc renames of local vars when they conflict with the above

Because md, mic and gpio dig into sysfs details, this patch ends up
modifying them.  All are sysfs_dirent renames and trivial.  While we
can avoid these by introducing a dummy wrapping struct sysfs_dirent
around kernfs_node, given the limited usage outside kernfs and sysfs
proper, I don't think such workaround is called for.

This patch is strictly rename only and doesn't introduce any
functional difference.

- mic / gpio renames were missing.  Spotted by kbuild test robot.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Neil Brown <neilb@suse.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
Cc: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a8b1c019
...@@ -393,7 +393,7 @@ static const DEVICE_ATTR(value, 0644, ...@@ -393,7 +393,7 @@ static const DEVICE_ATTR(value, 0644,
static irqreturn_t gpio_sysfs_irq(int irq, void *priv) static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
{ {
struct sysfs_dirent *value_sd = priv; struct kernfs_node *value_sd = priv;
sysfs_notify_dirent(value_sd); sysfs_notify_dirent(value_sd);
return IRQ_HANDLED; return IRQ_HANDLED;
...@@ -402,7 +402,7 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv) ...@@ -402,7 +402,7 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
unsigned long gpio_flags) unsigned long gpio_flags)
{ {
struct sysfs_dirent *value_sd; struct kernfs_node *value_sd;
unsigned long irq_flags; unsigned long irq_flags;
int ret, irq, id; int ret, irq, id;
......
...@@ -1635,7 +1635,7 @@ int bitmap_create(struct mddev *mddev) ...@@ -1635,7 +1635,7 @@ int bitmap_create(struct mddev *mddev)
sector_t blocks = mddev->resync_max_sectors; sector_t blocks = mddev->resync_max_sectors;
struct file *file = mddev->bitmap_info.file; struct file *file = mddev->bitmap_info.file;
int err; int err;
struct sysfs_dirent *bm = NULL; struct kernfs_node *bm = NULL;
BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
......
...@@ -225,7 +225,7 @@ struct bitmap { ...@@ -225,7 +225,7 @@ struct bitmap {
wait_queue_head_t overflow_wait; wait_queue_head_t overflow_wait;
wait_queue_head_t behind_wait; wait_queue_head_t behind_wait;
struct sysfs_dirent *sysfs_can_clear; struct kernfs_node *sysfs_can_clear;
}; };
/* the bitmap API */ /* the bitmap API */
......
...@@ -106,7 +106,7 @@ struct md_rdev { ...@@ -106,7 +106,7 @@ struct md_rdev {
*/ */
struct work_struct del_work; /* used for delayed sysfs removal */ struct work_struct del_work; /* used for delayed sysfs removal */
struct sysfs_dirent *sysfs_state; /* handle for 'state' struct kernfs_node *sysfs_state; /* handle for 'state'
* sysfs entry */ * sysfs entry */
struct badblocks { struct badblocks {
...@@ -376,10 +376,10 @@ struct mddev { ...@@ -376,10 +376,10 @@ struct mddev {
sector_t resync_max; /* resync should pause sector_t resync_max; /* resync should pause
* when it gets here */ * when it gets here */
struct sysfs_dirent *sysfs_state; /* handle for 'array_state' struct kernfs_node *sysfs_state; /* handle for 'array_state'
* file in sysfs. * file in sysfs.
*/ */
struct sysfs_dirent *sysfs_action; /* handle for 'sync_action' */ struct kernfs_node *sysfs_action; /* handle for 'sync_action' */
struct work_struct del_work; /* used for delayed sysfs removal */ struct work_struct del_work; /* used for delayed sysfs removal */
...@@ -498,13 +498,13 @@ struct md_sysfs_entry { ...@@ -498,13 +498,13 @@ struct md_sysfs_entry {
}; };
extern struct attribute_group md_bitmap_group; extern struct attribute_group md_bitmap_group;
static inline struct sysfs_dirent *sysfs_get_dirent_safe(struct sysfs_dirent *sd, char *name) static inline struct kernfs_node *sysfs_get_dirent_safe(struct kernfs_node *sd, char *name)
{ {
if (sd) if (sd)
return sysfs_get_dirent(sd, name); return sysfs_get_dirent(sd, name);
return sd; return sd;
} }
static inline void sysfs_notify_dirent_safe(struct sysfs_dirent *sd) static inline void sysfs_notify_dirent_safe(struct kernfs_node *sd)
{ {
if (sd) if (sd)
sysfs_notify_dirent(sd); sysfs_notify_dirent(sd);
......
...@@ -112,7 +112,7 @@ struct mic_device { ...@@ -112,7 +112,7 @@ struct mic_device {
struct work_struct shutdown_work; struct work_struct shutdown_work;
u8 state; u8 state;
u8 shutdown_status; u8 shutdown_status;
struct sysfs_dirent *state_sysfs; struct kernfs_node *state_sysfs;
struct completion reset_wait; struct completion reset_wait;
void *log_buf_addr; void *log_buf_addr;
int *log_buf_len; int *log_buf_len;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
DEFINE_MUTEX(sysfs_mutex); DEFINE_MUTEX(sysfs_mutex);
#define to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb) #define rb_to_kn(X) rb_entry((X), struct kernfs_node, s_rb)
/** /**
* sysfs_name_hash * sysfs_name_hash
...@@ -45,28 +45,28 @@ static unsigned int sysfs_name_hash(const char *name, const void *ns) ...@@ -45,28 +45,28 @@ static unsigned int sysfs_name_hash(const char *name, const void *ns)
} }
static int sysfs_name_compare(unsigned int hash, const char *name, static int sysfs_name_compare(unsigned int hash, const char *name,
const void *ns, const struct sysfs_dirent *sd) const void *ns, const struct kernfs_node *kn)
{ {
if (hash != sd->s_hash) if (hash != kn->s_hash)
return hash - sd->s_hash; return hash - kn->s_hash;
if (ns != sd->s_ns) if (ns != kn->s_ns)
return ns - sd->s_ns; return ns - kn->s_ns;
return strcmp(name, sd->s_name); return strcmp(name, kn->s_name);
} }
static int sysfs_sd_compare(const struct sysfs_dirent *left, static int sysfs_sd_compare(const struct kernfs_node *left,
const struct sysfs_dirent *right) const struct kernfs_node *right)
{ {
return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns, return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns,
right); right);
} }
/** /**
* sysfs_link_sibling - link sysfs_dirent into sibling rbtree * sysfs_link_sibling - link kernfs_node into sibling rbtree
* @sd: sysfs_dirent of interest * @kn: kernfs_node of interest
* *
* Link @sd into its sibling rbtree which starts from * Link @kn into its sibling rbtree which starts from
* sd->s_parent->s_dir.children. * @kn->s_parent->s_dir.children.
* *
* Locking: * Locking:
* mutex_lock(sysfs_mutex) * mutex_lock(sysfs_mutex)
...@@ -74,21 +74,21 @@ static int sysfs_sd_compare(const struct sysfs_dirent *left, ...@@ -74,21 +74,21 @@ static int sysfs_sd_compare(const struct sysfs_dirent *left,
* RETURNS: * RETURNS:
* 0 on susccess -EEXIST on failure. * 0 on susccess -EEXIST on failure.
*/ */
static int sysfs_link_sibling(struct sysfs_dirent *sd) static int sysfs_link_sibling(struct kernfs_node *kn)
{ {
struct rb_node **node = &sd->s_parent->s_dir.children.rb_node; struct rb_node **node = &kn->s_parent->s_dir.children.rb_node;
struct rb_node *parent = NULL; struct rb_node *parent = NULL;
if (sysfs_type(sd) == SYSFS_DIR) if (sysfs_type(kn) == SYSFS_DIR)
sd->s_parent->s_dir.subdirs++; kn->s_parent->s_dir.subdirs++;
while (*node) { while (*node) {
struct sysfs_dirent *pos; struct kernfs_node *pos;
int result; int result;
pos = to_sysfs_dirent(*node); pos = rb_to_kn(*node);
parent = *node; parent = *node;
result = sysfs_sd_compare(sd, pos); result = sysfs_sd_compare(kn, pos);
if (result < 0) if (result < 0)
node = &pos->s_rb.rb_left; node = &pos->s_rb.rb_left;
else if (result > 0) else if (result > 0)
...@@ -97,168 +97,169 @@ static int sysfs_link_sibling(struct sysfs_dirent *sd) ...@@ -97,168 +97,169 @@ static int sysfs_link_sibling(struct sysfs_dirent *sd)
return -EEXIST; return -EEXIST;
} }
/* add new node and rebalance the tree */ /* add new node and rebalance the tree */
rb_link_node(&sd->s_rb, parent, node); rb_link_node(&kn->s_rb, parent, node);
rb_insert_color(&sd->s_rb, &sd->s_parent->s_dir.children); rb_insert_color(&kn->s_rb, &kn->s_parent->s_dir.children);
return 0; return 0;
} }
/** /**
* sysfs_unlink_sibling - unlink sysfs_dirent from sibling rbtree * sysfs_unlink_sibling - unlink kernfs_node from sibling rbtree
* @sd: sysfs_dirent of interest * @kn: kernfs_node of interest
* *
* Unlink @sd from its sibling rbtree which starts from * Unlink @kn from its sibling rbtree which starts from
* sd->s_parent->s_dir.children. * kn->s_parent->s_dir.children.
* *
* Locking: * Locking:
* mutex_lock(sysfs_mutex) * mutex_lock(sysfs_mutex)
*/ */
static void sysfs_unlink_sibling(struct sysfs_dirent *sd) static void sysfs_unlink_sibling(struct kernfs_node *kn)
{ {
if (sysfs_type(sd) == SYSFS_DIR) if (sysfs_type(kn) == SYSFS_DIR)
sd->s_parent->s_dir.subdirs--; kn->s_parent->s_dir.subdirs--;
rb_erase(&sd->s_rb, &sd->s_parent->s_dir.children); rb_erase(&kn->s_rb, &kn->s_parent->s_dir.children);
} }
/** /**
* sysfs_get_active - get an active reference to sysfs_dirent * sysfs_get_active - get an active reference to kernfs_node
* @sd: sysfs_dirent to get an active reference to * @kn: kernfs_node to get an active reference to
* *
* Get an active reference of @sd. This function is noop if @sd * Get an active reference of @kn. This function is noop if @kn
* is NULL. * is NULL.
* *
* RETURNS: * RETURNS:
* Pointer to @sd on success, NULL on failure. * Pointer to @kn on success, NULL on failure.
*/ */
struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd) struct kernfs_node *sysfs_get_active(struct kernfs_node *kn)
{ {
if (unlikely(!sd)) if (unlikely(!kn))
return NULL; return NULL;
if (!atomic_inc_unless_negative(&sd->s_active)) if (!atomic_inc_unless_negative(&kn->s_active))
return NULL; return NULL;
if (sd->s_flags & SYSFS_FLAG_LOCKDEP) if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_); rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_);
return sd; return kn;
} }
/** /**
* sysfs_put_active - put an active reference to sysfs_dirent * sysfs_put_active - put an active reference to kernfs_node
* @sd: sysfs_dirent to put an active reference to * @kn: kernfs_node to put an active reference to
* *
* Put an active reference to @sd. This function is noop if @sd * Put an active reference to @kn. This function is noop if @kn
* is NULL. * is NULL.
*/ */
void sysfs_put_active(struct sysfs_dirent *sd) void sysfs_put_active(struct kernfs_node *kn)
{ {
int v; int v;
if (unlikely(!sd)) if (unlikely(!kn))
return; return;
if (sd->s_flags & SYSFS_FLAG_LOCKDEP) if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
rwsem_release(&sd->dep_map, 1, _RET_IP_); rwsem_release(&kn->dep_map, 1, _RET_IP_);
v = atomic_dec_return(&sd->s_active); v = atomic_dec_return(&kn->s_active);
if (likely(v != SD_DEACTIVATED_BIAS)) if (likely(v != SD_DEACTIVATED_BIAS))
return; return;
/* atomic_dec_return() is a mb(), we'll always see the updated /*
* sd->u.completion. * atomic_dec_return() is a mb(), we'll always see the updated
* kn->u.completion.
*/ */
complete(sd->u.completion); complete(kn->u.completion);
} }
/** /**
* sysfs_deactivate - deactivate sysfs_dirent * sysfs_deactivate - deactivate kernfs_node
* @sd: sysfs_dirent to deactivate * @kn: kernfs_node to deactivate
* *
* Deny new active references and drain existing ones. * Deny new active references and drain existing ones.
*/ */
static void sysfs_deactivate(struct sysfs_dirent *sd) static void sysfs_deactivate(struct kernfs_node *kn)
{ {
DECLARE_COMPLETION_ONSTACK(wait); DECLARE_COMPLETION_ONSTACK(wait);
int v; int v;
BUG_ON(!(sd->s_flags & SYSFS_FLAG_REMOVED)); BUG_ON(!(kn->s_flags & SYSFS_FLAG_REMOVED));
if (!(sysfs_type(sd) & SYSFS_ACTIVE_REF)) if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF))
return; return;
sd->u.completion = (void *)&wait; kn->u.completion = (void *)&wait;
rwsem_acquire(&sd->dep_map, 0, 0, _RET_IP_); rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
/* atomic_add_return() is a mb(), put_active() will always see /* atomic_add_return() is a mb(), put_active() will always see
* the updated sd->u.completion. * the updated kn->u.completion.
*/ */
v = atomic_add_return(SD_DEACTIVATED_BIAS, &sd->s_active); v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->s_active);
if (v != SD_DEACTIVATED_BIAS) { if (v != SD_DEACTIVATED_BIAS) {
lock_contended(&sd->dep_map, _RET_IP_); lock_contended(&kn->dep_map, _RET_IP_);
wait_for_completion(&wait); wait_for_completion(&wait);
} }
lock_acquired(&sd->dep_map, _RET_IP_); lock_acquired(&kn->dep_map, _RET_IP_);
rwsem_release(&sd->dep_map, 1, _RET_IP_); rwsem_release(&kn->dep_map, 1, _RET_IP_);
} }
/** /**
* kernfs_get - get a reference count on a sysfs_dirent * kernfs_get - get a reference count on a kernfs_node
* @sd: the target sysfs_dirent * @kn: the target kernfs_node
*/ */
void kernfs_get(struct sysfs_dirent *sd) void kernfs_get(struct kernfs_node *kn)
{ {
if (sd) { if (kn) {
WARN_ON(!atomic_read(&sd->s_count)); WARN_ON(!atomic_read(&kn->s_count));
atomic_inc(&sd->s_count); atomic_inc(&kn->s_count);
} }
} }
EXPORT_SYMBOL_GPL(kernfs_get); EXPORT_SYMBOL_GPL(kernfs_get);
/** /**
* kernfs_put - put a reference count on a sysfs_dirent * kernfs_put - put a reference count on a kernfs_node
* @sd: the target sysfs_dirent * @kn: the target kernfs_node
* *
* Put a reference count of @sd and destroy it if it reached zero. * Put a reference count of @kn and destroy it if it reached zero.
*/ */
void kernfs_put(struct sysfs_dirent *sd) void kernfs_put(struct kernfs_node *kn)
{ {
struct sysfs_dirent *parent_sd; struct kernfs_node *parent;
struct kernfs_root *root; struct kernfs_root *root;
if (!sd || !atomic_dec_and_test(&sd->s_count)) if (!kn || !atomic_dec_and_test(&kn->s_count))
return; return;
root = kernfs_root(sd); root = kernfs_root(kn);
repeat: repeat:
/* Moving/renaming is always done while holding reference. /* Moving/renaming is always done while holding reference.
* sd->s_parent won't change beneath us. * kn->s_parent won't change beneath us.
*/ */
parent_sd = sd->s_parent; parent = kn->s_parent;
WARN(!(sd->s_flags & SYSFS_FLAG_REMOVED), WARN(!(kn->s_flags & SYSFS_FLAG_REMOVED),
"sysfs: free using entry: %s/%s\n", "sysfs: free using entry: %s/%s\n",
parent_sd ? parent_sd->s_name : "", sd->s_name); parent ? parent->s_name : "", kn->s_name);
if (sysfs_type(sd) == SYSFS_KOBJ_LINK) if (sysfs_type(kn) == SYSFS_KOBJ_LINK)
kernfs_put(sd->s_symlink.target_sd); kernfs_put(kn->s_symlink.target_kn);
if (sysfs_type(sd) & SYSFS_COPY_NAME) if (sysfs_type(kn) & SYSFS_COPY_NAME)
kfree(sd->s_name); kfree(kn->s_name);
if (sd->s_iattr) { if (kn->s_iattr) {
if (sd->s_iattr->ia_secdata) if (kn->s_iattr->ia_secdata)
security_release_secctx(sd->s_iattr->ia_secdata, security_release_secctx(kn->s_iattr->ia_secdata,
sd->s_iattr->ia_secdata_len); kn->s_iattr->ia_secdata_len);
simple_xattrs_free(&sd->s_iattr->xattrs); simple_xattrs_free(&kn->s_iattr->xattrs);
} }
kfree(sd->s_iattr); kfree(kn->s_iattr);
ida_simple_remove(&root->ino_ida, sd->s_ino); ida_simple_remove(&root->ino_ida, kn->s_ino);
kmem_cache_free(sysfs_dir_cachep, sd); kmem_cache_free(sysfs_dir_cachep, kn);
sd = parent_sd; kn = parent;
if (sd) { if (kn) {
if (atomic_dec_and_test(&sd->s_count)) if (atomic_dec_and_test(&kn->s_count))
goto repeat; goto repeat;
} else { } else {
/* just released the root sd, free @root too */ /* just released the root kn, free @root too */
ida_destroy(&root->ino_ida); ida_destroy(&root->ino_ida);
kfree(root); kfree(root);
} }
...@@ -267,35 +268,35 @@ EXPORT_SYMBOL_GPL(kernfs_put); ...@@ -267,35 +268,35 @@ EXPORT_SYMBOL_GPL(kernfs_put);
static int sysfs_dentry_delete(const struct dentry *dentry) static int sysfs_dentry_delete(const struct dentry *dentry)
{ {
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
return !(sd && !(sd->s_flags & SYSFS_FLAG_REMOVED)); return !(kn && !(kn->s_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)
{ {
struct sysfs_dirent *sd; struct kernfs_node *kn;
if (flags & LOOKUP_RCU) if (flags & LOOKUP_RCU)
return -ECHILD; return -ECHILD;
sd = dentry->d_fsdata; kn = dentry->d_fsdata;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
/* The sysfs dirent has been deleted */ /* The sysfs dirent has been deleted */
if (sd->s_flags & SYSFS_FLAG_REMOVED) if (kn->s_flags & SYSFS_FLAG_REMOVED)
goto out_bad; goto out_bad;
/* The sysfs dirent has been moved? */ /* The sysfs dirent has been moved? */
if (dentry->d_parent->d_fsdata != sd->s_parent) if (dentry->d_parent->d_fsdata != kn->s_parent)
goto out_bad; goto out_bad;
/* The sysfs dirent has been renamed */ /* The sysfs dirent has been renamed */
if (strcmp(dentry->d_name.name, sd->s_name) != 0) if (strcmp(dentry->d_name.name, kn->s_name) != 0)
goto out_bad; goto out_bad;
/* The sysfs dirent has been moved to a different namespace */ /* The sysfs dirent has been moved to a different namespace */
if (sd->s_parent && kernfs_ns_enabled(sd->s_parent) && if (kn->s_parent && kernfs_ns_enabled(kn->s_parent) &&
sysfs_info(dentry->d_sb)->ns != sd->s_ns) sysfs_info(dentry->d_sb)->ns != kn->s_ns)
goto out_bad; goto out_bad;
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
...@@ -335,11 +336,11 @@ const struct dentry_operations sysfs_dentry_ops = { ...@@ -335,11 +336,11 @@ const struct dentry_operations sysfs_dentry_ops = {
.d_release = sysfs_dentry_release, .d_release = sysfs_dentry_release,
}; };
struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
const char *name, umode_t mode, int type) const char *name, umode_t mode, int type)
{ {
char *dup_name = NULL; char *dup_name = NULL;
struct sysfs_dirent *sd; struct kernfs_node *kn;
int ret; int ret;
if (type & SYSFS_COPY_NAME) { if (type & SYSFS_COPY_NAME) {
...@@ -348,38 +349,38 @@ struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, ...@@ -348,38 +349,38 @@ struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root,
return NULL; return NULL;
} }
sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); kn = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL);
if (!sd) if (!kn)
goto err_out1; goto err_out1;
ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL);
if (ret < 0) if (ret < 0)
goto err_out2; goto err_out2;
sd->s_ino = ret; kn->s_ino = ret;
atomic_set(&sd->s_count, 1); atomic_set(&kn->s_count, 1);
atomic_set(&sd->s_active, 0); atomic_set(&kn->s_active, 0);
sd->s_name = name; kn->s_name = name;
sd->s_mode = mode; kn->s_mode = mode;
sd->s_flags = type | SYSFS_FLAG_REMOVED; kn->s_flags = type | SYSFS_FLAG_REMOVED;
return sd; return kn;
err_out2: err_out2:
kmem_cache_free(sysfs_dir_cachep, sd); kmem_cache_free(sysfs_dir_cachep, kn);
err_out1: err_out1:
kfree(dup_name); kfree(dup_name);
return NULL; return NULL;
} }
/** /**
* sysfs_addrm_start - prepare for sysfs_dirent add/remove * sysfs_addrm_start - prepare for kernfs_node add/remove
* @acxt: pointer to sysfs_addrm_cxt to be used * @acxt: pointer to sysfs_addrm_cxt to be used
* *
* This function is called when the caller is about to add or remove * This function is called when the caller is about to add or remove
* sysfs_dirent. This function acquires sysfs_mutex. @acxt is used * kernfs_node. This function acquires sysfs_mutex. @acxt is used to
* to keep and pass context to other addrm functions. * keep and pass context to other addrm functions.
* *
* LOCKING: * LOCKING:
* Kernel thread context (may sleep). sysfs_mutex is locked on * Kernel thread context (may sleep). sysfs_mutex is locked on
...@@ -394,13 +395,13 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt) ...@@ -394,13 +395,13 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
} }
/** /**
* sysfs_add_one - add sysfs_dirent to parent without warning * sysfs_add_one - add kernfs_node to parent without warning
* @acxt: addrm context to use * @acxt: addrm context to use
* @sd: sysfs_dirent to be added * @kn: kernfs_node to be added
* @parent_sd: the parent sysfs_dirent to add @sd to * @parent: the parent kernfs_node to add @kn to
* *
* Get @parent_sd and set @sd->s_parent to it and increment nlink of * Get @parent and set @kn->s_parent to it and increment nlink of
* the parent inode if @sd is a directory and link into the children * the parent inode if @kn is a directory and link into the children
* list of the parent. * list of the parent.
* *
* This function should be called between calls to * This function should be called between calls to
...@@ -414,51 +415,51 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt) ...@@ -414,51 +415,51 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
* 0 on success, -EEXIST if entry with the given name already * 0 on success, -EEXIST if entry with the given name already
* exists. * exists.
*/ */
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
struct sysfs_dirent *parent_sd) struct kernfs_node *parent)
{ {
bool has_ns = kernfs_ns_enabled(parent_sd); bool has_ns = kernfs_ns_enabled(parent);
struct sysfs_inode_attrs *ps_iattr; struct sysfs_inode_attrs *ps_iattr;
int ret; int ret;
if (has_ns != (bool)sd->s_ns) { if (has_ns != (bool)kn->s_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", has_ns ? "required" : "invalid",
parent_sd->s_name, sd->s_name); parent->s_name, kn->s_name);
return -EINVAL; return -EINVAL;
} }
if (sysfs_type(parent_sd) != SYSFS_DIR) if (sysfs_type(parent) != SYSFS_DIR)
return -EINVAL; return -EINVAL;
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
sd->s_parent = parent_sd; kn->s_parent = parent;
kernfs_get(parent_sd); kernfs_get(parent);
ret = sysfs_link_sibling(sd); ret = sysfs_link_sibling(kn);
if (ret) if (ret)
return ret; return ret;
/* Update timestamps on the parent */ /* Update timestamps on the parent */
ps_iattr = parent_sd->s_iattr; ps_iattr = parent->s_iattr;
if (ps_iattr) { if (ps_iattr) {
struct iattr *ps_iattrs = &ps_iattr->ia_iattr; struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
} }
/* Mark the entry added into directory tree */ /* Mark the entry added into directory tree */
sd->s_flags &= ~SYSFS_FLAG_REMOVED; kn->s_flags &= ~SYSFS_FLAG_REMOVED;
return 0; return 0;
} }
/** /**
* sysfs_remove_one - remove sysfs_dirent from parent * sysfs_remove_one - remove kernfs_node from parent
* @acxt: addrm context to use * @acxt: addrm context to use
* @sd: sysfs_dirent to be removed * @kn: kernfs_node to be removed
* *
* Mark @sd removed and drop nlink of parent inode if @sd is a * Mark @kn removed and drop nlink of parent inode if @kn is a
* directory. @sd is unlinked from the children list. * directory. @kn is unlinked from the children list.
* *
* This function should be called between calls to * This function should be called between calls to
* sysfs_addrm_start() and sysfs_addrm_finish() and should be * sysfs_addrm_start() and sysfs_addrm_finish() and should be
...@@ -468,7 +469,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, ...@@ -468,7 +469,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
* Determined by sysfs_addrm_start(). * Determined by sysfs_addrm_start().
*/ */
static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
struct sysfs_dirent *sd) struct kernfs_node *kn)
{ {
struct sysfs_inode_attrs *ps_iattr; struct sysfs_inode_attrs *ps_iattr;
...@@ -476,31 +477,31 @@ static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, ...@@ -476,31 +477,31 @@ static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
* Removal can be called multiple times on the same node. Only the * Removal can be called multiple times on the same node. Only the
* first invocation is effective and puts the base ref. * first invocation is effective and puts the base ref.
*/ */
if (sd->s_flags & SYSFS_FLAG_REMOVED) if (kn->s_flags & SYSFS_FLAG_REMOVED)
return; return;
if (sd->s_parent) { if (kn->s_parent) {
sysfs_unlink_sibling(sd); sysfs_unlink_sibling(kn);
/* Update timestamps on the parent */ /* Update timestamps on the parent */
ps_iattr = sd->s_parent->s_iattr; ps_iattr = kn->s_parent->s_iattr;
if (ps_iattr) { if (ps_iattr) {
ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME;
ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME;
} }
} }
sd->s_flags |= SYSFS_FLAG_REMOVED; kn->s_flags |= SYSFS_FLAG_REMOVED;
sd->u.removed_list = acxt->removed; kn->u.removed_list = acxt->removed;
acxt->removed = sd; acxt->removed = kn;
} }
/** /**
* sysfs_addrm_finish - finish up sysfs_dirent add/remove * sysfs_addrm_finish - finish up kernfs_node add/remove
* @acxt: addrm context to finish up * @acxt: addrm context to finish up
* *
* Finish up sysfs_dirent add/remove. Resources acquired by * Finish up kernfs_node add/remove. Resources acquired by
* sysfs_addrm_start() are released and removed sysfs_dirents are * sysfs_addrm_start() are released and removed kernfs_nodes are
* cleaned up. * cleaned up.
* *
* LOCKING: * LOCKING:
...@@ -512,30 +513,30 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt) ...@@ -512,30 +513,30 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
/* release resources acquired by sysfs_addrm_start() */ /* release resources acquired by sysfs_addrm_start() */
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
/* kill removed sysfs_dirents */ /* kill removed kernfs_nodes */
while (acxt->removed) { while (acxt->removed) {
struct sysfs_dirent *sd = acxt->removed; struct kernfs_node *kn = acxt->removed;
acxt->removed = sd->u.removed_list; acxt->removed = kn->u.removed_list;
sysfs_deactivate(sd); sysfs_deactivate(kn);
sysfs_unmap_bin_file(sd); sysfs_unmap_bin_file(kn);
kernfs_put(sd); kernfs_put(kn);
} }
} }
/** /**
* kernfs_find_ns - find sysfs_dirent with the given name * kernfs_find_ns - find kernfs_node with the given name
* @parent: sysfs_dirent to search under * @parent: kernfs_node to search under
* @name: name to look for * @name: name to look for
* @ns: the namespace tag to use * @ns: the namespace tag to use
* *
* Look for sysfs_dirent with name @name under @parent. Returns pointer to * Look for kernfs_node with name @name under @parent. Returns pointer to
* the found sysfs_dirent on success, %NULL on failure. * the found kernfs_node on success, %NULL on failure.
*/ */
static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent, static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
const unsigned char *name, const unsigned char *name,
const void *ns) const void *ns)
{ {
struct rb_node *node = parent->s_dir.children.rb_node; struct rb_node *node = parent->s_dir.children.rb_node;
bool has_ns = kernfs_ns_enabled(parent); bool has_ns = kernfs_ns_enabled(parent);
...@@ -552,42 +553,42 @@ static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent, ...@@ -552,42 +553,42 @@ static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent,
hash = sysfs_name_hash(name, ns); hash = sysfs_name_hash(name, ns);
while (node) { while (node) {
struct sysfs_dirent *sd; struct kernfs_node *kn;
int result; int result;
sd = to_sysfs_dirent(node); kn = rb_to_kn(node);
result = sysfs_name_compare(hash, name, ns, sd); result = sysfs_name_compare(hash, name, ns, kn);
if (result < 0) if (result < 0)
node = node->rb_left; node = node->rb_left;
else if (result > 0) else if (result > 0)
node = node->rb_right; node = node->rb_right;
else else
return sd; return kn;
} }
return NULL; return NULL;
} }
/** /**
* kernfs_find_and_get_ns - find and get sysfs_dirent with the given name * kernfs_find_and_get_ns - find and get kernfs_node with the given name
* @parent: sysfs_dirent to search under * @parent: kernfs_node to search under
* @name: name to look for * @name: name to look for
* @ns: the namespace tag to use * @ns: the namespace tag to use
* *
* Look for sysfs_dirent with name @name under @parent and get a reference * Look for kernfs_node with name @name under @parent and get a reference
* if found. This function may sleep and returns pointer to the found * if found. This function may sleep and returns pointer to the found
* sysfs_dirent on success, %NULL on failure. * kernfs_node on success, %NULL on failure.
*/ */
struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
const char *name, const void *ns) const char *name, const void *ns)
{ {
struct sysfs_dirent *sd; struct kernfs_node *kn;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
sd = kernfs_find_ns(parent, name, ns); kn = kernfs_find_ns(parent, name, ns);
kernfs_get(sd); kernfs_get(kn);
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
return sd; return kn;
} }
EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns); EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
...@@ -601,7 +602,7 @@ EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns); ...@@ -601,7 +602,7 @@ EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
struct kernfs_root *kernfs_create_root(void *priv) struct kernfs_root *kernfs_create_root(void *priv)
{ {
struct kernfs_root *root; struct kernfs_root *root;
struct sysfs_dirent *sd; struct kernfs_node *kn;
root = kzalloc(sizeof(*root), GFP_KERNEL); root = kzalloc(sizeof(*root), GFP_KERNEL);
if (!root) if (!root)
...@@ -609,18 +610,18 @@ struct kernfs_root *kernfs_create_root(void *priv) ...@@ -609,18 +610,18 @@ struct kernfs_root *kernfs_create_root(void *priv)
ida_init(&root->ino_ida); ida_init(&root->ino_ida);
sd = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR); kn = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR);
if (!sd) { if (!kn) {
ida_destroy(&root->ino_ida); ida_destroy(&root->ino_ida);
kfree(root); kfree(root);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
sd->s_flags &= ~SYSFS_FLAG_REMOVED; kn->s_flags &= ~SYSFS_FLAG_REMOVED;
sd->priv = priv; kn->priv = priv;
sd->s_dir.root = root; kn->s_dir.root = root;
root->sd = sd; root->kn = kn;
return root; return root;
} }
...@@ -634,7 +635,7 @@ struct kernfs_root *kernfs_create_root(void *priv) ...@@ -634,7 +635,7 @@ struct kernfs_root *kernfs_create_root(void *priv)
*/ */
void kernfs_destroy_root(struct kernfs_root *root) void kernfs_destroy_root(struct kernfs_root *root)
{ {
kernfs_remove(root->sd); /* will also free @root */ kernfs_remove(root->kn); /* will also free @root */
} }
/** /**
...@@ -646,33 +647,33 @@ void kernfs_destroy_root(struct kernfs_root *root) ...@@ -646,33 +647,33 @@ void kernfs_destroy_root(struct kernfs_root *root)
* *
* Returns the created node on success, ERR_PTR() value on failure. * Returns the created node on success, ERR_PTR() value on failure.
*/ */
struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
const char *name, void *priv, const char *name, void *priv,
const void *ns) const void *ns)
{ {
umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
struct sysfs_addrm_cxt acxt; struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd; struct kernfs_node *kn;
int rc; int rc;
/* allocate */ /* allocate */
sd = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR); kn = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR);
if (!sd) if (!kn)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
sd->s_dir.root = parent->s_dir.root; kn->s_dir.root = parent->s_dir.root;
sd->s_ns = ns; kn->s_ns = ns;
sd->priv = priv; kn->priv = priv;
/* link in */ /* link in */
sysfs_addrm_start(&acxt); sysfs_addrm_start(&acxt);
rc = sysfs_add_one(&acxt, sd, parent); rc = sysfs_add_one(&acxt, kn, parent);
sysfs_addrm_finish(&acxt); sysfs_addrm_finish(&acxt);
if (!rc) if (!rc)
return sd; return kn;
kernfs_put(sd); kernfs_put(kn);
return ERR_PTR(rc); return ERR_PTR(rc);
} }
...@@ -680,29 +681,28 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -680,29 +681,28 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags) unsigned int flags)
{ {
struct dentry *ret = NULL; struct dentry *ret = NULL;
struct dentry *parent = dentry->d_parent; struct kernfs_node *parent = dentry->d_parent->d_fsdata;
struct sysfs_dirent *parent_sd = parent->d_fsdata; struct kernfs_node *kn;
struct sysfs_dirent *sd;
struct inode *inode; struct inode *inode;
const void *ns = NULL; const void *ns = NULL;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
if (kernfs_ns_enabled(parent_sd)) if (kernfs_ns_enabled(parent))
ns = sysfs_info(dir->i_sb)->ns; ns = sysfs_info(dir->i_sb)->ns;
sd = kernfs_find_ns(parent_sd, dentry->d_name.name, ns); kn = kernfs_find_ns(parent, dentry->d_name.name, ns);
/* no such entry */ /* no such entry */
if (!sd) { if (!kn) {
ret = ERR_PTR(-ENOENT); ret = ERR_PTR(-ENOENT);
goto out_unlock; goto out_unlock;
} }
kernfs_get(sd); kernfs_get(kn);
dentry->d_fsdata = sd; dentry->d_fsdata = kn;
/* attach dentry and inode */ /* attach dentry and inode */
inode = sysfs_get_inode(dir->i_sb, sd); inode = sysfs_get_inode(dir->i_sb, kn);
if (!inode) { if (!inode) {
ret = ERR_PTR(-ENOMEM); ret = ERR_PTR(-ENOMEM);
goto out_unlock; goto out_unlock;
...@@ -726,9 +726,9 @@ const struct inode_operations sysfs_dir_inode_operations = { ...@@ -726,9 +726,9 @@ const struct inode_operations sysfs_dir_inode_operations = {
.listxattr = sysfs_listxattr, .listxattr = sysfs_listxattr,
}; };
static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) static struct kernfs_node *sysfs_leftmost_descendant(struct kernfs_node *pos)
{ {
struct sysfs_dirent *last; struct kernfs_node *last;
while (true) { while (true) {
struct rb_node *rbn; struct rb_node *rbn;
...@@ -742,7 +742,7 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) ...@@ -742,7 +742,7 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
if (!rbn) if (!rbn)
break; break;
pos = to_sysfs_dirent(rbn); pos = rb_to_kn(rbn);
} }
return last; return last;
...@@ -751,14 +751,14 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) ...@@ -751,14 +751,14 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
/** /**
* sysfs_next_descendant_post - find the next descendant for post-order walk * sysfs_next_descendant_post - find the next descendant for post-order walk
* @pos: the current position (%NULL to initiate traversal) * @pos: the current position (%NULL to initiate traversal)
* @root: sysfs_dirent whose descendants to walk * @root: kernfs_node whose descendants to walk
* *
* Find the next descendant to visit for post-order traversal of @root's * Find the next descendant to visit for post-order traversal of @root's
* descendants. @root is included in the iteration and the last node to be * descendants. @root is included in the iteration and the last node to be
* visited. * visited.
*/ */
static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos, static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos,
struct sysfs_dirent *root) struct kernfs_node *root)
{ {
struct rb_node *rbn; struct rb_node *rbn;
...@@ -775,62 +775,62 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos, ...@@ -775,62 +775,62 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos,
/* if there's an unvisited sibling, visit its leftmost descendant */ /* if there's an unvisited sibling, visit its leftmost descendant */
rbn = rb_next(&pos->s_rb); rbn = rb_next(&pos->s_rb);
if (rbn) if (rbn)
return sysfs_leftmost_descendant(to_sysfs_dirent(rbn)); return sysfs_leftmost_descendant(rb_to_kn(rbn));
/* no sibling left, visit parent */ /* no sibling left, visit parent */
return pos->s_parent; return pos->s_parent;
} }
static void __kernfs_remove(struct sysfs_addrm_cxt *acxt, static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
struct sysfs_dirent *sd) struct kernfs_node *kn)
{ {
struct sysfs_dirent *pos, *next; struct kernfs_node *pos, *next;
if (!sd) if (!kn)
return; return;
pr_debug("sysfs %s: removing\n", sd->s_name); pr_debug("sysfs %s: removing\n", kn->s_name);
next = NULL; next = NULL;
do { do {
pos = next; pos = next;
next = sysfs_next_descendant_post(pos, sd); next = sysfs_next_descendant_post(pos, kn);
if (pos) if (pos)
sysfs_remove_one(acxt, pos); sysfs_remove_one(acxt, pos);
} while (next); } while (next);
} }
/** /**
* kernfs_remove - remove a sysfs_dirent recursively * kernfs_remove - remove a kernfs_node recursively
* @sd: the sysfs_dirent to remove * @kn: the kernfs_node to remove
* *
* Remove @sd along with all its subdirectories and files. * Remove @kn along with all its subdirectories and files.
*/ */
void kernfs_remove(struct sysfs_dirent *sd) void kernfs_remove(struct kernfs_node *kn)
{ {
struct sysfs_addrm_cxt acxt; struct sysfs_addrm_cxt acxt;
sysfs_addrm_start(&acxt); sysfs_addrm_start(&acxt);
__kernfs_remove(&acxt, sd); __kernfs_remove(&acxt, kn);
sysfs_addrm_finish(&acxt); sysfs_addrm_finish(&acxt);
} }
/** /**
* kernfs_remove_by_name_ns - find a sysfs_dirent by name and remove it * kernfs_remove_by_name_ns - find a kernfs_node by name and remove it
* @dir_sd: parent of the target * @parent: parent of the target
* @name: name of the sysfs_dirent to remove * @name: name of the kernfs_node to remove
* @ns: namespace tag of the sysfs_dirent to remove * @ns: namespace tag of the kernfs_node to remove
* *
* Look for the sysfs_dirent with @name and @ns under @dir_sd and remove * Look for the kernfs_node with @name and @ns under @parent and remove it.
* it. Returns 0 on success, -ENOENT if such entry doesn't exist. * Returns 0 on success, -ENOENT if such entry doesn't exist.
*/ */
int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name, int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
const void *ns) const void *ns)
{ {
struct sysfs_addrm_cxt acxt; struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd; struct kernfs_node *kn;
if (!dir_sd) { if (!parent) {
WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n", WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n",
name); name);
return -ENOENT; return -ENOENT;
...@@ -838,13 +838,13 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name, ...@@ -838,13 +838,13 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
sysfs_addrm_start(&acxt); sysfs_addrm_start(&acxt);
sd = kernfs_find_ns(dir_sd, name, ns); kn = kernfs_find_ns(parent, name, ns);
if (sd) if (kn)
__kernfs_remove(&acxt, sd); __kernfs_remove(&acxt, kn);
sysfs_addrm_finish(&acxt); sysfs_addrm_finish(&acxt);
if (sd) if (kn)
return 0; return 0;
else else
return -ENOENT; return -ENOENT;
...@@ -852,12 +852,12 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name, ...@@ -852,12 +852,12 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
/** /**
* kernfs_rename_ns - move and rename a kernfs_node * kernfs_rename_ns - move and rename a kernfs_node
* @sd: target node * @kn: target node
* @new_parent: new parent to put @sd under * @new_parent: new parent to put @sd under
* @new_name: new name * @new_name: new name
* @new_ns: new namespace tag * @new_ns: new namespace tag
*/ */
int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
const char *new_name, const void *new_ns) const char *new_name, const void *new_ns)
{ {
int error; int error;
...@@ -865,35 +865,35 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, ...@@ -865,35 +865,35 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
error = 0; error = 0;
if ((sd->s_parent == new_parent) && (sd->s_ns == new_ns) && if ((kn->s_parent == new_parent) && (kn->s_ns == new_ns) &&
(strcmp(sd->s_name, new_name) == 0)) (strcmp(kn->s_name, new_name) == 0))
goto out; /* nothing to rename */ goto out; /* nothing to rename */
error = -EEXIST; error = -EEXIST;
if (kernfs_find_ns(new_parent, new_name, new_ns)) if (kernfs_find_ns(new_parent, new_name, new_ns))
goto out; goto out;
/* rename sysfs_dirent */ /* rename kernfs_node */
if (strcmp(sd->s_name, new_name) != 0) { if (strcmp(kn->s_name, new_name) != 0) {
error = -ENOMEM; error = -ENOMEM;
new_name = kstrdup(new_name, GFP_KERNEL); new_name = kstrdup(new_name, GFP_KERNEL);
if (!new_name) if (!new_name)
goto out; goto out;
kfree(sd->s_name); kfree(kn->s_name);
sd->s_name = new_name; kn->s_name = new_name;
} }
/* /*
* Move to the appropriate place in the appropriate directories rbtree. * Move to the appropriate place in the appropriate directories rbtree.
*/ */
sysfs_unlink_sibling(sd); sysfs_unlink_sibling(kn);
kernfs_get(new_parent); kernfs_get(new_parent);
kernfs_put(sd->s_parent); kernfs_put(kn->s_parent);
sd->s_ns = new_ns; kn->s_ns = new_ns;
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
sd->s_parent = new_parent; kn->s_parent = new_parent;
sysfs_link_sibling(sd); sysfs_link_sibling(kn);
error = 0; error = 0;
out: out:
...@@ -902,9 +902,9 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, ...@@ -902,9 +902,9 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
} }
/* Relationship between s_mode and the DT_xxx types */ /* Relationship between s_mode and the DT_xxx types */
static inline unsigned char dt_type(struct sysfs_dirent *sd) static inline unsigned char dt_type(struct kernfs_node *kn)
{ {
return (sd->s_mode >> 12) & 15; return (kn->s_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)
...@@ -913,21 +913,21 @@ static int sysfs_dir_release(struct inode *inode, struct file *filp) ...@@ -913,21 +913,21 @@ static int sysfs_dir_release(struct inode *inode, struct file *filp)
return 0; return 0;
} }
static struct sysfs_dirent *sysfs_dir_pos(const void *ns, static struct kernfs_node *sysfs_dir_pos(const void *ns,
struct sysfs_dirent *parent_sd, loff_t hash, struct sysfs_dirent *pos) struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
{ {
if (pos) { if (pos) {
int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) && int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
pos->s_parent == parent_sd && pos->s_parent == parent &&
hash == pos->s_hash; hash == pos->s_hash;
kernfs_put(pos); kernfs_put(pos);
if (!valid) if (!valid)
pos = NULL; pos = NULL;
} }
if (!pos && (hash > 1) && (hash < INT_MAX)) { if (!pos && (hash > 1) && (hash < INT_MAX)) {
struct rb_node *node = parent_sd->s_dir.children.rb_node; struct rb_node *node = parent->s_dir.children.rb_node;
while (node) { while (node) {
pos = to_sysfs_dirent(node); pos = rb_to_kn(node);
if (hash < pos->s_hash) if (hash < pos->s_hash)
node = node->rb_left; node = node->rb_left;
...@@ -943,22 +943,22 @@ static struct sysfs_dirent *sysfs_dir_pos(const void *ns, ...@@ -943,22 +943,22 @@ static struct sysfs_dirent *sysfs_dir_pos(const void *ns,
if (!node) if (!node)
pos = NULL; pos = NULL;
else else
pos = to_sysfs_dirent(node); pos = rb_to_kn(node);
} }
return pos; return pos;
} }
static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns, static struct kernfs_node *sysfs_dir_next_pos(const void *ns,
struct sysfs_dirent *parent_sd, ino_t ino, struct sysfs_dirent *pos) struct kernfs_node *parent, ino_t ino, struct kernfs_node *pos)
{ {
pos = sysfs_dir_pos(ns, parent_sd, ino, pos); pos = sysfs_dir_pos(ns, parent, ino, pos);
if (pos) if (pos)
do { do {
struct rb_node *node = rb_next(&pos->s_rb); struct rb_node *node = rb_next(&pos->s_rb);
if (!node) if (!node)
pos = NULL; pos = NULL;
else else
pos = to_sysfs_dirent(node); pos = rb_to_kn(node);
} while (pos && pos->s_ns != ns); } while (pos && pos->s_ns != ns);
return pos; return pos;
} }
...@@ -966,20 +966,20 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns, ...@@ -966,20 +966,20 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns,
static int sysfs_readdir(struct file *file, struct dir_context *ctx) static int sysfs_readdir(struct file *file, struct dir_context *ctx)
{ {
struct dentry *dentry = file->f_path.dentry; struct dentry *dentry = file->f_path.dentry;
struct sysfs_dirent *parent_sd = dentry->d_fsdata; struct kernfs_node *parent = dentry->d_fsdata;
struct sysfs_dirent *pos = file->private_data; struct kernfs_node *pos = file->private_data;
const void *ns = NULL; const void *ns = NULL;
if (!dir_emit_dots(file, ctx)) if (!dir_emit_dots(file, ctx))
return 0; return 0;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
if (kernfs_ns_enabled(parent_sd)) if (kernfs_ns_enabled(parent))
ns = sysfs_info(dentry->d_sb)->ns; ns = sysfs_info(dentry->d_sb)->ns;
for (pos = sysfs_dir_pos(ns, parent_sd, ctx->pos, pos); for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos);
pos; pos;
pos = sysfs_dir_next_pos(ns, parent_sd, ctx->pos, pos)) { pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
const char *name = pos->s_name; const char *name = pos->s_name;
unsigned int type = dt_type(pos); unsigned int type = dt_type(pos);
int len = strlen(name); int len = strlen(name);
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
/* /*
* There's one sysfs_open_file for each open file and one sysfs_open_dirent * There's one sysfs_open_file for each open file and one sysfs_open_dirent
* for each sysfs_dirent with one or more open files. * for each kernfs_node with one or more open files.
* *
* sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open is * kernfs_node->s_attr.open points to sysfs_open_dirent. s_attr.open is
* protected by sysfs_open_dirent_lock. * protected by sysfs_open_dirent_lock.
* *
* filp->private_data points to seq_file whose ->private points to * filp->private_data points to seq_file whose ->private points to
...@@ -44,14 +44,14 @@ static struct sysfs_open_file *sysfs_of(struct file *file) ...@@ -44,14 +44,14 @@ static struct sysfs_open_file *sysfs_of(struct file *file)
} }
/* /*
* Determine the kernfs_ops for the given sysfs_dirent. This function must * Determine the kernfs_ops for the given kernfs_node. This function must
* be called while holding an active reference. * be called while holding an active reference.
*/ */
static const struct kernfs_ops *kernfs_ops(struct sysfs_dirent *sd) static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn)
{ {
if (sd->s_flags & SYSFS_FLAG_LOCKDEP) if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
lockdep_assert_held(sd); lockdep_assert_held(kn);
return sd->s_attr.ops; return kn->s_attr.ops;
} }
static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos) static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
...@@ -64,10 +64,10 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos) ...@@ -64,10 +64,10 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
* the ops aren't called concurrently for the same open file. * the ops aren't called concurrently for the same open file.
*/ */
mutex_lock(&of->mutex); mutex_lock(&of->mutex);
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
ops = kernfs_ops(of->sd); ops = kernfs_ops(of->kn);
if (ops->seq_start) { if (ops->seq_start) {
return ops->seq_start(sf, ppos); return ops->seq_start(sf, ppos);
} else { } else {
...@@ -82,7 +82,7 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos) ...@@ -82,7 +82,7 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos) static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
{ {
struct sysfs_open_file *of = sf->private; struct sysfs_open_file *of = sf->private;
const struct kernfs_ops *ops = kernfs_ops(of->sd); const struct kernfs_ops *ops = kernfs_ops(of->kn);
if (ops->seq_next) { if (ops->seq_next) {
return ops->seq_next(sf, v, ppos); return ops->seq_next(sf, v, ppos);
...@@ -99,12 +99,12 @@ static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos) ...@@ -99,12 +99,12 @@ static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
static void kernfs_seq_stop(struct seq_file *sf, void *v) static void kernfs_seq_stop(struct seq_file *sf, void *v)
{ {
struct sysfs_open_file *of = sf->private; struct sysfs_open_file *of = sf->private;
const struct kernfs_ops *ops = kernfs_ops(of->sd); const struct kernfs_ops *ops = kernfs_ops(of->kn);
if (ops->seq_stop) if (ops->seq_stop)
ops->seq_stop(sf, v); ops->seq_stop(sf, v);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
mutex_unlock(&of->mutex); mutex_unlock(&of->mutex);
} }
...@@ -112,9 +112,9 @@ static int kernfs_seq_show(struct seq_file *sf, void *v) ...@@ -112,9 +112,9 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
{ {
struct sysfs_open_file *of = sf->private; struct sysfs_open_file *of = sf->private;
of->event = atomic_read(&of->sd->s_attr.open->event); of->event = atomic_read(&of->kn->s_attr.open->event);
return of->sd->s_attr.ops->seq_show(sf, v); return of->kn->s_attr.ops->seq_show(sf, v);
} }
static const struct seq_operations kernfs_seq_ops = { static const struct seq_operations kernfs_seq_ops = {
...@@ -147,19 +147,19 @@ static ssize_t kernfs_file_direct_read(struct sysfs_open_file *of, ...@@ -147,19 +147,19 @@ static ssize_t kernfs_file_direct_read(struct sysfs_open_file *of,
* the ops aren't called concurrently for the same open file. * the ops aren't called concurrently for the same open file.
*/ */
mutex_lock(&of->mutex); mutex_lock(&of->mutex);
if (!sysfs_get_active(of->sd)) { if (!sysfs_get_active(of->kn)) {
len = -ENODEV; len = -ENODEV;
mutex_unlock(&of->mutex); mutex_unlock(&of->mutex);
goto out_free; goto out_free;
} }
ops = kernfs_ops(of->sd); ops = kernfs_ops(of->kn);
if (ops->read) if (ops->read)
len = ops->read(of, buf, len, *ppos); len = ops->read(of, buf, len, *ppos);
else else
len = -EINVAL; len = -EINVAL;
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
mutex_unlock(&of->mutex); mutex_unlock(&of->mutex);
if (len < 0) if (len < 0)
...@@ -189,7 +189,7 @@ static ssize_t kernfs_file_read(struct file *file, char __user *user_buf, ...@@ -189,7 +189,7 @@ static ssize_t kernfs_file_read(struct file *file, char __user *user_buf,
{ {
struct sysfs_open_file *of = sysfs_of(file); struct sysfs_open_file *of = sysfs_of(file);
if (of->sd->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW) if (of->kn->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW)
return seq_read(file, user_buf, count, ppos); return seq_read(file, user_buf, count, ppos);
else else
return kernfs_file_direct_read(of, user_buf, count, ppos); return kernfs_file_direct_read(of, user_buf, count, ppos);
...@@ -234,19 +234,19 @@ static ssize_t kernfs_file_write(struct file *file, const char __user *user_buf, ...@@ -234,19 +234,19 @@ static ssize_t kernfs_file_write(struct file *file, const char __user *user_buf,
* the ops aren't called concurrently for the same open file. * the ops aren't called concurrently for the same open file.
*/ */
mutex_lock(&of->mutex); mutex_lock(&of->mutex);
if (!sysfs_get_active(of->sd)) { if (!sysfs_get_active(of->kn)) {
mutex_unlock(&of->mutex); mutex_unlock(&of->mutex);
len = -ENODEV; len = -ENODEV;
goto out_free; goto out_free;
} }
ops = kernfs_ops(of->sd); ops = kernfs_ops(of->kn);
if (ops->write) if (ops->write)
len = ops->write(of, buf, len, *ppos); len = ops->write(of, buf, len, *ppos);
else else
len = -EINVAL; len = -EINVAL;
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
mutex_unlock(&of->mutex); mutex_unlock(&of->mutex);
if (len > 0) if (len > 0)
...@@ -264,13 +264,13 @@ static void kernfs_vma_open(struct vm_area_struct *vma) ...@@ -264,13 +264,13 @@ static void kernfs_vma_open(struct vm_area_struct *vma)
if (!of->vm_ops) if (!of->vm_ops)
return; return;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return; return;
if (of->vm_ops->open) if (of->vm_ops->open)
of->vm_ops->open(vma); of->vm_ops->open(vma);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
} }
static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
...@@ -282,14 +282,14 @@ static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -282,14 +282,14 @@ static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
if (!of->vm_ops) if (!of->vm_ops)
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
ret = VM_FAULT_SIGBUS; ret = VM_FAULT_SIGBUS;
if (of->vm_ops->fault) if (of->vm_ops->fault)
ret = of->vm_ops->fault(vma, vmf); ret = of->vm_ops->fault(vma, vmf);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
return ret; return ret;
} }
...@@ -303,7 +303,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma, ...@@ -303,7 +303,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
if (!of->vm_ops) if (!of->vm_ops)
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
ret = 0; ret = 0;
...@@ -312,7 +312,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma, ...@@ -312,7 +312,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
else else
file_update_time(file); file_update_time(file);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
return ret; return ret;
} }
...@@ -326,14 +326,14 @@ static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr, ...@@ -326,14 +326,14 @@ static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
if (!of->vm_ops) if (!of->vm_ops)
return -EINVAL; return -EINVAL;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return -EINVAL; return -EINVAL;
ret = -EINVAL; ret = -EINVAL;
if (of->vm_ops->access) if (of->vm_ops->access)
ret = of->vm_ops->access(vma, addr, buf, len, write); ret = of->vm_ops->access(vma, addr, buf, len, write);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
return ret; return ret;
} }
...@@ -348,14 +348,14 @@ static int kernfs_vma_set_policy(struct vm_area_struct *vma, ...@@ -348,14 +348,14 @@ static int kernfs_vma_set_policy(struct vm_area_struct *vma,
if (!of->vm_ops) if (!of->vm_ops)
return 0; return 0;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return -EINVAL; return -EINVAL;
ret = 0; ret = 0;
if (of->vm_ops->set_policy) if (of->vm_ops->set_policy)
ret = of->vm_ops->set_policy(vma, new); ret = of->vm_ops->set_policy(vma, new);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
return ret; return ret;
} }
...@@ -369,14 +369,14 @@ static struct mempolicy *kernfs_vma_get_policy(struct vm_area_struct *vma, ...@@ -369,14 +369,14 @@ static struct mempolicy *kernfs_vma_get_policy(struct vm_area_struct *vma,
if (!of->vm_ops) if (!of->vm_ops)
return vma->vm_policy; return vma->vm_policy;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return vma->vm_policy; return vma->vm_policy;
pol = vma->vm_policy; pol = vma->vm_policy;
if (of->vm_ops->get_policy) if (of->vm_ops->get_policy)
pol = of->vm_ops->get_policy(vma, addr); pol = of->vm_ops->get_policy(vma, addr);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
return pol; return pol;
} }
...@@ -391,14 +391,14 @@ static int kernfs_vma_migrate(struct vm_area_struct *vma, ...@@ -391,14 +391,14 @@ static int kernfs_vma_migrate(struct vm_area_struct *vma,
if (!of->vm_ops) if (!of->vm_ops)
return 0; return 0;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
return 0; return 0;
ret = 0; ret = 0;
if (of->vm_ops->migrate) if (of->vm_ops->migrate)
ret = of->vm_ops->migrate(vma, from, to, flags); ret = of->vm_ops->migrate(vma, from, to, flags);
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
return ret; return ret;
} }
#endif #endif
...@@ -428,16 +428,16 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -428,16 +428,16 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
* without grabbing @of->mutex by testing HAS_MMAP flag. See the * without grabbing @of->mutex by testing HAS_MMAP flag. See the
* comment in kernfs_file_open() for more details. * comment in kernfs_file_open() for more details.
*/ */
if (!(of->sd->s_flags & SYSFS_FLAG_HAS_MMAP)) if (!(of->kn->s_flags & SYSFS_FLAG_HAS_MMAP))
return -ENODEV; return -ENODEV;
mutex_lock(&of->mutex); mutex_lock(&of->mutex);
rc = -ENODEV; rc = -ENODEV;
if (!sysfs_get_active(of->sd)) if (!sysfs_get_active(of->kn))
goto out_unlock; goto out_unlock;
ops = kernfs_ops(of->sd); ops = kernfs_ops(of->kn);
rc = ops->mmap(of, vma); rc = ops->mmap(of, vma);
/* /*
...@@ -465,7 +465,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -465,7 +465,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
of->vm_ops = vma->vm_ops; of->vm_ops = vma->vm_ops;
vma->vm_ops = &kernfs_vm_ops; vma->vm_ops = &kernfs_vm_ops;
out_put: out_put:
sysfs_put_active(of->sd); sysfs_put_active(of->kn);
out_unlock: out_unlock:
mutex_unlock(&of->mutex); mutex_unlock(&of->mutex);
...@@ -474,10 +474,10 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -474,10 +474,10 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
/** /**
* sysfs_get_open_dirent - get or create sysfs_open_dirent * sysfs_get_open_dirent - get or create sysfs_open_dirent
* @sd: target sysfs_dirent * @kn: target kernfs_node
* @of: sysfs_open_file for this instance of open * @of: sysfs_open_file for this instance of open
* *
* If @sd->s_attr.open exists, increment its reference count; * If @kn->s_attr.open exists, increment its reference count;
* otherwise, create one. @of is chained to the files list. * otherwise, create one. @of is chained to the files list.
* *
* LOCKING: * LOCKING:
...@@ -486,7 +486,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -486,7 +486,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
* RETURNS: * RETURNS:
* 0 on success, -errno on failure. * 0 on success, -errno on failure.
*/ */
static int sysfs_get_open_dirent(struct sysfs_dirent *sd, static int sysfs_get_open_dirent(struct kernfs_node *kn,
struct sysfs_open_file *of) struct sysfs_open_file *of)
{ {
struct sysfs_open_dirent *od, *new_od = NULL; struct sysfs_open_dirent *od, *new_od = NULL;
...@@ -495,12 +495,12 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, ...@@ -495,12 +495,12 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
mutex_lock(&sysfs_open_file_mutex); mutex_lock(&sysfs_open_file_mutex);
spin_lock_irq(&sysfs_open_dirent_lock); spin_lock_irq(&sysfs_open_dirent_lock);
if (!sd->s_attr.open && new_od) { if (!kn->s_attr.open && new_od) {
sd->s_attr.open = new_od; kn->s_attr.open = new_od;
new_od = NULL; new_od = NULL;
} }
od = sd->s_attr.open; od = kn->s_attr.open;
if (od) { if (od) {
atomic_inc(&od->refcnt); atomic_inc(&od->refcnt);
list_add_tail(&of->list, &od->files); list_add_tail(&of->list, &od->files);
...@@ -528,19 +528,19 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, ...@@ -528,19 +528,19 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
/** /**
* sysfs_put_open_dirent - put sysfs_open_dirent * sysfs_put_open_dirent - put sysfs_open_dirent
* @sd: target sysfs_dirent * @kn: target kernfs_nodet
* @of: associated sysfs_open_file * @of: associated sysfs_open_file
* *
* Put @sd->s_attr.open and unlink @of from the files list. If * Put @kn->s_attr.open and unlink @of from the files list. If
* reference count reaches zero, disassociate and free it. * reference count reaches zero, disassociate and free it.
* *
* LOCKING: * LOCKING:
* None. * None.
*/ */
static void sysfs_put_open_dirent(struct sysfs_dirent *sd, static void sysfs_put_open_dirent(struct kernfs_node *kn,
struct sysfs_open_file *of) struct sysfs_open_file *of)
{ {
struct sysfs_open_dirent *od = sd->s_attr.open; struct sysfs_open_dirent *od = kn->s_attr.open;
unsigned long flags; unsigned long flags;
mutex_lock(&sysfs_open_file_mutex); mutex_lock(&sysfs_open_file_mutex);
...@@ -550,7 +550,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, ...@@ -550,7 +550,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
list_del(&of->list); list_del(&of->list);
if (atomic_dec_and_test(&od->refcnt)) if (atomic_dec_and_test(&od->refcnt))
sd->s_attr.open = NULL; kn->s_attr.open = NULL;
else else
od = NULL; od = NULL;
...@@ -562,16 +562,16 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, ...@@ -562,16 +562,16 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
static int kernfs_file_open(struct inode *inode, struct file *file) static int kernfs_file_open(struct inode *inode, struct file *file)
{ {
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; struct kernfs_node *kn = file->f_path.dentry->d_fsdata;
const struct kernfs_ops *ops; const struct kernfs_ops *ops;
struct sysfs_open_file *of; struct sysfs_open_file *of;
bool has_read, has_write, has_mmap; bool has_read, has_write, has_mmap;
int error = -EACCES; int error = -EACCES;
if (!sysfs_get_active(attr_sd)) if (!sysfs_get_active(kn))
return -ENODEV; return -ENODEV;
ops = kernfs_ops(attr_sd); ops = kernfs_ops(kn);
has_read = ops->seq_show || ops->read || ops->mmap; has_read = ops->seq_show || ops->read || ops->mmap;
has_write = ops->write || ops->mmap; has_write = ops->write || ops->mmap;
...@@ -612,7 +612,7 @@ static int kernfs_file_open(struct inode *inode, struct file *file) ...@@ -612,7 +612,7 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
else else
mutex_init(&of->mutex); mutex_init(&of->mutex);
of->sd = attr_sd; of->kn = kn;
of->file = file; of->file = file;
/* /*
...@@ -634,12 +634,12 @@ static int kernfs_file_open(struct inode *inode, struct file *file) ...@@ -634,12 +634,12 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
file->f_mode |= FMODE_PWRITE; file->f_mode |= FMODE_PWRITE;
/* make sure we have open dirent struct */ /* make sure we have open dirent struct */
error = sysfs_get_open_dirent(attr_sd, of); error = sysfs_get_open_dirent(kn, of);
if (error) if (error)
goto err_close; goto err_close;
/* open succeeded, put active references */ /* open succeeded, put active references */
sysfs_put_active(attr_sd); sysfs_put_active(kn);
return 0; return 0;
err_close: err_close:
...@@ -647,32 +647,32 @@ static int kernfs_file_open(struct inode *inode, struct file *file) ...@@ -647,32 +647,32 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
err_free: err_free:
kfree(of); kfree(of);
err_out: err_out:
sysfs_put_active(attr_sd); sysfs_put_active(kn);
return error; return error;
} }
static int kernfs_file_release(struct inode *inode, struct file *filp) static int kernfs_file_release(struct inode *inode, struct file *filp)
{ {
struct sysfs_dirent *sd = filp->f_path.dentry->d_fsdata; struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
struct sysfs_open_file *of = sysfs_of(filp); struct sysfs_open_file *of = sysfs_of(filp);
sysfs_put_open_dirent(sd, of); sysfs_put_open_dirent(kn, of);
seq_release(inode, filp); seq_release(inode, filp);
kfree(of); kfree(of);
return 0; return 0;
} }
void sysfs_unmap_bin_file(struct sysfs_dirent *sd) void sysfs_unmap_bin_file(struct kernfs_node *kn)
{ {
struct sysfs_open_dirent *od; struct sysfs_open_dirent *od;
struct sysfs_open_file *of; struct sysfs_open_file *of;
if (!(sd->s_flags & SYSFS_FLAG_HAS_MMAP)) if (!(kn->s_flags & SYSFS_FLAG_HAS_MMAP))
return; return;
spin_lock_irq(&sysfs_open_dirent_lock); spin_lock_irq(&sysfs_open_dirent_lock);
od = sd->s_attr.open; od = kn->s_attr.open;
if (od) if (od)
atomic_inc(&od->refcnt); atomic_inc(&od->refcnt);
spin_unlock_irq(&sysfs_open_dirent_lock); spin_unlock_irq(&sysfs_open_dirent_lock);
...@@ -686,7 +686,7 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd) ...@@ -686,7 +686,7 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd)
} }
mutex_unlock(&sysfs_open_file_mutex); mutex_unlock(&sysfs_open_file_mutex);
sysfs_put_open_dirent(sd, NULL); sysfs_put_open_dirent(kn, NULL);
} }
/* Sysfs attribute files are pollable. The idea is that you read /* Sysfs attribute files are pollable. The idea is that you read
...@@ -705,16 +705,16 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd) ...@@ -705,16 +705,16 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd)
static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait) static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
{ {
struct sysfs_open_file *of = sysfs_of(filp); struct sysfs_open_file *of = sysfs_of(filp);
struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
struct sysfs_open_dirent *od = attr_sd->s_attr.open; struct sysfs_open_dirent *od = kn->s_attr.open;
/* need parent for the kobj, grab both */ /* need parent for the kobj, grab both */
if (!sysfs_get_active(attr_sd)) if (!sysfs_get_active(kn))
goto trigger; goto trigger;
poll_wait(filp, &od->poll, wait); poll_wait(filp, &od->poll, wait);
sysfs_put_active(attr_sd); sysfs_put_active(kn);
if (of->event != atomic_read(&od->event)) if (of->event != atomic_read(&od->event))
goto trigger; goto trigger;
...@@ -727,19 +727,19 @@ static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait) ...@@ -727,19 +727,19 @@ static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
/** /**
* kernfs_notify - notify a kernfs file * kernfs_notify - notify a kernfs file
* @sd: file to notify * @kn: file to notify
* *
* Notify @sd such that poll(2) on @sd wakes up. * Notify @kn such that poll(2) on @kn wakes up.
*/ */
void kernfs_notify(struct sysfs_dirent *sd) void kernfs_notify(struct kernfs_node *kn)
{ {
struct sysfs_open_dirent *od; struct sysfs_open_dirent *od;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sysfs_open_dirent_lock, flags); spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) { if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) {
od = sd->s_attr.open; od = kn->s_attr.open;
if (od) { if (od) {
atomic_inc(&od->event); atomic_inc(&od->event);
wake_up_interruptible(&od->poll); wake_up_interruptible(&od->poll);
...@@ -773,51 +773,51 @@ const struct file_operations kernfs_file_operations = { ...@@ -773,51 +773,51 @@ const struct file_operations kernfs_file_operations = {
* *
* Returns the created node on success, ERR_PTR() value on error. * Returns the created node on success, ERR_PTR() value on error.
*/ */
struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
const char *name, const char *name,
umode_t mode, loff_t size, umode_t mode, loff_t size,
const struct kernfs_ops *ops, const struct kernfs_ops *ops,
void *priv, const void *ns, void *priv, const void *ns,
struct lock_class_key *key) struct lock_class_key *key)
{ {
struct sysfs_addrm_cxt acxt; struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd; struct kernfs_node *kn;
int rc; int rc;
sd = sysfs_new_dirent(kernfs_root(parent), name, kn = sysfs_new_dirent(kernfs_root(parent), name,
(mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR); (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR);
if (!sd) if (!kn)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
sd->s_attr.ops = ops; kn->s_attr.ops = ops;
sd->s_attr.size = size; kn->s_attr.size = size;
sd->s_ns = ns; kn->s_ns = ns;
sd->priv = priv; kn->priv = priv;
#ifdef CONFIG_DEBUG_LOCK_ALLOC #ifdef CONFIG_DEBUG_LOCK_ALLOC
if (key) { if (key) {
lockdep_init_map(&sd->dep_map, "s_active", key, 0); lockdep_init_map(&kn->dep_map, "s_active", key, 0);
sd->s_flags |= SYSFS_FLAG_LOCKDEP; kn->s_flags |= SYSFS_FLAG_LOCKDEP;
} }
#endif #endif
/* /*
* sd->s_attr.ops is accesible only while holding active ref. We * kn->s_attr.ops is accesible only while holding active ref. We
* need to know whether some ops are implemented outside active * need to know whether some ops are implemented outside active
* ref. Cache their existence in flags. * ref. Cache their existence in flags.
*/ */
if (ops->seq_show) if (ops->seq_show)
sd->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW; kn->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW;
if (ops->mmap) if (ops->mmap)
sd->s_flags |= SYSFS_FLAG_HAS_MMAP; kn->s_flags |= SYSFS_FLAG_HAS_MMAP;
sysfs_addrm_start(&acxt); sysfs_addrm_start(&acxt);
rc = sysfs_add_one(&acxt, sd, parent); rc = sysfs_add_one(&acxt, kn, parent);
sysfs_addrm_finish(&acxt); sysfs_addrm_finish(&acxt);
if (rc) { if (rc) {
kernfs_put(sd); kernfs_put(kn);
return ERR_PTR(rc); return ERR_PTR(rc);
} }
return sd; return kn;
} }
...@@ -46,36 +46,36 @@ void __init sysfs_inode_init(void) ...@@ -46,36 +46,36 @@ void __init sysfs_inode_init(void)
panic("failed to init sysfs_backing_dev_info"); panic("failed to init sysfs_backing_dev_info");
} }
static struct sysfs_inode_attrs *sysfs_inode_attrs(struct sysfs_dirent *sd) static struct sysfs_inode_attrs *sysfs_inode_attrs(struct kernfs_node *kn)
{ {
struct iattr *iattrs; struct iattr *iattrs;
if (sd->s_iattr) if (kn->s_iattr)
return sd->s_iattr; return kn->s_iattr;
sd->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL); kn->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL);
if (!sd->s_iattr) if (!kn->s_iattr)
return NULL; return NULL;
iattrs = &sd->s_iattr->ia_iattr; iattrs = &kn->s_iattr->ia_iattr;
/* assign default attributes */ /* assign default attributes */
iattrs->ia_mode = sd->s_mode; iattrs->ia_mode = kn->s_mode;
iattrs->ia_uid = GLOBAL_ROOT_UID; iattrs->ia_uid = GLOBAL_ROOT_UID;
iattrs->ia_gid = GLOBAL_ROOT_GID; iattrs->ia_gid = GLOBAL_ROOT_GID;
iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME; iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME;
simple_xattrs_init(&sd->s_iattr->xattrs); simple_xattrs_init(&kn->s_iattr->xattrs);
return sd->s_iattr; return kn->s_iattr;
} }
static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) static int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
{ {
struct sysfs_inode_attrs *attrs; struct sysfs_inode_attrs *attrs;
struct iattr *iattrs; struct iattr *iattrs;
unsigned int ia_valid = iattr->ia_valid; unsigned int ia_valid = iattr->ia_valid;
attrs = sysfs_inode_attrs(sd); attrs = sysfs_inode_attrs(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENOMEM;
...@@ -93,24 +93,24 @@ static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) ...@@ -93,24 +93,24 @@ static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr)
iattrs->ia_ctime = iattr->ia_ctime; iattrs->ia_ctime = iattr->ia_ctime;
if (ia_valid & ATTR_MODE) { if (ia_valid & ATTR_MODE) {
umode_t mode = iattr->ia_mode; umode_t mode = iattr->ia_mode;
iattrs->ia_mode = sd->s_mode = mode; iattrs->ia_mode = kn->s_mode = mode;
} }
return 0; return 0;
} }
/** /**
* kernfs_setattr - set iattr on a node * kernfs_setattr - set iattr on a node
* @sd: target node * @kn: target node
* @iattr: iattr to set * @iattr: iattr to set
* *
* Returns 0 on success, -errno on failure. * Returns 0 on success, -errno on failure.
*/ */
int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
{ {
int ret; int ret;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
ret = __kernfs_setattr(sd, iattr); ret = __kernfs_setattr(kn, iattr);
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
return ret; return ret;
} }
...@@ -118,10 +118,10 @@ int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) ...@@ -118,10 +118,10 @@ int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr)
int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) int sysfs_setattr(struct dentry *dentry, struct iattr *iattr)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
int error; int error;
if (!sd) if (!kn)
return -EINVAL; return -EINVAL;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
...@@ -129,7 +129,7 @@ int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) ...@@ -129,7 +129,7 @@ int sysfs_setattr(struct dentry *dentry, struct iattr *iattr)
if (error) if (error)
goto out; goto out;
error = __kernfs_setattr(sd, iattr); error = __kernfs_setattr(kn, iattr);
if (error) if (error)
goto out; goto out;
...@@ -141,14 +141,14 @@ int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) ...@@ -141,14 +141,14 @@ int sysfs_setattr(struct dentry *dentry, struct iattr *iattr)
return error; return error;
} }
static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata, static int sysfs_sd_setsecdata(struct kernfs_node *kn, void **secdata,
u32 *secdata_len) u32 *secdata_len)
{ {
struct sysfs_inode_attrs *attrs; struct sysfs_inode_attrs *attrs;
void *old_secdata; void *old_secdata;
size_t old_secdata_len; size_t old_secdata_len;
attrs = sysfs_inode_attrs(sd); attrs = sysfs_inode_attrs(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENOMEM;
...@@ -166,13 +166,13 @@ static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata, ...@@ -166,13 +166,13 @@ static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata,
int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
size_t size, int flags) size_t size, int flags)
{ {
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
struct sysfs_inode_attrs *attrs; struct sysfs_inode_attrs *attrs;
void *secdata; void *secdata;
int error; int error;
u32 secdata_len = 0; u32 secdata_len = 0;
attrs = sysfs_inode_attrs(sd); attrs = sysfs_inode_attrs(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENOMEM;
...@@ -188,7 +188,7 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, ...@@ -188,7 +188,7 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
return error; return error;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
error = sysfs_sd_setsecdata(sd, &secdata, &secdata_len); error = sysfs_sd_setsecdata(kn, &secdata, &secdata_len);
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
if (secdata) if (secdata)
...@@ -204,10 +204,10 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, ...@@ -204,10 +204,10 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
int sysfs_removexattr(struct dentry *dentry, const char *name) int sysfs_removexattr(struct dentry *dentry, const char *name)
{ {
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
struct sysfs_inode_attrs *attrs; struct sysfs_inode_attrs *attrs;
attrs = sysfs_inode_attrs(sd); attrs = sysfs_inode_attrs(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENOMEM;
...@@ -217,10 +217,10 @@ int sysfs_removexattr(struct dentry *dentry, const char *name) ...@@ -217,10 +217,10 @@ int sysfs_removexattr(struct dentry *dentry, const char *name)
ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf, ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf,
size_t size) size_t size)
{ {
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
struct sysfs_inode_attrs *attrs; struct sysfs_inode_attrs *attrs;
attrs = sysfs_inode_attrs(sd); attrs = sysfs_inode_attrs(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENOMEM;
...@@ -229,10 +229,10 @@ ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf, ...@@ -229,10 +229,10 @@ ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf,
ssize_t sysfs_listxattr(struct dentry *dentry, char *buf, size_t size) ssize_t sysfs_listxattr(struct dentry *dentry, char *buf, size_t size)
{ {
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
struct sysfs_inode_attrs *attrs; struct sysfs_inode_attrs *attrs;
attrs = sysfs_inode_attrs(sd); attrs = sysfs_inode_attrs(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENOMEM;
...@@ -254,57 +254,58 @@ static inline void set_inode_attr(struct inode *inode, struct iattr *iattr) ...@@ -254,57 +254,58 @@ static inline void set_inode_attr(struct inode *inode, struct iattr *iattr)
inode->i_ctime = iattr->ia_ctime; inode->i_ctime = iattr->ia_ctime;
} }
static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode) static void sysfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
{ {
struct sysfs_inode_attrs *attrs = sd->s_iattr; struct sysfs_inode_attrs *attrs = kn->s_iattr;
inode->i_mode = sd->s_mode; inode->i_mode = kn->s_mode;
if (attrs) { if (attrs) {
/* sysfs_dirent has non-default attributes /*
* get them from persistent copy in sysfs_dirent * kernfs_node has non-default attributes get them from
* persistent copy in kernfs_node.
*/ */
set_inode_attr(inode, &attrs->ia_iattr); set_inode_attr(inode, &attrs->ia_iattr);
security_inode_notifysecctx(inode, attrs->ia_secdata, security_inode_notifysecctx(inode, attrs->ia_secdata,
attrs->ia_secdata_len); attrs->ia_secdata_len);
} }
if (sysfs_type(sd) == SYSFS_DIR) if (sysfs_type(kn) == SYSFS_DIR)
set_nlink(inode, sd->s_dir.subdirs + 2); set_nlink(inode, kn->s_dir.subdirs + 2);
} }
int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat) struct kstat *stat)
{ {
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
sysfs_refresh_inode(sd, inode); sysfs_refresh_inode(kn, inode);
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
generic_fillattr(inode, stat); generic_fillattr(inode, stat);
return 0; return 0;
} }
static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) static void sysfs_init_inode(struct kernfs_node *kn, struct inode *inode)
{ {
kernfs_get(sd); kernfs_get(kn);
inode->i_private = sd; inode->i_private = kn;
inode->i_mapping->a_ops = &sysfs_aops; inode->i_mapping->a_ops = &sysfs_aops;
inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
inode->i_op = &sysfs_inode_operations; inode->i_op = &sysfs_inode_operations;
set_default_inode_attr(inode, sd->s_mode); set_default_inode_attr(inode, kn->s_mode);
sysfs_refresh_inode(sd, inode); sysfs_refresh_inode(kn, inode);
/* initialize inode according to type */ /* initialize inode according to type */
switch (sysfs_type(sd)) { switch (sysfs_type(kn)) {
case SYSFS_DIR: case SYSFS_DIR:
inode->i_op = &sysfs_dir_inode_operations; inode->i_op = &sysfs_dir_inode_operations;
inode->i_fop = &sysfs_dir_operations; inode->i_fop = &sysfs_dir_operations;
break; break;
case SYSFS_KOBJ_ATTR: case SYSFS_KOBJ_ATTR:
inode->i_size = sd->s_attr.size; inode->i_size = kn->s_attr.size;
inode->i_fop = &kernfs_file_operations; inode->i_fop = &kernfs_file_operations;
break; break;
case SYSFS_KOBJ_LINK: case SYSFS_KOBJ_LINK:
...@@ -318,13 +319,13 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) ...@@ -318,13 +319,13 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
} }
/** /**
* sysfs_get_inode - get inode for sysfs_dirent * sysfs_get_inode - get inode for kernfs_node
* @sb: super block * @sb: super block
* @sd: sysfs_dirent to allocate inode for * @kn: kernfs_node to allocate inode for
* *
* Get inode for @sd. If such inode doesn't exist, a new inode * Get inode for @kn. If such inode doesn't exist, a new inode is
* is allocated and basics are initialized. New inode is * allocated and basics are initialized. New inode is returned
* returned locked. * locked.
* *
* LOCKING: * LOCKING:
* Kernel thread context (may sleep). * Kernel thread context (may sleep).
...@@ -332,44 +333,44 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) ...@@ -332,44 +333,44 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
* RETURNS: * RETURNS:
* Pointer to allocated inode on success, NULL on failure. * Pointer to allocated inode on success, NULL on failure.
*/ */
struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd) struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
{ {
struct inode *inode; struct inode *inode;
inode = iget_locked(sb, sd->s_ino); inode = iget_locked(sb, kn->s_ino);
if (inode && (inode->i_state & I_NEW)) if (inode && (inode->i_state & I_NEW))
sysfs_init_inode(sd, inode); sysfs_init_inode(kn, inode);
return inode; return inode;
} }
/* /*
* The sysfs_dirent serves as both an inode and a directory entry for sysfs. * The kernfs_node serves as both an inode and a directory entry for sysfs.
* To prevent the sysfs inode numbers from being freed prematurely we take a * To prevent the sysfs inode numbers from being freed prematurely we take
* reference to sysfs_dirent from the sysfs inode. A * a reference to kernfs_node from the sysfs inode. A
* super_operations.evict_inode() implementation is needed to drop that * super_operations.evict_inode() implementation is needed to drop that
* reference upon inode destruction. * reference upon inode destruction.
*/ */
void sysfs_evict_inode(struct inode *inode) void sysfs_evict_inode(struct inode *inode)
{ {
struct sysfs_dirent *sd = inode->i_private; struct kernfs_node *kn = inode->i_private;
truncate_inode_pages(&inode->i_data, 0); truncate_inode_pages(&inode->i_data, 0);
clear_inode(inode); clear_inode(inode);
kernfs_put(sd); kernfs_put(kn);
} }
int sysfs_permission(struct inode *inode, int mask) int sysfs_permission(struct inode *inode, int mask)
{ {
struct sysfs_dirent *sd; struct kernfs_node *kn;
if (mask & MAY_NOT_BLOCK) if (mask & MAY_NOT_BLOCK)
return -ECHILD; return -ECHILD;
sd = inode->i_private; kn = inode->i_private;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
sysfs_refresh_inode(sd, inode); sysfs_refresh_inode(kn, inode);
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
return generic_permission(inode, mask); return generic_permission(inode, mask);
......
...@@ -31,24 +31,24 @@ struct sysfs_inode_attrs { ...@@ -31,24 +31,24 @@ struct sysfs_inode_attrs {
/* SYSFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ /* SYSFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
/** /**
* kernfs_root - find out the kernfs_root a sysfs_dirent belongs to * kernfs_root - find out the kernfs_root a kernfs_node belongs to
* @sd: sysfs_dirent of interest * @kn: kernfs_node of interest
* *
* Return the kernfs_root @sd belongs to. * Return the kernfs_root @kn belongs to.
*/ */
static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd) 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 parent exists, it's always a dir; otherwise, @sd is a dir */
if (sd->s_parent) if (kn->s_parent)
sd = sd->s_parent; kn = kn->s_parent;
return sd->s_dir.root; return kn->s_dir.root;
} }
/* /*
* Context structure to be used while adding/removing nodes. * Context structure to be used while adding/removing nodes.
*/ */
struct sysfs_addrm_cxt { struct sysfs_addrm_cxt {
struct sysfs_dirent *removed; struct kernfs_node *removed;
}; };
/* /*
...@@ -62,10 +62,10 @@ struct sysfs_super_info { ...@@ -62,10 +62,10 @@ struct sysfs_super_info {
struct kernfs_root *root; struct kernfs_root *root;
/* /*
* Each sb is associated with one namespace tag, currently the network * Each sb is associated with one namespace tag, currently the
* namespace of the task which mounted this sysfs instance. If multiple * network namespace of the task which mounted this sysfs instance.
* tags become necessary, make the following an array and compare * If multiple tags become necessary, make the following an array
* sysfs_dirent tag against every entry. * and compare kernfs_node tag against every entry.
*/ */
const void *ns; const void *ns;
}; };
...@@ -76,7 +76,7 @@ extern struct kmem_cache *sysfs_dir_cachep; ...@@ -76,7 +76,7 @@ extern struct kmem_cache *sysfs_dir_cachep;
/* /*
* inode.c * inode.c
*/ */
struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd); struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
void sysfs_evict_inode(struct inode *inode); void sysfs_evict_inode(struct inode *inode);
int sysfs_permission(struct inode *inode, int mask); int sysfs_permission(struct inode *inode, int mask);
int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
...@@ -98,21 +98,21 @@ extern const struct dentry_operations sysfs_dentry_ops; ...@@ -98,21 +98,21 @@ extern const struct dentry_operations sysfs_dentry_ops;
extern const struct file_operations sysfs_dir_operations; extern const struct file_operations sysfs_dir_operations;
extern const struct inode_operations sysfs_dir_inode_operations; extern const struct inode_operations sysfs_dir_inode_operations;
struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); struct kernfs_node *sysfs_get_active(struct kernfs_node *kn);
void sysfs_put_active(struct sysfs_dirent *sd); void sysfs_put_active(struct kernfs_node *kn);
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt); void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
struct sysfs_dirent *parent_sd); struct kernfs_node *parent);
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
const char *name, umode_t mode, int type); const char *name, umode_t mode, int type);
/* /*
* file.c * file.c
*/ */
extern const struct file_operations kernfs_file_operations; extern const struct file_operations kernfs_file_operations;
void sysfs_unmap_bin_file(struct sysfs_dirent *sd); void sysfs_unmap_bin_file(struct kernfs_node *kn);
/* /*
* symlink.c * symlink.c
......
...@@ -39,7 +39,7 @@ static int sysfs_fill_super(struct super_block *sb) ...@@ -39,7 +39,7 @@ static int sysfs_fill_super(struct super_block *sb)
/* get root inode, initialize and unlock it */ /* get root inode, initialize and unlock it */
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
inode = sysfs_get_inode(sb, info->root->sd); inode = sysfs_get_inode(sb, info->root->kn);
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
if (!inode) { if (!inode) {
pr_debug("sysfs: could not get root inode\n"); pr_debug("sysfs: could not get root inode\n");
...@@ -52,8 +52,8 @@ static int sysfs_fill_super(struct super_block *sb) ...@@ -52,8 +52,8 @@ static int sysfs_fill_super(struct super_block *sb)
pr_debug("%s: could not get root dentry!\n", __func__); pr_debug("%s: could not get root dentry!\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
kernfs_get(info->root->sd); kernfs_get(info->root->kn);
root->d_fsdata = info->root->sd; root->d_fsdata = info->root->kn;
sb->s_root = root; sb->s_root = root;
sb->s_d_op = &sysfs_dentry_ops; sb->s_d_op = &sysfs_dentry_ops;
return 0; return 0;
...@@ -145,7 +145,7 @@ struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, ...@@ -145,7 +145,7 @@ struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
void kernfs_kill_sb(struct super_block *sb) void kernfs_kill_sb(struct super_block *sb)
{ {
struct sysfs_super_info *info = sysfs_info(sb); struct sysfs_super_info *info = sysfs_info(sb);
struct sysfs_dirent *root_sd = sb->s_root->d_fsdata; struct kernfs_node *root_kn = sb->s_root->d_fsdata;
/* /*
* Remove the superblock from fs_supers/s_instances * Remove the superblock from fs_supers/s_instances
...@@ -153,13 +153,13 @@ void kernfs_kill_sb(struct super_block *sb) ...@@ -153,13 +153,13 @@ void kernfs_kill_sb(struct super_block *sb)
*/ */
kill_anon_super(sb); kill_anon_super(sb);
kfree(info); kfree(info);
kernfs_put(root_sd); kernfs_put(root_kn);
} }
void __init kernfs_init(void) void __init kernfs_init(void)
{ {
sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache", sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache",
sizeof(struct sysfs_dirent), sizeof(struct kernfs_node),
0, SLAB_PANIC, NULL); 0, SLAB_PANIC, NULL);
sysfs_inode_init(); sysfs_inode_init();
} }
...@@ -22,50 +22,50 @@ ...@@ -22,50 +22,50 @@
* *
* Returns the created node on success, ERR_PTR() value on error. * Returns the created node on success, ERR_PTR() value on error.
*/ */
struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
const char *name, const char *name,
struct sysfs_dirent *target) struct kernfs_node *target)
{ {
struct sysfs_dirent *sd; struct kernfs_node *kn;
struct sysfs_addrm_cxt acxt; struct sysfs_addrm_cxt acxt;
int error; int error;
sd = sysfs_new_dirent(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO, kn = sysfs_new_dirent(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO,
SYSFS_KOBJ_LINK); SYSFS_KOBJ_LINK);
if (!sd) if (!kn)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (kernfs_ns_enabled(parent)) if (kernfs_ns_enabled(parent))
sd->s_ns = target->s_ns; kn->s_ns = target->s_ns;
sd->s_symlink.target_sd = target; kn->s_symlink.target_kn = target;
kernfs_get(target); /* ref owned by symlink */ kernfs_get(target); /* ref owned by symlink */
sysfs_addrm_start(&acxt); sysfs_addrm_start(&acxt);
error = sysfs_add_one(&acxt, sd, parent); error = sysfs_add_one(&acxt, kn, parent);
sysfs_addrm_finish(&acxt); sysfs_addrm_finish(&acxt);
if (!error) if (!error)
return sd; return kn;
kernfs_put(sd); kernfs_put(kn);
return ERR_PTR(error); return ERR_PTR(error);
} }
static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, static int sysfs_get_target_path(struct kernfs_node *parent,
struct sysfs_dirent *target_sd, char *path) struct kernfs_node *target, char *path)
{ {
struct sysfs_dirent *base, *sd; struct kernfs_node *base, *kn;
char *s = path; char *s = path;
int len = 0; int len = 0;
/* go up to the root, stop at the base */ /* go up to the root, stop at the base */
base = parent_sd; base = parent;
while (base->s_parent) { while (base->s_parent) {
sd = target_sd->s_parent; kn = target->s_parent;
while (sd->s_parent && base != sd) while (kn->s_parent && base != kn)
sd = sd->s_parent; kn = kn->s_parent;
if (base == sd) if (base == kn)
break; break;
strcpy(s, "../"); strcpy(s, "../");
...@@ -74,10 +74,10 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, ...@@ -74,10 +74,10 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
} }
/* determine end of target string for reverse fillup */ /* determine end of target string for reverse fillup */
sd = target_sd; kn = target;
while (sd->s_parent && sd != base) { while (kn->s_parent && kn != base) {
len += strlen(sd->s_name) + 1; len += strlen(kn->s_name) + 1;
sd = sd->s_parent; kn = kn->s_parent;
} }
/* check limits */ /* check limits */
...@@ -88,16 +88,16 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, ...@@ -88,16 +88,16 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
return -ENAMETOOLONG; return -ENAMETOOLONG;
/* reverse fillup of target string from target to base */ /* reverse fillup of target string from target to base */
sd = target_sd; kn = target;
while (sd->s_parent && sd != base) { while (kn->s_parent && kn != base) {
int slen = strlen(sd->s_name); int slen = strlen(kn->s_name);
len -= slen; len -= slen;
strncpy(s + len, sd->s_name, slen); strncpy(s + len, kn->s_name, slen);
if (len) if (len)
s[--len] = '/'; s[--len] = '/';
sd = sd->s_parent; kn = kn->s_parent;
} }
return 0; return 0;
...@@ -105,13 +105,13 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, ...@@ -105,13 +105,13 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
static int sysfs_getlink(struct dentry *dentry, char *path) static int sysfs_getlink(struct dentry *dentry, char *path)
{ {
struct sysfs_dirent *sd = dentry->d_fsdata; struct kernfs_node *kn = dentry->d_fsdata;
struct sysfs_dirent *parent_sd = sd->s_parent; struct kernfs_node *parent = kn->s_parent;
struct sysfs_dirent *target_sd = sd->s_symlink.target_sd; struct kernfs_node *target = kn->s_symlink.target_kn;
int error; int error;
mutex_lock(&sysfs_mutex); mutex_lock(&sysfs_mutex);
error = sysfs_get_target_path(parent_sd, target_sd, path); error = sysfs_get_target_path(parent, target, path);
mutex_unlock(&sysfs_mutex); mutex_unlock(&sysfs_mutex);
return error; return error;
......
...@@ -21,23 +21,23 @@ DEFINE_SPINLOCK(sysfs_symlink_target_lock); ...@@ -21,23 +21,23 @@ DEFINE_SPINLOCK(sysfs_symlink_target_lock);
/** /**
* sysfs_pathname - return full path to sysfs dirent * sysfs_pathname - return full path to sysfs dirent
* @sd: sysfs_dirent whose path we want * @kn: kernfs_node whose path we want
* @path: caller allocated buffer of size PATH_MAX * @path: caller allocated buffer of size PATH_MAX
* *
* Gives the name "/" to the sysfs_root entry; any path returned * Gives the name "/" to the sysfs_root entry; any path returned
* is relative to wherever sysfs is mounted. * is relative to wherever sysfs is mounted.
*/ */
static char *sysfs_pathname(struct sysfs_dirent *sd, char *path) static char *sysfs_pathname(struct kernfs_node *kn, char *path)
{ {
if (sd->s_parent) { if (kn->s_parent) {
sysfs_pathname(sd->s_parent, path); sysfs_pathname(kn->s_parent, path);
strlcat(path, "/", PATH_MAX); strlcat(path, "/", PATH_MAX);
} }
strlcat(path, sd->s_name, PATH_MAX); strlcat(path, kn->s_name, PATH_MAX);
return path; return path;
} }
void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name) void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
{ {
char *path; char *path;
...@@ -61,26 +61,26 @@ void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name) ...@@ -61,26 +61,26 @@ void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name)
*/ */
int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
{ {
struct sysfs_dirent *parent_sd, *sd; struct kernfs_node *parent, *kn;
BUG_ON(!kobj); BUG_ON(!kobj);
if (kobj->parent) if (kobj->parent)
parent_sd = kobj->parent->sd; parent = kobj->parent->sd;
else else
parent_sd = sysfs_root_sd; parent = sysfs_root_kn;
if (!parent_sd) if (!parent)
return -ENOENT; return -ENOENT;
sd = kernfs_create_dir_ns(parent_sd, kobject_name(kobj), kobj, ns); kn = kernfs_create_dir_ns(parent, kobject_name(kobj), kobj, ns);
if (IS_ERR(sd)) { if (IS_ERR(kn)) {
if (PTR_ERR(sd) == -EEXIST) if (PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(parent_sd, kobject_name(kobj)); sysfs_warn_dup(parent, kobject_name(kobj));
return PTR_ERR(sd); return PTR_ERR(kn);
} }
kobj->sd = sd; kobj->sd = kn;
return 0; return 0;
} }
...@@ -94,47 +94,47 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) ...@@ -94,47 +94,47 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
*/ */
void sysfs_remove_dir(struct kobject *kobj) void sysfs_remove_dir(struct kobject *kobj)
{ {
struct sysfs_dirent *sd = kobj->sd; struct kernfs_node *kn = kobj->sd;
/* /*
* In general, kboject owner is responsible for ensuring removal * In general, kboject owner is responsible for ensuring removal
* doesn't race with other operations and sysfs doesn't provide any * doesn't race with other operations and sysfs doesn't provide any
* protection; however, when @kobj is used as a symlink target, the * protection; however, when @kobj is used as a symlink target, the
* symlinking entity usually doesn't own @kobj and thus has no * symlinking entity usually doesn't own @kobj and thus has no
* control over removal. @kobj->sd may be removed anytime and * control over removal. @kobj->sd may be removed anytime
* symlink code may end up dereferencing an already freed sd. * and symlink code may end up dereferencing an already freed node.
* *
* sysfs_symlink_target_lock synchronizes @kobj->sd disassociation * sysfs_symlink_target_lock synchronizes @kobj->sd
* against symlink operations so that symlink code can safely * disassociation against symlink operations so that symlink code
* dereference @kobj->sd. * can safely dereference @kobj->sd.
*/ */
spin_lock(&sysfs_symlink_target_lock); spin_lock(&sysfs_symlink_target_lock);
kobj->sd = NULL; kobj->sd = NULL;
spin_unlock(&sysfs_symlink_target_lock); spin_unlock(&sysfs_symlink_target_lock);
if (sd) { if (kn) {
WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
kernfs_remove(sd); kernfs_remove(kn);
} }
} }
int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
const void *new_ns) const void *new_ns)
{ {
struct sysfs_dirent *parent_sd = kobj->sd->s_parent; struct kernfs_node *parent = kobj->sd->s_parent;
return kernfs_rename_ns(kobj->sd, parent_sd, new_name, new_ns); return kernfs_rename_ns(kobj->sd, parent, new_name, new_ns);
} }
int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
const void *new_ns) const void *new_ns)
{ {
struct sysfs_dirent *sd = kobj->sd; struct kernfs_node *kn = kobj->sd;
struct sysfs_dirent *new_parent_sd; struct kernfs_node *new_parent;
BUG_ON(!sd->s_parent); BUG_ON(!kn->s_parent);
new_parent_sd = new_parent_kobj && new_parent_kobj->sd ? new_parent = new_parent_kobj && new_parent_kobj->sd ?
new_parent_kobj->sd : sysfs_root_sd; new_parent_kobj->sd : sysfs_root_kn;
return kernfs_rename_ns(sd, new_parent_sd, sd->s_name, new_ns); return kernfs_rename_ns(kn, new_parent, kn->s_name, new_ns);
} }
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
#include "../kernfs/kernfs-internal.h" #include "../kernfs/kernfs-internal.h"
/* /*
* Determine ktype->sysfs_ops for the given sysfs_dirent. This function * Determine ktype->sysfs_ops for the given kernfs_node. This function
* must be called while holding an active reference. * must be called while holding an active reference.
*/ */
static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) static const struct sysfs_ops *sysfs_file_ops(struct kernfs_node *kn)
{ {
struct kobject *kobj = sd->s_parent->priv; struct kobject *kobj = kn->s_parent->priv;
if (sd->s_flags & SYSFS_FLAG_LOCKDEP) if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
lockdep_assert_held(sd); lockdep_assert_held(kn);
return kobj->ktype ? kobj->ktype->sysfs_ops : NULL; return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
} }
...@@ -42,8 +42,8 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) ...@@ -42,8 +42,8 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
static int sysfs_kf_seq_show(struct seq_file *sf, void *v) static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
{ {
struct sysfs_open_file *of = sf->private; struct sysfs_open_file *of = sf->private;
struct kobject *kobj = of->sd->s_parent->priv; struct kobject *kobj = of->kn->s_parent->priv;
const struct sysfs_ops *ops = sysfs_file_ops(of->sd); const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
ssize_t count; ssize_t count;
char *buf; char *buf;
...@@ -59,7 +59,7 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v) ...@@ -59,7 +59,7 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
* if @ops->show() isn't implemented. * if @ops->show() isn't implemented.
*/ */
if (ops->show) { if (ops->show) {
count = ops->show(kobj, of->sd->priv, buf); count = ops->show(kobj, of->kn->priv, buf);
if (count < 0) if (count < 0)
return count; return count;
} }
...@@ -81,8 +81,8 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v) ...@@ -81,8 +81,8 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf, static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf,
size_t count, loff_t pos) size_t count, loff_t pos)
{ {
struct bin_attribute *battr = of->sd->priv; struct bin_attribute *battr = of->kn->priv;
struct kobject *kobj = of->sd->s_parent->priv; struct kobject *kobj = of->kn->s_parent->priv;
loff_t size = file_inode(of->file)->i_size; loff_t size = file_inode(of->file)->i_size;
if (!count) if (!count)
...@@ -105,21 +105,21 @@ static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf, ...@@ -105,21 +105,21 @@ static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf,
static ssize_t sysfs_kf_write(struct sysfs_open_file *of, char *buf, static ssize_t sysfs_kf_write(struct sysfs_open_file *of, char *buf,
size_t count, loff_t pos) size_t count, loff_t pos)
{ {
const struct sysfs_ops *ops = sysfs_file_ops(of->sd); const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
struct kobject *kobj = of->sd->s_parent->priv; struct kobject *kobj = of->kn->s_parent->priv;
if (!count) if (!count)
return 0; return 0;
return ops->store(kobj, of->sd->priv, buf, count); return ops->store(kobj, of->kn->priv, buf, count);
} }
/* kernfs write callback for bin sysfs files */ /* kernfs write callback for bin sysfs files */
static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf, static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf,
size_t count, loff_t pos) size_t count, loff_t pos)
{ {
struct bin_attribute *battr = of->sd->priv; struct bin_attribute *battr = of->kn->priv;
struct kobject *kobj = of->sd->s_parent->priv; struct kobject *kobj = of->kn->s_parent->priv;
loff_t size = file_inode(of->file)->i_size; loff_t size = file_inode(of->file)->i_size;
if (size) { if (size) {
...@@ -139,30 +139,30 @@ static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf, ...@@ -139,30 +139,30 @@ static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf,
static int sysfs_kf_bin_mmap(struct sysfs_open_file *of, static int sysfs_kf_bin_mmap(struct sysfs_open_file *of,
struct vm_area_struct *vma) struct vm_area_struct *vma)
{ {
struct bin_attribute *battr = of->sd->priv; struct bin_attribute *battr = of->kn->priv;
struct kobject *kobj = of->sd->s_parent->priv; struct kobject *kobj = of->kn->s_parent->priv;
return battr->mmap(of->file, kobj, battr, vma); return battr->mmap(of->file, kobj, battr, vma);
} }
void sysfs_notify(struct kobject *k, const char *dir, const char *attr) void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr)
{ {
struct sysfs_dirent *sd = k->sd, *tmp; struct kernfs_node *kn = kobj->sd, *tmp;
if (sd && dir) if (kn && dir)
sd = kernfs_find_and_get(sd, dir); kn = kernfs_find_and_get(kn, dir);
else else
kernfs_get(sd); kernfs_get(kn);
if (sd && attr) { if (kn && attr) {
tmp = kernfs_find_and_get(sd, attr); tmp = kernfs_find_and_get(kn, attr);
kernfs_put(sd); kernfs_put(kn);
sd = tmp; kn = tmp;
} }
if (sd) { if (kn) {
kernfs_notify(sd); kernfs_notify(kn);
kernfs_put(sd); kernfs_put(kn);
} }
} }
EXPORT_SYMBOL_GPL(sysfs_notify); EXPORT_SYMBOL_GPL(sysfs_notify);
...@@ -202,17 +202,17 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = { ...@@ -202,17 +202,17 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = {
.mmap = sysfs_kf_bin_mmap, .mmap = sysfs_kf_bin_mmap,
}; };
int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, int sysfs_add_file_mode_ns(struct kernfs_node *parent,
const struct attribute *attr, bool is_bin, const struct attribute *attr, bool is_bin,
umode_t mode, const void *ns) umode_t mode, const void *ns)
{ {
struct lock_class_key *key = NULL; struct lock_class_key *key = NULL;
const struct kernfs_ops *ops; const struct kernfs_ops *ops;
struct sysfs_dirent *sd; struct kernfs_node *kn;
loff_t size; loff_t size;
if (!is_bin) { if (!is_bin) {
struct kobject *kobj = dir_sd->priv; struct kobject *kobj = parent->priv;
const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops;
/* every kobject with an attribute needs a ktype assigned */ /* every kobject with an attribute needs a ktype assigned */
...@@ -252,20 +252,20 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, ...@@ -252,20 +252,20 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
if (!attr->ignore_lockdep) if (!attr->ignore_lockdep)
key = attr->key ?: (struct lock_class_key *)&attr->skey; key = attr->key ?: (struct lock_class_key *)&attr->skey;
#endif #endif
sd = kernfs_create_file_ns_key(dir_sd, attr->name, mode, size, kn = kernfs_create_file_ns_key(parent, attr->name, mode, size,
ops, (void *)attr, ns, key); ops, (void *)attr, ns, key);
if (IS_ERR(sd)) { if (IS_ERR(kn)) {
if (PTR_ERR(sd) == -EEXIST) if (PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(dir_sd, attr->name); sysfs_warn_dup(parent, attr->name);
return PTR_ERR(sd); return PTR_ERR(kn);
} }
return 0; return 0;
} }
int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, int sysfs_add_file(struct kernfs_node *parent, const struct attribute *attr,
bool is_bin) bool is_bin)
{ {
return sysfs_add_file_mode_ns(dir_sd, attr, is_bin, attr->mode, NULL); return sysfs_add_file_mode_ns(parent, attr, is_bin, attr->mode, NULL);
} }
/** /**
...@@ -307,21 +307,21 @@ EXPORT_SYMBOL_GPL(sysfs_create_files); ...@@ -307,21 +307,21 @@ EXPORT_SYMBOL_GPL(sysfs_create_files);
int sysfs_add_file_to_group(struct kobject *kobj, int sysfs_add_file_to_group(struct kobject *kobj,
const struct attribute *attr, const char *group) const struct attribute *attr, const char *group)
{ {
struct sysfs_dirent *dir_sd; struct kernfs_node *parent;
int error; int error;
if (group) { if (group) {
dir_sd = kernfs_find_and_get(kobj->sd, group); parent = kernfs_find_and_get(kobj->sd, group);
} else { } else {
dir_sd = kobj->sd; parent = kobj->sd;
kernfs_get(dir_sd); kernfs_get(parent);
} }
if (!dir_sd) if (!parent)
return -ENOENT; return -ENOENT;
error = sysfs_add_file(dir_sd, attr, false); error = sysfs_add_file(parent, attr, false);
kernfs_put(dir_sd); kernfs_put(parent);
return error; return error;
} }
...@@ -337,20 +337,20 @@ EXPORT_SYMBOL_GPL(sysfs_add_file_to_group); ...@@ -337,20 +337,20 @@ EXPORT_SYMBOL_GPL(sysfs_add_file_to_group);
int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr, int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
umode_t mode) umode_t mode)
{ {
struct sysfs_dirent *sd; struct kernfs_node *kn;
struct iattr newattrs; struct iattr newattrs;
int rc; int rc;
sd = kernfs_find_and_get(kobj->sd, attr->name); kn = kernfs_find_and_get(kobj->sd, attr->name);
if (!sd) if (!kn)
return -ENOENT; return -ENOENT;
newattrs.ia_mode = (mode & S_IALLUGO) | (sd->s_mode & ~S_IALLUGO); newattrs.ia_mode = (mode & S_IALLUGO) | (kn->s_mode & ~S_IALLUGO);
newattrs.ia_valid = ATTR_MODE; newattrs.ia_valid = ATTR_MODE;
rc = kernfs_setattr(sd, &newattrs); rc = kernfs_setattr(kn, &newattrs);
kernfs_put(sd); kernfs_put(kn);
return rc; return rc;
} }
EXPORT_SYMBOL_GPL(sysfs_chmod_file); EXPORT_SYMBOL_GPL(sysfs_chmod_file);
...@@ -366,9 +366,9 @@ EXPORT_SYMBOL_GPL(sysfs_chmod_file); ...@@ -366,9 +366,9 @@ EXPORT_SYMBOL_GPL(sysfs_chmod_file);
void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
const void *ns) const void *ns)
{ {
struct sysfs_dirent *dir_sd = kobj->sd; struct kernfs_node *parent = kobj->sd;
kernfs_remove_by_name_ns(dir_sd, attr->name, ns); kernfs_remove_by_name_ns(parent, attr->name, ns);
} }
EXPORT_SYMBOL_GPL(sysfs_remove_file_ns); EXPORT_SYMBOL_GPL(sysfs_remove_file_ns);
...@@ -389,18 +389,18 @@ EXPORT_SYMBOL_GPL(sysfs_remove_files); ...@@ -389,18 +389,18 @@ EXPORT_SYMBOL_GPL(sysfs_remove_files);
void sysfs_remove_file_from_group(struct kobject *kobj, void sysfs_remove_file_from_group(struct kobject *kobj,
const struct attribute *attr, const char *group) const struct attribute *attr, const char *group)
{ {
struct sysfs_dirent *dir_sd; struct kernfs_node *parent;
if (group) { if (group) {
dir_sd = kernfs_find_and_get(kobj->sd, group); parent = kernfs_find_and_get(kobj->sd, group);
} else { } else {
dir_sd = kobj->sd; parent = kobj->sd;
kernfs_get(dir_sd); kernfs_get(parent);
} }
if (dir_sd) { if (parent) {
kernfs_remove_by_name(dir_sd, attr->name); kernfs_remove_by_name(parent, attr->name);
kernfs_put(dir_sd); kernfs_put(parent);
} }
} }
EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group); EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "sysfs.h" #include "sysfs.h"
static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, static void remove_files(struct kernfs_node *parent, struct kobject *kobj,
const struct attribute_group *grp) const struct attribute_group *grp)
{ {
struct attribute *const *attr; struct attribute *const *attr;
...@@ -26,13 +26,13 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, ...@@ -26,13 +26,13 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
if (grp->attrs) if (grp->attrs)
for (attr = grp->attrs; *attr; attr++) for (attr = grp->attrs; *attr; attr++)
kernfs_remove_by_name(dir_sd, (*attr)->name); kernfs_remove_by_name(parent, (*attr)->name);
if (grp->bin_attrs) if (grp->bin_attrs)
for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++)
sysfs_remove_bin_file(kobj, *bin_attr); sysfs_remove_bin_file(kobj, *bin_attr);
} }
static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, static int create_files(struct kernfs_node *parent, struct kobject *kobj,
const struct attribute_group *grp, int update) const struct attribute_group *grp, int update)
{ {
struct attribute *const *attr; struct attribute *const *attr;
...@@ -49,20 +49,20 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, ...@@ -49,20 +49,20 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
* re-adding (if required) the file. * re-adding (if required) the file.
*/ */
if (update) if (update)
kernfs_remove_by_name(dir_sd, (*attr)->name); kernfs_remove_by_name(parent, (*attr)->name);
if (grp->is_visible) { if (grp->is_visible) {
mode = grp->is_visible(kobj, *attr, i); mode = grp->is_visible(kobj, *attr, i);
if (!mode) if (!mode)
continue; continue;
} }
error = sysfs_add_file_mode_ns(dir_sd, *attr, false, error = sysfs_add_file_mode_ns(parent, *attr, false,
(*attr)->mode | mode, (*attr)->mode | mode,
NULL); NULL);
if (unlikely(error)) if (unlikely(error))
break; break;
} }
if (error) { if (error) {
remove_files(dir_sd, kobj, grp); remove_files(parent, kobj, grp);
goto exit; goto exit;
} }
} }
...@@ -76,7 +76,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, ...@@ -76,7 +76,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
break; break;
} }
if (error) if (error)
remove_files(dir_sd, kobj, grp); remove_files(parent, kobj, grp);
} }
exit: exit:
return error; return error;
...@@ -86,7 +86,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, ...@@ -86,7 +86,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
static int internal_create_group(struct kobject *kobj, int update, static int internal_create_group(struct kobject *kobj, int update,
const struct attribute_group *grp) const struct attribute_group *grp)
{ {
struct sysfs_dirent *sd; struct kernfs_node *kn;
int error; int error;
BUG_ON(!kobj || (!update && !kobj->sd)); BUG_ON(!kobj || (!update && !kobj->sd));
...@@ -100,21 +100,21 @@ static int internal_create_group(struct kobject *kobj, int update, ...@@ -100,21 +100,21 @@ static int internal_create_group(struct kobject *kobj, int update,
return -EINVAL; return -EINVAL;
} }
if (grp->name) { if (grp->name) {
sd = kernfs_create_dir(kobj->sd, grp->name, kobj); kn = kernfs_create_dir(kobj->sd, grp->name, kobj);
if (IS_ERR(sd)) { if (IS_ERR(kn)) {
if (PTR_ERR(sd) == -EEXIST) if (PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(kobj->sd, grp->name); sysfs_warn_dup(kobj->sd, grp->name);
return PTR_ERR(sd); return PTR_ERR(kn);
} }
} else } else
sd = kobj->sd; kn = kobj->sd;
kernfs_get(sd); kernfs_get(kn);
error = create_files(sd, kobj, grp, update); error = create_files(kn, kobj, grp, update);
if (error) { if (error) {
if (grp->name) if (grp->name)
kernfs_remove(sd); kernfs_remove(kn);
} }
kernfs_put(sd); kernfs_put(kn);
return error; return error;
} }
...@@ -204,27 +204,27 @@ EXPORT_SYMBOL_GPL(sysfs_update_group); ...@@ -204,27 +204,27 @@ EXPORT_SYMBOL_GPL(sysfs_update_group);
void sysfs_remove_group(struct kobject *kobj, void sysfs_remove_group(struct kobject *kobj,
const struct attribute_group *grp) const struct attribute_group *grp)
{ {
struct sysfs_dirent *dir_sd = kobj->sd; struct kernfs_node *parent = kobj->sd;
struct sysfs_dirent *sd; struct kernfs_node *kn;
if (grp->name) { if (grp->name) {
sd = kernfs_find_and_get(dir_sd, grp->name); kn = kernfs_find_and_get(parent, grp->name);
if (!sd) { if (!kn) {
WARN(!sd, KERN_WARNING WARN(!kn, KERN_WARNING
"sysfs group %p not found for kobject '%s'\n", "sysfs group %p not found for kobject '%s'\n",
grp, kobject_name(kobj)); grp, kobject_name(kobj));
return; return;
} }
} else { } else {
sd = dir_sd; kn = parent;
kernfs_get(sd); kernfs_get(kn);
} }
remove_files(sd, kobj, grp); remove_files(kn, kobj, grp);
if (grp->name) if (grp->name)
kernfs_remove(sd); kernfs_remove(kn);
kernfs_put(sd); kernfs_put(kn);
} }
EXPORT_SYMBOL_GPL(sysfs_remove_group); EXPORT_SYMBOL_GPL(sysfs_remove_group);
...@@ -260,22 +260,22 @@ EXPORT_SYMBOL_GPL(sysfs_remove_groups); ...@@ -260,22 +260,22 @@ EXPORT_SYMBOL_GPL(sysfs_remove_groups);
int sysfs_merge_group(struct kobject *kobj, int sysfs_merge_group(struct kobject *kobj,
const struct attribute_group *grp) const struct attribute_group *grp)
{ {
struct sysfs_dirent *dir_sd; struct kernfs_node *parent;
int error = 0; int error = 0;
struct attribute *const *attr; struct attribute *const *attr;
int i; int i;
dir_sd = kernfs_find_and_get(kobj->sd, grp->name); parent = kernfs_find_and_get(kobj->sd, grp->name);
if (!dir_sd) if (!parent)
return -ENOENT; return -ENOENT;
for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr))
error = sysfs_add_file(dir_sd, *attr, false); error = sysfs_add_file(parent, *attr, false);
if (error) { if (error) {
while (--i >= 0) while (--i >= 0)
kernfs_remove_by_name(dir_sd, (*--attr)->name); kernfs_remove_by_name(parent, (*--attr)->name);
} }
kernfs_put(dir_sd); kernfs_put(parent);
return error; return error;
} }
...@@ -289,14 +289,14 @@ EXPORT_SYMBOL_GPL(sysfs_merge_group); ...@@ -289,14 +289,14 @@ EXPORT_SYMBOL_GPL(sysfs_merge_group);
void sysfs_unmerge_group(struct kobject *kobj, void sysfs_unmerge_group(struct kobject *kobj,
const struct attribute_group *grp) const struct attribute_group *grp)
{ {
struct sysfs_dirent *dir_sd; struct kernfs_node *parent;
struct attribute *const *attr; struct attribute *const *attr;
dir_sd = kernfs_find_and_get(kobj->sd, grp->name); parent = kernfs_find_and_get(kobj->sd, grp->name);
if (dir_sd) { if (parent) {
for (attr = grp->attrs; *attr; ++attr) for (attr = grp->attrs; *attr; ++attr)
kernfs_remove_by_name(dir_sd, (*attr)->name); kernfs_remove_by_name(parent, (*attr)->name);
kernfs_put(dir_sd); kernfs_put(parent);
} }
} }
EXPORT_SYMBOL_GPL(sysfs_unmerge_group); EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
...@@ -311,15 +311,15 @@ EXPORT_SYMBOL_GPL(sysfs_unmerge_group); ...@@ -311,15 +311,15 @@ EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
struct kobject *target, const char *link_name) struct kobject *target, const char *link_name)
{ {
struct sysfs_dirent *dir_sd; struct kernfs_node *parent;
int error = 0; int error = 0;
dir_sd = kernfs_find_and_get(kobj->sd, group_name); parent = kernfs_find_and_get(kobj->sd, group_name);
if (!dir_sd) if (!parent)
return -ENOENT; return -ENOENT;
error = sysfs_create_link_sd(dir_sd, target, link_name); error = sysfs_create_link_sd(parent, target, link_name);
kernfs_put(dir_sd); kernfs_put(parent);
return error; return error;
} }
...@@ -334,12 +334,12 @@ EXPORT_SYMBOL_GPL(sysfs_add_link_to_group); ...@@ -334,12 +334,12 @@ EXPORT_SYMBOL_GPL(sysfs_add_link_to_group);
void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
const char *link_name) const char *link_name)
{ {
struct sysfs_dirent *dir_sd; struct kernfs_node *parent;
dir_sd = kernfs_find_and_get(kobj->sd, group_name); parent = kernfs_find_and_get(kobj->sd, group_name);
if (dir_sd) { if (parent) {
kernfs_remove_by_name(dir_sd, link_name); kernfs_remove_by_name(parent, link_name);
kernfs_put(dir_sd); kernfs_put(parent);
} }
} }
EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "sysfs.h" #include "sysfs.h"
static struct kernfs_root *sysfs_root; static struct kernfs_root *sysfs_root;
struct sysfs_dirent *sysfs_root_sd; struct kernfs_node *sysfs_root_kn;
static struct dentry *sysfs_mount(struct file_system_type *fs_type, static struct dentry *sysfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data) int flags, const char *dev_name, void *data)
...@@ -66,7 +66,7 @@ int __init sysfs_init(void) ...@@ -66,7 +66,7 @@ int __init sysfs_init(void)
if (IS_ERR(sysfs_root)) if (IS_ERR(sysfs_root))
return PTR_ERR(sysfs_root); return PTR_ERR(sysfs_root);
sysfs_root_sd = sysfs_root->sd; sysfs_root_kn = sysfs_root->kn;
err = register_filesystem(&sysfs_fs_type); err = register_filesystem(&sysfs_fs_type);
if (err) { if (err) {
......
...@@ -18,66 +18,66 @@ ...@@ -18,66 +18,66 @@
#include "sysfs.h" #include "sysfs.h"
static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd, static int sysfs_do_create_link_sd(struct kernfs_node *parent,
struct kobject *target, struct kobject *target_kobj,
const char *name, int warn) const char *name, int warn)
{ {
struct sysfs_dirent *sd, *target_sd = NULL; struct kernfs_node *kn, *target = NULL;
BUG_ON(!name || !parent_sd); BUG_ON(!name || !parent);
/* /*
* We don't own @target and it may be removed at any time. * We don't own @target_kobj and it may be removed at any time.
* Synchronize using sysfs_symlink_target_lock. See * Synchronize using sysfs_symlink_target_lock. See
* sysfs_remove_dir() for details. * sysfs_remove_dir() for details.
*/ */
spin_lock(&sysfs_symlink_target_lock); spin_lock(&sysfs_symlink_target_lock);
if (target->sd) { if (target_kobj->sd) {
target_sd = target->sd; target = target_kobj->sd;
kernfs_get(target_sd); kernfs_get(target);
} }
spin_unlock(&sysfs_symlink_target_lock); spin_unlock(&sysfs_symlink_target_lock);
if (!target_sd) if (!target)
return -ENOENT; return -ENOENT;
sd = kernfs_create_link(parent_sd, name, target_sd); kn = kernfs_create_link(parent, name, target);
kernfs_put(target_sd); kernfs_put(target);
if (!IS_ERR(sd)) if (!IS_ERR(kn))
return 0; return 0;
if (warn && PTR_ERR(sd) == -EEXIST) if (warn && PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(parent_sd, name); sysfs_warn_dup(parent, name);
return PTR_ERR(sd); return PTR_ERR(kn);
} }
/** /**
* sysfs_create_link_sd - create symlink to a given object. * sysfs_create_link_sd - create symlink to a given object.
* @sd: directory we're creating the link in. * @kn: directory we're creating the link in.
* @target: object we're pointing to. * @target: object we're pointing to.
* @name: name of the symlink. * @name: name of the symlink.
*/ */
int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target,
const char *name) const char *name)
{ {
return sysfs_do_create_link_sd(sd, target, name, 1); return sysfs_do_create_link_sd(kn, target, name, 1);
} }
static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target, static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
const char *name, int warn) const char *name, int warn)
{ {
struct sysfs_dirent *parent_sd = NULL; struct kernfs_node *parent = NULL;
if (!kobj) if (!kobj)
parent_sd = sysfs_root_sd; parent = sysfs_root_kn;
else else
parent_sd = kobj->sd; parent = kobj->sd;
if (!parent_sd) if (!parent)
return -EFAULT; return -EFAULT;
return sysfs_do_create_link_sd(parent_sd, target, name, warn); return sysfs_do_create_link_sd(parent, target, name, warn);
} }
/** /**
...@@ -141,14 +141,14 @@ void sysfs_delete_link(struct kobject *kobj, struct kobject *targ, ...@@ -141,14 +141,14 @@ void sysfs_delete_link(struct kobject *kobj, struct kobject *targ,
*/ */
void sysfs_remove_link(struct kobject *kobj, const char *name) void sysfs_remove_link(struct kobject *kobj, const char *name)
{ {
struct sysfs_dirent *parent_sd = NULL; struct kernfs_node *parent = NULL;
if (!kobj) if (!kobj)
parent_sd = sysfs_root_sd; parent = sysfs_root_kn;
else else
parent_sd = kobj->sd; parent = kobj->sd;
kernfs_remove_by_name(parent_sd, name); kernfs_remove_by_name(parent, name);
} }
EXPORT_SYMBOL_GPL(sysfs_remove_link); EXPORT_SYMBOL_GPL(sysfs_remove_link);
...@@ -165,33 +165,33 @@ EXPORT_SYMBOL_GPL(sysfs_remove_link); ...@@ -165,33 +165,33 @@ EXPORT_SYMBOL_GPL(sysfs_remove_link);
int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ, int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
const char *old, const char *new, const void *new_ns) const char *old, const char *new, const void *new_ns)
{ {
struct sysfs_dirent *parent_sd, *sd = NULL; struct kernfs_node *parent, *kn = NULL;
const void *old_ns = NULL; const void *old_ns = NULL;
int result; int result;
if (!kobj) if (!kobj)
parent_sd = sysfs_root_sd; parent = sysfs_root_kn;
else else
parent_sd = kobj->sd; parent = kobj->sd;
if (targ->sd) if (targ->sd)
old_ns = targ->sd->s_ns; old_ns = targ->sd->s_ns;
result = -ENOENT; result = -ENOENT;
sd = kernfs_find_and_get_ns(parent_sd, old, old_ns); kn = kernfs_find_and_get_ns(parent, old, old_ns);
if (!sd) if (!kn)
goto out; goto out;
result = -EINVAL; result = -EINVAL;
if (sysfs_type(sd) != SYSFS_KOBJ_LINK) if (sysfs_type(kn) != SYSFS_KOBJ_LINK)
goto out; goto out;
if (sd->s_symlink.target_sd->priv != targ) if (kn->s_symlink.target_kn->priv != targ)
goto out; goto out;
result = kernfs_rename_ns(sd, parent_sd, new, new_ns); result = kernfs_rename_ns(kn, parent, new, new_ns);
out: out:
kernfs_put(sd); kernfs_put(kn);
return result; return result;
} }
EXPORT_SYMBOL_GPL(sysfs_rename_link_ns); EXPORT_SYMBOL_GPL(sysfs_rename_link_ns);
...@@ -16,28 +16,28 @@ ...@@ -16,28 +16,28 @@
/* /*
* mount.c * mount.c
*/ */
extern struct sysfs_dirent *sysfs_root_sd; extern struct kernfs_node *sysfs_root_kn;
/* /*
* dir.c * dir.c
*/ */
extern spinlock_t sysfs_symlink_target_lock; extern spinlock_t sysfs_symlink_target_lock;
void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name); void sysfs_warn_dup(struct kernfs_node *parent, const char *name);
/* /*
* file.c * file.c
*/ */
int sysfs_add_file(struct sysfs_dirent *dir_sd, int sysfs_add_file(struct kernfs_node *parent,
const struct attribute *attr, bool is_bin); const struct attribute *attr, bool is_bin);
int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, int sysfs_add_file_mode_ns(struct kernfs_node *parent,
const struct attribute *attr, bool is_bin, const struct attribute *attr, bool is_bin,
umode_t amode, const void *ns); umode_t amode, const void *ns);
/* /*
* symlink.c * symlink.c
*/ */
int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target,
const char *name); const char *name);
#endif /* __SYSFS_INTERNAL_H */ #endif /* __SYSFS_INTERNAL_H */
...@@ -46,61 +46,61 @@ enum kernfs_node_flag { ...@@ -46,61 +46,61 @@ enum kernfs_node_flag {
SYSFS_FLAG_LOCKDEP = 0x0100, SYSFS_FLAG_LOCKDEP = 0x0100,
}; };
/* type-specific structures for sysfs_dirent->s_* union members */ /* type-specific structures for kernfs_node union members */
struct sysfs_elem_dir { struct kernfs_elem_dir {
unsigned long subdirs; unsigned long subdirs;
/* children rbtree starts here and goes through sd->s_rb */ /* children rbtree starts here and goes through kn->s_rb */
struct rb_root children; struct rb_root children;
/* /*
* The kernfs hierarchy this directory belongs to. This fits * The kernfs hierarchy this directory belongs to. This fits
* better directly in sysfs_dirent but is here to save space. * better directly in kernfs_node but is here to save space.
*/ */
struct kernfs_root *root; struct kernfs_root *root;
}; };
struct sysfs_elem_symlink { struct kernfs_elem_symlink {
struct sysfs_dirent *target_sd; struct kernfs_node *target_kn;
}; };
struct sysfs_elem_attr { struct kernfs_elem_attr {
const struct kernfs_ops *ops; const struct kernfs_ops *ops;
struct sysfs_open_dirent *open; struct sysfs_open_dirent *open;
loff_t size; loff_t size;
}; };
/* /*
* sysfs_dirent - the building block of sysfs hierarchy. Each and every * kernfs_node - the building block of kernfs hierarchy. Each and every
* sysfs node is represented by single sysfs_dirent. Most fields are * kernfs node is represented by single kernfs_node. Most fields are
* private to kernfs and shouldn't be accessed directly by kernfs users. * private to kernfs and shouldn't be accessed directly by kernfs users.
* *
* As long as s_count reference is held, the sysfs_dirent itself is * As long as s_count reference is held, the kernfs_node itself is
* accessible. Dereferencing s_elem or any other outer entity * accessible. Dereferencing elem or any other outer entity requires
* requires s_active reference. * active reference.
*/ */
struct sysfs_dirent { struct kernfs_node {
atomic_t s_count; atomic_t s_count;
atomic_t s_active; atomic_t s_active;
#ifdef CONFIG_DEBUG_LOCK_ALLOC #ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map; struct lockdep_map dep_map;
#endif #endif
/* the following two fields are published */ /* the following two fields are published */
struct sysfs_dirent *s_parent; struct kernfs_node *s_parent;
const char *s_name; const char *s_name;
struct rb_node s_rb; struct rb_node s_rb;
union { union {
struct completion *completion; struct completion *completion;
struct sysfs_dirent *removed_list; struct kernfs_node *removed_list;
} u; } u;
const void *s_ns; /* namespace tag */ const void *s_ns; /* namespace tag */
unsigned int s_hash; /* ns + name hash */ unsigned int s_hash; /* ns + name hash */
union { union {
struct sysfs_elem_dir s_dir; struct kernfs_elem_dir s_dir;
struct sysfs_elem_symlink s_symlink; struct kernfs_elem_symlink s_symlink;
struct sysfs_elem_attr s_attr; struct kernfs_elem_attr s_attr;
}; };
void *priv; void *priv;
...@@ -113,7 +113,7 @@ struct sysfs_dirent { ...@@ -113,7 +113,7 @@ struct sysfs_dirent {
struct kernfs_root { struct kernfs_root {
/* published fields */ /* published fields */
struct sysfs_dirent *sd; struct kernfs_node *kn;
/* private fields, do not use outside kernfs proper */ /* private fields, do not use outside kernfs proper */
struct ida ino_ida; struct ida ino_ida;
...@@ -121,7 +121,7 @@ struct kernfs_root { ...@@ -121,7 +121,7 @@ struct kernfs_root {
struct sysfs_open_file { struct sysfs_open_file {
/* published fields */ /* published fields */
struct sysfs_dirent *sd; struct kernfs_node *kn;
struct file *file; struct file *file;
/* private fields, do not use outside kernfs proper */ /* private fields, do not use outside kernfs proper */
...@@ -170,64 +170,64 @@ struct kernfs_ops { ...@@ -170,64 +170,64 @@ struct kernfs_ops {
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
static inline enum kernfs_node_type sysfs_type(struct sysfs_dirent *sd) static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
{ {
return sd->s_flags & SYSFS_TYPE_MASK; return kn->s_flags & SYSFS_TYPE_MASK;
} }
/** /**
* kernfs_enable_ns - enable namespace under a directory * kernfs_enable_ns - enable namespace under a directory
* @sd: directory of interest, should be empty * @kn: directory of interest, should be empty
* *
* This is to be called right after @sd is created to enable namespace * This is to be called right after @kn is created to enable namespace
* under it. All children of @sd must have non-NULL namespace tags and * under it. All children of @kn must have non-NULL namespace tags and
* only the ones which match the super_block's tag will be visible. * only the ones which match the super_block's tag will be visible.
*/ */
static inline void kernfs_enable_ns(struct sysfs_dirent *sd) static inline void kernfs_enable_ns(struct kernfs_node *kn)
{ {
WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
WARN_ON_ONCE(!RB_EMPTY_ROOT(&sd->s_dir.children)); WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->s_dir.children));
sd->s_flags |= SYSFS_FLAG_NS; kn->s_flags |= SYSFS_FLAG_NS;
} }
/** /**
* kernfs_ns_enabled - test whether namespace is enabled * kernfs_ns_enabled - test whether namespace is enabled
* @sd: the node to test * @kn: the node to test
* *
* Test whether namespace filtering is enabled for the children of @ns. * Test whether namespace filtering is enabled for the children of @ns.
*/ */
static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd) static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
{ {
return sd->s_flags & SYSFS_FLAG_NS; return kn->s_flags & SYSFS_FLAG_NS;
} }
struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
const char *name, const void *ns); const char *name, const void *ns);
void kernfs_get(struct sysfs_dirent *sd); void kernfs_get(struct kernfs_node *kn);
void kernfs_put(struct sysfs_dirent *sd); void kernfs_put(struct kernfs_node *kn);
struct kernfs_root *kernfs_create_root(void *priv); struct kernfs_root *kernfs_create_root(void *priv);
void kernfs_destroy_root(struct kernfs_root *root); void kernfs_destroy_root(struct kernfs_root *root);
struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
const char *name, void *priv, const char *name, void *priv,
const void *ns); const void *ns);
struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
const char *name, const char *name,
umode_t mode, loff_t size, umode_t mode, loff_t size,
const struct kernfs_ops *ops, const struct kernfs_ops *ops,
void *priv, const void *ns, void *priv, const void *ns,
struct lock_class_key *key); struct lock_class_key *key);
struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
const char *name, const char *name,
struct sysfs_dirent *target); struct kernfs_node *target);
void kernfs_remove(struct sysfs_dirent *sd); void kernfs_remove(struct kernfs_node *kn);
int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name, int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
const void *ns); const void *ns);
int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
const char *new_name, const void *new_ns); const char *new_name, const void *new_ns);
int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr); int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
void kernfs_notify(struct sysfs_dirent *sd); void kernfs_notify(struct kernfs_node *kn);
const void *kernfs_super_ns(struct super_block *sb); const void *kernfs_super_ns(struct super_block *sb);
struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
...@@ -238,60 +238,60 @@ void kernfs_init(void); ...@@ -238,60 +238,60 @@ void kernfs_init(void);
#else /* CONFIG_SYSFS */ #else /* CONFIG_SYSFS */
static inline enum kernfs_node_type sysfs_type(struct sysfs_dirent *sd) static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
{ return 0; } /* whatever */ { return 0; } /* whatever */
static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { } static inline void kernfs_enable_ns(struct kernfs_node *kn) { }
static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd) static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
{ return false; } { return false; }
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_find_and_get_ns(struct sysfs_dirent *parent, const char *name, kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
const void *ns) const void *ns)
{ return NULL; } { return NULL; }
static inline void kernfs_get(struct sysfs_dirent *sd) { } static inline void kernfs_get(struct kernfs_node *kn) { }
static inline void kernfs_put(struct sysfs_dirent *sd) { } static inline void kernfs_put(struct kernfs_node *kn) { }
static inline struct kernfs_root *kernfs_create_root(void *priv) static inline struct kernfs_root *kernfs_create_root(void *priv)
{ return ERR_PTR(-ENOSYS); } { return ERR_PTR(-ENOSYS); }
static inline void kernfs_destroy_root(struct kernfs_root *root) { } static inline void kernfs_destroy_root(struct kernfs_root *root) { }
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv, kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, void *priv,
const void *ns) const void *ns)
{ return ERR_PTR(-ENOSYS); } { return ERR_PTR(-ENOSYS); }
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_create_file_ns_key(struct sysfs_dirent *parent, const char *name, kernfs_create_file_ns_key(struct kernfs_node *parent, const char *name,
umode_t mode, loff_t size, umode_t mode, loff_t size,
const struct kernfs_ops *ops, void *priv, const struct kernfs_ops *ops, void *priv,
const void *ns, struct lock_class_key *key) const void *ns, struct lock_class_key *key)
{ return ERR_PTR(-ENOSYS); } { return ERR_PTR(-ENOSYS); }
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_create_link(struct sysfs_dirent *parent, const char *name, kernfs_create_link(struct kernfs_node *parent, const char *name,
struct sysfs_dirent *target) struct kernfs_node *target)
{ return ERR_PTR(-ENOSYS); } { return ERR_PTR(-ENOSYS); }
static inline void kernfs_remove(struct sysfs_dirent *sd) { } static inline void kernfs_remove(struct kernfs_node *kn) { }
static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn,
const char *name, const void *ns) const char *name, const void *ns)
{ return -ENOSYS; } { return -ENOSYS; }
static inline int kernfs_rename_ns(struct sysfs_dirent *sd, static inline int kernfs_rename_ns(struct kernfs_node *kn,
struct sysfs_dirent *new_parent, struct kernfs_node *new_parent,
const char *new_name, const void *new_ns) const char *new_name, const void *new_ns)
{ return -ENOSYS; } { return -ENOSYS; }
static inline int kernfs_setattr(struct sysfs_dirent *sd, static inline int kernfs_setattr(struct kernfs_node *kn,
const struct iattr *iattr) const struct iattr *iattr)
{ return -ENOSYS; } { return -ENOSYS; }
static inline void kernfs_notify(struct sysfs_dirent *sd) { } static inline void kernfs_notify(struct kernfs_node *kn) { }
static inline const void *kernfs_super_ns(struct super_block *sb) static inline const void *kernfs_super_ns(struct super_block *sb)
{ return NULL; } { return NULL; }
...@@ -307,20 +307,20 @@ static inline void kernfs_init(void) { } ...@@ -307,20 +307,20 @@ static inline void kernfs_init(void) { }
#endif /* CONFIG_SYSFS */ #endif /* CONFIG_SYSFS */
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_find_and_get(struct sysfs_dirent *sd, const char *name) kernfs_find_and_get(struct kernfs_node *kn, const char *name)
{ {
return kernfs_find_and_get_ns(sd, name, NULL); return kernfs_find_and_get_ns(kn, name, NULL);
} }
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv) kernfs_create_dir(struct kernfs_node *parent, const char *name, void *priv)
{ {
return kernfs_create_dir_ns(parent, name, priv, NULL); return kernfs_create_dir_ns(parent, name, priv, NULL);
} }
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name, kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
umode_t mode, loff_t size, const struct kernfs_ops *ops, umode_t mode, loff_t size, const struct kernfs_ops *ops,
void *priv, const void *ns) void *priv, const void *ns)
{ {
...@@ -333,14 +333,14 @@ kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name, ...@@ -333,14 +333,14 @@ kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name,
ns, key); ns, key);
} }
static inline struct sysfs_dirent * static inline struct kernfs_node *
kernfs_create_file(struct sysfs_dirent *parent, const char *name, umode_t mode, kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode,
loff_t size, const struct kernfs_ops *ops, void *priv) loff_t size, const struct kernfs_ops *ops, void *priv)
{ {
return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL); return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL);
} }
static inline int kernfs_remove_by_name(struct sysfs_dirent *parent, static inline int kernfs_remove_by_name(struct kernfs_node *parent,
const char *name) const char *name)
{ {
return kernfs_remove_by_name_ns(parent, name, NULL); return kernfs_remove_by_name_ns(parent, name, NULL);
......
...@@ -64,7 +64,7 @@ struct kobject { ...@@ -64,7 +64,7 @@ struct kobject {
struct kobject *parent; struct kobject *parent;
struct kset *kset; struct kset *kset;
struct kobj_type *ktype; struct kobj_type *ktype;
struct sysfs_dirent *sd; struct kernfs_node *sd;
struct kref kref; struct kref kref;
#ifdef CONFIG_DEBUG_KOBJECT_RELEASE #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
struct delayed_work release; struct delayed_work release;
......
...@@ -438,26 +438,26 @@ static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target ...@@ -438,26 +438,26 @@ static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target
return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL); return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
} }
static inline void sysfs_notify_dirent(struct sysfs_dirent *sd) static inline void sysfs_notify_dirent(struct kernfs_node *kn)
{ {
kernfs_notify(sd); kernfs_notify(kn);
} }
static inline struct sysfs_dirent * static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent,
sysfs_get_dirent(struct sysfs_dirent *parent_sd, const unsigned char *name) const unsigned char *name)
{ {
return kernfs_find_and_get(parent_sd, name); return kernfs_find_and_get(parent, name);
} }
static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn)
{ {
kernfs_get(sd); kernfs_get(kn);
return sd; return kn;
} }
static inline void sysfs_put(struct sysfs_dirent *sd) static inline void sysfs_put(struct kernfs_node *kn)
{ {
kernfs_put(sd); kernfs_put(kn);
} }
#endif /* _SYSFS_H_ */ #endif /* _SYSFS_H_ */
...@@ -556,7 +556,7 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent) ...@@ -556,7 +556,7 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)
*/ */
void kobject_del(struct kobject *kobj) void kobject_del(struct kobject *kobj)
{ {
struct sysfs_dirent *sd; struct kernfs_node *sd;
if (!kobj) if (!kobj)
return; return;
......
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