diff options
| author | Tejun Heo <tj@kernel.org> | 2013-11-28 14:54:40 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-29 21:10:48 -0500 |
| commit | ba7443bc656e5236c316b2acacc8b551f872910f (patch) | |
| tree | 08b9a7a0504ae77abc634419167958ce4e6c4e64 /include/linux | |
| parent | 061447a496b915f1dc8f8c645c6825f856d2bbac (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 'include/linux')
| -rw-r--r-- | include/linux/kernfs.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index fd8f574ef2fe..f75548b8ed7a 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h | |||
| @@ -20,6 +20,11 @@ struct vm_area_struct; | |||
| 20 | 20 | ||
| 21 | struct sysfs_dirent; | 21 | struct sysfs_dirent; |
| 22 | 22 | ||
| 23 | struct kernfs_root { | ||
| 24 | /* published fields */ | ||
| 25 | struct sysfs_dirent *sd; | ||
| 26 | }; | ||
| 27 | |||
| 23 | struct sysfs_open_file { | 28 | struct sysfs_open_file { |
| 24 | /* published fields */ | 29 | /* published fields */ |
| 25 | struct sysfs_dirent *sd; | 30 | struct sysfs_dirent *sd; |
| @@ -76,6 +81,9 @@ struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, | |||
| 76 | void kernfs_get(struct sysfs_dirent *sd); | 81 | void kernfs_get(struct sysfs_dirent *sd); |
| 77 | void kernfs_put(struct sysfs_dirent *sd); | 82 | void kernfs_put(struct sysfs_dirent *sd); |
| 78 | 83 | ||
| 84 | struct kernfs_root *kernfs_create_root(void *priv); | ||
| 85 | void kernfs_destroy_root(struct kernfs_root *root); | ||
| 86 | |||
| 79 | struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, | 87 | struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, |
| 80 | const char *name, void *priv, | 88 | const char *name, void *priv, |
| 81 | const void *ns); | 89 | const void *ns); |
| @@ -107,6 +115,11 @@ kernfs_find_and_get_ns(struct sysfs_dirent *parent, const char *name, | |||
| 107 | static inline void kernfs_get(struct sysfs_dirent *sd) { } | 115 | static inline void kernfs_get(struct sysfs_dirent *sd) { } |
| 108 | static inline void kernfs_put(struct sysfs_dirent *sd) { } | 116 | static inline void kernfs_put(struct sysfs_dirent *sd) { } |
| 109 | 117 | ||
| 118 | static inline struct kernfs_root *kernfs_create_root(void *priv) | ||
| 119 | { return ERR_PTR(-ENOSYS); } | ||
| 120 | |||
| 121 | static inline void kernfs_destroy_root(struct kernfs_root *root) { } | ||
| 122 | |||
| 110 | static inline struct sysfs_dirent * | 123 | static inline struct sysfs_dirent * |
| 111 | kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv, | 124 | kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv, |
| 112 | const void *ns) | 125 | const void *ns) |
