Skip to content

Commit 87d2846

Browse files
committed
sysfs: Add support for permanently empty directories to serve as mount points.
Add two functions sysfs_create_mount_point and sysfs_remove_mount_point that hang a permanently empty directory off of a kobject or remove a permanently emptpy directory hanging from a kobject. Export these new functions so modular filesystems can use them. Cc: stable@vger.kernel.org Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent ea01521 commit 87d2846

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎fs/sysfs/dir.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,37 @@ int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
121121

122122
return kernfs_rename_ns(kn, new_parent, kn->name, new_ns);
123123
}
124+
125+
/**
126+
* sysfs_create_mount_point - create an always empty directory
127+
* @parent_kobj: kobject that will contain this always empty directory
128+
* @name: The name of the always empty directory to add
129+
*/
130+
int sysfs_create_mount_point(struct kobject *parent_kobj, const char *name)
131+
{
132+
struct kernfs_node *kn, *parent = parent_kobj->sd;
133+
134+
kn = kernfs_create_empty_dir(parent, name);
135+
if (IS_ERR(kn)) {
136+
if (PTR_ERR(kn) == -EEXIST)
137+
sysfs_warn_dup(parent, name);
138+
return PTR_ERR(kn);
139+
}
140+
141+
return 0;
142+
}
143+
EXPORT_SYMBOL_GPL(sysfs_create_mount_point);
144+
145+
/**
146+
* sysfs_remove_mount_point - remove an always empty directory.
147+
* @parent_kobj: kobject that will contain this always empty directory
148+
* @name: The name of the always empty directory to remove
149+
*
150+
*/
151+
void sysfs_remove_mount_point(struct kobject *parent_kobj, const char *name)
152+
{
153+
struct kernfs_node *parent = parent_kobj->sd;
154+
155+
kernfs_remove_by_name_ns(parent, name, NULL);
156+
}
157+
EXPORT_SYMBOL_GPL(sysfs_remove_mount_point);

‎include/linux/sysfs.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
210210
int __must_check sysfs_move_dir_ns(struct kobject *kobj,
211211
struct kobject *new_parent_kobj,
212212
const void *new_ns);
213+
int __must_check sysfs_create_mount_point(struct kobject *parent_kobj,
214+
const char *name);
215+
void sysfs_remove_mount_point(struct kobject *parent_kobj,
216+
const char *name);
213217

214218
int __must_check sysfs_create_file_ns(struct kobject *kobj,
215219
const struct attribute *attr,
@@ -298,6 +302,17 @@ static inline int sysfs_move_dir_ns(struct kobject *kobj,
298302
return 0;
299303
}
300304

305+
static inline int sysfs_create_mount_point(struct kobject *parent_kobj,
306+
const char *name)
307+
{
308+
return 0;
309+
}
310+
311+
static inline void sysfs_remove_mount_point(struct kobject *parent_kobj,
312+
const char *name)
313+
{
314+
}
315+
301316
static inline int sysfs_create_file_ns(struct kobject *kobj,
302317
const struct attribute *attr,
303318
const void *ns)

0 commit comments

Comments
 (0)