Lines Matching refs: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)
69 return rcu_dereference_protected(of->kn->attr.open,
70 !list_empty(&of->list));
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;
138 const struct kernfs_ops *ops = kernfs_ops(of->kn);
142 kernfs_put_active(of->kn);
147 struct kernfs_open_file *of = sf->private;
151 * @of->mutex nests outside active ref and is primarily to ensure that
154 mutex_lock(&of->mutex);
155 if (!kernfs_get_active(of->kn))
158 ops = kernfs_ops(of->kn);
171 struct kernfs_open_file *of = sf->private;
172 const struct kernfs_ops *ops = kernfs_ops(of->kn);
192 struct kernfs_open_file *of = sf->private;
196 mutex_unlock(&of->mutex);
201 struct kernfs_open_file *of = sf->private;
203 of->event = atomic_read(&of_on(of)->event);
205 return of->kn->attr.ops->seq_show(sf, v);
223 struct kernfs_open_file *of = kernfs_of(iocb->ki_filp);
228 buf = of->prealloc_buf;
230 mutex_lock(&of->prealloc_mutex);
237 * @of->mutex nests outside active ref and is used both to ensure that
240 mutex_lock(&of->mutex);
241 if (!kernfs_get_active(of->kn)) {
243 mutex_unlock(&of->mutex);
247 of->event = atomic_read(&of_on(of)->event);
249 ops = kernfs_ops(of->kn);
251 len = ops->read(of, buf, len, iocb->ki_pos);
255 kernfs_put_active(of->kn);
256 mutex_unlock(&of->mutex);
269 if (buf == of->prealloc_buf)
270 mutex_unlock(&of->prealloc_mutex);
295 struct kernfs_open_file *of = kernfs_of(iocb->ki_filp);
300 if (of->atomic_write_len) {
301 if (len > of->atomic_write_len)
307 buf = of->prealloc_buf;
309 mutex_lock(&of->prealloc_mutex);
322 * @of->mutex nests outside active ref and is used both to ensure that
325 mutex_lock(&of->mutex);
326 if (!kernfs_get_active(of->kn)) {
327 mutex_unlock(&of->mutex);
332 ops = kernfs_ops(of->kn);
334 len = ops->write(of, buf, len, iocb->ki_pos);
338 kernfs_put_active(of->kn);
339 mutex_unlock(&of->mutex);
345 if (buf == of->prealloc_buf)
346 mutex_unlock(&of->prealloc_mutex);
355 struct kernfs_open_file *of = kernfs_of(file);
357 if (!of->vm_ops)
360 if (!kernfs_get_active(of->kn))
363 if (of->vm_ops->open)
364 of->vm_ops->open(vma);
366 kernfs_put_active(of->kn);
372 struct kernfs_open_file *of = kernfs_of(file);
375 if (!of->vm_ops)
378 if (!kernfs_get_active(of->kn))
382 if (of->vm_ops->fault)
383 ret = of->vm_ops->fault(vmf);
385 kernfs_put_active(of->kn);
392 struct kernfs_open_file *of = kernfs_of(file);
395 if (!of->vm_ops)
398 if (!kernfs_get_active(of->kn))
402 if (of->vm_ops->page_mkwrite)
403 ret = of->vm_ops->page_mkwrite(vmf);
407 kernfs_put_active(of->kn);
415 struct kernfs_open_file *of = kernfs_of(file);
418 if (!of->vm_ops)
421 if (!kernfs_get_active(of->kn))
425 if (of->vm_ops->access)
426 ret = of->vm_ops->access(vma, addr, buf, len, write);
428 kernfs_put_active(of->kn);
437 struct kernfs_open_file *of = kernfs_of(file);
440 if (!of->vm_ops)
443 if (!kernfs_get_active(of->kn))
447 if (of->vm_ops->set_policy)
448 ret = of->vm_ops->set_policy(vma, new);
450 kernfs_put_active(of->kn);
458 struct kernfs_open_file *of = kernfs_of(file);
461 if (!of->vm_ops)
464 if (!kernfs_get_active(of->kn))
468 if (of->vm_ops->get_policy)
469 pol = of->vm_ops->get_policy(vma, addr);
471 kernfs_put_active(of->kn);
490 struct kernfs_open_file *of = kernfs_of(file);
495 * mmap path and of->mutex are prone to triggering spurious lockdep
498 * without grabbing @of->mutex by testing HAS_MMAP flag. See the
501 if (!(of->kn->flags & KERNFS_HAS_MMAP))
504 mutex_lock(&of->mutex);
507 if (!kernfs_get_active(of->kn))
510 ops = kernfs_ops(of->kn);
511 rc = ops->mmap(of, vma);
516 * PowerPC's pci_mmap of legacy_mem uses shmem_zero_setup()
517 * to satisfy versions of X which crash if the mmap fails: that
524 if (of->mmapped && of->vm_ops != vma->vm_ops)
535 of->mmapped = true;
536 of_on(of)->nr_mmapped++;
537 of->vm_ops = vma->vm_ops;
540 kernfs_put_active(of->kn);
542 mutex_unlock(&of->mutex);
550 * @of: kernfs_open_file for this instance of open
553 * create one. @of is chained to the files list.
562 struct kernfs_open_file *of)
583 list_add_tail(&of->list, &on->files);
592 * kernfs_unlink_open_file - Unlink @of from @kn.
595 * @of: associated kernfs_open_file
598 * Unlink @of from list of @kn's associated open files. If list of
606 struct kernfs_open_file *of,
620 if (of) {
622 WARN_ON_ONCE(of->released == open_failed);
626 if (of->mmapped)
628 list_del(&of->list);
644 struct kernfs_open_file *of;
670 of = kzalloc(sizeof(struct kernfs_open_file), GFP_KERNEL);
671 if (!of)
676 * @of->mutex for files which implement mmap. This is a rather
678 * mm->mmap_lock - mmap nests @of->mutex under mm->mmap_lock and
680 * which mm->mmap_lock nests, while holding @of->mutex. As each
686 * Both paths of the branch look the same. They're supposed to
687 * look that way and give @of->mutex different static lockdep keys.
690 mutex_init(&of->mutex);
692 mutex_init(&of->mutex);
694 of->kn = kn;
695 of->file = file;
701 of->atomic_write_len = ops->atomic_write_len;
712 int len = of->atomic_write_len ?: PAGE_SIZE;
713 of->prealloc_buf = kmalloc(len + 1, GFP_KERNEL);
715 if (!of->prealloc_buf)
717 mutex_init(&of->prealloc_mutex);
732 of->seq_file = file->private_data;
733 of->seq_file->private = of;
740 error = kernfs_get_open_node(kn, of);
745 /* nobody has access to @of yet, skip @of->mutex */
746 error = ops->open(of);
756 kernfs_unlink_open_file(kn, of, true);
760 kfree(of->prealloc_buf);
761 kfree(of);
769 struct kernfs_open_file *of)
772 * @of is guaranteed to have no other file operations in flight and
774 * @kernfs_open_file_mutex_ptr(kn) is enough. @of->mutex can't be used
780 if (!of->released) {
786 kn->attr.ops->release(of);
787 of->released = true;
788 of_on(of)->nr_to_release--;
795 struct kernfs_open_file *of = kernfs_of(filp);
801 kernfs_release_file(kn, of);
805 kernfs_unlink_open_file(kn, of, false);
807 kfree(of->prealloc_buf);
808 kfree(of);
835 struct kernfs_open_file *of;
845 list_for_each_entry(of, &on->files, list) {
846 struct inode *inode = file_inode(of->file);
848 if (of->mmapped) {
850 of->mmapped = false;
855 kernfs_release_file(kn, of);
876 __poll_t kernfs_generic_poll(struct kernfs_open_file *of, poll_table *wait)
878 struct kernfs_open_node *on = of_on(of);
880 poll_wait(of->file, &on->poll, wait);
882 if (of->event != atomic_read(&on->event))
890 struct kernfs_open_file *of = kernfs_of(filp);
898 ret = kn->attr.ops->poll(of, wait);
900 ret = kernfs_generic_poll(of, wait);
1021 * @name: name of the file
1022 * @mode: mode of the file
1023 * @uid: uid of the file
1024 * @gid: gid of the file
1025 * @size: size of the file
1028 * @ns: optional namespace tag of the file