Lines Matching refs:cs
724 static void fuse_copy_init(struct fuse_copy_state *cs, in fuse_copy_init() argument
729 memset(cs, 0, sizeof(*cs)); in fuse_copy_init()
730 cs->fc = fc; in fuse_copy_init()
731 cs->write = write; in fuse_copy_init()
732 cs->iter = iter; in fuse_copy_init()
736 static void fuse_copy_finish(struct fuse_copy_state *cs) in fuse_copy_finish() argument
738 if (cs->currbuf) { in fuse_copy_finish()
739 struct pipe_buffer *buf = cs->currbuf; in fuse_copy_finish()
741 if (cs->write) in fuse_copy_finish()
742 buf->len = PAGE_SIZE - cs->len; in fuse_copy_finish()
743 cs->currbuf = NULL; in fuse_copy_finish()
744 } else if (cs->pg) { in fuse_copy_finish()
745 if (cs->write) { in fuse_copy_finish()
746 flush_dcache_page(cs->pg); in fuse_copy_finish()
747 set_page_dirty_lock(cs->pg); in fuse_copy_finish()
749 put_page(cs->pg); in fuse_copy_finish()
751 cs->pg = NULL; in fuse_copy_finish()
758 static int fuse_copy_fill(struct fuse_copy_state *cs) in fuse_copy_fill() argument
763 unlock_request(cs->fc, cs->req); in fuse_copy_fill()
764 fuse_copy_finish(cs); in fuse_copy_fill()
765 if (cs->pipebufs) { in fuse_copy_fill()
766 struct pipe_buffer *buf = cs->pipebufs; in fuse_copy_fill()
768 if (!cs->write) { in fuse_copy_fill()
769 err = buf->ops->confirm(cs->pipe, buf); in fuse_copy_fill()
773 BUG_ON(!cs->nr_segs); in fuse_copy_fill()
774 cs->currbuf = buf; in fuse_copy_fill()
775 cs->pg = buf->page; in fuse_copy_fill()
776 cs->offset = buf->offset; in fuse_copy_fill()
777 cs->len = buf->len; in fuse_copy_fill()
778 cs->pipebufs++; in fuse_copy_fill()
779 cs->nr_segs--; in fuse_copy_fill()
781 if (cs->nr_segs == cs->pipe->buffers) in fuse_copy_fill()
792 cs->currbuf = buf; in fuse_copy_fill()
793 cs->pg = page; in fuse_copy_fill()
794 cs->offset = 0; in fuse_copy_fill()
795 cs->len = PAGE_SIZE; in fuse_copy_fill()
796 cs->pipebufs++; in fuse_copy_fill()
797 cs->nr_segs++; in fuse_copy_fill()
801 err = iov_iter_get_pages(cs->iter, &page, PAGE_SIZE, 1, &off); in fuse_copy_fill()
805 cs->len = err; in fuse_copy_fill()
806 cs->offset = off; in fuse_copy_fill()
807 cs->pg = page; in fuse_copy_fill()
808 cs->offset = off; in fuse_copy_fill()
809 iov_iter_advance(cs->iter, err); in fuse_copy_fill()
812 return lock_request(cs->fc, cs->req); in fuse_copy_fill()
816 static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size) in fuse_copy_do() argument
818 unsigned ncpy = min(*size, cs->len); in fuse_copy_do()
820 void *pgaddr = kmap_atomic(cs->pg); in fuse_copy_do()
821 void *buf = pgaddr + cs->offset; in fuse_copy_do()
823 if (cs->write) in fuse_copy_do()
832 cs->len -= ncpy; in fuse_copy_do()
833 cs->offset += ncpy; in fuse_copy_do()
856 static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) in fuse_try_move_page() argument
861 struct pipe_buffer *buf = cs->pipebufs; in fuse_try_move_page()
863 unlock_request(cs->fc, cs->req); in fuse_try_move_page()
864 fuse_copy_finish(cs); in fuse_try_move_page()
866 err = buf->ops->confirm(cs->pipe, buf); in fuse_try_move_page()
870 BUG_ON(!cs->nr_segs); in fuse_try_move_page()
871 cs->currbuf = buf; in fuse_try_move_page()
872 cs->len = buf->len; in fuse_try_move_page()
873 cs->pipebufs++; in fuse_try_move_page()
874 cs->nr_segs--; in fuse_try_move_page()
876 if (cs->len != PAGE_SIZE) in fuse_try_move_page()
879 if (buf->ops->steal(cs->pipe, buf) != 0) in fuse_try_move_page()
917 spin_lock(&cs->fc->lock); in fuse_try_move_page()
918 if (cs->req->aborted) in fuse_try_move_page()
922 spin_unlock(&cs->fc->lock); in fuse_try_move_page()
932 cs->len = 0; in fuse_try_move_page()
939 cs->pg = buf->page; in fuse_try_move_page()
940 cs->offset = buf->offset; in fuse_try_move_page()
942 err = lock_request(cs->fc, cs->req); in fuse_try_move_page()
949 static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, in fuse_ref_page() argument
954 if (cs->nr_segs == cs->pipe->buffers) in fuse_ref_page()
957 unlock_request(cs->fc, cs->req); in fuse_ref_page()
958 fuse_copy_finish(cs); in fuse_ref_page()
960 buf = cs->pipebufs; in fuse_ref_page()
966 cs->pipebufs++; in fuse_ref_page()
967 cs->nr_segs++; in fuse_ref_page()
968 cs->len = 0; in fuse_ref_page()
977 static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep, in fuse_copy_page() argument
987 if (cs->write && cs->pipebufs && page) { in fuse_copy_page()
988 return fuse_ref_page(cs, page, offset, count); in fuse_copy_page()
989 } else if (!cs->len) { in fuse_copy_page()
990 if (cs->move_pages && page && in fuse_copy_page()
992 err = fuse_try_move_page(cs, pagep); in fuse_copy_page()
996 err = fuse_copy_fill(cs); in fuse_copy_page()
1004 offset += fuse_copy_do(cs, &buf, &count); in fuse_copy_page()
1007 offset += fuse_copy_do(cs, NULL, &count); in fuse_copy_page()
1009 if (page && !cs->write) in fuse_copy_page()
1015 static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes, in fuse_copy_pages() argument
1019 struct fuse_req *req = cs->req; in fuse_copy_pages()
1026 err = fuse_copy_page(cs, &req->pages[i], offset, count, in fuse_copy_pages()
1037 static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size) in fuse_copy_one() argument
1040 if (!cs->len) { in fuse_copy_one()
1041 int err = fuse_copy_fill(cs); in fuse_copy_one()
1045 fuse_copy_do(cs, &val, &size); in fuse_copy_one()
1051 static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs, in fuse_copy_args() argument
1061 err = fuse_copy_pages(cs, arg->size, zeroing); in fuse_copy_args()
1063 err = fuse_copy_one(cs, arg->value, arg->size); in fuse_copy_args()
1108 static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_copy_state *cs, in fuse_read_interrupt() argument
1130 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_interrupt()
1132 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_interrupt()
1133 fuse_copy_finish(cs); in fuse_read_interrupt()
1161 struct fuse_copy_state *cs, in fuse_read_single_forget() argument
1182 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_single_forget()
1184 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_single_forget()
1185 fuse_copy_finish(cs); in fuse_read_single_forget()
1194 struct fuse_copy_state *cs, size_t nbytes) in fuse_read_batch_forget() argument
1219 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_batch_forget()
1221 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_batch_forget()
1227 err = fuse_copy_one(cs, &forget->forget_one, in fuse_read_batch_forget()
1234 fuse_copy_finish(cs); in fuse_read_batch_forget()
1242 static int fuse_read_forget(struct fuse_conn *fc, struct fuse_copy_state *cs, in fuse_read_forget() argument
1247 return fuse_read_single_forget(fc, cs, nbytes); in fuse_read_forget()
1249 return fuse_read_batch_forget(fc, cs, nbytes); in fuse_read_forget()
1262 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_read() argument
1287 return fuse_read_interrupt(fc, cs, nbytes, req); in fuse_dev_do_read()
1292 return fuse_read_forget(fc, cs, nbytes); in fuse_dev_do_read()
1314 cs->req = req; in fuse_dev_do_read()
1315 err = fuse_copy_one(cs, &in->h, sizeof(in->h)); in fuse_dev_do_read()
1317 err = fuse_copy_args(cs, in->numargs, in->argpages, in fuse_dev_do_read()
1319 fuse_copy_finish(cs); in fuse_dev_do_read()
1360 struct fuse_copy_state cs; in fuse_dev_read() local
1369 fuse_copy_init(&cs, fc, 1, to); in fuse_dev_read()
1371 return fuse_dev_do_read(fc, file, &cs, iov_iter_count(to)); in fuse_dev_read()
1382 struct fuse_copy_state cs; in fuse_dev_splice_read() local
1391 fuse_copy_init(&cs, fc, 1, NULL); in fuse_dev_splice_read()
1392 cs.pipebufs = bufs; in fuse_dev_splice_read()
1393 cs.pipe = pipe; in fuse_dev_splice_read()
1394 ret = fuse_dev_do_read(fc, in, &cs, len); in fuse_dev_splice_read()
1408 if (pipe->nrbufs + cs.nr_segs > pipe->buffers) { in fuse_dev_splice_read()
1413 while (page_nr < cs.nr_segs) { in fuse_dev_splice_read()
1445 for (; page_nr < cs.nr_segs; page_nr++) in fuse_dev_splice_read()
1453 struct fuse_copy_state *cs) in fuse_notify_poll() argument
1461 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_poll()
1465 fuse_copy_finish(cs); in fuse_notify_poll()
1469 fuse_copy_finish(cs); in fuse_notify_poll()
1474 struct fuse_copy_state *cs) in fuse_notify_inval_inode() argument
1482 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_inode()
1485 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1497 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1502 struct fuse_copy_state *cs) in fuse_notify_inval_entry() argument
1517 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_entry()
1531 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_inval_entry()
1534 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1548 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1553 struct fuse_copy_state *cs) in fuse_notify_delete() argument
1568 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_delete()
1582 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_delete()
1585 fuse_copy_finish(cs); in fuse_notify_delete()
1600 fuse_copy_finish(cs); in fuse_notify_delete()
1605 struct fuse_copy_state *cs) in fuse_notify_store() argument
1622 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_store()
1664 err = fuse_copy_page(cs, &page, offset, this_num, 0); in fuse_notify_store()
1686 fuse_copy_finish(cs); in fuse_notify_store()
1765 struct fuse_copy_state *cs) in fuse_notify_retrieve() argument
1775 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_retrieve()
1779 fuse_copy_finish(cs); in fuse_notify_retrieve()
1797 fuse_copy_finish(cs); in fuse_notify_retrieve()
1802 unsigned int size, struct fuse_copy_state *cs) in fuse_notify() argument
1805 cs->move_pages = 0; in fuse_notify()
1809 return fuse_notify_poll(fc, size, cs); in fuse_notify()
1812 return fuse_notify_inval_inode(fc, size, cs); in fuse_notify()
1815 return fuse_notify_inval_entry(fc, size, cs); in fuse_notify()
1818 return fuse_notify_store(fc, size, cs); in fuse_notify()
1821 return fuse_notify_retrieve(fc, size, cs); in fuse_notify()
1824 return fuse_notify_delete(fc, size, cs); in fuse_notify()
1827 fuse_copy_finish(cs); in fuse_notify()
1844 static int copy_out_args(struct fuse_copy_state *cs, struct fuse_out *out, in copy_out_args() argument
1863 return fuse_copy_args(cs, out->numargs, out->argpages, out->args, in copy_out_args()
1875 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_write() argument
1884 err = fuse_copy_one(cs, &oh, sizeof(oh)); in fuse_dev_do_write()
1897 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
1916 fuse_copy_finish(cs); in fuse_dev_do_write()
1933 fuse_copy_finish(cs); in fuse_dev_do_write()
1941 cs->req = req; in fuse_dev_do_write()
1943 cs->move_pages = 0; in fuse_dev_do_write()
1946 err = copy_out_args(cs, &req->out, nbytes); in fuse_dev_do_write()
1947 fuse_copy_finish(cs); in fuse_dev_do_write()
1963 fuse_copy_finish(cs); in fuse_dev_do_write()
1969 struct fuse_copy_state cs; in fuse_dev_write() local
1977 fuse_copy_init(&cs, fc, 0, from); in fuse_dev_write()
1979 return fuse_dev_do_write(fc, &cs, iov_iter_count(from)); in fuse_dev_write()
1989 struct fuse_copy_state cs; in fuse_dev_splice_write() local
2042 fuse_copy_init(&cs, fc, 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(fc, &cs, len); in fuse_dev_splice_write()