Lines Matching full:of

33  * pending queue is implemented as a singly linked list of kernfs_nodes.
62 * of_on - Get the kernfs_open_node of the specified kernfs_open_file
63 * @of: target kernfs_open_file
65 * Return: the kernfs_open_node of the kernfs_open_file
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()
78 * Fetch and return ->attr.open of @kn when caller holds the
81 * Update of ->attr.open happens under kernfs_open_file_mutex_ptr(kn). So when
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
151 * @of->mutex nests outside active ref and is primarily to ensure that in kernfs_seq_start()
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()
237 * @of->mutex nests outside active ref and is used both to ensure that 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()
322 * @of->mutex nests outside active ref and is used both to ensure that 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()
441 struct kernfs_open_file *of = kernfs_of(file); in kernfs_fop_mmap() local
446 * mmap path and of->mutex are prone to triggering spurious lockdep in kernfs_fop_mmap()
449 * without grabbing @of->mutex by testing HAS_MMAP flag. See the in kernfs_fop_mmap()
452 if (!(of->kn->flags & KERNFS_HAS_MMAP)) in kernfs_fop_mmap()
455 mutex_lock(&of->mutex); in kernfs_fop_mmap()
458 if (!kernfs_get_active(of->kn)) in kernfs_fop_mmap()
461 ops = kernfs_ops(of->kn); in kernfs_fop_mmap()
462 rc = ops->mmap(of, vma); in kernfs_fop_mmap()
467 * PowerPC's pci_mmap of legacy_mem uses shmem_zero_setup() in kernfs_fop_mmap()
468 * to satisfy versions of X which crash if the mmap fails: that in kernfs_fop_mmap()
475 if (of->mmapped && of->vm_ops != vma->vm_ops) in kernfs_fop_mmap()
486 if (!of->mmapped) { in kernfs_fop_mmap()
487 of->mmapped = true; in kernfs_fop_mmap()
488 of_on(of)->nr_mmapped++; in kernfs_fop_mmap()
489 of->vm_ops = vma->vm_ops; in kernfs_fop_mmap()
493 kernfs_put_active(of->kn); in kernfs_fop_mmap()
495 mutex_unlock(&of->mutex); in kernfs_fop_mmap()
503 * @of: kernfs_open_file for this instance of open
506 * create one. @of is chained to the files list.
515 struct kernfs_open_file *of) in kernfs_get_open_node() argument
536 list_add_tail(&of->list, &on->files); in kernfs_get_open_node()
545 * kernfs_unlink_open_file - Unlink @of from @kn.
548 * @of: associated kernfs_open_file
551 * Unlink @of from list of @kn's associated open files. If list of
559 struct kernfs_open_file *of, in kernfs_unlink_open_file() argument
573 if (of) { in kernfs_unlink_open_file()
575 WARN_ON_ONCE(of->released == open_failed); in kernfs_unlink_open_file()
579 if (of->mmapped) in kernfs_unlink_open_file()
581 list_del(&of->list); in kernfs_unlink_open_file()
597 struct kernfs_open_file *of; in kernfs_fop_open() local
623 of = kzalloc(sizeof(struct kernfs_open_file), GFP_KERNEL); in kernfs_fop_open()
624 if (!of) in kernfs_fop_open()
629 * @of->mutex for files which implement mmap. This is a rather in kernfs_fop_open()
631 * mm->mmap_lock - mmap nests @of->mutex under mm->mmap_lock and in kernfs_fop_open()
633 * which mm->mmap_lock nests, while holding @of->mutex. As each in kernfs_fop_open()
642 * overlayfs from vfs helpers when sysfs is a lower layer of overalyfs. in kernfs_fop_open()
645 * look that way and give @of->mutex different static lockdep keys. in kernfs_fop_open()
648 mutex_init(&of->mutex); in kernfs_fop_open()
650 mutex_init(&of->mutex); in kernfs_fop_open()
652 mutex_init(&of->mutex); in kernfs_fop_open()
654 of->kn = kn; in kernfs_fop_open()
655 of->file = file; in kernfs_fop_open()
661 of->atomic_write_len = ops->atomic_write_len; in kernfs_fop_open()
672 int len = of->atomic_write_len ?: PAGE_SIZE; in kernfs_fop_open()
673 of->prealloc_buf = kmalloc(len + 1, GFP_KERNEL); in kernfs_fop_open()
675 if (!of->prealloc_buf) in kernfs_fop_open()
677 mutex_init(&of->prealloc_mutex); in kernfs_fop_open()
692 of->seq_file = file->private_data; in kernfs_fop_open()
693 of->seq_file->private = of; in kernfs_fop_open()
700 error = kernfs_get_open_node(kn, of); in kernfs_fop_open()
705 /* nobody has access to @of yet, skip @of->mutex */ in kernfs_fop_open()
706 error = ops->open(of); in kernfs_fop_open()
716 kernfs_unlink_open_file(kn, of, true); in kernfs_fop_open()
720 kfree(of->prealloc_buf); in kernfs_fop_open()
721 kfree(of); in kernfs_fop_open()
729 struct kernfs_open_file *of) in kernfs_release_file() argument
732 * @of is guaranteed to have no other file operations in flight and in kernfs_release_file()
734 * @kernfs_open_file_mutex_ptr(kn) is enough. @of->mutex can't be used in kernfs_release_file()
740 if (!of->released) { in kernfs_release_file()
746 kn->attr.ops->release(of); in kernfs_release_file()
747 of->released = true; in kernfs_release_file()
748 of_on(of)->nr_to_release--; in kernfs_release_file()
755 struct kernfs_open_file *of = kernfs_of(filp); in kernfs_fop_release() local
761 kernfs_release_file(kn, of); in kernfs_fop_release()
765 kernfs_unlink_open_file(kn, of, false); in kernfs_fop_release()
767 kfree(of->prealloc_buf); in kernfs_fop_release()
768 kfree(of); in kernfs_fop_release()
795 struct kernfs_open_file *of; in kernfs_drain_open_files() local
805 list_for_each_entry(of, &on->files, list) { in kernfs_drain_open_files()
806 struct inode *inode = file_inode(of->file); in kernfs_drain_open_files()
808 if (of->mmapped) { in kernfs_drain_open_files()
810 of->mmapped = false; in kernfs_drain_open_files()
815 kernfs_release_file(kn, of); in kernfs_drain_open_files()
836 __poll_t kernfs_generic_poll(struct kernfs_open_file *of, poll_table *wait) in kernfs_generic_poll() argument
838 struct kernfs_open_node *on = of_on(of); in kernfs_generic_poll()
840 poll_wait(of->file, &on->poll, wait); in kernfs_generic_poll()
842 if (of->event != atomic_read(&on->event)) in kernfs_generic_poll()
850 struct kernfs_open_file *of = kernfs_of(filp); in kernfs_fop_poll() local
858 ret = kn->attr.ops->poll(of, wait); in kernfs_fop_poll()
860 ret = kernfs_generic_poll(of, wait); in kernfs_fop_poll()
868 struct kernfs_open_file *of = kernfs_of(file); in kernfs_fop_llseek() local
873 * @of->mutex nests outside active ref and is primarily to ensure that in kernfs_fop_llseek()
876 mutex_lock(&of->mutex); in kernfs_fop_llseek()
877 if (!kernfs_get_active(of->kn)) { in kernfs_fop_llseek()
878 mutex_unlock(&of->mutex); in kernfs_fop_llseek()
882 ops = kernfs_ops(of->kn); in kernfs_fop_llseek()
884 ret = ops->llseek(of, offset, whence); in kernfs_fop_llseek()
888 kernfs_put_active(of->kn); in kernfs_fop_llseek()
889 mutex_unlock(&of->mutex); in kernfs_fop_llseek()
1008 * @name: name of the file
1009 * @mode: mode of the file
1010 * @uid: uid of the file
1011 * @gid: gid of the file
1012 * @size: size of the file
1015 * @ns: optional namespace tag of the file