struct rb_node **node = &kn->parent->dir.children.rb_node;
struct rb_node *parent = NULL;
- if (sysfs_type(kn) == SYSFS_DIR)
+ if (kernfs_type(kn) == KERNFS_DIR)
kn->parent->dir.subdirs++;
while (*node) {
*/
static void sysfs_unlink_sibling(struct kernfs_node *kn)
{
- if (sysfs_type(kn) == SYSFS_DIR)
+ if (kernfs_type(kn) == KERNFS_DIR)
kn->parent->dir.subdirs--;
rb_erase(&kn->rb, &kn->parent->dir.children);
if (!atomic_inc_unless_negative(&kn->active))
return NULL;
- if (kn->flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & KERNFS_LOCKDEP)
rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_);
return kn;
}
if (unlikely(!kn))
return;
- if (kn->flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & KERNFS_LOCKDEP)
rwsem_release(&kn->dep_map, 1, _RET_IP_);
v = atomic_dec_return(&kn->active);
- if (likely(v != SD_DEACTIVATED_BIAS))
+ if (likely(v != KN_DEACTIVATED_BIAS))
return;
/*
DECLARE_COMPLETION_ONSTACK(wait);
int v;
- BUG_ON(!(kn->flags & SYSFS_FLAG_REMOVED));
+ BUG_ON(!(kn->flags & KERNFS_REMOVED));
- if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF))
+ if (!(kernfs_type(kn) & KERNFS_ACTIVE_REF))
return;
kn->u.completion = (void *)&wait;
/* atomic_add_return() is a mb(), put_active() will always see
* the updated kn->u.completion.
*/
- v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->active);
+ v = atomic_add_return(KN_DEACTIVATED_BIAS, &kn->active);
- if (v != SD_DEACTIVATED_BIAS) {
+ if (v != KN_DEACTIVATED_BIAS) {
lock_contended(&kn->dep_map, _RET_IP_);
wait_for_completion(&wait);
}
*/
parent = kn->parent;
- WARN(!(kn->flags & SYSFS_FLAG_REMOVED),
+ WARN(!(kn->flags & KERNFS_REMOVED),
"sysfs: free using entry: %s/%s\n",
parent ? parent->name : "", kn->name);
- if (sysfs_type(kn) == SYSFS_KOBJ_LINK)
+ if (kernfs_type(kn) == KERNFS_LINK)
kernfs_put(kn->symlink.target_kn);
- if (sysfs_type(kn) & SYSFS_COPY_NAME)
+ if (kernfs_type(kn) & KERNFS_COPY_NAME)
kfree(kn->name);
if (kn->iattr) {
if (kn->iattr->ia_secdata)
static int sysfs_dentry_delete(const struct dentry *dentry)
{
struct kernfs_node *kn = dentry->d_fsdata;
- return !(kn && !(kn->flags & SYSFS_FLAG_REMOVED));
+ return !(kn && !(kn->flags & KERNFS_REMOVED));
}
static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
mutex_lock(&sysfs_mutex);
/* The sysfs dirent has been deleted */
- if (kn->flags & SYSFS_FLAG_REMOVED)
+ if (kn->flags & KERNFS_REMOVED)
goto out_bad;
/* The sysfs dirent has been moved? */
struct kernfs_node *kn;
int ret;
- if (type & SYSFS_COPY_NAME) {
+ if (type & KERNFS_COPY_NAME) {
name = dup_name = kstrdup(name, GFP_KERNEL);
if (!name)
return NULL;
kn->name = name;
kn->mode = mode;
- kn->flags = type | SYSFS_FLAG_REMOVED;
+ kn->flags = type | KERNFS_REMOVED;
return kn;
return -EINVAL;
}
- if (sysfs_type(parent) != SYSFS_DIR)
+ if (kernfs_type(parent) != KERNFS_DIR)
return -EINVAL;
kn->hash = sysfs_name_hash(kn->name, kn->ns);
}
/* Mark the entry added into directory tree */
- kn->flags &= ~SYSFS_FLAG_REMOVED;
+ kn->flags &= ~KERNFS_REMOVED;
return 0;
}
* Removal can be called multiple times on the same node. Only the
* first invocation is effective and puts the base ref.
*/
- if (kn->flags & SYSFS_FLAG_REMOVED)
+ if (kn->flags & KERNFS_REMOVED)
return;
if (kn->parent) {
}
}
- kn->flags |= SYSFS_FLAG_REMOVED;
+ kn->flags |= KERNFS_REMOVED;
kn->u.removed_list = acxt->removed;
acxt->removed = kn;
}
ida_init(&root->ino_ida);
- kn = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR);
+ kn = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, KERNFS_DIR);
if (!kn) {
ida_destroy(&root->ino_ida);
kfree(root);
return ERR_PTR(-ENOMEM);
}
- kn->flags &= ~SYSFS_FLAG_REMOVED;
+ kn->flags &= ~KERNFS_REMOVED;
kn->priv = priv;
kn->dir.root = root;
int rc;
/* allocate */
- kn = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR);
+ kn = sysfs_new_dirent(kernfs_root(parent), name, mode, KERNFS_DIR);
if (!kn)
return ERR_PTR(-ENOMEM);
last = pos;
- if (sysfs_type(pos) != SYSFS_DIR)
+ if (kernfs_type(pos) != KERNFS_DIR)
break;
rbn = rb_first(&pos->dir.children);
struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
{
if (pos) {
- int valid = !(pos->flags & SYSFS_FLAG_REMOVED) &&
+ int valid = !(pos->flags & KERNFS_REMOVED) &&
pos->parent == parent && hash == pos->hash;
kernfs_put(pos);
if (!valid)
*/
static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn)
{
- if (kn->flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & KERNFS_LOCKDEP)
lockdep_assert_held(kn);
return kn->attr.ops;
}
{
struct kernfs_open_file *of = kernfs_of(file);
- if (of->kn->flags & SYSFS_FLAG_HAS_SEQ_SHOW)
+ if (of->kn->flags & KERNFS_HAS_SEQ_SHOW)
return seq_read(file, user_buf, count, ppos);
else
return kernfs_file_direct_read(of, user_buf, count, ppos);
* without grabbing @of->mutex by testing HAS_MMAP flag. See the
* comment in kernfs_file_open() for more details.
*/
- if (!(of->kn->flags & SYSFS_FLAG_HAS_MMAP))
+ if (!(of->kn->flags & KERNFS_HAS_MMAP))
return -ENODEV;
mutex_lock(&of->mutex);
struct kernfs_open_node *on;
struct kernfs_open_file *of;
- if (!(kn->flags & SYSFS_FLAG_HAS_MMAP))
+ if (!(kn->flags & KERNFS_HAS_MMAP))
return;
spin_lock_irq(&kernfs_open_node_lock);
spin_lock_irqsave(&kernfs_open_node_lock, flags);
- if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) {
+ if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
on = kn->attr.open;
if (on) {
atomic_inc(&on->event);
int rc;
kn = sysfs_new_dirent(kernfs_root(parent), name,
- (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR);
+ (mode & S_IALLUGO) | S_IFREG, KERNFS_FILE);
if (!kn)
return ERR_PTR(-ENOMEM);
#ifdef CONFIG_DEBUG_LOCK_ALLOC
if (key) {
lockdep_init_map(&kn->dep_map, "s_active", key, 0);
- kn->flags |= SYSFS_FLAG_LOCKDEP;
+ kn->flags |= KERNFS_LOCKDEP;
}
#endif
* ref. Cache their existence in flags.
*/
if (ops->seq_show)
- kn->flags |= SYSFS_FLAG_HAS_SEQ_SHOW;
+ kn->flags |= KERNFS_HAS_SEQ_SHOW;
if (ops->mmap)
- kn->flags |= SYSFS_FLAG_HAS_MMAP;
+ kn->flags |= KERNFS_HAS_MMAP;
sysfs_addrm_start(&acxt);
rc = sysfs_add_one(&acxt, kn, parent);
attrs->ia_secdata_len);
}
- if (sysfs_type(kn) == SYSFS_DIR)
+ if (kernfs_type(kn) == KERNFS_DIR)
set_nlink(inode, kn->dir.subdirs + 2);
}
sysfs_refresh_inode(kn, inode);
/* initialize inode according to type */
- switch (sysfs_type(kn)) {
- case SYSFS_DIR:
+ switch (kernfs_type(kn)) {
+ case KERNFS_DIR:
inode->i_op = &sysfs_dir_inode_operations;
inode->i_fop = &sysfs_dir_operations;
break;
- case SYSFS_KOBJ_ATTR:
+ case KERNFS_FILE:
inode->i_size = kn->attr.size;
inode->i_fop = &kernfs_file_operations;
break;
- case SYSFS_KOBJ_LINK:
+ case KERNFS_LINK:
inode->i_op = &sysfs_symlink_inode_operations;
break;
default:
struct simple_xattrs xattrs;
};
-#define SD_DEACTIVATED_BIAS INT_MIN
+#define KN_DEACTIVATED_BIAS INT_MIN
-/* SYSFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
+/* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
/**
* kernfs_root - find out the kernfs_root a kernfs_node belongs to
int error;
kn = sysfs_new_dirent(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO,
- SYSFS_KOBJ_LINK);
+ KERNFS_LINK);
if (!kn)
return ERR_PTR(-ENOMEM);
spin_unlock(&sysfs_symlink_target_lock);
if (kn) {
- WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
+ WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR);
kernfs_remove(kn);
}
}
{
struct kobject *kobj = kn->parent->priv;
- if (kn->flags & SYSFS_FLAG_LOCKDEP)
+ if (kn->flags & KERNFS_LOCKDEP)
lockdep_assert_held(kn);
return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
}
goto out;
result = -EINVAL;
- if (sysfs_type(kn) != SYSFS_KOBJ_LINK)
+ if (kernfs_type(kn) != KERNFS_LINK)
goto out;
if (kn->symlink.target_kn->priv != targ)
goto out;
struct kernfs_iattrs;
enum kernfs_node_type {
- SYSFS_DIR = 0x0001,
- SYSFS_KOBJ_ATTR = 0x0002,
- SYSFS_KOBJ_LINK = 0x0004,
+ KERNFS_DIR = 0x0001,
+ KERNFS_FILE = 0x0002,
+ KERNFS_LINK = 0x0004,
};
-#define SYSFS_TYPE_MASK 0x000f
-#define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
-#define SYSFS_ACTIVE_REF SYSFS_KOBJ_ATTR
-#define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
+#define KERNFS_TYPE_MASK 0x000f
+#define KERNFS_COPY_NAME (KERNFS_DIR | KERNFS_LINK)
+#define KERNFS_ACTIVE_REF KERNFS_FILE
+#define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK
enum kernfs_node_flag {
- SYSFS_FLAG_REMOVED = 0x0010,
- SYSFS_FLAG_NS = 0x0020,
- SYSFS_FLAG_HAS_SEQ_SHOW = 0x0040,
- SYSFS_FLAG_HAS_MMAP = 0x0080,
- SYSFS_FLAG_LOCKDEP = 0x0100,
+ KERNFS_REMOVED = 0x0010,
+ KERNFS_NS = 0x0020,
+ KERNFS_HAS_SEQ_SHOW = 0x0040,
+ KERNFS_HAS_MMAP = 0x0080,
+ KERNFS_LOCKDEP = 0x0100,
};
/* type-specific structures for kernfs_node union members */
#ifdef CONFIG_SYSFS
-static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
+static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
{
- return kn->flags & SYSFS_TYPE_MASK;
+ return kn->flags & KERNFS_TYPE_MASK;
}
/**
*/
static inline void kernfs_enable_ns(struct kernfs_node *kn)
{
- WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
+ WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR);
WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children));
- kn->flags |= SYSFS_FLAG_NS;
+ kn->flags |= KERNFS_NS;
}
/**
*/
static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
{
- return kn->flags & SYSFS_FLAG_NS;
+ return kn->flags & KERNFS_NS;
}
struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
#else /* CONFIG_SYSFS */
-static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
+static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
{ return 0; } /* whatever */
static inline void kernfs_enable_ns(struct kernfs_node *kn) { }