file.c (16e7483e6f02973972f832b18042fd6c45fe26c0) file.c (694565356c2e06224d94774a42709cc8dfab49ee)
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8

--- 18 unchanged lines hidden (view full) ---

27
28 pages = kzalloc(npages * (sizeof(struct page *) +
29 sizeof(struct fuse_page_desc)), flags);
30 *desc = (void *) (pages + npages);
31
32 return pages;
33}
34
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8

--- 18 unchanged lines hidden (view full) ---

27
28 pages = kzalloc(npages * (sizeof(struct page *) +
29 sizeof(struct fuse_page_desc)), flags);
30 *desc = (void *) (pages + npages);
31
32 return pages;
33}
34
35static int fuse_send_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
35static int fuse_send_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
36 int opcode, struct fuse_open_out *outargp)
37{
38 struct fuse_open_in inarg;
39 FUSE_ARGS(args);
40
41 memset(&inarg, 0, sizeof(inarg));
42 inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY);
36 int opcode, struct fuse_open_out *outargp)
37{
38 struct fuse_open_in inarg;
39 FUSE_ARGS(args);
40
41 memset(&inarg, 0, sizeof(inarg));
42 inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY);
43 if (!fc->atomic_o_trunc)
43 if (!fm->fc->atomic_o_trunc)
44 inarg.flags &= ~O_TRUNC;
45 args.opcode = opcode;
46 args.nodeid = nodeid;
47 args.in_numargs = 1;
48 args.in_args[0].size = sizeof(inarg);
49 args.in_args[0].value = &inarg;
50 args.out_numargs = 1;
51 args.out_args[0].size = sizeof(*outargp);
52 args.out_args[0].value = outargp;
53
44 inarg.flags &= ~O_TRUNC;
45 args.opcode = opcode;
46 args.nodeid = nodeid;
47 args.in_numargs = 1;
48 args.in_args[0].size = sizeof(inarg);
49 args.in_args[0].value = &inarg;
50 args.out_numargs = 1;
51 args.out_args[0].size = sizeof(*outargp);
52 args.out_args[0].value = outargp;
53
54 return fuse_simple_request(fc, &args);
54 return fuse_simple_request(fm, &args);
55}
56
57struct fuse_release_args {
58 struct fuse_args args;
59 struct fuse_release_in inarg;
60 struct inode *inode;
61};
62
55}
56
57struct fuse_release_args {
58 struct fuse_args args;
59 struct fuse_release_in inarg;
60 struct inode *inode;
61};
62
63struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
63struct fuse_file *fuse_file_alloc(struct fuse_mount *fm)
64{
65 struct fuse_file *ff;
66
67 ff = kzalloc(sizeof(struct fuse_file), GFP_KERNEL_ACCOUNT);
68 if (unlikely(!ff))
69 return NULL;
70
64{
65 struct fuse_file *ff;
66
67 ff = kzalloc(sizeof(struct fuse_file), GFP_KERNEL_ACCOUNT);
68 if (unlikely(!ff))
69 return NULL;
70
71 ff->fc = fc;
71 ff->fm = fm;
72 ff->release_args = kzalloc(sizeof(*ff->release_args),
73 GFP_KERNEL_ACCOUNT);
74 if (!ff->release_args) {
75 kfree(ff);
76 return NULL;
77 }
78
79 INIT_LIST_HEAD(&ff->write_entry);
80 mutex_init(&ff->readdir.lock);
81 refcount_set(&ff->count, 1);
82 RB_CLEAR_NODE(&ff->polled_node);
83 init_waitqueue_head(&ff->poll_wait);
84
72 ff->release_args = kzalloc(sizeof(*ff->release_args),
73 GFP_KERNEL_ACCOUNT);
74 if (!ff->release_args) {
75 kfree(ff);
76 return NULL;
77 }
78
79 INIT_LIST_HEAD(&ff->write_entry);
80 mutex_init(&ff->readdir.lock);
81 refcount_set(&ff->count, 1);
82 RB_CLEAR_NODE(&ff->polled_node);
83 init_waitqueue_head(&ff->poll_wait);
84
85 ff->kh = atomic64_inc_return(&fc->khctr);
85 ff->kh = atomic64_inc_return(&fm->fc->khctr);
86
87 return ff;
88}
89
90void fuse_file_free(struct fuse_file *ff)
91{
92 kfree(ff->release_args);
93 mutex_destroy(&ff->readdir.lock);
94 kfree(ff);
95}
96
97static struct fuse_file *fuse_file_get(struct fuse_file *ff)
98{
99 refcount_inc(&ff->count);
100 return ff;
101}
102
86
87 return ff;
88}
89
90void fuse_file_free(struct fuse_file *ff)
91{
92 kfree(ff->release_args);
93 mutex_destroy(&ff->readdir.lock);
94 kfree(ff);
95}
96
97static struct fuse_file *fuse_file_get(struct fuse_file *ff)
98{
99 refcount_inc(&ff->count);
100 return ff;
101}
102
103static void fuse_release_end(struct fuse_conn *fc, struct fuse_args *args,
103static void fuse_release_end(struct fuse_mount *fm, struct fuse_args *args,
104 int error)
105{
106 struct fuse_release_args *ra = container_of(args, typeof(*ra), args);
107
108 iput(ra->inode);
109 kfree(ra);
110}
111
112static void fuse_file_put(struct fuse_file *ff, bool sync, bool isdir)
113{
114 if (refcount_dec_and_test(&ff->count)) {
115 struct fuse_args *args = &ff->release_args->args;
116
104 int error)
105{
106 struct fuse_release_args *ra = container_of(args, typeof(*ra), args);
107
108 iput(ra->inode);
109 kfree(ra);
110}
111
112static void fuse_file_put(struct fuse_file *ff, bool sync, bool isdir)
113{
114 if (refcount_dec_and_test(&ff->count)) {
115 struct fuse_args *args = &ff->release_args->args;
116
117 if (isdir ? ff->fc->no_opendir : ff->fc->no_open) {
117 if (isdir ? ff->fm->fc->no_opendir : ff->fm->fc->no_open) {
118 /* Do nothing when client does not implement 'open' */
118 /* Do nothing when client does not implement 'open' */
119 fuse_release_end(ff->fc, args, 0);
119 fuse_release_end(ff->fm, args, 0);
120 } else if (sync) {
120 } else if (sync) {
121 fuse_simple_request(ff->fc, args);
122 fuse_release_end(ff->fc, args, 0);
121 fuse_simple_request(ff->fm, args);
122 fuse_release_end(ff->fm, args, 0);
123 } else {
124 args->end = fuse_release_end;
123 } else {
124 args->end = fuse_release_end;
125 if (fuse_simple_background(ff->fc, args,
125 if (fuse_simple_background(ff->fm, args,
126 GFP_KERNEL | __GFP_NOFAIL))
126 GFP_KERNEL | __GFP_NOFAIL))
127 fuse_release_end(ff->fc, args, -ENOTCONN);
127 fuse_release_end(ff->fm, args, -ENOTCONN);
128 }
129 kfree(ff);
130 }
131}
132
128 }
129 kfree(ff);
130 }
131}
132
133int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
133int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
134 bool isdir)
135{
134 bool isdir)
135{
136 struct fuse_conn *fc = fm->fc;
136 struct fuse_file *ff;
137 int opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN;
138
137 struct fuse_file *ff;
138 int opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN;
139
139 ff = fuse_file_alloc(fc);
140 ff = fuse_file_alloc(fm);
140 if (!ff)
141 return -ENOMEM;
142
143 ff->fh = 0;
144 /* Default for no-open */
145 ff->open_flags = FOPEN_KEEP_CACHE | (isdir ? FOPEN_CACHE_DIR : 0);
146 if (isdir ? !fc->no_opendir : !fc->no_open) {
147 struct fuse_open_out outarg;
148 int err;
149
141 if (!ff)
142 return -ENOMEM;
143
144 ff->fh = 0;
145 /* Default for no-open */
146 ff->open_flags = FOPEN_KEEP_CACHE | (isdir ? FOPEN_CACHE_DIR : 0);
147 if (isdir ? !fc->no_opendir : !fc->no_open) {
148 struct fuse_open_out outarg;
149 int err;
150
150 err = fuse_send_open(fc, nodeid, file, opcode, &outarg);
151 err = fuse_send_open(fm, nodeid, file, opcode, &outarg);
151 if (!err) {
152 ff->fh = outarg.fh;
153 ff->open_flags = outarg.open_flags;
154
155 } else if (err != -ENOSYS) {
156 fuse_file_free(ff);
157 return err;
158 } else {

--- 52 unchanged lines hidden (view full) ---

211 file_update_time(file);
212 }
213 if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache)
214 fuse_link_write_file(file);
215}
216
217int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
218{
152 if (!err) {
153 ff->fh = outarg.fh;
154 ff->open_flags = outarg.open_flags;
155
156 } else if (err != -ENOSYS) {
157 fuse_file_free(ff);
158 return err;
159 } else {

--- 52 unchanged lines hidden (view full) ---

212 file_update_time(file);
213 }
214 if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache)
215 fuse_link_write_file(file);
216}
217
218int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
219{
219 struct fuse_conn *fc = get_fuse_conn(inode);
220 struct fuse_mount *fm = get_fuse_mount(inode);
221 struct fuse_conn *fc = fm->fc;
220 int err;
221 bool is_wb_truncate = (file->f_flags & O_TRUNC) &&
222 fc->atomic_o_trunc &&
223 fc->writeback_cache;
222 int err;
223 bool is_wb_truncate = (file->f_flags & O_TRUNC) &&
224 fc->atomic_o_trunc &&
225 fc->writeback_cache;
226 bool dax_truncate = (file->f_flags & O_TRUNC) &&
227 fc->atomic_o_trunc && FUSE_IS_DAX(inode);
224
225 err = generic_file_open(inode, file);
226 if (err)
227 return err;
228
228
229 err = generic_file_open(inode, file);
230 if (err)
231 return err;
232
229 if (is_wb_truncate) {
233 if (is_wb_truncate || dax_truncate) {
230 inode_lock(inode);
231 fuse_set_nowrite(inode);
232 }
233
234 inode_lock(inode);
235 fuse_set_nowrite(inode);
236 }
237
234 err = fuse_do_open(fc, get_node_id(inode), file, isdir);
238 if (dax_truncate) {
239 down_write(&get_fuse_inode(inode)->i_mmap_sem);
240 err = fuse_dax_break_layouts(inode, 0, 0);
241 if (err)
242 goto out;
243 }
235
244
245 err = fuse_do_open(fm, get_node_id(inode), file, isdir);
236 if (!err)
237 fuse_finish_open(inode, file);
238
246 if (!err)
247 fuse_finish_open(inode, file);
248
239 if (is_wb_truncate) {
249out:
250 if (dax_truncate)
251 up_write(&get_fuse_inode(inode)->i_mmap_sem);
252
253 if (is_wb_truncate | dax_truncate) {
240 fuse_release_nowrite(inode);
241 inode_unlock(inode);
242 }
243
244 return err;
245}
246
247static void fuse_prepare_release(struct fuse_inode *fi, struct fuse_file *ff,
248 int flags, int opcode)
249{
254 fuse_release_nowrite(inode);
255 inode_unlock(inode);
256 }
257
258 return err;
259}
260
261static void fuse_prepare_release(struct fuse_inode *fi, struct fuse_file *ff,
262 int flags, int opcode)
263{
250 struct fuse_conn *fc = ff->fc;
264 struct fuse_conn *fc = ff->fm->fc;
251 struct fuse_release_args *ra = ff->release_args;
252
253 /* Inode is NULL on error path of fuse_create_open() */
254 if (likely(fi)) {
255 spin_lock(&fi->lock);
256 list_del(&ff->write_entry);
257 spin_unlock(&fi->lock);
258 }

--- 21 unchanged lines hidden (view full) ---

280 struct fuse_file *ff = file->private_data;
281 struct fuse_release_args *ra = ff->release_args;
282 int opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;
283
284 fuse_prepare_release(fi, ff, file->f_flags, opcode);
285
286 if (ff->flock) {
287 ra->inarg.release_flags |= FUSE_RELEASE_FLOCK_UNLOCK;
265 struct fuse_release_args *ra = ff->release_args;
266
267 /* Inode is NULL on error path of fuse_create_open() */
268 if (likely(fi)) {
269 spin_lock(&fi->lock);
270 list_del(&ff->write_entry);
271 spin_unlock(&fi->lock);
272 }

--- 21 unchanged lines hidden (view full) ---

294 struct fuse_file *ff = file->private_data;
295 struct fuse_release_args *ra = ff->release_args;
296 int opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;
297
298 fuse_prepare_release(fi, ff, file->f_flags, opcode);
299
300 if (ff->flock) {
301 ra->inarg.release_flags |= FUSE_RELEASE_FLOCK_UNLOCK;
288 ra->inarg.lock_owner = fuse_lock_owner_id(ff->fc,
302 ra->inarg.lock_owner = fuse_lock_owner_id(ff->fm->fc,
289 (fl_owner_t) file);
290 }
291 /* Hold inode until release is finished */
292 ra->inode = igrab(file_inode(file));
293
294 /*
295 * Normally this will send the RELEASE request, however if
296 * some asynchronous READ or WRITE requests are outstanding,
297 * the sending will be delayed.
298 *
299 * Make the release synchronous if this is a fuseblk mount,
300 * synchronous RELEASE is allowed (and desirable) in this case
301 * because the server can be trusted not to screw up.
302 */
303 (fl_owner_t) file);
304 }
305 /* Hold inode until release is finished */
306 ra->inode = igrab(file_inode(file));
307
308 /*
309 * Normally this will send the RELEASE request, however if
310 * some asynchronous READ or WRITE requests are outstanding,
311 * the sending will be delayed.
312 *
313 * Make the release synchronous if this is a fuseblk mount,
314 * synchronous RELEASE is allowed (and desirable) in this case
315 * because the server can be trusted not to screw up.
316 */
303 fuse_file_put(ff, ff->fc->destroy, isdir);
317 fuse_file_put(ff, ff->fm->fc->destroy, isdir);
304}
305
306static int fuse_open(struct inode *inode, struct file *file)
307{
308 return fuse_open_common(inode, file, false);
309}
310
311static int fuse_release(struct inode *inode, struct file *file)

