]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
kernfs: implement kernfs_node_from_dentry(), kernfs_root_from_sb() and kernfs_rename()
authorTejun Heo <tj@kernel.org>
Mon, 3 Feb 2014 19:09:15 +0000 (14:09 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 8 Feb 2014 00:00:41 +0000 (16:00 -0800)
Implement helpers to determine node from dentry and root from
super_block.  Also add a kernfs_rename_ns() wrapper which assumes NULL
namespace.  These generally make sense and will be used by cgroup.

v2: Some dummy implementations for !CONFIG_SYSFS was missing.  Fixed.
    Reported by kbuild test robot.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/kernfs/dir.c
fs/kernfs/mount.c
include/linux/kernfs.h

index 3cff0a233cd14b4c6767aa9b4ffbae07f3be5adb..42a250f83b98cf1c294be3f4136aa9e837333e50 100644 (file)
@@ -350,6 +350,24 @@ const struct dentry_operations kernfs_dops = {
        .d_release      = kernfs_dop_release,
 };
 
+/**
+ * kernfs_node_from_dentry - determine kernfs_node associated with a dentry
+ * @dentry: the dentry in question
+ *
+ * Return the kernfs_node associated with @dentry.  If @dentry is not a
+ * kernfs one, %NULL is returned.
+ *
+ * While the returned kernfs_node will stay accessible as long as @dentry
+ * is accessible, the returned node can be in any state and the caller is
+ * fully responsible for determining what's accessible.
+ */
+struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry)
+{
+       if (dentry->d_op == &kernfs_dops)
+               return dentry->d_fsdata;
+       return NULL;
+}
+
 static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
                                             const char *name, umode_t mode,
                                             unsigned flags)
index 70cc6983d9b55e30406fea9d1d62cc2b11ee6f7c..e5b28b0ebc37563703eb693fa7f98672e12c97d4 100644 (file)
@@ -48,6 +48,20 @@ static const struct super_operations kernfs_sops = {
        .show_options   = kernfs_sop_show_options,
 };
 
+/**
+ * kernfs_root_from_sb - determine kernfs_root associated with a super_block
+ * @sb: the super_block in question
+ *
+ * Return the kernfs_root associated with @sb.  If @sb is not a kernfs one,
+ * %NULL is returned.
+ */
+struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
+{
+       if (sb->s_op == &kernfs_sops)
+               return kernfs_info(sb)->root;
+       return NULL;
+}
+
 static int kernfs_fill_super(struct super_block *sb)
 {
        struct kernfs_super_info *info = kernfs_info(sb);
index 9ca0f09757a116c661c37d3aa97f371dae348190..9c899040c05e413e6be7103fcc1c558b46336786 100644 (file)
@@ -234,6 +234,9 @@ struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
 void kernfs_get(struct kernfs_node *kn);
 void kernfs_put(struct kernfs_node *kn);
 
+struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
+struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
+
 struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
                                       unsigned int flags, void *priv);
 void kernfs_destroy_root(struct kernfs_root *root);
@@ -288,6 +291,12 @@ kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
 static inline void kernfs_get(struct kernfs_node *kn) { }
 static inline void kernfs_put(struct kernfs_node *kn) { }
 
+static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry)
+{ return NULL; }
+
+static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
+{ return NULL; }
+
 static inline struct kernfs_root *
 kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags,
                   void *priv)
@@ -388,6 +397,13 @@ static inline int kernfs_remove_by_name(struct kernfs_node *parent,
        return kernfs_remove_by_name_ns(parent, name, NULL);
 }
 
+static inline int kernfs_rename(struct kernfs_node *kn,
+                               struct kernfs_node *new_parent,
+                               const char *new_name)
+{
+       return kernfs_rename_ns(kn, new_parent, new_name, NULL);
+}
+
 static inline struct dentry *
 kernfs_mount(struct file_system_type *fs_type, int flags,
             struct kernfs_root *root)