History

Merge tag 'fuse-update-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse

Pull fuse updates from Miklos Szeredi: "Scalability and performance improvements, as well as minor bug fixes and cleanups" * tag 'fuse-update-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: (25 commits) fuse: cache readdir calls if filesystem opts out of opendir fuse: support clients that don't implement 'opendir' fuse: lift bad inode checks into callers fuse: multiplex cached/direct_io file operations fuse add copy_file_range to direct io fops fuse: use iov_iter based generic splice helpers fuse: Switch to using async direct IO for FOPEN_DIRECT_IO fuse: use atomic64_t for khctr fuse: clean up aborted fuse: Protect ff->reserved_req via corresponding fi->lock fuse: Protect fi->nlookup with fi->lock fuse: Introduce fi->lock to protect write related fields fuse: Convert fc->attr_version into atomic64_t fuse: Add fuse_inode argument to fuse_prepare_release() fuse: Verify userspace asks to requeue interrupt that we really sent fuse: Do some refactoring in fuse_dev_do_write() fuse: Wake up req->waitq of only if not background fuse: Optimize request_end() by not taking fiq->waitq.lock fuse: Kill fasync only if interrupt is queued in queue_interrupt() fuse: Remove stale comment in end_requests() ...

Linus Torvalds committed 7 years ago

Commit dfee9c22 parents 7b47a9e fabf7e09 files · +327 −260Browse files

Unified · Split

9 files
  1. fs/fuse/control.c +3 −1
  2. fs/fuse/cuse.c +4 −3
  3. fs/fuse/dev.c +66 −49
  4. fs/fuse/dir.c +20 −34
  5. fs/fuse/file.c +191 −151
  6. fs/fuse/fuse_i.h +20 −8
  7. fs/fuse/inode.c +15 −11
  8. fs/fuse/readdir.c +2 −2
  9. include/uapi/linux/fuse.h +6 −1