--- 126 unchanged lines hidden (view full) ---

438{
439 fuse_set_nowrite(inode);
440 fuse_release_nowrite(inode);
441}
442
443static int fuse_flush(struct file *file, fl_owner_t id)
444{
445 struct inode *inode = file_inode(file);
318}
319
320static int fuse_open(struct inode *inode, struct file *file)
321{
322 return fuse_open_common(inode, file, false);
323}
324
325static int fuse_release(struct inode *inode, struct file *file)

--- 126 unchanged lines hidden (view full) ---

452{
453 fuse_set_nowrite(inode);
454 fuse_release_nowrite(inode);
455}
456
457static int fuse_flush(struct file *file, fl_owner_t id)
458{
459 struct inode *inode = file_inode(file);
446 struct fuse_conn *fc = get_fuse_conn(inode);
460 struct fuse_mount *fm = get_fuse_mount(inode);
447 struct fuse_file *ff = file->private_data;
448 struct fuse_flush_in inarg;
449 FUSE_ARGS(args);
450 int err;
451
452 if (is_bad_inode(inode))
453 return -EIO;
454

--- 5 unchanged lines hidden (view full) ---

460 fuse_sync_writes(inode);
461 inode_unlock(inode);
462
463 err = filemap_check_errors(file->f_mapping);
464 if (err)
465 return err;
466
467 err = 0;
461 struct fuse_file *ff = file->private_data;
462 struct fuse_flush_in inarg;
463 FUSE_ARGS(args);
464 int err;
465
466 if (is_bad_inode(inode))
467 return -EIO;
468

--- 5 unchanged lines hidden (view full) ---

474 fuse_sync_writes(inode);
475 inode_unlock(inode);
476
477 err = filemap_check_errors(file->f_mapping);
478 if (err)
479 return err;
480
481 err = 0;
468 if (fc->no_flush)
482 if (fm->fc->no_flush)
469 goto inval_attr_out;
470
471 memset(&inarg, 0, sizeof(inarg));
472 inarg.fh = ff->fh;
483 goto inval_attr_out;
484
485 memset(&inarg, 0, sizeof(inarg));
486 inarg.fh = ff->fh;
473 inarg.lock_owner = fuse_lock_owner_id(fc, id);
487 inarg.lock_owner = fuse_lock_owner_id(fm->fc, id);
474 args.opcode = FUSE_FLUSH;
475 args.nodeid = get_node_id(inode);
476 args.in_numargs = 1;
477 args.in_args[0].size = sizeof(inarg);
478 args.in_args[0].value = &inarg;
479 args.force = true;
480
488 args.opcode = FUSE_FLUSH;
489 args.nodeid = get_node_id(inode);
490 args.in_numargs = 1;
491 args.in_args[0].size = sizeof(inarg);
492 args.in_args[0].value = &inarg;
493 args.force = true;
494
481 err = fuse_simple_request(fc, &args);
495 err = fuse_simple_request(fm, &args);
482 if (err == -ENOSYS) {
496 if (err == -ENOSYS) {
483 fc->no_flush = 1;
497 fm->fc->no_flush = 1;
484 err = 0;
485 }
486
487inval_attr_out:
488 /*
489 * In memory i_blocks is not maintained by fuse, if writeback cache is
490 * enabled, i_blocks from cached attr may not be accurate.
491 */
498 err = 0;
499 }
500
501inval_attr_out:
502 /*
503 * In memory i_blocks is not maintained by fuse, if writeback cache is
504 * enabled, i_blocks from cached attr may not be accurate.
505 */
492 if (!err && fc->writeback_cache)
506 if (!err && fm->fc->writeback_cache)
493 fuse_invalidate_attr(inode);
494 return err;
495}
496
497int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
498 int datasync, int opcode)
499{
500 struct inode *inode = file->f_mapping->host;
507 fuse_invalidate_attr(inode);
508 return err;
509}
510
511int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
512 int datasync, int opcode)
513{
514 struct inode *inode = file->f_mapping->host;
501 struct fuse_conn *fc = get_fuse_conn(inode);
515 struct fuse_mount *fm = get_fuse_mount(inode);
502 struct fuse_file *ff = file->private_data;
503 FUSE_ARGS(args);
504 struct fuse_fsync_in inarg;
505
506 memset(&inarg, 0, sizeof(inarg));
507 inarg.fh = ff->fh;
508 inarg.fsync_flags = datasync ? FUSE_FSYNC_FDATASYNC : 0;
509 args.opcode = opcode;
510 args.nodeid = get_node_id(inode);
511 args.in_numargs = 1;
512 args.in_args[0].size = sizeof(inarg);
513 args.in_args[0].value = &inarg;
516 struct fuse_file *ff = file->private_data;
517 FUSE_ARGS(args);
518 struct fuse_fsync_in inarg;
519
520 memset(&inarg, 0, sizeof(inarg));
521 inarg.fh = ff->fh;
522 inarg.fsync_flags = datasync ? FUSE_FSYNC_FDATASYNC : 0;
523 args.opcode = opcode;
524 args.nodeid = get_node_id(inode);
525 args.in_numargs = 1;
526 args.in_args[0].size = sizeof(inarg);
527 args.in_args[0].value = &inarg;
514 return fuse_simple_request(fc, &args);
528 return fuse_simple_request(fm, &args);
515}
516
517static int fuse_fsync(struct file *file, loff_t start, loff_t end,
518 int datasync)
519{
520 struct inode *inode = file->f_mapping->host;
521 struct fuse_conn *fc = get_fuse_conn(inode);
522 int err;

--- 158 unchanged lines hidden (view full) ---

681}
682
683static void fuse_io_free(struct fuse_io_args *ia)
684{
685 kfree(ia->ap.pages);
686 kfree(ia);
687}
688
529}
530
531static int fuse_fsync(struct file *file, loff_t start, loff_t end,
532 int datasync)
533{
534 struct inode *inode = file->f_mapping->host;
535 struct fuse_conn *fc = get_fuse_conn(inode);
536 int err;

--- 158 unchanged lines hidden (view full) ---

695}
696
697static void fuse_io_free(struct fuse_io_args *ia)
698{
699 kfree(ia->ap.pages);
700 kfree(ia);
701}
702
689static void fuse_aio_complete_req(struct fuse_conn *fc, struct fuse_args *args,
703static void fuse_aio_complete_req(struct fuse_mount *fm, struct fuse_args *args,
690 int err)
691{
692 struct fuse_io_args *ia = container_of(args, typeof(*ia), ap.args);
693 struct fuse_io_priv *io = ia->io;
694 ssize_t pos = -1;
695
696 fuse_release_user_pages(&ia->ap, io->should_dirty);
697

--- 12 unchanged lines hidden (view full) ---

710 if (ia->read.in.size != outsize)
711 pos = ia->read.in.offset - io->offset + outsize;
712 }
713
714 fuse_aio_complete(io, err, pos);
715 fuse_io_free(ia);
716}
717
704 int err)
705{
706 struct fuse_io_args *ia = container_of(args, typeof(*ia), ap.args);
707 struct fuse_io_priv *io = ia->io;
708 ssize_t pos = -1;
709
710 fuse_release_user_pages(&ia->ap, io->should_dirty);
711

--- 12 unchanged lines hidden (view full) ---

724 if (ia->read.in.size != outsize)
725 pos = ia->read.in.offset - io->offset + outsize;
726 }
727
728 fuse_aio_complete(io, err, pos);
729 fuse_io_free(ia);
730}
731
718static ssize_t fuse_async_req_send(struct fuse_conn *fc,
732static ssize_t fuse_async_req_send(struct fuse_mount *fm,
719 struct fuse_io_args *ia, size_t num_bytes)
720{
721 ssize_t err;
722 struct fuse_io_priv *io = ia->io;
723
724 spin_lock(&io->lock);
725 kref_get(&io->refcnt);
726 io->size += num_bytes;
727 io->reqs++;
728 spin_unlock(&io->lock);
729
730 ia->ap.args.end = fuse_aio_complete_req;
731 ia->ap.args.may_block = io->should_dirty;
733 struct fuse_io_args *ia, size_t num_bytes)
734{
735 ssize_t err;
736 struct fuse_io_priv *io = ia->io;
737
738 spin_lock(&io->lock);
739 kref_get(&io->refcnt);
740 io->size += num_bytes;
741 io->reqs++;
742 spin_unlock(&io->lock);
743
744 ia->ap.args.end = fuse_aio_complete_req;
745 ia->ap.args.may_block = io->should_dirty;
732 err = fuse_simple_background(fc, &ia->ap.args, GFP_KERNEL);
746 err = fuse_simple_background(fm, &ia->ap.args, GFP_KERNEL);
733 if (err)
747 if (err)
734 fuse_aio_complete_req(fc, &ia->ap.args, err);
748 fuse_aio_complete_req(fm, &ia->ap.args, err);
735
736 return num_bytes;
737}
738
739static ssize_t fuse_send_read(struct fuse_io_args *ia, loff_t pos, size_t count,
740 fl_owner_t owner)
741{
742 struct file *file = ia->io->iocb->ki_filp;
743 struct fuse_file *ff = file->private_data;
749
750 return num_bytes;
751}
752
753static ssize_t fuse_send_read(struct fuse_io_args *ia, loff_t pos, size_t count,
754 fl_owner_t owner)
755{
756 struct file *file = ia->io->iocb->ki_filp;
757 struct fuse_file *ff = file->private_data;
744 struct fuse_conn *fc = ff->fc;
758 struct fuse_mount *fm = ff->fm;
745
746 fuse_read_args_fill(ia, file, pos, count, FUSE_READ);
747 if (owner != NULL) {
748 ia->read.in.read_flags |= FUSE_READ_LOCKOWNER;
759
760 fuse_read_args_fill(ia, file, pos, count, FUSE_READ);
761 if (owner != NULL) {
762 ia->read.in.read_flags |= FUSE_READ_LOCKOWNER;
749 ia->read.in.lock_owner = fuse_lock_owner_id(fc, owner);
763 ia->read.in.lock_owner = fuse_lock_owner_id(fm->fc, owner);
750 }
751
752 if (ia->io->async)
764 }
765
766 if (ia->io->async)
753 return fuse_async_req_send(fc, ia, count);
767 return fuse_async_req_send(fm, ia, count);
754
768
755 return fuse_simple_request(fc, &ia->ap.args);
769 return fuse_simple_request(fm, &ia->ap.args);
756}
757
758static void fuse_read_update_size(struct inode *inode, loff_t size,
759 u64 attr_ver)
760{
761 struct fuse_conn *fc = get_fuse_conn(inode);
762 struct fuse_inode *fi = get_fuse_inode(inode);
763

--- 29 unchanged lines hidden (view full) ---

793 loff_t pos = page_offset(ap->pages[0]) + num_read;
794 fuse_read_update_size(inode, pos, attr_ver);
795 }
796}
797
798static int fuse_do_readpage(struct file *file, struct page *page)
799{
800 struct inode *inode = page->mapping->host;
770}
771
772static void fuse_read_update_size(struct inode *inode, loff_t size,
773 u64 attr_ver)
774{
775 struct fuse_conn *fc = get_fuse_conn(inode);
776 struct fuse_inode *fi = get_fuse_inode(inode);
777

--- 29 unchanged lines hidden (view full) ---

807 loff_t pos = page_offset(ap->pages[0]) + num_read;
808 fuse_read_update_size(inode, pos, attr_ver);
809 }
810}
811
812static int fuse_do_readpage(struct file *file, struct page *page)
813{
814 struct inode *inode = page->mapping->host;
801 struct fuse_conn *fc = get_fuse_conn(inode);
815 struct fuse_mount *fm = get_fuse_mount(inode);
802 loff_t pos = page_offset(page);
803 struct fuse_page_desc desc = { .length = PAGE_SIZE };
804 struct fuse_io_args ia = {
805 .ap.args.page_zeroing = true,
806 .ap.args.out_pages = true,
807 .ap.num_pages = 1,
808 .ap.pages = &page,
809 .ap.descs = &desc,
810 };
811 ssize_t res;
812 u64 attr_ver;
813
814 /*
815 * Page writeback can extend beyond the lifetime of the
816 * page-cache page, so make sure we read a properly synced
817 * page.
818 */
819 fuse_wait_on_page_writeback(inode, page->index);
820
816 loff_t pos = page_offset(page);
817 struct fuse_page_desc desc = { .length = PAGE_SIZE };
818 struct fuse_io_args ia = {
819 .ap.args.page_zeroing = true,
820 .ap.args.out_pages = true,
821 .ap.num_pages = 1,
822 .ap.pages = &page,
823 .ap.descs = &desc,
824 };
825 ssize_t res;
826 u64 attr_ver;
827
828 /*
829 * Page writeback can extend beyond the lifetime of the
830 * page-cache page, so make sure we read a properly synced
831 * page.
832 */
833 fuse_wait_on_page_writeback(inode, page->index);
834
821 attr_ver = fuse_get_attr_version(fc);
835 attr_ver = fuse_get_attr_version(fm->fc);
822
823 /* Don't overflow end offset */
824 if (pos + (desc.length - 1) == LLONG_MAX)
825 desc.length--;
826
827 fuse_read_args_fill(&ia, file, pos, desc.length, FUSE_READ);
836
837 /* Don't overflow end offset */
838 if (pos + (desc.length - 1) == LLONG_MAX)
839 desc.length--;
840
841 fuse_read_args_fill(&ia, file, pos, desc.length, FUSE_READ);
828 res = fuse_simple_request(fc, &ia.ap.args);
842 res = fuse_simple_request(fm, &ia.ap.args);
829 if (res < 0)
830 return res;
831 /*
832 * Short read means EOF. If file size is larger, truncate it
833 */
834 if (res < desc.length)
835 fuse_short_read(inode, attr_ver, res, &ia.ap);
836

--- 13 unchanged lines hidden (view full) ---

850
851 err = fuse_do_readpage(file, page);
852 fuse_invalidate_atime(inode);
853 out:
854 unlock_page(page);
855 return err;
856}
857
843 if (res < 0)
844 return res;
845 /*
846 * Short read means EOF. If file size is larger, truncate it
847 */
848 if (res < desc.length)
849 fuse_short_read(inode, attr_ver, res, &ia.ap);
850

