aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/kernfs-internal.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-28 14:54:40 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-29 21:10:48 -0500
commitba7443bc656e5236c316b2acacc8b551f872910f (patch)
tree08b9a7a0504ae77abc634419167958ce4e6c4e64 /fs/kernfs/kernfs-internal.h
parent061447a496b915f1dc8f8c645c6825f856d2bbac (diff)
sysfs, kernfs: implement kernfs_create/destroy_root()
There currently is single kernfs hierarchy in the whole system which is used for sysfs. kernfs needs to support multiple hierarchies to allow other users. This patch introduces struct kernfs_root which serves as the root of each kernfs hierarchy and implements kernfs_create/destroy_root(). * Each kernfs_root is associated with a root sd (sysfs_dentry). The root is freed when the root sd is released and kernfs_destory_root() simply invokes kernfs_remove() on the root sd. sysfs_remove_one() is updated to handle release of the root sd. Note that ps_iattr update in sysfs_remove_one() is trivially updated for readability. * Root sd's are now dynamically allocated using sysfs_new_dirent(). Update sysfs_alloc_ino() so that it gives out ino from 1 so that the root sd still gets ino 1. * While kernfs currently only points to the root sd, it'll soon grow fields which are specific to each hierarchy. As determining a given sd's root will be necessary, sd->s_dir.root is added. This backlink fits better as a separate field in sd; however, sd->s_dir is inside union with space to spare, so use it to save space and provide kernfs_root() accessor to determine the root sd. * As hierarchies may be destroyed now, each mount needs to hold onto the hierarchy it's attached to. Update sysfs_fill_super() and sysfs_kill_sb() so that they get and put the kernfs_root respectively. * sysfs_root is replaced with kernfs_root which is dynamically created by invoking kernfs_create_root() from sysfs_init(). This patch doesn't introduce any visible behavior changes. v2: kernfs_create_root() forgot to set @sd->priv. Fixed. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/kernfs/kernfs-internal.h')
-rw-r--r--fs/kernfs/kernfs-internal.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h
index 62ae35f997f7..7dfe06278350 100644
--- a/fs/kernfs/kernfs-internal.h
+++ b/fs/kernfs/kernfs-internal.h
@@ -25,6 +25,12 @@ struct sysfs_elem_dir {
25 unsigned long subdirs; 25 unsigned long subdirs;
26 /* children rbtree starts here and goes through sd->s_rb */ 26 /* children rbtree starts here and goes through sd->s_rb */
27 struct rb_root children; 27 struct rb_root children;
28
29 /*
30 * The kernfs hierarchy this directory belongs to. This fits
31 * better directly in sysfs_dirent but is here to save space.
32 */
33 struct kernfs_root *root;
28}; 34};
29 35
30struct sysfs_elem_symlink { 36struct sysfs_elem_symlink {
@@ -104,6 +110,20 @@ static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
104 return sd->s_flags & SYSFS_TYPE_MASK; 110 return sd->s_flags & SYSFS_TYPE_MASK;
105} 111}
106 112
113/**
114 * kernfs_root - find out the kernfs_root a sysfs_dirent belongs to
115 * @sd: sysfs_dirent of interest
116 *
117 * Return the kernfs_root @sd belongs to.
118 */
119static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd)
120{
121 /* if parent exists, it's always a dir; otherwise, @sd is a dir */
122 if (sd->s_parent)
123 sd = sd->s_parent;
124 return sd->s_dir.root;
125}
126
107/* 127/*
108 * Context structure to be used while adding/removing nodes. 128 * Context structure to be used while adding/removing nodes.
109 */ 129 */