Lines Matching refs:cs
656 static void fuse_copy_init(struct fuse_copy_state *cs, int write, in fuse_copy_init() argument
659 memset(cs, 0, sizeof(*cs)); in fuse_copy_init()
660 cs->write = write; in fuse_copy_init()
661 cs->iter = iter; in fuse_copy_init()
665 static void fuse_copy_finish(struct fuse_copy_state *cs) in fuse_copy_finish() argument
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()
687 static int fuse_copy_fill(struct fuse_copy_state *cs) in fuse_copy_fill() argument
692 err = unlock_request(cs->req); in fuse_copy_fill()
696 fuse_copy_finish(cs); 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()
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()
746 static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size) in fuse_copy_do() argument
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()
762 cs->len -= ncpy; in fuse_copy_do()
763 cs->offset += ncpy; in fuse_copy_do()
787 static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) in fuse_try_move_page() argument
792 struct pipe_buffer *buf = cs->pipebufs; in fuse_try_move_page()
795 err = unlock_request(cs->req); in fuse_try_move_page()
799 fuse_copy_finish(cs); 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()
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()
859 spin_unlock(&cs->req->waitq.lock); 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()
891 static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, in fuse_ref_page() argument
897 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_ref_page()
901 err = unlock_request(cs->req); in fuse_ref_page()
907 fuse_copy_finish(cs); in fuse_ref_page()
909 buf = cs->pipebufs; 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()
925 static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep, in fuse_copy_page() argument
935 if (cs->write && cs->pipebufs && page) { in fuse_copy_page()
940 if (cs->req->args->user_pages) { in fuse_copy_page()
941 err = fuse_copy_fill(cs); in fuse_copy_page()
945 return fuse_ref_page(cs, page, offset, count); in fuse_copy_page()
947 } else if (!cs->len) { in fuse_copy_page()
948 if (cs->move_pages && page && in fuse_copy_page()
950 err = fuse_try_move_page(cs, pagep); in fuse_copy_page()
954 err = fuse_copy_fill(cs); in fuse_copy_page()
962 offset += fuse_copy_do(cs, &buf, &count); in fuse_copy_page()
965 offset += fuse_copy_do(cs, NULL, &count); in fuse_copy_page()
967 if (page && !cs->write) in fuse_copy_page()
973 static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes, in fuse_copy_pages() argument
977 struct fuse_req *req = cs->req; in fuse_copy_pages()
986 err = fuse_copy_page(cs, &ap->pages[i], offset, count, zeroing); in fuse_copy_pages()
996 static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size) in fuse_copy_one() argument
999 if (!cs->len) { in fuse_copy_one()
1000 int err = fuse_copy_fill(cs); in fuse_copy_one()
1004 fuse_copy_do(cs, &val, &size); in fuse_copy_one()
1010 static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs, in fuse_copy_args() argument
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()
1047 struct fuse_copy_state *cs, in fuse_read_interrupt() argument
1068 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_interrupt()
1070 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_interrupt()
1071 fuse_copy_finish(cs); in fuse_read_interrupt()
1100 struct fuse_copy_state *cs, in fuse_read_single_forget() argument
1121 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_single_forget()
1123 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_single_forget()
1124 fuse_copy_finish(cs); in fuse_read_single_forget()
1133 struct fuse_copy_state *cs, size_t nbytes) in fuse_read_batch_forget() argument
1158 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_batch_forget()
1160 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_batch_forget()
1166 err = fuse_copy_one(cs, &forget->forget_one, in fuse_read_batch_forget()
1173 fuse_copy_finish(cs); in fuse_read_batch_forget()
1182 struct fuse_copy_state *cs, in fuse_read_forget() argument
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()
1202 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_read() argument
1254 return fuse_read_interrupt(fiq, cs, nbytes, req); in fuse_dev_do_read()
1259 return fuse_read_forget(fc, fiq, cs, nbytes); 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()
1299 fuse_copy_finish(cs); in fuse_dev_do_read()
1352 struct fuse_copy_state cs; in fuse_dev_read() local
1362 fuse_copy_init(&cs, 1, to); in fuse_dev_read()
1364 return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to)); in fuse_dev_read()
1374 struct fuse_copy_state cs; in fuse_dev_splice_read() local
1385 fuse_copy_init(&cs, 1, NULL); in fuse_dev_splice_read()
1386 cs.pipebufs = bufs; in fuse_dev_splice_read()
1387 cs.pipe = pipe; in fuse_dev_splice_read()
1388 ret = fuse_dev_do_read(fud, in, &cs, len); in fuse_dev_splice_read()
1392 if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->max_usage) { in fuse_dev_splice_read()
1397 for (ret = total = 0; page_nr < cs.nr_segs; total += ret) { in fuse_dev_splice_read()
1411 for (; page_nr < cs.nr_segs; page_nr++) in fuse_dev_splice_read()
1419 struct fuse_copy_state *cs) in fuse_notify_poll() argument
1427 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_poll()
1431 fuse_copy_finish(cs); in fuse_notify_poll()
1435 fuse_copy_finish(cs); in fuse_notify_poll()
1440 struct fuse_copy_state *cs) in fuse_notify_inval_inode() argument
1448 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_inode()
1451 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1460 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1465 struct fuse_copy_state *cs) in fuse_notify_inval_entry() argument
1480 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_entry()
1494 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_inval_entry()
1497 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1508 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1513 struct fuse_copy_state *cs) in fuse_notify_delete() argument
1528 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_delete()
1542 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_delete()
1545 fuse_copy_finish(cs); in fuse_notify_delete()
1556 fuse_copy_finish(cs); in fuse_notify_delete()
1561 struct fuse_copy_state *cs) in fuse_notify_store() argument
1578 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_store()
1617 err = fuse_copy_page(cs, &page, offset, this_num, 0); in fuse_notify_store()
1639 fuse_copy_finish(cs); in fuse_notify_store()
1739 struct fuse_copy_state *cs) in fuse_notify_retrieve() argument
1751 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_retrieve()
1755 fuse_copy_finish(cs); in fuse_notify_retrieve()
1771 fuse_copy_finish(cs); in fuse_notify_retrieve()
1776 unsigned int size, struct fuse_copy_state *cs) in fuse_notify() argument
1779 cs->move_pages = 0; in fuse_notify()
1783 return fuse_notify_poll(fc, size, cs); in fuse_notify()
1786 return fuse_notify_inval_inode(fc, size, cs); in fuse_notify()
1789 return fuse_notify_inval_entry(fc, size, cs); in fuse_notify()
1792 return fuse_notify_store(fc, size, cs); in fuse_notify()
1795 return fuse_notify_retrieve(fc, size, cs); in fuse_notify()
1798 return fuse_notify_delete(fc, size, cs); in fuse_notify()
1801 fuse_copy_finish(cs); in fuse_notify()
1819 static int copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args, in copy_out_args() argument
1836 return fuse_copy_args(cs, args->out_numargs, args->out_pages, in copy_out_args()
1848 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_write() argument
1860 err = fuse_copy_one(cs, &oh, sizeof(oh)); in fuse_dev_do_write()
1873 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
1915 cs->req = req; in fuse_dev_do_write()
1917 cs->move_pages = 0; in fuse_dev_do_write()
1922 err = copy_out_args(cs, req->args, nbytes); in fuse_dev_do_write()
1923 fuse_copy_finish(cs); in fuse_dev_do_write()
1940 fuse_copy_finish(cs); in fuse_dev_do_write()
1946 struct fuse_copy_state cs; in fuse_dev_write() local
1955 fuse_copy_init(&cs, 0, from); in fuse_dev_write()
1957 return fuse_dev_do_write(fud, &cs, iov_iter_count(from)); in fuse_dev_write()
1968 struct fuse_copy_state cs; in fuse_dev_splice_write() local
2030 fuse_copy_init(&cs, 0, NULL); in fuse_dev_splice_write()
2031 cs.pipebufs = bufs; in fuse_dev_splice_write()
2032 cs.nr_segs = nbuf; in fuse_dev_splice_write()
2033 cs.pipe = pipe; in fuse_dev_splice_write()
2036 cs.move_pages = 1; in fuse_dev_splice_write()
2038 ret = fuse_dev_do_write(fud, &cs, len); in fuse_dev_splice_write()