Lines Matching +full:fiq +full:- +full:index

3   Copyright (C) 2001-2008  Miklos Szeredi <miklos@szeredi.hu>
37 * Lockless access is OK, because file->private data is set in fuse_get_dev()
40 return READ_ONCE(file->private_data); in fuse_get_dev()
45 INIT_LIST_HEAD(&req->list); in fuse_request_init()
46 INIT_LIST_HEAD(&req->intr_entry); in fuse_request_init()
47 init_waitqueue_head(&req->waitq); in fuse_request_init()
48 refcount_set(&req->count, 1); in fuse_request_init()
49 __set_bit(FR_PENDING, &req->flags); in fuse_request_init()
50 req->fm = fm; in fuse_request_init()
69 refcount_inc(&req->count); in __fuse_get_request()
75 refcount_dec(&req->count); in __fuse_put_request()
82 fc->initialized = 1; in fuse_set_initialized()
87 return !fc->initialized || (for_background && fc->blocked); in fuse_block_alloc()
93 * lockess check of fc->connected is okay, because atomic_dec_and_test() in fuse_drop_waiting()
95 * to ensure no wake-up is missed. in fuse_drop_waiting()
97 if (atomic_dec_and_test(&fc->num_waiting) && in fuse_drop_waiting()
98 !READ_ONCE(fc->connected)) { in fuse_drop_waiting()
100 wake_up_all(&fc->blocked_waitq); in fuse_drop_waiting()
108 struct fuse_conn *fc = fm->fc; in fuse_get_req()
111 atomic_inc(&fc->num_waiting); in fuse_get_req()
114 err = -EINTR; in fuse_get_req()
115 if (wait_event_killable_exclusive(fc->blocked_waitq, in fuse_get_req()
122 err = -ENOTCONN; in fuse_get_req()
123 if (!fc->connected) in fuse_get_req()
126 err = -ECONNREFUSED; in fuse_get_req()
127 if (fc->conn_error) in fuse_get_req()
131 err = -ENOMEM; in fuse_get_req()
134 wake_up(&fc->blocked_waitq); in fuse_get_req()
138 req->in.h.uid = from_kuid(fc->user_ns, current_fsuid()); in fuse_get_req()
139 req->in.h.gid = from_kgid(fc->user_ns, current_fsgid()); in fuse_get_req()
140 req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns); in fuse_get_req()
142 __set_bit(FR_WAITING, &req->flags); in fuse_get_req()
144 __set_bit(FR_BACKGROUND, &req->flags); in fuse_get_req()
146 if (unlikely(req->in.h.uid == ((uid_t)-1) || in fuse_get_req()
147 req->in.h.gid == ((gid_t)-1))) { in fuse_get_req()
149 return ERR_PTR(-EOVERFLOW); in fuse_get_req()
160 struct fuse_conn *fc = req->fm->fc; in fuse_put_request()
162 if (refcount_dec_and_test(&req->count)) { in fuse_put_request()
163 if (test_bit(FR_BACKGROUND, &req->flags)) { in fuse_put_request()
168 spin_lock(&fc->bg_lock); in fuse_put_request()
169 if (!fc->blocked) in fuse_put_request()
170 wake_up(&fc->blocked_waitq); in fuse_put_request()
171 spin_unlock(&fc->bg_lock); in fuse_put_request()
174 if (test_bit(FR_WAITING, &req->flags)) { in fuse_put_request()
175 __clear_bit(FR_WAITING, &req->flags); in fuse_put_request()
195 u64 fuse_get_unique(struct fuse_iqueue *fiq) in fuse_get_unique() argument
197 fiq->reqctr += FUSE_REQ_ID_STEP; in fuse_get_unique()
198 return fiq->reqctr; in fuse_get_unique()
208 * A new request is available, wake fiq->waitq
210 static void fuse_dev_wake_and_unlock(struct fuse_iqueue *fiq) in fuse_dev_wake_and_unlock() argument
211 __releases(fiq->lock) in fuse_dev_wake_and_unlock()
213 wake_up(&fiq->waitq); in fuse_dev_wake_and_unlock()
214 kill_fasync(&fiq->fasync, SIGIO, POLL_IN); in fuse_dev_wake_and_unlock()
215 spin_unlock(&fiq->lock); in fuse_dev_wake_and_unlock()
225 static void queue_request_and_unlock(struct fuse_iqueue *fiq, in queue_request_and_unlock() argument
227 __releases(fiq->lock) in queue_request_and_unlock()
229 req->in.h.len = sizeof(struct fuse_in_header) + in queue_request_and_unlock()
230 fuse_len_args(req->args->in_numargs, in queue_request_and_unlock()
231 (struct fuse_arg *) req->args->in_args); in queue_request_and_unlock()
232 list_add_tail(&req->list, &fiq->pending); in queue_request_and_unlock()
233 fiq->ops->wake_pending_and_unlock(fiq); in queue_request_and_unlock()
239 struct fuse_iqueue *fiq = &fc->iq; in fuse_queue_forget() local
241 forget->forget_one.nodeid = nodeid; in fuse_queue_forget()
242 forget->forget_one.nlookup = nlookup; in fuse_queue_forget()
244 spin_lock(&fiq->lock); in fuse_queue_forget()
245 if (fiq->connected) { in fuse_queue_forget()
246 fiq->forget_list_tail->next = forget; in fuse_queue_forget()
247 fiq->forget_list_tail = forget; in fuse_queue_forget()
248 fiq->ops->wake_forget_and_unlock(fiq); in fuse_queue_forget()
251 spin_unlock(&fiq->lock); in fuse_queue_forget()
257 struct fuse_iqueue *fiq = &fc->iq; in flush_bg_queue() local
259 while (fc->active_background < fc->max_background && in flush_bg_queue()
260 !list_empty(&fc->bg_queue)) { in flush_bg_queue()
263 req = list_first_entry(&fc->bg_queue, struct fuse_req, list); in flush_bg_queue()
264 list_del(&req->list); in flush_bg_queue()
265 fc->active_background++; in flush_bg_queue()
266 spin_lock(&fiq->lock); in flush_bg_queue()
267 req->in.h.unique = fuse_get_unique(fiq); in flush_bg_queue()
268 queue_request_and_unlock(fiq, req); in flush_bg_queue()
282 struct fuse_mount *fm = req->fm; in fuse_request_end()
283 struct fuse_conn *fc = fm->fc; in fuse_request_end()
284 struct fuse_iqueue *fiq = &fc->iq; in fuse_request_end() local
286 if (test_and_set_bit(FR_FINISHED, &req->flags)) in fuse_request_end()
294 if (test_bit(FR_INTERRUPTED, &req->flags)) { in fuse_request_end()
295 spin_lock(&fiq->lock); in fuse_request_end()
296 list_del_init(&req->intr_entry); in fuse_request_end()
297 spin_unlock(&fiq->lock); in fuse_request_end()
299 WARN_ON(test_bit(FR_PENDING, &req->flags)); in fuse_request_end()
300 WARN_ON(test_bit(FR_SENT, &req->flags)); in fuse_request_end()
301 if (test_bit(FR_BACKGROUND, &req->flags)) { in fuse_request_end()
302 spin_lock(&fc->bg_lock); in fuse_request_end()
303 clear_bit(FR_BACKGROUND, &req->flags); in fuse_request_end()
304 if (fc->num_background == fc->max_background) { in fuse_request_end()
305 fc->blocked = 0; in fuse_request_end()
306 wake_up(&fc->blocked_waitq); in fuse_request_end()
307 } else if (!fc->blocked) { in fuse_request_end()
311 * fc->blocked with waiters with the wake_up() call in fuse_request_end()
314 if (waitqueue_active(&fc->blocked_waitq)) in fuse_request_end()
315 wake_up(&fc->blocked_waitq); in fuse_request_end()
318 fc->num_background--; in fuse_request_end()
319 fc->active_background--; in fuse_request_end()
321 spin_unlock(&fc->bg_lock); in fuse_request_end()
324 wake_up(&req->waitq); in fuse_request_end()
327 if (test_bit(FR_ASYNC, &req->flags)) in fuse_request_end()
328 req->args->end(fm, req->args, req->out.h.error); in fuse_request_end()
336 struct fuse_iqueue *fiq = &req->fm->fc->iq; in queue_interrupt() local
338 spin_lock(&fiq->lock); in queue_interrupt()
340 if (unlikely(!test_bit(FR_INTERRUPTED, &req->flags))) { in queue_interrupt()
341 spin_unlock(&fiq->lock); in queue_interrupt()
342 return -EINVAL; in queue_interrupt()
345 if (list_empty(&req->intr_entry)) { in queue_interrupt()
346 list_add_tail(&req->intr_entry, &fiq->interrupts); in queue_interrupt()
352 if (test_bit(FR_FINISHED, &req->flags)) { in queue_interrupt()
353 list_del_init(&req->intr_entry); in queue_interrupt()
354 spin_unlock(&fiq->lock); in queue_interrupt()
357 fiq->ops->wake_interrupt_and_unlock(fiq); in queue_interrupt()
359 spin_unlock(&fiq->lock); in queue_interrupt()
366 struct fuse_conn *fc = req->fm->fc; in request_wait_answer()
367 struct fuse_iqueue *fiq = &fc->iq; in request_wait_answer() local
370 if (!fc->no_interrupt) { in request_wait_answer()
372 err = wait_event_interruptible(req->waitq, in request_wait_answer()
373 test_bit(FR_FINISHED, &req->flags)); in request_wait_answer()
377 set_bit(FR_INTERRUPTED, &req->flags); in request_wait_answer()
380 if (test_bit(FR_SENT, &req->flags)) in request_wait_answer()
384 if (!test_bit(FR_FORCE, &req->flags)) { in request_wait_answer()
386 err = wait_event_killable(req->waitq, in request_wait_answer()
387 test_bit(FR_FINISHED, &req->flags)); in request_wait_answer()
391 spin_lock(&fiq->lock); in request_wait_answer()
393 if (test_bit(FR_PENDING, &req->flags)) { in request_wait_answer()
394 list_del(&req->list); in request_wait_answer()
395 spin_unlock(&fiq->lock); in request_wait_answer()
397 req->out.h.error = -EINTR; in request_wait_answer()
400 spin_unlock(&fiq->lock); in request_wait_answer()
407 wait_event(req->waitq, test_bit(FR_FINISHED, &req->flags)); in request_wait_answer()
412 struct fuse_iqueue *fiq = &req->fm->fc->iq; in __fuse_request_send() local
414 BUG_ON(test_bit(FR_BACKGROUND, &req->flags)); in __fuse_request_send()
415 spin_lock(&fiq->lock); in __fuse_request_send()
416 if (!fiq->connected) { in __fuse_request_send()
417 spin_unlock(&fiq->lock); in __fuse_request_send()
418 req->out.h.error = -ENOTCONN; in __fuse_request_send()
420 req->in.h.unique = fuse_get_unique(fiq); in __fuse_request_send()
424 queue_request_and_unlock(fiq, req); in __fuse_request_send()
434 if (fc->minor < 4 && args->opcode == FUSE_STATFS) in fuse_adjust_compat()
435 args->out_args[0].size = FUSE_COMPAT_STATFS_SIZE; in fuse_adjust_compat()
437 if (fc->minor < 9) { in fuse_adjust_compat()
438 switch (args->opcode) { in fuse_adjust_compat()
445 args->out_args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE; in fuse_adjust_compat()
449 args->out_args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE; in fuse_adjust_compat()
453 if (fc->minor < 12) { in fuse_adjust_compat()
454 switch (args->opcode) { in fuse_adjust_compat()
456 args->in_args[0].size = sizeof(struct fuse_open_in); in fuse_adjust_compat()
459 args->in_args[0].size = FUSE_COMPAT_MKNOD_IN_SIZE; in fuse_adjust_compat()
467 struct fuse_conn *fc = req->fm->fc; in fuse_force_creds()
469 req->in.h.uid = from_kuid_munged(fc->user_ns, current_fsuid()); in fuse_force_creds()
470 req->in.h.gid = from_kgid_munged(fc->user_ns, current_fsgid()); in fuse_force_creds()
471 req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns); in fuse_force_creds()
476 req->in.h.opcode = args->opcode; in fuse_args_to_req()
477 req->in.h.nodeid = args->nodeid; in fuse_args_to_req()
478 req->args = args; in fuse_args_to_req()
479 if (args->end) in fuse_args_to_req()
480 __set_bit(FR_ASYNC, &req->flags); in fuse_args_to_req()
485 struct fuse_conn *fc = fm->fc; in fuse_simple_request()
489 if (args->force) { in fuse_simple_request()
490 atomic_inc(&fc->num_waiting); in fuse_simple_request()
493 if (!args->nocreds) in fuse_simple_request()
496 __set_bit(FR_WAITING, &req->flags); in fuse_simple_request()
497 __set_bit(FR_FORCE, &req->flags); in fuse_simple_request()
499 WARN_ON(args->nocreds); in fuse_simple_request()
505 /* Needs to be done after fuse_get_req() so that fc->minor is valid */ in fuse_simple_request()
509 if (!args->noreply) in fuse_simple_request()
510 __set_bit(FR_ISREPLY, &req->flags); in fuse_simple_request()
512 ret = req->out.h.error; in fuse_simple_request()
513 if (!ret && args->out_argvar) { in fuse_simple_request()
514 BUG_ON(args->out_numargs == 0); in fuse_simple_request()
515 ret = args->out_args[args->out_numargs - 1].size; in fuse_simple_request()
524 struct fuse_mount *fm = req->fm; in fuse_request_queue_background()
525 struct fuse_conn *fc = fm->fc; in fuse_request_queue_background()
528 WARN_ON(!test_bit(FR_BACKGROUND, &req->flags)); in fuse_request_queue_background()
529 if (!test_bit(FR_WAITING, &req->flags)) { in fuse_request_queue_background()
530 __set_bit(FR_WAITING, &req->flags); in fuse_request_queue_background()
531 atomic_inc(&fc->num_waiting); in fuse_request_queue_background()
533 __set_bit(FR_ISREPLY, &req->flags); in fuse_request_queue_background()
534 spin_lock(&fc->bg_lock); in fuse_request_queue_background()
535 if (likely(fc->connected)) { in fuse_request_queue_background()
536 fc->num_background++; in fuse_request_queue_background()
537 if (fc->num_background == fc->max_background) in fuse_request_queue_background()
538 fc->blocked = 1; in fuse_request_queue_background()
539 list_add_tail(&req->list, &fc->bg_queue); in fuse_request_queue_background()
543 spin_unlock(&fc->bg_lock); in fuse_request_queue_background()
553 if (args->force) { in fuse_simple_background()
554 WARN_ON(!args->nocreds); in fuse_simple_background()
557 return -ENOMEM; in fuse_simple_background()
558 __set_bit(FR_BACKGROUND, &req->flags); in fuse_simple_background()
560 WARN_ON(args->nocreds); in fuse_simple_background()
570 return -ENOTCONN; in fuse_simple_background()
581 struct fuse_iqueue *fiq = &fm->fc->iq; in fuse_simple_notify_reply() local
588 __clear_bit(FR_ISREPLY, &req->flags); in fuse_simple_notify_reply()
589 req->in.h.unique = unique; in fuse_simple_notify_reply()
593 spin_lock(&fiq->lock); in fuse_simple_notify_reply()
594 if (fiq->connected) { in fuse_simple_notify_reply()
595 queue_request_and_unlock(fiq, req); in fuse_simple_notify_reply()
597 err = -ENODEV; in fuse_simple_notify_reply()
598 spin_unlock(&fiq->lock); in fuse_simple_notify_reply()
607 * anything that could cause a page-fault. If the request was already
614 spin_lock(&req->waitq.lock); in lock_request()
615 if (test_bit(FR_ABORTED, &req->flags)) in lock_request()
616 err = -ENOENT; in lock_request()
618 set_bit(FR_LOCKED, &req->flags); in lock_request()
619 spin_unlock(&req->waitq.lock); in lock_request()
632 spin_lock(&req->waitq.lock); in unlock_request()
633 if (test_bit(FR_ABORTED, &req->flags)) in unlock_request()
634 err = -ENOENT; in unlock_request()
636 clear_bit(FR_LOCKED, &req->flags); in unlock_request()
637 spin_unlock(&req->waitq.lock); in unlock_request()
660 cs->write = write; in fuse_copy_init()
661 cs->iter = iter; in fuse_copy_init()
667 if (cs->currbuf) { in fuse_copy_finish()
668 struct pipe_buffer *buf = cs->currbuf; in fuse_copy_finish()
670 if (cs->write) in fuse_copy_finish()
671 buf->len = PAGE_SIZE - cs->len; in fuse_copy_finish()
672 cs->currbuf = NULL; in fuse_copy_finish()
673 } else if (cs->pg) { in fuse_copy_finish()
674 if (cs->write) { in fuse_copy_finish()
675 flush_dcache_page(cs->pg); in fuse_copy_finish()
676 set_page_dirty_lock(cs->pg); in fuse_copy_finish()
678 put_page(cs->pg); in fuse_copy_finish()
680 cs->pg = NULL; in fuse_copy_finish()
692 err = unlock_request(cs->req); in fuse_copy_fill()
697 if (cs->pipebufs) { in fuse_copy_fill()
698 struct pipe_buffer *buf = cs->pipebufs; in fuse_copy_fill()
700 if (!cs->write) { in fuse_copy_fill()
701 err = pipe_buf_confirm(cs->pipe, buf); in fuse_copy_fill()
705 BUG_ON(!cs->nr_segs); in fuse_copy_fill()
706 cs->currbuf = buf; in fuse_copy_fill()
707 cs->pg = buf->page; in fuse_copy_fill()
708 cs->offset = buf->offset; in fuse_copy_fill()
709 cs->len = buf->len; in fuse_copy_fill()
710 cs->pipebufs++; in fuse_copy_fill()
711 cs->nr_segs--; in fuse_copy_fill()
713 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_copy_fill()
714 return -EIO; in fuse_copy_fill()
718 return -ENOMEM; in fuse_copy_fill()
720 buf->page = page; in fuse_copy_fill()
721 buf->offset = 0; in fuse_copy_fill()
722 buf->len = 0; in fuse_copy_fill()
724 cs->currbuf = buf; in fuse_copy_fill()
725 cs->pg = page; in fuse_copy_fill()
726 cs->offset = 0; in fuse_copy_fill()
727 cs->len = PAGE_SIZE; in fuse_copy_fill()
728 cs->pipebufs++; in fuse_copy_fill()
729 cs->nr_segs++; in fuse_copy_fill()
733 err = iov_iter_get_pages2(cs->iter, &page, PAGE_SIZE, 1, &off); in fuse_copy_fill()
737 cs->len = err; in fuse_copy_fill()
738 cs->offset = off; in fuse_copy_fill()
739 cs->pg = page; in fuse_copy_fill()
742 return lock_request(cs->req); in fuse_copy_fill()
748 unsigned ncpy = min(*size, cs->len); in fuse_copy_do()
750 void *pgaddr = kmap_local_page(cs->pg); in fuse_copy_do()
751 void *buf = pgaddr + cs->offset; in fuse_copy_do()
753 if (cs->write) in fuse_copy_do()
761 *size -= ncpy; in fuse_copy_do()
762 cs->len -= ncpy; in fuse_copy_do()
763 cs->offset += ncpy; in fuse_copy_do()
770 page->mapping != NULL || in fuse_check_page()
771 (page->flags & PAGE_FLAGS_CHECK_AT_PREP & in fuse_check_page()
792 struct pipe_buffer *buf = cs->pipebufs; in fuse_try_move_page()
795 err = unlock_request(cs->req); in fuse_try_move_page()
801 err = pipe_buf_confirm(cs->pipe, buf); in fuse_try_move_page()
805 BUG_ON(!cs->nr_segs); in fuse_try_move_page()
806 cs->currbuf = buf; in fuse_try_move_page()
807 cs->len = buf->len; in fuse_try_move_page()
808 cs->pipebufs++; in fuse_try_move_page()
809 cs->nr_segs--; in fuse_try_move_page()
811 if (cs->len != PAGE_SIZE) in fuse_try_move_page()
814 if (!pipe_buf_try_steal(cs->pipe, buf)) in fuse_try_move_page()
817 newpage = buf->page; in fuse_try_move_page()
844 if (!(buf->flags & PIPE_BUF_FLAG_LRU)) in fuse_try_move_page()
851 pipe_buf_release(cs->pipe, buf); in fuse_try_move_page()
854 spin_lock(&cs->req->waitq.lock); in fuse_try_move_page()
855 if (test_bit(FR_ABORTED, &cs->req->flags)) in fuse_try_move_page()
856 err = -ENOENT; in fuse_try_move_page()
859 spin_unlock(&cs->req->waitq.lock); in fuse_try_move_page()
868 /* Drop ref for ap->pages[] array */ in fuse_try_move_page()
870 cs->len = 0; in fuse_try_move_page()
881 cs->pg = buf->page; in fuse_try_move_page()
882 cs->offset = buf->offset; in fuse_try_move_page()
884 err = lock_request(cs->req); in fuse_try_move_page()
897 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_ref_page()
898 return -EIO; in fuse_ref_page()
901 err = unlock_request(cs->req); in fuse_ref_page()
909 buf = cs->pipebufs; in fuse_ref_page()
910 buf->page = page; in fuse_ref_page()
911 buf->offset = offset; in fuse_ref_page()
912 buf->len = count; in fuse_ref_page()
914 cs->pipebufs++; in fuse_ref_page()
915 cs->nr_segs++; in fuse_ref_page()
916 cs->len = 0; in fuse_ref_page()
935 if (cs->write && cs->pipebufs && page) { in fuse_copy_page()
940 if (cs->req->args->user_pages) { in fuse_copy_page()
947 } else if (!cs->len) { in fuse_copy_page()
948 if (cs->move_pages && page && in fuse_copy_page()
967 if (page && !cs->write) in fuse_copy_page()
977 struct fuse_req *req = cs->req; in fuse_copy_pages()
978 struct fuse_args_pages *ap = container_of(req->args, typeof(*ap), args); in fuse_copy_pages()
981 for (i = 0; i < ap->num_pages && (nbytes || zeroing); i++) { in fuse_copy_pages()
983 unsigned int offset = ap->descs[i].offset; in fuse_copy_pages()
984 unsigned int count = min(nbytes, ap->descs[i].length); in fuse_copy_pages()
986 err = fuse_copy_page(cs, &ap->pages[i], offset, count, zeroing); in fuse_copy_pages()
990 nbytes -= count; in fuse_copy_pages()
999 if (!cs->len) { in fuse_copy_one()
1019 if (i == numargs - 1 && argpages) in fuse_copy_args()
1020 err = fuse_copy_pages(cs, arg->size, zeroing); in fuse_copy_args()
1022 err = fuse_copy_one(cs, arg->value, arg->size); in fuse_copy_args()
1027 static int forget_pending(struct fuse_iqueue *fiq) in forget_pending() argument
1029 return fiq->forget_list_head.next != NULL; in forget_pending()
1032 static int request_pending(struct fuse_iqueue *fiq) in request_pending() argument
1034 return !list_empty(&fiq->pending) || !list_empty(&fiq->interrupts) || in request_pending()
1035 forget_pending(fiq); in request_pending()
1044 * Called with fiq->lock held, releases it
1046 static int fuse_read_interrupt(struct fuse_iqueue *fiq, in fuse_read_interrupt() argument
1049 __releases(fiq->lock) in fuse_read_interrupt()
1056 list_del_init(&req->intr_entry); in fuse_read_interrupt()
1061 ih.unique = (req->in.h.unique | FUSE_INT_REQ_BIT); in fuse_read_interrupt()
1062 arg.unique = req->in.h.unique; in fuse_read_interrupt()
1064 spin_unlock(&fiq->lock); in fuse_read_interrupt()
1066 return -EINVAL; in fuse_read_interrupt()
1076 struct fuse_forget_link *fuse_dequeue_forget(struct fuse_iqueue *fiq, in fuse_dequeue_forget() argument
1080 struct fuse_forget_link *head = fiq->forget_list_head.next; in fuse_dequeue_forget()
1085 newhead = &(*newhead)->next; in fuse_dequeue_forget()
1087 fiq->forget_list_head.next = *newhead; in fuse_dequeue_forget()
1089 if (fiq->forget_list_head.next == NULL) in fuse_dequeue_forget()
1090 fiq->forget_list_tail = &fiq->forget_list_head; in fuse_dequeue_forget()
1099 static int fuse_read_single_forget(struct fuse_iqueue *fiq, in fuse_read_single_forget() argument
1102 __releases(fiq->lock) in fuse_read_single_forget()
1105 struct fuse_forget_link *forget = fuse_dequeue_forget(fiq, 1, NULL); in fuse_read_single_forget()
1107 .nlookup = forget->forget_one.nlookup, in fuse_read_single_forget()
1111 .nodeid = forget->forget_one.nodeid, in fuse_read_single_forget()
1112 .unique = fuse_get_unique(fiq), in fuse_read_single_forget()
1116 spin_unlock(&fiq->lock); in fuse_read_single_forget()
1119 return -EINVAL; in fuse_read_single_forget()
1132 static int fuse_read_batch_forget(struct fuse_iqueue *fiq, in fuse_read_batch_forget() argument
1134 __releases(fiq->lock) in fuse_read_batch_forget()
1143 .unique = fuse_get_unique(fiq), in fuse_read_batch_forget()
1148 spin_unlock(&fiq->lock); in fuse_read_batch_forget()
1149 return -EINVAL; in fuse_read_batch_forget()
1152 max_forgets = (nbytes - ih.len) / sizeof(struct fuse_forget_one); in fuse_read_batch_forget()
1153 head = fuse_dequeue_forget(fiq, max_forgets, &count); in fuse_read_batch_forget()
1154 spin_unlock(&fiq->lock); in fuse_read_batch_forget()
1166 err = fuse_copy_one(cs, &forget->forget_one, in fuse_read_batch_forget()
1167 sizeof(forget->forget_one)); in fuse_read_batch_forget()
1169 head = forget->next; in fuse_read_batch_forget()
1181 static int fuse_read_forget(struct fuse_conn *fc, struct fuse_iqueue *fiq, in fuse_read_forget() argument
1184 __releases(fiq->lock) in fuse_read_forget()
1186 if (fc->minor < 16 || fiq->forget_list_head.next->next == NULL) in fuse_read_forget()
1187 return fuse_read_single_forget(fiq, cs, nbytes); in fuse_read_forget()
1189 return fuse_read_batch_forget(fiq, cs, nbytes); in fuse_read_forget()
1205 struct fuse_conn *fc = fud->fc; in fuse_dev_do_read()
1206 struct fuse_iqueue *fiq = &fc->iq; in fuse_dev_do_read() local
1207 struct fuse_pqueue *fpq = &fud->pq; in fuse_dev_do_read()
1214 * Require sane minimum read buffer - that has capacity for fixed part in fuse_dev_do_read()
1228 fc->max_write)) in fuse_dev_do_read()
1229 return -EINVAL; in fuse_dev_do_read()
1233 spin_lock(&fiq->lock); in fuse_dev_do_read()
1234 if (!fiq->connected || request_pending(fiq)) in fuse_dev_do_read()
1236 spin_unlock(&fiq->lock); in fuse_dev_do_read()
1238 if (file->f_flags & O_NONBLOCK) in fuse_dev_do_read()
1239 return -EAGAIN; in fuse_dev_do_read()
1240 err = wait_event_interruptible_exclusive(fiq->waitq, in fuse_dev_do_read()
1241 !fiq->connected || request_pending(fiq)); in fuse_dev_do_read()
1246 if (!fiq->connected) { in fuse_dev_do_read()
1247 err = fc->aborted ? -ECONNABORTED : -ENODEV; in fuse_dev_do_read()
1251 if (!list_empty(&fiq->interrupts)) { in fuse_dev_do_read()
1252 req = list_entry(fiq->interrupts.next, struct fuse_req, in fuse_dev_do_read()
1254 return fuse_read_interrupt(fiq, cs, nbytes, req); in fuse_dev_do_read()
1257 if (forget_pending(fiq)) { in fuse_dev_do_read()
1258 if (list_empty(&fiq->pending) || fiq->forget_batch-- > 0) in fuse_dev_do_read()
1259 return fuse_read_forget(fc, fiq, cs, nbytes); in fuse_dev_do_read()
1261 if (fiq->forget_batch <= -8) in fuse_dev_do_read()
1262 fiq->forget_batch = 16; in fuse_dev_do_read()
1265 req = list_entry(fiq->pending.next, struct fuse_req, list); in fuse_dev_do_read()
1266 clear_bit(FR_PENDING, &req->flags); in fuse_dev_do_read()
1267 list_del_init(&req->list); in fuse_dev_do_read()
1268 spin_unlock(&fiq->lock); in fuse_dev_do_read()
1270 args = req->args; in fuse_dev_do_read()
1271 reqsize = req->in.h.len; in fuse_dev_do_read()
1275 req->out.h.error = -EIO; in fuse_dev_do_read()
1277 if (args->opcode == FUSE_SETXATTR) in fuse_dev_do_read()
1278 req->out.h.error = -E2BIG; in fuse_dev_do_read()
1282 spin_lock(&fpq->lock); in fuse_dev_do_read()
1284 * Must not put request on fpq->io queue after having been shut down by in fuse_dev_do_read()
1287 if (!fpq->connected) { in fuse_dev_do_read()
1288 req->out.h.error = err = -ECONNABORTED; in fuse_dev_do_read()
1292 list_add(&req->list, &fpq->io); in fuse_dev_do_read()
1293 spin_unlock(&fpq->lock); in fuse_dev_do_read()
1294 cs->req = req; in fuse_dev_do_read()
1295 err = fuse_copy_one(cs, &req->in.h, sizeof(req->in.h)); in fuse_dev_do_read()
1297 err = fuse_copy_args(cs, args->in_numargs, args->in_pages, in fuse_dev_do_read()
1298 (struct fuse_arg *) args->in_args, 0); in fuse_dev_do_read()
1300 spin_lock(&fpq->lock); in fuse_dev_do_read()
1301 clear_bit(FR_LOCKED, &req->flags); in fuse_dev_do_read()
1302 if (!fpq->connected) { in fuse_dev_do_read()
1303 err = fc->aborted ? -ECONNABORTED : -ENODEV; in fuse_dev_do_read()
1307 req->out.h.error = -EIO; in fuse_dev_do_read()
1310 if (!test_bit(FR_ISREPLY, &req->flags)) { in fuse_dev_do_read()
1314 hash = fuse_req_hash(req->in.h.unique); in fuse_dev_do_read()
1315 list_move_tail(&req->list, &fpq->processing[hash]); in fuse_dev_do_read()
1317 set_bit(FR_SENT, &req->flags); in fuse_dev_do_read()
1318 spin_unlock(&fpq->lock); in fuse_dev_do_read()
1321 if (test_bit(FR_INTERRUPTED, &req->flags)) in fuse_dev_do_read()
1328 if (!test_bit(FR_PRIVATE, &req->flags)) in fuse_dev_do_read()
1329 list_del_init(&req->list); in fuse_dev_do_read()
1330 spin_unlock(&fpq->lock); in fuse_dev_do_read()
1335 spin_unlock(&fiq->lock); in fuse_dev_do_read()
1346 file->private_data = NULL; in fuse_dev_open()
1353 struct file *file = iocb->ki_filp; in fuse_dev_read()
1357 return -EPERM; in fuse_dev_read()
1360 return -EINVAL; in fuse_dev_read()
1378 return -EPERM; in fuse_dev_splice_read()
1380 bufs = kvmalloc_array(pipe->max_usage, sizeof(struct pipe_buffer), in fuse_dev_splice_read()
1383 return -ENOMEM; in fuse_dev_splice_read()
1392 if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->max_usage) { in fuse_dev_splice_read()
1393 ret = -EIO; in fuse_dev_splice_read()
1399 * Need to be careful about this. Having buf->ops in module in fuse_dev_splice_read()
1422 int err = -EINVAL; in fuse_notify_poll()
1443 int err = -EINVAL; in fuse_notify_inval_inode()
1453 down_read(&fc->killsb); in fuse_notify_inval_inode()
1456 up_read(&fc->killsb); in fuse_notify_inval_inode()
1468 int err = -ENOMEM; in fuse_notify_inval_entry()
1476 err = -EINVAL; in fuse_notify_inval_entry()
1484 err = -ENAMETOOLONG; in fuse_notify_inval_entry()
1488 err = -EINVAL; in fuse_notify_inval_entry()
1500 down_read(&fc->killsb); in fuse_notify_inval_entry()
1502 up_read(&fc->killsb); in fuse_notify_inval_entry()
1516 int err = -ENOMEM; in fuse_notify_delete()
1524 err = -EINVAL; in fuse_notify_delete()
1532 err = -ENAMETOOLONG; in fuse_notify_delete()
1536 err = -EINVAL; in fuse_notify_delete()
1548 down_read(&fc->killsb); in fuse_notify_delete()
1550 up_read(&fc->killsb); in fuse_notify_delete()
1568 pgoff_t index; in fuse_notify_store() local
1574 err = -EINVAL; in fuse_notify_store()
1582 err = -EINVAL; in fuse_notify_store()
1583 if (size - sizeof(outarg) != outarg.size) in fuse_notify_store()
1588 down_read(&fc->killsb); in fuse_notify_store()
1590 err = -ENOENT; in fuse_notify_store()
1595 mapping = inode->i_mapping; in fuse_notify_store()
1596 index = outarg.offset >> PAGE_SHIFT; in fuse_notify_store()
1610 err = -ENOMEM; in fuse_notify_store()
1611 page = find_or_create_page(mapping, index, in fuse_notify_store()
1616 this_num = min_t(unsigned, num, PAGE_SIZE - offset); in fuse_notify_store()
1627 num -= this_num; in fuse_notify_store()
1629 index++; in fuse_notify_store()
1637 up_read(&fc->killsb); in fuse_notify_store()
1654 release_pages(ra->ap.pages, ra->ap.num_pages); in fuse_retrieve_end()
1662 struct address_space *mapping = inode->i_mapping; in fuse_retrieve()
1663 pgoff_t index; in fuse_retrieve() local
1669 struct fuse_conn *fc = fm->fc; in fuse_retrieve()
1675 offset = outarg->offset & ~PAGE_MASK; in fuse_retrieve()
1678 num = min(outarg->size, fc->max_write); in fuse_retrieve()
1679 if (outarg->offset > file_size) in fuse_retrieve()
1681 else if (outarg->offset + num > file_size) in fuse_retrieve()
1682 num = file_size - outarg->offset; in fuse_retrieve()
1684 num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; in fuse_retrieve()
1685 num_pages = min(num_pages, fc->max_pages); in fuse_retrieve()
1687 args_size += num_pages * (sizeof(ap->pages[0]) + sizeof(ap->descs[0])); in fuse_retrieve()
1691 return -ENOMEM; in fuse_retrieve()
1693 ap = &ra->ap; in fuse_retrieve()
1694 ap->pages = (void *) (ra + 1); in fuse_retrieve()
1695 ap->descs = (void *) (ap->pages + num_pages); in fuse_retrieve()
1697 args = &ap->args; in fuse_retrieve()
1698 args->nodeid = outarg->nodeid; in fuse_retrieve()
1699 args->opcode = FUSE_NOTIFY_REPLY; in fuse_retrieve()
1700 args->in_numargs = 2; in fuse_retrieve()
1701 args->in_pages = true; in fuse_retrieve()
1702 args->end = fuse_retrieve_end; in fuse_retrieve()
1704 index = outarg->offset >> PAGE_SHIFT; in fuse_retrieve()
1706 while (num && ap->num_pages < num_pages) { in fuse_retrieve()
1710 page = find_get_page(mapping, index); in fuse_retrieve()
1714 this_num = min_t(unsigned, num, PAGE_SIZE - offset); in fuse_retrieve()
1715 ap->pages[ap->num_pages] = page; in fuse_retrieve()
1716 ap->descs[ap->num_pages].offset = offset; in fuse_retrieve()
1717 ap->descs[ap->num_pages].length = this_num; in fuse_retrieve()
1718 ap->num_pages++; in fuse_retrieve()
1721 num -= this_num; in fuse_retrieve()
1723 index++; in fuse_retrieve()
1725 ra->inarg.offset = outarg->offset; in fuse_retrieve()
1726 ra->inarg.size = total_len; in fuse_retrieve()
1727 args->in_args[0].size = sizeof(ra->inarg); in fuse_retrieve()
1728 args->in_args[0].value = &ra->inarg; in fuse_retrieve()
1729 args->in_args[1].size = total_len; in fuse_retrieve()
1731 err = fuse_simple_notify_reply(fm, args, outarg->notify_unique); in fuse_retrieve()
1747 err = -EINVAL; in fuse_notify_retrieve()
1757 down_read(&fc->killsb); in fuse_notify_retrieve()
1758 err = -ENOENT; in fuse_notify_retrieve()
1766 up_read(&fc->killsb); in fuse_notify_retrieve()
1779 cs->move_pages = 0; in fuse_notify()
1802 return -EINVAL; in fuse_notify()
1812 list_for_each_entry(req, &fpq->processing[hash], list) { in request_find()
1813 if (req->in.h.unique == unique) in request_find()
1824 reqsize += fuse_len_args(args->out_numargs, args->out_args); in copy_out_args()
1826 if (reqsize < nbytes || (reqsize > nbytes && !args->out_argvar)) in copy_out_args()
1827 return -EINVAL; in copy_out_args()
1829 struct fuse_arg *lastarg = &args->out_args[args->out_numargs-1]; in copy_out_args()
1830 unsigned diffsize = reqsize - nbytes; in copy_out_args()
1832 if (diffsize > lastarg->size) in copy_out_args()
1833 return -EINVAL; in copy_out_args()
1834 lastarg->size -= diffsize; in copy_out_args()
1836 return fuse_copy_args(cs, args->out_numargs, args->out_pages, in copy_out_args()
1837 args->out_args, args->page_zeroing); in copy_out_args()
1851 struct fuse_conn *fc = fud->fc; in fuse_dev_do_write()
1852 struct fuse_pqueue *fpq = &fud->pq; in fuse_dev_do_write()
1856 err = -EINVAL; in fuse_dev_do_write()
1864 err = -EINVAL; in fuse_dev_do_write()
1873 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
1877 err = -EINVAL; in fuse_dev_do_write()
1878 if (oh.error <= -512 || oh.error > 0) in fuse_dev_do_write()
1881 spin_lock(&fpq->lock); in fuse_dev_do_write()
1883 if (fpq->connected) in fuse_dev_do_write()
1886 err = -ENOENT; in fuse_dev_do_write()
1888 spin_unlock(&fpq->lock); in fuse_dev_do_write()
1895 spin_unlock(&fpq->lock); in fuse_dev_do_write()
1899 err = -EINVAL; in fuse_dev_do_write()
1900 else if (oh.error == -ENOSYS) in fuse_dev_do_write()
1901 fc->no_interrupt = 1; in fuse_dev_do_write()
1902 else if (oh.error == -EAGAIN) in fuse_dev_do_write()
1910 clear_bit(FR_SENT, &req->flags); in fuse_dev_do_write()
1911 list_move(&req->list, &fpq->io); in fuse_dev_do_write()
1912 req->out.h = oh; in fuse_dev_do_write()
1913 set_bit(FR_LOCKED, &req->flags); in fuse_dev_do_write()
1914 spin_unlock(&fpq->lock); in fuse_dev_do_write()
1915 cs->req = req; in fuse_dev_do_write()
1916 if (!req->args->page_replace) in fuse_dev_do_write()
1917 cs->move_pages = 0; in fuse_dev_do_write()
1920 err = nbytes != sizeof(oh) ? -EINVAL : 0; in fuse_dev_do_write()
1922 err = copy_out_args(cs, req->args, nbytes); in fuse_dev_do_write()
1925 spin_lock(&fpq->lock); in fuse_dev_do_write()
1926 clear_bit(FR_LOCKED, &req->flags); in fuse_dev_do_write()
1927 if (!fpq->connected) in fuse_dev_do_write()
1928 err = -ENOENT; in fuse_dev_do_write()
1930 req->out.h.error = -EIO; in fuse_dev_do_write()
1931 if (!test_bit(FR_PRIVATE, &req->flags)) in fuse_dev_do_write()
1932 list_del_init(&req->list); in fuse_dev_do_write()
1933 spin_unlock(&fpq->lock); in fuse_dev_do_write()
1947 struct fuse_dev *fud = fuse_get_dev(iocb->ki_filp); in fuse_dev_write()
1950 return -EPERM; in fuse_dev_write()
1953 return -EINVAL; in fuse_dev_write()
1975 return -EPERM; in fuse_dev_splice_write()
1979 head = pipe->head; in fuse_dev_splice_write()
1980 tail = pipe->tail; in fuse_dev_splice_write()
1981 mask = pipe->ring_size - 1; in fuse_dev_splice_write()
1982 count = head - tail; in fuse_dev_splice_write()
1987 return -ENOMEM; in fuse_dev_splice_write()
1993 rem += pipe->bufs[idx & mask].len; in fuse_dev_splice_write()
1995 ret = -EINVAL; in fuse_dev_splice_write()
2007 ibuf = &pipe->bufs[tail & mask]; in fuse_dev_splice_write()
2010 if (rem >= ibuf->len) { in fuse_dev_splice_write()
2012 ibuf->ops = NULL; in fuse_dev_splice_write()
2014 pipe->tail = tail; in fuse_dev_splice_write()
2020 obuf->flags &= ~PIPE_BUF_FLAG_GIFT; in fuse_dev_splice_write()
2021 obuf->len = rem; in fuse_dev_splice_write()
2022 ibuf->offset += obuf->len; in fuse_dev_splice_write()
2023 ibuf->len -= obuf->len; in fuse_dev_splice_write()
2026 rem -= obuf->len; in fuse_dev_splice_write()
2045 if (buf->ops) in fuse_dev_splice_write()
2057 struct fuse_iqueue *fiq; in fuse_dev_poll() local
2063 fiq = &fud->fc->iq; in fuse_dev_poll()
2064 poll_wait(file, &fiq->waitq, wait); in fuse_dev_poll()
2066 spin_lock(&fiq->lock); in fuse_dev_poll()
2067 if (!fiq->connected) in fuse_dev_poll()
2069 else if (request_pending(fiq)) in fuse_dev_poll()
2071 spin_unlock(&fiq->lock); in fuse_dev_poll()
2081 req = list_entry(head->next, struct fuse_req, list); in end_requests()
2082 req->out.h.error = -ECONNABORTED; in end_requests()
2083 clear_bit(FR_SENT, &req->flags); in end_requests()
2084 list_del_init(&req->list); in end_requests()
2093 p = rb_first(&fc->polled_files); in end_polls()
2098 wake_up_interruptible_all(&ff->poll_wait); in end_polls()
2124 struct fuse_iqueue *fiq = &fc->iq; in fuse_abort_conn() local
2126 spin_lock(&fc->lock); in fuse_abort_conn()
2127 if (fc->connected) { in fuse_abort_conn()
2133 /* Background queuing checks fc->connected under bg_lock */ in fuse_abort_conn()
2134 spin_lock(&fc->bg_lock); in fuse_abort_conn()
2135 fc->connected = 0; in fuse_abort_conn()
2136 spin_unlock(&fc->bg_lock); in fuse_abort_conn()
2139 list_for_each_entry(fud, &fc->devices, entry) { in fuse_abort_conn()
2140 struct fuse_pqueue *fpq = &fud->pq; in fuse_abort_conn()
2142 spin_lock(&fpq->lock); in fuse_abort_conn()
2143 fpq->connected = 0; in fuse_abort_conn()
2144 list_for_each_entry_safe(req, next, &fpq->io, list) { in fuse_abort_conn()
2145 req->out.h.error = -ECONNABORTED; in fuse_abort_conn()
2146 spin_lock(&req->waitq.lock); in fuse_abort_conn()
2147 set_bit(FR_ABORTED, &req->flags); in fuse_abort_conn()
2148 if (!test_bit(FR_LOCKED, &req->flags)) { in fuse_abort_conn()
2149 set_bit(FR_PRIVATE, &req->flags); in fuse_abort_conn()
2151 list_move(&req->list, &to_end); in fuse_abort_conn()
2153 spin_unlock(&req->waitq.lock); in fuse_abort_conn()
2156 list_splice_tail_init(&fpq->processing[i], in fuse_abort_conn()
2158 spin_unlock(&fpq->lock); in fuse_abort_conn()
2160 spin_lock(&fc->bg_lock); in fuse_abort_conn()
2161 fc->blocked = 0; in fuse_abort_conn()
2162 fc->max_background = UINT_MAX; in fuse_abort_conn()
2164 spin_unlock(&fc->bg_lock); in fuse_abort_conn()
2166 spin_lock(&fiq->lock); in fuse_abort_conn()
2167 fiq->connected = 0; in fuse_abort_conn()
2168 list_for_each_entry(req, &fiq->pending, list) in fuse_abort_conn()
2169 clear_bit(FR_PENDING, &req->flags); in fuse_abort_conn()
2170 list_splice_tail_init(&fiq->pending, &to_end); in fuse_abort_conn()
2171 while (forget_pending(fiq)) in fuse_abort_conn()
2172 kfree(fuse_dequeue_forget(fiq, 1, NULL)); in fuse_abort_conn()
2173 wake_up_all(&fiq->waitq); in fuse_abort_conn()
2174 spin_unlock(&fiq->lock); in fuse_abort_conn()
2175 kill_fasync(&fiq->fasync, SIGIO, POLL_IN); in fuse_abort_conn()
2177 wake_up_all(&fc->blocked_waitq); in fuse_abort_conn()
2178 spin_unlock(&fc->lock); in fuse_abort_conn()
2182 spin_unlock(&fc->lock); in fuse_abort_conn()
2191 wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0); in fuse_wait_aborted()
2199 struct fuse_conn *fc = fud->fc; in fuse_dev_release()
2200 struct fuse_pqueue *fpq = &fud->pq; in fuse_dev_release()
2204 spin_lock(&fpq->lock); in fuse_dev_release()
2205 WARN_ON(!list_empty(&fpq->io)); in fuse_dev_release()
2207 list_splice_init(&fpq->processing[i], &to_end); in fuse_dev_release()
2208 spin_unlock(&fpq->lock); in fuse_dev_release()
2213 if (atomic_dec_and_test(&fc->dev_count)) { in fuse_dev_release()
2214 WARN_ON(fc->iq.fasync != NULL); in fuse_dev_release()
2228 return -EPERM; in fuse_dev_fasync()
2230 /* No locking - fasync_helper does its own locking */ in fuse_dev_fasync()
2231 return fasync_helper(fd, file, on, &fud->fc->iq.fasync); in fuse_dev_fasync()
2238 if (new->private_data) in fuse_device_clone()
2239 return -EINVAL; in fuse_device_clone()
2243 return -ENOMEM; in fuse_device_clone()
2245 new->private_data = fud; in fuse_device_clone()
2246 atomic_inc(&fc->dev_count); in fuse_device_clone()
2260 res = -EFAULT; in fuse_dev_ioctl()
2264 res = -EINVAL; in fuse_dev_ioctl()
2267 * Check against file->f_op because CUSE in fuse_dev_ioctl()
2270 if (old->f_op == file->f_op && in fuse_dev_ioctl()
2271 old->f_cred->user_ns == file->f_cred->user_ns) in fuse_dev_ioctl()
2276 res = fuse_device_clone(fud->fc, file); in fuse_dev_ioctl()
2284 res = -ENOTTY; in fuse_dev_ioctl()
2314 int err = -ENOMEM; in fuse_dev_init()