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>
This commit is contained in:
Tejun Heo 2013-11-28 14:54:30 -05:00 committed by Greg Kroah-Hartman
parent 517e64f578
commit ccf73cf336
9 changed files with 154 additions and 151 deletions

View file

@ -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 struct sysfs_dirent *
sysfs_get_dirent(struct sysfs_dirent *parent_sd, const unsigned char *name)
{
return sysfs_get_dirent_ns(parent_sd, 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 kernfs_find_and_get(parent_sd, name);
}
static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
{
kernfs_get(sd);
return sd;
}
static inline void sysfs_put(struct sysfs_dirent *sd)
{
kernfs_put(sd);
}
#endif /* _SYSFS_H_ */