aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-12-11 14:11:53 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-11 18:28:36 -0500
commit324a56e16e44baecac3ca799fd216154145c14bf (patch)
tree4fb43421bfe884cf4e245e3a4672295bae4c7bd9 /fs/sysfs
parenta8b1c0193602b7ecdeaa7aa8c15c9c3da33244c8 (diff)
kernfs: s/sysfs_dirent/kernfs_node/ and rename its friends accordingly
kernfs has just been separated out from sysfs and we're already in full conflict mode. Nothing can make the situation any worse. Let's take the chance to name things properly. This patch performs the following renames. * s/sysfs_elem_dir/kernfs_elem_dir/ * s/sysfs_elem_symlink/kernfs_elem_symlink/ * s/sysfs_elem_attr/kernfs_elem_file/ * s/sysfs_dirent/kernfs_node/ * s/sd/kn/ in kernfs proper * s/parent_sd/parent/ * s/target_sd/target/ * s/dir_sd/parent/ * s/to_sysfs_dirent()/rb_to_kn()/ * misc renames of local vars when they conflict with the above Because md, mic and gpio dig into sysfs details, this patch ends up modifying them. All are sysfs_dirent renames and trivial. While we can avoid these by introducing a dummy wrapping struct sysfs_dirent around kernfs_node, given the limited usage outside kernfs and sysfs proper, I don't think such workaround is called for. This patch is strictly rename only and doesn't introduce any functional difference. - mic / gpio renames were missing. Spotted by kbuild test robot. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Neil Brown <neilb@suse.de> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Ashutosh Dixit <ashutosh.dixit@intel.com> Cc: kbuild test robot <fengguang.wu@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/dir.c66
-rw-r--r--fs/sysfs/file.c122
-rw-r--r--fs/sysfs/group.c96
-rw-r--r--fs/sysfs/mount.c4
-rw-r--r--fs/sysfs/symlink.c72
-rw-r--r--fs/sysfs/sysfs.h10
6 files changed, 185 insertions, 185 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 2fea501889e7..f1efe3df0de6 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -21,23 +21,23 @@ DEFINE_SPINLOCK(sysfs_symlink_target_lock);
21 21
22/** 22/**
23 * sysfs_pathname - return full path to sysfs dirent 23 * sysfs_pathname - return full path to sysfs dirent
24 * @sd: sysfs_dirent whose path we want 24 * @kn: kernfs_node whose path we want
25 * @path: caller allocated buffer of size PATH_MAX 25 * @path: caller allocated buffer of size PATH_MAX
26 * 26 *
27 * Gives the name "/" to the sysfs_root entry; any path returned 27 * Gives the name "/" to the sysfs_root entry; any path returned
28 * is relative to wherever sysfs is mounted. 28 * is relative to wherever sysfs is mounted.
29 */ 29 */
30static char *sysfs_pathname(struct sysfs_dirent *sd, char *path) 30static char *sysfs_pathname(struct kernfs_node *kn, char *path)
31{ 31{
32 if (sd->s_parent) { 32 if (kn->s_parent) {
33 sysfs_pathname(sd->s_parent, path); 33 sysfs_pathname(kn->s_parent, path);
34 strlcat(path, "/", PATH_MAX); 34 strlcat(path, "/", PATH_MAX);
35 } 35 }
36 strlcat(path, sd->s_name, PATH_MAX); 36 strlcat(path, kn->s_name, PATH_MAX);
37 return path; 37 return path;
38} 38}
39 39
40void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name) 40void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
41{ 41{
42 char *path; 42 char *path;
43 43
@@ -61,26 +61,26 @@ void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name)
61 */ 61 */
62int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) 62int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
63{ 63{
64 struct sysfs_dirent *parent_sd, *sd; 64 struct kernfs_node *parent, *kn;
65 65
66 BUG_ON(!kobj); 66 BUG_ON(!kobj);
67 67
68 if (kobj->parent) 68 if (kobj->parent)
69 parent_sd = kobj->parent->sd; 69 parent = kobj->parent->sd;
70 else 70 else
71 parent_sd = sysfs_root_sd; 71 parent = sysfs_root_kn;
72 72
73 if (!parent_sd) 73 if (!parent)
74 return -ENOENT; 74 return -ENOENT;
75 75
76 sd = kernfs_create_dir_ns(parent_sd, kobject_name(kobj), kobj, ns); 76 kn = kernfs_create_dir_ns(parent, kobject_name(kobj), kobj, ns);
77 if (IS_ERR(sd)) { 77 if (IS_ERR(kn)) {
78 if (PTR_ERR(sd) == -EEXIST) 78 if (PTR_ERR(kn) == -EEXIST)
79 sysfs_warn_dup(parent_sd, kobject_name(kobj)); 79 sysfs_warn_dup(parent, kobject_name(kobj));
80 return PTR_ERR(sd); 80 return PTR_ERR(kn);
81 } 81 }
82 82
83 kobj->sd = sd; 83 kobj->sd = kn;
84 return 0; 84 return 0;
85} 85}
86 86
@@ -94,47 +94,47 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
94 */ 94 */
95void sysfs_remove_dir(struct kobject *kobj) 95void sysfs_remove_dir(struct kobject *kobj)
96{ 96{
97 struct sysfs_dirent *sd = kobj->sd; 97 struct kernfs_node *kn = kobj->sd;
98 98
99 /* 99 /*
100 * In general, kboject owner is responsible for ensuring removal 100 * In general, kboject owner is responsible for ensuring removal
101 * doesn't race with other operations and sysfs doesn't provide any 101 * doesn't race with other operations and sysfs doesn't provide any
102 * protection; however, when @kobj is used as a symlink target, the 102 * protection; however, when @kobj is used as a symlink target, the
103 * symlinking entity usually doesn't own @kobj and thus has no 103 * symlinking entity usually doesn't own @kobj and thus has no
104 * control over removal. @kobj->sd may be removed anytime and 104 * control over removal. @kobj->sd may be removed anytime
105 * symlink code may end up dereferencing an already freed sd. 105 * and symlink code may end up dereferencing an already freed node.
106 * 106 *
107 * sysfs_symlink_target_lock synchronizes @kobj->sd disassociation 107 * sysfs_symlink_target_lock synchronizes @kobj->sd
108 * against symlink operations so that symlink code can safely 108 * disassociation against symlink operations so that symlink code
109 * dereference @kobj->sd. 109 * can safely dereference @kobj->sd.
110 */ 110 */
111 spin_lock(&sysfs_symlink_target_lock); 111 spin_lock(&sysfs_symlink_target_lock);
112 kobj->sd = NULL; 112 kobj->sd = NULL;
113 spin_unlock(&sysfs_symlink_target_lock); 113 spin_unlock(&sysfs_symlink_target_lock);
114 114
115 if (sd) { 115 if (kn) {
116 WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); 116 WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
117 kernfs_remove(sd); 117 kernfs_remove(kn);
118 } 118 }
119} 119}
120 120
121int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, 121int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
122 const void *new_ns) 122 const void *new_ns)
123{ 123{
124 struct sysfs_dirent *parent_sd = kobj->sd->s_parent; 124 struct kernfs_node *parent = kobj->sd->s_parent;
125 125
126 return kernfs_rename_ns(kobj->sd, parent_sd, new_name, new_ns); 126 return kernfs_rename_ns(kobj->sd, parent, new_name, new_ns);
127} 127}
128 128
129int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, 129int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
130 const void *new_ns) 130 const void *new_ns)
131{ 131{
132 struct sysfs_dirent *sd = kobj->sd; 132 struct kernfs_node *kn = kobj->sd;
133 struct sysfs_dirent *new_parent_sd; 133 struct kernfs_node *new_parent;
134 134
135 BUG_ON(!sd->s_parent); 135 BUG_ON(!kn->s_parent);
136 new_parent_sd = new_parent_kobj && new_parent_kobj->sd ? 136 new_parent = new_parent_kobj && new_parent_kobj->sd ?
137 new_parent_kobj->sd : sysfs_root_sd; 137 new_parent_kobj->sd : sysfs_root_kn;
138 138
139 return kernfs_rename_ns(sd, new_parent_sd, sd->s_name, new_ns); 139 return kernfs_rename_ns(kn, new_parent, kn->s_name, new_ns);
140} 140}
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index a67d1c682fed..be1cc39035bd 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -22,15 +22,15 @@
22#include "../kernfs/kernfs-internal.h" 22#include "../kernfs/kernfs-internal.h"
23 23
24/* 24/*
25 * Determine ktype->sysfs_ops for the given sysfs_dirent. This function 25 * Determine ktype->sysfs_ops for the given kernfs_node. This function
26 * must be called while holding an active reference. 26 * must be called while holding an active reference.
27 */ 27 */
28static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) 28static const struct sysfs_ops *sysfs_file_ops(struct kernfs_node *kn)
29{ 29{
30 struct kobject *kobj = sd->s_parent->priv; 30 struct kobject *kobj = kn->s_parent->priv;
31 31
32 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 32 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
33 lockdep_assert_held(sd); 33 lockdep_assert_held(kn);
34 return kobj->ktype ? kobj->ktype->sysfs_ops : NULL; 34 return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
35} 35}
36 36
@@ -42,8 +42,8 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
42static int sysfs_kf_seq_show(struct seq_file *sf, void *v) 42static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
43{ 43{
44 struct sysfs_open_file *of = sf->private; 44 struct sysfs_open_file *of = sf->private;
45 struct kobject *kobj = of->sd->s_parent->priv; 45 struct kobject *kobj = of->kn->s_parent->priv;
46 const struct sysfs_ops *ops = sysfs_file_ops(of->sd); 46 const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
47 ssize_t count; 47 ssize_t count;
48 char *buf; 48 char *buf;
49 49
@@ -59,7 +59,7 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
59 * if @ops->show() isn't implemented. 59 * if @ops->show() isn't implemented.
60 */ 60 */
61 if (ops->show) { 61 if (ops->show) {
62 count = ops->show(kobj, of->sd->priv, buf); 62 count = ops->show(kobj, of->kn->priv, buf);
63 if (count < 0) 63 if (count < 0)
64 return count; 64 return count;
65 } 65 }
@@ -81,8 +81,8 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
81static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf, 81static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf,
82 size_t count, loff_t pos) 82 size_t count, loff_t pos)
83{ 83{
84 struct bin_attribute *battr = of->sd->priv; 84 struct bin_attribute *battr = of->kn->priv;
85 struct kobject *kobj = of->sd->s_parent->priv; 85 struct kobject *kobj = of->kn->s_parent->priv;
86 loff_t size = file_inode(of->file)->i_size; 86 loff_t size = file_inode(of->file)->i_size;
87 87
88 if (!count) 88 if (!count)
@@ -105,21 +105,21 @@ static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf,
105static ssize_t sysfs_kf_write(struct sysfs_open_file *of, char *buf, 105static ssize_t sysfs_kf_write(struct sysfs_open_file *of, char *buf,
106 size_t count, loff_t pos) 106 size_t count, loff_t pos)
107{ 107{
108 const struct sysfs_ops *ops = sysfs_file_ops(of->sd); 108 const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
109 struct kobject *kobj = of->sd->s_parent->priv; 109 struct kobject *kobj = of->kn->s_parent->priv;
110 110
111 if (!count) 111 if (!count)
112 return 0; 112 return 0;
113 113
114 return ops->store(kobj, of->sd->priv, buf, count); 114 return ops->store(kobj, of->kn->priv, buf, count);
115} 115}
116 116
117/* kernfs write callback for bin sysfs files */ 117/* kernfs write callback for bin sysfs files */
118static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf, 118static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf,
119 size_t count, loff_t pos) 119 size_t count, loff_t pos)
120{ 120{
121 struct bin_attribute *battr = of->sd->priv; 121 struct bin_attribute *battr = of->kn->priv;
122 struct kobject *kobj = of->sd->s_parent->priv; 122 struct kobject *kobj = of->kn->s_parent->priv;
123 loff_t size = file_inode(of->file)->i_size; 123 loff_t size = file_inode(of->file)->i_size;
124 124
125 if (size) { 125 if (size) {
@@ -139,30 +139,30 @@ static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf,
139static int sysfs_kf_bin_mmap(struct sysfs_open_file *of, 139static int sysfs_kf_bin_mmap(struct sysfs_open_file *of,
140 struct vm_area_struct *vma) 140 struct vm_area_struct *vma)
141{ 141{
142 struct bin_attribute *battr = of->sd->priv; 142 struct bin_attribute *battr = of->kn->priv;
143 struct kobject *kobj = of->sd->s_parent->priv; 143 struct kobject *kobj = of->kn->s_parent->priv;
144 144
145 return battr->mmap(of->file, kobj, battr, vma); 145 return battr->mmap(of->file, kobj, battr, vma);
146} 146}
147 147
148void sysfs_notify(struct kobject *k, const char *dir, const char *attr) 148void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr)
149{ 149{
150 struct sysfs_dirent *sd = k->sd, *tmp; 150 struct kernfs_node *kn = kobj->sd, *tmp;
151 151
152 if (sd && dir) 152 if (kn && dir)
153 sd = kernfs_find_and_get(sd, dir); 153 kn = kernfs_find_and_get(kn, dir);
154 else 154 else
155 kernfs_get(sd); 155 kernfs_get(kn);
156 156
157 if (sd && attr) { 157 if (kn && attr) {
158 tmp = kernfs_find_and_get(sd, attr); 158 tmp = kernfs_find_and_get(kn, attr);
159 kernfs_put(sd); 159 kernfs_put(kn);
160 sd = tmp; 160 kn = tmp;
161 } 161 }
162 162
163 if (sd) { 163 if (kn) {
164 kernfs_notify(sd); 164 kernfs_notify(kn);
165 kernfs_put(sd); 165 kernfs_put(kn);
166 } 166 }
167} 167}
168EXPORT_SYMBOL_GPL(sysfs_notify); 168EXPORT_SYMBOL_GPL(sysfs_notify);
@@ -202,17 +202,17 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = {
202 .mmap = sysfs_kf_bin_mmap, 202 .mmap = sysfs_kf_bin_mmap,
203}; 203};
204 204
205int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, 205int sysfs_add_file_mode_ns(struct kernfs_node *parent,
206 const struct attribute *attr, bool is_bin, 206 const struct attribute *attr, bool is_bin,
207 umode_t mode, const void *ns) 207 umode_t mode, const void *ns)
208{ 208{
209 struct lock_class_key *key = NULL; 209 struct lock_class_key *key = NULL;
210 const struct kernfs_ops *ops; 210 const struct kernfs_ops *ops;
211 struct sysfs_dirent *sd; 211 struct kernfs_node *kn;
212 loff_t size; 212 loff_t size;
213 213
214 if (!is_bin) { 214 if (!is_bin) {
215 struct kobject *kobj = dir_sd->priv; 215 struct kobject *kobj = parent->priv;
216 const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; 216 const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops;
217 217
218 /* every kobject with an attribute needs a ktype assigned */ 218 /* every kobject with an attribute needs a ktype assigned */
@@ -252,20 +252,20 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
252 if (!attr->ignore_lockdep) 252 if (!attr->ignore_lockdep)
253 key = attr->key ?: (struct lock_class_key *)&attr->skey; 253 key = attr->key ?: (struct lock_class_key *)&attr->skey;
254#endif 254#endif
255 sd = kernfs_create_file_ns_key(dir_sd, attr->name, mode, size, 255 kn = kernfs_create_file_ns_key(parent, attr->name, mode, size,
256 ops, (void *)attr, ns, key); 256 ops, (void *)attr, ns, key);
257 if (IS_ERR(sd)) { 257 if (IS_ERR(kn)) {
258 if (PTR_ERR(sd) == -EEXIST) 258 if (PTR_ERR(kn) == -EEXIST)
259 sysfs_warn_dup(dir_sd, attr->name); 259 sysfs_warn_dup(parent, attr->name);
260 return PTR_ERR(sd); 260 return PTR_ERR(kn);
261 } 261 }
262 return 0; 262 return 0;
263} 263}
264 264
265int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, 265int sysfs_add_file(struct kernfs_node *parent, const struct attribute *attr,
266 bool is_bin) 266 bool is_bin)
267{ 267{
268 return sysfs_add_file_mode_ns(dir_sd, attr, is_bin, attr->mode, NULL); 268 return sysfs_add_file_mode_ns(parent, attr, is_bin, attr->mode, NULL);
269} 269}
270 270
271/** 271/**
@@ -307,21 +307,21 @@ EXPORT_SYMBOL_GPL(sysfs_create_files);
307int sysfs_add_file_to_group(struct kobject *kobj, 307int sysfs_add_file_to_group(struct kobject *kobj,
308 const struct attribute *attr, const char *group) 308 const struct attribute *attr, const char *group)
309{ 309{
310 struct sysfs_dirent *dir_sd; 310 struct kernfs_node *parent;
311 int error; 311 int error;
312 312
313 if (group) { 313 if (group) {
314 dir_sd = kernfs_find_and_get(kobj->sd, group); 314 parent = kernfs_find_and_get(kobj->sd, group);
315 } else { 315 } else {
316 dir_sd = kobj->sd; 316 parent = kobj->sd;
317 kernfs_get(dir_sd); 317 kernfs_get(parent);
318 } 318 }
319 319
320 if (!dir_sd) 320 if (!parent)
321 return -ENOENT; 321 return -ENOENT;
322 322
323 error = sysfs_add_file(dir_sd, attr, false); 323 error = sysfs_add_file(parent, attr, false);
324 kernfs_put(dir_sd); 324 kernfs_put(parent);
325 325
326 return error; 326 return error;
327} 327}
@@ -337,20 +337,20 @@ EXPORT_SYMBOL_GPL(sysfs_add_file_to_group);
337int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr, 337int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
338 umode_t mode) 338 umode_t mode)
339{ 339{
340 struct sysfs_dirent *sd; 340 struct kernfs_node *kn;
341 struct iattr newattrs; 341 struct iattr newattrs;
342 int rc; 342 int rc;
343 343
344 sd = kernfs_find_and_get(kobj->sd, attr->name); 344 kn = kernfs_find_and_get(kobj->sd, attr->name);
345 if (!sd) 345 if (!kn)
346 return -ENOENT; 346 return -ENOENT;
347 347
348 newattrs.ia_mode = (mode & S_IALLUGO) | (sd->s_mode & ~S_IALLUGO); 348 newattrs.ia_mode = (mode & S_IALLUGO) | (kn->s_mode & ~S_IALLUGO);
349 newattrs.ia_valid = ATTR_MODE; 349 newattrs.ia_valid = ATTR_MODE;
350 350
351 rc = kernfs_setattr(sd, &newattrs); 351 rc = kernfs_setattr(kn, &newattrs);
352 352
353 kernfs_put(sd); 353 kernfs_put(kn);
354 return rc; 354 return rc;
355} 355}
356EXPORT_SYMBOL_GPL(sysfs_chmod_file); 356EXPORT_SYMBOL_GPL(sysfs_chmod_file);
@@ -366,9 +366,9 @@ EXPORT_SYMBOL_GPL(sysfs_chmod_file);
366void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, 366void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
367 const void *ns) 367 const void *ns)
368{ 368{
369 struct sysfs_dirent *dir_sd = kobj->sd; 369 struct kernfs_node *parent = kobj->sd;
370 370
371 kernfs_remove_by_name_ns(dir_sd, attr->name, ns); 371 kernfs_remove_by_name_ns(parent, attr->name, ns);
372} 372}
373EXPORT_SYMBOL_GPL(sysfs_remove_file_ns); 373EXPORT_SYMBOL_GPL(sysfs_remove_file_ns);
374 374
@@ -389,18 +389,18 @@ EXPORT_SYMBOL_GPL(sysfs_remove_files);
389void sysfs_remove_file_from_group(struct kobject *kobj, 389void sysfs_remove_file_from_group(struct kobject *kobj,
390 const struct attribute *attr, const char *group) 390 const struct attribute *attr, const char *group)
391{ 391{
392 struct sysfs_dirent *dir_sd; 392 struct kernfs_node *parent;
393 393
394 if (group) { 394 if (group) {
395 dir_sd = kernfs_find_and_get(kobj->sd, group); 395 parent = kernfs_find_and_get(kobj->sd, group);
396 } else { 396 } else {
397 dir_sd = kobj->sd; 397 parent = kobj->sd;
398 kernfs_get(dir_sd); 398 kernfs_get(parent);
399 } 399 }
400 400
401 if (dir_sd) { 401 if (parent) {
402 kernfs_remove_by_name(dir_sd, attr->name); 402 kernfs_remove_by_name(parent, attr->name);
403 kernfs_put(dir_sd); 403 kernfs_put(parent);
404 } 404 }
405} 405}
406EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group); 406EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 7177532b8f7b..4d00d3996477 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -18,7 +18,7 @@
18#include "sysfs.h" 18#include "sysfs.h"
19 19
20 20
21static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 21static void remove_files(struct kernfs_node *parent, struct kobject *kobj,
22 const struct attribute_group *grp) 22 const struct attribute_group *grp)
23{ 23{
24 struct attribute *const *attr; 24 struct attribute *const *attr;
@@ -26,13 +26,13 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
26 26
27 if (grp->attrs) 27 if (grp->attrs)
28 for (attr = grp->attrs; *attr; attr++) 28 for (attr = grp->attrs; *attr; attr++)
29 kernfs_remove_by_name(dir_sd, (*attr)->name); 29 kernfs_remove_by_name(parent, (*attr)->name);
30 if (grp->bin_attrs) 30 if (grp->bin_attrs)
31 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) 31 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++)
32 sysfs_remove_bin_file(kobj, *bin_attr); 32 sysfs_remove_bin_file(kobj, *bin_attr);
33} 33}
34 34
35static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 35static int create_files(struct kernfs_node *parent, struct kobject *kobj,
36 const struct attribute_group *grp, int update) 36 const struct attribute_group *grp, int update)
37{ 37{
38 struct attribute *const *attr; 38 struct attribute *const *attr;
@@ -49,20 +49,20 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
49 * re-adding (if required) the file. 49 * re-adding (if required) the file.
50 */ 50 */
51 if (update) 51 if (update)
52 kernfs_remove_by_name(dir_sd, (*attr)->name); 52 kernfs_remove_by_name(parent, (*attr)->name);
53 if (grp->is_visible) { 53 if (grp->is_visible) {
54 mode = grp->is_visible(kobj, *attr, i); 54 mode = grp->is_visible(kobj, *attr, i);
55 if (!mode) 55 if (!mode)
56 continue; 56 continue;
57 } 57 }
58 error = sysfs_add_file_mode_ns(dir_sd, *attr, false, 58 error = sysfs_add_file_mode_ns(parent, *attr, false,
59 (*attr)->mode | mode, 59 (*attr)->mode | mode,
60 NULL); 60 NULL);
61 if (unlikely(error)) 61 if (unlikely(error))
62 break; 62 break;
63 } 63 }
64 if (error) { 64 if (error) {
65 remove_files(dir_sd, kobj, grp); 65 remove_files(parent, kobj, grp);
66 goto exit; 66 goto exit;
67 } 67 }
68 } 68 }
@@ -76,7 +76,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
76 break; 76 break;
77 } 77 }
78 if (error) 78 if (error)
79 remove_files(dir_sd, kobj, grp); 79 remove_files(parent, kobj, grp);
80 } 80 }
81exit: 81exit:
82 return error; 82 return error;
@@ -86,7 +86,7 @@ exit:
86static int internal_create_group(struct kobject *kobj, int update, 86static int internal_create_group(struct kobject *kobj, int update,
87 const struct attribute_group *grp) 87 const struct attribute_group *grp)
88{ 88{
89 struct sysfs_dirent *sd; 89 struct kernfs_node *kn;
90 int error; 90 int error;
91 91
92 BUG_ON(!kobj || (!update && !kobj->sd)); 92 BUG_ON(!kobj || (!update && !kobj->sd));
@@ -100,21 +100,21 @@ static int internal_create_group(struct kobject *kobj, int update,
100 return -EINVAL; 100 return -EINVAL;
101 } 101 }
102 if (grp->name) { 102 if (grp->name) {
103 sd = kernfs_create_dir(kobj->sd, grp->name, kobj); 103 kn = kernfs_create_dir(kobj->sd, grp->name, kobj);
104 if (IS_ERR(sd)) { 104 if (IS_ERR(kn)) {
105 if (PTR_ERR(sd) == -EEXIST) 105 if (PTR_ERR(kn) == -EEXIST)
106 sysfs_warn_dup(kobj->sd, grp->name); 106 sysfs_warn_dup(kobj->sd, grp->name);
107 return PTR_ERR(sd); 107 return PTR_ERR(kn);
108 } 108 }
109 } else 109 } else
110 sd = kobj->sd; 110 kn = kobj->sd;
111 kernfs_get(sd); 111 kernfs_get(kn);
112 error = create_files(sd, kobj, grp, update); 112 error = create_files(kn, kobj, grp, update);
113 if (error) { 113 if (error) {
114 if (grp->name) 114 if (grp->name)
115 kernfs_remove(sd); 115 kernfs_remove(kn);
116 } 116 }
117 kernfs_put(sd); 117 kernfs_put(kn);
118 return error; 118 return error;
119} 119}
120 120
@@ -204,27 +204,27 @@ EXPORT_SYMBOL_GPL(sysfs_update_group);
204void sysfs_remove_group(struct kobject *kobj, 204void sysfs_remove_group(struct kobject *kobj,
205 const struct attribute_group *grp) 205 const struct attribute_group *grp)
206{ 206{
207 struct sysfs_dirent *dir_sd = kobj->sd; 207 struct kernfs_node *parent = kobj->sd;
208 struct sysfs_dirent *sd; 208 struct kernfs_node *kn;
209 209
210 if (grp->name) { 210 if (grp->name) {
211 sd = kernfs_find_and_get(dir_sd, grp->name); 211 kn = kernfs_find_and_get(parent, grp->name);
212 if (!sd) { 212 if (!kn) {
213 WARN(!sd, KERN_WARNING 213 WARN(!kn, KERN_WARNING
214 "sysfs group %p not found for kobject '%s'\n", 214 "sysfs group %p not found for kobject '%s'\n",
215 grp, kobject_name(kobj)); 215 grp, kobject_name(kobj));
216 return; 216 return;
217 } 217 }
218 } else { 218 } else {
219 sd = dir_sd; 219 kn = parent;
220 kernfs_get(sd); 220 kernfs_get(kn);
221 } 221 }
222 222
223 remove_files(sd, kobj, grp); 223 remove_files(kn, kobj, grp);
224 if (grp->name) 224 if (grp->name)
225 kernfs_remove(sd); 225 kernfs_remove(kn);
226 226
227 kernfs_put(sd); 227 kernfs_put(kn);
228} 228}
229EXPORT_SYMBOL_GPL(sysfs_remove_group); 229EXPORT_SYMBOL_GPL(sysfs_remove_group);
230 230
@@ -260,22 +260,22 @@ EXPORT_SYMBOL_GPL(sysfs_remove_groups);
260int sysfs_merge_group(struct kobject *kobj, 260int sysfs_merge_group(struct kobject *kobj,
261 const struct attribute_group *grp) 261 const struct attribute_group *grp)
262{ 262{
263 struct sysfs_dirent *dir_sd; 263 struct kernfs_node *parent;
264 int error = 0; 264 int error = 0;
265 struct attribute *const *attr; 265 struct attribute *const *attr;
266 int i; 266 int i;
267 267
268 dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 268 parent = kernfs_find_and_get(kobj->sd, grp->name);
269 if (!dir_sd) 269 if (!parent)
270 return -ENOENT; 270 return -ENOENT;
271 271
272 for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) 272 for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr))
273 error = sysfs_add_file(dir_sd, *attr, false); 273 error = sysfs_add_file(parent, *attr, false);
274 if (error) { 274 if (error) {
275 while (--i >= 0) 275 while (--i >= 0)
276 kernfs_remove_by_name(dir_sd, (*--attr)->name); 276 kernfs_remove_by_name(parent, (*--attr)->name);
277 } 277 }
278 kernfs_put(dir_sd); 278 kernfs_put(parent);
279 279
280 return error; 280 return error;
281} 281}
@@ -289,14 +289,14 @@ EXPORT_SYMBOL_GPL(sysfs_merge_group);
289void sysfs_unmerge_group(struct kobject *kobj, 289void sysfs_unmerge_group(struct kobject *kobj,
290 const struct attribute_group *grp) 290 const struct attribute_group *grp)
291{ 291{
292 struct sysfs_dirent *dir_sd; 292 struct kernfs_node *parent;
293 struct attribute *const *attr; 293 struct attribute *const *attr;
294 294
295 dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 295 parent = kernfs_find_and_get(kobj->sd, grp->name);
296 if (dir_sd) { 296 if (parent) {
297 for (attr = grp->attrs; *attr; ++attr) 297 for (attr = grp->attrs; *attr; ++attr)
298 kernfs_remove_by_name(dir_sd, (*attr)->name); 298 kernfs_remove_by_name(parent, (*attr)->name);
299 kernfs_put(dir_sd); 299 kernfs_put(parent);
300 } 300 }
301} 301}
302EXPORT_SYMBOL_GPL(sysfs_unmerge_group); 302EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
@@ -311,15 +311,15 @@ EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
311int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, 311int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
312 struct kobject *target, const char *link_name) 312 struct kobject *target, const char *link_name)
313{ 313{
314 struct sysfs_dirent *dir_sd; 314 struct kernfs_node *parent;
315 int error = 0; 315 int error = 0;
316 316
317 dir_sd = kernfs_find_and_get(kobj->sd, group_name); 317 parent = kernfs_find_and_get(kobj->sd, group_name);
318 if (!dir_sd) 318 if (!parent)
319 return -ENOENT; 319 return -ENOENT;
320 320
321 error = sysfs_create_link_sd(dir_sd, target, link_name); 321 error = sysfs_create_link_sd(parent, target, link_name);
322 kernfs_put(dir_sd); 322 kernfs_put(parent);
323 323
324 return error; 324 return error;
325} 325}
@@ -334,12 +334,12 @@ EXPORT_SYMBOL_GPL(sysfs_add_link_to_group);
334void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, 334void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
335 const char *link_name) 335 const char *link_name)
336{ 336{
337 struct sysfs_dirent *dir_sd; 337 struct kernfs_node *parent;
338 338
339 dir_sd = kernfs_find_and_get(kobj->sd, group_name); 339 parent = kernfs_find_and_get(kobj->sd, group_name);
340 if (dir_sd) { 340 if (parent) {
341 kernfs_remove_by_name(dir_sd, link_name); 341 kernfs_remove_by_name(parent, link_name);
342 kernfs_put(dir_sd); 342 kernfs_put(parent);
343 } 343 }
344} 344}
345EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); 345EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 8d075272cace..701a56f341c6 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -20,7 +20,7 @@
20#include "sysfs.h" 20#include "sysfs.h"
21 21
22static struct kernfs_root *sysfs_root; 22static struct kernfs_root *sysfs_root;
23struct sysfs_dirent *sysfs_root_sd; 23struct kernfs_node *sysfs_root_kn;
24 24
25static struct dentry *sysfs_mount(struct file_system_type *fs_type, 25static struct dentry *sysfs_mount(struct file_system_type *fs_type,
26 int flags, const char *dev_name, void *data) 26 int flags, const char *dev_name, void *data)
@@ -66,7 +66,7 @@ int __init sysfs_init(void)
66 if (IS_ERR(sysfs_root)) 66 if (IS_ERR(sysfs_root))
67 return PTR_ERR(sysfs_root); 67 return PTR_ERR(sysfs_root);
68 68
69 sysfs_root_sd = sysfs_root->sd; 69 sysfs_root_kn = sysfs_root->kn;
70 70
71 err = register_filesystem(&sysfs_fs_type); 71 err = register_filesystem(&sysfs_fs_type);
72 if (err) { 72 if (err) {
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 1b8c9ed8511a..4ed3d49ad279 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -18,66 +18,66 @@
18 18
19#include "sysfs.h" 19#include "sysfs.h"
20 20
21static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd, 21static int sysfs_do_create_link_sd(struct kernfs_node *parent,
22 struct kobject *target, 22 struct kobject *target_kobj,
23 const char *name, int warn) 23 const char *name, int warn)
24{ 24{
25 struct sysfs_dirent *sd, *target_sd = NULL; 25 struct kernfs_node *kn, *target = NULL;
26 26
27 BUG_ON(!name || !parent_sd); 27 BUG_ON(!name || !parent);
28 28
29 /* 29 /*
30 * We don't own @target and it may be removed at any time. 30 * We don't own @target_kobj and it may be removed at any time.
31 * Synchronize using sysfs_symlink_target_lock. See 31 * Synchronize using sysfs_symlink_target_lock. See
32 * sysfs_remove_dir() for details. 32 * sysfs_remove_dir() for details.
33 */ 33 */
34 spin_lock(&sysfs_symlink_target_lock); 34 spin_lock(&sysfs_symlink_target_lock);
35 if (target->sd) { 35 if (target_kobj->sd) {
36 target_sd = target->sd; 36 target = target_kobj->sd;
37 kernfs_get(target_sd); 37 kernfs_get(target);
38 } 38 }
39 spin_unlock(&sysfs_symlink_target_lock); 39 spin_unlock(&sysfs_symlink_target_lock);
40 40
41 if (!target_sd) 41 if (!target)
42 return -ENOENT; 42 return -ENOENT;
43 43
44 sd = kernfs_create_link(parent_sd, name, target_sd); 44 kn = kernfs_create_link(parent, name, target);
45 kernfs_put(target_sd); 45 kernfs_put(target);
46 46
47 if (!IS_ERR(sd)) 47 if (!IS_ERR(kn))
48 return 0; 48 return 0;
49 49
50 if (warn && PTR_ERR(sd) == -EEXIST) 50 if (warn && PTR_ERR(kn) == -EEXIST)
51 sysfs_warn_dup(parent_sd, name); 51 sysfs_warn_dup(parent, name);
52 return PTR_ERR(sd); 52 return PTR_ERR(kn);
53} 53}
54 54
55/** 55/**
56 * sysfs_create_link_sd - create symlink to a given object. 56 * sysfs_create_link_sd - create symlink to a given object.
57 * @sd: directory we're creating the link in. 57 * @kn: directory we're creating the link in.
58 * @target: object we're pointing to. 58 * @target: object we're pointing to.
59 * @name: name of the symlink. 59 * @name: name of the symlink.
60 */ 60 */
61int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, 61int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target,
62 const char *name) 62 const char *name)
63{ 63{
64 return sysfs_do_create_link_sd(sd, target, name, 1); 64 return sysfs_do_create_link_sd(kn, target, name, 1);
65} 65}
66 66
67static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target, 67static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
68 const char *name, int warn) 68 const char *name, int warn)
69{ 69{
70 struct sysfs_dirent *parent_sd = NULL; 70 struct kernfs_node *parent = NULL;
71 71
72 if (!kobj) 72 if (!kobj)
73 parent_sd = sysfs_root_sd; 73 parent = sysfs_root_kn;
74 else 74 else
75 parent_sd = kobj->sd; 75 parent = kobj->sd;
76 76
77 if (!parent_sd) 77 if (!parent)
78 return -EFAULT; 78 return -EFAULT;
79 79
80 return sysfs_do_create_link_sd(parent_sd, target, name, warn); 80 return sysfs_do_create_link_sd(parent, target, name, warn);
81} 81}
82 82
83/** 83/**
@@ -141,14 +141,14 @@ void sysfs_delete_link(struct kobject *kobj, struct kobject *targ,
141 */ 141 */
142void sysfs_remove_link(struct kobject *kobj, const char *name) 142void sysfs_remove_link(struct kobject *kobj, const char *name)
143{ 143{
144 struct sysfs_dirent *parent_sd = NULL; 144 struct kernfs_node *parent = NULL;
145 145
146 if (!kobj) 146 if (!kobj)
147 parent_sd = sysfs_root_sd; 147 parent = sysfs_root_kn;
148 else 148 else
149 parent_sd = kobj->sd; 149 parent = kobj->sd;
150 150
151 kernfs_remove_by_name(parent_sd, name); 151 kernfs_remove_by_name(parent, name);
152} 152}
153EXPORT_SYMBOL_GPL(sysfs_remove_link); 153EXPORT_SYMBOL_GPL(sysfs_remove_link);
154 154
@@ -165,33 +165,33 @@ EXPORT_SYMBOL_GPL(sysfs_remove_link);
165int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ, 165int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
166 const char *old, const char *new, const void *new_ns) 166 const char *old, const char *new, const void *new_ns)
167{ 167{
168 struct sysfs_dirent *parent_sd, *sd = NULL; 168 struct kernfs_node *parent, *kn = NULL;
169 const void *old_ns = NULL; 169 const void *old_ns = NULL;
170 int result; 170 int result;
171 171
172 if (!kobj) 172 if (!kobj)
173 parent_sd = sysfs_root_sd; 173 parent = sysfs_root_kn;
174 else 174 else
175 parent_sd = kobj->sd; 175 parent = kobj->sd;
176 176
177 if (targ->sd) 177 if (targ->sd)
178 old_ns = targ->sd->s_ns; 178 old_ns = targ->sd->s_ns;
179 179
180 result = -ENOENT; 180 result = -ENOENT;
181 sd = kernfs_find_and_get_ns(parent_sd, old, old_ns); 181 kn = kernfs_find_and_get_ns(parent, old, old_ns);
182 if (!sd) 182 if (!kn)
183 goto out; 183 goto out;
184 184
185 result = -EINVAL; 185 result = -EINVAL;
186 if (sysfs_type(sd) != SYSFS_KOBJ_LINK) 186 if (sysfs_type(kn) != SYSFS_KOBJ_LINK)
187 goto out; 187 goto out;
188 if (sd->s_symlink.target_sd->priv != targ) 188 if (kn->s_symlink.target_kn->priv != targ)
189 goto out; 189 goto out;
190 190
191 result = kernfs_rename_ns(sd, parent_sd, new, new_ns); 191 result = kernfs_rename_ns(kn, parent, new, new_ns);
192 192
193out: 193out:
194 kernfs_put(sd); 194 kernfs_put(kn);
195 return result; 195 return result;
196} 196}
197EXPORT_SYMBOL_GPL(sysfs_rename_link_ns); 197EXPORT_SYMBOL_GPL(sysfs_rename_link_ns);
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index c8e395b49330..0e2f1cccb812 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -16,28 +16,28 @@
16/* 16/*
17 * mount.c 17 * mount.c
18 */ 18 */
19extern struct sysfs_dirent *sysfs_root_sd; 19extern struct kernfs_node *sysfs_root_kn;
20 20
21/* 21/*
22 * dir.c 22 * dir.c
23 */ 23 */
24extern spinlock_t sysfs_symlink_target_lock; 24extern spinlock_t sysfs_symlink_target_lock;
25 25
26void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name); 26void sysfs_warn_dup(struct kernfs_node *parent, const char *name);
27 27
28/* 28/*
29 * file.c 29 * file.c
30 */ 30 */
31int sysfs_add_file(struct sysfs_dirent *dir_sd, 31int sysfs_add_file(struct kernfs_node *parent,
32 const struct attribute *attr, bool is_bin); 32 const struct attribute *attr, bool is_bin);
33int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, 33int sysfs_add_file_mode_ns(struct kernfs_node *parent,
34 const struct attribute *attr, bool is_bin, 34 const struct attribute *attr, bool is_bin,
35 umode_t amode, const void *ns); 35 umode_t amode, const void *ns);
36 36
37/* 37/*
38 * symlink.c 38 * symlink.c
39 */ 39 */
40int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, 40int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target,
41 const char *name); 41 const char *name);
42 42
43#endif /* __SYSFS_INTERNAL_H */ 43#endif /* __SYSFS_INTERNAL_H */