aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs
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/kernfs
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/kernfs')
-rw-r--r--fs/kernfs/dir.c542
-rw-r--r--fs/kernfs/file.c186
-rw-r--r--fs/kernfs/inode.c123
-rw-r--r--fs/kernfs/kernfs-internal.h40
-rw-r--r--fs/kernfs/mount.c12
-rw-r--r--fs/kernfs/symlink.c64
6 files changed, 484 insertions, 483 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index a441e3be8052..800ebf521472 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -19,7 +19,7 @@
19 19
20DEFINE_MUTEX(sysfs_mutex); 20DEFINE_MUTEX(sysfs_mutex);
21 21
22#define to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb) 22#define rb_to_kn(X) rb_entry((X), struct kernfs_node, s_rb)
23 23
24/** 24/**
25 * sysfs_name_hash 25 * sysfs_name_hash
@@ -45,28 +45,28 @@ static unsigned int sysfs_name_hash(const char *name, const void *ns)
45} 45}
46 46
47static int sysfs_name_compare(unsigned int hash, const char *name, 47static int sysfs_name_compare(unsigned int hash, const char *name,
48 const void *ns, const struct sysfs_dirent *sd) 48 const void *ns, const struct kernfs_node *kn)
49{ 49{
50 if (hash != sd->s_hash) 50 if (hash != kn->s_hash)
51 return hash - sd->s_hash; 51 return hash - kn->s_hash;
52 if (ns != sd->s_ns) 52 if (ns != kn->s_ns)
53 return ns - sd->s_ns; 53 return ns - kn->s_ns;
54 return strcmp(name, sd->s_name); 54 return strcmp(name, kn->s_name);
55} 55}
56 56
57static int sysfs_sd_compare(const struct sysfs_dirent *left, 57static int sysfs_sd_compare(const struct kernfs_node *left,
58 const struct sysfs_dirent *right) 58 const struct kernfs_node *right)
59{ 59{
60 return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns, 60 return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns,
61 right); 61 right);
62} 62}
63 63
64/** 64/**
65 * sysfs_link_sibling - link sysfs_dirent into sibling rbtree 65 * sysfs_link_sibling - link kernfs_node into sibling rbtree
66 * @sd: sysfs_dirent of interest 66 * @kn: kernfs_node of interest
67 * 67 *
68 * Link @sd into its sibling rbtree which starts from 68 * Link @kn into its sibling rbtree which starts from
69 * sd->s_parent->s_dir.children. 69 * @kn->s_parent->s_dir.children.
70 * 70 *
71 * Locking: 71 * Locking:
72 * mutex_lock(sysfs_mutex) 72 * mutex_lock(sysfs_mutex)
@@ -74,21 +74,21 @@ static int sysfs_sd_compare(const struct sysfs_dirent *left,
74 * RETURNS: 74 * RETURNS:
75 * 0 on susccess -EEXIST on failure. 75 * 0 on susccess -EEXIST on failure.
76 */ 76 */
77static int sysfs_link_sibling(struct sysfs_dirent *sd) 77static int sysfs_link_sibling(struct kernfs_node *kn)
78{ 78{
79 struct rb_node **node = &sd->s_parent->s_dir.children.rb_node; 79 struct rb_node **node = &kn->s_parent->s_dir.children.rb_node;
80 struct rb_node *parent = NULL; 80 struct rb_node *parent = NULL;
81 81
82 if (sysfs_type(sd) == SYSFS_DIR) 82 if (sysfs_type(kn) == SYSFS_DIR)
83 sd->s_parent->s_dir.subdirs++; 83 kn->s_parent->s_dir.subdirs++;
84 84
85 while (*node) { 85 while (*node) {
86 struct sysfs_dirent *pos; 86 struct kernfs_node *pos;
87 int result; 87 int result;
88 88
89 pos = to_sysfs_dirent(*node); 89 pos = rb_to_kn(*node);
90 parent = *node; 90 parent = *node;
91 result = sysfs_sd_compare(sd, pos); 91 result = sysfs_sd_compare(kn, pos);
92 if (result < 0) 92 if (result < 0)
93 node = &pos->s_rb.rb_left; 93 node = &pos->s_rb.rb_left;
94 else if (result > 0) 94 else if (result > 0)
@@ -97,168 +97,169 @@ static int sysfs_link_sibling(struct sysfs_dirent *sd)
97 return -EEXIST; 97 return -EEXIST;
98 } 98 }
99 /* add new node and rebalance the tree */ 99 /* add new node and rebalance the tree */
100 rb_link_node(&sd->s_rb, parent, node); 100 rb_link_node(&kn->s_rb, parent, node);
101 rb_insert_color(&sd->s_rb, &sd->s_parent->s_dir.children); 101 rb_insert_color(&kn->s_rb, &kn->s_parent->s_dir.children);
102 return 0; 102 return 0;
103} 103}
104 104
105/** 105/**
106 * sysfs_unlink_sibling - unlink sysfs_dirent from sibling rbtree 106 * sysfs_unlink_sibling - unlink kernfs_node from sibling rbtree
107 * @sd: sysfs_dirent of interest 107 * @kn: kernfs_node of interest
108 * 108 *
109 * Unlink @sd from its sibling rbtree which starts from 109 * Unlink @kn from its sibling rbtree which starts from
110 * sd->s_parent->s_dir.children. 110 * kn->s_parent->s_dir.children.
111 * 111 *
112 * Locking: 112 * Locking:
113 * mutex_lock(sysfs_mutex) 113 * mutex_lock(sysfs_mutex)
114 */ 114 */
115static void sysfs_unlink_sibling(struct sysfs_dirent *sd) 115static void sysfs_unlink_sibling(struct kernfs_node *kn)
116{ 116{
117 if (sysfs_type(sd) == SYSFS_DIR) 117 if (sysfs_type(kn) == SYSFS_DIR)
118 sd->s_parent->s_dir.subdirs--; 118 kn->s_parent->s_dir.subdirs--;
119 119
120 rb_erase(&sd->s_rb, &sd->s_parent->s_dir.children); 120 rb_erase(&kn->s_rb, &kn->s_parent->s_dir.children);
121} 121}
122 122
123/** 123/**
124 * sysfs_get_active - get an active reference to sysfs_dirent 124 * sysfs_get_active - get an active reference to kernfs_node
125 * @sd: sysfs_dirent to get an active reference to 125 * @kn: kernfs_node to get an active reference to
126 * 126 *
127 * Get an active reference of @sd. This function is noop if @sd 127 * Get an active reference of @kn. This function is noop if @kn
128 * is NULL. 128 * is NULL.
129 * 129 *
130 * RETURNS: 130 * RETURNS:
131 * Pointer to @sd on success, NULL on failure. 131 * Pointer to @kn on success, NULL on failure.
132 */ 132 */
133struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd) 133struct kernfs_node *sysfs_get_active(struct kernfs_node *kn)
134{ 134{
135 if (unlikely(!sd)) 135 if (unlikely(!kn))
136 return NULL; 136 return NULL;
137 137
138 if (!atomic_inc_unless_negative(&sd->s_active)) 138 if (!atomic_inc_unless_negative(&kn->s_active))
139 return NULL; 139 return NULL;
140 140
141 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 141 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
142 rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_); 142 rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_);
143 return sd; 143 return kn;
144} 144}
145 145
146/** 146/**
147 * sysfs_put_active - put an active reference to sysfs_dirent 147 * sysfs_put_active - put an active reference to kernfs_node
148 * @sd: sysfs_dirent to put an active reference to 148 * @kn: kernfs_node to put an active reference to
149 * 149 *
150 * Put an active reference to @sd. This function is noop if @sd 150 * Put an active reference to @kn. This function is noop if @kn
151 * is NULL. 151 * is NULL.
152 */ 152 */
153void sysfs_put_active(struct sysfs_dirent *sd) 153void sysfs_put_active(struct kernfs_node *kn)
154{ 154{
155 int v; 155 int v;
156 156
157 if (unlikely(!sd)) 157 if (unlikely(!kn))
158 return; 158 return;
159 159
160 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 160 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
161 rwsem_release(&sd->dep_map, 1, _RET_IP_); 161 rwsem_release(&kn->dep_map, 1, _RET_IP_);
162 v = atomic_dec_return(&sd->s_active); 162 v = atomic_dec_return(&kn->s_active);
163 if (likely(v != SD_DEACTIVATED_BIAS)) 163 if (likely(v != SD_DEACTIVATED_BIAS))
164 return; 164 return;
165 165
166 /* atomic_dec_return() is a mb(), we'll always see the updated 166 /*
167 * sd->u.completion. 167 * atomic_dec_return() is a mb(), we'll always see the updated
168 * kn->u.completion.
168 */ 169 */
169 complete(sd->u.completion); 170 complete(kn->u.completion);
170} 171}
171 172
172/** 173/**
173 * sysfs_deactivate - deactivate sysfs_dirent 174 * sysfs_deactivate - deactivate kernfs_node
174 * @sd: sysfs_dirent to deactivate 175 * @kn: kernfs_node to deactivate
175 * 176 *
176 * Deny new active references and drain existing ones. 177 * Deny new active references and drain existing ones.
177 */ 178 */
178static void sysfs_deactivate(struct sysfs_dirent *sd) 179static void sysfs_deactivate(struct kernfs_node *kn)
179{ 180{
180 DECLARE_COMPLETION_ONSTACK(wait); 181 DECLARE_COMPLETION_ONSTACK(wait);
181 int v; 182 int v;
182 183
183 BUG_ON(!(sd->s_flags & SYSFS_FLAG_REMOVED)); 184 BUG_ON(!(kn->s_flags & SYSFS_FLAG_REMOVED));
184 185
185 if (!(sysfs_type(sd) & SYSFS_ACTIVE_REF)) 186 if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF))
186 return; 187 return;
187 188
188 sd->u.completion = (void *)&wait; 189 kn->u.completion = (void *)&wait;
189 190
190 rwsem_acquire(&sd->dep_map, 0, 0, _RET_IP_); 191 rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
191 /* atomic_add_return() is a mb(), put_active() will always see 192 /* atomic_add_return() is a mb(), put_active() will always see
192 * the updated sd->u.completion. 193 * the updated kn->u.completion.
193 */ 194 */
194 v = atomic_add_return(SD_DEACTIVATED_BIAS, &sd->s_active); 195 v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->s_active);
195 196
196 if (v != SD_DEACTIVATED_BIAS) { 197 if (v != SD_DEACTIVATED_BIAS) {
197 lock_contended(&sd->dep_map, _RET_IP_); 198 lock_contended(&kn->dep_map, _RET_IP_);
198 wait_for_completion(&wait); 199 wait_for_completion(&wait);
199 } 200 }
200 201
201 lock_acquired(&sd->dep_map, _RET_IP_); 202 lock_acquired(&kn->dep_map, _RET_IP_);
202 rwsem_release(&sd->dep_map, 1, _RET_IP_); 203 rwsem_release(&kn->dep_map, 1, _RET_IP_);
203} 204}
204 205
205/** 206/**
206 * kernfs_get - get a reference count on a sysfs_dirent 207 * kernfs_get - get a reference count on a kernfs_node
207 * @sd: the target sysfs_dirent 208 * @kn: the target kernfs_node
208 */ 209 */
209void kernfs_get(struct sysfs_dirent *sd) 210void kernfs_get(struct kernfs_node *kn)
210{ 211{
211 if (sd) { 212 if (kn) {
212 WARN_ON(!atomic_read(&sd->s_count)); 213 WARN_ON(!atomic_read(&kn->s_count));
213 atomic_inc(&sd->s_count); 214 atomic_inc(&kn->s_count);
214 } 215 }
215} 216}
216EXPORT_SYMBOL_GPL(kernfs_get); 217EXPORT_SYMBOL_GPL(kernfs_get);
217 218
218/** 219/**
219 * kernfs_put - put a reference count on a sysfs_dirent 220 * kernfs_put - put a reference count on a kernfs_node
220 * @sd: the target sysfs_dirent 221 * @kn: the target kernfs_node
221 * 222 *
222 * Put a reference count of @sd and destroy it if it reached zero. 223 * Put a reference count of @kn and destroy it if it reached zero.
223 */ 224 */
224void kernfs_put(struct sysfs_dirent *sd) 225void kernfs_put(struct kernfs_node *kn)
225{ 226{
226 struct sysfs_dirent *parent_sd; 227 struct kernfs_node *parent;
227 struct kernfs_root *root; 228 struct kernfs_root *root;
228 229
229 if (!sd || !atomic_dec_and_test(&sd->s_count)) 230 if (!kn || !atomic_dec_and_test(&kn->s_count))
230 return; 231 return;
231 root = kernfs_root(sd); 232 root = kernfs_root(kn);
232 repeat: 233 repeat:
233 /* Moving/renaming is always done while holding reference. 234 /* Moving/renaming is always done while holding reference.
234 * sd->s_parent won't change beneath us. 235 * kn->s_parent won't change beneath us.
235 */ 236 */
236 parent_sd = sd->s_parent; 237 parent = kn->s_parent;
237 238
238 WARN(!(sd->s_flags & SYSFS_FLAG_REMOVED), 239 WARN(!(kn->s_flags & SYSFS_FLAG_REMOVED),
239 "sysfs: free using entry: %s/%s\n", 240 "sysfs: free using entry: %s/%s\n",
240 parent_sd ? parent_sd->s_name : "", sd->s_name); 241 parent ? parent->s_name : "", kn->s_name);
241 242
242 if (sysfs_type(sd) == SYSFS_KOBJ_LINK) 243 if (sysfs_type(kn) == SYSFS_KOBJ_LINK)
243 kernfs_put(sd->s_symlink.target_sd); 244 kernfs_put(kn->s_symlink.target_kn);
244 if (sysfs_type(sd) & SYSFS_COPY_NAME) 245 if (sysfs_type(kn) & SYSFS_COPY_NAME)
245 kfree(sd->s_name); 246 kfree(kn->s_name);
246 if (sd->s_iattr) { 247 if (kn->s_iattr) {
247 if (sd->s_iattr->ia_secdata) 248 if (kn->s_iattr->ia_secdata)
248 security_release_secctx(sd->s_iattr->ia_secdata, 249 security_release_secctx(kn->s_iattr->ia_secdata,
249 sd->s_iattr->ia_secdata_len); 250 kn->s_iattr->ia_secdata_len);
250 simple_xattrs_free(&sd->s_iattr->xattrs); 251 simple_xattrs_free(&kn->s_iattr->xattrs);
251 } 252 }
252 kfree(sd->s_iattr); 253 kfree(kn->s_iattr);
253 ida_simple_remove(&root->ino_ida, sd->s_ino); 254 ida_simple_remove(&root->ino_ida, kn->s_ino);
254 kmem_cache_free(sysfs_dir_cachep, sd); 255 kmem_cache_free(sysfs_dir_cachep, kn);
255 256
256 sd = parent_sd; 257 kn = parent;
257 if (sd) { 258 if (kn) {
258 if (atomic_dec_and_test(&sd->s_count)) 259 if (atomic_dec_and_test(&kn->s_count))
259 goto repeat; 260 goto repeat;
260 } else { 261 } else {
261 /* just released the root sd, free @root too */ 262 /* just released the root kn, free @root too */
262 ida_destroy(&root->ino_ida); 263 ida_destroy(&root->ino_ida);
263 kfree(root); 264 kfree(root);
264 } 265 }
@@ -267,35 +268,35 @@ EXPORT_SYMBOL_GPL(kernfs_put);
267 268
268static int sysfs_dentry_delete(const struct dentry *dentry) 269static int sysfs_dentry_delete(const struct dentry *dentry)
269{ 270{
270 struct sysfs_dirent *sd = dentry->d_fsdata; 271 struct kernfs_node *kn = dentry->d_fsdata;
271 return !(sd && !(sd->s_flags & SYSFS_FLAG_REMOVED)); 272 return !(kn && !(kn->s_flags & SYSFS_FLAG_REMOVED));
272} 273}
273 274
274static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags) 275static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
275{ 276{
276 struct sysfs_dirent *sd; 277 struct kernfs_node *kn;
277 278
278 if (flags & LOOKUP_RCU) 279 if (flags & LOOKUP_RCU)
279 return -ECHILD; 280 return -ECHILD;
280 281
281 sd = dentry->d_fsdata; 282 kn = dentry->d_fsdata;
282 mutex_lock(&sysfs_mutex); 283 mutex_lock(&sysfs_mutex);
283 284
284 /* The sysfs dirent has been deleted */ 285 /* The sysfs dirent has been deleted */
285 if (sd->s_flags & SYSFS_FLAG_REMOVED) 286 if (kn->s_flags & SYSFS_FLAG_REMOVED)
286 goto out_bad; 287 goto out_bad;
287 288
288 /* The sysfs dirent has been moved? */ 289 /* The sysfs dirent has been moved? */
289 if (dentry->d_parent->d_fsdata != sd->s_parent) 290 if (dentry->d_parent->d_fsdata != kn->s_parent)
290 goto out_bad; 291 goto out_bad;
291 292
292 /* The sysfs dirent has been renamed */ 293 /* The sysfs dirent has been renamed */
293 if (strcmp(dentry->d_name.name, sd->s_name) != 0) 294 if (strcmp(dentry->d_name.name, kn->s_name) != 0)
294 goto out_bad; 295 goto out_bad;
295 296
296 /* The sysfs dirent has been moved to a different namespace */ 297 /* The sysfs dirent has been moved to a different namespace */
297 if (sd->s_parent && kernfs_ns_enabled(sd->s_parent) && 298 if (kn->s_parent && kernfs_ns_enabled(kn->s_parent) &&
298 sysfs_info(dentry->d_sb)->ns != sd->s_ns) 299 sysfs_info(dentry->d_sb)->ns != kn->s_ns)
299 goto out_bad; 300 goto out_bad;
300 301
301 mutex_unlock(&sysfs_mutex); 302 mutex_unlock(&sysfs_mutex);
@@ -335,11 +336,11 @@ const struct dentry_operations sysfs_dentry_ops = {
335 .d_release = sysfs_dentry_release, 336 .d_release = sysfs_dentry_release,
336}; 337};
337 338
338struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, 339struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
339 const char *name, umode_t mode, int type) 340 const char *name, umode_t mode, int type)
340{ 341{
341 char *dup_name = NULL; 342 char *dup_name = NULL;
342 struct sysfs_dirent *sd; 343 struct kernfs_node *kn;
343 int ret; 344 int ret;
344 345
345 if (type & SYSFS_COPY_NAME) { 346 if (type & SYSFS_COPY_NAME) {
@@ -348,38 +349,38 @@ struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root,
348 return NULL; 349 return NULL;
349 } 350 }
350 351
351 sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); 352 kn = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL);
352 if (!sd) 353 if (!kn)
353 goto err_out1; 354 goto err_out1;
354 355
355 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); 356 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL);
356 if (ret < 0) 357 if (ret < 0)
357 goto err_out2; 358 goto err_out2;
358 sd->s_ino = ret; 359 kn->s_ino = ret;
359 360
360 atomic_set(&sd->s_count, 1); 361 atomic_set(&kn->s_count, 1);
361 atomic_set(&sd->s_active, 0); 362 atomic_set(&kn->s_active, 0);
362 363
363 sd->s_name = name; 364 kn->s_name = name;
364 sd->s_mode = mode; 365 kn->s_mode = mode;
365 sd->s_flags = type | SYSFS_FLAG_REMOVED; 366 kn->s_flags = type | SYSFS_FLAG_REMOVED;
366 367
367 return sd; 368 return kn;
368 369
369 err_out2: 370 err_out2:
370 kmem_cache_free(sysfs_dir_cachep, sd); 371 kmem_cache_free(sysfs_dir_cachep, kn);
371 err_out1: 372 err_out1:
372 kfree(dup_name); 373 kfree(dup_name);
373 return NULL; 374 return NULL;
374} 375}
375 376
376/** 377/**
377 * sysfs_addrm_start - prepare for sysfs_dirent add/remove 378 * sysfs_addrm_start - prepare for kernfs_node add/remove
378 * @acxt: pointer to sysfs_addrm_cxt to be used 379 * @acxt: pointer to sysfs_addrm_cxt to be used
379 * 380 *
380 * This function is called when the caller is about to add or remove 381 * This function is called when the caller is about to add or remove
381 * sysfs_dirent. This function acquires sysfs_mutex. @acxt is used 382 * kernfs_node. This function acquires sysfs_mutex. @acxt is used to
382 * to keep and pass context to other addrm functions. 383 * keep and pass context to other addrm functions.
383 * 384 *
384 * LOCKING: 385 * LOCKING:
385 * Kernel thread context (may sleep). sysfs_mutex is locked on 386 * Kernel thread context (may sleep). sysfs_mutex is locked on
@@ -394,13 +395,13 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
394} 395}
395 396
396/** 397/**
397 * sysfs_add_one - add sysfs_dirent to parent without warning 398 * sysfs_add_one - add kernfs_node to parent without warning
398 * @acxt: addrm context to use 399 * @acxt: addrm context to use
399 * @sd: sysfs_dirent to be added 400 * @kn: kernfs_node to be added
400 * @parent_sd: the parent sysfs_dirent to add @sd to 401 * @parent: the parent kernfs_node to add @kn to
401 * 402 *
402 * Get @parent_sd and set @sd->s_parent to it and increment nlink of 403 * Get @parent and set @kn->s_parent to it and increment nlink of
403 * the parent inode if @sd is a directory and link into the children 404 * the parent inode if @kn is a directory and link into the children
404 * list of the parent. 405 * list of the parent.
405 * 406 *
406 * This function should be called between calls to 407 * This function should be called between calls to
@@ -414,51 +415,51 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
414 * 0 on success, -EEXIST if entry with the given name already 415 * 0 on success, -EEXIST if entry with the given name already
415 * exists. 416 * exists.
416 */ 417 */
417int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, 418int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
418 struct sysfs_dirent *parent_sd) 419 struct kernfs_node *parent)
419{ 420{
420 bool has_ns = kernfs_ns_enabled(parent_sd); 421 bool has_ns = kernfs_ns_enabled(parent);
421 struct sysfs_inode_attrs *ps_iattr; 422 struct sysfs_inode_attrs *ps_iattr;
422 int ret; 423 int ret;
423 424
424 if (has_ns != (bool)sd->s_ns) { 425 if (has_ns != (bool)kn->s_ns) {
425 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 426 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
426 has_ns ? "required" : "invalid", 427 has_ns ? "required" : "invalid",
427 parent_sd->s_name, sd->s_name); 428 parent->s_name, kn->s_name);
428 return -EINVAL; 429 return -EINVAL;
429 } 430 }
430 431
431 if (sysfs_type(parent_sd) != SYSFS_DIR) 432 if (sysfs_type(parent) != SYSFS_DIR)
432 return -EINVAL; 433 return -EINVAL;
433 434
434 sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); 435 kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
435 sd->s_parent = parent_sd; 436 kn->s_parent = parent;
436 kernfs_get(parent_sd); 437 kernfs_get(parent);
437 438
438 ret = sysfs_link_sibling(sd); 439 ret = sysfs_link_sibling(kn);
439 if (ret) 440 if (ret)
440 return ret; 441 return ret;
441 442
442 /* Update timestamps on the parent */ 443 /* Update timestamps on the parent */
443 ps_iattr = parent_sd->s_iattr; 444 ps_iattr = parent->s_iattr;
444 if (ps_iattr) { 445 if (ps_iattr) {
445 struct iattr *ps_iattrs = &ps_iattr->ia_iattr; 446 struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
446 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 447 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
447 } 448 }
448 449
449 /* Mark the entry added into directory tree */ 450 /* Mark the entry added into directory tree */
450 sd->s_flags &= ~SYSFS_FLAG_REMOVED; 451 kn->s_flags &= ~SYSFS_FLAG_REMOVED;
451 452
452 return 0; 453 return 0;
453} 454}
454 455
455/** 456/**
456 * sysfs_remove_one - remove sysfs_dirent from parent 457 * sysfs_remove_one - remove kernfs_node from parent
457 * @acxt: addrm context to use 458 * @acxt: addrm context to use
458 * @sd: sysfs_dirent to be removed 459 * @kn: kernfs_node to be removed
459 * 460 *
460 * Mark @sd removed and drop nlink of parent inode if @sd is a 461 * Mark @kn removed and drop nlink of parent inode if @kn is a
461 * directory. @sd is unlinked from the children list. 462 * directory. @kn is unlinked from the children list.
462 * 463 *
463 * This function should be called between calls to 464 * This function should be called between calls to
464 * sysfs_addrm_start() and sysfs_addrm_finish() and should be 465 * sysfs_addrm_start() and sysfs_addrm_finish() and should be
@@ -468,7 +469,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
468 * Determined by sysfs_addrm_start(). 469 * Determined by sysfs_addrm_start().
469 */ 470 */
470static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, 471static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
471 struct sysfs_dirent *sd) 472 struct kernfs_node *kn)
472{ 473{
473 struct sysfs_inode_attrs *ps_iattr; 474 struct sysfs_inode_attrs *ps_iattr;
474 475
@@ -476,31 +477,31 @@ static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
476 * Removal can be called multiple times on the same node. Only the 477 * Removal can be called multiple times on the same node. Only the
477 * first invocation is effective and puts the base ref. 478 * first invocation is effective and puts the base ref.
478 */ 479 */
479 if (sd->s_flags & SYSFS_FLAG_REMOVED) 480 if (kn->s_flags & SYSFS_FLAG_REMOVED)
480 return; 481 return;
481 482
482 if (sd->s_parent) { 483 if (kn->s_parent) {
483 sysfs_unlink_sibling(sd); 484 sysfs_unlink_sibling(kn);
484 485
485 /* Update timestamps on the parent */ 486 /* Update timestamps on the parent */
486 ps_iattr = sd->s_parent->s_iattr; 487 ps_iattr = kn->s_parent->s_iattr;
487 if (ps_iattr) { 488 if (ps_iattr) {
488 ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; 489 ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME;
489 ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; 490 ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME;
490 } 491 }
491 } 492 }
492 493
493 sd->s_flags |= SYSFS_FLAG_REMOVED; 494 kn->s_flags |= SYSFS_FLAG_REMOVED;
494 sd->u.removed_list = acxt->removed; 495 kn->u.removed_list = acxt->removed;
495 acxt->removed = sd; 496 acxt->removed = kn;
496} 497}
497 498
498/** 499/**
499 * sysfs_addrm_finish - finish up sysfs_dirent add/remove 500 * sysfs_addrm_finish - finish up kernfs_node add/remove
500 * @acxt: addrm context to finish up 501 * @acxt: addrm context to finish up
501 * 502 *
502 * Finish up sysfs_dirent add/remove. Resources acquired by 503 * Finish up kernfs_node add/remove. Resources acquired by
503 * sysfs_addrm_start() are released and removed sysfs_dirents are 504 * sysfs_addrm_start() are released and removed kernfs_nodes are
504 * cleaned up. 505 * cleaned up.
505 * 506 *
506 * LOCKING: 507 * LOCKING:
@@ -512,30 +513,30 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
512 /* release resources acquired by sysfs_addrm_start() */ 513 /* release resources acquired by sysfs_addrm_start() */
513 mutex_unlock(&sysfs_mutex); 514 mutex_unlock(&sysfs_mutex);
514 515
515 /* kill removed sysfs_dirents */ 516 /* kill removed kernfs_nodes */
516 while (acxt->removed) { 517 while (acxt->removed) {
517 struct sysfs_dirent *sd = acxt->removed; 518 struct kernfs_node *kn = acxt->removed;
518 519
519 acxt->removed = sd->u.removed_list; 520 acxt->removed = kn->u.removed_list;
520 521
521 sysfs_deactivate(sd); 522 sysfs_deactivate(kn);
522 sysfs_unmap_bin_file(sd); 523 sysfs_unmap_bin_file(kn);
523 kernfs_put(sd); 524 kernfs_put(kn);
524 } 525 }
525} 526}
526 527
527/** 528/**
528 * kernfs_find_ns - find sysfs_dirent with the given name 529 * kernfs_find_ns - find kernfs_node with the given name
529 * @parent: sysfs_dirent to search under 530 * @parent: kernfs_node to search under
530 * @name: name to look for 531 * @name: name to look for
531 * @ns: the namespace tag to use 532 * @ns: the namespace tag to use
532 * 533 *
533 * Look for sysfs_dirent with name @name under @parent. Returns pointer to 534 * Look for kernfs_node with name @name under @parent. Returns pointer to
534 * the found sysfs_dirent on success, %NULL on failure. 535 * the found kernfs_node on success, %NULL on failure.
535 */ 536 */
536static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent, 537static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
537 const unsigned char *name, 538 const unsigned char *name,
538 const void *ns) 539 const void *ns)
539{ 540{
540 struct rb_node *node = parent->s_dir.children.rb_node; 541 struct rb_node *node = parent->s_dir.children.rb_node;
541 bool has_ns = kernfs_ns_enabled(parent); 542 bool has_ns = kernfs_ns_enabled(parent);
@@ -552,42 +553,42 @@ static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent,
552 553
553 hash = sysfs_name_hash(name, ns); 554 hash = sysfs_name_hash(name, ns);
554 while (node) { 555 while (node) {
555 struct sysfs_dirent *sd; 556 struct kernfs_node *kn;
556 int result; 557 int result;
557 558
558 sd = to_sysfs_dirent(node); 559 kn = rb_to_kn(node);
559 result = sysfs_name_compare(hash, name, ns, sd); 560 result = sysfs_name_compare(hash, name, ns, kn);
560 if (result < 0) 561 if (result < 0)
561 node = node->rb_left; 562 node = node->rb_left;
562 else if (result > 0) 563 else if (result > 0)
563 node = node->rb_right; 564 node = node->rb_right;
564 else 565 else
565 return sd; 566 return kn;
566 } 567 }
567 return NULL; 568 return NULL;
568} 569}
569 570
570/** 571/**
571 * kernfs_find_and_get_ns - find and get sysfs_dirent with the given name 572 * kernfs_find_and_get_ns - find and get kernfs_node with the given name
572 * @parent: sysfs_dirent to search under 573 * @parent: kernfs_node to search under
573 * @name: name to look for 574 * @name: name to look for
574 * @ns: the namespace tag to use 575 * @ns: the namespace tag to use
575 * 576 *
576 * Look for sysfs_dirent with name @name under @parent and get a reference 577 * Look for kernfs_node with name @name under @parent and get a reference
577 * if found. This function may sleep and returns pointer to the found 578 * if found. This function may sleep and returns pointer to the found
578 * sysfs_dirent on success, %NULL on failure. 579 * kernfs_node on success, %NULL on failure.
579 */ 580 */
580struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, 581struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
581 const char *name, const void *ns) 582 const char *name, const void *ns)
582{ 583{
583 struct sysfs_dirent *sd; 584 struct kernfs_node *kn;
584 585
585 mutex_lock(&sysfs_mutex); 586 mutex_lock(&sysfs_mutex);
586 sd = kernfs_find_ns(parent, name, ns); 587 kn = kernfs_find_ns(parent, name, ns);
587 kernfs_get(sd); 588 kernfs_get(kn);
588 mutex_unlock(&sysfs_mutex); 589 mutex_unlock(&sysfs_mutex);
589 590
590 return sd; 591 return kn;
591} 592}
592EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns); 593EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
593 594
@@ -601,7 +602,7 @@ EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
601struct kernfs_root *kernfs_create_root(void *priv) 602struct kernfs_root *kernfs_create_root(void *priv)
602{ 603{
603 struct kernfs_root *root; 604 struct kernfs_root *root;
604 struct sysfs_dirent *sd; 605 struct kernfs_node *kn;
605 606
606 root = kzalloc(sizeof(*root), GFP_KERNEL); 607 root = kzalloc(sizeof(*root), GFP_KERNEL);
607 if (!root) 608 if (!root)
@@ -609,18 +610,18 @@ struct kernfs_root *kernfs_create_root(void *priv)
609 610
610 ida_init(&root->ino_ida); 611 ida_init(&root->ino_ida);
611 612
612 sd = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR); 613 kn = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR);
613 if (!sd) { 614 if (!kn) {
614 ida_destroy(&root->ino_ida); 615 ida_destroy(&root->ino_ida);
615 kfree(root); 616 kfree(root);
616 return ERR_PTR(-ENOMEM); 617 return ERR_PTR(-ENOMEM);
617 } 618 }
618 619
619 sd->s_flags &= ~SYSFS_FLAG_REMOVED; 620 kn->s_flags &= ~SYSFS_FLAG_REMOVED;
620 sd->priv = priv; 621 kn->priv = priv;
621 sd->s_dir.root = root; 622 kn->s_dir.root = root;
622 623
623 root->sd = sd; 624 root->kn = kn;
624 625
625 return root; 626 return root;
626} 627}
@@ -634,7 +635,7 @@ struct kernfs_root *kernfs_create_root(void *priv)
634 */ 635 */
635void kernfs_destroy_root(struct kernfs_root *root) 636void kernfs_destroy_root(struct kernfs_root *root)
636{ 637{
637 kernfs_remove(root->sd); /* will also free @root */ 638 kernfs_remove(root->kn); /* will also free @root */
638} 639}
639 640
640/** 641/**
@@ -646,33 +647,33 @@ void kernfs_destroy_root(struct kernfs_root *root)
646 * 647 *
647 * Returns the created node on success, ERR_PTR() value on failure. 648 * Returns the created node on success, ERR_PTR() value on failure.
648 */ 649 */
649struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, 650struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
650 const char *name, void *priv, 651 const char *name, void *priv,
651 const void *ns) 652 const void *ns)
652{ 653{
653 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; 654 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
654 struct sysfs_addrm_cxt acxt; 655 struct sysfs_addrm_cxt acxt;
655 struct sysfs_dirent *sd; 656 struct kernfs_node *kn;
656 int rc; 657 int rc;
657 658
658 /* allocate */ 659 /* allocate */
659 sd = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR); 660 kn = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR);
660 if (!sd) 661 if (!kn)
661 return ERR_PTR(-ENOMEM); 662 return ERR_PTR(-ENOMEM);
662 663
663 sd->s_dir.root = parent->s_dir.root; 664 kn->s_dir.root = parent->s_dir.root;
664 sd->s_ns = ns; 665 kn->s_ns = ns;
665 sd->priv = priv; 666 kn->priv = priv;
666 667
667 /* link in */ 668 /* link in */
668 sysfs_addrm_start(&acxt); 669 sysfs_addrm_start(&acxt);
669 rc = sysfs_add_one(&acxt, sd, parent); 670 rc = sysfs_add_one(&acxt, kn, parent);
670 sysfs_addrm_finish(&acxt); 671 sysfs_addrm_finish(&acxt);
671 672
672 if (!rc) 673 if (!rc)
673 return sd; 674 return kn;
674 675
675 kernfs_put(sd); 676 kernfs_put(kn);
676 return ERR_PTR(rc); 677 return ERR_PTR(rc);
677} 678}
678 679
@@ -680,29 +681,28 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
680 unsigned int flags) 681 unsigned int flags)
681{ 682{
682 struct dentry *ret = NULL; 683 struct dentry *ret = NULL;
683 struct dentry *parent = dentry->d_parent; 684 struct kernfs_node *parent = dentry->d_parent->d_fsdata;
684 struct sysfs_dirent *parent_sd = parent->d_fsdata; 685 struct kernfs_node *kn;
685 struct sysfs_dirent *sd;
686 struct inode *inode; 686 struct inode *inode;
687 const void *ns = NULL; 687 const void *ns = NULL;
688 688
689 mutex_lock(&sysfs_mutex); 689 mutex_lock(&sysfs_mutex);
690 690
691 if (kernfs_ns_enabled(parent_sd)) 691 if (kernfs_ns_enabled(parent))
692 ns = sysfs_info(dir->i_sb)->ns; 692 ns = sysfs_info(dir->i_sb)->ns;
693 693
694 sd = kernfs_find_ns(parent_sd, dentry->d_name.name, ns); 694 kn = kernfs_find_ns(parent, dentry->d_name.name, ns);
695 695
696 /* no such entry */ 696 /* no such entry */
697 if (!sd) { 697 if (!kn) {
698 ret = ERR_PTR(-ENOENT); 698 ret = ERR_PTR(-ENOENT);
699 goto out_unlock; 699 goto out_unlock;
700 } 700 }
701 kernfs_get(sd); 701 kernfs_get(kn);
702 dentry->d_fsdata = sd; 702 dentry->d_fsdata = kn;
703 703
704 /* attach dentry and inode */ 704 /* attach dentry and inode */
705 inode = sysfs_get_inode(dir->i_sb, sd); 705 inode = sysfs_get_inode(dir->i_sb, kn);
706 if (!inode) { 706 if (!inode) {
707 ret = ERR_PTR(-ENOMEM); 707 ret = ERR_PTR(-ENOMEM);
708 goto out_unlock; 708 goto out_unlock;
@@ -726,9 +726,9 @@ const struct inode_operations sysfs_dir_inode_operations = {
726 .listxattr = sysfs_listxattr, 726 .listxattr = sysfs_listxattr,
727}; 727};
728 728
729static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) 729static struct kernfs_node *sysfs_leftmost_descendant(struct kernfs_node *pos)
730{ 730{
731 struct sysfs_dirent *last; 731 struct kernfs_node *last;
732 732
733 while (true) { 733 while (true) {
734 struct rb_node *rbn; 734 struct rb_node *rbn;
@@ -742,7 +742,7 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
742 if (!rbn) 742 if (!rbn)
743 break; 743 break;
744 744
745 pos = to_sysfs_dirent(rbn); 745 pos = rb_to_kn(rbn);
746 } 746 }
747 747
748 return last; 748 return last;
@@ -751,14 +751,14 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
751/** 751/**
752 * sysfs_next_descendant_post - find the next descendant for post-order walk 752 * sysfs_next_descendant_post - find the next descendant for post-order walk
753 * @pos: the current position (%NULL to initiate traversal) 753 * @pos: the current position (%NULL to initiate traversal)
754 * @root: sysfs_dirent whose descendants to walk 754 * @root: kernfs_node whose descendants to walk
755 * 755 *
756 * Find the next descendant to visit for post-order traversal of @root's 756 * Find the next descendant to visit for post-order traversal of @root's
757 * descendants. @root is included in the iteration and the last node to be 757 * descendants. @root is included in the iteration and the last node to be
758 * visited. 758 * visited.
759 */ 759 */
760static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos, 760static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos,
761 struct sysfs_dirent *root) 761 struct kernfs_node *root)
762{ 762{
763 struct rb_node *rbn; 763 struct rb_node *rbn;
764 764
@@ -775,62 +775,62 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos,
775 /* if there's an unvisited sibling, visit its leftmost descendant */ 775 /* if there's an unvisited sibling, visit its leftmost descendant */
776 rbn = rb_next(&pos->s_rb); 776 rbn = rb_next(&pos->s_rb);
777 if (rbn) 777 if (rbn)
778 return sysfs_leftmost_descendant(to_sysfs_dirent(rbn)); 778 return sysfs_leftmost_descendant(rb_to_kn(rbn));
779 779
780 /* no sibling left, visit parent */ 780 /* no sibling left, visit parent */
781 return pos->s_parent; 781 return pos->s_parent;
782} 782}
783 783
784static void __kernfs_remove(struct sysfs_addrm_cxt *acxt, 784static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
785 struct sysfs_dirent *sd) 785 struct kernfs_node *kn)
786{ 786{
787 struct sysfs_dirent *pos, *next; 787 struct kernfs_node *pos, *next;
788 788
789 if (!sd) 789 if (!kn)
790 return; 790 return;
791 791
792 pr_debug("sysfs %s: removing\n", sd->s_name); 792 pr_debug("sysfs %s: removing\n", kn->s_name);
793 793
794 next = NULL; 794 next = NULL;
795 do { 795 do {
796 pos = next; 796 pos = next;
797 next = sysfs_next_descendant_post(pos, sd); 797 next = sysfs_next_descendant_post(pos, kn);
798 if (pos) 798 if (pos)
799 sysfs_remove_one(acxt, pos); 799 sysfs_remove_one(acxt, pos);
800 } while (next); 800 } while (next);
801} 801}
802 802
803/** 803/**
804 * kernfs_remove - remove a sysfs_dirent recursively 804 * kernfs_remove - remove a kernfs_node recursively
805 * @sd: the sysfs_dirent to remove 805 * @kn: the kernfs_node to remove
806 * 806 *
807 * Remove @sd along with all its subdirectories and files. 807 * Remove @kn along with all its subdirectories and files.
808 */ 808 */
809void kernfs_remove(struct sysfs_dirent *sd) 809void kernfs_remove(struct kernfs_node *kn)
810{ 810{
811 struct sysfs_addrm_cxt acxt; 811 struct sysfs_addrm_cxt acxt;
812 812
813 sysfs_addrm_start(&acxt); 813 sysfs_addrm_start(&acxt);
814 __kernfs_remove(&acxt, sd); 814 __kernfs_remove(&acxt, kn);
815 sysfs_addrm_finish(&acxt); 815 sysfs_addrm_finish(&acxt);
816} 816}
817 817
818/** 818/**
819 * kernfs_remove_by_name_ns - find a sysfs_dirent by name and remove it 819 * kernfs_remove_by_name_ns - find a kernfs_node by name and remove it
820 * @dir_sd: parent of the target 820 * @parent: parent of the target
821 * @name: name of the sysfs_dirent to remove 821 * @name: name of the kernfs_node to remove
822 * @ns: namespace tag of the sysfs_dirent to remove 822 * @ns: namespace tag of the kernfs_node to remove
823 * 823 *
824 * Look for the sysfs_dirent with @name and @ns under @dir_sd and remove 824 * Look for the kernfs_node with @name and @ns under @parent and remove it.
825 * it. Returns 0 on success, -ENOENT if such entry doesn't exist. 825 * Returns 0 on success, -ENOENT if such entry doesn't exist.
826 */ 826 */
827int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name, 827int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
828 const void *ns) 828 const void *ns)
829{ 829{
830 struct sysfs_addrm_cxt acxt; 830 struct sysfs_addrm_cxt acxt;
831 struct sysfs_dirent *sd; 831 struct kernfs_node *kn;
832 832
833 if (!dir_sd) { 833 if (!parent) {
834 WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n", 834 WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n",
835 name); 835 name);
836 return -ENOENT; 836 return -ENOENT;
@@ -838,13 +838,13 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
838 838
839 sysfs_addrm_start(&acxt); 839 sysfs_addrm_start(&acxt);
840 840
841 sd = kernfs_find_ns(dir_sd, name, ns); 841 kn = kernfs_find_ns(parent, name, ns);
842 if (sd) 842 if (kn)
843 __kernfs_remove(&acxt, sd); 843 __kernfs_remove(&acxt, kn);
844 844
845 sysfs_addrm_finish(&acxt); 845 sysfs_addrm_finish(&acxt);
846 846
847 if (sd) 847 if (kn)
848 return 0; 848 return 0;
849 else 849 else
850 return -ENOENT; 850 return -ENOENT;
@@ -852,12 +852,12 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
852 852
853/** 853/**
854 * kernfs_rename_ns - move and rename a kernfs_node 854 * kernfs_rename_ns - move and rename a kernfs_node
855 * @sd: target node 855 * @kn: target node
856 * @new_parent: new parent to put @sd under 856 * @new_parent: new parent to put @sd under
857 * @new_name: new name 857 * @new_name: new name
858 * @new_ns: new namespace tag 858 * @new_ns: new namespace tag
859 */ 859 */
860int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, 860int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
861 const char *new_name, const void *new_ns) 861 const char *new_name, const void *new_ns)
862{ 862{
863 int error; 863 int error;
@@ -865,35 +865,35 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
865 mutex_lock(&sysfs_mutex); 865 mutex_lock(&sysfs_mutex);
866 866
867 error = 0; 867 error = 0;
868 if ((sd->s_parent == new_parent) && (sd->s_ns == new_ns) && 868 if ((kn->s_parent == new_parent) && (kn->s_ns == new_ns) &&
869 (strcmp(sd->s_name, new_name) == 0)) 869 (strcmp(kn->s_name, new_name) == 0))
870 goto out; /* nothing to rename */ 870 goto out; /* nothing to rename */
871 871
872 error = -EEXIST; 872 error = -EEXIST;
873 if (kernfs_find_ns(new_parent, new_name, new_ns)) 873 if (kernfs_find_ns(new_parent, new_name, new_ns))
874 goto out; 874 goto out;
875 875
876 /* rename sysfs_dirent */ 876 /* rename kernfs_node */
877 if (strcmp(sd->s_name, new_name) != 0) { 877 if (strcmp(kn->s_name, new_name) != 0) {
878 error = -ENOMEM; 878 error = -ENOMEM;
879 new_name = kstrdup(new_name, GFP_KERNEL); 879 new_name = kstrdup(new_name, GFP_KERNEL);
880 if (!new_name) 880 if (!new_name)
881 goto out; 881 goto out;
882 882
883 kfree(sd->s_name); 883 kfree(kn->s_name);
884 sd->s_name = new_name; 884 kn->s_name = new_name;
885 } 885 }
886 886
887 /* 887 /*
888 * Move to the appropriate place in the appropriate directories rbtree. 888 * Move to the appropriate place in the appropriate directories rbtree.
889 */ 889 */
890 sysfs_unlink_sibling(sd); 890 sysfs_unlink_sibling(kn);
891 kernfs_get(new_parent); 891 kernfs_get(new_parent);
892 kernfs_put(sd->s_parent); 892 kernfs_put(kn->s_parent);
893 sd->s_ns = new_ns; 893 kn->s_ns = new_ns;
894 sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); 894 kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
895 sd->s_parent = new_parent; 895 kn->s_parent = new_parent;
896 sysfs_link_sibling(sd); 896 sysfs_link_sibling(kn);
897 897
898 error = 0; 898 error = 0;
899 out: 899 out:
@@ -902,9 +902,9 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
902} 902}
903 903
904/* Relationship between s_mode and the DT_xxx types */ 904/* Relationship between s_mode and the DT_xxx types */
905static inline unsigned char dt_type(struct sysfs_dirent *sd) 905static inline unsigned char dt_type(struct kernfs_node *kn)
906{ 906{
907 return (sd->s_mode >> 12) & 15; 907 return (kn->s_mode >> 12) & 15;
908} 908}
909 909
910static int sysfs_dir_release(struct inode *inode, struct file *filp) 910static int sysfs_dir_release(struct inode *inode, struct file *filp)
@@ -913,21 +913,21 @@ static int sysfs_dir_release(struct inode *inode, struct file *filp)
913 return 0; 913 return 0;
914} 914}
915 915
916static struct sysfs_dirent *sysfs_dir_pos(const void *ns, 916static struct kernfs_node *sysfs_dir_pos(const void *ns,
917 struct sysfs_dirent *parent_sd, loff_t hash, struct sysfs_dirent *pos) 917 struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
918{ 918{
919 if (pos) { 919 if (pos) {
920 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) && 920 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
921 pos->s_parent == parent_sd && 921 pos->s_parent == parent &&
922 hash == pos->s_hash; 922 hash == pos->s_hash;
923 kernfs_put(pos); 923 kernfs_put(pos);
924 if (!valid) 924 if (!valid)
925 pos = NULL; 925 pos = NULL;
926 } 926 }
927 if (!pos && (hash > 1) && (hash < INT_MAX)) { 927 if (!pos && (hash > 1) && (hash < INT_MAX)) {
928 struct rb_node *node = parent_sd->s_dir.children.rb_node; 928 struct rb_node *node = parent->s_dir.children.rb_node;
929 while (node) { 929 while (node) {
930 pos = to_sysfs_dirent(node); 930 pos = rb_to_kn(node);
931 931
932 if (hash < pos->s_hash) 932 if (hash < pos->s_hash)
933 node = node->rb_left; 933 node = node->rb_left;
@@ -943,22 +943,22 @@ static struct sysfs_dirent *sysfs_dir_pos(const void *ns,
943 if (!node) 943 if (!node)
944 pos = NULL; 944 pos = NULL;
945 else 945 else
946 pos = to_sysfs_dirent(node); 946 pos = rb_to_kn(node);
947 } 947 }
948 return pos; 948 return pos;
949} 949}
950 950
951static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns, 951static struct kernfs_node *sysfs_dir_next_pos(const void *ns,
952 struct sysfs_dirent *parent_sd, ino_t ino, struct sysfs_dirent *pos) 952 struct kernfs_node *parent, ino_t ino, struct kernfs_node *pos)
953{ 953{
954 pos = sysfs_dir_pos(ns, parent_sd, ino, pos); 954 pos = sysfs_dir_pos(ns, parent, ino, pos);
955 if (pos) 955 if (pos)
956 do { 956 do {
957 struct rb_node *node = rb_next(&pos->s_rb); 957 struct rb_node *node = rb_next(&pos->s_rb);
958 if (!node) 958 if (!node)
959 pos = NULL; 959 pos = NULL;
960 else 960 else
961 pos = to_sysfs_dirent(node); 961 pos = rb_to_kn(node);
962 } while (pos && pos->s_ns != ns); 962 } while (pos && pos->s_ns != ns);
963 return pos; 963 return pos;
964} 964}
@@ -966,20 +966,20 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns,
966static int sysfs_readdir(struct file *file, struct dir_context *ctx) 966static int sysfs_readdir(struct file *file, struct dir_context *ctx)
967{ 967{
968 struct dentry *dentry = file->f_path.dentry; 968 struct dentry *dentry = file->f_path.dentry;
969 struct sysfs_dirent *parent_sd = dentry->d_fsdata; 969 struct kernfs_node *parent = dentry->d_fsdata;
970 struct sysfs_dirent *pos = file->private_data; 970 struct kernfs_node *pos = file->private_data;
971 const void *ns = NULL; 971 const void *ns = NULL;
972 972
973 if (!dir_emit_dots(file, ctx)) 973 if (!dir_emit_dots(file, ctx))
974 return 0; 974 return 0;
975 mutex_lock(&sysfs_mutex); 975 mutex_lock(&sysfs_mutex);
976 976
977 if (kernfs_ns_enabled(parent_sd)) 977 if (kernfs_ns_enabled(parent))
978 ns = sysfs_info(dentry->d_sb)->ns; 978 ns = sysfs_info(dentry->d_sb)->ns;
979 979
980 for (pos = sysfs_dir_pos(ns, parent_sd, ctx->pos, pos); 980 for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos);
981 pos; 981 pos;
982 pos = sysfs_dir_next_pos(ns, parent_sd, ctx->pos, pos)) { 982 pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
983 const char *name = pos->s_name; 983 const char *name = pos->s_name;
984 unsigned int type = dt_type(pos); 984 unsigned int type = dt_type(pos);
985 int len = strlen(name); 985 int len = strlen(name);
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index fa053151fa96..1bf07ded826a 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -19,9 +19,9 @@
19 19
20/* 20/*
21 * There's one sysfs_open_file for each open file and one sysfs_open_dirent 21 * There's one sysfs_open_file for each open file and one sysfs_open_dirent
22 * for each sysfs_dirent with one or more open files. 22 * for each kernfs_node with one or more open files.
23 * 23 *
24 * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open is 24 * kernfs_node->s_attr.open points to sysfs_open_dirent. s_attr.open is
25 * protected by sysfs_open_dirent_lock. 25 * protected by sysfs_open_dirent_lock.
26 * 26 *
27 * filp->private_data points to seq_file whose ->private points to 27 * filp->private_data points to seq_file whose ->private points to
@@ -44,14 +44,14 @@ static struct sysfs_open_file *sysfs_of(struct file *file)
44} 44}
45 45
46/* 46/*
47 * Determine the kernfs_ops for the given sysfs_dirent. This function must 47 * Determine the kernfs_ops for the given kernfs_node. This function must
48 * be called while holding an active reference. 48 * be called while holding an active reference.
49 */ 49 */
50static const struct kernfs_ops *kernfs_ops(struct sysfs_dirent *sd) 50static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn)
51{ 51{
52 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 52 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
53 lockdep_assert_held(sd); 53 lockdep_assert_held(kn);
54 return sd->s_attr.ops; 54 return kn->s_attr.ops;
55} 55}
56 56
57static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos) 57static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
@@ -64,10 +64,10 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
64 * the ops aren't called concurrently for the same open file. 64 * the ops aren't called concurrently for the same open file.
65 */ 65 */
66 mutex_lock(&of->mutex); 66 mutex_lock(&of->mutex);
67 if (!sysfs_get_active(of->sd)) 67 if (!sysfs_get_active(of->kn))
68 return ERR_PTR(-ENODEV); 68 return ERR_PTR(-ENODEV);
69 69
70 ops = kernfs_ops(of->sd); 70 ops = kernfs_ops(of->kn);
71 if (ops->seq_start) { 71 if (ops->seq_start) {
72 return ops->seq_start(sf, ppos); 72 return ops->seq_start(sf, ppos);
73 } else { 73 } else {
@@ -82,7 +82,7 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
82static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos) 82static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
83{ 83{
84 struct sysfs_open_file *of = sf->private; 84 struct sysfs_open_file *of = sf->private;
85 const struct kernfs_ops *ops = kernfs_ops(of->sd); 85 const struct kernfs_ops *ops = kernfs_ops(of->kn);
86 86
87 if (ops->seq_next) { 87 if (ops->seq_next) {
88 return ops->seq_next(sf, v, ppos); 88 return ops->seq_next(sf, v, ppos);
@@ -99,12 +99,12 @@ static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
99static void kernfs_seq_stop(struct seq_file *sf, void *v) 99static void kernfs_seq_stop(struct seq_file *sf, void *v)
100{ 100{
101 struct sysfs_open_file *of = sf->private; 101 struct sysfs_open_file *of = sf->private;
102 const struct kernfs_ops *ops = kernfs_ops(of->sd); 102 const struct kernfs_ops *ops = kernfs_ops(of->kn);
103 103
104 if (ops->seq_stop) 104 if (ops->seq_stop)
105 ops->seq_stop(sf, v); 105 ops->seq_stop(sf, v);
106 106
107 sysfs_put_active(of->sd); 107 sysfs_put_active(of->kn);
108 mutex_unlock(&of->mutex); 108 mutex_unlock(&of->mutex);
109} 109}
110 110
@@ -112,9 +112,9 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
112{ 112{
113 struct sysfs_open_file *of = sf->private; 113 struct sysfs_open_file *of = sf->private;
114 114
115 of->event = atomic_read(&of->sd->s_attr.open->event); 115 of->event = atomic_read(&of->kn->s_attr.open->event);
116 116
117 return of->sd->s_attr.ops->seq_show(sf, v); 117 return of->kn->s_attr.ops->seq_show(sf, v);
118} 118}
119 119
120static const struct seq_operations kernfs_seq_ops = { 120static const struct seq_operations kernfs_seq_ops = {
@@ -147,19 +147,19 @@ static ssize_t kernfs_file_direct_read(struct sysfs_open_file *of,
147 * the ops aren't called concurrently for the same open file. 147 * the ops aren't called concurrently for the same open file.
148 */ 148 */
149 mutex_lock(&of->mutex); 149 mutex_lock(&of->mutex);
150 if (!sysfs_get_active(of->sd)) { 150 if (!sysfs_get_active(of->kn)) {
151 len = -ENODEV; 151 len = -ENODEV;
152 mutex_unlock(&of->mutex); 152 mutex_unlock(&of->mutex);
153 goto out_free; 153 goto out_free;
154 } 154 }
155 155
156 ops = kernfs_ops(of->sd); 156 ops = kernfs_ops(of->kn);
157 if (ops->read) 157 if (ops->read)
158 len = ops->read(of, buf, len, *ppos); 158 len = ops->read(of, buf, len, *ppos);
159 else 159 else
160 len = -EINVAL; 160 len = -EINVAL;
161 161
162 sysfs_put_active(of->sd); 162 sysfs_put_active(of->kn);
163 mutex_unlock(&of->mutex); 163 mutex_unlock(&of->mutex);
164 164
165 if (len < 0) 165 if (len < 0)
@@ -189,7 +189,7 @@ static ssize_t kernfs_file_read(struct file *file, char __user *user_buf,
189{ 189{
190 struct sysfs_open_file *of = sysfs_of(file); 190 struct sysfs_open_file *of = sysfs_of(file);
191 191
192 if (of->sd->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW) 192 if (of->kn->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW)
193 return seq_read(file, user_buf, count, ppos); 193 return seq_read(file, user_buf, count, ppos);
194 else 194 else
195 return kernfs_file_direct_read(of, user_buf, count, ppos); 195 return kernfs_file_direct_read(of, user_buf, count, ppos);
@@ -234,19 +234,19 @@ static ssize_t kernfs_file_write(struct file *file, const char __user *user_buf,
234 * the ops aren't called concurrently for the same open file. 234 * the ops aren't called concurrently for the same open file.
235 */ 235 */
236 mutex_lock(&of->mutex); 236 mutex_lock(&of->mutex);
237 if (!sysfs_get_active(of->sd)) { 237 if (!sysfs_get_active(of->kn)) {
238 mutex_unlock(&of->mutex); 238 mutex_unlock(&of->mutex);
239 len = -ENODEV; 239 len = -ENODEV;
240 goto out_free; 240 goto out_free;
241 } 241 }
242 242
243 ops = kernfs_ops(of->sd); 243 ops = kernfs_ops(of->kn);
244 if (ops->write) 244 if (ops->write)
245 len = ops->write(of, buf, len, *ppos); 245 len = ops->write(of, buf, len, *ppos);
246 else 246 else
247 len = -EINVAL; 247 len = -EINVAL;
248 248
249 sysfs_put_active(of->sd); 249 sysfs_put_active(of->kn);
250 mutex_unlock(&of->mutex); 250 mutex_unlock(&of->mutex);
251 251
252 if (len > 0) 252 if (len > 0)
@@ -264,13 +264,13 @@ static void kernfs_vma_open(struct vm_area_struct *vma)
264 if (!of->vm_ops) 264 if (!of->vm_ops)
265 return; 265 return;
266 266
267 if (!sysfs_get_active(of->sd)) 267 if (!sysfs_get_active(of->kn))
268 return; 268 return;
269 269
270 if (of->vm_ops->open) 270 if (of->vm_ops->open)
271 of->vm_ops->open(vma); 271 of->vm_ops->open(vma);
272 272
273 sysfs_put_active(of->sd); 273 sysfs_put_active(of->kn);
274} 274}
275 275
276static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) 276static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
@@ -282,14 +282,14 @@ static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
282 if (!of->vm_ops) 282 if (!of->vm_ops)
283 return VM_FAULT_SIGBUS; 283 return VM_FAULT_SIGBUS;
284 284
285 if (!sysfs_get_active(of->sd)) 285 if (!sysfs_get_active(of->kn))
286 return VM_FAULT_SIGBUS; 286 return VM_FAULT_SIGBUS;
287 287
288 ret = VM_FAULT_SIGBUS; 288 ret = VM_FAULT_SIGBUS;
289 if (of->vm_ops->fault) 289 if (of->vm_ops->fault)
290 ret = of->vm_ops->fault(vma, vmf); 290 ret = of->vm_ops->fault(vma, vmf);
291 291
292 sysfs_put_active(of->sd); 292 sysfs_put_active(of->kn);
293 return ret; 293 return ret;
294} 294}
295 295
@@ -303,7 +303,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
303 if (!of->vm_ops) 303 if (!of->vm_ops)
304 return VM_FAULT_SIGBUS; 304 return VM_FAULT_SIGBUS;
305 305
306 if (!sysfs_get_active(of->sd)) 306 if (!sysfs_get_active(of->kn))
307 return VM_FAULT_SIGBUS; 307 return VM_FAULT_SIGBUS;
308 308
309 ret = 0; 309 ret = 0;
@@ -312,7 +312,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
312 else 312 else
313 file_update_time(file); 313 file_update_time(file);
314 314
315 sysfs_put_active(of->sd); 315 sysfs_put_active(of->kn);
316 return ret; 316 return ret;
317} 317}
318 318
@@ -326,14 +326,14 @@ static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
326 if (!of->vm_ops) 326 if (!of->vm_ops)
327 return -EINVAL; 327 return -EINVAL;
328 328
329 if (!sysfs_get_active(of->sd)) 329 if (!sysfs_get_active(of->kn))
330 return -EINVAL; 330 return -EINVAL;
331 331
332 ret = -EINVAL; 332 ret = -EINVAL;
333 if (of->vm_ops->access) 333 if (of->vm_ops->access)
334 ret = of->vm_ops->access(vma, addr, buf, len, write); 334 ret = of->vm_ops->access(vma, addr, buf, len, write);
335 335
336 sysfs_put_active(of->sd); 336 sysfs_put_active(of->kn);
337 return ret; 337 return ret;
338} 338}
339 339
@@ -348,14 +348,14 @@ static int kernfs_vma_set_policy(struct vm_area_struct *vma,
348 if (!of->vm_ops) 348 if (!of->vm_ops)
349 return 0; 349 return 0;
350 350
351 if (!sysfs_get_active(of->sd)) 351 if (!sysfs_get_active(of->kn))
352 return -EINVAL; 352 return -EINVAL;
353 353
354 ret = 0; 354 ret = 0;
355 if (of->vm_ops->set_policy) 355 if (of->vm_ops->set_policy)
356 ret = of->vm_ops->set_policy(vma, new); 356 ret = of->vm_ops->set_policy(vma, new);
357 357
358 sysfs_put_active(of->sd); 358 sysfs_put_active(of->kn);
359 return ret; 359 return ret;
360} 360}
361 361
@@ -369,14 +369,14 @@ static struct mempolicy *kernfs_vma_get_policy(struct vm_area_struct *vma,
369 if (!of->vm_ops) 369 if (!of->vm_ops)
370 return vma->vm_policy; 370 return vma->vm_policy;
371 371
372 if (!sysfs_get_active(of->sd)) 372 if (!sysfs_get_active(of->kn))
373 return vma->vm_policy; 373 return vma->vm_policy;
374 374
375 pol = vma->vm_policy; 375 pol = vma->vm_policy;
376 if (of->vm_ops->get_policy) 376 if (of->vm_ops->get_policy)
377 pol = of->vm_ops->get_policy(vma, addr); 377 pol = of->vm_ops->get_policy(vma, addr);
378 378
379 sysfs_put_active(of->sd); 379 sysfs_put_active(of->kn);
380 return pol; 380 return pol;
381} 381}
382 382
@@ -391,14 +391,14 @@ static int kernfs_vma_migrate(struct vm_area_struct *vma,
391 if (!of->vm_ops) 391 if (!of->vm_ops)
392 return 0; 392 return 0;
393 393
394 if (!sysfs_get_active(of->sd)) 394 if (!sysfs_get_active(of->kn))
395 return 0; 395 return 0;
396 396
397 ret = 0; 397 ret = 0;
398 if (of->vm_ops->migrate) 398 if (of->vm_ops->migrate)
399 ret = of->vm_ops->migrate(vma, from, to, flags); 399 ret = of->vm_ops->migrate(vma, from, to, flags);
400 400
401 sysfs_put_active(of->sd); 401 sysfs_put_active(of->kn);
402 return ret; 402 return ret;
403} 403}
404#endif 404#endif
@@ -428,16 +428,16 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
428 * without grabbing @of->mutex by testing HAS_MMAP flag. See the 428 * without grabbing @of->mutex by testing HAS_MMAP flag. See the
429 * comment in kernfs_file_open() for more details. 429 * comment in kernfs_file_open() for more details.
430 */ 430 */
431 if (!(of->sd->s_flags & SYSFS_FLAG_HAS_MMAP)) 431 if (!(of->kn->s_flags & SYSFS_FLAG_HAS_MMAP))
432 return -ENODEV; 432 return -ENODEV;
433 433
434 mutex_lock(&of->mutex); 434 mutex_lock(&of->mutex);
435 435
436 rc = -ENODEV; 436 rc = -ENODEV;
437 if (!sysfs_get_active(of->sd)) 437 if (!sysfs_get_active(of->kn))
438 goto out_unlock; 438 goto out_unlock;
439 439
440 ops = kernfs_ops(of->sd); 440 ops = kernfs_ops(of->kn);
441 rc = ops->mmap(of, vma); 441 rc = ops->mmap(of, vma);
442 442
443 /* 443 /*
@@ -465,7 +465,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
465 of->vm_ops = vma->vm_ops; 465 of->vm_ops = vma->vm_ops;
466 vma->vm_ops = &kernfs_vm_ops; 466 vma->vm_ops = &kernfs_vm_ops;
467out_put: 467out_put:
468 sysfs_put_active(of->sd); 468 sysfs_put_active(of->kn);
469out_unlock: 469out_unlock:
470 mutex_unlock(&of->mutex); 470 mutex_unlock(&of->mutex);
471 471
@@ -474,10 +474,10 @@ out_unlock:
474 474
475/** 475/**
476 * sysfs_get_open_dirent - get or create sysfs_open_dirent 476 * sysfs_get_open_dirent - get or create sysfs_open_dirent
477 * @sd: target sysfs_dirent 477 * @kn: target kernfs_node
478 * @of: sysfs_open_file for this instance of open 478 * @of: sysfs_open_file for this instance of open
479 * 479 *
480 * If @sd->s_attr.open exists, increment its reference count; 480 * If @kn->s_attr.open exists, increment its reference count;
481 * otherwise, create one. @of is chained to the files list. 481 * otherwise, create one. @of is chained to the files list.
482 * 482 *
483 * LOCKING: 483 * LOCKING:
@@ -486,7 +486,7 @@ out_unlock:
486 * RETURNS: 486 * RETURNS:
487 * 0 on success, -errno on failure. 487 * 0 on success, -errno on failure.
488 */ 488 */
489static int sysfs_get_open_dirent(struct sysfs_dirent *sd, 489static int sysfs_get_open_dirent(struct kernfs_node *kn,
490 struct sysfs_open_file *of) 490 struct sysfs_open_file *of)
491{ 491{
492 struct sysfs_open_dirent *od, *new_od = NULL; 492 struct sysfs_open_dirent *od, *new_od = NULL;
@@ -495,12 +495,12 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
495 mutex_lock(&sysfs_open_file_mutex); 495 mutex_lock(&sysfs_open_file_mutex);
496 spin_lock_irq(&sysfs_open_dirent_lock); 496 spin_lock_irq(&sysfs_open_dirent_lock);
497 497
498 if (!sd->s_attr.open && new_od) { 498 if (!kn->s_attr.open && new_od) {
499 sd->s_attr.open = new_od; 499 kn->s_attr.open = new_od;
500 new_od = NULL; 500 new_od = NULL;
501 } 501 }
502 502
503 od = sd->s_attr.open; 503 od = kn->s_attr.open;
504 if (od) { 504 if (od) {
505 atomic_inc(&od->refcnt); 505 atomic_inc(&od->refcnt);
506 list_add_tail(&of->list, &od->files); 506 list_add_tail(&of->list, &od->files);
@@ -528,19 +528,19 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
528 528
529/** 529/**
530 * sysfs_put_open_dirent - put sysfs_open_dirent 530 * sysfs_put_open_dirent - put sysfs_open_dirent
531 * @sd: target sysfs_dirent 531 * @kn: target kernfs_nodet
532 * @of: associated sysfs_open_file 532 * @of: associated sysfs_open_file
533 * 533 *
534 * Put @sd->s_attr.open and unlink @of from the files list. If 534 * Put @kn->s_attr.open and unlink @of from the files list. If
535 * reference count reaches zero, disassociate and free it. 535 * reference count reaches zero, disassociate and free it.
536 * 536 *
537 * LOCKING: 537 * LOCKING:
538 * None. 538 * None.
539 */ 539 */
540static void sysfs_put_open_dirent(struct sysfs_dirent *sd, 540static void sysfs_put_open_dirent(struct kernfs_node *kn,
541 struct sysfs_open_file *of) 541 struct sysfs_open_file *of)
542{ 542{
543 struct sysfs_open_dirent *od = sd->s_attr.open; 543 struct sysfs_open_dirent *od = kn->s_attr.open;
544 unsigned long flags; 544 unsigned long flags;
545 545
546 mutex_lock(&sysfs_open_file_mutex); 546 mutex_lock(&sysfs_open_file_mutex);
@@ -550,7 +550,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
550 list_del(&of->list); 550 list_del(&of->list);
551 551
552 if (atomic_dec_and_test(&od->refcnt)) 552 if (atomic_dec_and_test(&od->refcnt))
553 sd->s_attr.open = NULL; 553 kn->s_attr.open = NULL;
554 else 554 else
555 od = NULL; 555 od = NULL;
556 556
@@ -562,16 +562,16 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
562 562
563static int kernfs_file_open(struct inode *inode, struct file *file) 563static int kernfs_file_open(struct inode *inode, struct file *file)
564{ 564{
565 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; 565 struct kernfs_node *kn = file->f_path.dentry->d_fsdata;
566 const struct kernfs_ops *ops; 566 const struct kernfs_ops *ops;
567 struct sysfs_open_file *of; 567 struct sysfs_open_file *of;
568 bool has_read, has_write, has_mmap; 568 bool has_read, has_write, has_mmap;
569 int error = -EACCES; 569 int error = -EACCES;
570 570
571 if (!sysfs_get_active(attr_sd)) 571 if (!sysfs_get_active(kn))
572 return -ENODEV; 572 return -ENODEV;
573 573
574 ops = kernfs_ops(attr_sd); 574 ops = kernfs_ops(kn);
575 575
576 has_read = ops->seq_show || ops->read || ops->mmap; 576 has_read = ops->seq_show || ops->read || ops->mmap;
577 has_write = ops->write || ops->mmap; 577 has_write = ops->write || ops->mmap;
@@ -612,7 +612,7 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
612 else 612 else
613 mutex_init(&of->mutex); 613 mutex_init(&of->mutex);
614 614
615 of->sd = attr_sd; 615 of->kn = kn;
616 of->file = file; 616 of->file = file;
617 617
618 /* 618 /*
@@ -634,12 +634,12 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
634 file->f_mode |= FMODE_PWRITE; 634 file->f_mode |= FMODE_PWRITE;
635 635
636 /* make sure we have open dirent struct */ 636 /* make sure we have open dirent struct */
637 error = sysfs_get_open_dirent(attr_sd, of); 637 error = sysfs_get_open_dirent(kn, of);
638 if (error) 638 if (error)
639 goto err_close; 639 goto err_close;
640 640
641 /* open succeeded, put active references */ 641 /* open succeeded, put active references */
642 sysfs_put_active(attr_sd); 642 sysfs_put_active(kn);
643 return 0; 643 return 0;
644 644
645err_close: 645err_close:
@@ -647,32 +647,32 @@ err_close:
647err_free: 647err_free:
648 kfree(of); 648 kfree(of);
649err_out: 649err_out:
650 sysfs_put_active(attr_sd); 650 sysfs_put_active(kn);
651 return error; 651 return error;
652} 652}
653 653
654static int kernfs_file_release(struct inode *inode, struct file *filp) 654static int kernfs_file_release(struct inode *inode, struct file *filp)
655{ 655{
656 struct sysfs_dirent *sd = filp->f_path.dentry->d_fsdata; 656 struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
657 struct sysfs_open_file *of = sysfs_of(filp); 657 struct sysfs_open_file *of = sysfs_of(filp);
658 658
659 sysfs_put_open_dirent(sd, of); 659 sysfs_put_open_dirent(kn, of);
660 seq_release(inode, filp); 660 seq_release(inode, filp);
661 kfree(of); 661 kfree(of);
662 662
663 return 0; 663 return 0;
664} 664}
665 665
666void sysfs_unmap_bin_file(struct sysfs_dirent *sd) 666void sysfs_unmap_bin_file(struct kernfs_node *kn)
667{ 667{
668 struct sysfs_open_dirent *od; 668 struct sysfs_open_dirent *od;
669 struct sysfs_open_file *of; 669 struct sysfs_open_file *of;
670 670
671 if (!(sd->s_flags & SYSFS_FLAG_HAS_MMAP)) 671 if (!(kn->s_flags & SYSFS_FLAG_HAS_MMAP))
672 return; 672 return;
673 673
674 spin_lock_irq(&sysfs_open_dirent_lock); 674 spin_lock_irq(&sysfs_open_dirent_lock);
675 od = sd->s_attr.open; 675 od = kn->s_attr.open;
676 if (od) 676 if (od)
677 atomic_inc(&od->refcnt); 677 atomic_inc(&od->refcnt);
678 spin_unlock_irq(&sysfs_open_dirent_lock); 678 spin_unlock_irq(&sysfs_open_dirent_lock);
@@ -686,7 +686,7 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd)
686 } 686 }
687 mutex_unlock(&sysfs_open_file_mutex); 687 mutex_unlock(&sysfs_open_file_mutex);
688 688
689 sysfs_put_open_dirent(sd, NULL); 689 sysfs_put_open_dirent(kn, NULL);
690} 690}
691 691
692/* Sysfs attribute files are pollable. The idea is that you read 692/* Sysfs attribute files are pollable. The idea is that you read
@@ -705,16 +705,16 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd)
705static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait) 705static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
706{ 706{
707 struct sysfs_open_file *of = sysfs_of(filp); 707 struct sysfs_open_file *of = sysfs_of(filp);
708 struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; 708 struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
709 struct sysfs_open_dirent *od = attr_sd->s_attr.open; 709 struct sysfs_open_dirent *od = kn->s_attr.open;
710 710
711 /* need parent for the kobj, grab both */ 711 /* need parent for the kobj, grab both */
712 if (!sysfs_get_active(attr_sd)) 712 if (!sysfs_get_active(kn))
713 goto trigger; 713 goto trigger;
714 714
715 poll_wait(filp, &od->poll, wait); 715 poll_wait(filp, &od->poll, wait);
716 716
717 sysfs_put_active(attr_sd); 717 sysfs_put_active(kn);
718 718
719 if (of->event != atomic_read(&od->event)) 719 if (of->event != atomic_read(&od->event))
720 goto trigger; 720 goto trigger;
@@ -727,19 +727,19 @@ static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
727 727
728/** 728/**
729 * kernfs_notify - notify a kernfs file 729 * kernfs_notify - notify a kernfs file
730 * @sd: file to notify 730 * @kn: file to notify
731 * 731 *
732 * Notify @sd such that poll(2) on @sd wakes up. 732 * Notify @kn such that poll(2) on @kn wakes up.
733 */ 733 */
734void kernfs_notify(struct sysfs_dirent *sd) 734void kernfs_notify(struct kernfs_node *kn)
735{ 735{
736 struct sysfs_open_dirent *od; 736 struct sysfs_open_dirent *od;
737 unsigned long flags; 737 unsigned long flags;
738 738
739 spin_lock_irqsave(&sysfs_open_dirent_lock, flags); 739 spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
740 740
741 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) { 741 if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) {
742 od = sd->s_attr.open; 742 od = kn->s_attr.open;
743 if (od) { 743 if (od) {
744 atomic_inc(&od->event); 744 atomic_inc(&od->event);
745 wake_up_interruptible(&od->poll); 745 wake_up_interruptible(&od->poll);
@@ -773,51 +773,51 @@ const struct file_operations kernfs_file_operations = {
773 * 773 *
774 * Returns the created node on success, ERR_PTR() value on error. 774 * Returns the created node on success, ERR_PTR() value on error.
775 */ 775 */
776struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, 776struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
777 const char *name, 777 const char *name,
778 umode_t mode, loff_t size, 778 umode_t mode, loff_t size,
779 const struct kernfs_ops *ops, 779 const struct kernfs_ops *ops,
780 void *priv, const void *ns, 780 void *priv, const void *ns,
781 struct lock_class_key *key) 781 struct lock_class_key *key)
782{ 782{
783 struct sysfs_addrm_cxt acxt; 783 struct sysfs_addrm_cxt acxt;
784 struct sysfs_dirent *sd; 784 struct kernfs_node *kn;
785 int rc; 785 int rc;
786 786
787 sd = sysfs_new_dirent(kernfs_root(parent), name, 787 kn = sysfs_new_dirent(kernfs_root(parent), name,
788 (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR); 788 (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR);
789 if (!sd) 789 if (!kn)
790 return ERR_PTR(-ENOMEM); 790 return ERR_PTR(-ENOMEM);
791 791
792 sd->s_attr.ops = ops; 792 kn->s_attr.ops = ops;
793 sd->s_attr.size = size; 793 kn->s_attr.size = size;
794 sd->s_ns = ns; 794 kn->s_ns = ns;
795 sd->priv = priv; 795 kn->priv = priv;
796 796
797#ifdef CONFIG_DEBUG_LOCK_ALLOC 797#ifdef CONFIG_DEBUG_LOCK_ALLOC
798 if (key) { 798 if (key) {
799 lockdep_init_map(&sd->dep_map, "s_active", key, 0); 799 lockdep_init_map(&kn->dep_map, "s_active", key, 0);
800 sd->s_flags |= SYSFS_FLAG_LOCKDEP; 800 kn->s_flags |= SYSFS_FLAG_LOCKDEP;
801 } 801 }
802#endif 802#endif
803 803
804 /* 804 /*
805 * sd->s_attr.ops is accesible only while holding active ref. We 805 * kn->s_attr.ops is accesible only while holding active ref. We
806 * need to know whether some ops are implemented outside active 806 * need to know whether some ops are implemented outside active
807 * ref. Cache their existence in flags. 807 * ref. Cache their existence in flags.
808 */ 808 */
809 if (ops->seq_show) 809 if (ops->seq_show)
810 sd->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW; 810 kn->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW;
811 if (ops->mmap) 811 if (ops->mmap)
812 sd->s_flags |= SYSFS_FLAG_HAS_MMAP; 812 kn->s_flags |= SYSFS_FLAG_HAS_MMAP;
813 813
814 sysfs_addrm_start(&acxt); 814 sysfs_addrm_start(&acxt);
815 rc = sysfs_add_one(&acxt, sd, parent); 815 rc = sysfs_add_one(&acxt, kn, parent);
816 sysfs_addrm_finish(&acxt); 816 sysfs_addrm_finish(&acxt);
817 817
818 if (rc) { 818 if (rc) {
819 kernfs_put(sd); 819 kernfs_put(kn);
820 return ERR_PTR(rc); 820 return ERR_PTR(rc);
821 } 821 }
822 return sd; 822 return kn;
823} 823}
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index 18ad431e8c2a..9e74eed63539 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -46,36 +46,36 @@ void __init sysfs_inode_init(void)
46 panic("failed to init sysfs_backing_dev_info"); 46 panic("failed to init sysfs_backing_dev_info");
47} 47}
48 48
49static struct sysfs_inode_attrs *sysfs_inode_attrs(struct sysfs_dirent *sd) 49static struct sysfs_inode_attrs *sysfs_inode_attrs(struct kernfs_node *kn)
50{ 50{
51 struct iattr *iattrs; 51 struct iattr *iattrs;
52 52
53 if (sd->s_iattr) 53 if (kn->s_iattr)
54 return sd->s_iattr; 54 return kn->s_iattr;
55 55
56 sd->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL); 56 kn->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL);
57 if (!sd->s_iattr) 57 if (!kn->s_iattr)
58 return NULL; 58 return NULL;
59 iattrs = &sd->s_iattr->ia_iattr; 59 iattrs = &kn->s_iattr->ia_iattr;
60 60
61 /* assign default attributes */ 61 /* assign default attributes */
62 iattrs->ia_mode = sd->s_mode; 62 iattrs->ia_mode = kn->s_mode;
63 iattrs->ia_uid = GLOBAL_ROOT_UID; 63 iattrs->ia_uid = GLOBAL_ROOT_UID;
64 iattrs->ia_gid = GLOBAL_ROOT_GID; 64 iattrs->ia_gid = GLOBAL_ROOT_GID;
65 iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME; 65 iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME;
66 66
67 simple_xattrs_init(&sd->s_iattr->xattrs); 67 simple_xattrs_init(&kn->s_iattr->xattrs);
68 68
69 return sd->s_iattr; 69 return kn->s_iattr;
70} 70}
71 71
72static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) 72static int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
73{ 73{
74 struct sysfs_inode_attrs *attrs; 74 struct sysfs_inode_attrs *attrs;
75 struct iattr *iattrs; 75 struct iattr *iattrs;
76 unsigned int ia_valid = iattr->ia_valid; 76 unsigned int ia_valid = iattr->ia_valid;
77 77
78 attrs = sysfs_inode_attrs(sd); 78 attrs = sysfs_inode_attrs(kn);
79 if (!attrs) 79 if (!attrs)
80 return -ENOMEM; 80 return -ENOMEM;
81 81
@@ -93,24 +93,24 @@ static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr)
93 iattrs->ia_ctime = iattr->ia_ctime; 93 iattrs->ia_ctime = iattr->ia_ctime;
94 if (ia_valid & ATTR_MODE) { 94 if (ia_valid & ATTR_MODE) {
95 umode_t mode = iattr->ia_mode; 95 umode_t mode = iattr->ia_mode;
96 iattrs->ia_mode = sd->s_mode = mode; 96 iattrs->ia_mode = kn->s_mode = mode;
97 } 97 }
98 return 0; 98 return 0;
99} 99}
100 100
101/** 101/**
102 * kernfs_setattr - set iattr on a node 102 * kernfs_setattr - set iattr on a node
103 * @sd: target node 103 * @kn: target node
104 * @iattr: iattr to set 104 * @iattr: iattr to set
105 * 105 *
106 * Returns 0 on success, -errno on failure. 106 * Returns 0 on success, -errno on failure.
107 */ 107 */
108int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) 108int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
109{ 109{
110 int ret; 110 int ret;
111 111
112 mutex_lock(&sysfs_mutex); 112 mutex_lock(&sysfs_mutex);
113 ret = __kernfs_setattr(sd, iattr); 113 ret = __kernfs_setattr(kn, iattr);
114 mutex_unlock(&sysfs_mutex); 114 mutex_unlock(&sysfs_mutex);
115 return ret; 115 return ret;
116} 116}
@@ -118,10 +118,10 @@ int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr)
118int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) 118int sysfs_setattr(struct dentry *dentry, struct iattr *iattr)
119{ 119{
120 struct inode *inode = dentry->d_inode; 120 struct inode *inode = dentry->d_inode;
121 struct sysfs_dirent *sd = dentry->d_fsdata; 121 struct kernfs_node *kn = dentry->d_fsdata;
122 int error; 122 int error;
123 123
124 if (!sd) 124 if (!kn)
125 return -EINVAL; 125 return -EINVAL;
126 126
127 mutex_lock(&sysfs_mutex); 127 mutex_lock(&sysfs_mutex);
@@ -129,7 +129,7 @@ int sysfs_setattr(struct dentry *dentry, struct iattr *iattr)
129 if (error) 129 if (error)
130 goto out; 130 goto out;
131 131
132 error = __kernfs_setattr(sd, iattr); 132 error = __kernfs_setattr(kn, iattr);
133 if (error) 133 if (error)
134 goto out; 134 goto out;
135 135
@@ -141,14 +141,14 @@ out:
141 return error; 141 return error;
142} 142}
143 143
144static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata, 144static int sysfs_sd_setsecdata(struct kernfs_node *kn, void **secdata,
145 u32 *secdata_len) 145 u32 *secdata_len)
146{ 146{
147 struct sysfs_inode_attrs *attrs; 147 struct sysfs_inode_attrs *attrs;
148 void *old_secdata; 148 void *old_secdata;
149 size_t old_secdata_len; 149 size_t old_secdata_len;
150 150
151 attrs = sysfs_inode_attrs(sd); 151 attrs = sysfs_inode_attrs(kn);
152 if (!attrs) 152 if (!attrs)
153 return -ENOMEM; 153 return -ENOMEM;
154 154
@@ -166,13 +166,13 @@ static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata,
166int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, 166int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
167 size_t size, int flags) 167 size_t size, int flags)
168{ 168{
169 struct sysfs_dirent *sd = dentry->d_fsdata; 169 struct kernfs_node *kn = dentry->d_fsdata;
170 struct sysfs_inode_attrs *attrs; 170 struct sysfs_inode_attrs *attrs;
171 void *secdata; 171 void *secdata;
172 int error; 172 int error;
173 u32 secdata_len = 0; 173 u32 secdata_len = 0;
174 174
175 attrs = sysfs_inode_attrs(sd); 175 attrs = sysfs_inode_attrs(kn);
176 if (!attrs) 176 if (!attrs)
177 return -ENOMEM; 177 return -ENOMEM;
178 178
@@ -188,7 +188,7 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
188 return error; 188 return error;
189 189
190 mutex_lock(&sysfs_mutex); 190 mutex_lock(&sysfs_mutex);
191 error = sysfs_sd_setsecdata(sd, &secdata, &secdata_len); 191 error = sysfs_sd_setsecdata(kn, &secdata, &secdata_len);
192 mutex_unlock(&sysfs_mutex); 192 mutex_unlock(&sysfs_mutex);
193 193
194 if (secdata) 194 if (secdata)
@@ -204,10 +204,10 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
204 204
205int sysfs_removexattr(struct dentry *dentry, const char *name) 205int sysfs_removexattr(struct dentry *dentry, const char *name)
206{ 206{
207 struct sysfs_dirent *sd = dentry->d_fsdata; 207 struct kernfs_node *kn = dentry->d_fsdata;
208 struct sysfs_inode_attrs *attrs; 208 struct sysfs_inode_attrs *attrs;
209 209
210 attrs = sysfs_inode_attrs(sd); 210 attrs = sysfs_inode_attrs(kn);
211 if (!attrs) 211 if (!attrs)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
@@ -217,10 +217,10 @@ int sysfs_removexattr(struct dentry *dentry, const char *name)
217ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf, 217ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf,
218 size_t size) 218 size_t size)
219{ 219{
220 struct sysfs_dirent *sd = dentry->d_fsdata; 220 struct kernfs_node *kn = dentry->d_fsdata;
221 struct sysfs_inode_attrs *attrs; 221 struct sysfs_inode_attrs *attrs;
222 222
223 attrs = sysfs_inode_attrs(sd); 223 attrs = sysfs_inode_attrs(kn);
224 if (!attrs) 224 if (!attrs)
225 return -ENOMEM; 225 return -ENOMEM;
226 226
@@ -229,10 +229,10 @@ ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf,
229 229
230ssize_t sysfs_listxattr(struct dentry *dentry, char *buf, size_t size) 230ssize_t sysfs_listxattr(struct dentry *dentry, char *buf, size_t size)
231{ 231{
232 struct sysfs_dirent *sd = dentry->d_fsdata; 232 struct kernfs_node *kn = dentry->d_fsdata;
233 struct sysfs_inode_attrs *attrs; 233 struct sysfs_inode_attrs *attrs;
234 234
235 attrs = sysfs_inode_attrs(sd); 235 attrs = sysfs_inode_attrs(kn);
236 if (!attrs) 236 if (!attrs)
237 return -ENOMEM; 237 return -ENOMEM;
238 238
@@ -254,57 +254,58 @@ static inline void set_inode_attr(struct inode *inode, struct iattr *iattr)
254 inode->i_ctime = iattr->ia_ctime; 254 inode->i_ctime = iattr->ia_ctime;
255} 255}
256 256
257static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode) 257static void sysfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
258{ 258{
259 struct sysfs_inode_attrs *attrs = sd->s_iattr; 259 struct sysfs_inode_attrs *attrs = kn->s_iattr;
260 260
261 inode->i_mode = sd->s_mode; 261 inode->i_mode = kn->s_mode;
262 if (attrs) { 262 if (attrs) {
263 /* sysfs_dirent has non-default attributes 263 /*
264 * get them from persistent copy in sysfs_dirent 264 * kernfs_node has non-default attributes get them from
265 * persistent copy in kernfs_node.
265 */ 266 */
266 set_inode_attr(inode, &attrs->ia_iattr); 267 set_inode_attr(inode, &attrs->ia_iattr);
267 security_inode_notifysecctx(inode, attrs->ia_secdata, 268 security_inode_notifysecctx(inode, attrs->ia_secdata,
268 attrs->ia_secdata_len); 269 attrs->ia_secdata_len);
269 } 270 }
270 271
271 if (sysfs_type(sd) == SYSFS_DIR) 272 if (sysfs_type(kn) == SYSFS_DIR)
272 set_nlink(inode, sd->s_dir.subdirs + 2); 273 set_nlink(inode, kn->s_dir.subdirs + 2);
273} 274}
274 275
275int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, 276int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
276 struct kstat *stat) 277 struct kstat *stat)
277{ 278{
278 struct sysfs_dirent *sd = dentry->d_fsdata; 279 struct kernfs_node *kn = dentry->d_fsdata;
279 struct inode *inode = dentry->d_inode; 280 struct inode *inode = dentry->d_inode;
280 281
281 mutex_lock(&sysfs_mutex); 282 mutex_lock(&sysfs_mutex);
282 sysfs_refresh_inode(sd, inode); 283 sysfs_refresh_inode(kn, inode);
283 mutex_unlock(&sysfs_mutex); 284 mutex_unlock(&sysfs_mutex);
284 285
285 generic_fillattr(inode, stat); 286 generic_fillattr(inode, stat);
286 return 0; 287 return 0;
287} 288}
288 289
289static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) 290static void sysfs_init_inode(struct kernfs_node *kn, struct inode *inode)
290{ 291{
291 kernfs_get(sd); 292 kernfs_get(kn);
292 inode->i_private = sd; 293 inode->i_private = kn;
293 inode->i_mapping->a_ops = &sysfs_aops; 294 inode->i_mapping->a_ops = &sysfs_aops;
294 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 295 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
295 inode->i_op = &sysfs_inode_operations; 296 inode->i_op = &sysfs_inode_operations;
296 297
297 set_default_inode_attr(inode, sd->s_mode); 298 set_default_inode_attr(inode, kn->s_mode);
298 sysfs_refresh_inode(sd, inode); 299 sysfs_refresh_inode(kn, inode);
299 300
300 /* initialize inode according to type */ 301 /* initialize inode according to type */
301 switch (sysfs_type(sd)) { 302 switch (sysfs_type(kn)) {
302 case SYSFS_DIR: 303 case SYSFS_DIR:
303 inode->i_op = &sysfs_dir_inode_operations; 304 inode->i_op = &sysfs_dir_inode_operations;
304 inode->i_fop = &sysfs_dir_operations; 305 inode->i_fop = &sysfs_dir_operations;
305 break; 306 break;
306 case SYSFS_KOBJ_ATTR: 307 case SYSFS_KOBJ_ATTR:
307 inode->i_size = sd->s_attr.size; 308 inode->i_size = kn->s_attr.size;
308 inode->i_fop = &kernfs_file_operations; 309 inode->i_fop = &kernfs_file_operations;
309 break; 310 break;
310 case SYSFS_KOBJ_LINK: 311 case SYSFS_KOBJ_LINK:
@@ -318,13 +319,13 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
318} 319}
319 320
320/** 321/**
321 * sysfs_get_inode - get inode for sysfs_dirent 322 * sysfs_get_inode - get inode for kernfs_node
322 * @sb: super block 323 * @sb: super block
323 * @sd: sysfs_dirent to allocate inode for 324 * @kn: kernfs_node to allocate inode for
324 * 325 *
325 * Get inode for @sd. If such inode doesn't exist, a new inode 326 * Get inode for @kn. If such inode doesn't exist, a new inode is
326 * is allocated and basics are initialized. New inode is 327 * allocated and basics are initialized. New inode is returned
327 * returned locked. 328 * locked.
328 * 329 *
329 * LOCKING: 330 * LOCKING:
330 * Kernel thread context (may sleep). 331 * Kernel thread context (may sleep).
@@ -332,44 +333,44 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
332 * RETURNS: 333 * RETURNS:
333 * Pointer to allocated inode on success, NULL on failure. 334 * Pointer to allocated inode on success, NULL on failure.
334 */ 335 */
335struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd) 336struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
336{ 337{
337 struct inode *inode; 338 struct inode *inode;
338 339
339 inode = iget_locked(sb, sd->s_ino); 340 inode = iget_locked(sb, kn->s_ino);
340 if (inode && (inode->i_state & I_NEW)) 341 if (inode && (inode->i_state & I_NEW))
341 sysfs_init_inode(sd, inode); 342 sysfs_init_inode(kn, inode);
342 343
343 return inode; 344 return inode;
344} 345}
345 346
346/* 347/*
347 * The sysfs_dirent serves as both an inode and a directory entry for sysfs. 348 * The kernfs_node serves as both an inode and a directory entry for sysfs.
348 * To prevent the sysfs inode numbers from being freed prematurely we take a 349 * To prevent the sysfs inode numbers from being freed prematurely we take
349 * reference to sysfs_dirent from the sysfs inode. A 350 * a reference to kernfs_node from the sysfs inode. A
350 * super_operations.evict_inode() implementation is needed to drop that 351 * super_operations.evict_inode() implementation is needed to drop that
351 * reference upon inode destruction. 352 * reference upon inode destruction.
352 */ 353 */
353void sysfs_evict_inode(struct inode *inode) 354void sysfs_evict_inode(struct inode *inode)
354{ 355{
355 struct sysfs_dirent *sd = inode->i_private; 356 struct kernfs_node *kn = inode->i_private;
356 357
357 truncate_inode_pages(&inode->i_data, 0); 358 truncate_inode_pages(&inode->i_data, 0);
358 clear_inode(inode); 359 clear_inode(inode);
359 kernfs_put(sd); 360 kernfs_put(kn);
360} 361}
361 362
362int sysfs_permission(struct inode *inode, int mask) 363int sysfs_permission(struct inode *inode, int mask)
363{ 364{
364 struct sysfs_dirent *sd; 365 struct kernfs_node *kn;
365 366
366 if (mask & MAY_NOT_BLOCK) 367 if (mask & MAY_NOT_BLOCK)
367 return -ECHILD; 368 return -ECHILD;
368 369
369 sd = inode->i_private; 370 kn = inode->i_private;
370 371
371 mutex_lock(&sysfs_mutex); 372 mutex_lock(&sysfs_mutex);
372 sysfs_refresh_inode(sd, inode); 373 sysfs_refresh_inode(kn, inode);
373 mutex_unlock(&sysfs_mutex); 374 mutex_unlock(&sysfs_mutex);
374 375
375 return generic_permission(inode, mask); 376 return generic_permission(inode, mask);
diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h
index 910e485b7333..b7ea76c6fb33 100644
--- a/fs/kernfs/kernfs-internal.h
+++ b/fs/kernfs/kernfs-internal.h
@@ -31,24 +31,24 @@ struct sysfs_inode_attrs {
31/* SYSFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ 31/* SYSFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
32 32
33/** 33/**
34 * kernfs_root - find out the kernfs_root a sysfs_dirent belongs to 34 * kernfs_root - find out the kernfs_root a kernfs_node belongs to
35 * @sd: sysfs_dirent of interest 35 * @kn: kernfs_node of interest
36 * 36 *
37 * Return the kernfs_root @sd belongs to. 37 * Return the kernfs_root @kn belongs to.
38 */ 38 */
39static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd) 39static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
40{ 40{
41 /* if parent exists, it's always a dir; otherwise, @sd is a dir */ 41 /* if parent exists, it's always a dir; otherwise, @sd is a dir */
42 if (sd->s_parent) 42 if (kn->s_parent)
43 sd = sd->s_parent; 43 kn = kn->s_parent;
44 return sd->s_dir.root; 44 return kn->s_dir.root;
45} 45}
46 46
47/* 47/*
48 * Context structure to be used while adding/removing nodes. 48 * Context structure to be used while adding/removing nodes.
49 */ 49 */
50struct sysfs_addrm_cxt { 50struct sysfs_addrm_cxt {
51 struct sysfs_dirent *removed; 51 struct kernfs_node *removed;
52}; 52};
53 53
54/* 54/*
@@ -62,10 +62,10 @@ struct sysfs_super_info {
62 struct kernfs_root *root; 62 struct kernfs_root *root;
63 63
64 /* 64 /*
65 * Each sb is associated with one namespace tag, currently the network 65 * Each sb is associated with one namespace tag, currently the
66 * namespace of the task which mounted this sysfs instance. If multiple 66 * network namespace of the task which mounted this sysfs instance.
67 * tags become necessary, make the following an array and compare 67 * If multiple tags become necessary, make the following an array
68 * sysfs_dirent tag against every entry. 68 * and compare kernfs_node tag against every entry.
69 */ 69 */
70 const void *ns; 70 const void *ns;
71}; 71};
@@ -76,7 +76,7 @@ extern struct kmem_cache *sysfs_dir_cachep;
76/* 76/*
77 * inode.c 77 * inode.c
78 */ 78 */
79struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd); 79struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
80void sysfs_evict_inode(struct inode *inode); 80void sysfs_evict_inode(struct inode *inode);
81int sysfs_permission(struct inode *inode, int mask); 81int sysfs_permission(struct inode *inode, int mask);
82int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); 82int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
@@ -98,21 +98,21 @@ extern const struct dentry_operations sysfs_dentry_ops;
98extern const struct file_operations sysfs_dir_operations; 98extern const struct file_operations sysfs_dir_operations;
99extern const struct inode_operations sysfs_dir_inode_operations; 99extern const struct inode_operations sysfs_dir_inode_operations;
100 100
101struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); 101struct kernfs_node *sysfs_get_active(struct kernfs_node *kn);
102void sysfs_put_active(struct sysfs_dirent *sd); 102void sysfs_put_active(struct kernfs_node *kn);
103void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt); 103void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
104int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, 104int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
105 struct sysfs_dirent *parent_sd); 105 struct kernfs_node *parent);
106void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); 106void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
107struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, 107struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
108 const char *name, umode_t mode, int type); 108 const char *name, umode_t mode, int type);
109 109
110/* 110/*
111 * file.c 111 * file.c
112 */ 112 */
113extern const struct file_operations kernfs_file_operations; 113extern const struct file_operations kernfs_file_operations;
114 114
115void sysfs_unmap_bin_file(struct sysfs_dirent *sd); 115void sysfs_unmap_bin_file(struct kernfs_node *kn);
116 116
117/* 117/*
118 * symlink.c 118 * symlink.c
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 84c83e24bf25..9dbbf37b1af9 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -39,7 +39,7 @@ static int sysfs_fill_super(struct super_block *sb)
39 39
40 /* get root inode, initialize and unlock it */ 40 /* get root inode, initialize and unlock it */
41 mutex_lock(&sysfs_mutex); 41 mutex_lock(&sysfs_mutex);
42 inode = sysfs_get_inode(sb, info->root->sd); 42 inode = sysfs_get_inode(sb, info->root->kn);
43 mutex_unlock(&sysfs_mutex); 43 mutex_unlock(&sysfs_mutex);
44 if (!inode) { 44 if (!inode) {
45 pr_debug("sysfs: could not get root inode\n"); 45 pr_debug("sysfs: could not get root inode\n");
@@ -52,8 +52,8 @@ static int sysfs_fill_super(struct super_block *sb)
52 pr_debug("%s: could not get root dentry!\n", __func__); 52 pr_debug("%s: could not get root dentry!\n", __func__);
53 return -ENOMEM; 53 return -ENOMEM;
54 } 54 }
55 kernfs_get(info->root->sd); 55 kernfs_get(info->root->kn);
56 root->d_fsdata = info->root->sd; 56 root->d_fsdata = info->root->kn;
57 sb->s_root = root; 57 sb->s_root = root;
58 sb->s_d_op = &sysfs_dentry_ops; 58 sb->s_d_op = &sysfs_dentry_ops;
59 return 0; 59 return 0;
@@ -145,7 +145,7 @@ struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
145void kernfs_kill_sb(struct super_block *sb) 145void kernfs_kill_sb(struct super_block *sb)
146{ 146{
147 struct sysfs_super_info *info = sysfs_info(sb); 147 struct sysfs_super_info *info = sysfs_info(sb);
148 struct sysfs_dirent *root_sd = sb->s_root->d_fsdata; 148 struct kernfs_node *root_kn = sb->s_root->d_fsdata;
149 149
150 /* 150 /*
151 * Remove the superblock from fs_supers/s_instances 151 * Remove the superblock from fs_supers/s_instances
@@ -153,13 +153,13 @@ void kernfs_kill_sb(struct super_block *sb)
153 */ 153 */
154 kill_anon_super(sb); 154 kill_anon_super(sb);
155 kfree(info); 155 kfree(info);
156 kernfs_put(root_sd); 156 kernfs_put(root_kn);
157} 157}
158 158
159void __init kernfs_init(void) 159void __init kernfs_init(void)
160{ 160{
161 sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache", 161 sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache",
162 sizeof(struct sysfs_dirent), 162 sizeof(struct kernfs_node),
163 0, SLAB_PANIC, NULL); 163 0, SLAB_PANIC, NULL);
164 sysfs_inode_init(); 164 sysfs_inode_init();
165} 165}
diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
index adf28755b0ee..29dcf5e8debd 100644
--- a/fs/kernfs/symlink.c
+++ b/fs/kernfs/symlink.c
@@ -22,50 +22,50 @@
22 * 22 *
23 * Returns the created node on success, ERR_PTR() value on error. 23 * Returns the created node on success, ERR_PTR() value on error.
24 */ 24 */
25struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, 25struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
26 const char *name, 26 const char *name,
27 struct sysfs_dirent *target) 27 struct kernfs_node *target)
28{ 28{
29 struct sysfs_dirent *sd; 29 struct kernfs_node *kn;
30 struct sysfs_addrm_cxt acxt; 30 struct sysfs_addrm_cxt acxt;
31 int error; 31 int error;
32 32
33 sd = sysfs_new_dirent(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO, 33 kn = sysfs_new_dirent(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO,
34 SYSFS_KOBJ_LINK); 34 SYSFS_KOBJ_LINK);
35 if (!sd) 35 if (!kn)
36 return ERR_PTR(-ENOMEM); 36 return ERR_PTR(-ENOMEM);
37 37
38 if (kernfs_ns_enabled(parent)) 38 if (kernfs_ns_enabled(parent))
39 sd->s_ns = target->s_ns; 39 kn->s_ns = target->s_ns;
40 sd->s_symlink.target_sd = target; 40 kn->s_symlink.target_kn = target;
41 kernfs_get(target); /* ref owned by symlink */ 41 kernfs_get(target); /* ref owned by symlink */
42 42
43 sysfs_addrm_start(&acxt); 43 sysfs_addrm_start(&acxt);
44 error = sysfs_add_one(&acxt, sd, parent); 44 error = sysfs_add_one(&acxt, kn, parent);
45 sysfs_addrm_finish(&acxt); 45 sysfs_addrm_finish(&acxt);
46 46
47 if (!error) 47 if (!error)
48 return sd; 48 return kn;
49 49
50 kernfs_put(sd); 50 kernfs_put(kn);
51 return ERR_PTR(error); 51 return ERR_PTR(error);
52} 52}
53 53
54static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, 54static int sysfs_get_target_path(struct kernfs_node *parent,
55 struct sysfs_dirent *target_sd, char *path) 55 struct kernfs_node *target, char *path)
56{ 56{
57 struct sysfs_dirent *base, *sd; 57 struct kernfs_node *base, *kn;
58 char *s = path; 58 char *s = path;
59 int len = 0; 59 int len = 0;
60 60
61 /* go up to the root, stop at the base */ 61 /* go up to the root, stop at the base */
62 base = parent_sd; 62 base = parent;
63 while (base->s_parent) { 63 while (base->s_parent) {
64 sd = target_sd->s_parent; 64 kn = target->s_parent;
65 while (sd->s_parent && base != sd) 65 while (kn->s_parent && base != kn)
66 sd = sd->s_parent; 66 kn = kn->s_parent;
67 67
68 if (base == sd) 68 if (base == kn)
69 break; 69 break;
70 70
71 strcpy(s, "../"); 71 strcpy(s, "../");
@@ -74,10 +74,10 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
74 } 74 }
75 75
76 /* determine end of target string for reverse fillup */ 76 /* determine end of target string for reverse fillup */
77 sd = target_sd; 77 kn = target;
78 while (sd->s_parent && sd != base) { 78 while (kn->s_parent && kn != base) {
79 len += strlen(sd->s_name) + 1; 79 len += strlen(kn->s_name) + 1;
80 sd = sd->s_parent; 80 kn = kn->s_parent;
81 } 81 }
82 82
83 /* check limits */ 83 /* check limits */
@@ -88,16 +88,16 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
88 return -ENAMETOOLONG; 88 return -ENAMETOOLONG;
89 89
90 /* reverse fillup of target string from target to base */ 90 /* reverse fillup of target string from target to base */
91 sd = target_sd; 91 kn = target;
92 while (sd->s_parent && sd != base) { 92 while (kn->s_parent && kn != base) {
93 int slen = strlen(sd->s_name); 93 int slen = strlen(kn->s_name);
94 94
95 len -= slen; 95 len -= slen;
96 strncpy(s + len, sd->s_name, slen); 96 strncpy(s + len, kn->s_name, slen);
97 if (len) 97 if (len)
98 s[--len] = '/'; 98 s[--len] = '/';
99 99
100 sd = sd->s_parent; 100 kn = kn->s_parent;
101 } 101 }
102 102
103 return 0; 103 return 0;
@@ -105,13 +105,13 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
105 105
106static int sysfs_getlink(struct dentry *dentry, char *path) 106static int sysfs_getlink(struct dentry *dentry, char *path)
107{ 107{
108 struct sysfs_dirent *sd = dentry->d_fsdata; 108 struct kernfs_node *kn = dentry->d_fsdata;
109 struct sysfs_dirent *parent_sd = sd->s_parent; 109 struct kernfs_node *parent = kn->s_parent;
110 struct sysfs_dirent *target_sd = sd->s_symlink.target_sd; 110 struct kernfs_node *target = kn->s_symlink.target_kn;
111 int error; 111 int error;
112 112
113 mutex_lock(&sysfs_mutex); 113 mutex_lock(&sysfs_mutex);
114 error = sysfs_get_target_path(parent_sd, target_sd, path); 114 error = sysfs_get_target_path(parent, target, path);
115 mutex_unlock(&sysfs_mutex); 115 mutex_unlock(&sysfs_mutex);
116 116
117 return error; 117 return error;