fs/fuse/control.c+3−1
@@ -35,7 +35,9 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf, · 34 unmodified lines
3535 {
3636 struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
3737 if (fc) {
38− fuse_abort_conn(fc, true);
38+ if (fc->abort_err)
39+ fc->aborted = true;
40+ fuse_abort_conn(fc);
3941 fuse_conn_put(fc);
4042 }
4143 return count;
fs/fuse/cuse.c+4−3
@@ -141,10 +141,11 @@ static int cuse_open(struct inode *inode, struct file *file) · 140 unmodified lines
141141
142142 static int cuse_release(struct inode *inode, struct file *file)
143143 {
144+ struct fuse_inode *fi = get_fuse_inode(inode);
144145 struct fuse_file *ff = file->private_data;
145146 struct fuse_conn *fc = ff->fc;
146147
147− fuse_sync_release(ff, file->f_flags);
148+ fuse_sync_release(fi, ff, file->f_flags);
148149 fuse_conn_put(fc);
149150
150151 return 0;
@@ -407,7 +408,7 @@ err_unlock: · 256 unmodified lines
407408 err_region:
408409 unregister_chrdev_region(devt, 1);
409410 err:
410− fuse_abort_conn(fc, false);
411+ fuse_abort_conn(fc);
411412 goto out;
412413 }
413414
@@ -586,7 +587,7 @@ static ssize_t cuse_class_abort_store(struct device *dev, · 172 unmodified lines
586587 {
587588 struct cuse_conn *cc = dev_get_drvdata(dev);
588589
589− fuse_abort_conn(&cc->fc, false);
590+ fuse_abort_conn(&cc->fc);
590591 return count;
591592 }
592593 static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store);
fs/fuse/dev.c+66−49
@@ -251,17 +251,18 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc, · 250 unmodified lines
251251 struct file *file)
252252 {
253253 struct fuse_req *req = NULL;
254+ struct fuse_inode *fi = get_fuse_inode(file_inode(file));
254255 struct fuse_file *ff = file->private_data;
255256
256257 do {
257258 wait_event(fc->reserved_req_waitq, ff->reserved_req);
258− spin_lock(&fc->lock);
259+ spin_lock(&fi->lock);
259260 if (ff->reserved_req) {
260261 req = ff->reserved_req;
261262 ff->reserved_req = NULL;
262263 req->stolen_file = get_file(file);
263264 }
264− spin_unlock(&fc->lock);
265+ spin_unlock(&fi->lock);
265266 } while (!req);
266267
267268 return req;
@@ -273,16 +274,17 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc, · 5 unmodified lines
273274 static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req)
274275 {
275276 struct file *file = req->stolen_file;
277+ struct fuse_inode *fi = get_fuse_inode(file_inode(file));
276278 struct fuse_file *ff = file->private_data;
277279
278280 WARN_ON(req->max_pages);
279− spin_lock(&fc->lock);
281+ spin_lock(&fi->lock);
280282 memset(req, 0, sizeof(*req));
281283 fuse_request_init(req, NULL, NULL, 0);
282284 BUG_ON(ff->reserved_req);
283285 ff->reserved_req = req;
284286 wake_up_all(&fc->reserved_req_waitq);
285− spin_unlock(&fc->lock);
287+ spin_unlock(&fi->lock);
286288 fput(file);
287289 }
288290
@@ -431,10 +433,16 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) · 142 unmodified lines
431433
432434 if (test_and_set_bit(FR_FINISHED, &req->flags))
433435 goto put_request;
434−
435− spin_lock(&fiq->waitq.lock);
436− list_del_init(&req->intr_entry);
437− spin_unlock(&fiq->waitq.lock);
436+ /*
437+ * test_and_set_bit() implies smp_mb() between bit
438+ * changing and below intr_entry check. Pairs with
439+ * smp_mb() from queue_interrupt().
440+ */
441+ if (!list_empty(&req->intr_entry)) {
442+ spin_lock(&fiq->waitq.lock);
443+ list_del_init(&req->intr_entry);
444+ spin_unlock(&fiq->waitq.lock);
445+ }
438446 WARN_ON(test_bit(FR_PENDING, &req->flags));
439447 WARN_ON(test_bit(FR_SENT, &req->flags));
440448 if (test_bit(FR_BACKGROUND, &req->flags)) {
@@ -462,27 +470,43 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) · 21 unmodified lines
462470 fc->active_background--;
463471 flush_bg_queue(fc);
464472 spin_unlock(&fc->bg_lock);
473+ } else {
474+ /* Wake up waiter sleeping in request_wait_answer() */
475+ wake_up(&req->waitq);
465476 }
466− wake_up(&req->waitq);
477+
467478 if (req->end)
468479 req->end(fc, req);
469480 put_request:
470481 fuse_put_request(fc, req);
471482 }
472483
473−static void queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
484+static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
474485 {
475486 spin_lock(&fiq->waitq.lock);
476− if (test_bit(FR_FINISHED, &req->flags)) {
487+ /* Check for we've sent request to interrupt this req */
488+ if (unlikely(!test_bit(FR_INTERRUPTED, &req->flags))) {
477489 spin_unlock(&fiq->waitq.lock);
478− return;
490+ return -EINVAL;
479491 }
492+
480493 if (list_empty(&req->intr_entry)) {
481494 list_add_tail(&req->intr_entry, &fiq->interrupts);
495+ /*
496+ * Pairs with smp_mb() implied by test_and_set_bit()
497+ * from request_end().
498+ */
499+ smp_mb();
500+ if (test_bit(FR_FINISHED, &req->flags)) {
501+ list_del_init(&req->intr_entry);
502+ spin_unlock(&fiq->waitq.lock);
503+ return 0;
504+ }
482505 wake_up_locked(&fiq->waitq);
506+ kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
483507 }
484508 spin_unlock(&fiq->waitq.lock);
485− kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
509+ return 0;
486510 }
487511
488512 static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
@@ -1306,7 +1330,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, · 817 unmodified lines
13061330 goto err_unlock;
13071331
13081332 if (!fiq->connected) {
1309− err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV;
1333+ err = fc->aborted ? -ECONNABORTED : -ENODEV;
13101334 goto err_unlock;
13111335 }
13121336
@@ -1353,7 +1377,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, · 40 unmodified lines
13531377 spin_lock(&fpq->lock);
13541378 clear_bit(FR_LOCKED, &req->flags);
13551379 if (!fpq->connected) {
1356− err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV;
1380+ err = fc->aborted ? -ECONNABORTED : -ENODEV;
13571381 goto out_end;
13581382 }
13591383 if (err) {
@@ -1900,16 +1924,17 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, · 540 unmodified lines
19001924 struct fuse_req *req;
19011925 struct fuse_out_header oh;
19021926
1927+ err = -EINVAL;
19031928 if (nbytes < sizeof(struct fuse_out_header))
1904− return -EINVAL;
1929+ goto out;
19051930
19061931 err = fuse_copy_one(cs, &oh, sizeof(oh));
19071932 if (err)
1908− goto err_finish;
1933+ goto copy_finish;
19091934
19101935 err = -EINVAL;
19111936 if (oh.len != nbytes)
1912− goto err_finish;
1937+ goto copy_finish;
19131938
19141939 /*
19151940 * Zero oh.unique indicates unsolicited notification message
@@ -1917,41 +1942,40 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, · 1 unmodified line
19171942 */
19181943 if (!oh.unique) {
19191944 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs);
1920− return err ? err : nbytes;
1945+ goto out;
19211946 }
19221947
19231948 err = -EINVAL;
19241949 if (oh.error <= -1000 || oh.error > 0)
1925− goto err_finish;
1950+ goto copy_finish;
19261951
19271952 spin_lock(&fpq->lock);
1928− err = -ENOENT;
1929− if (!fpq->connected)
1930− goto err_unlock_pq;
1953+ req = NULL;
1954+ if (fpq->connected)
1955+ req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT);
19311956
1932− req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT);
1933− if (!req)
1934− goto err_unlock_pq;
1957+ err = -ENOENT;
1958+ if (!req) {
1959+ spin_unlock(&fpq->lock);
1960+ goto copy_finish;
1961+ }
19351962
19361963 /* Is it an interrupt reply ID? */
19371964 if (oh.unique & FUSE_INT_REQ_BIT) {
19381965 __fuse_get_request(req);
19391966 spin_unlock(&fpq->lock);
19401967
1941− err = -EINVAL;
1942− if (nbytes != sizeof(struct fuse_out_header)) {
1943− fuse_put_request(fc, req);
1944− goto err_finish;
1945− }
1946−
1947− if (oh.error == -ENOSYS)
1968+ err = 0;
1969+ if (nbytes != sizeof(struct fuse_out_header))
1970+ err = -EINVAL;
1971+ else if (oh.error == -ENOSYS)
19481972 fc->no_interrupt = 1;
19491973 else if (oh.error == -EAGAIN)
1950− queue_interrupt(&fc->iq, req);
1974+ err = queue_interrupt(&fc->iq, req);
1975+
19511976 fuse_put_request(fc, req);
19521977
1953− fuse_copy_finish(cs);
1954− return nbytes;
1978+ goto copy_finish;
19551979 }
19561980
19571981 clear_bit(FR_SENT, &req->flags);
@@ -1977,14 +2001,12 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, · 19 unmodified lines
19772001 spin_unlock(&fpq->lock);
19782002
19792003 request_end(fc, req);
1980−
2004+out:
19812005 return err ? err : nbytes;
19822006
1983− err_unlock_pq:
1984− spin_unlock(&fpq->lock);
1985− err_finish:
2007+copy_finish:
19862008 fuse_copy_finish(cs);
1987− return err;
2009+ goto out;
19882010 }
19892011
19902012 static ssize_t fuse_dev_write(struct kiocb *iocb, struct iov_iter *from)
@@ -2109,11 +2131,7 @@ static __poll_t fuse_dev_poll(struct file *file, poll_table *wait) · 118 unmodified lines
21092131 return mask;
21102132 }
21112133
2112−/*
2113− * Abort all requests on the given list (pending or processing)
2114− *
2115− * This function releases and reacquires fc->lock
2116− */
2134+/* Abort all requests on the given list (pending or processing) */
21172135 static void end_requests(struct fuse_conn *fc, struct list_head *head)
21182136 {
21192137 while (!list_empty(head)) {
@@ -2159,7 +2177,7 @@ static void end_polls(struct fuse_conn *fc) · 39 unmodified lines
21592177 * is OK, the request will in that case be removed from the list before we touch
21602178 * it.
21612179 */
2162−void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
2180+void fuse_abort_conn(struct fuse_conn *fc)
21632181 {
21642182 struct fuse_iqueue *fiq = &fc->iq;
21652183
@@ -2175,7 +2193,6 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort) · 9 unmodified lines
21752193 fc->connected = 0;
21762194 spin_unlock(&fc->bg_lock);
21772195
2178− fc->aborted = is_abort;
21792196 fuse_set_initialized(fc);
21802197 list_for_each_entry(fud, &fc->devices, entry) {
21812198 struct fuse_pqueue *fpq = &fud->pq;
@@ -2253,7 +2270,7 @@ int fuse_dev_release(struct inode *inode, struct file *file) · 71 unmodified lines
22532270 /* Are we the last open device? */
22542271 if (atomic_dec_and_test(&fc->dev_count)) {
22552272 WARN_ON(fc->iq.fasync != NULL);
2256− fuse_abort_conn(fc, false);
2273+ fuse_abort_conn(fc);
22572274 }
22582275 fuse_dev_free(fud);
22592276 }
fs/fuse/dir.c+20−34
@@ -149,21 +149,6 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args, · 148 unmodified lines
149149 args->out.args[0].value = outarg;
150150 }
151151
152−u64 fuse_get_attr_version(struct fuse_conn *fc)
153−{
154− u64 curr_version;
155−
156− /*
157− * The spin lock isn't actually needed on 64bit archs, but we
158− * don't yet care too much about such optimizations.
159− */
160− spin_lock(&fc->lock);
161− curr_version = fc->attr_version;
162− spin_unlock(&fc->lock);
163−
164− return curr_version;
165−}
166−
167152 /*
168153 * Check whether the dentry is still valid
169154 *
@@ -222,9 +207,9 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) · 52 unmodified lines
222207 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
223208 goto invalid;
224209 }
225− spin_lock(&fc->lock);
210+ spin_lock(&fi->lock);
226211 fi->nlookup++;
227− spin_unlock(&fc->lock);
212+ spin_unlock(&fi->lock);
228213 }
229214 kfree(forget);
230215 if (ret == -ENOMEM)
@@ -400,6 +385,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, · 169 unmodified lines
400385 struct fuse_create_in inarg;
401386 struct fuse_open_out outopen;
402387 struct fuse_entry_out outentry;
388+ struct fuse_inode *fi;
403389 struct fuse_file *ff;
404390
405391 /* Userspace expects S_IFREG in create mode */
@@ -451,7 +437,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, · 45 unmodified lines
451437 &outentry.attr, entry_attr_timeout(&outentry), 0);
452438 if (!inode) {
453439 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
454− fuse_sync_release(ff, flags);
440+ fuse_sync_release(NULL, ff, flags);
455441 fuse_queue_forget(fc, forget, outentry.nodeid, 1);
456442 err = -ENOMEM;
457443 goto out_err;
@@ -462,7 +448,8 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, · 4 unmodified lines
462448 fuse_dir_changed(dir);
463449 err = finish_open(file, entry, generic_file_open);
464450 if (err) {
465− fuse_sync_release(ff, flags);
451+ fi = get_fuse_inode(inode);
452+ fuse_sync_release(fi, ff, flags);
466453 } else {
467454 file->private_data = ff;
468455 fuse_finish_open(inode, file);
@@ -671,8 +658,8 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) · 202 unmodified lines
671658 struct inode *inode = d_inode(entry);
672659 struct fuse_inode *fi = get_fuse_inode(inode);
673660
674− spin_lock(&fc->lock);
675− fi->attr_version = ++fc->attr_version;
661+ spin_lock(&fi->lock);
662+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
676663 /*
677664 * If i_nlink == 0 then unlink doesn't make sense, yet this can
678665 * happen if userspace filesystem is careless. It would be
@@ -681,7 +668,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) · 2 unmodified lines
681668 */
682669 if (inode->i_nlink > 0)
683670 drop_nlink(inode);
684− spin_unlock(&fc->lock);
671+ spin_unlock(&fi->lock);
685672 fuse_invalidate_attr(inode);
686673 fuse_dir_changed(dir);
687674 fuse_invalidate_entry_cache(entry);
@@ -825,10 +812,10 @@ static int fuse_link(struct dentry *entry, struct inode *newdir, · 137 unmodified lines
825812 if (!err) {
826813 struct fuse_inode *fi = get_fuse_inode(inode);
827814
828− spin_lock(&fc->lock);
829− fi->attr_version = ++fc->attr_version;
815+ spin_lock(&fi->lock);
816+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
830817 inc_nlink(inode);
831− spin_unlock(&fc->lock);
818+ spin_unlock(&fi->lock);
832819 fuse_invalidate_attr(inode);
833820 fuse_update_ctime(inode);
834821 } else if (err == -EINTR) {
@@ -1356,15 +1343,14 @@ static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr, · 521 unmodified lines
13561343 */
13571344 void fuse_set_nowrite(struct inode *inode)
13581345 {
1359− struct fuse_conn *fc = get_fuse_conn(inode);
13601346 struct fuse_inode *fi = get_fuse_inode(inode);
13611347
13621348 BUG_ON(!inode_is_locked(inode));
13631349
1364− spin_lock(&fc->lock);
1350+ spin_lock(&fi->lock);
13651351 BUG_ON(fi->writectr < 0);
13661352 fi->writectr += FUSE_NOWRITE;
1367− spin_unlock(&fc->lock);
1353+ spin_unlock(&fi->lock);
13681354 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
13691355 }
13701356
@@ -1385,11 +1371,11 @@ static void __fuse_release_nowrite(struct inode *inode) · 14 unmodified lines
13851371
13861372 void fuse_release_nowrite(struct inode *inode)
13871373 {
1388− struct fuse_conn *fc = get_fuse_conn(inode);
1374+ struct fuse_inode *fi = get_fuse_inode(inode);
13891375
1390− spin_lock(&fc->lock);
1376+ spin_lock(&fi->lock);
13911377 __fuse_release_nowrite(inode);
1392− spin_unlock(&fc->lock);
1378+ spin_unlock(&fi->lock);
13931379 }
13941380
13951381 static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args,
@@ -1524,7 +1510,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, · 128 unmodified lines
15241510 goto error;
15251511 }
15261512
1527− spin_lock(&fc->lock);
1513+ spin_lock(&fi->lock);
15281514 /* the kernel maintains i_mtime locally */
15291515 if (trust_local_cmtime) {
15301516 if (attr->ia_valid & ATTR_MTIME)
@@ -1542,10 +1528,10 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, · 11 unmodified lines
15421528 i_size_write(inode, outarg.attr.size);
15431529
15441530 if (is_truncate) {
1545− /* NOTE: this may release/reacquire fc->lock */
1531+ /* NOTE: this may release/reacquire fi->lock */
15461532 __fuse_release_nowrite(inode);
15471533 }
1548− spin_unlock(&fc->lock);
1534+ spin_unlock(&fi->lock);
15491535
15501536 /*
15511537 * Only call invalidate_inode_pages2() after removing
fs/fuse/file.c+191−151
@@ -19,8 +19,6 @@ · 18 unmodified lines
1919 #include <linux/falloc.h>
2020 #include <linux/uio.h>
2121
22−static const struct file_operations fuse_direct_io_file_operations;
23−
2422 static int fuse_send_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
2523 int opcode, struct fuse_open_out *outargp)
2624 {
@@ -64,9 +62,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc) · 37 unmodified lines
6462 RB_CLEAR_NODE(&ff->polled_node);
6563 init_waitqueue_head(&ff->poll_wait);
6664
67− spin_lock(&fc->lock);
68− ff->kh = ++fc->khctr;
69− spin_unlock(&fc->lock);
65+ ff->kh = atomic64_inc_return(&fc->khctr);
7066
7167 return ff;
7268 }
@@ -94,7 +90,7 @@ static void fuse_file_put(struct fuse_file *ff, bool sync, bool isdir) · 21 unmodified lines
9490 if (refcount_dec_and_test(&ff->count)) {
9591 struct fuse_req *req = ff->reserved_req;
9692
97− if (ff->fc->no_open && !isdir) {
93+ if (isdir ? ff->fc->no_opendir : ff->fc->no_open) {
9894 /*
9995 * Drop the release request when client does not
10096 * implement 'open'
@@ -128,8 +124,9 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, · 27 unmodified lines
128124 return -ENOMEM;
129125
130126 ff->fh = 0;
131− ff->open_flags = FOPEN_KEEP_CACHE; /* Default for no-open */
132− if (!fc->no_open || isdir) {
127+ /* Default for no-open */
128+ ff->open_flags = FOPEN_KEEP_CACHE | (isdir ? FOPEN_CACHE_DIR : 0);
129+ if (isdir ? !fc->no_opendir : !fc->no_open) {
133130 struct fuse_open_out outarg;
134131 int err;
135132
@@ -138,11 +135,14 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, · 2 unmodified lines
138135 ff->fh = outarg.fh;
139136 ff->open_flags = outarg.open_flags;
140137
141− } else if (err != -ENOSYS || isdir) {
138+ } else if (err != -ENOSYS) {
142139 fuse_file_free(ff);
143140 return err;
144141 } else {
145− fc->no_open = 1;
142+ if (isdir)
143+ fc->no_opendir = 1;
144+ else
145+ fc->no_open = 1;
146146 }
147147 }
148148
@@ -159,17 +159,16 @@ EXPORT_SYMBOL_GPL(fuse_do_open); · 10 unmodified lines
159159 static void fuse_link_write_file(struct file *file)
160160 {
161161 struct inode *inode = file_inode(file);
162− struct fuse_conn *fc = get_fuse_conn(inode);
163162 struct fuse_inode *fi = get_fuse_inode(inode);
164163 struct fuse_file *ff = file->private_data;
165164 /*
166165 * file may be written through mmap, so chain it onto the
167166 * inodes's write_file list
168167 */
169− spin_lock(&fc->lock);
168+ spin_lock(&fi->lock);
170169 if (list_empty(&ff->write_entry))
171170 list_add(&ff->write_entry, &fi->write_files);
172− spin_unlock(&fc->lock);
171+ spin_unlock(&fi->lock);
173172 }
174173
175174 void fuse_finish_open(struct inode *inode, struct file *file)
@@ -177,8 +176,6 @@ void fuse_finish_open(struct inode *inode, struct file *file) · 1 unmodified line
177176 struct fuse_file *ff = file->private_data;
178177 struct fuse_conn *fc = get_fuse_conn(inode);
179178
180− if (ff->open_flags & FOPEN_DIRECT_IO)
181− file->f_op = &fuse_direct_io_file_operations;
182179 if (!(ff->open_flags & FOPEN_KEEP_CACHE))
183180 invalidate_inode_pages2(inode->i_mapping);
184181 if (ff->open_flags & FOPEN_NONSEEKABLE)
@@ -186,10 +183,10 @@ void fuse_finish_open(struct inode *inode, struct file *file) · 1 unmodified line
186183 if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) {
187184 struct fuse_inode *fi = get_fuse_inode(inode);
188185
189− spin_lock(&fc->lock);
190− fi->attr_version = ++fc->attr_version;
186+ spin_lock(&fi->lock);
187+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
191188 i_size_write(inode, 0);
192− spin_unlock(&fc->lock);
189+ spin_unlock(&fi->lock);
193190 fuse_invalidate_attr(inode);
194191 if (fc->writeback_cache)
195192 file_update_time(file);
@@ -224,14 +221,20 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir) · 28 unmodified lines
224221 return err;
225222 }
226223
227−static void fuse_prepare_release(struct fuse_file *ff, int flags, int opcode)
224+static void fuse_prepare_release(struct fuse_inode *fi, struct fuse_file *ff,
225+ int flags, int opcode)
228226 {
229227 struct fuse_conn *fc = ff->fc;
230228 struct fuse_req *req = ff->reserved_req;
231229 struct fuse_release_in *inarg = &req->misc.release.in;
232230
231+ /* Inode is NULL on error path of fuse_create_open() */
232+ if (likely(fi)) {
233+ spin_lock(&fi->lock);
234+ list_del(&ff->write_entry);
235+ spin_unlock(&fi->lock);
236+ }
233237 spin_lock(&fc->lock);
234− list_del(&ff->write_entry);
235238 if (!RB_EMPTY_NODE(&ff->polled_node))
236239 rb_erase(&ff->polled_node, &fc->polled_files);
237240 spin_unlock(&fc->lock);
@@ -249,11 +252,12 @@ static void fuse_prepare_release(struct fuse_file *ff, int flags, int opcode) · 11 unmodified lines
249252
250253 void fuse_release_common(struct file *file, bool isdir)
251254 {
255+ struct fuse_inode *fi = get_fuse_inode(file_inode(file));
252256 struct fuse_file *ff = file->private_data;
253257 struct fuse_req *req = ff->reserved_req;
254258 int opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;
255259
256− fuse_prepare_release(ff, file->f_flags, opcode);
260+ fuse_prepare_release(fi, ff, file->f_flags, opcode);
257261
258262 if (ff->flock) {
259263 struct fuse_release_in *inarg = &req->misc.release.in;
@@ -295,10 +299,10 @@ static int fuse_release(struct inode *inode, struct file *file) · 35 unmodified lines
295299 return 0;
296300 }
297301
298−void fuse_sync_release(struct fuse_file *ff, int flags)
302+void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags)
299303 {
300304 WARN_ON(refcount_read(&ff->count) > 1);
301− fuse_prepare_release(ff, flags, FUSE_RELEASE);
305+ fuse_prepare_release(fi, ff, flags, FUSE_RELEASE);
302306 /*
303307 * iput(NULL) is a no-op and since the refcount is 1 and everything's
304308 * synchronous, we are fine with not doing igrab() here"
@@ -329,33 +333,39 @@ u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id) · 24 unmodified lines
329333 return (u64) v0 + ((u64) v1 << 32);
330334 }
331335
332−/*
333− * Check if any page in a range is under writeback
334− *
335− * This is currently done by walking the list of writepage requests
336− * for the inode, which can be pretty inefficient.
337− */
338−static bool fuse_range_is_writeback(struct inode *inode, pgoff_t idx_from,
339− pgoff_t idx_to)
336+static struct fuse_req *fuse_find_writeback(struct fuse_inode *fi,
337+ pgoff_t idx_from, pgoff_t idx_to)
340338 {
341− struct fuse_conn *fc = get_fuse_conn(inode);
342− struct fuse_inode *fi = get_fuse_inode(inode);
343339 struct fuse_req *req;
344− bool found = false;
345340
346− spin_lock(&fc->lock);
347341 list_for_each_entry(req, &fi->writepages, writepages_entry) {
348342 pgoff_t curr_index;
349343
350− BUG_ON(req->inode != inode);
344+ WARN_ON(get_fuse_inode(req->inode) != fi);
351345 curr_index = req->misc.write.in.offset >> PAGE_SHIFT;
352346 if (idx_from < curr_index + req->num_pages &&
353347 curr_index <= idx_to) {
354− found = true;
355− break;
348+ return req;
356349 }
357350 }
358− spin_unlock(&fc->lock);
351+ return NULL;
352+}
353+
354+/*
355+ * Check if any page in a range is under writeback
356+ *
357+ * This is currently done by walking the list of writepage requests
358+ * for the inode, which can be pretty inefficient.
359+ */
360+static bool fuse_range_is_writeback(struct inode *inode, pgoff_t idx_from,
361+ pgoff_t idx_to)
362+{
363+ struct fuse_inode *fi = get_fuse_inode(inode);
364+ bool found;
365+
366+ spin_lock(&fi->lock);
367+ found = fuse_find_writeback(fi, idx_from, idx_to);
368+ spin_unlock(&fi->lock);
359369
360370 return found;
361371 }
@@ -598,9 +608,9 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos) · 236 unmodified lines
598608 struct fuse_conn *fc = get_fuse_conn(inode);
599609 struct fuse_inode *fi = get_fuse_inode(inode);
600610
601− spin_lock(&fc->lock);
602− fi->attr_version = ++fc->attr_version;
603− spin_unlock(&fc->lock);
611+ spin_lock(&fi->lock);
612+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
613+ spin_unlock(&fi->lock);
604614 }
605615
606616 io->iocb->ki_complete(io->iocb, res, 0);
@@ -675,13 +685,13 @@ static void fuse_read_update_size(struct inode *inode, loff_t size, · 68 unmodified lines
675685 struct fuse_conn *fc = get_fuse_conn(inode);
676686 struct fuse_inode *fi = get_fuse_inode(inode);
677687
678− spin_lock(&fc->lock);
688+ spin_lock(&fi->lock);
679689 if (attr_ver == fi->attr_version && size < inode->i_size &&
680690 !test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
681− fi->attr_version = ++fc->attr_version;
691+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
682692 i_size_write(inode, size);
683693 }
684− spin_unlock(&fc->lock);
694+ spin_unlock(&fi->lock);
685695 }
686696
687697 static void fuse_short_read(struct fuse_req *req, struct inode *inode,
@@ -919,7 +929,7 @@ out: · 231 unmodified lines
919929 return err;
920930 }
921931
922−static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
932+static ssize_t fuse_cache_read_iter(struct kiocb *iocb, struct iov_iter *to)
923933 {
924934 struct inode *inode = iocb->ki_filp->f_mapping->host;
925935 struct fuse_conn *fc = get_fuse_conn(inode);
@@ -996,13 +1006,13 @@ bool fuse_write_update_size(struct inode *inode, loff_t pos) · 70 unmodified lines
9961006 struct fuse_inode *fi = get_fuse_inode(inode);
9971007 bool ret = false;
9981008
999− spin_lock(&fc->lock);
1000− fi->attr_version = ++fc->attr_version;
1009+ spin_lock(&fi->lock);
1010+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
10011011 if (pos > inode->i_size) {
10021012 i_size_write(inode, pos);
10031013 ret = true;
10041014 }
1005− spin_unlock(&fc->lock);
1015+ spin_unlock(&fi->lock);
10061016
10071017 return ret;
10081018 }
@@ -1125,9 +1135,6 @@ static ssize_t fuse_perform_write(struct kiocb *iocb, · 116 unmodified lines
11251135 int err = 0;
11261136 ssize_t res = 0;
11271137
1128− if (is_bad_inode(inode))
1129− return -EIO;
1130−
11311138 if (inode->i_size < pos + iov_iter_count(ii))
11321139 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
11331140
@@ -1173,7 +1180,7 @@ static ssize_t fuse_perform_write(struct kiocb *iocb, · 39 unmodified lines
11731180 return res > 0 ? res : err;
11741181 }
11751182
1176−static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1183+static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
11771184 {
11781185 struct file *file = iocb->ki_filp;
11791186 struct address_space *mapping = file->f_mapping;
@@ -1416,9 +1423,6 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv *io, · 236 unmodified lines
14161423 ssize_t res;
14171424 struct inode *inode = file_inode(io->iocb->ki_filp);
14181425
1419− if (is_bad_inode(inode))
1420− return -EIO;
1421−
14221426 res = fuse_direct_io(io, iter, ppos, 0);
14231427
14241428 fuse_invalidate_atime(inode);
@@ -1426,10 +1430,21 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv *io, · 1 unmodified line
14261430 return res;
14271431 }
14281432
1433+static ssize_t fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
1434+
14291435 static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)
14301436 {
1431− struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb);
1432− return __fuse_direct_read(&io, to, &iocb->ki_pos);
1437+ ssize_t res;
1438+
1439+ if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) {
1440+ res = fuse_direct_IO(iocb, to);
1441+ } else {
1442+ struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb);
1443+
1444+ res = __fuse_direct_read(&io, to, &iocb->ki_pos);
1445+ }
1446+
1447+ return res;
14331448 }
14341449
14351450 static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
@@ -1438,14 +1453,17 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) · 2 unmodified lines
14381453 struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb);
14391454 ssize_t res;
14401455
1441− if (is_bad_inode(inode))
1442− return -EIO;
1443−
14441456 /* Don't allow parallel writes to the same file */
14451457 inode_lock(inode);
14461458 res = generic_write_checks(iocb, from);
1447− if (res > 0)
1448− res = fuse_direct_io(&io, from, &iocb->ki_pos, FUSE_DIO_WRITE);
1459+ if (res > 0) {
1460+ if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) {
1461+ res = fuse_direct_IO(iocb, from);
1462+ } else {
1463+ res = fuse_direct_io(&io, from, &iocb->ki_pos,
1464+ FUSE_DIO_WRITE);
1465+ }
1466+ }
14491467 fuse_invalidate_attr(inode);
14501468 if (res > 0)
14511469 fuse_write_update_size(inode, iocb->ki_pos);
@@ -1454,6 +1472,34 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) · 2 unmodified lines
14541472 return res;
14551473 }
14561474
1475+static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
1476+{
1477+ struct file *file = iocb->ki_filp;
1478+ struct fuse_file *ff = file->private_data;
1479+
1480+ if (is_bad_inode(file_inode(file)))
1481+ return -EIO;
1482+
1483+ if (!(ff->open_flags & FOPEN_DIRECT_IO))
1484+ return fuse_cache_read_iter(iocb, to);
1485+ else
1486+ return fuse_direct_read_iter(iocb, to);
1487+}
1488+
1489+static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1490+{
1491+ struct file *file = iocb->ki_filp;
1492+ struct fuse_file *ff = file->private_data;
1493+
1494+ if (is_bad_inode(file_inode(file)))
1495+ return -EIO;
1496+
1497+ if (!(ff->open_flags & FOPEN_DIRECT_IO))
1498+ return fuse_cache_write_iter(iocb, from);
1499+ else
1500+ return fuse_direct_write_iter(iocb, from);
1501+}
1502+
14571503 static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req)
14581504 {
14591505 int i;
@@ -1481,20 +1527,18 @@ static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req) · 21 unmodified lines
14811527 wake_up(&fi->page_waitq);
14821528 }
14831529
1484−/* Called under fc->lock, may release and reacquire it */
1530+/* Called under fi->lock, may release and reacquire it */
14851531 static void fuse_send_writepage(struct fuse_conn *fc, struct fuse_req *req,
14861532 loff_t size)
1487−__releases(fc->lock)
1488−__acquires(fc->lock)
1533+__releases(fi->lock)
1534+__acquires(fi->lock)
14891535 {
1536+ struct fuse_req *aux, *next;
14901537 struct fuse_inode *fi = get_fuse_inode(req->inode);
14911538 struct fuse_write_in *inarg = &req->misc.write.in;
14921539 __u64 data_size = req->num_pages * PAGE_SIZE;
14931540 bool queued;
14941541
1495− if (!fc->connected)
1496− goto out_free;
1497−
14981542 if (inarg->offset + data_size <= size) {
14991543 inarg->size = data_size;
15001544 } else if (inarg->offset < size) {
@@ -1505,28 +1549,40 @@ __acquires(fc->lock) · 4 unmodified lines
15051549 }
15061550
15071551 req->in.args[1].size = inarg->size;
1508− fi->writectr++;
15091552 queued = fuse_request_queue_background(fc, req);
1510− WARN_ON(!queued);
1553+ /* Fails on broken connection only */
1554+ if (unlikely(!queued))
1555+ goto out_free;
1556+
1557+ fi->writectr++;
15111558 return;
15121559
15131560 out_free:
15141561 fuse_writepage_finish(fc, req);
1515− spin_unlock(&fc->lock);
1562+ spin_unlock(&fi->lock);
1563+
1564+ /* After fuse_writepage_finish() aux request list is private */
1565+ for (aux = req->misc.write.next; aux; aux = next) {
1566+ next = aux->misc.write.next;
1567+ aux->misc.write.next = NULL;
1568+ fuse_writepage_free(fc, aux);
1569+ fuse_put_request(fc, aux);
1570+ }
1571+
15161572 fuse_writepage_free(fc, req);
15171573 fuse_put_request(fc, req);
1518− spin_lock(&fc->lock);
1574+ spin_lock(&fi->lock);
15191575 }
15201576
15211577 /*
15221578 * If fi->writectr is positive (no truncate or fsync going on) send
15231579 * all queued writepage requests.
15241580 *
1525− * Called with fc->lock
1581+ * Called with fi->lock
15261582 */
15271583 void fuse_flush_writepages(struct inode *inode)
1528−__releases(fc->lock)
1529−__acquires(fc->lock)
1584+__releases(fi->lock)
1585+__acquires(fi->lock)
15301586 {
15311587 struct fuse_conn *fc = get_fuse_conn(inode);
15321588 struct fuse_inode *fi = get_fuse_inode(inode);
@@ -1546,7 +1602,7 @@ static void fuse_writepage_end(struct fuse_conn *fc, struct fuse_req *req) · 13 unmodified lines
15461602 struct fuse_inode *fi = get_fuse_inode(inode);
15471603
15481604 mapping_set_error(inode->i_mapping, req->out.h.error);
1549− spin_lock(&fc->lock);
1605+ spin_lock(&fi->lock);
15501606 while (req->misc.write.next) {
15511607 struct fuse_conn *fc = get_fuse_conn(inode);
15521608 struct fuse_write_in *inarg = &req->misc.write.in;
@@ -1583,7 +1639,7 @@ static void fuse_writepage_end(struct fuse_conn *fc, struct fuse_req *req) · 30 unmodified lines
15831639 }
15841640 fi->writectr--;
15851641 fuse_writepage_finish(fc, req);
1586− spin_unlock(&fc->lock);
1642+ spin_unlock(&fi->lock);
15871643 fuse_writepage_free(fc, req);
15881644 }
15891645
@@ -1592,13 +1648,13 @@ static struct fuse_file *__fuse_write_file_get(struct fuse_conn *fc, · 2 unmodified lines
15921648 {
15931649 struct fuse_file *ff = NULL;
15941650
1595− spin_lock(&fc->lock);
1651+ spin_lock(&fi->lock);
15961652 if (!list_empty(&fi->write_files)) {
15971653 ff = list_entry(fi->write_files.next, struct fuse_file,
15981654 write_entry);
15991655 fuse_file_get(ff);
16001656 }
1601− spin_unlock(&fc->lock);
1657+ spin_unlock(&fi->lock);
16021658
16031659 return ff;
16041660 }
@@ -1669,11 +1725,11 @@ static int fuse_writepage_locked(struct page *page) · 64 unmodified lines
16691725 inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK);
16701726 inc_node_page_state(tmp_page, NR_WRITEBACK_TEMP);
16711727
1672− spin_lock(&fc->lock);
1728+ spin_lock(&fi->lock);
16731729 list_add(&req->writepages_entry, &fi->writepages);
16741730 list_add_tail(&req->list, &fi->queued_writes);
16751731 fuse_flush_writepages(inode);
1676− spin_unlock(&fc->lock);
1732+ spin_unlock(&fi->lock);
16771733
16781734 end_page_writeback(page);
16791735
@@ -1722,21 +1778,27 @@ static void fuse_writepages_send(struct fuse_fill_wb_data *data) · 42 unmodified lines
17221778 {
17231779 struct fuse_req *req = data->req;
17241780 struct inode *inode = data->inode;
1725− struct fuse_conn *fc = get_fuse_conn(inode);
17261781 struct fuse_inode *fi = get_fuse_inode(inode);
17271782 int num_pages = req->num_pages;
17281783 int i;
17291784
17301785 req->ff = fuse_file_get(data->ff);
1731− spin_lock(&fc->lock);
1786+ spin_lock(&fi->lock);
17321787 list_add_tail(&req->list, &fi->queued_writes);
17331788 fuse_flush_writepages(inode);
1734− spin_unlock(&fc->lock);
1789+ spin_unlock(&fi->lock);
17351790
17361791 for (i = 0; i < num_pages; i++)
17371792 end_page_writeback(data->orig_pages[i]);
17381793 }
17391794
1795+/*
1796+ * First recheck under fi->lock if the offending offset is still under
1797+ * writeback. If yes, then iterate auxiliary write requests, to see if there's
1798+ * one already added for a page at this offset. If there's none, then insert
1799+ * this new request onto the auxiliary list, otherwise reuse the existing one by
1800+ * copying the new page contents over to the old temporary page.
1801+ */
17401802 static bool fuse_writepage_in_flight(struct fuse_req *new_req,
17411803 struct page *page)
17421804 {
@@ -1744,57 +1806,50 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req, · 1 unmodified line
17441806 struct fuse_inode *fi = get_fuse_inode(new_req->inode);
17451807 struct fuse_req *tmp;
17461808 struct fuse_req *old_req;
1747− bool found = false;
1748− pgoff_t curr_index;
17491809
1750− BUG_ON(new_req->num_pages != 0);
1810+ WARN_ON(new_req->num_pages != 0);
17511811
1752− spin_lock(&fc->lock);
1812+ spin_lock(&fi->lock);
17531813 list_del(&new_req->writepages_entry);
1754− list_for_each_entry(old_req, &fi->writepages, writepages_entry) {
1755− BUG_ON(old_req->inode != new_req->inode);
1756− curr_index = old_req->misc.write.in.offset >> PAGE_SHIFT;
1757− if (curr_index <= page->index &&
1758− page->index < curr_index + old_req->num_pages) {
1759− found = true;
1760− break;
1761− }
1762− }
1763− if (!found) {
1814+ old_req = fuse_find_writeback(fi, page->index, page->index);
1815+ if (!old_req) {
17641816 list_add(&new_req->writepages_entry, &fi->writepages);
1765− goto out_unlock;
1817+ spin_unlock(&fi->lock);
1818+ return false;
17661819 }
17671820
17681821 new_req->num_pages = 1;
1769− for (tmp = old_req; tmp != NULL; tmp = tmp->misc.write.next) {
1770− BUG_ON(tmp->inode != new_req->inode);
1822+ for (tmp = old_req->misc.write.next; tmp; tmp = tmp->misc.write.next) {
1823+ pgoff_t curr_index;
1824+
1825+ WARN_ON(tmp->inode != new_req->inode);
17711826 curr_index = tmp->misc.write.in.offset >> PAGE_SHIFT;
1772− if (tmp->num_pages == 1 &&
1773− curr_index == page->index) {
1774− old_req = tmp;
1827+ if (curr_index == page->index) {
1828+ WARN_ON(tmp->num_pages != 1);
1829+ WARN_ON(!test_bit(FR_PENDING, &tmp->flags));
1830+ swap(tmp->pages[0], new_req->pages[0]);
1831+ break;
17751832 }
17761833 }
17771834
1778− if (old_req->num_pages == 1 && test_bit(FR_PENDING, &old_req->flags)) {
1779− struct backing_dev_info *bdi = inode_to_bdi(page->mapping->host);
1835+ if (!tmp) {
1836+ new_req->misc.write.next = old_req->misc.write.next;
1837+ old_req->misc.write.next = new_req;
1838+ }
1839+
1840+ spin_unlock(&fi->lock);
17801841
1781− copy_highpage(old_req->pages[0], page);
1782− spin_unlock(&fc->lock);
1842+ if (tmp) {
1843+ struct backing_dev_info *bdi = inode_to_bdi(new_req->inode);
17831844
17841845 dec_wb_stat(&bdi->wb, WB_WRITEBACK);
17851846 dec_node_page_state(new_req->pages[0], NR_WRITEBACK_TEMP);
17861847 wb_writeout_inc(&bdi->wb);
17871848 fuse_writepage_free(fc, new_req);
17881849 fuse_request_free(new_req);
1789− goto out;
1790− } else {
1791− new_req->misc.write.next = old_req->misc.write.next;
1792− old_req->misc.write.next = new_req;
17931850 }
1794−out_unlock:
1795− spin_unlock(&fc->lock);
1796−out:
1797− return found;
1851+
1852+ return true;
17981853 }
17991854
18001855 static int fuse_writepages_fill(struct page *page,
@@ -1803,6 +1858,7 @@ static int fuse_writepages_fill(struct page *page, · 2 unmodified lines
18031858 struct fuse_fill_wb_data *data = _data;
18041859 struct fuse_req *req = data->req;
18051860 struct inode *inode = data->inode;
1861+ struct fuse_inode *fi = get_fuse_inode(inode);
18061862 struct fuse_conn *fc = get_fuse_conn(inode);
18071863 struct page *tmp_page;
18081864 bool is_writeback;
@@ -1873,9 +1929,9 @@ static int fuse_writepages_fill(struct page *page, · 64 unmodified lines
18731929 req->end = fuse_writepage_end;
18741930 req->inode = inode;
18751931
1876− spin_lock(&fc->lock);
1932+ spin_lock(&fi->lock);
18771933 list_add(&req->writepages_entry, &fi->writepages);
1878− spin_unlock(&fc->lock);
1934+ spin_unlock(&fi->lock);
18791935
18801936 data->req = req;
18811937 }
@@ -1898,12 +1954,12 @@ static int fuse_writepages_fill(struct page *page, · 16 unmodified lines
18981954 data->orig_pages[req->num_pages] = page;
18991955
19001956 /*
1901− * Protected by fc->lock against concurrent access by
1957+ * Protected by fi->lock against concurrent access by
19021958 * fuse_page_is_writeback().
19031959 */
1904− spin_lock(&fc->lock);
1960+ spin_lock(&fi->lock);
19051961 req->num_pages++;
1906− spin_unlock(&fc->lock);
1962+ spin_unlock(&fi->lock);
19071963
19081964 out_unlock:
19091965 unlock_page(page);
@@ -2087,6 +2143,18 @@ static const struct vm_operations_struct fuse_file_vm_ops = { · 177 unmodified lines
20872143
20882144 static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
20892145 {
2146+ struct fuse_file *ff = file->private_data;
2147+
2148+ if (ff->open_flags & FOPEN_DIRECT_IO) {
2149+ /* Can't provide the coherency needed for MAP_SHARED */
2150+ if (vma->vm_flags & VM_MAYSHARE)
2151+ return -ENODEV;
2152+
2153+ invalidate_inode_pages2(file->f_mapping);
2154+
2155+ return generic_file_mmap(file, vma);
2156+ }
2157+
20902158 if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
20912159 fuse_link_write_file(file);
20922160
@@ -2095,17 +2163,6 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) · 2 unmodified lines
20952163 return 0;
20962164 }
20972165
2098−static int fuse_direct_mmap(struct file *file, struct vm_area_struct *vma)
2099−{
2100− /* Can't provide the coherency needed for MAP_SHARED */
2101− if (vma->vm_flags & VM_MAYSHARE)
2102− return -ENODEV;
2103−
2104− invalidate_inode_pages2(file->f_mapping);
2105−
2106− return generic_file_mmap(file, vma);
2107−}
2108−
21092166 static int convert_fuse_file_lock(struct fuse_conn *fc,
21102167 const struct fuse_file_lock *ffl,
21112168 struct file_lock *fl)
@@ -3114,6 +3171,7 @@ static const struct file_operations fuse_file_operations = { · 1002 unmodified lines
31143171 .lock = fuse_file_lock,
31153172 .flock = fuse_file_flock,
31163173 .splice_read = generic_file_splice_read,
3174+ .splice_write = iter_file_splice_write,
31173175 .unlocked_ioctl = fuse_file_ioctl,
31183176 .compat_ioctl = fuse_file_compat_ioctl,
31193177 .poll = fuse_file_poll,
@@ -3121,24 +3179,6 @@ static const struct file_operations fuse_file_operations = { · 1 unmodified line
31213179 .copy_file_range = fuse_copy_file_range,
31223180 };
31233181
3124−static const struct file_operations fuse_direct_io_file_operations = {
3125− .llseek = fuse_file_llseek,
3126− .read_iter = fuse_direct_read_iter,
3127− .write_iter = fuse_direct_write_iter,
3128− .mmap = fuse_direct_mmap,
3129− .open = fuse_open,
3130− .flush = fuse_flush,
3131− .release = fuse_release,
3132− .fsync = fuse_fsync,
3133− .lock = fuse_file_lock,
3134− .flock = fuse_file_flock,
3135− .unlocked_ioctl = fuse_file_ioctl,
3136− .compat_ioctl = fuse_file_compat_ioctl,
3137− .poll = fuse_file_poll,
3138− .fallocate = fuse_file_fallocate,
3139− /* no splice_read */
3140−};
3141−
31423182 static const struct address_space_operations fuse_file_aops = {
31433183 .readpage = fuse_readpage,
31443184 .writepage = fuse_writepage,
fs/fuse/fuse_i.h+20−8
@@ -96,7 +96,7 @@ struct fuse_inode { · 95 unmodified lines
9696 union {
9797 /* Write related fields (regular file only) */
9898 struct {
99− /* Files usable in writepage. Protected by fc->lock */
99+ /* Files usable in writepage. Protected by fi->lock */
100100 struct list_head write_files;
101101
102102 /* Writepages pending on truncate or fsync */
@@ -144,6 +144,9 @@ struct fuse_inode { · 41 unmodified lines
144144
145145 /** Lock for serializing lookup and readdir for back compatibility*/
146146 struct mutex mutex;
147+
148+ /** Lock to protect write related fields */
149+ spinlock_t lock;
147150 };
148151
149152 /** FUSE inode state bits */
@@ -163,7 +166,10 @@ struct fuse_file { · 13 unmodified lines
163166 /** Fuse connection for this file */
164167 struct fuse_conn *fc;
165168
166− /** Request reserved for flush and release */
169+ /*
170+ * Request reserved for flush and release.
171+ * Modified under relative fuse_inode::lock.
172+ */
167173 struct fuse_req *reserved_req;
168174
169175 /** Kernel file handle guaranteed to be unique */
@@ -538,7 +544,7 @@ struct fuse_conn { · 368 unmodified lines
538544 struct fuse_iqueue iq;
539545
540546 /** The next unique kernel file handle */
541− u64 khctr;
547+ atomic64_t khctr;
542548
543549 /** rbtree of fuse_files waiting for poll events indexed by ph */
544550 struct rb_root polled_files;
@@ -624,6 +630,9 @@ struct fuse_conn { · 79 unmodified lines
624630 /** Is open/release not implemented by fs? */
625631 unsigned no_open:1;
626632
633+ /** Is opendir/releasedir not implemented by fs? */
634+ unsigned no_opendir:1;
635+
627636 /** Is fsync not implemented by fs? */
628637 unsigned no_fsync:1;
629638
@@ -730,7 +739,7 @@ struct fuse_conn { · 100 unmodified lines
730739 struct fuse_req *destroy_req;
731740
732741 /** Version counter for attribute changes */
733− u64 attr_version;
742+ atomic64_t attr_version;
734743
735744 /** Called on final put */
736745 void (*release)(struct fuse_conn *);
@@ -770,6 +779,11 @@ static inline int invalid_nodeid(u64 nodeid) · 33 unmodified lines
770779 return !nodeid || nodeid == FUSE_ROOT_ID;
771780 }
772781
782+static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
783+{
784+ return atomic64_read(&fc->attr_version);
785+}
786+
773787 /** Device operations */
774788 extern const struct file_operations fuse_dev_operations;
775789
@@ -817,7 +831,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); · 41 unmodified lines
817831 void fuse_file_free(struct fuse_file *ff);
818832 void fuse_finish_open(struct inode *inode, struct file *file);
819833
820−void fuse_sync_release(struct fuse_file *ff, int flags);
834+void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
821835
822836 /**
823837 * Send RELEASE or RELEASEDIR request
@@ -936,7 +950,7 @@ void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); · 112 unmodified lines
936950 bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
937951
938952 /* Abort all requests */
939−void fuse_abort_conn(struct fuse_conn *fc, bool is_abort);
953+void fuse_abort_conn(struct fuse_conn *fc);
940954 void fuse_wait_aborted(struct fuse_conn *fc);
941955
942956 /**
@@ -1000,8 +1014,6 @@ void fuse_flush_writepages(struct inode *inode); · 57 unmodified lines
10001014 void fuse_set_nowrite(struct inode *inode);
10011015 void fuse_release_nowrite(struct inode *inode);
10021016
1003−u64 fuse_get_attr_version(struct fuse_conn *fc);
1004−
10051017 /**
10061018 * File-system tells the kernel to invalidate cache for the given node id.
10071019 */
fs/fuse/inode.c+15−11
@@ -97,6 +97,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb) · 96 unmodified lines
9797 fi->orig_ino = 0;
9898 fi->state = 0;
9999 mutex_init(&fi->mutex);
100+ spin_lock_init(&fi->lock);
100101 fi->forget = fuse_alloc_forget();
101102 if (!fi->forget) {
102103 kmem_cache_free(fuse_inode_cachep, inode);
@@ -163,7 +164,9 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, · 60 unmodified lines
163164 struct fuse_conn *fc = get_fuse_conn(inode);
164165 struct fuse_inode *fi = get_fuse_inode(inode);
165166
166− fi->attr_version = ++fc->attr_version;
167+ lockdep_assert_held(&fi->lock);
168+
169+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
167170 fi->i_time = attr_valid;
168171 WRITE_ONCE(fi->inval_mask, 0);
169172
@@ -209,10 +212,10 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, · 39 unmodified lines
209212 loff_t oldsize;
210213 struct timespec64 old_mtime;
211214
212− spin_lock(&fc->lock);
215+ spin_lock(&fi->lock);
213216 if ((attr_version != 0 && fi->attr_version > attr_version) ||
214217 test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
215− spin_unlock(&fc->lock);
218+ spin_unlock(&fi->lock);
216219 return;
217220 }
218221
@@ -227,7 +230,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, · 8 unmodified lines
227230 */
228231 if (!is_wb || !S_ISREG(inode->i_mode))
229232 i_size_write(inode, attr->size);
230− spin_unlock(&fc->lock);
233+ spin_unlock(&fi->lock);
231234
232235 if (!is_wb && S_ISREG(inode->i_mode)) {
233236 bool inval = false;
@@ -322,9 +325,9 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid, · 88 unmodified lines
322325 }
323326
324327 fi = get_fuse_inode(inode);
325− spin_lock(&fc->lock);
328+ spin_lock(&fi->lock);
326329 fi->nlookup++;
327− spin_unlock(&fc->lock);
330+ spin_unlock(&fi->lock);
328331 fuse_change_attributes(inode, attr, attr_valid, attr_version);
329332
330333 return inode;
@@ -376,7 +379,7 @@ void fuse_unlock_inode(struct inode *inode, bool locked) · 45 unmodified lines
376379
377380 static void fuse_umount_begin(struct super_block *sb)
378381 {
379− fuse_abort_conn(get_fuse_conn_super(sb), false);
382+ fuse_abort_conn(get_fuse_conn_super(sb));
380383 }
381384
382385 static void fuse_send_destroy(struct fuse_conn *fc)
@@ -619,12 +622,12 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns) · 236 unmodified lines
619622 atomic_set(&fc->num_waiting, 0);
620623 fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
621624 fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD;
622− fc->khctr = 0;
625+ atomic64_set(&fc->khctr, 0);
623626 fc->polled_files = RB_ROOT;
624627 fc->blocked = 0;
625628 fc->initialized = 0;
626629 fc->connected = 1;
627− fc->attr_version = 1;
630+ atomic64_set(&fc->attr_version, 1);
628631 get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
629632 fc->pid_ns = get_pid_ns(task_active_pid_ns(current));
630633 fc->user_ns = get_user_ns(user_ns);
@@ -969,7 +972,8 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req) · 338 unmodified lines
969972 FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO |
970973 FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT |
971974 FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL |
972− FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS;
975+ FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS |
976+ FUSE_NO_OPENDIR_SUPPORT;
973977 req->in.h.opcode = FUSE_INIT;
974978 req->in.numargs = 1;
975979 req->in.args[0].size = sizeof(*arg);
@@ -1242,7 +1246,7 @@ static void fuse_sb_destroy(struct super_block *sb) · 266 unmodified lines
12421246 if (fc) {
12431247 fuse_send_destroy(fc);
12441248
1245− fuse_abort_conn(fc, false);
1249+ fuse_abort_conn(fc);
12461250 fuse_wait_aborted(fc);
12471251
12481252 down_write(&fc->killsb);
fs/fuse/readdir.c+2−2
@@ -213,9 +213,9 @@ retry: · 212 unmodified lines
213213 }
214214
215215 fi = get_fuse_inode(inode);
216− spin_lock(&fc->lock);
216+ spin_lock(&fi->lock);
217217 fi->nlookup++;
218− spin_unlock(&fc->lock);
218+ spin_unlock(&fi->lock);
219219
220220 forget_all_cached_acls(inode);
221221 fuse_change_attributes(inode, &o->attr,
include/uapi/linux/fuse.h+6−1
@@ -122,6 +122,9 @@ · 121 unmodified lines
122122 * - add FOPEN_CACHE_DIR
123123 * - add FUSE_MAX_PAGES, add max_pages to init_out
124124 * - add FUSE_CACHE_SYMLINKS
125+ *
126+ * 7.29
127+ * - add FUSE_NO_OPENDIR_SUPPORT flag
125128 */
126129
127130 #ifndef _LINUX_FUSE_H
@@ -157,7 +160,7 @@ · 29 unmodified lines
157160 #define FUSE_KERNEL_VERSION 7
158161
159162 /** Minor version number of this interface */
160−#define FUSE_KERNEL_MINOR_VERSION 28
163+#define FUSE_KERNEL_MINOR_VERSION 29
161164
162165 /** The node ID of the root inode */
163166 #define FUSE_ROOT_ID 1
@@ -259,6 +262,7 @@ struct fuse_file_lock { · 95 unmodified lines
259262 * FUSE_ABORT_ERROR: reading the device after abort returns ECONNABORTED
260263 * FUSE_MAX_PAGES: init_out.max_pages contains the max number of req pages
261264 * FUSE_CACHE_SYMLINKS: cache READLINK responses
265+ * FUSE_NO_OPENDIR_SUPPORT: kernel supports zero-message opendir
262266 */
263267 #define FUSE_ASYNC_READ (1 << 0)
264268 #define FUSE_POSIX_LOCKS (1 << 1)
@@ -284,6 +288,7 @@ struct fuse_file_lock { · 19 unmodified lines
284288 #define FUSE_ABORT_ERROR (1 << 21)
285289 #define FUSE_MAX_PAGES (1 << 22)
286290 #define FUSE_CACHE_SYMLINKS (1 << 23)
291+#define FUSE_NO_OPENDIR_SUPPORT (1 << 24)
287292
288293 /**
289294 * CUSE INIT request/reply flags

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t