Lines Matching full:file

10  * General Public License (GPL) Version 2, available from the file
44 #include <linux/file.h>
80 static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
130 struct ib_uverbs_event_file *file = in ib_uverbs_release_event_file() local
133 kfree(file); in ib_uverbs_release_event_file()
136 void ib_uverbs_release_ucq(struct ib_uverbs_file *file, in ib_uverbs_release_ucq() argument
153 spin_lock_irq(&file->async_file->lock); in ib_uverbs_release_ucq()
158 spin_unlock_irq(&file->async_file->lock); in ib_uverbs_release_ucq()
161 void ib_uverbs_release_uevent(struct ib_uverbs_file *file, in ib_uverbs_release_uevent() argument
166 spin_lock_irq(&file->async_file->lock); in ib_uverbs_release_uevent()
171 spin_unlock_irq(&file->async_file->lock); in ib_uverbs_release_uevent()
186 static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, in ib_uverbs_cleanup_ucontext() argument
216 ib_uverbs_release_uevent(file, &uqp->uevent); in ib_uverbs_cleanup_ucontext()
228 ib_uverbs_release_ucq(file, ev_file, ucq); in ib_uverbs_cleanup_ucontext()
239 ib_uverbs_release_uevent(file, uevent); in ib_uverbs_cleanup_ucontext()
253 mutex_lock(&file->device->xrcd_tree_mutex); in ib_uverbs_cleanup_ucontext()
260 ib_uverbs_dealloc_xrcd(file->device, xrcd); in ib_uverbs_cleanup_ucontext()
263 mutex_unlock(&file->device->xrcd_tree_mutex); in ib_uverbs_cleanup_ucontext()
278 struct ib_uverbs_file *file = in ib_uverbs_release_file() local
281 module_put(file->device->ib_dev->owner); in ib_uverbs_release_file()
282 kref_put(&file->device->ref, ib_uverbs_release_dev); in ib_uverbs_release_file()
284 kfree(file); in ib_uverbs_release_file()
287 static ssize_t ib_uverbs_event_read(struct file *filp, char __user *buf, in ib_uverbs_event_read()
290 struct ib_uverbs_event_file *file = filp->private_data; in ib_uverbs_event_read() local
295 spin_lock_irq(&file->lock); in ib_uverbs_event_read()
297 while (list_empty(&file->event_list)) { in ib_uverbs_event_read()
298 spin_unlock_irq(&file->lock); in ib_uverbs_event_read()
303 if (wait_event_interruptible(file->poll_wait, in ib_uverbs_event_read()
304 !list_empty(&file->event_list))) in ib_uverbs_event_read()
307 spin_lock_irq(&file->lock); in ib_uverbs_event_read()
310 event = list_entry(file->event_list.next, struct ib_uverbs_event, list); in ib_uverbs_event_read()
312 if (file->is_async) in ib_uverbs_event_read()
321 list_del(file->event_list.next); in ib_uverbs_event_read()
328 spin_unlock_irq(&file->lock); in ib_uverbs_event_read()
342 static unsigned int ib_uverbs_event_poll(struct file *filp, in ib_uverbs_event_poll()
346 struct ib_uverbs_event_file *file = filp->private_data; in ib_uverbs_event_poll() local
348 poll_wait(filp, &file->poll_wait, wait); in ib_uverbs_event_poll()
350 spin_lock_irq(&file->lock); in ib_uverbs_event_poll()
351 if (!list_empty(&file->event_list)) in ib_uverbs_event_poll()
353 spin_unlock_irq(&file->lock); in ib_uverbs_event_poll()
358 static int ib_uverbs_event_fasync(int fd, struct file *filp, int on) in ib_uverbs_event_fasync()
360 struct ib_uverbs_event_file *file = filp->private_data; in ib_uverbs_event_fasync() local
362 return fasync_helper(fd, filp, on, &file->async_queue); in ib_uverbs_event_fasync()
365 static int ib_uverbs_event_close(struct inode *inode, struct file *filp) in ib_uverbs_event_close()
367 struct ib_uverbs_event_file *file = filp->private_data; in ib_uverbs_event_close() local
370 spin_lock_irq(&file->lock); in ib_uverbs_event_close()
371 file->is_closed = 1; in ib_uverbs_event_close()
372 list_for_each_entry_safe(entry, tmp, &file->event_list, list) { in ib_uverbs_event_close()
377 spin_unlock_irq(&file->lock); in ib_uverbs_event_close()
379 if (file->is_async) { in ib_uverbs_event_close()
380 ib_unregister_event_handler(&file->uverbs_file->event_handler); in ib_uverbs_event_close()
381 kref_put(&file->uverbs_file->ref, ib_uverbs_release_file); in ib_uverbs_event_close()
383 kref_put(&file->ref, ib_uverbs_release_event_file); in ib_uverbs_event_close()
399 struct ib_uverbs_event_file *file = cq_context; in ib_uverbs_comp_handler() local
404 if (!file) in ib_uverbs_comp_handler()
407 spin_lock_irqsave(&file->lock, flags); in ib_uverbs_comp_handler()
408 if (file->is_closed) { in ib_uverbs_comp_handler()
409 spin_unlock_irqrestore(&file->lock, flags); in ib_uverbs_comp_handler()
415 spin_unlock_irqrestore(&file->lock, flags); in ib_uverbs_comp_handler()
424 list_add_tail(&entry->list, &file->event_list); in ib_uverbs_comp_handler()
426 spin_unlock_irqrestore(&file->lock, flags); in ib_uverbs_comp_handler()
428 wake_up_interruptible(&file->poll_wait); in ib_uverbs_comp_handler()
429 kill_fasync(&file->async_queue, SIGIO, POLL_IN); in ib_uverbs_comp_handler()
432 static void ib_uverbs_async_handler(struct ib_uverbs_file *file, in ib_uverbs_async_handler() argument
440 spin_lock_irqsave(&file->async_file->lock, flags); in ib_uverbs_async_handler()
441 if (file->async_file->is_closed) { in ib_uverbs_async_handler()
442 spin_unlock_irqrestore(&file->async_file->lock, flags); in ib_uverbs_async_handler()
448 spin_unlock_irqrestore(&file->async_file->lock, flags); in ib_uverbs_async_handler()
456 list_add_tail(&entry->list, &file->async_file->event_list); in ib_uverbs_async_handler()
459 spin_unlock_irqrestore(&file->async_file->lock, flags); in ib_uverbs_async_handler()
461 wake_up_interruptible(&file->async_file->poll_wait); in ib_uverbs_async_handler()
462 kill_fasync(&file->async_file->async_queue, SIGIO, POLL_IN); in ib_uverbs_async_handler()
502 struct ib_uverbs_file *file = in ib_uverbs_event_handler() local
505 ib_uverbs_async_handler(file, event->element.port_num, event->event, in ib_uverbs_event_handler()
509 struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, in ib_uverbs_alloc_event_file()
513 struct file *filp; in ib_uverbs_alloc_event_file()
537 * Look up a completion event file by FD. If lookup is successful,
538 * takes a ref to the event file struct that it returns; if
544 struct file *filp; in ib_uverbs_lookup_comp_file()
566 static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, in ib_uverbs_write()
569 struct ib_uverbs_file *file = filp->private_data; in ib_uverbs_write() local
585 if (!file->ucontext && in ib_uverbs_write()
589 if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << hdr.command))) in ib_uverbs_write()
592 return uverbs_cmd_table[hdr.command](file, buf + sizeof hdr, in ib_uverbs_write()
596 static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma) in ib_uverbs_mmap()
598 struct ib_uverbs_file *file = filp->private_data; in ib_uverbs_mmap() local
600 if (!file->ucontext) in ib_uverbs_mmap()
603 return file->device->ib_dev->mmap(file->ucontext, vma); in ib_uverbs_mmap()
610 * everything else is purely local to the file being created, so
616 static int ib_uverbs_open(struct inode *inode, struct file *filp) in ib_uverbs_open()
619 struct ib_uverbs_file *file; in ib_uverbs_open() local
633 file = kmalloc(sizeof *file, GFP_KERNEL); in ib_uverbs_open()
634 if (!file) { in ib_uverbs_open()
639 file->device = dev; in ib_uverbs_open()
640 file->ucontext = NULL; in ib_uverbs_open()
641 file->async_file = NULL; in ib_uverbs_open()
642 kref_init(&file->ref); in ib_uverbs_open()
643 mutex_init(&file->mutex); in ib_uverbs_open()
645 filp->private_data = file; in ib_uverbs_open()
657 static int ib_uverbs_close(struct inode *inode, struct file *filp) in ib_uverbs_close()
659 struct ib_uverbs_file *file = filp->private_data; in ib_uverbs_close() local
661 ib_uverbs_cleanup_ucontext(file, file->ucontext); in ib_uverbs_close()
663 if (file->async_file) in ib_uverbs_close()
664 kref_put(&file->async_file->ref, ib_uverbs_release_event_file); in ib_uverbs_close()
666 kref_put(&file->ref, ib_uverbs_release_file); in ib_uverbs_close()