--- 13 unchanged lines hidden (view full) ---

864
865 err = fuse_do_readpage(file, page);
866 fuse_invalidate_atime(inode);
867 out:
868 unlock_page(page);
869 return err;
870}
871
858static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_args *args,
872static void fuse_readpages_end(struct fuse_mount *fm, struct fuse_args *args,
859 int err)
860{
861 int i;
862 struct fuse_io_args *ia = container_of(args, typeof(*ia), ap.args);
863 struct fuse_args_pages *ap = &ia->ap;
864 size_t count = ia->read.in.size;
865 size_t num_read = args->out_args[0].size;
866 struct address_space *mapping = NULL;

--- 27 unchanged lines hidden (view full) ---

894 fuse_file_put(ia->ff, false, false);
895
896 fuse_io_free(ia);
897}
898
899static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file)
900{
901 struct fuse_file *ff = file->private_data;
873 int err)
874{
875 int i;
876 struct fuse_io_args *ia = container_of(args, typeof(*ia), ap.args);
877 struct fuse_args_pages *ap = &ia->ap;
878 size_t count = ia->read.in.size;
879 size_t num_read = args->out_args[0].size;
880 struct address_space *mapping = NULL;

--- 27 unchanged lines hidden (view full) ---

908 fuse_file_put(ia->ff, false, false);
909
910 fuse_io_free(ia);
911}
912
913static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file)
914{
915 struct fuse_file *ff = file->private_data;
902 struct fuse_conn *fc = ff->fc;
916 struct fuse_mount *fm = ff->fm;
903 struct fuse_args_pages *ap = &ia->ap;
904 loff_t pos = page_offset(ap->pages[0]);
905 size_t count = ap->num_pages << PAGE_SHIFT;
906 ssize_t res;
907 int err;
908
909 ap->args.out_pages = true;
910 ap->args.page_zeroing = true;
911 ap->args.page_replace = true;
912
913 /* Don't overflow end offset */
914 if (pos + (count - 1) == LLONG_MAX) {
915 count--;
916 ap->descs[ap->num_pages - 1].length--;
917 }
918 WARN_ON((loff_t) (pos + count) < 0);
919
920 fuse_read_args_fill(ia, file, pos, count, FUSE_READ);
917 struct fuse_args_pages *ap = &ia->ap;
918 loff_t pos = page_offset(ap->pages[0]);
919 size_t count = ap->num_pages << PAGE_SHIFT;
920 ssize_t res;
921 int err;
922
923 ap->args.out_pages = true;
924 ap->args.page_zeroing = true;
925 ap->args.page_replace = true;
926
927 /* Don't overflow end offset */
928 if (pos + (count - 1) == LLONG_MAX) {
929 count--;
930 ap->descs[ap->num_pages - 1].length--;
931 }
932 WARN_ON((loff_t) (pos + count) < 0);
933
934 fuse_read_args_fill(ia, file, pos, count, FUSE_READ);
921 ia->read.attr_ver = fuse_get_attr_version(fc);
922 if (fc->async_read) {
935 ia->read.attr_ver = fuse_get_attr_version(fm->fc);
936 if (fm->fc->async_read) {
923 ia->ff = fuse_file_get(ff);
924 ap->args.end = fuse_readpages_end;
937 ia->ff = fuse_file_get(ff);
938 ap->args.end = fuse_readpages_end;
925 err = fuse_simple_background(fc, &ap->args, GFP_KERNEL);
939 err = fuse_simple_background(fm, &ap->args, GFP_KERNEL);
926 if (!err)
927 return;
928 } else {
940 if (!err)
941 return;
942 } else {
929 res = fuse_simple_request(fc, &ap->args);
943 res = fuse_simple_request(fm, &ap->args);
930 err = res < 0 ? res : 0;
931 }
944 err = res < 0 ? res : 0;
945 }
932 fuse_readpages_end(fc, &ap->args, err);
946 fuse_readpages_end(fm, &ap->args, err);
933}
934
935static void fuse_readahead(struct readahead_control *rac)
936{
937 struct inode *inode = rac->mapping->host;
938 struct fuse_conn *fc = get_fuse_conn(inode);
939 unsigned int i, max_pages, nr_pages = 0;
940

--- 54 unchanged lines hidden (view full) ---

995 struct fuse_args *args = &ia->ap.args;
996
997 ia->write.in.fh = ff->fh;
998 ia->write.in.offset = pos;
999 ia->write.in.size = count;
1000 args->opcode = FUSE_WRITE;
1001 args->nodeid = ff->nodeid;
1002 args->in_numargs = 2;
947}
948
949static void fuse_readahead(struct readahead_control *rac)
950{
951 struct inode *inode = rac->mapping->host;
952 struct fuse_conn *fc = get_fuse_conn(inode);
953 unsigned int i, max_pages, nr_pages = 0;
954

--- 54 unchanged lines hidden (view full) ---

1009 struct fuse_args *args = &ia->ap.args;
1010
1011 ia->write.in.fh = ff->fh;
1012 ia->write.in.offset = pos;
1013 ia->write.in.size = count;
1014 args->opcode = FUSE_WRITE;
1015 args->nodeid = ff->nodeid;
1016 args->in_numargs = 2;
1003 if (ff->fc->minor < 9)
1017 if (ff->fm->fc->minor < 9)
1004 args->in_args[0].size = FUSE_COMPAT_WRITE_IN_SIZE;
1005 else
1006 args->in_args[0].size = sizeof(ia->write.in);
1007 args->in_args[0].value = &ia->write.in;
1008 args->in_args[1].size = count;
1009 args->out_numargs = 1;
1010 args->out_args[0].size = sizeof(ia->write.out);
1011 args->out_args[0].value = &ia->write.out;

--- 12 unchanged lines hidden (view full) ---

1024}
1025
1026static ssize_t fuse_send_write(struct fuse_io_args *ia, loff_t pos,
1027 size_t count, fl_owner_t owner)
1028{
1029 struct kiocb *iocb = ia->io->iocb;
1030 struct file *file = iocb->ki_filp;
1031 struct fuse_file *ff = file->private_data;
1018 args->in_args[0].size = FUSE_COMPAT_WRITE_IN_SIZE;
1019 else
1020 args->in_args[0].size = sizeof(ia->write.in);
1021 args->in_args[0].value = &ia->write.in;
1022 args->in_args[1].size = count;
1023 args->out_numargs = 1;
1024 args->out_args[0].size = sizeof(ia->write.out);
1025 args->out_args[0].value = &ia->write.out;

--- 12 unchanged lines hidden (view full) ---

1038}
1039
1040static ssize_t fuse_send_write(struct fuse_io_args *ia, loff_t pos,
1041 size_t count, fl_owner_t owner)
1042{
1043 struct kiocb *iocb = ia->io->iocb;
1044 struct file *file = iocb->ki_filp;
1045 struct fuse_file *ff = file->private_data;
1032 struct fuse_conn *fc = ff->fc;
1046 struct fuse_mount *fm = ff->fm;
1033 struct fuse_write_in *inarg = &ia->write.in;
1034 ssize_t err;
1035
1036 fuse_write_args_fill(ia, ff, pos, count);
1037 inarg->flags = fuse_write_flags(iocb);
1038 if (owner != NULL) {
1039 inarg->write_flags |= FUSE_WRITE_LOCKOWNER;
1047 struct fuse_write_in *inarg = &ia->write.in;
1048 ssize_t err;
1049
1050 fuse_write_args_fill(ia, ff, pos, count);
1051 inarg->flags = fuse_write_flags(iocb);
1052 if (owner != NULL) {
1053 inarg->write_flags |= FUSE_WRITE_LOCKOWNER;
1040 inarg->lock_owner = fuse_lock_owner_id(fc, owner);
1054 inarg->lock_owner = fuse_lock_owner_id(fm->fc, owner);
1041 }
1042
1043 if (ia->io->async)
1055 }
1056
1057 if (ia->io->async)
1044 return fuse_async_req_send(fc, ia, count);
1058 return fuse_async_req_send(fm, ia, count);
1045
1059
1046 err = fuse_simple_request(fc, &ia->ap.args);
1060 err = fuse_simple_request(fm, &ia->ap.args);
1047 if (!err && ia->write.out.size > count)
1048 err = -EIO;
1049
1050 return err ?: ia->write.out.size;
1051}
1052
1053bool fuse_write_update_size(struct inode *inode, loff_t pos)
1054{

--- 14 unchanged lines hidden (view full) ---

1069
1070static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
1071 struct kiocb *iocb, struct inode *inode,
1072 loff_t pos, size_t count)
1073{
1074 struct fuse_args_pages *ap = &ia->ap;
1075 struct file *file = iocb->ki_filp;
1076 struct fuse_file *ff = file->private_data;
1061 if (!err && ia->write.out.size > count)
1062 err = -EIO;
1063
1064 return err ?: ia->write.out.size;
1065}
1066
1067bool fuse_write_update_size(struct inode *inode, loff_t pos)
1068{

--- 14 unchanged lines hidden (view full) ---

1083
1084static ssize_t fuse_send_write_pages(struct fuse_io_args *ia,
1085 struct kiocb *iocb, struct inode *inode,
1086 loff_t pos, size_t count)
1087{
1088 struct fuse_args_pages *ap = &ia->ap;
1089 struct file *file = iocb->ki_filp;
1090 struct fuse_file *ff = file->private_data;
1077 struct fuse_conn *fc = ff->fc;
1091 struct fuse_mount *fm = ff->fm;
1078 unsigned int offset, i;
1079 int err;
1080
1081 for (i = 0; i < ap->num_pages; i++)
1082 fuse_wait_on_page_writeback(inode, ap->pages[i]->index);
1083
1084 fuse_write_args_fill(ia, ff, pos, count);
1085 ia->write.in.flags = fuse_write_flags(iocb);
1086
1092 unsigned int offset, i;
1093 int err;
1094
1095 for (i = 0; i < ap->num_pages; i++)
1096 fuse_wait_on_page_writeback(inode, ap->pages[i]->index);
1097
1098 fuse_write_args_fill(ia, ff, pos, count);
1099 ia->write.in.flags = fuse_write_flags(iocb);
1100
1087 err = fuse_simple_request(fc, &ap->args);
1101 err = fuse_simple_request(fm, &ap->args);
1088 if (!err && ia->write.out.size > count)
1089 err = -EIO;
1090
1091 offset = ap->descs[0].offset;
1092 count = ia->write.out.size;
1093 for (i = 0; i < ap->num_pages; i++) {
1094 struct page *page = ap->pages[i];
1095

--- 298 unchanged lines hidden (view full) ---

1394ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1395 loff_t *ppos, int flags)
1396{
1397 int write = flags & FUSE_DIO_WRITE;
1398 int cuse = flags & FUSE_DIO_CUSE;
1399 struct file *file = io->iocb->ki_filp;
1400 struct inode *inode = file->f_mapping->host;
1401 struct fuse_file *ff = file->private_data;
1102 if (!err && ia->write.out.size > count)
1103 err = -EIO;
1104
1105 offset = ap->descs[0].offset;
1106 count = ia->write.out.size;
1107 for (i = 0; i < ap->num_pages; i++) {
1108 struct page *page = ap->pages[i];
1109

--- 298 unchanged lines hidden (view full) ---

1408ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1409 loff_t *ppos, int flags)
1410{
1411 int write = flags & FUSE_DIO_WRITE;
1412 int cuse = flags & FUSE_DIO_CUSE;
1413 struct file *file = io->iocb->ki_filp;
1414 struct inode *inode = file->f_mapping->host;
1415 struct fuse_file *ff = file->private_data;
1402 struct fuse_conn *fc = ff->fc;
1416 struct fuse_conn *fc = ff->fm->fc;
1403 size_t nmax = write ? fc->max_write : fc->max_read;
1404 loff_t pos = *ppos;
1405 size_t count = iov_iter_count(iter);
1406 pgoff_t idx_from = pos >> PAGE_SHIFT;
1407 pgoff_t idx_to = (pos + count - 1) >> PAGE_SHIFT;
1408 ssize_t res = 0;
1409 int err = 0;
1410 struct fuse_io_args *ia;

--- 123 unchanged lines hidden (view full) ---

1534
1535 return res;
1536}
1537
1538static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
1539{
1540 struct file *file = iocb->ki_filp;
1541 struct fuse_file *ff = file->private_data;
1417 size_t nmax = write ? fc->max_write : fc->max_read;
1418 loff_t pos = *ppos;
1419 size_t count = iov_iter_count(iter);
1420 pgoff_t idx_from = pos >> PAGE_SHIFT;
1421 pgoff_t idx_to = (pos + count - 1) >> PAGE_SHIFT;
1422 ssize_t res = 0;
1423 int err = 0;
1424 struct fuse_io_args *ia;

--- 123 unchanged lines hidden (view full) ---

1548
1549 return res;
1550}
1551
1552static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
1553{
1554 struct file *file = iocb->ki_filp;
1555 struct fuse_file *ff = file->private_data;
1556 struct inode *inode = file_inode(file);
1542
1557
1543 if (is_bad_inode(file_inode(file)))
1558 if (is_bad_inode(inode))
1544 return -EIO;
1545
1559 return -EIO;
1560
1561 if (FUSE_IS_DAX(inode))
1562 return fuse_dax_read_iter(iocb, to);
1563
1546 if (!(ff->open_flags & FOPEN_DIRECT_IO))
1547 return fuse_cache_read_iter(iocb, to);
1548 else
1549 return fuse_direct_read_iter(iocb, to);
1550}
1551
1552static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1553{
1554 struct file *file = iocb->ki_filp;
1555 struct fuse_file *ff = file->private_data;
1564 if (!(ff->open_flags & FOPEN_DIRECT_IO))
1565 return fuse_cache_read_iter(iocb, to);
1566 else
1567 return fuse_direct_read_iter(iocb, to);
1568}
1569
1570static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1571{
1572 struct file *file = iocb->ki_filp;
1573 struct fuse_file *ff = file->private_data;
1574 struct inode *inode = file_inode(file);
1556
1575
1557 if (is_bad_inode(file_inode(file)))
1576 if (is_bad_inode(inode))
1558 return -EIO;
1559
1577 return -EIO;
1578
1579 if (FUSE_IS_DAX(inode))
1580 return fuse_dax_write_iter(iocb, from);
1581
1560 if (!(ff->open_flags & FOPEN_DIRECT_IO))
1561 return fuse_cache_write_iter(iocb, from);
1562 else
1563 return fuse_direct_write_iter(iocb, from);
1564}
1565
1566static void fuse_writepage_free(struct fuse_writepage_args *wpa)
1567{

--- 5 unchanged lines hidden (view full) ---

1573
1574 if (wpa->ia.ff)
1575 fuse_file_put(wpa->ia.ff, false, false);
1576
1577 kfree(ap->pages);
1578 kfree(wpa);
1579}
1580
1582 if (!(ff->open_flags & FOPEN_DIRECT_IO))
1583 return fuse_cache_write_iter(iocb, from);
1584 else
1585 return fuse_direct_write_iter(iocb, from);
1586}
1587
1588static void fuse_writepage_free(struct fuse_writepage_args *wpa)
1589{

--- 5 unchanged lines hidden (view full) ---

1595
1596 if (wpa->ia.ff)
1597 fuse_file_put(wpa->ia.ff, false, false);
1598
1599 kfree(ap->pages);
1600 kfree(wpa);
1601}
1602
1581static void fuse_writepage_finish(struct fuse_conn *fc,
1603static void fuse_writepage_finish(struct fuse_mount *fm,
1582 struct fuse_writepage_args *wpa)
1583{
1584 struct fuse_args_pages *ap = &wpa->ia.ap;
1585 struct inode *inode = wpa->inode;
1586 struct fuse_inode *fi = get_fuse_inode(inode);
1587 struct backing_dev_info *bdi = inode_to_bdi(inode);
1588 int i;
1589
1590 for (i = 0; i < ap->num_pages; i++) {
1591 dec_wb_stat(&bdi->wb, WB_WRITEBACK);
1592 dec_node_page_state(ap->pages[i], NR_WRITEBACK_TEMP);
1593 wb_writeout_inc(&bdi->wb);
1594 }
1595 wake_up(&fi->page_waitq);
1596}
1597
1598/* Called under fi->lock, may release and reacquire it */
1604 struct fuse_writepage_args *wpa)
1605{
1606 struct fuse_args_pages *ap = &wpa->ia.ap;
1607 struct inode *inode = wpa->inode;
1608 struct fuse_inode *fi = get_fuse_inode(inode);
1609 struct backing_dev_info *bdi = inode_to_bdi(inode);
1610 int i;
1611
1612 for (i = 0; i < ap->num_pages; i++) {
1613 dec_wb_stat(&bdi->wb, WB_WRITEBACK);
1614 dec_node_page_state(ap->pages[i], NR_WRITEBACK_TEMP);
1615 wb_writeout_inc(&bdi->wb);
1616 }
1617 wake_up(&fi->page_waitq);
1618}
1619
1620/* Called under fi->lock, may release and reacquire it */
1599static void fuse_send_writepage(struct fuse_conn *fc,
1621static void fuse_send_writepage(struct fuse_mount *fm,
1600 struct fuse_writepage_args *wpa, loff_t size)
1601__releases(fi->lock)
1602__acquires(fi->lock)
1603{
1604 struct fuse_writepage_args *aux, *next;
1605 struct fuse_inode *fi = get_fuse_inode(wpa->inode);
1606 struct fuse_write_in *inarg = &wpa->ia.write.in;
1607 struct fuse_args *args = &wpa->ia.ap.args;

--- 9 unchanged lines hidden (view full) ---

1617 /* Got truncated off completely */
1618 goto out_free;
1619 }
1620
1621 args->in_args[1].size = inarg->size;
1622 args->force = true;
1623 args->nocreds = true;
1624
1622 struct fuse_writepage_args *wpa, loff_t size)
1623__releases(fi->lock)
1624__acquires(fi->lock)
1625{
1626 struct fuse_writepage_args *aux, *next;
1627 struct fuse_inode *fi = get_fuse_inode(wpa->inode);
1628 struct fuse_write_in *inarg = &wpa->ia.write.in;
1629 struct fuse_args *args = &wpa->ia.ap.args;

--- 9 unchanged lines hidden (view full) ---

1639 /* Got truncated off completely */
1640 goto out_free;
1641 }
1642
1643 args->in_args[1].size = inarg->size;
1644 args->force = true;
1645 args->nocreds = true;
1646
1625 err = fuse_simple_background(fc, args, GFP_ATOMIC);
1647 err = fuse_simple_background(fm, args, GFP_ATOMIC);
1626 if (err == -ENOMEM) {
1627 spin_unlock(&fi->lock);
1648 if (err == -ENOMEM) {
1649 spin_unlock(&fi->lock);
1628 err = fuse_simple_background(fc, args, GFP_NOFS | __GFP_NOFAIL);
1650 err = fuse_simple_background(fm, args, GFP_NOFS | __GFP_NOFAIL);
1629 spin_lock(&fi->lock);
1630 }
1631
1632 /* Fails on broken connection only */
1633 if (unlikely(err))
1634 goto out_free;
1635
1636 return;
1637
1638 out_free:
1639 fi->writectr--;
1640 rb_erase(&wpa->writepages_entry, &fi->writepages);
1651 spin_lock(&fi->lock);
1652 }
1653
1654 /* Fails on broken connection only */
1655 if (unlikely(err))
1656 goto out_free;
1657
1658 return;
1659
1660 out_free:
1661 fi->writectr--;
1662 rb_erase(&wpa->writepages_entry, &fi->writepages);
1641 fuse_writepage_finish(fc, wpa);
1663 fuse_writepage_finish(fm, wpa);
1642 spin_unlock(&fi->lock);
1643
1644 /* After fuse_writepage_finish() aux request list is private */
1645 for (aux = wpa->next; aux; aux = next) {
1646 next = aux->next;
1647 aux->next = NULL;
1648 fuse_writepage_free(aux);
1649 }

--- 7 unchanged lines hidden (view full) ---

1657 * all queued writepage requests.
1658 *
1659 * Called with fi->lock
1660 */
1661void fuse_flush_writepages(struct inode *inode)
1662__releases(fi->lock)
1663__acquires(fi->lock)
1664{
1664 spin_unlock(&fi->lock);
1665
1666 /* After fuse_writepage_finish() aux request list is private */
1667 for (aux = wpa->next; aux; aux = next) {
1668 next = aux->next;
1669 aux->next = NULL;
1670 fuse_writepage_free(aux);
1671 }

--- 7 unchanged lines hidden (view full) ---

1679 * all queued writepage requests.
1680 *
1681 * Called with fi->lock
1682 */
1683void fuse_flush_writepages(struct inode *inode)
1684__releases(fi->lock)
1685__acquires(fi->lock)
1686{
1665 struct fuse_conn *fc = get_fuse_conn(inode);
1687 struct fuse_mount *fm = get_fuse_mount(inode);
1666 struct fuse_inode *fi = get_fuse_inode(inode);
1667 loff_t crop = i_size_read(inode);
1668 struct fuse_writepage_args *wpa;
1669
1670 while (fi->writectr >= 0 && !list_empty(&fi->queued_writes)) {
1671 wpa = list_entry(fi->queued_writes.next,
1672 struct fuse_writepage_args, queue_entry);
1673 list_del_init(&wpa->queue_entry);
1688 struct fuse_inode *fi = get_fuse_inode(inode);
1689 loff_t crop = i_size_read(inode);
1690 struct fuse_writepage_args *wpa;
1691
1692 while (fi->writectr >= 0 && !list_empty(&fi->queued_writes)) {
1693 wpa = list_entry(fi->queued_writes.next,
1694 struct fuse_writepage_args, queue_entry);
1695 list_del_init(&wpa->queue_entry);
1674 fuse_send_writepage(fc, wpa, crop);
1696 fuse_send_writepage(fm, wpa, crop);
1675 }
1676}
1677
1678static struct fuse_writepage_args *fuse_insert_writeback(struct rb_root *root,
1679 struct fuse_writepage_args *wpa)
1680{
1681 pgoff_t idx_from = wpa->ia.write.in.offset >> PAGE_SHIFT;
1682 pgoff_t idx_to = idx_from + wpa->ia.ap.num_pages - 1;

--- 24 unchanged lines hidden (view full) ---

1707 return NULL;
1708}
1709
1710static void tree_insert(struct rb_root *root, struct fuse_writepage_args *wpa)
1711{
1712 WARN_ON(fuse_insert_writeback(root, wpa));
1713}
1714
1697 }
1698}
1699
1700static struct fuse_writepage_args *fuse_insert_writeback(struct rb_root *root,
1701 struct fuse_writepage_args *wpa)
1702{
1703 pgoff_t idx_from = wpa->ia.write.in.offset >> PAGE_SHIFT;
1704 pgoff_t idx_to = idx_from + wpa->ia.ap.num_pages - 1;

--- 24 unchanged lines hidden (view full) ---

1729 return NULL;
1730}
1731
1732static void tree_insert(struct rb_root *root, struct fuse_writepage_args *wpa)
1733{
1734 WARN_ON(fuse_insert_writeback(root, wpa));
1735}
1736
1715static void fuse_writepage_end(struct fuse_conn *fc, struct fuse_args *args,
1737static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,
1716 int error)
1717{
1718 struct fuse_writepage_args *wpa =
1719 container_of(args, typeof(*wpa), ia.ap.args);
1720 struct inode *inode = wpa->inode;
1721 struct fuse_inode *fi = get_fuse_inode(inode);
1722
1723 mapping_set_error(inode->i_mapping, error);
1724 spin_lock(&fi->lock);
1725 rb_erase(&wpa->writepages_entry, &fi->writepages);
1726 while (wpa->next) {
1738 int error)
1739{
1740 struct fuse_writepage_args *wpa =
1741 container_of(args, typeof(*wpa), ia.ap.args);
1742 struct inode *inode = wpa->inode;
1743 struct fuse_inode *fi = get_fuse_inode(inode);
1744
1745 mapping_set_error(inode->i_mapping, error);
1746 spin_lock(&fi->lock);
1747 rb_erase(&wpa->writepages_entry, &fi->writepages);
1748 while (wpa->next) {
1727 struct fuse_conn *fc = get_fuse_conn(inode);
1749 struct fuse_mount *fm = get_fuse_mount(inode);
1728 struct fuse_write_in *inarg = &wpa->ia.write.in;
1729 struct fuse_writepage_args *next = wpa->next;
1730
1731 wpa->next = next->next;
1732 next->next = NULL;
1733 next->ia.ff = fuse_file_get(wpa->ia.ff);
1734 tree_insert(&fi->writepages, next);
1735

--- 15 unchanged lines hidden (view full) ---

1751 * of fuse_set_nowrite..fuse_release_nowrite section. The fact
1752 * that fuse_set_nowrite returned implies that all in-flight
1753 * requests were completed along with all of their secondary
1754 * requests. Further primary requests are blocked by negative
1755 * writectr. Hence there cannot be any in-flight requests and
1756 * no invocations of fuse_writepage_end() while we're in
1757 * fuse_set_nowrite..fuse_release_nowrite section.
1758 */
1750 struct fuse_write_in *inarg = &wpa->ia.write.in;
1751 struct fuse_writepage_args *next = wpa->next;
1752
1753 wpa->next = next->next;
1754 next->next = NULL;
1755 next->ia.ff = fuse_file_get(wpa->ia.ff);
1756 tree_insert(&fi->writepages, next);
1757

--- 15 unchanged lines hidden (view full) ---

1773 * of fuse_set_nowrite..fuse_release_nowrite section. The fact
1774 * that fuse_set_nowrite returned implies that all in-flight
1775 * requests were completed along with all of their secondary
1776 * requests. Further primary requests are blocked by negative
1777 * writectr. Hence there cannot be any in-flight requests and
1778 * no invocations of fuse_writepage_end() while we're in
1779 * fuse_set_nowrite..fuse_release_nowrite section.
1780 */
1759 fuse_send_writepage(fc, next, inarg->offset + inarg->size);
1781 fuse_send_writepage(fm, next, inarg->offset + inarg->size);
1760 }
1761 fi->writectr--;
1782 }
1783 fi->writectr--;
1762 fuse_writepage_finish(fc, wpa);
1784 fuse_writepage_finish(fm, wpa);
1763 spin_unlock(&fi->lock);
1764 fuse_writepage_free(wpa);
1765}
1766
1767static struct fuse_file *__fuse_write_file_get(struct fuse_conn *fc,
1768 struct fuse_inode *fi)
1769{
1770 struct fuse_file *ff = NULL;

--- 541 unchanged lines hidden (view full) ---

2312 .map_pages = filemap_map_pages,
2313 .page_mkwrite = fuse_page_mkwrite,
2314};
2315
2316static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
2317{
2318 struct fuse_file *ff = file->private_data;
2319
1785 spin_unlock(&fi->lock);
1786 fuse_writepage_free(wpa);
1787}
1788
1789static struct fuse_file *__fuse_write_file_get(struct fuse_conn *fc,
1790 struct fuse_inode *fi)
1791{
1792 struct fuse_file *ff = NULL;

--- 541 unchanged lines hidden (view full) ---

2334 .map_pages = filemap_map_pages,
2335 .page_mkwrite = fuse_page_mkwrite,
2336};
2337
2338static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
2339{
2340 struct fuse_file *ff = file->private_data;
2341
2342 /* DAX mmap is superior to direct_io mmap */
2343 if (FUSE_IS_DAX(file_inode(file)))
2344 return fuse_dax_mmap(file, vma);
2345
2320 if (ff->open_flags & FOPEN_DIRECT_IO) {
2321 /* Can't provide the coherency needed for MAP_SHARED */
2322 if (vma->vm_flags & VM_MAYSHARE)
2323 return -ENODEV;
2324
2325 invalidate_inode_pages2(file->f_mapping);
2326
2327 return generic_file_mmap(file, vma);

--- 62 unchanged lines hidden (view full) ---

2390 args->in_numargs = 1;
2391 args->in_args[0].size = sizeof(*inarg);
2392 args->in_args[0].value = inarg;
2393}
2394
2395static int fuse_getlk(struct file *file, struct file_lock *fl)
2396{
2397 struct inode *inode = file_inode(file);
2346 if (ff->open_flags & FOPEN_DIRECT_IO) {
2347 /* Can't provide the coherency needed for MAP_SHARED */
2348 if (vma->vm_flags & VM_MAYSHARE)
2349 return -ENODEV;
2350
2351 invalidate_inode_pages2(file->f_mapping);
2352
2353 return generic_file_mmap(file, vma);

--- 62 unchanged lines hidden (view full) ---

2416 args->in_numargs = 1;
2417 args->in_args[0].size = sizeof(*inarg);
2418 args->in_args[0].value = inarg;
2419}
2420
2421static int fuse_getlk(struct file *file, struct file_lock *fl)
2422{
2423 struct inode *inode = file_inode(file);
2398 struct fuse_conn *fc = get_fuse_conn(inode);
2424 struct fuse_mount *fm = get_fuse_mount(inode);
2399 FUSE_ARGS(args);
2400 struct fuse_lk_in inarg;
2401 struct fuse_lk_out outarg;
2402 int err;
2403
2404 fuse_lk_fill(&args, file, fl, FUSE_GETLK, 0, 0, &inarg);
2405 args.out_numargs = 1;
2406 args.out_args[0].size = sizeof(outarg);
2407 args.out_args[0].value = &outarg;
2425 FUSE_ARGS(args);
2426 struct fuse_lk_in inarg;
2427 struct fuse_lk_out outarg;
2428 int err;
2429
2430 fuse_lk_fill(&args, file, fl, FUSE_GETLK, 0, 0, &inarg);
2431 args.out_numargs = 1;
2432 args.out_args[0].size = sizeof(outarg);
2433 args.out_args[0].value = &outarg;
2408 err = fuse_simple_request(fc, &args);
2434 err = fuse_simple_request(fm, &args);
2409 if (!err)
2435 if (!err)
2410 err = convert_fuse_file_lock(fc, &outarg.lk, fl);
2436 err = convert_fuse_file_lock(fm->fc, &outarg.lk, fl);
2411
2412 return err;
2413}
2414
2415static int fuse_setlk(struct file *file, struct file_lock *fl, int flock)
2416{
2417 struct inode *inode = file_inode(file);
2437
2438 return err;
2439}
2440
2441static int fuse_setlk(struct file *file, struct file_lock *fl, int flock)
2442{
2443 struct inode *inode = file_inode(file);
2418 struct fuse_conn *fc = get_fuse_conn(inode);
2444 struct fuse_mount *fm = get_fuse_mount(inode);
2419 FUSE_ARGS(args);
2420 struct fuse_lk_in inarg;
2421 int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK;
2422 struct pid *pid = fl->fl_type != F_UNLCK ? task_tgid(current) : NULL;
2445 FUSE_ARGS(args);
2446 struct fuse_lk_in inarg;
2447 int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK;
2448 struct pid *pid = fl->fl_type != F_UNLCK ? task_tgid(current) : NULL;
2423 pid_t pid_nr = pid_nr_ns(pid, fc->pid_ns);
2449 pid_t pid_nr = pid_nr_ns(pid, fm->fc->pid_ns);
2424 int err;
2425
2426 if (fl->fl_lmops && fl->fl_lmops->lm_grant) {
2427 /* NLM needs asynchronous locks, which we don't support yet */
2428 return -ENOLCK;
2429 }
2430
2431 /* Unlock on close is handled by the flush method */
2432 if ((fl->fl_flags & FL_CLOSE_POSIX) == FL_CLOSE_POSIX)
2433 return 0;
2434
2435 fuse_lk_fill(&args, file, fl, opcode, pid_nr, flock, &inarg);
2450 int err;
2451
2452 if (fl->fl_lmops && fl->fl_lmops->lm_grant) {
2453 /* NLM needs asynchronous locks, which we don't support yet */
2454 return -ENOLCK;
2455 }
2456
2457 /* Unlock on close is handled by the flush method */
2458 if ((fl->fl_flags & FL_CLOSE_POSIX) == FL_CLOSE_POSIX)
2459 return 0;
2460
2461 fuse_lk_fill(&args, file, fl, opcode, pid_nr, flock, &inarg);
2436 err = fuse_simple_request(fc, &args);
2462 err = fuse_simple_request(fm, &args);
2437
2438 /* locking is restartable */
2439 if (err == -EINTR)
2440 err = -ERESTARTSYS;
2441
2442 return err;
2443}
2444

--- 37 unchanged lines hidden (view full) ---

2482 }
2483
2484 return err;
2485}
2486
2487static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
2488{
2489 struct inode *inode = mapping->host;
2463
2464 /* locking is restartable */
2465 if (err == -EINTR)
2466 err = -ERESTARTSYS;
2467
2468 return err;
2469}
2470

--- 37 unchanged lines hidden (view full) ---

2508 }
2509
2510 return err;
2511}
2512
2513static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
2514{
2515 struct inode *inode = mapping->host;
2490 struct fuse_conn *fc = get_fuse_conn(inode);
2516 struct fuse_mount *fm = get_fuse_mount(inode);
2491 FUSE_ARGS(args);
2492 struct fuse_bmap_in inarg;
2493 struct fuse_bmap_out outarg;
2494 int err;
2495
2517 FUSE_ARGS(args);
2518 struct fuse_bmap_in inarg;
2519 struct fuse_bmap_out outarg;
2520 int err;
2521
2496 if (!inode->i_sb->s_bdev || fc->no_bmap)
2522 if (!inode->i_sb->s_bdev || fm->fc->no_bmap)
2497 return 0;
2498
2499 memset(&inarg, 0, sizeof(inarg));
2500 inarg.block = block;
2501 inarg.blocksize = inode->i_sb->s_blocksize;
2502 args.opcode = FUSE_BMAP;
2503 args.nodeid = get_node_id(inode);
2504 args.in_numargs = 1;
2505 args.in_args[0].size = sizeof(inarg);
2506 args.in_args[0].value = &inarg;
2507 args.out_numargs = 1;
2508 args.out_args[0].size = sizeof(outarg);
2509 args.out_args[0].value = &outarg;
2523 return 0;
2524
2525 memset(&inarg, 0, sizeof(inarg));
2526 inarg.block = block;
2527 inarg.blocksize = inode->i_sb->s_blocksize;
2528 args.opcode = FUSE_BMAP;
2529 args.nodeid = get_node_id(inode);
2530 args.in_numargs = 1;
2531 args.in_args[0].size = sizeof(inarg);
2532 args.in_args[0].value = &inarg;
2533 args.out_numargs = 1;
2534 args.out_args[0].size = sizeof(outarg);
2535 args.out_args[0].value = &outarg;
2510 err = fuse_simple_request(fc, &args);
2536 err = fuse_simple_request(fm, &args);
2511 if (err == -ENOSYS)
2537 if (err == -ENOSYS)
2512 fc->no_bmap = 1;
2538 fm->fc->no_bmap = 1;
2513
2514 return err ? 0 : outarg.block;
2515}
2516
2517static loff_t fuse_lseek(struct file *file, loff_t offset, int whence)
2518{
2519 struct inode *inode = file->f_mapping->host;
2539
2540 return err ? 0 : outarg.block;
2541}
2542
2543static loff_t fuse_lseek(struct file *file, loff_t offset, int whence)
2544{
2545 struct inode *inode = file->f_mapping->host;
2520 struct fuse_conn *fc = get_fuse_conn(inode);
2546 struct fuse_mount *fm = get_fuse_mount(inode);
2521 struct fuse_file *ff = file->private_data;
2522 FUSE_ARGS(args);
2523 struct fuse_lseek_in inarg = {
2524 .fh = ff->fh,
2525 .offset = offset,
2526 .whence = whence
2527 };
2528 struct fuse_lseek_out outarg;
2529 int err;
2530
2547 struct fuse_file *ff = file->private_data;
2548 FUSE_ARGS(args);
2549 struct fuse_lseek_in inarg = {
2550 .fh = ff->fh,
2551 .offset = offset,
2552 .whence = whence
2553 };
2554 struct fuse_lseek_out outarg;
2555 int err;
2556
2531 if (fc->no_lseek)
2557 if (fm->fc->no_lseek)
2532 goto fallback;
2533
2534 args.opcode = FUSE_LSEEK;
2535 args.nodeid = ff->nodeid;
2536 args.in_numargs = 1;
2537 args.in_args[0].size = sizeof(inarg);
2538 args.in_args[0].value = &inarg;
2539 args.out_numargs = 1;
2540 args.out_args[0].size = sizeof(outarg);
2541 args.out_args[0].value = &outarg;
2558 goto fallback;
2559
2560 args.opcode = FUSE_LSEEK;
2561 args.nodeid = ff->nodeid;
2562 args.in_numargs = 1;
2563 args.in_args[0].size = sizeof(inarg);
2564 args.in_args[0].value = &inarg;
2565 args.out_numargs = 1;
2566 args.out_args[0].size = sizeof(outarg);
2567 args.out_args[0].value = &outarg;
2542 err = fuse_simple_request(fc, &args);
2568 err = fuse_simple_request(fm, &args);
2543 if (err) {
2544 if (err == -ENOSYS) {
2569 if (err) {
2570 if (err == -ENOSYS) {
2545 fc->no_lseek = 1;
2571 fm->fc->no_lseek = 1;
2546 goto fallback;
2547 }
2548 return err;
2549 }
2550
2551 return vfs_setpos(file, outarg.offset, inode->i_sb->s_maxbytes);
2552
2553fallback:

--- 169 unchanged lines hidden (view full) ---

2723 * _IOC_* macros and the server is not allowed to request RETRY. This
2724 * limits ioctl data transfers to well-formed ioctls and is the forced
2725 * behavior for all FUSE servers.
2726 */
2727long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
2728 unsigned int flags)
2729{
2730 struct fuse_file *ff = file->private_data;
2572 goto fallback;
2573 }
2574 return err;
2575 }
2576
2577 return vfs_setpos(file, outarg.offset, inode->i_sb->s_maxbytes);
2578
2579fallback:

--- 169 unchanged lines hidden (view full) ---

2749 * _IOC_* macros and the server is not allowed to request RETRY. This
2750 * limits ioctl data transfers to well-formed ioctls and is the forced
2751 * behavior for all FUSE servers.
2752 */
2753long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
2754 unsigned int flags)
2755{
2756 struct fuse_file *ff = file->private_data;
2731 struct fuse_conn *fc = ff->fc;
2757 struct fuse_mount *fm = ff->fm;
2732 struct fuse_ioctl_in inarg = {
2733 .fh = ff->fh,
2734 .cmd = cmd,
2735 .arg = arg,
2736 .flags = flags
2737 };
2738 struct fuse_ioctl_out outarg;
2739 struct iovec *iov_page = NULL;

--- 16 unchanged lines hidden (view full) ---

2756#endif
2757 }
2758#endif
2759
2760 /* assume all the iovs returned by client always fits in a page */
2761 BUILD_BUG_ON(sizeof(struct fuse_ioctl_iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE);
2762
2763 err = -ENOMEM;
2758 struct fuse_ioctl_in inarg = {
2759 .fh = ff->fh,
2760 .cmd = cmd,
2761 .arg = arg,
2762 .flags = flags
2763 };
2764 struct fuse_ioctl_out outarg;
2765 struct iovec *iov_page = NULL;

--- 16 unchanged lines hidden (view full) ---

2782#endif
2783 }
2784#endif
2785
2786 /* assume all the iovs returned by client always fits in a page */
2787 BUILD_BUG_ON(sizeof(struct fuse_ioctl_iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE);
2788
2789 err = -ENOMEM;
2764 ap.pages = fuse_pages_alloc(fc->max_pages, GFP_KERNEL, &ap.descs);
2790 ap.pages = fuse_pages_alloc(fm->fc->max_pages, GFP_KERNEL, &ap.descs);
2765 iov_page = (struct iovec *) __get_free_page(GFP_KERNEL);
2766 if (!ap.pages || !iov_page)
2767 goto out;
2768
2791 iov_page = (struct iovec *) __get_free_page(GFP_KERNEL);
2792 if (!ap.pages || !iov_page)
2793 goto out;
2794
2769 fuse_page_descs_length_init(ap.descs, 0, fc->max_pages);
2795 fuse_page_descs_length_init(ap.descs, 0, fm->fc->max_pages);
2770
2771 /*
2772 * If restricted, initialize IO parameters as encoded in @cmd.
2773 * RETRY from server is not allowed.
2774 */
2775 if (!(flags & FUSE_IOCTL_UNRESTRICTED)) {
2776 struct iovec *iov = iov_page;
2777

--- 28 unchanged lines hidden (view full) ---

2806 * Out data can be used either for actual out data or iovs,
2807 * make sure there always is at least one page.
2808 */
2809 out_size = max_t(size_t, out_size, PAGE_SIZE);
2810 max_pages = DIV_ROUND_UP(max(in_size, out_size), PAGE_SIZE);
2811
2812 /* make sure there are enough buffer pages and init request with them */
2813 err = -ENOMEM;
2796
2797 /*
2798 * If restricted, initialize IO parameters as encoded in @cmd.
2799 * RETRY from server is not allowed.
2800 */
2801 if (!(flags & FUSE_IOCTL_UNRESTRICTED)) {
2802 struct iovec *iov = iov_page;
2803

--- 28 unchanged lines hidden (view full) ---

2832 * Out data can be used either for actual out data or iovs,
2833 * make sure there always is at least one page.
2834 */
2835 out_size = max_t(size_t, out_size, PAGE_SIZE);
2836 max_pages = DIV_ROUND_UP(max(in_size, out_size), PAGE_SIZE);
2837
2838 /* make sure there are enough buffer pages and init request with them */
2839 err = -ENOMEM;
2814 if (max_pages > fc->max_pages)
2840 if (max_pages > fm->fc->max_pages)
2815 goto out;
2816 while (ap.num_pages < max_pages) {
2817 ap.pages[ap.num_pages] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
2818 if (!ap.pages[ap.num_pages])
2819 goto out;
2820 ap.num_pages++;
2821 }
2822

--- 20 unchanged lines hidden (view full) ---

2843
2844 ap.args.out_numargs = 2;
2845 ap.args.out_args[0].size = sizeof(outarg);
2846 ap.args.out_args[0].value = &outarg;
2847 ap.args.out_args[1].size = out_size;
2848 ap.args.out_pages = true;
2849 ap.args.out_argvar = true;
2850
2841 goto out;
2842 while (ap.num_pages < max_pages) {
2843 ap.pages[ap.num_pages] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
2844 if (!ap.pages[ap.num_pages])
2845 goto out;
2846 ap.num_pages++;
2847 }
2848

--- 20 unchanged lines hidden (view full) ---

2869
2870 ap.args.out_numargs = 2;
2871 ap.args.out_args[0].size = sizeof(outarg);
2872 ap.args.out_args[0].value = &outarg;
2873 ap.args.out_args[1].size = out_size;
2874 ap.args.out_pages = true;
2875 ap.args.out_argvar = true;
2876
2851 transferred = fuse_simple_request(fc, &ap.args);
2877 transferred = fuse_simple_request(fm, &ap.args);
2852 err = transferred;
2853 if (transferred < 0)
2854 goto out;
2855
2856 /* did it ask for retry? */
2857 if (outarg.flags & FUSE_IOCTL_RETRY) {
2858 void *vaddr;
2859

--- 11 unchanged lines hidden (view full) ---

2871 */
2872 err = -ENOMEM;
2873 if (in_iovs > FUSE_IOCTL_MAX_IOV ||
2874 out_iovs > FUSE_IOCTL_MAX_IOV ||
2875 in_iovs + out_iovs > FUSE_IOCTL_MAX_IOV)
2876 goto out;
2877
2878 vaddr = kmap_atomic(ap.pages[0]);
2878 err = transferred;
2879 if (transferred < 0)
2880 goto out;
2881
2882 /* did it ask for retry? */
2883 if (outarg.flags & FUSE_IOCTL_RETRY) {
2884 void *vaddr;
2885

--- 11 unchanged lines hidden (view full) ---

2897 */
2898 err = -ENOMEM;
2899 if (in_iovs > FUSE_IOCTL_MAX_IOV ||
2900 out_iovs > FUSE_IOCTL_MAX_IOV ||
2901 in_iovs + out_iovs > FUSE_IOCTL_MAX_IOV)
2902 goto out;
2903
2904 vaddr = kmap_atomic(ap.pages[0]);
2879 err = fuse_copy_ioctl_iovec(fc, iov_page, vaddr,
2905 err = fuse_copy_ioctl_iovec(fm->fc, iov_page, vaddr,
2880 transferred, in_iovs + out_iovs,
2881 (flags & FUSE_IOCTL_COMPAT) != 0);
2882 kunmap_atomic(vaddr);
2883 if (err)
2884 goto out;
2885
2886 in_iov = iov_page;
2887 out_iov = in_iov + in_iovs;
2888
2906 transferred, in_iovs + out_iovs,
2907 (flags & FUSE_IOCTL_COMPAT) != 0);
2908 kunmap_atomic(vaddr);
2909 if (err)
2910 goto out;
2911
2912 in_iov = iov_page;
2913 out_iov = in_iov + in_iovs;
2914
2889 err = fuse_verify_ioctl_iov(fc, in_iov, in_iovs);
2915 err = fuse_verify_ioctl_iov(fm->fc, in_iov, in_iovs);
2890 if (err)
2891 goto out;
2892
2916 if (err)
2917 goto out;
2918
2893 err = fuse_verify_ioctl_iov(fc, out_iov, out_iovs);
2919 err = fuse_verify_ioctl_iov(fm->fc, out_iov, out_iovs);
2894 if (err)
2895 goto out;
2896
2897 goto retry;
2898 }
2899
2900 err = -EIO;
2901 if (transferred > inarg.out_size)

--- 93 unchanged lines hidden (view full) ---

2995 rb_insert_color(&ff->polled_node, &fc->polled_files);
2996 }
2997 spin_unlock(&fc->lock);
2998}
2999
3000__poll_t fuse_file_poll(struct file *file, poll_table *wait)
3001{
3002 struct fuse_file *ff = file->private_data;
2920 if (err)
2921 goto out;
2922
2923 goto retry;
2924 }
2925
2926 err = -EIO;
2927 if (transferred > inarg.out_size)

--- 93 unchanged lines hidden (view full) ---

3021 rb_insert_color(&ff->polled_node, &fc->polled_files);
3022 }
3023 spin_unlock(&fc->lock);
3024}
3025
3026__poll_t fuse_file_poll(struct file *file, poll_table *wait)
3027{
3028 struct fuse_file *ff = file->private_data;
3003 struct fuse_conn *fc = ff->fc;
3029 struct fuse_mount *fm = ff->fm;
3004 struct fuse_poll_in inarg = { .fh = ff->fh, .kh = ff->kh };
3005 struct fuse_poll_out outarg;
3006 FUSE_ARGS(args);
3007 int err;
3008
3030 struct fuse_poll_in inarg = { .fh = ff->fh, .kh = ff->kh };
3031 struct fuse_poll_out outarg;
3032 FUSE_ARGS(args);
3033 int err;
3034
3009 if (fc->no_poll)
3035 if (fm->fc->no_poll)
3010 return DEFAULT_POLLMASK;
3011
3012 poll_wait(file, &ff->poll_wait, wait);
3013 inarg.events = mangle_poll(poll_requested_events(wait));
3014
3015 /*
3016 * Ask for notification iff there's someone waiting for it.
3017 * The client may ignore the flag and always notify.
3018 */
3019 if (waitqueue_active(&ff->poll_wait)) {
3020 inarg.flags |= FUSE_POLL_SCHEDULE_NOTIFY;
3036 return DEFAULT_POLLMASK;
3037
3038 poll_wait(file, &ff->poll_wait, wait);
3039 inarg.events = mangle_poll(poll_requested_events(wait));
3040
3041 /*
3042 * Ask for notification iff there's someone waiting for it.
3043 * The client may ignore the flag and always notify.
3044 */
3045 if (waitqueue_active(&ff->poll_wait)) {
3046 inarg.flags |= FUSE_POLL_SCHEDULE_NOTIFY;
3021 fuse_register_polled_file(fc, ff);
3047 fuse_register_polled_file(fm->fc, ff);
3022 }
3023
3024 args.opcode = FUSE_POLL;
3025 args.nodeid = ff->nodeid;
3026 args.in_numargs = 1;
3027 args.in_args[0].size = sizeof(inarg);
3028 args.in_args[0].value = &inarg;
3029 args.out_numargs = 1;
3030 args.out_args[0].size = sizeof(outarg);
3031 args.out_args[0].value = &outarg;
3048 }
3049
3050 args.opcode = FUSE_POLL;
3051 args.nodeid = ff->nodeid;
3052 args.in_numargs = 1;
3053 args.in_args[0].size = sizeof(inarg);
3054 args.in_args[0].value = &inarg;
3055 args.out_numargs = 1;
3056 args.out_args[0].size = sizeof(outarg);
3057 args.out_args[0].value = &outarg;
3032 err = fuse_simple_request(fc, &args);
3058 err = fuse_simple_request(fm, &args);
3033
3034 if (!err)
3035 return demangle_poll(outarg.revents);
3036 if (err == -ENOSYS) {
3059
3060 if (!err)
3061 return demangle_poll(outarg.revents);
3062 if (err == -ENOSYS) {
3037 fc->no_poll = 1;
3063 fm->fc->no_poll = 1;
3038 return DEFAULT_POLLMASK;
3039 }
3040 return EPOLLERR;
3041}
3042EXPORT_SYMBOL_GPL(fuse_file_poll);
3043
3044/*
3045 * This is called from fuse_handle_notify() on FUSE_NOTIFY_POLL and

--- 69 unchanged lines hidden (view full) ---

3115 io->size = 0;
3116 io->offset = offset;
3117 io->write = (iov_iter_rw(iter) == WRITE);
3118 io->err = 0;
3119 /*
3120 * By default, we want to optimize all I/Os with async request
3121 * submission to the client filesystem if supported.
3122 */
3064 return DEFAULT_POLLMASK;
3065 }
3066 return EPOLLERR;
3067}
3068EXPORT_SYMBOL_GPL(fuse_file_poll);
3069
3070/*
3071 * This is called from fuse_handle_notify() on FUSE_NOTIFY_POLL and

--- 69 unchanged lines hidden (view full) ---

3141 io->size = 0;
3142 io->offset = offset;
3143 io->write = (iov_iter_rw(iter) == WRITE);
3144 io->err = 0;
3145 /*
3146 * By default, we want to optimize all I/Os with async request
3147 * submission to the client filesystem if supported.
3148 */
3123 io->async = ff->fc->async_dio;
3149 io->async = ff->fm->fc->async_dio;
3124 io->iocb = iocb;
3125 io->blocking = is_sync_kiocb(iocb);
3126
3127 /* optimization for short read */
3128 if (io->async && !io->write && offset + count > i_size) {
3150 io->iocb = iocb;
3151 io->blocking = is_sync_kiocb(iocb);
3152
3153 /* optimization for short read */
3154 if (io->async && !io->write && offset + count > i_size) {
3129 iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset));
3155 iov_iter_truncate(iter, fuse_round_up(ff->fm->fc, i_size - offset));
3130 shortened = count - iov_iter_count(iter);
3131 count -= shortened;
3132 }
3133
3134 /*
3135 * We cannot asynchronously extend the size of a file.
3136 * In such case the aio will behave exactly like sync io.
3137 */

