Lines Matching full:cs

724 void fuse_copy_init(struct fuse_copy_state *cs, int write,  in fuse_copy_init()  argument
727 memset(cs, 0, sizeof(*cs)); in fuse_copy_init()
728 cs->write = write; in fuse_copy_init()
729 cs->iter = iter; in fuse_copy_init()
733 static void fuse_copy_finish(struct fuse_copy_state *cs) in fuse_copy_finish() argument
735 if (cs->currbuf) { in fuse_copy_finish()
736 struct pipe_buffer *buf = cs->currbuf; in fuse_copy_finish()
738 if (cs->write) in fuse_copy_finish()
739 buf->len = PAGE_SIZE - cs->len; in fuse_copy_finish()
740 cs->currbuf = NULL; in fuse_copy_finish()
741 } else if (cs->pg) { in fuse_copy_finish()
742 if (cs->write) { in fuse_copy_finish()
743 flush_dcache_page(cs->pg); in fuse_copy_finish()
744 set_page_dirty_lock(cs->pg); in fuse_copy_finish()
746 put_page(cs->pg); in fuse_copy_finish()
748 cs->pg = NULL; in fuse_copy_finish()
755 static int fuse_copy_fill(struct fuse_copy_state *cs) in fuse_copy_fill() argument
760 err = unlock_request(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 = pipe_buf_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->max_usage) 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_pages2(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()
810 return lock_request(cs->req); in fuse_copy_fill()
814 static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size) in fuse_copy_do() argument
816 unsigned ncpy = min(*size, cs->len); in fuse_copy_do()
818 void *pgaddr = kmap_local_page(cs->pg); in fuse_copy_do()
819 void *buf = pgaddr + cs->offset; in fuse_copy_do()
821 if (cs->write) in fuse_copy_do()
830 cs->len -= ncpy; in fuse_copy_do()
831 cs->offset += ncpy; in fuse_copy_do()
832 if (cs->is_uring) in fuse_copy_do()
833 cs->ring.copied_sz += ncpy; in fuse_copy_do()
863 static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) in fuse_try_move_page() argument
868 struct pipe_buffer *buf = cs->pipebufs; in fuse_try_move_page()
871 err = unlock_request(cs->req); in fuse_try_move_page()
875 fuse_copy_finish(cs); in fuse_try_move_page()
877 err = pipe_buf_confirm(cs->pipe, buf); in fuse_try_move_page()
881 BUG_ON(!cs->nr_segs); in fuse_try_move_page()
882 cs->currbuf = buf; in fuse_try_move_page()
883 cs->len = buf->len; in fuse_try_move_page()
884 cs->pipebufs++; in fuse_try_move_page()
885 cs->nr_segs--; in fuse_try_move_page()
887 if (cs->len != PAGE_SIZE) in fuse_try_move_page()
890 if (!pipe_buf_try_steal(cs->pipe, buf)) in fuse_try_move_page()
926 pipe_buf_release(cs->pipe, buf); in fuse_try_move_page()
929 spin_lock(&cs->req->waitq.lock); in fuse_try_move_page()
930 if (test_bit(FR_ABORTED, &cs->req->flags)) in fuse_try_move_page()
934 spin_unlock(&cs->req->waitq.lock); in fuse_try_move_page()
945 cs->len = 0; in fuse_try_move_page()
956 cs->pg = buf->page; in fuse_try_move_page()
957 cs->offset = buf->offset; in fuse_try_move_page()
959 err = lock_request(cs->req); in fuse_try_move_page()
966 static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page, in fuse_ref_page() argument
972 if (cs->nr_segs >= cs->pipe->max_usage) in fuse_ref_page()
976 err = unlock_request(cs->req); in fuse_ref_page()
982 fuse_copy_finish(cs); in fuse_ref_page()
984 buf = cs->pipebufs; in fuse_ref_page()
989 cs->pipebufs++; in fuse_ref_page()
990 cs->nr_segs++; in fuse_ref_page()
991 cs->len = 0; in fuse_ref_page()
1000 static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep, in fuse_copy_page() argument
1010 if (cs->write && cs->pipebufs && page) { in fuse_copy_page()
1015 if (cs->req->args->user_pages) { in fuse_copy_page()
1016 err = fuse_copy_fill(cs); in fuse_copy_page()
1020 return fuse_ref_page(cs, page, offset, count); in fuse_copy_page()
1022 } else if (!cs->len) { in fuse_copy_page()
1023 if (cs->move_pages && page && in fuse_copy_page()
1025 err = fuse_try_move_page(cs, pagep); in fuse_copy_page()
1029 err = fuse_copy_fill(cs); in fuse_copy_page()
1037 offset += fuse_copy_do(cs, &buf, &count); in fuse_copy_page()
1040 offset += fuse_copy_do(cs, NULL, &count); in fuse_copy_page()
1042 if (page && !cs->write) in fuse_copy_page()
1048 static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes, in fuse_copy_pages() argument
1052 struct fuse_req *req = cs->req; in fuse_copy_pages()
1063 err = fuse_copy_page(cs, &pagep, offset, count, zeroing); in fuse_copy_pages()
1081 static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size) in fuse_copy_one() argument
1084 if (!cs->len) { in fuse_copy_one()
1085 int err = fuse_copy_fill(cs); in fuse_copy_one()
1089 fuse_copy_do(cs, &val, &size); in fuse_copy_one()
1095 int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs, in fuse_copy_args() argument
1105 err = fuse_copy_pages(cs, arg->size, zeroing); in fuse_copy_args()
1107 err = fuse_copy_one(cs, arg->value, arg->size); in fuse_copy_args()
1132 struct fuse_copy_state *cs, in fuse_read_interrupt() argument
1153 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_interrupt()
1155 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_interrupt()
1156 fuse_copy_finish(cs); in fuse_read_interrupt()
1184 struct fuse_copy_state *cs, in fuse_read_single_forget() argument
1205 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_single_forget()
1207 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_single_forget()
1208 fuse_copy_finish(cs); in fuse_read_single_forget()
1217 struct fuse_copy_state *cs, size_t nbytes) in fuse_read_batch_forget() argument
1242 err = fuse_copy_one(cs, &ih, sizeof(ih)); in fuse_read_batch_forget()
1244 err = fuse_copy_one(cs, &arg, sizeof(arg)); in fuse_read_batch_forget()
1250 err = fuse_copy_one(cs, &forget->forget_one, in fuse_read_batch_forget()
1257 fuse_copy_finish(cs); in fuse_read_batch_forget()
1266 struct fuse_copy_state *cs, in fuse_read_forget() argument
1271 return fuse_read_single_forget(fiq, cs, nbytes); in fuse_read_forget()
1273 return fuse_read_batch_forget(fiq, cs, nbytes); in fuse_read_forget()
1286 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_read() argument
1338 return fuse_read_interrupt(fiq, cs, nbytes, req); in fuse_dev_do_read()
1343 return fuse_read_forget(fc, fiq, cs, nbytes); in fuse_dev_do_read()
1378 cs->req = req; in fuse_dev_do_read()
1379 err = fuse_copy_one(cs, &req->in.h, sizeof(req->in.h)); in fuse_dev_do_read()
1381 err = fuse_copy_args(cs, args->in_numargs, args->in_pages, in fuse_dev_do_read()
1383 fuse_copy_finish(cs); in fuse_dev_do_read()
1436 struct fuse_copy_state cs; in fuse_dev_read() local
1446 fuse_copy_init(&cs, 1, to); in fuse_dev_read()
1448 return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to)); in fuse_dev_read()
1458 struct fuse_copy_state cs; in fuse_dev_splice_read() local
1469 fuse_copy_init(&cs, 1, NULL); in fuse_dev_splice_read()
1470 cs.pipebufs = bufs; in fuse_dev_splice_read()
1471 cs.pipe = pipe; in fuse_dev_splice_read()
1472 ret = fuse_dev_do_read(fud, in, &cs, len); in fuse_dev_splice_read()
1476 if (pipe_buf_usage(pipe) + cs.nr_segs > pipe->max_usage) { in fuse_dev_splice_read()
1481 for (ret = total = 0; page_nr < cs.nr_segs; total += ret) { in fuse_dev_splice_read()
1495 for (; page_nr < cs.nr_segs; page_nr++) in fuse_dev_splice_read()
1503 struct fuse_copy_state *cs) in fuse_notify_poll() argument
1511 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_poll()
1515 fuse_copy_finish(cs); in fuse_notify_poll()
1519 fuse_copy_finish(cs); in fuse_notify_poll()
1524 struct fuse_copy_state *cs) in fuse_notify_inval_inode() argument
1532 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_inode()
1535 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1544 fuse_copy_finish(cs); in fuse_notify_inval_inode()
1549 struct fuse_copy_state *cs) in fuse_notify_inval_entry() argument
1564 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_inval_entry()
1578 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_inval_entry()
1581 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1592 fuse_copy_finish(cs); in fuse_notify_inval_entry()
1597 struct fuse_copy_state *cs) in fuse_notify_delete() argument
1612 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_delete()
1626 err = fuse_copy_one(cs, buf, outarg.namelen + 1); in fuse_notify_delete()
1629 fuse_copy_finish(cs); in fuse_notify_delete()
1640 fuse_copy_finish(cs); in fuse_notify_delete()
1645 struct fuse_copy_state *cs) in fuse_notify_store() argument
1662 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_store()
1702 err = fuse_copy_page(cs, &page, offset, this_num, 0); in fuse_notify_store()
1726 fuse_copy_finish(cs); in fuse_notify_store()
1828 struct fuse_copy_state *cs) in fuse_notify_retrieve() argument
1840 err = fuse_copy_one(cs, &outarg, sizeof(outarg)); in fuse_notify_retrieve()
1844 fuse_copy_finish(cs); in fuse_notify_retrieve()
1860 fuse_copy_finish(cs); in fuse_notify_retrieve()
1928 unsigned int size, struct fuse_copy_state *cs) in fuse_notify() argument
1931 cs->move_pages = 0; in fuse_notify()
1935 return fuse_notify_poll(fc, size, cs); in fuse_notify()
1938 return fuse_notify_inval_inode(fc, size, cs); in fuse_notify()
1941 return fuse_notify_inval_entry(fc, size, cs); in fuse_notify()
1944 return fuse_notify_store(fc, size, cs); in fuse_notify()
1947 return fuse_notify_retrieve(fc, size, cs); in fuse_notify()
1950 return fuse_notify_delete(fc, size, cs); in fuse_notify()
1956 fuse_copy_finish(cs); in fuse_notify()
1974 int fuse_copy_out_args(struct fuse_copy_state *cs, struct fuse_args *args, in fuse_copy_out_args() argument
1983 if (!cs->is_uring) in fuse_copy_out_args()
1998 return fuse_copy_args(cs, args->out_numargs, args->out_pages, in fuse_copy_out_args()
2010 struct fuse_copy_state *cs, size_t nbytes) in fuse_dev_do_write() argument
2022 err = fuse_copy_one(cs, &oh, sizeof(oh)); in fuse_dev_do_write()
2035 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); in fuse_dev_do_write()
2077 cs->req = req; in fuse_dev_do_write()
2079 cs->move_pages = 0; in fuse_dev_do_write()
2084 err = fuse_copy_out_args(cs, req->args, nbytes); in fuse_dev_do_write()
2085 fuse_copy_finish(cs); in fuse_dev_do_write()
2102 fuse_copy_finish(cs); in fuse_dev_do_write()
2108 struct fuse_copy_state cs; in fuse_dev_write() local
2117 fuse_copy_init(&cs, 0, from); in fuse_dev_write()
2119 return fuse_dev_do_write(fud, &cs, iov_iter_count(from)); in fuse_dev_write()
2130 struct fuse_copy_state cs; in fuse_dev_splice_write() local
2191 fuse_copy_init(&cs, 0, NULL); in fuse_dev_splice_write()
2192 cs.pipebufs = bufs; in fuse_dev_splice_write()
2193 cs.nr_segs = nbuf; in fuse_dev_splice_write()
2194 cs.pipe = pipe; in fuse_dev_splice_write()
2197 cs.move_pages = 1; in fuse_dev_splice_write()
2199 ret = fuse_dev_do_write(fud, &cs, len); in fuse_dev_splice_write()