return pos->s_parent;
}
-static void __sysfs_remove(struct sysfs_addrm_cxt *acxt,
- struct sysfs_dirent *sd)
+static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
+ struct sysfs_dirent *sd)
{
struct sysfs_dirent *pos, *next;
}
/**
- * sysfs_remove - remove a sysfs_dirent recursively
+ * kernfs_remove - remove a sysfs_dirent recursively
* @sd: the sysfs_dirent to remove
*
* Remove @sd along with all its subdirectories and files.
*/
-void sysfs_remove(struct sysfs_dirent *sd)
+void kernfs_remove(struct sysfs_dirent *sd)
{
struct sysfs_addrm_cxt acxt;
sysfs_addrm_start(&acxt);
- __sysfs_remove(&acxt, sd);
+ __kernfs_remove(&acxt, sd);
sysfs_addrm_finish(&acxt);
}
/**
- * sysfs_hash_and_remove - find a sysfs_dirent by name and remove it
+ * kernfs_remove_by_name_ns - find a sysfs_dirent by name and remove it
* @dir_sd: parent of the target
* @name: name of the sysfs_dirent to remove
* @ns: namespace tag of the sysfs_dirent to remove
* Look for the sysfs_dirent with @name and @ns under @dir_sd and remove
* it. Returns 0 on success, -ENOENT if such entry doesn't exist.
*/
-int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
- const void *ns)
+int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
+ const void *ns)
{
struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd;
sd = sysfs_find_dirent(dir_sd, name, ns);
if (sd)
- __sysfs_remove(&acxt, sd);
+ __kernfs_remove(&acxt, sd);
sysfs_addrm_finish(&acxt);
if (sd) {
WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR);
- sysfs_remove(sd);
+ kernfs_remove(sd);
}
}
{
struct sysfs_dirent *dir_sd = kobj->sd;
- sysfs_hash_and_remove(dir_sd, attr->name, ns);
+ kernfs_remove_by_name_ns(dir_sd, attr->name, ns);
}
EXPORT_SYMBOL_GPL(sysfs_remove_file_ns);
else
dir_sd = sysfs_get(kobj->sd);
if (dir_sd) {
- sysfs_hash_and_remove(dir_sd, attr->name, NULL);
+ kernfs_remove_by_name(dir_sd, attr->name);
sysfs_put(dir_sd);
}
}
void sysfs_remove_bin_file(struct kobject *kobj,
const struct bin_attribute *attr)
{
- sysfs_hash_and_remove(kobj->sd, attr->attr.name, NULL);
+ kernfs_remove_by_name(kobj->sd, attr->attr.name);
}
EXPORT_SYMBOL_GPL(sysfs_remove_bin_file);
if (grp->attrs)
for (attr = grp->attrs; *attr; attr++)
- sysfs_hash_and_remove(dir_sd, (*attr)->name, NULL);
+ kernfs_remove_by_name(dir_sd, (*attr)->name);
if (grp->bin_attrs)
for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++)
sysfs_remove_bin_file(kobj, *bin_attr);
* re-adding (if required) the file.
*/
if (update)
- sysfs_hash_and_remove(dir_sd, (*attr)->name,
- NULL);
+ kernfs_remove_by_name(dir_sd, (*attr)->name);
if (grp->is_visible) {
mode = grp->is_visible(kobj, *attr, i);
if (!mode)
error = create_files(sd, kobj, grp, update);
if (error) {
if (grp->name)
- sysfs_remove(sd);
+ kernfs_remove(sd);
}
sysfs_put(sd);
return error;
remove_files(sd, kobj, grp);
if (grp->name)
- sysfs_remove(sd);
+ kernfs_remove(sd);
sysfs_put(sd);
}
error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
if (error) {
while (--i >= 0)
- sysfs_hash_and_remove(dir_sd, (*--attr)->name, NULL);
+ kernfs_remove_by_name(dir_sd, (*--attr)->name);
}
sysfs_put(dir_sd);
dir_sd = sysfs_get_dirent(kobj->sd, grp->name);
if (dir_sd) {
for (attr = grp->attrs; *attr; ++attr)
- sysfs_hash_and_remove(dir_sd, (*attr)->name, NULL);
+ kernfs_remove_by_name(dir_sd, (*attr)->name);
sysfs_put(dir_sd);
}
}
dir_sd = sysfs_get_dirent(kobj->sd, group_name);
if (dir_sd) {
- sysfs_hash_and_remove(dir_sd, link_name, NULL);
+ kernfs_remove_by_name(dir_sd, link_name);
sysfs_put(dir_sd);
}
}
if (targ->sd && (kobj->sd->s_flags & SYSFS_FLAG_NS))
ns = targ->sd->s_ns;
spin_unlock(&sysfs_symlink_target_lock);
- sysfs_hash_and_remove(kobj->sd, name, ns);
+ kernfs_remove_by_name_ns(kobj->sd, name, ns);
}
/**
else
parent_sd = kobj->sd;
- sysfs_hash_and_remove(parent_sd, name, NULL);
+ kernfs_remove_by_name(parent_sd, name);
}
EXPORT_SYMBOL_GPL(sysfs_remove_link);
struct sysfs_dirent *parent_sd);
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
struct sysfs_dirent *parent_sd);
-void sysfs_remove(struct sysfs_dirent *sd);
-int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
- const void *ns);
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
#ifndef __LINUX_KERNFS_H
#define __LINUX_KERNFS_H
+#include <linux/kernel.h>
+
struct sysfs_dirent;
+#ifdef CONFIG_SYSFS
+
+void kernfs_remove(struct sysfs_dirent *sd);
+int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name,
+ const void *ns);
+
+#else /* CONFIG_SYSFS */
+
+static inline void kernfs_remove(struct sysfs_dirent *sd) { }
+
+static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent,
+ const char *name, const void *ns)
+{ return -ENOSYS; }
+
+#endif /* CONFIG_SYSFS */
+
+static inline int kernfs_remove_by_name(struct sysfs_dirent *parent,
+ const char *name)
+{
+ return kernfs_remove_by_name_ns(parent, name, NULL);
+}
+
#endif /* __LINUX_KERNFS_H */