Lines Matching refs:fc

77 void fuse_set_initialized(struct fuse_conn *fc)  in fuse_set_initialized()  argument
81 fc->initialized = 1; in fuse_set_initialized()
84 static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background) in fuse_block_alloc() argument
86 return !fc->initialized || (for_background && fc->blocked); in fuse_block_alloc()
89 static void fuse_drop_waiting(struct fuse_conn *fc) in fuse_drop_waiting() argument
96 if (atomic_dec_and_test(&fc->num_waiting) && in fuse_drop_waiting()
97 !READ_ONCE(fc->connected)) { in fuse_drop_waiting()
99 wake_up_all(&fc->blocked_waitq); in fuse_drop_waiting()
103 static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
105 static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background) in fuse_get_req() argument
109 atomic_inc(&fc->num_waiting); in fuse_get_req()
111 if (fuse_block_alloc(fc, for_background)) { in fuse_get_req()
113 if (wait_event_killable_exclusive(fc->blocked_waitq, in fuse_get_req()
114 !fuse_block_alloc(fc, for_background))) in fuse_get_req()
121 if (!fc->connected) in fuse_get_req()
125 if (fc->conn_error) in fuse_get_req()
132 wake_up(&fc->blocked_waitq); in fuse_get_req()
136 req->in.h.uid = from_kuid(fc->user_ns, current_fsuid()); in fuse_get_req()
137 req->in.h.gid = from_kgid(fc->user_ns, current_fsgid()); in fuse_get_req()
138 req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns); in fuse_get_req()
146 fuse_put_request(fc, req); in fuse_get_req()
152 fuse_drop_waiting(fc); in fuse_get_req()
156 static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req) in fuse_put_request() argument
164 spin_lock(&fc->bg_lock); in fuse_put_request()
165 if (!fc->blocked) in fuse_put_request()
166 wake_up(&fc->blocked_waitq); in fuse_put_request()
167 spin_unlock(&fc->bg_lock); in fuse_put_request()
172 fuse_drop_waiting(fc); in fuse_put_request()
232 void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, in fuse_queue_forget() argument
235 struct fuse_iqueue *fiq = &fc->iq; in fuse_queue_forget()
251 static void flush_bg_queue(struct fuse_conn *fc) in flush_bg_queue() argument
253 struct fuse_iqueue *fiq = &fc->iq; in flush_bg_queue()
255 while (fc->active_background < fc->max_background && in flush_bg_queue()
256 !list_empty(&fc->bg_queue)) { in flush_bg_queue()
259 req = list_first_entry(&fc->bg_queue, struct fuse_req, list); in flush_bg_queue()
261 fc->active_background++; in flush_bg_queue()
276 void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req) in fuse_request_end() argument
278 struct fuse_iqueue *fiq = &fc->iq; in fuse_request_end()
298 spin_lock(&fc->bg_lock); in fuse_request_end()
300 if (fc->num_background == fc->max_background) { in fuse_request_end()
301 fc->blocked = 0; in fuse_request_end()
302 wake_up(&fc->blocked_waitq); in fuse_request_end()
303 } else if (!fc->blocked) { in fuse_request_end()
310 if (waitqueue_active(&fc->blocked_waitq)) in fuse_request_end()
311 wake_up(&fc->blocked_waitq); in fuse_request_end()
314 if (fc->num_background == fc->congestion_threshold && fc->sb) { in fuse_request_end()
315 clear_bdi_congested(fc->sb->s_bdi, BLK_RW_SYNC); in fuse_request_end()
316 clear_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC); in fuse_request_end()
318 fc->num_background--; in fuse_request_end()
319 fc->active_background--; in fuse_request_end()
320 flush_bg_queue(fc); in fuse_request_end()
321 spin_unlock(&fc->bg_lock); in fuse_request_end()
328 req->args->end(fc, req->args, req->out.h.error); in fuse_request_end()
330 fuse_put_request(fc, req); in fuse_request_end()
362 static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) in request_wait_answer() argument
364 struct fuse_iqueue *fiq = &fc->iq; in request_wait_answer()
367 if (!fc->no_interrupt) { in request_wait_answer()
407 static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req) in __fuse_request_send() argument
409 struct fuse_iqueue *fiq = &fc->iq; in __fuse_request_send()
423 request_wait_answer(fc, req); in __fuse_request_send()
429 static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args) in fuse_adjust_compat() argument
431 if (fc->minor < 4 && args->opcode == FUSE_STATFS) in fuse_adjust_compat()
434 if (fc->minor < 9) { in fuse_adjust_compat()
450 if (fc->minor < 12) { in fuse_adjust_compat()
462 static void fuse_force_creds(struct fuse_conn *fc, struct fuse_req *req) in fuse_force_creds() argument
464 req->in.h.uid = from_kuid_munged(fc->user_ns, current_fsuid()); in fuse_force_creds()
465 req->in.h.gid = from_kgid_munged(fc->user_ns, current_fsgid()); in fuse_force_creds()
466 req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns); in fuse_force_creds()
476 ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args) in fuse_simple_request() argument
482 atomic_inc(&fc->num_waiting); in fuse_simple_request()
486 fuse_force_creds(fc, req); in fuse_simple_request()
492 req = fuse_get_req(fc, false); in fuse_simple_request()
498 fuse_adjust_compat(fc, args); in fuse_simple_request()
503 __fuse_request_send(fc, req); in fuse_simple_request()
509 fuse_put_request(fc, req); in fuse_simple_request()
514 static bool fuse_request_queue_background(struct fuse_conn *fc, in fuse_request_queue_background() argument
522 atomic_inc(&fc->num_waiting); in fuse_request_queue_background()
525 spin_lock(&fc->bg_lock); in fuse_request_queue_background()
526 if (likely(fc->connected)) { in fuse_request_queue_background()
527 fc->num_background++; in fuse_request_queue_background()
528 if (fc->num_background == fc->max_background) in fuse_request_queue_background()
529 fc->blocked = 1; in fuse_request_queue_background()
530 if (fc->num_background == fc->congestion_threshold && fc->sb) { in fuse_request_queue_background()
531 set_bdi_congested(fc->sb->s_bdi, BLK_RW_SYNC); in fuse_request_queue_background()
532 set_bdi_congested(fc->sb->s_bdi, BLK_RW_ASYNC); in fuse_request_queue_background()
534 list_add_tail(&req->list, &fc->bg_queue); in fuse_request_queue_background()
535 flush_bg_queue(fc); in fuse_request_queue_background()
538 spin_unlock(&fc->bg_lock); in fuse_request_queue_background()
543 int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args, in fuse_simple_background() argument
556 req = fuse_get_req(fc, true); in fuse_simple_background()
563 if (!fuse_request_queue_background(fc, req)) { in fuse_simple_background()
564 fuse_put_request(fc, req); in fuse_simple_background()
572 static int fuse_simple_notify_reply(struct fuse_conn *fc, in fuse_simple_notify_reply() argument
576 struct fuse_iqueue *fiq = &fc->iq; in fuse_simple_notify_reply()
579 req = fuse_get_req(fc, false); in fuse_simple_notify_reply()
594 fuse_put_request(fc, req); in fuse_simple_notify_reply()
1156 static int fuse_read_forget(struct fuse_conn *fc, struct fuse_iqueue *fiq, in fuse_read_forget() argument
1161 if (fc->minor < 16 || fiq->forget_list_head.next->next == NULL) in fuse_read_forget()
1180 struct fuse_conn *fc = fud->fc; in fuse_dev_do_read() local
1181 struct fuse_iqueue *fiq = &fc->iq; in fuse_dev_do_read()
1203 fc->max_write)) in fuse_dev_do_read()
1222 err = fc->aborted ? -ECONNABORTED : -ENODEV; in fuse_dev_do_read()
1234 return fuse_read_forget(fc, fiq, cs, nbytes); in fuse_dev_do_read()
1254 fuse_request_end(fc, req); in fuse_dev_do_read()
1269 err = fc->aborted ? -ECONNABORTED : -ENODEV; in fuse_dev_do_read()
1289 fuse_put_request(fc, req); in fuse_dev_do_read()
1297 fuse_request_end(fc, req); in fuse_dev_do_read()
1384 static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size, in fuse_notify_poll() argument
1398 return fuse_notify_poll_wakeup(fc, &outarg); in fuse_notify_poll()
1405 static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size, in fuse_notify_inval_inode() argument
1419 down_read(&fc->killsb); in fuse_notify_inval_inode()
1421 if (fc->sb) { in fuse_notify_inval_inode()
1422 err = fuse_reverse_inval_inode(fc->sb, outarg.ino, in fuse_notify_inval_inode()
1425 up_read(&fc->killsb); in fuse_notify_inval_inode()
1433 static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size, in fuse_notify_inval_entry() argument
1469 down_read(&fc->killsb); in fuse_notify_inval_entry()
1471 if (fc->sb) in fuse_notify_inval_entry()
1472 err = fuse_reverse_inval_entry(fc->sb, outarg.parent, 0, &name); in fuse_notify_inval_entry()
1473 up_read(&fc->killsb); in fuse_notify_inval_entry()
1483 static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size, in fuse_notify_delete() argument
1519 down_read(&fc->killsb); in fuse_notify_delete()
1521 if (fc->sb) in fuse_notify_delete()
1522 err = fuse_reverse_inval_entry(fc->sb, outarg.parent, in fuse_notify_delete()
1524 up_read(&fc->killsb); in fuse_notify_delete()
1534 static int fuse_notify_store(struct fuse_conn *fc, unsigned int size, in fuse_notify_store() argument
1562 down_read(&fc->killsb); in fuse_notify_store()
1565 if (!fc->sb) in fuse_notify_store()
1568 inode = ilookup5(fc->sb, nodeid, fuse_inode_eq, &nodeid); in fuse_notify_store()
1614 up_read(&fc->killsb); in fuse_notify_store()
1625 static void fuse_retrieve_end(struct fuse_conn *fc, struct fuse_args *args, in fuse_retrieve_end() argument
1635 static int fuse_retrieve(struct fuse_conn *fc, struct inode *inode, in fuse_retrieve() argument
1654 num = min(outarg->size, fc->max_write); in fuse_retrieve()
1661 num_pages = min(num_pages, fc->max_pages); in fuse_retrieve()
1707 err = fuse_simple_notify_reply(fc, args, outarg->notify_unique); in fuse_retrieve()
1709 fuse_retrieve_end(fc, args, err); in fuse_retrieve()
1714 static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size, in fuse_notify_retrieve() argument
1731 down_read(&fc->killsb); in fuse_notify_retrieve()
1733 if (fc->sb) { in fuse_notify_retrieve()
1736 inode = ilookup5(fc->sb, nodeid, fuse_inode_eq, &nodeid); in fuse_notify_retrieve()
1738 err = fuse_retrieve(fc, inode, &outarg); in fuse_notify_retrieve()
1742 up_read(&fc->killsb); in fuse_notify_retrieve()
1751 static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code, in fuse_notify() argument
1759 return fuse_notify_poll(fc, size, cs); in fuse_notify()
1762 return fuse_notify_inval_inode(fc, size, cs); in fuse_notify()
1765 return fuse_notify_inval_entry(fc, size, cs); in fuse_notify()
1768 return fuse_notify_store(fc, size, cs); in fuse_notify()
1771 return fuse_notify_retrieve(fc, size, cs); in fuse_notify()
1774 return fuse_notify_delete(fc, size, cs); in fuse_notify()
1827 struct fuse_conn *fc = fud->fc; in fuse_dev_do_write() local
1849 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
1877 fc->no_interrupt = 1; in fuse_dev_do_write()
1879 err = queue_interrupt(&fc->iq, req); in fuse_dev_do_write()
1881 fuse_put_request(fc, req); in fuse_dev_do_write()
1911 fuse_request_end(fc, req); in fuse_dev_do_write()
2029 fiq = &fud->fc->iq; in fuse_dev_poll()
2043 static void end_requests(struct fuse_conn *fc, struct list_head *head) in end_requests() argument
2051 fuse_request_end(fc, req); in end_requests()
2055 static void end_polls(struct fuse_conn *fc) in end_polls() argument
2059 p = rb_first(&fc->polled_files); in end_polls()
2088 void fuse_abort_conn(struct fuse_conn *fc) in fuse_abort_conn() argument
2090 struct fuse_iqueue *fiq = &fc->iq; in fuse_abort_conn()
2092 spin_lock(&fc->lock); in fuse_abort_conn()
2093 if (fc->connected) { in fuse_abort_conn()
2100 spin_lock(&fc->bg_lock); in fuse_abort_conn()
2101 fc->connected = 0; in fuse_abort_conn()
2102 spin_unlock(&fc->bg_lock); in fuse_abort_conn()
2104 fuse_set_initialized(fc); in fuse_abort_conn()
2105 list_for_each_entry(fud, &fc->devices, entry) { in fuse_abort_conn()
2126 spin_lock(&fc->bg_lock); in fuse_abort_conn()
2127 fc->blocked = 0; in fuse_abort_conn()
2128 fc->max_background = UINT_MAX; in fuse_abort_conn()
2129 flush_bg_queue(fc); in fuse_abort_conn()
2130 spin_unlock(&fc->bg_lock); in fuse_abort_conn()
2142 end_polls(fc); in fuse_abort_conn()
2143 wake_up_all(&fc->blocked_waitq); in fuse_abort_conn()
2144 spin_unlock(&fc->lock); in fuse_abort_conn()
2146 end_requests(fc, &to_end); in fuse_abort_conn()
2148 spin_unlock(&fc->lock); in fuse_abort_conn()
2153 void fuse_wait_aborted(struct fuse_conn *fc) in fuse_wait_aborted() argument
2157 wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0); in fuse_wait_aborted()
2165 struct fuse_conn *fc = fud->fc; in fuse_dev_release() local
2176 end_requests(fc, &to_end); in fuse_dev_release()
2179 if (atomic_dec_and_test(&fc->dev_count)) { in fuse_dev_release()
2180 WARN_ON(fc->iq.fasync != NULL); in fuse_dev_release()
2181 fuse_abort_conn(fc); in fuse_dev_release()
2197 return fasync_helper(fd, file, on, &fud->fc->iq.fasync); in fuse_dev_fasync()
2200 static int fuse_device_clone(struct fuse_conn *fc, struct file *new) in fuse_device_clone() argument
2207 fud = fuse_dev_alloc_install(fc); in fuse_device_clone()
2212 atomic_inc(&fc->dev_count); in fuse_device_clone()
2243 err = fuse_device_clone(fud->fc, file); in fuse_dev_ioctl()