summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-28 14:54:30 -0500
committerPawel Osmialowski <p.osmialowsk@mcdsrvbld02.digital.local>2015-03-27 18:13:17 +0100
commitc61ed30807afcdd6e4ea4e6d356ddca8598480f1 (patch)
treeaee715a7c0cae459763bde781f19e1f35e34eb93 /include
parentaa54854fe13af730fb5f63a8abae9c344eb0fd04 (diff)
downloadlinux-3.10-c61ed30807afcdd6e4ea4e6d356ddca8598480f1.tar.gz
linux-3.10-c61ed30807afcdd6e4ea4e6d356ddca8598480f1.tar.bz2
linux-3.10-c61ed30807afcdd6e4ea4e6d356ddca8598480f1.zip
sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put()
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/kernfs.h19
-rw-r--r--include/linux/sysfs.h35
2 files changed, 33 insertions, 21 deletions
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 105d09dcb06..fd8f574ef2f 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -71,6 +71,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);
@@ -95,6 +100,14 @@ 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 ERR_PTR(-ENOSYS); }
@@ -133,6 +146,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 b440f934afb..3ae97af44c6 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -196,11 +196,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);
@@ -359,19 +354,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)
{
@@ -398,15 +380,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_ */