aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/file.c
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/file.c
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/file.c')
-rw-r--r--fs/kernfs/file.c186
1 files changed, 93 insertions, 93 deletions
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}