Lines Matching refs:cs
658 static void fuse_copy_init(struct fuse_copy_state *cs, int write, in fuse_copy_init() argument
661 memset(cs, 0, sizeof(*cs)); in fuse_copy_init()
662 cs->write = write; in fuse_copy_init()
663 cs->iter = iter; in fuse_copy_init()
667 static void fuse_copy_finish(struct fuse_copy_state *cs) in fuse_copy_finish() argument
669 if (cs->currbuf) { in fuse_copy_finish()
670 struct pipe_buffer *buf = cs->currbuf; in fuse_copy_finish()
672 if (cs->write) in fuse_copy_finish()
673 buf->len = PAGE_SIZE - cs->len; in fuse_copy_finish()
674 cs->currbuf = NULL; in fuse_copy_finish()
675 } else if (cs->pg) { in fuse_copy_finish()
676 if (cs->write) { in fuse_copy_finish()
677 flush_dcache_page(cs->pg); in fuse_copy_finish()
678 set_page_dirty_lock(cs->pg); in fuse_copy_finish()
680 put_page(cs->pg); in fuse_copy_finish()
682 cs->pg = NULL; in fuse_copy_finish()
689 static int fuse_copy_fill(struct fuse_copy_state *cs) in fuse_copy_fill() argument
694 err = unlock_request(cs->req); in fuse_copy_fill()
698 fuse_copy_finish(cs); in fuse_copy_fill()
699 if (cs->pipebufs) { in fuse_copy_fill()
700 struct pipe_buffer *buf = cs->pipebufs; in fuse_copy_fill()
702 if (!cs->write) { in fuse_copy_fill()
703 err = pipe_buf_confirm(cs->pipe, buf); in fuse_copy_fill()
707 BUG_ON(!cs->nr_segs); in fuse_copy_fill()
708 cs->currbuf = buf; in fuse_copy_fill()
709 cs->pg = buf->page; in fuse_copy_fill()
710 cs->offset = buf->offset; in fuse_copy_fill()
711 cs->len = buf->len; in fuse_copy_fill()
712 cs->pipebufs++; in fuse_copy_fill()
713 cs->nr_segs--; in fuse_copy_fill()
715 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_copy_fill()
726 cs->currbuf = buf; in fuse_copy_fill()
727 cs->pg = page; in fuse_copy_fill()
728 cs->offset = 0; in fuse_copy_fill()
729 cs->len = PAGE_SIZE; in fuse_copy_fill()
730 cs->pipebufs++; in fuse_copy_fill()
731 cs->nr_segs++; in fuse_copy_fill()
735 err = iov_iter_get_pages2(cs->iter, &page, PAGE_SIZE, 1, &off); in fuse_copy_fill()
739 cs->len = err; in fuse_copy_fill()
740 cs->offset = off; in fuse_copy_fill()
741 cs->pg = page; in fuse_copy_fill()
744 return lock_request(cs->req); in fuse_copy_fill()
748 static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size) in fuse_copy_do() argument
750 unsigned ncpy = min(*size, cs->len); in fuse_copy_do()
752 void *pgaddr = kmap_local_page(cs->pg); in fuse_copy_do()
753 void *buf = pgaddr + cs->offset; in fuse_copy_do()
755 if (cs->write) in fuse_copy_do()
764 cs->len -= ncpy; in fuse_copy_do()
765 cs->offset += ncpy; in fuse_copy_do()
789 static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) in fuse_try_move_page() argument
794 struct pipe_buffer *buf = cs->pipebufs; in fuse_try_move_page()
797 err = unlock_request(cs->req); in fuse_try_move_page()
801 fuse_copy_finish(cs); in fuse_try_move_page()
803 err = pipe_buf_confirm(cs->pipe, buf); in fuse_try_move_page()
807 BUG_ON(!cs->nr_segs); in fuse_try_move_page()
808 cs->currbuf = buf; in fuse_try_move_page()
809 cs->len = buf->len; in fuse_try_move_page()
810 cs->pipebufs++; in fuse_try_move_page()
811 cs->nr_segs--; in fuse_try_move_page()
813 if (cs->len != PAGE_SIZE) in fuse_try_move_page()
816 if (!pipe_buf_try_steal(cs->pipe, buf)) in fuse_try_move_page()
854 pipe_buf_release(cs->pipe, buf); in fuse_try_move_page()
857 spin_lock(&cs->req->waitq.lock); in fuse_try_move_page()
858 if (test_bit(FR_ABORTED, &cs->req->flags)) in fuse_try_move_page()
862 spin_unlock(&cs->req->waitq.lock); in fuse_try_move_page()
873 cs->len = 0; in fuse_try_move_page()
884 cs->pg = buf->page; in fuse_try_move_page()
885 cs->offset = buf->offset; in fuse_try_move_page()
887 err = lock_request(cs->req); in fuse_try_move_page()
894 static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, in fuse_ref_page() argument
900 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_ref_page()
904 err = unlock_request(cs->req); in fuse_ref_page()
910 fuse_copy_finish(cs); in fuse_ref_page()
912 buf = cs->pipebufs; in fuse_ref_page()
917 cs->pipebufs++; in fuse_ref_page()
918 cs->nr_segs++; in fuse_ref_page()
919 cs->len = 0; in fuse_ref_page()
928 static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep, in fuse_copy_page() argument
938 if (cs->write && cs->pipebufs && page) { in fuse_copy_page()
943 if (cs->req->args->user_pages) { in fuse_copy_page()
944 err = fuse_copy_fill(cs); in fuse_copy_page()
948 return fuse_ref_page(cs, page, offset, count); in fuse_copy_page()
950 } else if (!cs->len) { in fuse_copy_page()
951 if (cs->move_pages && page && in fuse_copy_page()
953 err = fuse_try_move_page(cs, pagep); in fuse_copy_page()
957 err = fuse_copy_fill(cs); in fuse_copy_page()
965 offset += fuse_copy_do(cs, &buf, &count); in fuse_copy_page()
968 offset += fuse_copy_do(cs, NULL, &count); in fuse_copy_page()
970 if (page && !cs->write) in fuse_copy_page()
976 static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes, in fuse_copy_pages() argument
980 struct fuse_req *req = cs->req; in fuse_copy_pages()
989 err = fuse_copy_page(cs, &ap->pages[i], offset, count, zeroing); in fuse_copy_pages()
999 static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size) in fuse_copy_one() argument
1002 if (!cs->len) { in fuse_copy_one()
1003 int err = fuse_copy_fill(cs); in fuse_copy_one()
1007 fuse_copy_do(cs, &val, &size); in fuse_copy_one()
1013 static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs, in fuse_copy_args() argument
1023 err = fuse_copy_pages(cs, arg->size, zeroing); in fuse_copy_args()
1025 err = fuse_copy_one(cs, arg->value, arg->size); in fuse_copy_args()
1050 struct fuse_copy_state *cs, in fuse_read_interrupt() argument
1071 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_interrupt()
1073 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_interrupt()
1074 fuse_copy_finish(cs); in fuse_read_interrupt()
1103 struct fuse_copy_state *cs, in fuse_read_single_forget() argument
1124 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_single_forget()
1126 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_single_forget()
1127 fuse_copy_finish(cs); in fuse_read_single_forget()
1136 struct fuse_copy_state *cs, size_t nbytes) in fuse_read_batch_forget() argument
1161 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_batch_forget()
1163 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_batch_forget()
1169 err = fuse_copy_one(cs, &forget->forget_one, in fuse_read_batch_forget()
1176 fuse_copy_finish(cs); in fuse_read_batch_forget()
1185 struct fuse_copy_state *cs, in fuse_read_forget() argument
1190 return fuse_read_single_forget(fiq, cs, nbytes); in fuse_read_forget()
1192 return fuse_read_batch_forget(fiq, cs, nbytes); in fuse_read_forget()
1205 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_read() argument
1257 return fuse_read_interrupt(fiq, cs, nbytes, req); in fuse_dev_do_read()
1262 return fuse_read_forget(fc, fiq, cs, nbytes); in fuse_dev_do_read()
1297 cs->req = req; in fuse_dev_do_read()
1298 err = fuse_copy_one(cs, &req->in.h, sizeof(req->in.h)); in fuse_dev_do_read()
1300 err = fuse_copy_args(cs, args->in_numargs, args->in_pages, in fuse_dev_do_read()
1302 fuse_copy_finish(cs); in fuse_dev_do_read()
1355 struct fuse_copy_state cs; in fuse_dev_read() local
1365 fuse_copy_init(&cs, 1, to); in fuse_dev_read()
1367 return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to)); in fuse_dev_read()
1377 struct fuse_copy_state cs; in fuse_dev_splice_read() local
1388 fuse_copy_init(&cs, 1, NULL); in fuse_dev_splice_read()
1389 cs.pipebufs = bufs; in fuse_dev_splice_read()
1390 cs.pipe = pipe; in fuse_dev_splice_read()
1391 ret = fuse_dev_do_read(fud, in, &cs, len); in fuse_dev_splice_read()
1395 if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->max_usage) { in fuse_dev_splice_read()
1400 for (ret = total = 0; page_nr < cs.nr_segs; total += ret) { in fuse_dev_splice_read()
1414 for (; page_nr < cs.nr_segs; page_nr++) in fuse_dev_splice_read()
1422 struct fuse_copy_state *cs) in fuse_notify_poll() argument
1430 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_poll()
1434 fuse_copy_finish(cs); in fuse_notify_poll()
1438 fuse_copy_finish(cs); in fuse_notify_poll()
1443 struct fuse_copy_state *cs) in fuse_notify_inval_inode() argument
1451 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_inode()
1454 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1463 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1468 struct fuse_copy_state *cs) in fuse_notify_inval_entry() argument
1483 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_entry()
1497 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_inval_entry()
1500 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1511 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1516 struct fuse_copy_state *cs) in fuse_notify_delete() argument
1531 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_delete()
1545 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_delete()
1548 fuse_copy_finish(cs); in fuse_notify_delete()
1559 fuse_copy_finish(cs); in fuse_notify_delete()
1564 struct fuse_copy_state *cs) in fuse_notify_store() argument
1581 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_store()
1620 err = fuse_copy_page(cs, &page, offset, this_num, 0); in fuse_notify_store()
1642 fuse_copy_finish(cs); in fuse_notify_store()
1742 struct fuse_copy_state *cs) in fuse_notify_retrieve() argument
1754 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_retrieve()
1758 fuse_copy_finish(cs); in fuse_notify_retrieve()
1774 fuse_copy_finish(cs); in fuse_notify_retrieve()
1779 unsigned int size, struct fuse_copy_state *cs) in fuse_notify() argument
1782 cs->move_pages = 0; in fuse_notify()
1786 return fuse_notify_poll(fc, size, cs); in fuse_notify()
1789 return fuse_notify_inval_inode(fc, size, cs); in fuse_notify()
1792 return fuse_notify_inval_entry(fc, size, cs); in fuse_notify()
1795 return fuse_notify_store(fc, size, cs); in fuse_notify()
1798 return fuse_notify_retrieve(fc, size, cs); in fuse_notify()
1801 return fuse_notify_delete(fc, size, cs); in fuse_notify()
1804 fuse_copy_finish(cs); in fuse_notify()
1822 static int copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args, in copy_out_args() argument
1839 return fuse_copy_args(cs, args->out_numargs, args->out_pages, in copy_out_args()
1851 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_write() argument
1863 err = fuse_copy_one(cs, &oh, sizeof(oh)); in fuse_dev_do_write()
1876 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
1918 cs->req = req; in fuse_dev_do_write()
1920 cs->move_pages = 0; in fuse_dev_do_write()
1925 err = copy_out_args(cs, req->args, nbytes); in fuse_dev_do_write()
1926 fuse_copy_finish(cs); in fuse_dev_do_write()
1943 fuse_copy_finish(cs); in fuse_dev_do_write()
1949 struct fuse_copy_state cs; in fuse_dev_write() local
1958 fuse_copy_init(&cs, 0, from); in fuse_dev_write()
1960 return fuse_dev_do_write(fud, &cs, iov_iter_count(from)); in fuse_dev_write()
1971 struct fuse_copy_state cs; in fuse_dev_splice_write() local
2033 fuse_copy_init(&cs, 0, NULL); in fuse_dev_splice_write()
2034 cs.pipebufs = bufs; in fuse_dev_splice_write()
2035 cs.nr_segs = nbuf; in fuse_dev_splice_write()
2036 cs.pipe = pipe; in fuse_dev_splice_write()
2039 cs.move_pages = 1; in fuse_dev_splice_write()
2041 ret = fuse_dev_do_write(fud, &cs, len); in fuse_dev_splice_write()