Lines Matching refs: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_local_page(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()
859 pipe_buf_release(cs->pipe, buf); in fuse_try_move_page()
862 spin_lock(&cs->req->waitq.lock); in fuse_try_move_page()
863 if (test_bit(FR_ABORTED, &cs->req->flags)) in fuse_try_move_page()
867 spin_unlock(&cs->req->waitq.lock); in fuse_try_move_page()
878 cs->len = 0; in fuse_try_move_page()
889 cs->pg = buf->page; in fuse_try_move_page()
890 cs->offset = buf->offset; in fuse_try_move_page()
892 err = lock_request(cs->req); in fuse_try_move_page()
899 static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, in fuse_ref_page() argument
905 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_ref_page()
909 err = unlock_request(cs->req); in fuse_ref_page()
915 fuse_copy_finish(cs); in fuse_ref_page()
917 buf = cs->pipebufs; in fuse_ref_page()
922 cs->pipebufs++; in fuse_ref_page()
923 cs->nr_segs++; in fuse_ref_page()
924 cs->len = 0; in fuse_ref_page()
933 static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep, in fuse_copy_page() argument
943 if (cs->write && cs->pipebufs && page) { in fuse_copy_page()
944 return fuse_ref_page(cs, page, offset, count); in fuse_copy_page()
945 } else if (!cs->len) { in fuse_copy_page()
946 if (cs->move_pages && page && in fuse_copy_page()
948 err = fuse_try_move_page(cs, pagep); in fuse_copy_page()
952 err = fuse_copy_fill(cs); in fuse_copy_page()
960 offset += fuse_copy_do(cs, &buf, &count); in fuse_copy_page()
963 offset += fuse_copy_do(cs, NULL, &count); in fuse_copy_page()
965 if (page && !cs->write) in fuse_copy_page()
971 static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes, in fuse_copy_pages() argument
975 struct fuse_req *req = cs->req; in fuse_copy_pages()
984 err = fuse_copy_page(cs, &ap->pages[i], offset, count, zeroing); in fuse_copy_pages()
994 static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size) in fuse_copy_one() argument
997 if (!cs->len) { in fuse_copy_one()
998 int err = fuse_copy_fill(cs); in fuse_copy_one()
1002 fuse_copy_do(cs, &val, &size); in fuse_copy_one()
1008 static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs, in fuse_copy_args() argument
1018 err = fuse_copy_pages(cs, arg->size, zeroing); in fuse_copy_args()
1020 err = fuse_copy_one(cs, arg->value, arg->size); in fuse_copy_args()
1045 struct fuse_copy_state *cs, in fuse_read_interrupt() argument
1066 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_interrupt()
1068 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_interrupt()
1069 fuse_copy_finish(cs); in fuse_read_interrupt()
1098 struct fuse_copy_state *cs, in fuse_read_single_forget() argument
1119 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_single_forget()
1121 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_single_forget()
1122 fuse_copy_finish(cs); in fuse_read_single_forget()
1131 struct fuse_copy_state *cs, size_t nbytes) in fuse_read_batch_forget() argument
1156 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_batch_forget()
1158 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_batch_forget()
1164 err = fuse_copy_one(cs, &forget->forget_one, in fuse_read_batch_forget()
1171 fuse_copy_finish(cs); in fuse_read_batch_forget()
1180 struct fuse_copy_state *cs, in fuse_read_forget() argument
1185 return fuse_read_single_forget(fiq, cs, nbytes); in fuse_read_forget()
1187 return fuse_read_batch_forget(fiq, cs, nbytes); in fuse_read_forget()
1200 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_read() argument
1252 return fuse_read_interrupt(fiq, cs, nbytes, req); in fuse_dev_do_read()
1257 return fuse_read_forget(fc, fiq, cs, nbytes); in fuse_dev_do_read()
1292 cs->req = req; in fuse_dev_do_read()
1293 err = fuse_copy_one(cs, &req->in.h, sizeof(req->in.h)); in fuse_dev_do_read()
1295 err = fuse_copy_args(cs, args->in_numargs, args->in_pages, in fuse_dev_do_read()
1297 fuse_copy_finish(cs); in fuse_dev_do_read()
1350 struct fuse_copy_state cs; in fuse_dev_read() local
1360 fuse_copy_init(&cs, 1, to); in fuse_dev_read()
1362 return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to)); in fuse_dev_read()
1372 struct fuse_copy_state cs; in fuse_dev_splice_read() local
1383 fuse_copy_init(&cs, 1, NULL); in fuse_dev_splice_read()
1384 cs.pipebufs = bufs; in fuse_dev_splice_read()
1385 cs.pipe = pipe; in fuse_dev_splice_read()
1386 ret = fuse_dev_do_read(fud, in, &cs, len); in fuse_dev_splice_read()
1390 if (pipe_occupancy(pipe->head, pipe->tail) + cs.nr_segs > pipe->max_usage) { in fuse_dev_splice_read()
1395 for (ret = total = 0; page_nr < cs.nr_segs; total += ret) { in fuse_dev_splice_read()
1409 for (; page_nr < cs.nr_segs; page_nr++) in fuse_dev_splice_read()
1417 struct fuse_copy_state *cs) in fuse_notify_poll() argument
1425 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_poll()
1429 fuse_copy_finish(cs); in fuse_notify_poll()
1433 fuse_copy_finish(cs); in fuse_notify_poll()
1438 struct fuse_copy_state *cs) in fuse_notify_inval_inode() argument
1446 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_inode()
1449 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1458 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1463 struct fuse_copy_state *cs) in fuse_notify_inval_entry() argument
1478 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_entry()
1492 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_inval_entry()
1495 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1506 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1511 struct fuse_copy_state *cs) in fuse_notify_delete() argument
1526 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_delete()
1540 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_delete()
1543 fuse_copy_finish(cs); in fuse_notify_delete()
1554 fuse_copy_finish(cs); in fuse_notify_delete()
1559 struct fuse_copy_state *cs) in fuse_notify_store() argument
1576 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_store()
1615 err = fuse_copy_page(cs, &page, offset, this_num, 0); in fuse_notify_store()
1637 fuse_copy_finish(cs); in fuse_notify_store()
1737 struct fuse_copy_state *cs) in fuse_notify_retrieve() argument
1749 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_retrieve()
1753 fuse_copy_finish(cs); in fuse_notify_retrieve()
1769 fuse_copy_finish(cs); in fuse_notify_retrieve()
1774 unsigned int size, struct fuse_copy_state *cs) in fuse_notify() argument
1777 cs->move_pages = 0; in fuse_notify()
1781 return fuse_notify_poll(fc, size, cs); in fuse_notify()
1784 return fuse_notify_inval_inode(fc, size, cs); in fuse_notify()
1787 return fuse_notify_inval_entry(fc, size, cs); in fuse_notify()
1790 return fuse_notify_store(fc, size, cs); in fuse_notify()
1793 return fuse_notify_retrieve(fc, size, cs); in fuse_notify()
1796 return fuse_notify_delete(fc, size, cs); in fuse_notify()
1799 fuse_copy_finish(cs); in fuse_notify()
1817 static int copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args, in copy_out_args() argument
1834 return fuse_copy_args(cs, args->out_numargs, args->out_pages, in copy_out_args()
1846 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_write() argument
1858 err = fuse_copy_one(cs, &oh, sizeof(oh)); in fuse_dev_do_write()
1871 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
1913 cs->req = req; in fuse_dev_do_write()
1915 cs->move_pages = 0; in fuse_dev_do_write()
1920 err = copy_out_args(cs, req->args, nbytes); in fuse_dev_do_write()
1921 fuse_copy_finish(cs); in fuse_dev_do_write()
1938 fuse_copy_finish(cs); in fuse_dev_do_write()
1944 struct fuse_copy_state cs; in fuse_dev_write() local
1953 fuse_copy_init(&cs, 0, from); in fuse_dev_write()
1955 return fuse_dev_do_write(fud, &cs, iov_iter_count(from)); in fuse_dev_write()
1966 struct fuse_copy_state cs; in fuse_dev_splice_write() local
2028 fuse_copy_init(&cs, 0, NULL); in fuse_dev_splice_write()
2029 cs.pipebufs = bufs; in fuse_dev_splice_write()
2030 cs.nr_segs = nbuf; in fuse_dev_splice_write()
2031 cs.pipe = pipe; in fuse_dev_splice_write()
2034 cs.move_pages = 1; in fuse_dev_splice_write()
2036 ret = fuse_dev_do_write(fud, &cs, len); in fuse_dev_splice_write()