Lines Matching +full:blocking +full:- +full:io
3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
42 inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY); in fuse_send_open()
43 if (!fm->fc->atomic_o_trunc) in fuse_send_open()
71 ff->fm = fm; in fuse_file_alloc()
72 ff->release_args = kzalloc(sizeof(*ff->release_args), in fuse_file_alloc()
74 if (!ff->release_args) { in fuse_file_alloc()
79 INIT_LIST_HEAD(&ff->write_entry); in fuse_file_alloc()
80 mutex_init(&ff->readdir.lock); in fuse_file_alloc()
81 refcount_set(&ff->count, 1); in fuse_file_alloc()
82 RB_CLEAR_NODE(&ff->polled_node); in fuse_file_alloc()
83 init_waitqueue_head(&ff->poll_wait); in fuse_file_alloc()
85 ff->kh = atomic64_inc_return(&fm->fc->khctr); in fuse_file_alloc()
92 kfree(ff->release_args); in fuse_file_free()
93 mutex_destroy(&ff->readdir.lock); in fuse_file_free()
99 refcount_inc(&ff->count); in fuse_file_get()
108 iput(ra->inode); in fuse_release_end()
114 if (refcount_dec_and_test(&ff->count)) { in fuse_file_put()
115 struct fuse_args *args = &ff->release_args->args; in fuse_file_put()
117 if (isdir ? ff->fm->fc->no_opendir : ff->fm->fc->no_open) { in fuse_file_put()
119 fuse_release_end(ff->fm, args, 0); in fuse_file_put()
121 fuse_simple_request(ff->fm, args); in fuse_file_put()
122 fuse_release_end(ff->fm, args, 0); in fuse_file_put()
124 args->end = fuse_release_end; in fuse_file_put()
125 if (fuse_simple_background(ff->fm, args, in fuse_file_put()
127 fuse_release_end(ff->fm, args, -ENOTCONN); in fuse_file_put()
136 struct fuse_conn *fc = fm->fc; in fuse_do_open()
142 return -ENOMEM; in fuse_do_open()
144 ff->fh = 0; in fuse_do_open()
145 /* Default for no-open */ in fuse_do_open()
146 ff->open_flags = FOPEN_KEEP_CACHE | (isdir ? FOPEN_CACHE_DIR : 0); in fuse_do_open()
147 if (isdir ? !fc->no_opendir : !fc->no_open) { in fuse_do_open()
153 ff->fh = outarg.fh; in fuse_do_open()
154 ff->open_flags = outarg.open_flags; in fuse_do_open()
156 } else if (err != -ENOSYS) { in fuse_do_open()
161 fc->no_opendir = 1; in fuse_do_open()
163 fc->no_open = 1; in fuse_do_open()
168 ff->open_flags &= ~FOPEN_DIRECT_IO; in fuse_do_open()
170 ff->nodeid = nodeid; in fuse_do_open()
171 file->private_data = ff; in fuse_do_open()
181 struct fuse_file *ff = file->private_data; in fuse_link_write_file()
186 spin_lock(&fi->lock); in fuse_link_write_file()
187 if (list_empty(&ff->write_entry)) in fuse_link_write_file()
188 list_add(&ff->write_entry, &fi->write_files); in fuse_link_write_file()
189 spin_unlock(&fi->lock); in fuse_link_write_file()
194 struct fuse_file *ff = file->private_data; in fuse_finish_open()
197 if (!(ff->open_flags & FOPEN_KEEP_CACHE)) in fuse_finish_open()
198 invalidate_inode_pages2(inode->i_mapping); in fuse_finish_open()
199 if (ff->open_flags & FOPEN_STREAM) in fuse_finish_open()
201 else if (ff->open_flags & FOPEN_NONSEEKABLE) in fuse_finish_open()
203 if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) { in fuse_finish_open()
206 spin_lock(&fi->lock); in fuse_finish_open()
207 fi->attr_version = atomic64_inc_return(&fc->attr_version); in fuse_finish_open()
209 spin_unlock(&fi->lock); in fuse_finish_open()
211 if (fc->writeback_cache) in fuse_finish_open()
214 if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache) in fuse_finish_open()
221 struct fuse_conn *fc = fm->fc; in fuse_open_common()
223 bool is_wb_truncate = (file->f_flags & O_TRUNC) && in fuse_open_common()
224 fc->atomic_o_trunc && in fuse_open_common()
225 fc->writeback_cache; in fuse_open_common()
226 bool dax_truncate = (file->f_flags & O_TRUNC) && in fuse_open_common()
227 fc->atomic_o_trunc && FUSE_IS_DAX(inode); in fuse_open_common()
239 down_write(&get_fuse_inode(inode)->i_mmap_sem); in fuse_open_common()
251 up_write(&get_fuse_inode(inode)->i_mmap_sem); in fuse_open_common()
264 struct fuse_conn *fc = ff->fm->fc; in fuse_prepare_release()
265 struct fuse_release_args *ra = ff->release_args; in fuse_prepare_release()
269 spin_lock(&fi->lock); in fuse_prepare_release()
270 list_del(&ff->write_entry); in fuse_prepare_release()
271 spin_unlock(&fi->lock); in fuse_prepare_release()
273 spin_lock(&fc->lock); in fuse_prepare_release()
274 if (!RB_EMPTY_NODE(&ff->polled_node)) in fuse_prepare_release()
275 rb_erase(&ff->polled_node, &fc->polled_files); in fuse_prepare_release()
276 spin_unlock(&fc->lock); in fuse_prepare_release()
278 wake_up_interruptible_all(&ff->poll_wait); in fuse_prepare_release()
280 ra->inarg.fh = ff->fh; in fuse_prepare_release()
281 ra->inarg.flags = flags; in fuse_prepare_release()
282 ra->args.in_numargs = 1; in fuse_prepare_release()
283 ra->args.in_args[0].size = sizeof(struct fuse_release_in); in fuse_prepare_release()
284 ra->args.in_args[0].value = &ra->inarg; in fuse_prepare_release()
285 ra->args.opcode = opcode; in fuse_prepare_release()
286 ra->args.nodeid = ff->nodeid; in fuse_prepare_release()
287 ra->args.force = true; in fuse_prepare_release()
288 ra->args.nocreds = true; in fuse_prepare_release()
294 struct fuse_file *ff = file->private_data; in fuse_release_common()
295 struct fuse_release_args *ra = ff->release_args; in fuse_release_common()
298 fuse_prepare_release(fi, ff, file->f_flags, opcode); in fuse_release_common()
300 if (ff->flock) { in fuse_release_common()
301 ra->inarg.release_flags |= FUSE_RELEASE_FLOCK_UNLOCK; in fuse_release_common()
302 ra->inarg.lock_owner = fuse_lock_owner_id(ff->fm->fc, in fuse_release_common()
306 ra->inode = igrab(file_inode(file)); in fuse_release_common()
317 fuse_file_put(ff, ff->fm->fc->destroy, isdir); in fuse_release_common()
330 if (fc->writeback_cache) in fuse_release()
341 WARN_ON(refcount_read(&ff->count) > 1); in fuse_sync_release()
344 * iput(NULL) is a no-op and since the refcount is 1 and everything's in fuse_sync_release()
357 u32 *k = fc->scramble_key; in fuse_lock_owner_id()
386 n = fi->writepages.rb_node; in fuse_find_writeback()
393 WARN_ON(get_fuse_inode(wpa->inode) != fi); in fuse_find_writeback()
394 curr_index = wpa->ia.write.in.offset >> PAGE_SHIFT; in fuse_find_writeback()
395 if (idx_from >= curr_index + wpa->ia.ap.num_pages) in fuse_find_writeback()
396 n = n->rb_right; in fuse_find_writeback()
398 n = n->rb_left; in fuse_find_writeback()
417 spin_lock(&fi->lock); in fuse_range_is_writeback()
419 spin_unlock(&fi->lock); in fuse_range_is_writeback()
439 wait_event(fi->page_waitq, !fuse_page_is_writeback(inode, index)); in fuse_wait_on_page_writeback()
445 * This is currently done by blocking further writes with FUSE_NOWRITE
461 struct fuse_file *ff = file->private_data; in fuse_flush()
467 return -EIO; in fuse_flush()
477 err = filemap_check_errors(file->f_mapping); in fuse_flush()
482 if (fm->fc->no_flush) in fuse_flush()
486 inarg.fh = ff->fh; in fuse_flush()
487 inarg.lock_owner = fuse_lock_owner_id(fm->fc, id); in fuse_flush()
496 if (err == -ENOSYS) { in fuse_flush()
497 fm->fc->no_flush = 1; in fuse_flush()
506 if (!err && fm->fc->writeback_cache) in fuse_flush()
514 struct inode *inode = file->f_mapping->host; in fuse_fsync_common()
516 struct fuse_file *ff = file->private_data; in fuse_fsync_common()
521 inarg.fh = ff->fh; in fuse_fsync_common()
534 struct inode *inode = file->f_mapping->host; in fuse_fsync()
539 return -EIO; in fuse_fsync()
567 if (fc->no_fsync) in fuse_fsync()
571 if (err == -ENOSYS) { in fuse_fsync()
572 fc->no_fsync = 1; in fuse_fsync()
584 struct fuse_file *ff = file->private_data; in fuse_read_args_fill()
585 struct fuse_args *args = &ia->ap.args; in fuse_read_args_fill()
587 ia->read.in.fh = ff->fh; in fuse_read_args_fill()
588 ia->read.in.offset = pos; in fuse_read_args_fill()
589 ia->read.in.size = count; in fuse_read_args_fill()
590 ia->read.in.flags = file->f_flags; in fuse_read_args_fill()
591 args->opcode = opcode; in fuse_read_args_fill()
592 args->nodeid = ff->nodeid; in fuse_read_args_fill()
593 args->in_numargs = 1; in fuse_read_args_fill()
594 args->in_args[0].size = sizeof(ia->read.in); in fuse_read_args_fill()
595 args->in_args[0].value = &ia->read.in; in fuse_read_args_fill()
596 args->out_argvar = true; in fuse_read_args_fill()
597 args->out_numargs = 1; in fuse_read_args_fill()
598 args->out_args[0].size = count; in fuse_read_args_fill()
606 for (i = 0; i < ap->num_pages; i++) { in fuse_release_user_pages()
608 set_page_dirty_lock(ap->pages[i]); in fuse_release_user_pages()
609 put_page(ap->pages[i]); in fuse_release_user_pages()
618 static ssize_t fuse_get_res_by_io(struct fuse_io_priv *io) in fuse_get_res_by_io() argument
620 if (io->err) in fuse_get_res_by_io()
621 return io->err; in fuse_get_res_by_io()
623 if (io->bytes >= 0 && io->write) in fuse_get_res_by_io()
624 return -EIO; in fuse_get_res_by_io()
626 return io->bytes < 0 ? io->size : io->bytes; in fuse_get_res_by_io()
631 * actual end of fuse request in IO request. Otherwise, if bytes_requested
632 * == bytes_transferred or rw == WRITE, the caller sets 'pos' to -1.
637 * fully completed (req->out.args[0].size == 32K) resulting in pos == -1. The
641 * Thus, when all fuse requests are completed, the minimal non-negative 'pos'
643 * transferred data starting from the beginning of IO request.
645 static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos) in fuse_aio_complete() argument
649 spin_lock(&io->lock); in fuse_aio_complete()
651 io->err = io->err ? : err; in fuse_aio_complete()
652 else if (pos >= 0 && (io->bytes < 0 || pos < io->bytes)) in fuse_aio_complete()
653 io->bytes = pos; in fuse_aio_complete()
655 left = --io->reqs; in fuse_aio_complete()
656 if (!left && io->blocking) in fuse_aio_complete()
657 complete(io->done); in fuse_aio_complete()
658 spin_unlock(&io->lock); in fuse_aio_complete()
660 if (!left && !io->blocking) { in fuse_aio_complete()
661 ssize_t res = fuse_get_res_by_io(io); in fuse_aio_complete()
664 struct inode *inode = file_inode(io->iocb->ki_filp); in fuse_aio_complete()
668 spin_lock(&fi->lock); in fuse_aio_complete()
669 fi->attr_version = atomic64_inc_return(&fc->attr_version); in fuse_aio_complete()
670 spin_unlock(&fi->lock); in fuse_aio_complete()
673 io->iocb->ki_complete(io->iocb, res, 0); in fuse_aio_complete()
676 kref_put(&io->refcnt, fuse_io_release); in fuse_aio_complete()
679 static struct fuse_io_args *fuse_io_alloc(struct fuse_io_priv *io, in fuse_io_alloc() argument
686 ia->io = io; in fuse_io_alloc()
687 ia->ap.pages = fuse_pages_alloc(npages, GFP_KERNEL, in fuse_io_alloc()
688 &ia->ap.descs); in fuse_io_alloc()
689 if (!ia->ap.pages) { in fuse_io_alloc()
699 kfree(ia->ap.pages); in fuse_io_free()
707 struct fuse_io_priv *io = ia->io; in fuse_aio_complete_req() local
708 ssize_t pos = -1; in fuse_aio_complete_req()
710 fuse_release_user_pages(&ia->ap, io->should_dirty); in fuse_aio_complete_req()
714 } else if (io->write) { in fuse_aio_complete_req()
715 if (ia->write.out.size > ia->write.in.size) { in fuse_aio_complete_req()
716 err = -EIO; in fuse_aio_complete_req()
717 } else if (ia->write.in.size != ia->write.out.size) { in fuse_aio_complete_req()
718 pos = ia->write.in.offset - io->offset + in fuse_aio_complete_req()
719 ia->write.out.size; in fuse_aio_complete_req()
722 u32 outsize = args->out_args[0].size; in fuse_aio_complete_req()
724 if (ia->read.in.size != outsize) in fuse_aio_complete_req()
725 pos = ia->read.in.offset - io->offset + outsize; in fuse_aio_complete_req()
728 fuse_aio_complete(io, err, pos); in fuse_aio_complete_req()
736 struct fuse_io_priv *io = ia->io; in fuse_async_req_send() local
738 spin_lock(&io->lock); in fuse_async_req_send()
739 kref_get(&io->refcnt); in fuse_async_req_send()
740 io->size += num_bytes; in fuse_async_req_send()
741 io->reqs++; in fuse_async_req_send()
742 spin_unlock(&io->lock); in fuse_async_req_send()
744 ia->ap.args.end = fuse_aio_complete_req; in fuse_async_req_send()
745 ia->ap.args.may_block = io->should_dirty; in fuse_async_req_send()
746 err = fuse_simple_background(fm, &ia->ap.args, GFP_KERNEL); in fuse_async_req_send()
748 fuse_aio_complete_req(fm, &ia->ap.args, err); in fuse_async_req_send()
756 struct file *file = ia->io->iocb->ki_filp; in fuse_send_read()
757 struct fuse_file *ff = file->private_data; in fuse_send_read()
758 struct fuse_mount *fm = ff->fm; in fuse_send_read()
762 ia->read.in.read_flags |= FUSE_READ_LOCKOWNER; in fuse_send_read()
763 ia->read.in.lock_owner = fuse_lock_owner_id(fm->fc, owner); in fuse_send_read()
766 if (ia->io->async) in fuse_send_read()
769 return fuse_simple_request(fm, &ia->ap.args); in fuse_send_read()
778 spin_lock(&fi->lock); in fuse_read_update_size()
779 if (attr_ver == fi->attr_version && size < inode->i_size && in fuse_read_update_size()
780 !test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) { in fuse_read_update_size()
781 fi->attr_version = atomic64_inc_return(&fc->attr_version); in fuse_read_update_size()
784 spin_unlock(&fi->lock); in fuse_read_update_size()
792 if (fc->writeback_cache) { in fuse_short_read()
800 size_t off = num_read & (PAGE_SIZE - 1); in fuse_short_read()
802 for (i = start_idx; i < ap->num_pages; i++) { in fuse_short_read()
803 zero_user_segment(ap->pages[i], off, PAGE_SIZE); in fuse_short_read()
807 loff_t pos = page_offset(ap->pages[0]) + num_read; in fuse_short_read()
814 struct inode *inode = page->mapping->host; in fuse_do_readpage()
830 * page-cache page, so make sure we read a properly synced in fuse_do_readpage()
833 fuse_wait_on_page_writeback(inode, page->index); in fuse_do_readpage()
835 attr_ver = fuse_get_attr_version(fm->fc); in fuse_do_readpage()
838 if (pos + (desc.length - 1) == LLONG_MAX) in fuse_do_readpage()
839 desc.length--; in fuse_do_readpage()
858 struct inode *inode = page->mapping->host; in fuse_readpage()
861 err = -EIO; in fuse_readpage()
877 struct fuse_args_pages *ap = &ia->ap; in fuse_readpages_end()
878 size_t count = ia->read.in.size; in fuse_readpages_end()
879 size_t num_read = args->out_args[0].size; in fuse_readpages_end()
882 for (i = 0; mapping == NULL && i < ap->num_pages; i++) in fuse_readpages_end()
883 mapping = ap->pages[i]->mapping; in fuse_readpages_end()
886 struct inode *inode = mapping->host; in fuse_readpages_end()
892 fuse_short_read(inode, ia->read.attr_ver, num_read, ap); in fuse_readpages_end()
897 for (i = 0; i < ap->num_pages; i++) { in fuse_readpages_end()
898 struct page *page = ap->pages[i]; in fuse_readpages_end()
907 if (ia->ff) in fuse_readpages_end()
908 fuse_file_put(ia->ff, false, false); in fuse_readpages_end()
915 struct fuse_file *ff = file->private_data; in fuse_send_readpages()
916 struct fuse_mount *fm = ff->fm; in fuse_send_readpages()
917 struct fuse_args_pages *ap = &ia->ap; in fuse_send_readpages()
918 loff_t pos = page_offset(ap->pages[0]); in fuse_send_readpages()
919 size_t count = ap->num_pages << PAGE_SHIFT; in fuse_send_readpages()
923 ap->args.out_pages = true; in fuse_send_readpages()
924 ap->args.page_zeroing = true; in fuse_send_readpages()
925 ap->args.page_replace = true; in fuse_send_readpages()
928 if (pos + (count - 1) == LLONG_MAX) { in fuse_send_readpages()
929 count--; in fuse_send_readpages()
930 ap->descs[ap->num_pages - 1].length--; in fuse_send_readpages()
935 ia->read.attr_ver = fuse_get_attr_version(fm->fc); in fuse_send_readpages()
936 if (fm->fc->async_read) { in fuse_send_readpages()
937 ia->ff = fuse_file_get(ff); in fuse_send_readpages()
938 ap->args.end = fuse_readpages_end; in fuse_send_readpages()
939 err = fuse_simple_background(fm, &ap->args, GFP_KERNEL); in fuse_send_readpages()
943 res = fuse_simple_request(fm, &ap->args); in fuse_send_readpages()
946 fuse_readpages_end(fm, &ap->args, err); in fuse_send_readpages()
951 struct inode *inode = rac->mapping->host; in fuse_readahead()
958 max_pages = min_t(unsigned int, fc->max_pages, in fuse_readahead()
959 fc->max_read / PAGE_SIZE); in fuse_readahead()
965 nr_pages = readahead_count(rac) - nr_pages; in fuse_readahead()
973 ap = &ia->ap; in fuse_readahead()
974 nr_pages = __readahead_batch(rac, ap->pages, nr_pages); in fuse_readahead()
978 ap->descs[i].length = PAGE_SIZE; in fuse_readahead()
980 ap->num_pages = nr_pages; in fuse_readahead()
981 fuse_send_readpages(ia, rac->file); in fuse_readahead()
987 struct inode *inode = iocb->ki_filp->f_mapping->host; in fuse_cache_read_iter()
995 if (fc->auto_inval_data || in fuse_cache_read_iter()
996 (iocb->ki_pos + iov_iter_count(to) > i_size_read(inode))) { in fuse_cache_read_iter()
998 err = fuse_update_attributes(inode, iocb->ki_filp); in fuse_cache_read_iter()
1009 struct fuse_args *args = &ia->ap.args; in fuse_write_args_fill()
1011 ia->write.in.fh = ff->fh; in fuse_write_args_fill()
1012 ia->write.in.offset = pos; in fuse_write_args_fill()
1013 ia->write.in.size = count; in fuse_write_args_fill()
1014 args->opcode = FUSE_WRITE; in fuse_write_args_fill()
1015 args->nodeid = ff->nodeid; in fuse_write_args_fill()
1016 args->in_numargs = 2; in fuse_write_args_fill()
1017 if (ff->fm->fc->minor < 9) in fuse_write_args_fill()
1018 args->in_args[0].size = FUSE_COMPAT_WRITE_IN_SIZE; in fuse_write_args_fill()
1020 args->in_args[0].size = sizeof(ia->write.in); in fuse_write_args_fill()
1021 args->in_args[0].value = &ia->write.in; in fuse_write_args_fill()
1022 args->in_args[1].size = count; in fuse_write_args_fill()
1023 args->out_numargs = 1; in fuse_write_args_fill()
1024 args->out_args[0].size = sizeof(ia->write.out); in fuse_write_args_fill()
1025 args->out_args[0].value = &ia->write.out; in fuse_write_args_fill()
1030 unsigned int flags = iocb->ki_filp->f_flags; in fuse_write_flags()
1032 if (iocb->ki_flags & IOCB_DSYNC) in fuse_write_flags()
1034 if (iocb->ki_flags & IOCB_SYNC) in fuse_write_flags()
1043 struct kiocb *iocb = ia->io->iocb; in fuse_send_write()
1044 struct file *file = iocb->ki_filp; in fuse_send_write()
1045 struct fuse_file *ff = file->private_data; in fuse_send_write()
1046 struct fuse_mount *fm = ff->fm; in fuse_send_write()
1047 struct fuse_write_in *inarg = &ia->write.in; in fuse_send_write()
1051 inarg->flags = fuse_write_flags(iocb); in fuse_send_write()
1053 inarg->write_flags |= FUSE_WRITE_LOCKOWNER; in fuse_send_write()
1054 inarg->lock_owner = fuse_lock_owner_id(fm->fc, owner); in fuse_send_write()
1057 if (ia->io->async) in fuse_send_write()
1060 err = fuse_simple_request(fm, &ia->ap.args); in fuse_send_write()
1061 if (!err && ia->write.out.size > count) in fuse_send_write()
1062 err = -EIO; in fuse_send_write()
1064 return err ?: ia->write.out.size; in fuse_send_write()
1073 spin_lock(&fi->lock); in fuse_write_update_size()
1074 fi->attr_version = atomic64_inc_return(&fc->attr_version); in fuse_write_update_size()
1075 if (pos > inode->i_size) { in fuse_write_update_size()
1079 spin_unlock(&fi->lock); in fuse_write_update_size()
1088 struct fuse_args_pages *ap = &ia->ap; in fuse_send_write_pages()
1089 struct file *file = iocb->ki_filp; in fuse_send_write_pages()
1090 struct fuse_file *ff = file->private_data; in fuse_send_write_pages()
1091 struct fuse_mount *fm = ff->fm; in fuse_send_write_pages()
1095 for (i = 0; i < ap->num_pages; i++) in fuse_send_write_pages()
1096 fuse_wait_on_page_writeback(inode, ap->pages[i]->index); in fuse_send_write_pages()
1099 ia->write.in.flags = fuse_write_flags(iocb); in fuse_send_write_pages()
1101 err = fuse_simple_request(fm, &ap->args); in fuse_send_write_pages()
1102 if (!err && ia->write.out.size > count) in fuse_send_write_pages()
1103 err = -EIO; in fuse_send_write_pages()
1105 offset = ap->descs[0].offset; in fuse_send_write_pages()
1106 count = ia->write.out.size; in fuse_send_write_pages()
1107 for (i = 0; i < ap->num_pages; i++) { in fuse_send_write_pages()
1108 struct page *page = ap->pages[i]; in fuse_send_write_pages()
1113 if (count > PAGE_SIZE - offset) in fuse_send_write_pages()
1114 count -= PAGE_SIZE - offset; in fuse_send_write_pages()
1131 struct fuse_conn *fc = get_fuse_conn(mapping->host); in fuse_fill_write_pages()
1132 unsigned offset = pos & (PAGE_SIZE - 1); in fuse_fill_write_pages()
1136 ap->args.in_pages = true; in fuse_fill_write_pages()
1137 ap->descs[0].offset = offset; in fuse_fill_write_pages()
1143 size_t bytes = min_t(size_t, PAGE_SIZE - offset, in fuse_fill_write_pages()
1146 bytes = min_t(size_t, bytes, fc->max_write - count); in fuse_fill_write_pages()
1149 err = -EFAULT; in fuse_fill_write_pages()
1153 err = -ENOMEM; in fuse_fill_write_pages()
1173 ap->pages[ap->num_pages] = page; in fuse_fill_write_pages()
1174 ap->descs[ap->num_pages].length = tmp; in fuse_fill_write_pages()
1175 ap->num_pages++; in fuse_fill_write_pages()
1183 if (!fc->big_writes) in fuse_fill_write_pages()
1185 } while (iov_iter_count(ii) && count < fc->max_write && in fuse_fill_write_pages()
1186 ap->num_pages < max_pages && offset == 0); in fuse_fill_write_pages()
1195 ((pos + len - 1) >> PAGE_SHIFT) - in fuse_wr_pages()
1204 struct inode *inode = mapping->host; in fuse_perform_write()
1210 if (inode->i_size < pos + iov_iter_count(ii)) in fuse_perform_write()
1211 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); in fuse_perform_write()
1218 fc->max_pages); in fuse_perform_write()
1220 ap->pages = fuse_pages_alloc(nr_pages, GFP_KERNEL, &ap->descs); in fuse_perform_write()
1221 if (!ap->pages) { in fuse_perform_write()
1222 err = -ENOMEM; in fuse_perform_write()
1240 err = -EIO; in fuse_perform_write()
1243 kfree(ap->pages); in fuse_perform_write()
1249 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); in fuse_perform_write()
1257 struct file *file = iocb->ki_filp; in fuse_cache_write_iter()
1258 struct address_space *mapping = file->f_mapping; in fuse_cache_write_iter()
1261 struct inode *inode = mapping->host; in fuse_cache_write_iter()
1265 if (get_fuse_conn(inode)->writeback_cache) { in fuse_cache_write_iter()
1267 err = fuse_update_attributes(mapping->host, file); in fuse_cache_write_iter()
1277 current->backing_dev_info = inode_to_bdi(inode); in fuse_cache_write_iter()
1291 if (iocb->ki_flags & IOCB_DIRECT) { in fuse_cache_write_iter()
1292 loff_t pos = iocb->ki_pos; in fuse_cache_write_iter()
1304 endbyte = pos + written_buffered - 1; in fuse_cache_write_iter()
1306 err = filemap_write_and_wait_range(file->f_mapping, pos, in fuse_cache_write_iter()
1311 invalidate_mapping_pages(file->f_mapping, in fuse_cache_write_iter()
1316 iocb->ki_pos = pos + written_buffered; in fuse_cache_write_iter()
1318 written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); in fuse_cache_write_iter()
1320 iocb->ki_pos += written; in fuse_cache_write_iter()
1323 current->backing_dev_info = NULL; in fuse_cache_write_iter()
1338 descs[i].length = PAGE_SIZE - descs[i].offset; in fuse_page_descs_length_init()
1343 return (unsigned long)ii->iov->iov_base + ii->iov_offset; in fuse_get_user_addr()
1365 ap->args.in_args[1].value = (void *) user_addr; in fuse_get_user_pages()
1367 ap->args.out_args[0].value = (void *) user_addr; in fuse_get_user_pages()
1374 while (nbytes < *nbytesp && ap->num_pages < max_pages) { in fuse_get_user_pages()
1377 ret = iov_iter_get_pages(ii, &ap->pages[ap->num_pages], in fuse_get_user_pages()
1378 *nbytesp - nbytes, in fuse_get_user_pages()
1379 max_pages - ap->num_pages, in fuse_get_user_pages()
1388 npages = (ret + PAGE_SIZE - 1) / PAGE_SIZE; in fuse_get_user_pages()
1390 ap->descs[ap->num_pages].offset = start; in fuse_get_user_pages()
1391 fuse_page_descs_length_init(ap->descs, ap->num_pages, npages); in fuse_get_user_pages()
1393 ap->num_pages += npages; in fuse_get_user_pages()
1394 ap->descs[ap->num_pages - 1].length -= in fuse_get_user_pages()
1395 (PAGE_SIZE - ret) & (PAGE_SIZE - 1); in fuse_get_user_pages()
1399 ap->args.in_pages = true; in fuse_get_user_pages()
1401 ap->args.out_pages = true; in fuse_get_user_pages()
1408 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, in fuse_direct_io() argument
1413 struct file *file = io->iocb->ki_filp; in fuse_direct_io()
1414 struct inode *inode = file->f_mapping->host; in fuse_direct_io()
1415 struct fuse_file *ff = file->private_data; in fuse_direct_io()
1416 struct fuse_conn *fc = ff->fm->fc; in fuse_direct_io()
1417 size_t nmax = write ? fc->max_write : fc->max_read; in fuse_direct_io()
1421 pgoff_t idx_to = (pos + count - 1) >> PAGE_SHIFT; in fuse_direct_io()
1427 max_pages = iov_iter_npages(iter, fc->max_pages); in fuse_direct_io()
1428 ia = fuse_io_alloc(io, max_pages); in fuse_direct_io()
1430 return -ENOMEM; in fuse_direct_io()
1432 ia->io = io; in fuse_direct_io()
1441 io->should_dirty = !write && iter_is_iovec(iter); in fuse_direct_io()
1444 fl_owner_t owner = current->files; in fuse_direct_io()
1447 err = fuse_get_user_pages(&ia->ap, iter, &nbytes, write, in fuse_direct_io()
1454 ia->write.in.write_flags |= FUSE_WRITE_KILL_PRIV; in fuse_direct_io()
1461 if (!io->async || nres < 0) { in fuse_direct_io()
1462 fuse_release_user_pages(&ia->ap, io->should_dirty); in fuse_direct_io()
1473 count -= nres; in fuse_direct_io()
1477 iov_iter_revert(iter, nbytes - nres); in fuse_direct_io()
1481 max_pages = iov_iter_npages(iter, fc->max_pages); in fuse_direct_io()
1482 ia = fuse_io_alloc(io, max_pages); in fuse_direct_io()
1496 static ssize_t __fuse_direct_read(struct fuse_io_priv *io, in __fuse_direct_read() argument
1501 struct inode *inode = file_inode(io->iocb->ki_filp); in __fuse_direct_read()
1503 res = fuse_direct_io(io, iter, ppos, 0); in __fuse_direct_read()
1516 if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) { in fuse_direct_read_iter()
1519 struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb); in fuse_direct_read_iter() local
1521 res = __fuse_direct_read(&io, to, &iocb->ki_pos); in fuse_direct_read_iter()
1529 struct inode *inode = file_inode(iocb->ki_filp); in fuse_direct_write_iter()
1530 struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb); in fuse_direct_write_iter() local
1537 if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) { in fuse_direct_write_iter()
1540 res = fuse_direct_io(&io, from, &iocb->ki_pos, in fuse_direct_write_iter()
1546 fuse_write_update_size(inode, iocb->ki_pos); in fuse_direct_write_iter()
1554 struct file *file = iocb->ki_filp; in fuse_file_read_iter()
1555 struct fuse_file *ff = file->private_data; in fuse_file_read_iter()
1559 return -EIO; in fuse_file_read_iter()
1564 if (!(ff->open_flags & FOPEN_DIRECT_IO)) in fuse_file_read_iter()
1572 struct file *file = iocb->ki_filp; in fuse_file_write_iter()
1573 struct fuse_file *ff = file->private_data; in fuse_file_write_iter()
1577 return -EIO; in fuse_file_write_iter()
1582 if (!(ff->open_flags & FOPEN_DIRECT_IO)) in fuse_file_write_iter()
1590 struct fuse_args_pages *ap = &wpa->ia.ap; in fuse_writepage_free()
1593 for (i = 0; i < ap->num_pages; i++) in fuse_writepage_free()
1594 __free_page(ap->pages[i]); in fuse_writepage_free()
1596 if (wpa->ia.ff) in fuse_writepage_free()
1597 fuse_file_put(wpa->ia.ff, false, false); in fuse_writepage_free()
1599 kfree(ap->pages); in fuse_writepage_free()
1606 struct fuse_args_pages *ap = &wpa->ia.ap; in fuse_writepage_finish()
1607 struct inode *inode = wpa->inode; in fuse_writepage_finish()
1612 for (i = 0; i < ap->num_pages; i++) { in fuse_writepage_finish()
1613 dec_wb_stat(&bdi->wb, WB_WRITEBACK); in fuse_writepage_finish()
1614 dec_node_page_state(ap->pages[i], NR_WRITEBACK_TEMP); in fuse_writepage_finish()
1615 wb_writeout_inc(&bdi->wb); in fuse_writepage_finish()
1617 wake_up(&fi->page_waitq); in fuse_writepage_finish()
1620 /* Called under fi->lock, may release and reacquire it */
1623 __releases(fi->lock) in fuse_send_writepage()
1624 __acquires(fi->lock) in fuse_send_writepage()
1627 struct fuse_inode *fi = get_fuse_inode(wpa->inode); in fuse_send_writepage()
1628 struct fuse_write_in *inarg = &wpa->ia.write.in; in fuse_send_writepage()
1629 struct fuse_args *args = &wpa->ia.ap.args; in fuse_send_writepage()
1630 __u64 data_size = wpa->ia.ap.num_pages * PAGE_SIZE; in fuse_send_writepage()
1633 fi->writectr++; in fuse_send_writepage()
1634 if (inarg->offset + data_size <= size) { in fuse_send_writepage()
1635 inarg->size = data_size; in fuse_send_writepage()
1636 } else if (inarg->offset < size) { in fuse_send_writepage()
1637 inarg->size = size - inarg->offset; in fuse_send_writepage()
1643 args->in_args[1].size = inarg->size; in fuse_send_writepage()
1644 args->force = true; in fuse_send_writepage()
1645 args->nocreds = true; in fuse_send_writepage()
1648 if (err == -ENOMEM) { in fuse_send_writepage()
1649 spin_unlock(&fi->lock); in fuse_send_writepage()
1651 spin_lock(&fi->lock); in fuse_send_writepage()
1661 fi->writectr--; in fuse_send_writepage()
1662 rb_erase(&wpa->writepages_entry, &fi->writepages); in fuse_send_writepage()
1664 spin_unlock(&fi->lock); in fuse_send_writepage()
1667 for (aux = wpa->next; aux; aux = next) { in fuse_send_writepage()
1668 next = aux->next; in fuse_send_writepage()
1669 aux->next = NULL; in fuse_send_writepage()
1674 spin_lock(&fi->lock); in fuse_send_writepage()
1678 * If fi->writectr is positive (no truncate or fsync going on) send
1681 * Called with fi->lock
1684 __releases(fi->lock) in fuse_flush_writepages()
1685 __acquires(fi->lock) in fuse_flush_writepages()
1692 while (fi->writectr >= 0 && !list_empty(&fi->queued_writes)) { in fuse_flush_writepages()
1693 wpa = list_entry(fi->queued_writes.next, in fuse_flush_writepages()
1695 list_del_init(&wpa->queue_entry); in fuse_flush_writepages()
1703 pgoff_t idx_from = wpa->ia.write.in.offset >> PAGE_SHIFT; in fuse_insert_writeback()
1704 pgoff_t idx_to = idx_from + wpa->ia.ap.num_pages - 1; in fuse_insert_writeback()
1705 struct rb_node **p = &root->rb_node; in fuse_insert_writeback()
1708 WARN_ON(!wpa->ia.ap.num_pages); in fuse_insert_writeback()
1716 WARN_ON(curr->inode != wpa->inode); in fuse_insert_writeback()
1717 curr_index = curr->ia.write.in.offset >> PAGE_SHIFT; in fuse_insert_writeback()
1719 if (idx_from >= curr_index + curr->ia.ap.num_pages) in fuse_insert_writeback()
1720 p = &(*p)->rb_right; in fuse_insert_writeback()
1722 p = &(*p)->rb_left; in fuse_insert_writeback()
1727 rb_link_node(&wpa->writepages_entry, parent, p); in fuse_insert_writeback()
1728 rb_insert_color(&wpa->writepages_entry, root); in fuse_insert_writeback()
1742 struct inode *inode = wpa->inode; in fuse_writepage_end()
1745 mapping_set_error(inode->i_mapping, error); in fuse_writepage_end()
1746 spin_lock(&fi->lock); in fuse_writepage_end()
1747 rb_erase(&wpa->writepages_entry, &fi->writepages); in fuse_writepage_end()
1748 while (wpa->next) { in fuse_writepage_end()
1750 struct fuse_write_in *inarg = &wpa->ia.write.in; in fuse_writepage_end()
1751 struct fuse_writepage_args *next = wpa->next; in fuse_writepage_end()
1753 wpa->next = next->next; in fuse_writepage_end()
1754 next->next = NULL; in fuse_writepage_end()
1755 next->ia.ff = fuse_file_get(wpa->ia.ff); in fuse_writepage_end()
1756 tree_insert(&fi->writepages, next); in fuse_writepage_end()
1768 * now for completion of all in-flight requests. This happens in fuse_writepage_end()
1774 * that fuse_set_nowrite returned implies that all in-flight in fuse_writepage_end()
1777 * writectr. Hence there cannot be any in-flight requests and in fuse_writepage_end()
1781 fuse_send_writepage(fm, next, inarg->offset + inarg->size); in fuse_writepage_end()
1783 fi->writectr--; in fuse_writepage_end()
1785 spin_unlock(&fi->lock); in fuse_writepage_end()
1794 spin_lock(&fi->lock); in __fuse_write_file_get()
1795 if (!list_empty(&fi->write_files)) { in __fuse_write_file_get()
1796 ff = list_entry(fi->write_files.next, struct fuse_file, in __fuse_write_file_get()
1800 spin_unlock(&fi->lock); in __fuse_write_file_get()
1835 ap = &wpa->ia.ap; in fuse_writepage_args_alloc()
1836 ap->num_pages = 0; in fuse_writepage_args_alloc()
1837 ap->pages = fuse_pages_alloc(1, GFP_NOFS, &ap->descs); in fuse_writepage_args_alloc()
1838 if (!ap->pages) { in fuse_writepage_args_alloc()
1849 struct address_space *mapping = page->mapping; in fuse_writepage_locked()
1850 struct inode *inode = mapping->host; in fuse_writepage_locked()
1856 int error = -ENOMEM; in fuse_writepage_locked()
1863 ap = &wpa->ia.ap; in fuse_writepage_locked()
1869 error = -EIO; in fuse_writepage_locked()
1870 wpa->ia.ff = fuse_write_file_get(fc, fi); in fuse_writepage_locked()
1871 if (!wpa->ia.ff) in fuse_writepage_locked()
1874 fuse_write_args_fill(&wpa->ia, wpa->ia.ff, page_offset(page), 0); in fuse_writepage_locked()
1877 wpa->ia.write.in.write_flags |= FUSE_WRITE_CACHE; in fuse_writepage_locked()
1878 wpa->next = NULL; in fuse_writepage_locked()
1879 ap->args.in_pages = true; in fuse_writepage_locked()
1880 ap->num_pages = 1; in fuse_writepage_locked()
1881 ap->pages[0] = tmp_page; in fuse_writepage_locked()
1882 ap->descs[0].offset = 0; in fuse_writepage_locked()
1883 ap->descs[0].length = PAGE_SIZE; in fuse_writepage_locked()
1884 ap->args.end = fuse_writepage_end; in fuse_writepage_locked()
1885 wpa->inode = inode; in fuse_writepage_locked()
1887 inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK); in fuse_writepage_locked()
1890 spin_lock(&fi->lock); in fuse_writepage_locked()
1891 tree_insert(&fi->writepages, wpa); in fuse_writepage_locked()
1892 list_add_tail(&wpa->queue_entry, &fi->queued_writes); in fuse_writepage_locked()
1894 spin_unlock(&fi->lock); in fuse_writepage_locked()
1905 mapping_set_error(page->mapping, error); in fuse_writepage_locked()
1914 if (fuse_page_is_writeback(page->mapping->host, page->index)) { in fuse_writepage()
1916 * ->writepages() should be called for sync() and friends. We in fuse_writepage()
1920 WARN_ON(wbc->sync_mode == WB_SYNC_ALL); in fuse_writepage()
1943 struct fuse_args_pages *ap = &data->wpa->ia.ap; in fuse_pages_realloc()
1944 struct fuse_conn *fc = get_fuse_conn(data->inode); in fuse_pages_realloc()
1948 max_t(unsigned int, data->max_pages * 2, in fuse_pages_realloc()
1950 fc->max_pages); in fuse_pages_realloc()
1951 WARN_ON(npages <= data->max_pages); in fuse_pages_realloc()
1957 memcpy(pages, ap->pages, sizeof(struct page *) * ap->num_pages); in fuse_pages_realloc()
1958 memcpy(descs, ap->descs, sizeof(struct fuse_page_desc) * ap->num_pages); in fuse_pages_realloc()
1959 kfree(ap->pages); in fuse_pages_realloc()
1960 ap->pages = pages; in fuse_pages_realloc()
1961 ap->descs = descs; in fuse_pages_realloc()
1962 data->max_pages = npages; in fuse_pages_realloc()
1969 struct fuse_writepage_args *wpa = data->wpa; in fuse_writepages_send()
1970 struct inode *inode = data->inode; in fuse_writepages_send()
1972 int num_pages = wpa->ia.ap.num_pages; in fuse_writepages_send()
1975 wpa->ia.ff = fuse_file_get(data->ff); in fuse_writepages_send()
1976 spin_lock(&fi->lock); in fuse_writepages_send()
1977 list_add_tail(&wpa->queue_entry, &fi->queued_writes); in fuse_writepages_send()
1979 spin_unlock(&fi->lock); in fuse_writepages_send()
1982 end_page_writeback(data->orig_pages[i]); in fuse_writepages_send()
1986 * Check under fi->lock if the page is under writeback, and insert it onto the
1995 struct fuse_inode *fi = get_fuse_inode(new_wpa->inode); in fuse_writepage_add()
1998 struct fuse_args_pages *new_ap = &new_wpa->ia.ap; in fuse_writepage_add()
2000 WARN_ON(new_ap->num_pages != 0); in fuse_writepage_add()
2001 new_ap->num_pages = 1; in fuse_writepage_add()
2003 spin_lock(&fi->lock); in fuse_writepage_add()
2004 old_wpa = fuse_insert_writeback(&fi->writepages, new_wpa); in fuse_writepage_add()
2006 spin_unlock(&fi->lock); in fuse_writepage_add()
2010 for (tmp = old_wpa->next; tmp; tmp = tmp->next) { in fuse_writepage_add()
2013 WARN_ON(tmp->inode != new_wpa->inode); in fuse_writepage_add()
2014 curr_index = tmp->ia.write.in.offset >> PAGE_SHIFT; in fuse_writepage_add()
2015 if (curr_index == page->index) { in fuse_writepage_add()
2016 WARN_ON(tmp->ia.ap.num_pages != 1); in fuse_writepage_add()
2017 swap(tmp->ia.ap.pages[0], new_ap->pages[0]); in fuse_writepage_add()
2023 new_wpa->next = old_wpa->next; in fuse_writepage_add()
2024 old_wpa->next = new_wpa; in fuse_writepage_add()
2027 spin_unlock(&fi->lock); in fuse_writepage_add()
2030 struct backing_dev_info *bdi = inode_to_bdi(new_wpa->inode); in fuse_writepage_add()
2032 dec_wb_stat(&bdi->wb, WB_WRITEBACK); in fuse_writepage_add()
2033 dec_node_page_state(new_ap->pages[0], NR_WRITEBACK_TEMP); in fuse_writepage_add()
2034 wb_writeout_inc(&bdi->wb); in fuse_writepage_add()
2045 WARN_ON(!ap->num_pages); in fuse_writepage_need_send()
2053 if (fuse_page_is_writeback(data->inode, page->index)) in fuse_writepage_need_send()
2057 if (ap->num_pages == fc->max_pages) in fuse_writepage_need_send()
2061 if ((ap->num_pages + 1) * PAGE_SIZE > fc->max_write) in fuse_writepage_need_send()
2065 if (data->orig_pages[ap->num_pages - 1]->index + 1 != page->index) in fuse_writepage_need_send()
2069 if (ap->num_pages == data->max_pages && !fuse_pages_realloc(data)) in fuse_writepage_need_send()
2079 struct fuse_writepage_args *wpa = data->wpa; in fuse_writepages_fill()
2080 struct fuse_args_pages *ap = &wpa->ia.ap; in fuse_writepages_fill()
2081 struct inode *inode = data->inode; in fuse_writepages_fill()
2087 if (!data->ff) { in fuse_writepages_fill()
2088 err = -EIO; in fuse_writepages_fill()
2089 data->ff = fuse_write_file_get(fc, fi); in fuse_writepages_fill()
2090 if (!data->ff) in fuse_writepages_fill()
2096 data->wpa = NULL; in fuse_writepages_fill()
2099 err = -ENOMEM; in fuse_writepages_fill()
2113 * request to the fi->writepages list and increment ap->num_pages. in fuse_writepages_fill()
2117 if (data->wpa == NULL) { in fuse_writepages_fill()
2118 err = -ENOMEM; in fuse_writepages_fill()
2124 data->max_pages = 1; in fuse_writepages_fill()
2126 ap = &wpa->ia.ap; in fuse_writepages_fill()
2127 fuse_write_args_fill(&wpa->ia, data->ff, page_offset(page), 0); in fuse_writepages_fill()
2128 wpa->ia.write.in.write_flags |= FUSE_WRITE_CACHE; in fuse_writepages_fill()
2129 wpa->next = NULL; in fuse_writepages_fill()
2130 ap->args.in_pages = true; in fuse_writepages_fill()
2131 ap->args.end = fuse_writepage_end; in fuse_writepages_fill()
2132 ap->num_pages = 0; in fuse_writepages_fill()
2133 wpa->inode = inode; in fuse_writepages_fill()
2138 ap->pages[ap->num_pages] = tmp_page; in fuse_writepages_fill()
2139 ap->descs[ap->num_pages].offset = 0; in fuse_writepages_fill()
2140 ap->descs[ap->num_pages].length = PAGE_SIZE; in fuse_writepages_fill()
2141 data->orig_pages[ap->num_pages] = page; in fuse_writepages_fill()
2143 inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK); in fuse_writepages_fill()
2147 if (data->wpa) { in fuse_writepages_fill()
2149 * Protected by fi->lock against concurrent access by in fuse_writepages_fill()
2152 spin_lock(&fi->lock); in fuse_writepages_fill()
2153 ap->num_pages++; in fuse_writepages_fill()
2154 spin_unlock(&fi->lock); in fuse_writepages_fill()
2156 data->wpa = wpa; in fuse_writepages_fill()
2169 struct inode *inode = mapping->host; in fuse_writepages()
2174 err = -EIO; in fuse_writepages()
2182 err = -ENOMEM; in fuse_writepages()
2183 data.orig_pages = kcalloc(fc->max_pages, in fuse_writepages()
2191 WARN_ON(!data.wpa->ia.ap.num_pages); in fuse_writepages()
2214 int err = -ENOMEM; in fuse_write_begin()
2216 WARN_ON(!fc->writeback_cache); in fuse_write_begin()
2222 fuse_wait_on_page_writeback(mapping->host, page->index); in fuse_write_begin()
2230 fsize = i_size_read(mapping->host); in fuse_write_begin()
2255 struct inode *inode = page->mapping->host; in fuse_write_end()
2283 struct inode *inode = page->mapping->host; in fuse_launder_page()
2286 fuse_wait_on_page_writeback(inode, page->index); in fuse_launder_page()
2297 filemap_write_and_wait(vma->vm_file->f_mapping); in fuse_vma_close()
2305 * Block here, instead of in ->writepage(), so that the userspace fs
2311 * - page migration
2312 * - sync(2)
2313 * - try_to_free_pages() with order > PAGE_ALLOC_COSTLY_ORDER
2317 struct page *page = vmf->page; in fuse_page_mkwrite()
2318 struct inode *inode = file_inode(vmf->vma->vm_file); in fuse_page_mkwrite()
2320 file_update_time(vmf->vma->vm_file); in fuse_page_mkwrite()
2322 if (page->mapping != inode->i_mapping) { in fuse_page_mkwrite()
2327 fuse_wait_on_page_writeback(inode, page->index); in fuse_page_mkwrite()
2340 struct fuse_file *ff = file->private_data; in fuse_file_mmap()
2346 if (ff->open_flags & FOPEN_DIRECT_IO) { in fuse_file_mmap()
2348 if (vma->vm_flags & VM_MAYSHARE) in fuse_file_mmap()
2349 return -ENODEV; in fuse_file_mmap()
2351 invalidate_inode_pages2(file->f_mapping); in fuse_file_mmap()
2356 if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) in fuse_file_mmap()
2360 vma->vm_ops = &fuse_file_vm_ops; in fuse_file_mmap()
2368 switch (ffl->type) { in convert_fuse_file_lock()
2374 if (ffl->start > OFFSET_MAX || ffl->end > OFFSET_MAX || in convert_fuse_file_lock()
2375 ffl->end < ffl->start) in convert_fuse_file_lock()
2376 return -EIO; in convert_fuse_file_lock()
2378 fl->fl_start = ffl->start; in convert_fuse_file_lock()
2379 fl->fl_end = ffl->end; in convert_fuse_file_lock()
2386 fl->fl_pid = pid_nr_ns(find_pid_ns(ffl->pid, fc->pid_ns), &init_pid_ns); in convert_fuse_file_lock()
2391 return -EIO; in convert_fuse_file_lock()
2393 fl->fl_type = ffl->type; in convert_fuse_file_lock()
2403 struct fuse_file *ff = file->private_data; in fuse_lk_fill()
2406 inarg->fh = ff->fh; in fuse_lk_fill()
2407 inarg->owner = fuse_lock_owner_id(fc, fl->fl_owner); in fuse_lk_fill()
2408 inarg->lk.start = fl->fl_start; in fuse_lk_fill()
2409 inarg->lk.end = fl->fl_end; in fuse_lk_fill()
2410 inarg->lk.type = fl->fl_type; in fuse_lk_fill()
2411 inarg->lk.pid = pid; in fuse_lk_fill()
2413 inarg->lk_flags |= FUSE_LK_FLOCK; in fuse_lk_fill()
2414 args->opcode = opcode; in fuse_lk_fill()
2415 args->nodeid = get_node_id(inode); in fuse_lk_fill()
2416 args->in_numargs = 1; in fuse_lk_fill()
2417 args->in_args[0].size = sizeof(*inarg); in fuse_lk_fill()
2418 args->in_args[0].value = inarg; in fuse_lk_fill()
2436 err = convert_fuse_file_lock(fm->fc, &outarg.lk, fl); in fuse_getlk()
2447 int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK; in fuse_setlk()
2448 struct pid *pid = fl->fl_type != F_UNLCK ? task_tgid(current) : NULL; in fuse_setlk()
2449 pid_t pid_nr = pid_nr_ns(pid, fm->fc->pid_ns); in fuse_setlk()
2452 if (fl->fl_lmops && fl->fl_lmops->lm_grant) { in fuse_setlk()
2454 return -ENOLCK; in fuse_setlk()
2458 if ((fl->fl_flags & FL_CLOSE_POSIX) == FL_CLOSE_POSIX) in fuse_setlk()
2465 if (err == -EINTR) in fuse_setlk()
2466 err = -ERESTARTSYS; in fuse_setlk()
2480 if (fc->no_lock) { in fuse_file_lock()
2486 if (fc->no_lock) in fuse_file_lock()
2500 if (fc->no_flock) { in fuse_file_flock()
2503 struct fuse_file *ff = file->private_data; in fuse_file_flock()
2506 ff->flock = true; in fuse_file_flock()
2515 struct inode *inode = mapping->host; in fuse_bmap()
2522 if (!inode->i_sb->s_bdev || fm->fc->no_bmap) in fuse_bmap()
2527 inarg.blocksize = inode->i_sb->s_blocksize; in fuse_bmap()
2537 if (err == -ENOSYS) in fuse_bmap()
2538 fm->fc->no_bmap = 1; in fuse_bmap()
2545 struct inode *inode = file->f_mapping->host; in fuse_lseek()
2547 struct fuse_file *ff = file->private_data; in fuse_lseek()
2550 .fh = ff->fh, in fuse_lseek()
2557 if (fm->fc->no_lseek) in fuse_lseek()
2561 args.nodeid = ff->nodeid; in fuse_lseek()
2570 if (err == -ENOSYS) { in fuse_lseek()
2571 fm->fc->no_lseek = 1; in fuse_lseek()
2577 return vfs_setpos(file, outarg.offset, inode->i_sb->s_maxbytes); in fuse_lseek()
2612 retval = -EINVAL; in fuse_file_llseek()
2635 * non-compat (i.e. ones coming from 64bit apps) ioctl in fuse_copy_ioctl_iovec_old()
2639 return -EINVAL; in fuse_copy_ioctl_iovec_old()
2650 return -EIO; in fuse_copy_ioctl_iovec_old()
2661 u32 max = fc->max_pages << PAGE_SHIFT; in fuse_verify_ioctl_iov()
2664 if (iov->iov_len > (size_t) max) in fuse_verify_ioctl_iov()
2665 return -ENOMEM; in fuse_verify_ioctl_iov()
2666 max -= iov->iov_len; in fuse_verify_ioctl_iov()
2678 if (fc->minor < 16) { in fuse_copy_ioctl_iovec()
2684 return -EIO; in fuse_copy_ioctl_iovec()
2690 return -EIO; in fuse_copy_ioctl_iovec()
2699 return -EIO; in fuse_copy_ioctl_iovec()
2723 * On the first callout to FUSE server, inarg->in_size and
2724 * inarg->out_size will be NULL; then, the server completes the ioctl
2725 * with FUSE_IOCTL_RETRY set in out->flags, out->in_iovs set to 1 and
2733 * it sets FUSE_IOCTL_RETRY, out->in_iovs to 2 and iov array to
2750 * limits ioctl data transfers to well-formed ioctls and is the forced
2756 struct fuse_file *ff = file->private_data; in fuse_do_ioctl()
2757 struct fuse_mount *fm = ff->fm; in fuse_do_ioctl()
2759 .fh = ff->fh, in fuse_do_ioctl()
2789 err = -ENOMEM; in fuse_do_ioctl()
2790 ap.pages = fuse_pages_alloc(fm->fc->max_pages, GFP_KERNEL, &ap.descs); in fuse_do_ioctl()
2795 fuse_page_descs_length_init(ap.descs, 0, fm->fc->max_pages); in fuse_do_ioctl()
2798 * If restricted, initialize IO parameters as encoded in @cmd. in fuse_do_ioctl()
2804 iov->iov_base = (void __user *)arg; in fuse_do_ioctl()
2809 iov->iov_len = sizeof(int); in fuse_do_ioctl()
2812 iov->iov_len = _IOC_SIZE(cmd); in fuse_do_ioctl()
2839 err = -ENOMEM; in fuse_do_ioctl()
2840 if (max_pages > fm->fc->max_pages) in fuse_do_ioctl()
2852 ap.args.nodeid = ff->nodeid; in fuse_do_ioctl()
2861 err = -EFAULT; in fuse_do_ioctl()
2887 err = -EIO; in fuse_do_ioctl()
2898 err = -ENOMEM; in fuse_do_ioctl()
2905 err = fuse_copy_ioctl_iovec(fm->fc, iov_page, vaddr, in fuse_do_ioctl()
2915 err = fuse_verify_ioctl_iov(fm->fc, in_iov, in_iovs); in fuse_do_ioctl()
2919 err = fuse_verify_ioctl_iov(fm->fc, out_iov, out_iovs); in fuse_do_ioctl()
2926 err = -EIO; in fuse_do_ioctl()
2930 err = -EFAULT; in fuse_do_ioctl()
2941 __free_page(ap.pages[--ap.num_pages]); in fuse_do_ioctl()
2955 return -EACCES; in fuse_ioctl_common()
2958 return -EIO; in fuse_ioctl_common()
2977 * fuse_conn->polled_files which is indexed by kh. Walk the tree and
2983 struct rb_node **link = &fc->polled_files.rb_node; in fuse_find_polled_node()
2992 if (kh < ff->kh) in fuse_find_polled_node()
2993 link = &last->rb_left; in fuse_find_polled_node()
2994 else if (kh > ff->kh) in fuse_find_polled_node()
2995 link = &last->rb_right; in fuse_find_polled_node()
3014 spin_lock(&fc->lock); in fuse_register_polled_file()
3015 if (RB_EMPTY_NODE(&ff->polled_node)) { in fuse_register_polled_file()
3018 link = fuse_find_polled_node(fc, ff->kh, &parent); in fuse_register_polled_file()
3020 rb_link_node(&ff->polled_node, parent, link); in fuse_register_polled_file()
3021 rb_insert_color(&ff->polled_node, &fc->polled_files); in fuse_register_polled_file()
3023 spin_unlock(&fc->lock); in fuse_register_polled_file()
3028 struct fuse_file *ff = file->private_data; in fuse_file_poll()
3029 struct fuse_mount *fm = ff->fm; in fuse_file_poll()
3030 struct fuse_poll_in inarg = { .fh = ff->fh, .kh = ff->kh }; in fuse_file_poll()
3035 if (fm->fc->no_poll) in fuse_file_poll()
3038 poll_wait(file, &ff->poll_wait, wait); in fuse_file_poll()
3045 if (waitqueue_active(&ff->poll_wait)) { in fuse_file_poll()
3047 fuse_register_polled_file(fm->fc, ff); in fuse_file_poll()
3051 args.nodeid = ff->nodeid; in fuse_file_poll()
3062 if (err == -ENOSYS) { in fuse_file_poll()
3063 fm->fc->no_poll = 1; in fuse_file_poll()
3077 u64 kh = outarg->kh; in fuse_notify_poll_wakeup()
3080 spin_lock(&fc->lock); in fuse_notify_poll_wakeup()
3087 wake_up_interruptible_sync(&ff->poll_wait); in fuse_notify_poll_wakeup()
3090 spin_unlock(&fc->lock); in fuse_notify_poll_wakeup()
3096 struct inode *inode = file->f_mapping->host; in fuse_do_truncate()
3110 return round_up(off, fc->max_pages << PAGE_SHIFT); in fuse_round_up()
3118 struct file *file = iocb->ki_filp; in fuse_direct_IO()
3119 struct fuse_file *ff = file->private_data; in fuse_direct_IO()
3124 loff_t offset = iocb->ki_pos; in fuse_direct_IO()
3125 struct fuse_io_priv *io; in fuse_direct_IO() local
3128 inode = file->f_mapping->host; in fuse_direct_IO()
3134 io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); in fuse_direct_IO()
3135 if (!io) in fuse_direct_IO()
3136 return -ENOMEM; in fuse_direct_IO()
3137 spin_lock_init(&io->lock); in fuse_direct_IO()
3138 kref_init(&io->refcnt); in fuse_direct_IO()
3139 io->reqs = 1; in fuse_direct_IO()
3140 io->bytes = -1; in fuse_direct_IO()
3141 io->size = 0; in fuse_direct_IO()
3142 io->offset = offset; in fuse_direct_IO()
3143 io->write = (iov_iter_rw(iter) == WRITE); in fuse_direct_IO()
3144 io->err = 0; in fuse_direct_IO()
3149 io->async = ff->fm->fc->async_dio; in fuse_direct_IO()
3150 io->iocb = iocb; in fuse_direct_IO()
3151 io->blocking = is_sync_kiocb(iocb); in fuse_direct_IO()
3154 if (io->async && !io->write && offset + count > i_size) { in fuse_direct_IO()
3155 iov_iter_truncate(iter, fuse_round_up(ff->fm->fc, i_size - offset)); in fuse_direct_IO()
3156 shortened = count - iov_iter_count(iter); in fuse_direct_IO()
3157 count -= shortened; in fuse_direct_IO()
3162 * In such case the aio will behave exactly like sync io. in fuse_direct_IO()
3164 if ((offset + count > i_size) && io->write) in fuse_direct_IO()
3165 io->blocking = true; in fuse_direct_IO()
3167 if (io->async && io->blocking) { in fuse_direct_IO()
3169 * Additional reference to keep io around after in fuse_direct_IO()
3172 kref_get(&io->refcnt); in fuse_direct_IO()
3173 io->done = &wait; in fuse_direct_IO()
3177 ret = fuse_direct_io(io, iter, &pos, FUSE_DIO_WRITE); in fuse_direct_IO()
3180 ret = __fuse_direct_read(io, iter, &pos); in fuse_direct_IO()
3184 if (io->async) { in fuse_direct_IO()
3185 bool blocking = io->blocking; in fuse_direct_IO() local
3187 fuse_aio_complete(io, ret < 0 ? ret : 0, -1); in fuse_direct_IO()
3189 /* we have a non-extending, async request, so return */ in fuse_direct_IO()
3190 if (!blocking) in fuse_direct_IO()
3191 return -EIOCBQUEUED; in fuse_direct_IO()
3194 ret = fuse_get_res_by_io(io); in fuse_direct_IO()
3197 kref_put(&io->refcnt, fuse_io_release); in fuse_direct_IO()
3211 int err = filemap_write_and_wait_range(inode->i_mapping, start, end); in fuse_writeback_range()
3222 struct fuse_file *ff = file->private_data; in fuse_file_fallocate()
3225 struct fuse_mount *fm = ff->fm; in fuse_file_fallocate()
3228 .fh = ff->fh, in fuse_file_fallocate()
3240 return -EOPNOTSUPP; in fuse_file_fallocate()
3242 if (fm->fc->no_fallocate) in fuse_file_fallocate()
3243 return -EOPNOTSUPP; in fuse_file_fallocate()
3248 down_write(&fi->i_mmap_sem); in fuse_file_fallocate()
3255 loff_t endbyte = offset + length - 1; in fuse_file_fallocate()
3271 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); in fuse_file_fallocate()
3274 args.nodeid = ff->nodeid; in fuse_file_fallocate()
3279 if (err == -ENOSYS) { in fuse_file_fallocate()
3280 fm->fc->no_fallocate = 1; in fuse_file_fallocate()
3281 err = -EOPNOTSUPP; in fuse_file_fallocate()
3290 if (changed && fm->fc->writeback_cache) in fuse_file_fallocate()
3295 truncate_pagecache_range(inode, offset, offset + length - 1); in fuse_file_fallocate()
3301 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); in fuse_file_fallocate()
3304 up_write(&fi->i_mmap_sem); in fuse_file_fallocate()
3316 struct fuse_file *ff_in = file_in->private_data; in __fuse_copy_file_range()
3317 struct fuse_file *ff_out = file_out->private_data; in __fuse_copy_file_range()
3321 struct fuse_mount *fm = ff_in->fm; in __fuse_copy_file_range()
3322 struct fuse_conn *fc = fm->fc; in __fuse_copy_file_range()
3325 .fh_in = ff_in->fh, in __fuse_copy_file_range()
3327 .nodeid_out = ff_out->nodeid, in __fuse_copy_file_range()
3328 .fh_out = ff_out->fh, in __fuse_copy_file_range()
3335 /* mark unstable when write-back is not used, and file_out gets in __fuse_copy_file_range()
3337 bool is_unstable = (!fc->writeback_cache) && in __fuse_copy_file_range()
3338 ((pos_out + len) > inode_out->i_size); in __fuse_copy_file_range()
3340 if (fc->no_copy_file_range) in __fuse_copy_file_range()
3341 return -EOPNOTSUPP; in __fuse_copy_file_range()
3343 if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb) in __fuse_copy_file_range()
3344 return -EXDEV; in __fuse_copy_file_range()
3347 err = fuse_writeback_range(inode_in, pos_in, pos_in + len - 1); in __fuse_copy_file_range()
3376 err = fuse_writeback_range(inode_out, pos_out, pos_out + len - 1); in __fuse_copy_file_range()
3381 set_bit(FUSE_I_SIZE_UNSTABLE, &fi_out->state); in __fuse_copy_file_range()
3384 args.nodeid = ff_in->nodeid; in __fuse_copy_file_range()
3392 if (err == -ENOSYS) { in __fuse_copy_file_range()
3393 fc->no_copy_file_range = 1; in __fuse_copy_file_range()
3394 err = -EOPNOTSUPP; in __fuse_copy_file_range()
3399 truncate_inode_pages_range(inode_out->i_mapping, in __fuse_copy_file_range()
3401 ALIGN(pos_out + outarg.size, PAGE_SIZE) - 1); in __fuse_copy_file_range()
3403 if (fc->writeback_cache) { in __fuse_copy_file_range()
3413 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi_out->state); in __fuse_copy_file_range()
3430 if (ret == -EOPNOTSUPP || ret == -EXDEV) in fuse_copy_file_range()
3474 inode->i_fop = &fuse_file_operations; in fuse_init_file_inode()
3475 inode->i_data.a_ops = &fuse_file_aops; in fuse_init_file_inode()
3477 INIT_LIST_HEAD(&fi->write_files); in fuse_init_file_inode()
3478 INIT_LIST_HEAD(&fi->queued_writes); in fuse_init_file_inode()
3479 fi->writectr = 0; in fuse_init_file_inode()
3480 init_waitqueue_head(&fi->page_waitq); in fuse_init_file_inode()
3481 fi->writepages = RB_ROOT; in fuse_init_file_inode()