--- 53 unchanged lines hidden (view full) ---

3191}
3192
3193static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
3194 loff_t length)
3195{
3196 struct fuse_file *ff = file->private_data;
3197 struct inode *inode = file_inode(file);
3198 struct fuse_inode *fi = get_fuse_inode(inode);
3156 shortened = count - iov_iter_count(iter);
3157 count -= shortened;
3158 }
3159
3160 /*
3161 * We cannot asynchronously extend the size of a file.
3162 * In such case the aio will behave exactly like sync io.
3163 */

--- 53 unchanged lines hidden (view full) ---

3217}
3218
3219static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
3220 loff_t length)
3221{
3222 struct fuse_file *ff = file->private_data;
3223 struct inode *inode = file_inode(file);
3224 struct fuse_inode *fi = get_fuse_inode(inode);
3199 struct fuse_conn *fc = ff->fc;
3225 struct fuse_mount *fm = ff->fm;
3200 FUSE_ARGS(args);
3201 struct fuse_fallocate_in inarg = {
3202 .fh = ff->fh,
3203 .offset = offset,
3204 .length = length,
3205 .mode = mode
3206 };
3207 int err;
3208 bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) ||
3209 (mode & FALLOC_FL_PUNCH_HOLE);
3210
3226 FUSE_ARGS(args);
3227 struct fuse_fallocate_in inarg = {
3228 .fh = ff->fh,
3229 .offset = offset,
3230 .length = length,
3231 .mode = mode
3232 };
3233 int err;
3234 bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) ||
3235 (mode & FALLOC_FL_PUNCH_HOLE);
3236
3237 bool block_faults = FUSE_IS_DAX(inode) && lock_inode;
3238
3211 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
3212 return -EOPNOTSUPP;
3213
3239 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
3240 return -EOPNOTSUPP;
3241
3214 if (fc->no_fallocate)
3242 if (fm->fc->no_fallocate)
3215 return -EOPNOTSUPP;
3216
3217 if (lock_inode) {
3218 inode_lock(inode);
3243 return -EOPNOTSUPP;
3244
3245 if (lock_inode) {
3246 inode_lock(inode);
3247 if (block_faults) {
3248 down_write(&fi->i_mmap_sem);
3249 err = fuse_dax_break_layouts(inode, 0, 0);
3250 if (err)
3251 goto out;
3252 }
3253
3219 if (mode & FALLOC_FL_PUNCH_HOLE) {
3220 loff_t endbyte = offset + length - 1;
3221
3222 err = fuse_writeback_range(inode, offset, endbyte);
3223 if (err)
3224 goto out;
3225 }
3226 }

--- 8 unchanged lines hidden (view full) ---

3235 if (!(mode & FALLOC_FL_KEEP_SIZE))
3236 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3237
3238 args.opcode = FUSE_FALLOCATE;
3239 args.nodeid = ff->nodeid;
3240 args.in_numargs = 1;
3241 args.in_args[0].size = sizeof(inarg);
3242 args.in_args[0].value = &inarg;
3254 if (mode & FALLOC_FL_PUNCH_HOLE) {
3255 loff_t endbyte = offset + length - 1;
3256
3257 err = fuse_writeback_range(inode, offset, endbyte);
3258 if (err)
3259 goto out;
3260 }
3261 }

