Lines Matching refs:of

67 static struct kernfs_open_node *of_on(struct kernfs_open_file *of)  in of_on()  argument
69 return rcu_dereference_protected(of->kn->attr.open, in of_on()
70 !list_empty(&of->list)); in of_on()
137 struct kernfs_open_file *of = sf->private; in kernfs_seq_stop_active() local
138 const struct kernfs_ops *ops = kernfs_ops(of->kn); in kernfs_seq_stop_active()
142 kernfs_put_active(of->kn); in kernfs_seq_stop_active()
147 struct kernfs_open_file *of = sf->private; in kernfs_seq_start() local
154 mutex_lock(&of->mutex); in kernfs_seq_start()
155 if (!kernfs_get_active(of->kn)) in kernfs_seq_start()
158 ops = kernfs_ops(of->kn); in kernfs_seq_start()
171 struct kernfs_open_file *of = sf->private; in kernfs_seq_next() local
172 const struct kernfs_ops *ops = kernfs_ops(of->kn); in kernfs_seq_next()
192 struct kernfs_open_file *of = sf->private; in kernfs_seq_stop() local
196 mutex_unlock(&of->mutex); in kernfs_seq_stop()
201 struct kernfs_open_file *of = sf->private; in kernfs_seq_show() local
203 of->event = atomic_read(&of_on(of)->event); in kernfs_seq_show()
205 return of->kn->attr.ops->seq_show(sf, v); in kernfs_seq_show()
223 struct kernfs_open_file *of = kernfs_of(iocb->ki_filp); in kernfs_file_read_iter() local
228 buf = of->prealloc_buf; in kernfs_file_read_iter()
230 mutex_lock(&of->prealloc_mutex); in kernfs_file_read_iter()
240 mutex_lock(&of->mutex); in kernfs_file_read_iter()
241 if (!kernfs_get_active(of->kn)) { in kernfs_file_read_iter()
243 mutex_unlock(&of->mutex); in kernfs_file_read_iter()
247 of->event = atomic_read(&of_on(of)->event); in kernfs_file_read_iter()
249 ops = kernfs_ops(of->kn); in kernfs_file_read_iter()
251 len = ops->read(of, buf, len, iocb->ki_pos); in kernfs_file_read_iter()
255 kernfs_put_active(of->kn); in kernfs_file_read_iter()
256 mutex_unlock(&of->mutex); in kernfs_file_read_iter()
269 if (buf == of->prealloc_buf) in kernfs_file_read_iter()
270 mutex_unlock(&of->prealloc_mutex); in kernfs_file_read_iter()
295 struct kernfs_open_file *of = kernfs_of(iocb->ki_filp); in kernfs_fop_write_iter() local
300 if (of->atomic_write_len) { in kernfs_fop_write_iter()
301 if (len > of->atomic_write_len) in kernfs_fop_write_iter()
307 buf = of->prealloc_buf; in kernfs_fop_write_iter()
309 mutex_lock(&of->prealloc_mutex); in kernfs_fop_write_iter()
325 mutex_lock(&of->mutex); in kernfs_fop_write_iter()
326 if (!kernfs_get_active(of->kn)) { in kernfs_fop_write_iter()
327 mutex_unlock(&of->mutex); in kernfs_fop_write_iter()
332 ops = kernfs_ops(of->kn); in kernfs_fop_write_iter()
334 len = ops->write(of, buf, len, iocb->ki_pos); in kernfs_fop_write_iter()
338 kernfs_put_active(of->kn); in kernfs_fop_write_iter()
339 mutex_unlock(&of->mutex); in kernfs_fop_write_iter()
345 if (buf == of->prealloc_buf) in kernfs_fop_write_iter()
346 mutex_unlock(&of->prealloc_mutex); in kernfs_fop_write_iter()
355 struct kernfs_open_file *of = kernfs_of(file); in kernfs_vma_open() local
357 if (!of->vm_ops) in kernfs_vma_open()
360 if (!kernfs_get_active(of->kn)) in kernfs_vma_open()
363 if (of->vm_ops->open) in kernfs_vma_open()
364 of->vm_ops->open(vma); in kernfs_vma_open()
366 kernfs_put_active(of->kn); in kernfs_vma_open()
372 struct kernfs_open_file *of = kernfs_of(file); in kernfs_vma_fault() local
375 if (!of->vm_ops) in kernfs_vma_fault()
378 if (!kernfs_get_active(of->kn)) in kernfs_vma_fault()
382 if (of->vm_ops->fault) in kernfs_vma_fault()
383 ret = of->vm_ops->fault(vmf); in kernfs_vma_fault()
385 kernfs_put_active(of->kn); in kernfs_vma_fault()
392 struct kernfs_open_file *of = kernfs_of(file); in kernfs_vma_page_mkwrite() local
395 if (!of->vm_ops) in kernfs_vma_page_mkwrite()
398 if (!kernfs_get_active(of->kn)) in kernfs_vma_page_mkwrite()
402 if (of->vm_ops->page_mkwrite) in kernfs_vma_page_mkwrite()
403 ret = of->vm_ops->page_mkwrite(vmf); in kernfs_vma_page_mkwrite()
407 kernfs_put_active(of->kn); in kernfs_vma_page_mkwrite()
415 struct kernfs_open_file *of = kernfs_of(file); in kernfs_vma_access() local
418 if (!of->vm_ops) in kernfs_vma_access()
421 if (!kernfs_get_active(of->kn)) in kernfs_vma_access()
425 if (of->vm_ops->access) in kernfs_vma_access()
426 ret = of->vm_ops->access(vma, addr, buf, len, write); in kernfs_vma_access()
428 kernfs_put_active(of->kn); in kernfs_vma_access()
437 struct kernfs_open_file *of = kernfs_of(file); in kernfs_vma_set_policy() local
440 if (!of->vm_ops) in kernfs_vma_set_policy()
443 if (!kernfs_get_active(of->kn)) in kernfs_vma_set_policy()
447 if (of->vm_ops->set_policy) in kernfs_vma_set_policy()
448 ret = of->vm_ops->set_policy(vma, new); in kernfs_vma_set_policy()
450 kernfs_put_active(of->kn); in kernfs_vma_set_policy()
458 struct kernfs_open_file *of = kernfs_of(file); in kernfs_vma_get_policy() local
461 if (!of->vm_ops) in kernfs_vma_get_policy()
464 if (!kernfs_get_active(of->kn)) in kernfs_vma_get_policy()
468 if (of->vm_ops->get_policy) in kernfs_vma_get_policy()
469 pol = of->vm_ops->get_policy(vma, addr); in kernfs_vma_get_policy()
471 kernfs_put_active(of->kn); in kernfs_vma_get_policy()
490 struct kernfs_open_file *of = kernfs_of(file); in kernfs_fop_mmap() local
501 if (!(of->kn->flags & KERNFS_HAS_MMAP)) in kernfs_fop_mmap()
504 mutex_lock(&of->mutex); in kernfs_fop_mmap()
507 if (!kernfs_get_active(of->kn)) in kernfs_fop_mmap()
510 ops = kernfs_ops(of->kn); in kernfs_fop_mmap()
511 rc = ops->mmap(of, vma); in kernfs_fop_mmap()
524 if (of->mmapped && of->vm_ops != vma->vm_ops) in kernfs_fop_mmap()
535 if (!of->mmapped) { in kernfs_fop_mmap()
536 of->mmapped = true; in kernfs_fop_mmap()
537 of_on(of)->nr_mmapped++; in kernfs_fop_mmap()
538 of->vm_ops = vma->vm_ops; in kernfs_fop_mmap()
542 kernfs_put_active(of->kn); in kernfs_fop_mmap()
544 mutex_unlock(&of->mutex); in kernfs_fop_mmap()
564 struct kernfs_open_file *of) in kernfs_get_open_node() argument
585 list_add_tail(&of->list, &on->files); in kernfs_get_open_node()
608 struct kernfs_open_file *of, in kernfs_unlink_open_file() argument
622 if (of) { in kernfs_unlink_open_file()
624 WARN_ON_ONCE(of->released == open_failed); in kernfs_unlink_open_file()
628 if (of->mmapped) in kernfs_unlink_open_file()
630 list_del(&of->list); in kernfs_unlink_open_file()
646 struct kernfs_open_file *of; in kernfs_fop_open() local
672 of = kzalloc(sizeof(struct kernfs_open_file), GFP_KERNEL); in kernfs_fop_open()
673 if (!of) in kernfs_fop_open()
692 mutex_init(&of->mutex); in kernfs_fop_open()
694 mutex_init(&of->mutex); in kernfs_fop_open()
696 of->kn = kn; in kernfs_fop_open()
697 of->file = file; in kernfs_fop_open()
703 of->atomic_write_len = ops->atomic_write_len; in kernfs_fop_open()
714 int len = of->atomic_write_len ?: PAGE_SIZE; in kernfs_fop_open()
715 of->prealloc_buf = kmalloc(len + 1, GFP_KERNEL); in kernfs_fop_open()
717 if (!of->prealloc_buf) in kernfs_fop_open()
719 mutex_init(&of->prealloc_mutex); in kernfs_fop_open()
734 of->seq_file = file->private_data; in kernfs_fop_open()
735 of->seq_file->private = of; in kernfs_fop_open()
742 error = kernfs_get_open_node(kn, of); in kernfs_fop_open()
748 error = ops->open(of); in kernfs_fop_open()
758 kernfs_unlink_open_file(kn, of, true); in kernfs_fop_open()
762 kfree(of->prealloc_buf); in kernfs_fop_open()
763 kfree(of); in kernfs_fop_open()
771 struct kernfs_open_file *of) in kernfs_release_file() argument
782 if (!of->released) { in kernfs_release_file()
788 kn->attr.ops->release(of); in kernfs_release_file()
789 of->released = true; in kernfs_release_file()
790 of_on(of)->nr_to_release--; in kernfs_release_file()
797 struct kernfs_open_file *of = kernfs_of(filp); in kernfs_fop_release() local
803 kernfs_release_file(kn, of); in kernfs_fop_release()
807 kernfs_unlink_open_file(kn, of, false); in kernfs_fop_release()
809 kfree(of->prealloc_buf); in kernfs_fop_release()
810 kfree(of); in kernfs_fop_release()
837 struct kernfs_open_file *of; in kernfs_drain_open_files() local
847 list_for_each_entry(of, &on->files, list) { in kernfs_drain_open_files()
848 struct inode *inode = file_inode(of->file); in kernfs_drain_open_files()
850 if (of->mmapped) { in kernfs_drain_open_files()
852 of->mmapped = false; in kernfs_drain_open_files()
857 kernfs_release_file(kn, of); in kernfs_drain_open_files()
878 __poll_t kernfs_generic_poll(struct kernfs_open_file *of, poll_table *wait) in kernfs_generic_poll() argument
880 struct kernfs_open_node *on = of_on(of); in kernfs_generic_poll()
882 poll_wait(of->file, &on->poll, wait); in kernfs_generic_poll()
884 if (of->event != atomic_read(&on->event)) in kernfs_generic_poll()
892 struct kernfs_open_file *of = kernfs_of(filp); in kernfs_fop_poll() local
900 ret = kn->attr.ops->poll(of, wait); in kernfs_fop_poll()
902 ret = kernfs_generic_poll(of, wait); in kernfs_fop_poll()