From: Tejun Heo <tj@kernel.org>
To: gregkh@linuxfoundation.org
Cc: kay@vrfy.org, linux-kernel@vger.kernel.org,
ebiederm@xmission.com, bhelgaas@google.com,
Tejun Heo <tj@kernel.org>
Subject: [PATCH 29/34] sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put()
Date: Thu, 24 Oct 2013 11:49:35 -0400 [thread overview]
Message-ID: <1382629780-10006-30-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1382629780-10006-1-git-send-email-tj@kernel.org>
Introduce kernfs interface for finding, getting and putting
sysfs_dirents.
* sysfs_find_dirent() is renamed to kernfs_find_ns() and lockdep
assertion for sysfs_mutex is added.
* sysfs_get_dirent_ns() is renamed to kernfs_find_and_get().
* Macro inline dancing around __sysfs_get/put() are removed and
kernfs_get/put() are made proper functions implemented in
fs/sysfs/dir.c.
While the conversions are mostly equivalent, there's one difference -
kernfs_get() doesn't return the input param as its return value. This
change is intentional. While passing through the input increases
writability in some areas, it is unnecessary and has been shown to
cause confusion regarding how the last ref is handled.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
fs/sysfs/dir.c | 113 ++++++++++++++++++++++++++++---------------------
fs/sysfs/file.c | 41 ++++++++++--------
fs/sysfs/group.c | 30 +++++++------
fs/sysfs/inode.c | 5 ++-
fs/sysfs/mount.c | 14 ------
fs/sysfs/symlink.c | 16 ++++---
fs/sysfs/sysfs.h | 22 ----------
include/linux/kernfs.h | 21 +++++++++
include/linux/sysfs.h | 35 ++++++---------
9 files changed, 151 insertions(+), 146 deletions(-)
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index f541efa..0e46ff8 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -252,10 +252,31 @@ static void sysfs_free_ino(unsigned int ino)
spin_unlock(&sysfs_ino_lock);
}
-void release_sysfs_dirent(struct sysfs_dirent *sd)
+/**
+ * kernfs_get - get a reference count on a sysfs_dirent
+ * @sd: the target sysfs_dirent
+ */
+void kernfs_get(struct sysfs_dirent *sd)
+{
+ if (sd) {
+ WARN_ON(!atomic_read(&sd->s_count));
+ atomic_inc(&sd->s_count);
+ }
+}
+EXPORT_SYMBOL_GPL(kernfs_get);
+
+/**
+ * kernfs_put - put a reference count on a sysfs_dirent
+ * @sd: the target sysfs_dirent
+ *
+ * Put a reference count of @sd and destroy it if it reached zero.
+ */
+void kernfs_put(struct sysfs_dirent *sd)
{
struct sysfs_dirent *parent_sd;
+ if (!sd || !atomic_dec_and_test(&sd->s_count))
+ return;
repeat:
/* Moving/renaming is always done while holding reference.
* sd->s_parent won't change beneath us.
@@ -267,7 +288,7 @@ void release_sysfs_dirent(struct sysfs_dirent *sd)
parent_sd ? parent_sd->s_name : "", sd->s_name);
if (sysfs_type(sd) == SYSFS_KOBJ_LINK)
- sysfs_put(sd->s_symlink.target_sd);
+ kernfs_put(sd->s_symlink.target_sd);
if (sysfs_type(sd) & SYSFS_COPY_NAME)
kfree(sd->s_name);
if (sd->s_iattr && sd->s_iattr->ia_secdata)
@@ -281,6 +302,7 @@ void release_sysfs_dirent(struct sysfs_dirent *sd)
if (sd && atomic_dec_and_test(&sd->s_count))
goto repeat;
}
+EXPORT_SYMBOL_GPL(kernfs_put);
static int sysfs_dentry_delete(const struct dentry *dentry)
{
@@ -342,7 +364,7 @@ out_bad:
static void sysfs_dentry_release(struct dentry *dentry)
{
- sysfs_put(dentry->d_fsdata);
+ kernfs_put(dentry->d_fsdata);
}
const struct dentry_operations sysfs_dentry_ops = {
@@ -436,7 +458,8 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
return -EINVAL;
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
- sd->s_parent = sysfs_get(parent_sd);
+ sd->s_parent = parent_sd;
+ kernfs_get(parent_sd);
ret = sysfs_link_sibling(sd);
if (ret)
@@ -556,31 +579,28 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
sysfs_deactivate(sd);
sysfs_unmap_bin_file(sd);
- sysfs_put(sd);
+ kernfs_put(sd);
}
}
/**
- * sysfs_find_dirent - find sysfs_dirent with the given name
- * @parent_sd: sysfs_dirent to search under
- * @name: name to look for
- * @ns: the namespace tag to use
- *
- * Look for sysfs_dirent with name @name under @parent_sd.
- *
- * LOCKING:
- * mutex_lock(sysfs_mutex)
+ * kernfs_find_ns - find sysfs_dirent with the given name
+ * @parent: sysfs_dirent to search under
+ * @name: name to look for
+ * @ns: the namespace tag to use
*
- * RETURNS:
- * Pointer to sysfs_dirent if found, NULL if not.
+ * Look for sysfs_dirent with name @name under @parent. Returns pointer to
+ * the found sysfs_dirent on success, %NULL on failure.
*/
-struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
- const unsigned char *name,
- const void *ns)
+static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent,
+ const unsigned char *name,
+ const void *ns)
{
- struct rb_node *node = parent_sd->s_dir.children.rb_node;
+ struct rb_node *node = parent->s_dir.children.rb_node;
unsigned int hash;
+ lockdep_assert_held(&sysfs_mutex);
+
hash = sysfs_name_hash(name, ns);
while (node) {
struct sysfs_dirent *sd;
@@ -599,34 +619,28 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
}
/**
- * sysfs_get_dirent_ns - find and get sysfs_dirent with the given name
- * @parent_sd: sysfs_dirent to search under
- * @name: name to look for
- * @ns: the namespace tag to use
- *
- * Look for sysfs_dirent with name @name under @parent_sd and get
- * it if found.
- *
- * LOCKING:
- * Kernel thread context (may sleep). Grabs sysfs_mutex.
+ * kernfs_find_and_get_ns - find and get sysfs_dirent with the given name
+ * @parent: sysfs_dirent to search under
+ * @name: name to look for
+ * @ns: the namespace tag to use
*
- * RETURNS:
- * Pointer to sysfs_dirent if found, NULL if not.
+ * Look for sysfs_dirent with name @name under @parent and get a reference
+ * if found. This function may sleep and returns pointer to the found
+ * sysfs_dirent on success, %NULL on failure.
*/
-struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
- const unsigned char *name,
- const void *ns)
+struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent,
+ const char *name, const void *ns)
{
struct sysfs_dirent *sd;
mutex_lock(&sysfs_mutex);
- sd = sysfs_find_dirent(parent_sd, name, ns);
- sysfs_get(sd);
+ sd = kernfs_find_ns(parent, name, ns);
+ kernfs_get(sd);
mutex_unlock(&sysfs_mutex);
return sd;
}
-EXPORT_SYMBOL_GPL(sysfs_get_dirent_ns);
+EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
/**
* kernfs_create_dir_ns - create a directory
@@ -662,7 +676,7 @@ struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
if (!rc)
return sd;
- sysfs_put(sd);
+ kernfs_put(sd);
return ERR_PTR(rc);
}
@@ -711,14 +725,15 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
if (parent_sd->s_flags & SYSFS_FLAG_HAS_NS)
ns = sysfs_info(dir->i_sb)->ns;
- sd = sysfs_find_dirent(parent_sd, dentry->d_name.name, ns);
+ sd = kernfs_find_ns(parent_sd, dentry->d_name.name, ns);
/* no such entry */
if (!sd) {
ret = ERR_PTR(-ENOENT);
goto out_unlock;
}
- dentry->d_fsdata = sysfs_get(sd);
+ kernfs_get(sd);
+ dentry->d_fsdata = sd;
/* attach dentry and inode */
inode = sysfs_get_inode(dir->i_sb, sd);
@@ -854,7 +869,7 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
sysfs_addrm_start(&acxt);
- sd = sysfs_find_dirent(dir_sd, name, ns);
+ sd = kernfs_find_ns(dir_sd, name, ns);
if (sd)
__kernfs_remove(&acxt, sd);
@@ -908,7 +923,7 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
goto out; /* nothing to rename */
error = -EEXIST;
- if (sysfs_find_dirent(new_parent, new_name, new_ns))
+ if (kernfs_find_ns(new_parent, new_name, new_ns))
goto out;
/* rename sysfs_dirent */
@@ -926,8 +941,8 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
* Move to the appropriate place in the appropriate directories rbtree.
*/
sysfs_unlink_sibling(sd);
- sysfs_get(new_parent);
- sysfs_put(sd->s_parent);
+ kernfs_get(new_parent);
+ kernfs_put(sd->s_parent);
sd->s_ns = new_ns;
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
sd->s_parent = new_parent;
@@ -968,7 +983,7 @@ static inline unsigned char dt_type(struct sysfs_dirent *sd)
static int sysfs_dir_release(struct inode *inode, struct file *filp)
{
- sysfs_put(filp->private_data);
+ kernfs_put(filp->private_data);
return 0;
}
@@ -979,7 +994,7 @@ static struct sysfs_dirent *sysfs_dir_pos(const void *ns,
int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
pos->s_parent == parent_sd &&
hash == pos->s_hash;
- sysfs_put(pos);
+ kernfs_put(pos);
if (!valid)
pos = NULL;
}
@@ -1043,8 +1058,10 @@ static int sysfs_readdir(struct file *file, struct dir_context *ctx)
unsigned int type = dt_type(pos);
int len = strlen(name);
ino_t ino = pos->s_ino;
+
ctx->pos = pos->s_hash;
- file->private_data = sysfs_get(pos);
+ file->private_data = pos;
+ kernfs_get(pos);
mutex_unlock(&sysfs_mutex);
if (!dir_emit(ctx, name, len, ino, type))
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index fc58883..2b9cfb1 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -867,19 +867,19 @@ void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
struct sysfs_dirent *sd = k->sd, *tmp;
if (sd && dir)
- sd = sysfs_get_dirent(sd, dir);
+ sd = kernfs_find_and_get(sd, dir);
else
- sysfs_get(sd);
+ kernfs_get(sd);
if (sd && attr) {
- tmp = sysfs_get_dirent(sd, attr);
- sysfs_put(sd);
+ tmp = kernfs_find_and_get(sd, attr);
+ kernfs_put(sd);
sd = tmp;
}
if (sd) {
kernfs_notify(sd);
- sysfs_put(sd);
+ kernfs_put(sd);
}
}
EXPORT_SYMBOL_GPL(sysfs_notify);
@@ -1038,7 +1038,7 @@ struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent,
sysfs_addrm_finish(&acxt);
if (rc) {
- sysfs_put(sd);
+ kernfs_put(sd);
return ERR_PTR(rc);
}
return sd;
@@ -1092,16 +1092,18 @@ int sysfs_add_file_to_group(struct kobject *kobj,
struct sysfs_dirent *dir_sd;
int error;
- if (group)
- dir_sd = sysfs_get_dirent(kobj->sd, group);
- else
- dir_sd = sysfs_get(kobj->sd);
+ if (group) {
+ dir_sd = kernfs_find_and_get(kobj->sd, group);
+ } else {
+ dir_sd = kobj->sd;
+ kernfs_get(dir_sd);
+ }
if (!dir_sd)
return -ENOENT;
error = sysfs_add_file(dir_sd, attr, false);
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
return error;
}
@@ -1121,7 +1123,7 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
struct iattr newattrs;
int rc;
- sd = sysfs_get_dirent(kobj->sd, attr->name);
+ sd = kernfs_find_and_get(kobj->sd, attr->name);
if (!sd)
return -ENOENT;
@@ -1130,7 +1132,7 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
rc = kernfs_setattr(sd, &newattrs);
- sysfs_put(sd);
+ kernfs_put(sd);
return rc;
}
EXPORT_SYMBOL_GPL(sysfs_chmod_file);
@@ -1171,13 +1173,16 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
{
struct sysfs_dirent *dir_sd;
- if (group)
- dir_sd = sysfs_get_dirent(kobj->sd, group);
- else
- dir_sd = sysfs_get(kobj->sd);
+ if (group) {
+ dir_sd = kernfs_find_and_get(kobj->sd, group);
+ } else {
+ dir_sd = kobj->sd;
+ kernfs_get(dir_sd);
+ }
+
if (dir_sd) {
kernfs_remove_by_name(dir_sd, attr->name);
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
}
}
EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 9f65cd9..7177532 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -108,13 +108,13 @@ static int internal_create_group(struct kobject *kobj, int update,
}
} else
sd = kobj->sd;
- sysfs_get(sd);
+ kernfs_get(sd);
error = create_files(sd, kobj, grp, update);
if (error) {
if (grp->name)
kernfs_remove(sd);
}
- sysfs_put(sd);
+ kernfs_put(sd);
return error;
}
@@ -208,21 +208,23 @@ void sysfs_remove_group(struct kobject *kobj,
struct sysfs_dirent *sd;
if (grp->name) {
- sd = sysfs_get_dirent(dir_sd, grp->name);
+ sd = kernfs_find_and_get(dir_sd, grp->name);
if (!sd) {
WARN(!sd, KERN_WARNING
"sysfs group %p not found for kobject '%s'\n",
grp, kobject_name(kobj));
return;
}
- } else
- sd = sysfs_get(dir_sd);
+ } else {
+ sd = dir_sd;
+ kernfs_get(sd);
+ }
remove_files(sd, kobj, grp);
if (grp->name)
kernfs_remove(sd);
- sysfs_put(sd);
+ kernfs_put(sd);
}
EXPORT_SYMBOL_GPL(sysfs_remove_group);
@@ -263,7 +265,7 @@ int sysfs_merge_group(struct kobject *kobj,
struct attribute *const *attr;
int i;
- dir_sd = sysfs_get_dirent(kobj->sd, grp->name);
+ dir_sd = kernfs_find_and_get(kobj->sd, grp->name);
if (!dir_sd)
return -ENOENT;
@@ -273,7 +275,7 @@ int sysfs_merge_group(struct kobject *kobj,
while (--i >= 0)
kernfs_remove_by_name(dir_sd, (*--attr)->name);
}
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
return error;
}
@@ -290,11 +292,11 @@ void sysfs_unmerge_group(struct kobject *kobj,
struct sysfs_dirent *dir_sd;
struct attribute *const *attr;
- dir_sd = sysfs_get_dirent(kobj->sd, grp->name);
+ dir_sd = kernfs_find_and_get(kobj->sd, grp->name);
if (dir_sd) {
for (attr = grp->attrs; *attr; ++attr)
kernfs_remove_by_name(dir_sd, (*attr)->name);
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
}
}
EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
@@ -312,12 +314,12 @@ int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
struct sysfs_dirent *dir_sd;
int error = 0;
- dir_sd = sysfs_get_dirent(kobj->sd, group_name);
+ dir_sd = kernfs_find_and_get(kobj->sd, group_name);
if (!dir_sd)
return -ENOENT;
error = sysfs_create_link_sd(dir_sd, target, link_name);
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
return error;
}
@@ -334,10 +336,10 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
{
struct sysfs_dirent *dir_sd;
- dir_sd = sysfs_get_dirent(kobj->sd, group_name);
+ dir_sd = kernfs_find_and_get(kobj->sd, group_name);
if (dir_sd) {
kernfs_remove_by_name(dir_sd, link_name);
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
}
}
EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index b3c717a..bfe4478 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -254,7 +254,8 @@ int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
{
- inode->i_private = sysfs_get(sd);
+ kernfs_get(sd);
+ inode->i_private = sd;
inode->i_mapping->a_ops = &sysfs_aops;
inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
inode->i_op = &sysfs_inode_operations;
@@ -321,7 +322,7 @@ void sysfs_evict_inode(struct inode *inode)
truncate_inode_pages(&inode->i_data, 0);
clear_inode(inode);
- sysfs_put(sd);
+ kernfs_put(sd);
}
int sysfs_permission(struct inode *inode, int mask)
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 8c24bce..852d115 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -184,17 +184,3 @@ out_err:
sysfs_dir_cachep = NULL;
goto out;
}
-
-#undef sysfs_get
-struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
-{
- return __sysfs_get(sd);
-}
-EXPORT_SYMBOL_GPL(sysfs_get);
-
-#undef sysfs_put
-void sysfs_put(struct sysfs_dirent *sd)
-{
- __sysfs_put(sd);
-}
-EXPORT_SYMBOL_GPL(sysfs_put);
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 5600560..1aae6ff 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -43,7 +43,7 @@ struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
sd->s_ns = target->s_ns;
sd->s_symlink.target_sd = target;
- sysfs_get(target); /* ref owned by symlink */
+ kernfs_get(target); /* ref owned by symlink */
sysfs_addrm_start(&acxt);
error = sysfs_add_one(&acxt, sd, parent);
@@ -52,7 +52,7 @@ struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
if (!error)
return sd;
- sysfs_put(sd);
+ kernfs_put(sd);
return ERR_PTR(error);
}
@@ -69,15 +69,17 @@ static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
* sysfs_assoc_lock. Fetch target_sd from it.
*/
spin_lock(&sysfs_assoc_lock);
- if (target->sd)
- target_sd = sysfs_get(target->sd);
+ if (target->sd) {
+ target_sd = target->sd;
+ kernfs_get(target_sd);
+ }
spin_unlock(&sysfs_assoc_lock);
if (!target_sd)
return -ENOENT;
sd = kernfs_create_link(parent_sd, name, target_sd);
- sysfs_put(target_sd);
+ kernfs_put(target_sd);
if (!IS_ERR(sd))
return 0;
@@ -207,7 +209,7 @@ int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
old_ns = targ->sd->s_ns;
result = -ENOENT;
- sd = sysfs_get_dirent_ns(parent_sd, old, old_ns);
+ sd = kernfs_find_and_get_ns(parent_sd, old, old_ns);
if (!sd)
goto out;
@@ -220,7 +222,7 @@ int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
result = kernfs_rename_ns(sd, parent_sd, new, new_ns);
out:
- sysfs_put(sd);
+ kernfs_put(sd);
return result;
}
EXPORT_SYMBOL_GPL(sysfs_rename_link_ns);
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index fdfc603..0b1a781 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -141,30 +141,8 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
struct sysfs_dirent *parent_sd);
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
-struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
- const unsigned char *name,
- const void *ns);
struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
-void release_sysfs_dirent(struct sysfs_dirent *sd);
-
-static inline struct sysfs_dirent *__sysfs_get(struct sysfs_dirent *sd)
-{
- if (sd) {
- WARN_ON(!atomic_read(&sd->s_count));
- atomic_inc(&sd->s_count);
- }
- return sd;
-}
-#define sysfs_get(sd) __sysfs_get(sd)
-
-static inline void __sysfs_put(struct sysfs_dirent *sd)
-{
- if (sd && atomic_dec_and_test(&sd->s_count))
- release_sysfs_dirent(sd);
-}
-#define sysfs_put(sd) __sysfs_put(sd)
-
/*
* inode.c
*/
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 69f95b3..3d1de86 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -70,6 +70,11 @@ struct kernfs_ops {
#ifdef CONFIG_SYSFS
+struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent,
+ const char *name, const void *ns);
+void kernfs_get(struct sysfs_dirent *sd);
+void kernfs_put(struct sysfs_dirent *sd);
+
struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
const char *name, void *priv,
const void *ns);
@@ -93,6 +98,16 @@ void kernfs_notify(struct sysfs_dirent *sd);
#else /* CONFIG_SYSFS */
static inline struct sysfs_dirent *
+kernfs_find_and_get_ns(struct sysfs_dirent *parent, const char *name,
+ const void *ns)
+{
+ return NULL;
+}
+
+static inline void kernfs_get(struct sysfs_dirent *sd) { }
+static inline void kernfs_put(struct sysfs_dirent *sd) { }
+
+static inline struct sysfs_dirent *
kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv,
const void *ns)
{ return NULL; }
@@ -129,6 +144,12 @@ static inline void kernfs_notify(struct sysfs_dirent *sd) { }
#endif /* CONFIG_SYSFS */
static inline struct sysfs_dirent *
+kernfs_find_and_get(struct sysfs_dirent *sd, const char *name)
+{
+ return kernfs_find_and_get_ns(sd, name, NULL);
+}
+
+static inline struct sysfs_dirent *
kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv)
{
return kernfs_create_dir_ns(parent, name, priv, NULL);
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 0ab2b02..cd8f90b 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -243,11 +243,6 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
const char *link_name);
void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
-struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
- const unsigned char *name,
- const void *ns);
-struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
-void sysfs_put(struct sysfs_dirent *sd);
int __must_check sysfs_init(void);
@@ -417,19 +412,6 @@ static inline void sysfs_notify(struct kobject *kobj, const char *dir,
const char *attr)
{
}
-static inline struct sysfs_dirent *
-sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd, const unsigned char *name,
- const void *ns)
-{
- return NULL;
-}
-static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
-{
- return NULL;
-}
-static inline void sysfs_put(struct sysfs_dirent *sd)
-{
-}
static inline int __must_check sysfs_init(void)
{
@@ -456,15 +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);
}
+static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
+{
+ kernfs_notify(sd);
+}
+
static inline struct sysfs_dirent *
sysfs_get_dirent(struct sysfs_dirent *parent_sd, const unsigned char *name)
{
- return sysfs_get_dirent_ns(parent_sd, name, NULL);
+ return kernfs_find_and_get(parent_sd, name);
}
-static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
+static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
{
- kernfs_notify(sd);
+ kernfs_get(sd);
+ return sd;
+}
+
+static inline void sysfs_put(struct sysfs_dirent *sd)
+{
+ kernfs_put(sd);
}
#endif /* _SYSFS_H_ */
--
1.8.3.1
next prev parent reply other threads:[~2013-10-24 15:51 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-24 15:49 Subject: [PATCHSET driver-core-next] sysfs: separate out kernfs, part #1 Tejun Heo
2013-10-24 15:49 ` [PATCH 01/34] sysfs: merge sysfs_elem_bin_attr into sysfs_elem_attr Tejun Heo
2013-10-24 15:49 ` [PATCH 02/34] sysfs: honor bin_attr.attr.ignore_lockdep Tejun Heo
2013-10-24 15:49 ` [PATCH 03/34] sysfs: remove unused sysfs_get_dentry() prototype Tejun Heo
2013-10-24 15:49 ` [PATCH 04/34] sysfs: move sysfs_hash_and_remove() to fs/sysfs/dir.c Tejun Heo
2013-10-24 15:49 ` [PATCH 05/34] sysfs: separate out dup filename warning into a separate function Tejun Heo
2013-10-24 15:49 ` [PATCH 06/34] sysfs: make __sysfs_add_one() fail if the parent isn't a directory Tejun Heo
2013-10-24 15:49 ` [PATCH 07/34] sysfs, kernfs: add skeletons for kernfs Tejun Heo
2013-10-24 15:49 ` [PATCH 08/34] sysfs, kernfs: introduce kernfs_remove[_by_name[_ns]]() Tejun Heo
2013-10-24 15:49 ` [PATCH 09/34] sysfs, kernfs: introduce kernfs_create_link() Tejun Heo
2013-10-24 15:49 ` [PATCH 10/34] sysfs, kernfs: introduce kernfs_rename[_ns]() Tejun Heo
2013-10-24 15:49 ` [PATCH 11/34] sysfs, kernfs: introduce kernfs_setattr() Tejun Heo
2013-10-24 15:49 ` [PATCH 12/34] sysfs, kernfs: replace sysfs_dirent->s_dir.kobj and ->s_attr.[bin_]attr with ->priv Tejun Heo
2013-10-24 15:49 ` [PATCH 13/34] sysfs, kernfs: introduce kernfs_create_dir[_ns]() Tejun Heo
2013-10-24 15:49 ` [PATCH 14/34] sysfs, kernfs: prepare read path for kernfs Tejun Heo
2013-10-26 11:32 ` Pavel Machek
2013-10-27 11:30 ` Tejun Heo
2013-10-28 13:03 ` [PATCH v2 " Tejun Heo
2013-10-28 16:33 ` [PATCH v3 " Tejun Heo
2013-10-24 15:49 ` [PATCH 15/34] sysfs, kernfs: prepare write " Tejun Heo
2013-10-24 15:49 ` [PATCH 16/34] sysfs, kernfs: prepare llseek " Tejun Heo
2013-10-24 15:49 ` [PATCH 17/34] sysfs, kernfs: prepare mmap " Tejun Heo
2013-10-24 15:49 ` [PATCH 18/34] sysfs, kernfs: prepare open, release, poll paths " Tejun Heo
2013-10-24 15:49 ` [PATCH 19/34] sysfs, kernfs: move sysfs_open_file to include/linux/kernfs.h Tejun Heo
2013-10-24 15:49 ` [PATCH 20/34] sysfs, kernfs: introduce kernfs_ops Tejun Heo
2013-10-24 15:49 ` [PATCH 21/34] sysfs, kernfs: add sysfs_dirent->s_attr.size Tejun Heo
2013-10-24 15:49 ` [PATCH 22/34] sysfs, kernfs: remove SYSFS_KOBJ_BIN_ATTR Tejun Heo
2013-10-24 15:49 ` [PATCH 23/34] sysfs, kernfs: introduce kernfs_create_file[_ns]() Tejun Heo
2013-10-24 15:49 ` [PATCH 24/34] sysfs, kernfs: remove sysfs_add_one() Tejun Heo
2013-10-24 15:49 ` [PATCH 25/34] sysfs, kernfs: add kernfs_ops->seq_{start|next|stop}() Tejun Heo
2013-10-28 13:04 ` [PATCH v2 " Tejun Heo
2013-10-24 15:49 ` [PATCH 26/34] sysfs, kernfs: introduce kernfs_notify() Tejun Heo
2013-10-24 15:49 ` [PATCH 27/34] sysfs, kernfs: reorganize SYSFS_* constants Tejun Heo
2013-10-24 15:49 ` [PATCH 28/34] sysfs, kernfs: revamp sysfs_dirent active_ref lockdep annotation Tejun Heo
2013-10-24 15:49 ` Tejun Heo [this message]
2013-10-24 15:49 ` [PATCH 30/34] sysfs, kernfs: move internal decls to fs/kernfs/kernfs-internal.h Tejun Heo
2013-10-24 15:49 ` [PATCH 31/34] sysfs, kernfs: move inode code to fs/kernfs/inode.c Tejun Heo
2013-10-24 15:49 ` [PATCH 32/34] sysfs, kernfs: move dir core code to fs/kernfs/dir.c Tejun Heo
2013-10-24 15:49 ` [PATCH 33/34] sysfs, kernfs: move file core code to fs/kernfs/file.c Tejun Heo
2013-10-28 13:04 ` [PATCH v2 " Tejun Heo
2013-10-28 16:34 ` [PATCH v3 " Tejun Heo
2013-10-24 15:49 ` [PATCH 34/34] sysfs, kernfs: move symlink core code to fs/kernfs/symlink.c Tejun Heo
2013-10-28 13:06 ` Subject: [PATCHSET driver-core-next] sysfs: separate out kernfs, part #1 Tejun Heo
2013-10-28 16:35 ` Tejun Heo
2013-10-29 22:29 ` Greg KH
2013-10-30 14:41 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1382629780-10006-30-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=bhelgaas@google.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=kay@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).