--- 8 unchanged lines hidden (view full) ---

3270 if (!(mode & FALLOC_FL_KEEP_SIZE))
3271 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3272
3273 args.opcode = FUSE_FALLOCATE;
3274 args.nodeid = ff->nodeid;
3275 args.in_numargs = 1;
3276 args.in_args[0].size = sizeof(inarg);
3277 args.in_args[0].value = &inarg;
3243 err = fuse_simple_request(fc, &args);
3278 err = fuse_simple_request(fm, &args);
3244 if (err == -ENOSYS) {
3279 if (err == -ENOSYS) {
3245 fc->no_fallocate = 1;
3280 fm->fc->no_fallocate = 1;
3246 err = -EOPNOTSUPP;
3247 }
3248 if (err)
3249 goto out;
3250
3251 /* we could have extended the file */
3252 if (!(mode & FALLOC_FL_KEEP_SIZE)) {
3253 bool changed = fuse_write_update_size(inode, offset + length);
3254
3281 err = -EOPNOTSUPP;
3282 }
3283 if (err)
3284 goto out;
3285
3286 /* we could have extended the file */
3287 if (!(mode & FALLOC_FL_KEEP_SIZE)) {
3288 bool changed = fuse_write_update_size(inode, offset + length);
3289
3255 if (changed && fc->writeback_cache)
3290 if (changed && fm->fc->writeback_cache)
3256 file_update_time(file);
3257 }
3258
3259 if (mode & FALLOC_FL_PUNCH_HOLE)
3260 truncate_pagecache_range(inode, offset, offset + length - 1);
3261
3262 fuse_invalidate_attr(inode);
3263
3264out:
3265 if (!(mode & FALLOC_FL_KEEP_SIZE))
3266 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3267
3291 file_update_time(file);
3292 }
3293
3294 if (mode & FALLOC_FL_PUNCH_HOLE)
3295 truncate_pagecache_range(inode, offset, offset + length - 1);
3296
3297 fuse_invalidate_attr(inode);
3298
3299out:
3300 if (!(mode & FALLOC_FL_KEEP_SIZE))
3301 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
3302
3303 if (block_faults)
3304 up_write(&fi->i_mmap_sem);
3305
3268 if (lock_inode)
3269 inode_unlock(inode);
3270
3271 return err;
3272}
3273
3274static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
3275 struct file *file_out, loff_t pos_out,
3276 size_t len, unsigned int flags)
3277{
3278 struct fuse_file *ff_in = file_in->private_data;
3279 struct fuse_file *ff_out = file_out->private_data;
3280 struct inode *inode_in = file_inode(file_in);
3281 struct inode *inode_out = file_inode(file_out);
3282 struct fuse_inode *fi_out = get_fuse_inode(inode_out);
3306 if (lock_inode)
3307 inode_unlock(inode);
3308
3309 return err;
3310}
3311
3312static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
3313 struct file *file_out, loff_t pos_out,
3314 size_t len, unsigned int flags)
3315{
3316 struct fuse_file *ff_in = file_in->private_data;
3317 struct fuse_file *ff_out = file_out->private_data;
3318 struct inode *inode_in = file_inode(file_in);
3319 struct inode *inode_out = file_inode(file_out);
3320 struct fuse_inode *fi_out = get_fuse_inode(inode_out);
3283 struct fuse_conn *fc = ff_in->fc;
3321 struct fuse_mount *fm = ff_in->fm;
3322 struct fuse_conn *fc = fm->fc;
3284 FUSE_ARGS(args);
3285 struct fuse_copy_file_range_in inarg = {
3286 .fh_in = ff_in->fh,
3287 .off_in = pos_in,
3288 .nodeid_out = ff_out->nodeid,
3289 .fh_out = ff_out->fh,
3290 .off_out = pos_out,
3291 .len = len,

--- 52 unchanged lines hidden (view full) ---

3344 args.opcode = FUSE_COPY_FILE_RANGE;
3345 args.nodeid = ff_in->nodeid;
3346 args.in_numargs = 1;
3347 args.in_args[0].size = sizeof(inarg);
3348 args.in_args[0].value = &inarg;
3349 args.out_numargs = 1;
3350 args.out_args[0].size = sizeof(outarg);
3351 args.out_args[0].value = &outarg;
3323 FUSE_ARGS(args);
3324 struct fuse_copy_file_range_in inarg = {
3325 .fh_in = ff_in->fh,
3326 .off_in = pos_in,
3327 .nodeid_out = ff_out->nodeid,
3328 .fh_out = ff_out->fh,
3329 .off_out = pos_out,
3330 .len = len,

--- 52 unchanged lines hidden (view full) ---

3383 args.opcode = FUSE_COPY_FILE_RANGE;
3384 args.nodeid = ff_in->nodeid;
3385 args.in_numargs = 1;
3386 args.in_args[0].size = sizeof(inarg);
3387 args.in_args[0].value = &inarg;
3388 args.out_numargs = 1;
3389 args.out_args[0].size = sizeof(outarg);
3390 args.out_args[0].value = &outarg;
3352 err = fuse_simple_request(fc, &args);
3391 err = fuse_simple_request(fm, &args);
3353 if (err == -ENOSYS) {
3354 fc->no_copy_file_range = 1;
3355 err = -EOPNOTSUPP;
3356 }
3357 if (err)
3358 goto out;
3359
3360 truncate_inode_pages_range(inode_out->i_mapping,

--- 38 unchanged lines hidden (view full) ---

3399 .read_iter = fuse_file_read_iter,
3400 .write_iter = fuse_file_write_iter,
3401 .mmap = fuse_file_mmap,
3402 .open = fuse_open,
3403 .flush = fuse_flush,
3404 .release = fuse_release,
3405 .fsync = fuse_fsync,
3406 .lock = fuse_file_lock,
3392 if (err == -ENOSYS) {
3393 fc->no_copy_file_range = 1;
3394 err = -EOPNOTSUPP;
3395 }
3396 if (err)
3397 goto out;
3398
3399 truncate_inode_pages_range(inode_out->i_mapping,

--- 38 unchanged lines hidden (view full) ---

3438 .read_iter = fuse_file_read_iter,
3439 .write_iter = fuse_file_write_iter,
3440 .mmap = fuse_file_mmap,
3441 .open = fuse_open,
3442 .flush = fuse_flush,
3443 .release = fuse_release,
3444 .fsync = fuse_fsync,
3445 .lock = fuse_file_lock,
3446 .get_unmapped_area = thp_get_unmapped_area,
3407 .flock = fuse_file_flock,
3408 .splice_read = generic_file_splice_read,
3409 .splice_write = iter_file_splice_write,
3410 .unlocked_ioctl = fuse_file_ioctl,
3411 .compat_ioctl = fuse_file_compat_ioctl,
3412 .poll = fuse_file_poll,
3413 .fallocate = fuse_file_fallocate,
3414 .copy_file_range = fuse_copy_file_range,

--- 19 unchanged lines hidden (view full) ---

3434 inode->i_fop = &fuse_file_operations;
3435 inode->i_data.a_ops = &fuse_file_aops;
3436
3437 INIT_LIST_HEAD(&fi->write_files);
3438 INIT_LIST_HEAD(&fi->queued_writes);
3439 fi->writectr = 0;
3440 init_waitqueue_head(&fi->page_waitq);
3441 fi->writepages = RB_ROOT;
3447 .flock = fuse_file_flock,
3448 .splice_read = generic_file_splice_read,
3449 .splice_write = iter_file_splice_write,
3450 .unlocked_ioctl = fuse_file_ioctl,
3451 .compat_ioctl = fuse_file_compat_ioctl,
3452 .poll = fuse_file_poll,
3453 .fallocate = fuse_file_fallocate,
3454 .copy_file_range = fuse_copy_file_range,

--- 19 unchanged lines hidden (view full) ---

3474 inode->i_fop = &fuse_file_operations;
3475 inode->i_data.a_ops = &fuse_file_aops;
3476
3477 INIT_LIST_HEAD(&fi->write_files);
3478 INIT_LIST_HEAD(&fi->queued_writes);
3479 fi->writectr = 0;
3480 init_waitqueue_head(&fi->page_waitq);
3481 fi->writepages = RB_ROOT;
3482
3483 if (IS_ENABLED(CONFIG_FUSE_DAX))
3484 fuse_dax_inode_init(inode);
3442}
3485}