diff options
-rw-r--r-- | fs/kernfs/dir.c | 18 | ||||
-rw-r--r-- | fs/kernfs/mount.c | 14 | ||||
-rw-r--r-- | include/linux/kernfs.h | 16 |
3 files changed, 48 insertions, 0 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 3cff0a233cd1..42a250f83b98 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c | |||
@@ -350,6 +350,24 @@ const struct dentry_operations kernfs_dops = { | |||
350 | .d_release = kernfs_dop_release, | 350 | .d_release = kernfs_dop_release, |
351 | }; | 351 | }; |
352 | 352 | ||
353 | /** | ||
354 | * kernfs_node_from_dentry - determine kernfs_node associated with a dentry | ||
355 | * @dentry: the dentry in question | ||
356 | * | ||
357 | * Return the kernfs_node associated with @dentry. If @dentry is not a | ||
358 | * kernfs one, %NULL is returned. | ||
359 | * | ||
360 | * While the returned kernfs_node will stay accessible as long as @dentry | ||
361 | * is accessible, the returned node can be in any state and the caller is | ||
362 | * fully responsible for determining what's accessible. | ||
363 | */ | ||
364 | struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry) | ||
365 | { | ||
366 | if (dentry->d_op == &kernfs_dops) | ||
367 | return dentry->d_fsdata; | ||
368 | return NULL; | ||
369 | } | ||
370 | |||
353 | static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, | 371 | static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, |
354 | const char *name, umode_t mode, | 372 | const char *name, umode_t mode, |
355 | unsigned flags) | 373 | unsigned flags) |
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index 70cc6983d9b5..e5b28b0ebc37 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c | |||
@@ -48,6 +48,20 @@ static const struct super_operations kernfs_sops = { | |||
48 | .show_options = kernfs_sop_show_options, | 48 | .show_options = kernfs_sop_show_options, |
49 | }; | 49 | }; |
50 | 50 | ||
51 | /** | ||
52 | * kernfs_root_from_sb - determine kernfs_root associated with a super_block | ||
53 | * @sb: the super_block in question | ||
54 | * | ||
55 | * Return the kernfs_root associated with @sb. If @sb is not a kernfs one, | ||
56 | * %NULL is returned. | ||
57 | */ | ||
58 | struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) | ||
59 | { | ||
60 | if (sb->s_op == &kernfs_sops) | ||
61 | return kernfs_info(sb)->root; | ||
62 | return NULL; | ||
63 | } | ||
64 | |||
51 | static int kernfs_fill_super(struct super_block *sb) | 65 | static int kernfs_fill_super(struct super_block *sb) |
52 | { | 66 | { |
53 | struct kernfs_super_info *info = kernfs_info(sb); | 67 | struct kernfs_super_info *info = kernfs_info(sb); |
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 9ca0f09757a1..9c899040c05e 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h | |||
@@ -234,6 +234,9 @@ struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, | |||
234 | void kernfs_get(struct kernfs_node *kn); | 234 | void kernfs_get(struct kernfs_node *kn); |
235 | void kernfs_put(struct kernfs_node *kn); | 235 | void kernfs_put(struct kernfs_node *kn); |
236 | 236 | ||
237 | struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry); | ||
238 | struct kernfs_root *kernfs_root_from_sb(struct super_block *sb); | ||
239 | |||
237 | struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops, | 240 | struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops, |
238 | unsigned int flags, void *priv); | 241 | unsigned int flags, void *priv); |
239 | void kernfs_destroy_root(struct kernfs_root *root); | 242 | void kernfs_destroy_root(struct kernfs_root *root); |
@@ -288,6 +291,12 @@ kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, | |||
288 | static inline void kernfs_get(struct kernfs_node *kn) { } | 291 | static inline void kernfs_get(struct kernfs_node *kn) { } |
289 | static inline void kernfs_put(struct kernfs_node *kn) { } | 292 | static inline void kernfs_put(struct kernfs_node *kn) { } |
290 | 293 | ||
294 | static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry) | ||
295 | { return NULL; } | ||
296 | |||
297 | static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) | ||
298 | { return NULL; } | ||
299 | |||
291 | static inline struct kernfs_root * | 300 | static inline struct kernfs_root * |
292 | kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags, | 301 | kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags, |
293 | void *priv) | 302 | void *priv) |
@@ -388,6 +397,13 @@ static inline int kernfs_remove_by_name(struct kernfs_node *parent, | |||
388 | return kernfs_remove_by_name_ns(parent, name, NULL); | 397 | return kernfs_remove_by_name_ns(parent, name, NULL); |
389 | } | 398 | } |
390 | 399 | ||
400 | static inline int kernfs_rename(struct kernfs_node *kn, | ||
401 | struct kernfs_node *new_parent, | ||
402 | const char *new_name) | ||
403 | { | ||
404 | return kernfs_rename_ns(kn, new_parent, new_name, NULL); | ||
405 | } | ||
406 | |||
391 | static inline struct dentry * | 407 | static inline struct dentry * |
392 | kernfs_mount(struct file_system_type *fs_type, int flags, | 408 | kernfs_mount(struct file_system_type *fs_type, int flags, |
393 | struct kernfs_root *root) | 409 | struct kernfs_root *root) |