Lines Matching full:cs
664 static void fuse_copy_init(struct fuse_copy_state *cs, int write, in fuse_copy_init() argument
667 memset(cs, 0, sizeof(*cs)); in fuse_copy_init()
668 cs->write = write; in fuse_copy_init()
669 cs->iter = iter; in fuse_copy_init()
673 static void fuse_copy_finish(struct fuse_copy_state *cs) in fuse_copy_finish() argument
675 if (cs->currbuf) { in fuse_copy_finish()
676 struct pipe_buffer *buf = cs->currbuf; in fuse_copy_finish()
678 if (cs->write) in fuse_copy_finish()
679 buf->len = PAGE_SIZE - cs->len; in fuse_copy_finish()
680 cs->currbuf = NULL; in fuse_copy_finish()
681 } else if (cs->pg) { in fuse_copy_finish()
682 if (cs->write) { in fuse_copy_finish()
683 flush_dcache_page(cs->pg); in fuse_copy_finish()
684 set_page_dirty_lock(cs->pg); in fuse_copy_finish()
686 put_page(cs->pg); in fuse_copy_finish()
688 cs->pg = NULL; in fuse_copy_finish()
695 static int fuse_copy_fill(struct fuse_copy_state *cs) in fuse_copy_fill() argument
700 err = unlock_request(cs->req); in fuse_copy_fill()
704 fuse_copy_finish(cs); in fuse_copy_fill()
705 if (cs->pipebufs) { in fuse_copy_fill()
706 struct pipe_buffer *buf = cs->pipebufs; in fuse_copy_fill()
708 if (!cs->write) { in fuse_copy_fill()
709 err = pipe_buf_confirm(cs->pipe, buf); in fuse_copy_fill()
713 BUG_ON(!cs->nr_segs); in fuse_copy_fill()
714 cs->currbuf = buf; in fuse_copy_fill()
715 cs->pg = buf->page; in fuse_copy_fill()
716 cs->offset = buf->offset; in fuse_copy_fill()
717 cs->len = buf->len; in fuse_copy_fill()
718 cs->pipebufs++; in fuse_copy_fill()
719 cs->nr_segs--; in fuse_copy_fill()
721 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_copy_fill()
732 cs->currbuf = buf; in fuse_copy_fill()
733 cs->pg = page; in fuse_copy_fill()
734 cs->offset = 0; in fuse_copy_fill()
735 cs->len = PAGE_SIZE; in fuse_copy_fill()
736 cs->pipebufs++; in fuse_copy_fill()
737 cs->nr_segs++; in fuse_copy_fill()
741 err = iov_iter_get_pages(cs->iter, &page, PAGE_SIZE, 1, &off); in fuse_copy_fill()
745 cs->len = err; in fuse_copy_fill()
746 cs->offset = off; in fuse_copy_fill()
747 cs->pg = page; in fuse_copy_fill()
748 iov_iter_advance(cs->iter, err); in fuse_copy_fill()
751 return lock_request(cs->req); in fuse_copy_fill()
755 static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size) in fuse_copy_do() argument
757 unsigned ncpy = min(*size, cs->len); in fuse_copy_do()
759 void *pgaddr = kmap_atomic(cs->pg); in fuse_copy_do()
760 void *buf = pgaddr + cs->offset; in fuse_copy_do()
762 if (cs->write) in fuse_copy_do()
771 cs->len -= ncpy; in fuse_copy_do()
772 cs->offset += ncpy; in fuse_copy_do()
795 static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) in fuse_try_move_page() argument
800 struct pipe_buffer *buf = cs->pipebufs; in fuse_try_move_page()
803 err = unlock_request(cs->req); in fuse_try_move_page()
807 fuse_copy_finish(cs); in fuse_try_move_page()
809 err = pipe_buf_confirm(cs->pipe, buf); in fuse_try_move_page()
813 BUG_ON(!cs->nr_segs); in fuse_try_move_page()
814 cs->currbuf = buf; in fuse_try_move_page()
815 cs->len = buf->len; in fuse_try_move_page()
816 cs->pipebufs++; in fuse_try_move_page()
817 cs->nr_segs--; in fuse_try_move_page()
819 if (cs->len != PAGE_SIZE) in fuse_try_move_page()
822 if (!pipe_buf_try_steal(cs->pipe, buf)) in fuse_try_move_page()
863 pipe_buf_release(cs->pipe, buf); in fuse_try_move_page()
866 spin_lock(&cs->req->waitq.lock); in fuse_try_move_page()
867 if (test_bit(FR_ABORTED, &cs->req->flags)) in fuse_try_move_page()
871 spin_unlock(&cs->req->waitq.lock); in fuse_try_move_page()
882 cs->len = 0; in fuse_try_move_page()
893 cs->pg = buf->page; in fuse_try_move_page()
894 cs->offset = buf->offset; in fuse_try_move_page()
896 err = lock_request(cs->req); in fuse_try_move_page()
903 static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, in fuse_ref_page() argument
909 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_ref_page()
913 err = unlock_request(cs->req); in fuse_ref_page()
919 fuse_copy_finish(cs); in fuse_ref_page()
921 buf = cs->pipebufs; in fuse_ref_page()
926 cs->pipebufs++; in fuse_ref_page()
927 cs->nr_segs++; in fuse_ref_page()
928 cs->len = 0; in fuse_ref_page()
937 static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep, in fuse_copy_page() argument
947 if (cs->write && cs->pipebufs && page) { in fuse_copy_page()
952 if (cs->req->args->user_pages) { in fuse_copy_page()
953 err = fuse_copy_fill(cs); in fuse_copy_page()
957 return fuse_ref_page(cs, page, offset, count); in fuse_copy_page()
959 } else if (!cs->len) { in fuse_copy_page()
960 if (cs->move_pages && page && in fuse_copy_page()
962 err = fuse_try_move_page(cs, pagep); in fuse_copy_page()
966 err = fuse_copy_fill(cs); in fuse_copy_page()
974 offset += fuse_copy_do(cs, &buf, &count); in fuse_copy_page()
977 offset += fuse_copy_do(cs, NULL, &count); in fuse_copy_page()
979 if (page && !cs->write) in fuse_copy_page()
985 static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes, in fuse_copy_pages() argument
989 struct fuse_req *req = cs->req; in fuse_copy_pages()
998 err = fuse_copy_page(cs, &ap->pages[i], offset, count, zeroing); in fuse_copy_pages()
1008 static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size) in fuse_copy_one() argument
1011 if (!cs->len) { in fuse_copy_one()
1012 int err = fuse_copy_fill(cs); in fuse_copy_one()
1016 fuse_copy_do(cs, &val, &size); in fuse_copy_one()
1022 static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs, in fuse_copy_args() argument
1032 err = fuse_copy_pages(cs, arg->size, zeroing); in fuse_copy_args()
1034 err = fuse_copy_one(cs, arg->value, arg->size); in fuse_copy_args()
1059 struct fuse_copy_state *cs, in fuse_read_interrupt() argument
1080 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_interrupt()
1082 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_interrupt()
1083 fuse_copy_finish(cs); in fuse_read_interrupt()
1112 struct fuse_copy_state *cs, in fuse_read_single_forget() argument
1133 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_single_forget()
1135 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_single_forget()
1136 fuse_copy_finish(cs); in fuse_read_single_forget()
1145 struct fuse_copy_state *cs, size_t nbytes) in fuse_read_batch_forget() argument
1170 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_batch_forget()
1172 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_batch_forget()
1178 err = fuse_copy_one(cs, &forget->forget_one, in fuse_read_batch_forget()
1185 fuse_copy_finish(cs); in fuse_read_batch_forget()
1194 struct fuse_copy_state *cs, in fuse_read_forget() argument
1199 return fuse_read_single_forget(fiq, cs, nbytes); in fuse_read_forget()
1201 return fuse_read_batch_forget(fiq, cs, nbytes); in fuse_read_forget()
1214 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_read() argument
1266 return fuse_read_interrupt(fiq, cs, nbytes, req); in fuse_dev_do_read()
1271 return fuse_read_forget(fc, fiq, cs, nbytes); in fuse_dev_do_read()
1306 cs->req = req; in fuse_dev_do_read()
1307 err = fuse_copy_one(cs, &req->in.h, sizeof(req->in.h)); in fuse_dev_do_read()
1309 err = fuse_copy_args(cs, args->in_numargs, args->in_pages, in fuse_dev_do_read()
1311 fuse_copy_finish(cs); in fuse_dev_do_read()
1364 struct fuse_copy_state cs; in fuse_dev_read() local
1374 fuse_copy_init(&cs, 1, to); in fuse_dev_read()
1376 return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to)); in fuse_dev_read()
1386 struct fuse_copy_state cs; in fuse_dev_splice_read() local
1397 fuse_copy_init(&cs, 1, NULL); in fuse_dev_splice_read()
1398 cs.pipebufs = bufs; in fuse_dev_splice_read()
1399 cs.pipe = pipe; in fuse_dev_splice_read()
1400 ret = fuse_dev_do_read(fud, in, &cs, len); in fuse_dev_splice_read()
1404 if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->max_usage) { in fuse_dev_splice_read()
1409 for (ret = total = 0; page_nr < cs.nr_segs; total += ret) { in fuse_dev_splice_read()
1423 for (; page_nr < cs.nr_segs; page_nr++) in fuse_dev_splice_read()
1431 struct fuse_copy_state *cs) in fuse_notify_poll() argument
1439 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_poll()
1443 fuse_copy_finish(cs); in fuse_notify_poll()
1447 fuse_copy_finish(cs); in fuse_notify_poll()
1452 struct fuse_copy_state *cs) in fuse_notify_inval_inode() argument
1460 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_inode()
1463 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1472 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1477 struct fuse_copy_state *cs) in fuse_notify_inval_entry() argument
1492 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_entry()
1506 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_inval_entry()
1509 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1520 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1525 struct fuse_copy_state *cs) in fuse_notify_delete() argument
1540 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_delete()
1554 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_delete()
1557 fuse_copy_finish(cs); in fuse_notify_delete()
1568 fuse_copy_finish(cs); in fuse_notify_delete()
1573 struct fuse_copy_state *cs) in fuse_notify_store() argument
1590 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_store()
1629 err = fuse_copy_page(cs, &page, offset, this_num, 0); in fuse_notify_store()
1651 fuse_copy_finish(cs); in fuse_notify_store()
1751 struct fuse_copy_state *cs) in fuse_notify_retrieve() argument
1763 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_retrieve()
1767 fuse_copy_finish(cs); in fuse_notify_retrieve()
1783 fuse_copy_finish(cs); in fuse_notify_retrieve()
1788 unsigned int size, struct fuse_copy_state *cs) in fuse_notify() argument
1791 cs->move_pages = 0; in fuse_notify()
1795 return fuse_notify_poll(fc, size, cs); in fuse_notify()
1798 return fuse_notify_inval_inode(fc, size, cs); in fuse_notify()
1801 return fuse_notify_inval_entry(fc, size, cs); in fuse_notify()
1804 return fuse_notify_store(fc, size, cs); in fuse_notify()
1807 return fuse_notify_retrieve(fc, size, cs); in fuse_notify()
1810 return fuse_notify_delete(fc, size, cs); in fuse_notify()
1813 fuse_copy_finish(cs); in fuse_notify()
1831 static int copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args, in copy_out_args() argument
1848 return fuse_copy_args(cs, args->out_numargs, args->out_pages, in copy_out_args()
1860 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_write() argument
1872 err = fuse_copy_one(cs, &oh, sizeof(oh)); in fuse_dev_do_write()
1885 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
1927 cs->req = req; in fuse_dev_do_write()
1929 cs->move_pages = 0; in fuse_dev_do_write()
1934 err = copy_out_args(cs, req->args, nbytes); in fuse_dev_do_write()
1935 fuse_copy_finish(cs); in fuse_dev_do_write()
1952 fuse_copy_finish(cs); in fuse_dev_do_write()
1958 struct fuse_copy_state cs; in fuse_dev_write() local
1967 fuse_copy_init(&cs, 0, from); in fuse_dev_write()
1969 return fuse_dev_do_write(fud, &cs, iov_iter_count(from)); in fuse_dev_write()
1980 struct fuse_copy_state cs; in fuse_dev_splice_write() local
2042 fuse_copy_init(&cs, 0, NULL); in fuse_dev_splice_write()
2043 cs.pipebufs = bufs; in fuse_dev_splice_write()
2044 cs.nr_segs = nbuf; in fuse_dev_splice_write()
2045 cs.pipe = pipe; in fuse_dev_splice_write()
2048 cs.move_pages = 1; in fuse_dev_splice_write()
2050 ret = fuse_dev_do_write(fud, &cs, len); in fuse_dev_splice_write()