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

sysfs: implement sysfs_find_dirent() and sysfs_get_dirent()

Implement sysfs_find_dirent() and sysfs_get_dirent().
sysfs_dirent_exist() is replaced by sysfs_find_dirent().  These will
be used to make directory entries reclamiable.
Signed-off-by: default avatarTejun Heo <htejun@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 380e6fbb
...@@ -317,28 +317,55 @@ void sysfs_attach_dirent(struct sysfs_dirent *sd, ...@@ -317,28 +317,55 @@ void sysfs_attach_dirent(struct sysfs_dirent *sd,
} }
} }
/* /**
* sysfs_find_dirent - find sysfs_dirent with the given name
* @parent_sd: sysfs_dirent to search under
* @name: name to look for
* *
* Return -EEXIST if there is already a sysfs element with the same name for * Look for sysfs_dirent with name @name under @parent_sd.
* the same parent.
* *
* called with parent inode's i_mutex held * LOCKING:
* mutex_lock(parent->i_mutex)
*
* RETURNS:
* Pointer to sysfs_dirent if found, NULL if not.
*/ */
int sysfs_dirent_exist(struct sysfs_dirent *parent_sd, struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
const unsigned char *new) const unsigned char *name)
{ {
struct sysfs_dirent * sd; struct sysfs_dirent *sd;
for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) { for (sd = parent_sd->s_children; sd; sd = sd->s_sibling)
if (sysfs_type(sd)) { if (sysfs_type(sd) && !strcmp(sd->s_name, name))
if (strcmp(sd->s_name, new)) return sd;
continue; return NULL;
else }
return -EEXIST;
}
}
return 0; /**
* sysfs_get_dirent - find and get sysfs_dirent with the given name
* @parent_sd: sysfs_dirent to search under
* @name: name to look for
*
* Look for sysfs_dirent with name @name under @parent_sd and get
* it if found.
*
* LOCKING:
* Kernel thread context (may sleep)
*
* RETURNS:
* Pointer to sysfs_dirent if found, NULL if not.
*/
struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
const unsigned char *name)
{
struct sysfs_dirent *sd;
mutex_lock(&parent_sd->s_dentry->d_inode->i_mutex);
sd = sysfs_find_dirent(parent_sd, name);
sysfs_get(sd);
mutex_unlock(&parent_sd->s_dentry->d_inode->i_mutex);
return sd;
} }
static int create_dir(struct kobject *kobj, struct dentry *parent, static int create_dir(struct kobject *kobj, struct dentry *parent,
...@@ -382,7 +409,7 @@ static int create_dir(struct kobject *kobj, struct dentry *parent, ...@@ -382,7 +409,7 @@ static int create_dir(struct kobject *kobj, struct dentry *parent,
/* link in */ /* link in */
error = -EEXIST; error = -EEXIST;
if (sysfs_dirent_exist(parent->d_fsdata, name)) if (sysfs_find_dirent(parent->d_fsdata, name))
goto out_iput; goto out_iput;
sysfs_instantiate(dentry, inode); sysfs_instantiate(dentry, inode);
......
...@@ -421,7 +421,7 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type) ...@@ -421,7 +421,7 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type)
mutex_lock(&dir->d_inode->i_mutex); mutex_lock(&dir->d_inode->i_mutex);
if (sysfs_dirent_exist(parent_sd, attr->name)) { if (sysfs_find_dirent(parent_sd, attr->name)) {
error = -EEXIST; error = -EEXIST;
goto out_unlock; goto out_unlock;
} }
......
...@@ -95,7 +95,7 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char ...@@ -95,7 +95,7 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
return -ENOENT; return -ENOENT;
mutex_lock(&dentry->d_inode->i_mutex); mutex_lock(&dentry->d_inode->i_mutex);
if (!sysfs_dirent_exist(dentry->d_fsdata, name)) if (!sysfs_find_dirent(dentry->d_fsdata, name))
error = sysfs_add_link(parent_sd, name, target_sd); error = sysfs_add_link(parent_sd, name, target_sd);
mutex_unlock(&dentry->d_inode->i_mutex); mutex_unlock(&dentry->d_inode->i_mutex);
......
...@@ -59,7 +59,10 @@ extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd); ...@@ -59,7 +59,10 @@ extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode); extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode);
extern void release_sysfs_dirent(struct sysfs_dirent * sd); extern void release_sysfs_dirent(struct sysfs_dirent * sd);
extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *); extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
const unsigned char *name);
extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
const unsigned char *name);
extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
int type); int type);
extern void sysfs_attach_dirent(struct sysfs_dirent *sd, extern void sysfs_attach_dirent(struct sysfs_dirent *sd,
......
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