Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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()
...

+327 -260
+3 -1
fs/fuse/control.c
··· 35 35 { 36 36 struct fuse_conn *fc = fuse_ctl_file_conn_get(file); 37 37 if (fc) { 38 - fuse_abort_conn(fc, true); 38 + if (fc->abort_err) 39 + fc->aborted = true; 40 + fuse_abort_conn(fc); 39 41 fuse_conn_put(fc); 40 42 } 41 43 return count;
+4 -3
fs/fuse/cuse.c
··· 141 141 142 142 static int cuse_release(struct inode *inode, struct file *file) 143 143 { 144 + struct fuse_inode *fi = get_fuse_inode(inode); 144 145 struct fuse_file *ff = file->private_data; 145 146 struct fuse_conn *fc = ff->fc; 146 147 147 - fuse_sync_release(ff, file->f_flags); 148 + fuse_sync_release(fi, ff, file->f_flags); 148 149 fuse_conn_put(fc); 149 150 150 151 return 0; ··· 408 407 err_region: 409 408 unregister_chrdev_region(devt, 1); 410 409 err: 411 - fuse_abort_conn(fc, false); 410 + fuse_abort_conn(fc); 412 411 goto out; 413 412 } 414 413 ··· 587 586 { 588 587 struct cuse_conn *cc = dev_get_drvdata(dev); 589 588 590 - fuse_abort_conn(&cc->fc, false); 589 + fuse_abort_conn(&cc->fc); 591 590 return count; 592 591 } 593 592 static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store);
+66 -49
fs/fuse/dev.c
··· 251 251 struct file *file) 252 252 { 253 253 struct fuse_req *req = NULL; 254 + struct fuse_inode *fi = get_fuse_inode(file_inode(file)); 254 255 struct fuse_file *ff = file->private_data; 255 256 256 257 do { 257 258 wait_event(fc->reserved_req_waitq, ff->reserved_req); 258 - spin_lock(&fc->lock); 259 + spin_lock(&fi->lock); 259 260 if (ff->reserved_req) { 260 261 req = ff->reserved_req; 261 262 ff->reserved_req = NULL; 262 263 req->stolen_file = get_file(file); 263 264 } 264 - spin_unlock(&fc->lock); 265 + spin_unlock(&fi->lock); 265 266 } while (!req); 266 267 267 268 return req; ··· 274 273 static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req) 275 274 { 276 275 struct file *file = req->stolen_file; 276 + struct fuse_inode *fi = get_fuse_inode(file_inode(file)); 277 277 struct fuse_file *ff = file->private_data; 278 278 279 279 WARN_ON(req->max_pages); 280 - spin_lock(&fc->lock); 280 + spin_lock(&fi->lock); 281 281 memset(req, 0, sizeof(*req)); 282 282 fuse_request_init(req, NULL, NULL, 0); 283 283 BUG_ON(ff->reserved_req); 284 284 ff->reserved_req = req; 285 285 wake_up_all(&fc->reserved_req_waitq); 286 - spin_unlock(&fc->lock); 286 + spin_unlock(&fi->lock); 287 287 fput(file); 288 288 } 289 289 ··· 433 431 434 432 if (test_and_set_bit(FR_FINISHED, &req->flags)) 435 433 goto put_request; 436 - 437 - spin_lock(&fiq->waitq.lock); 438 - list_del_init(&req->intr_entry); 439 - spin_unlock(&fiq->waitq.lock); 434 + /* 435 + * test_and_set_bit() implies smp_mb() between bit 436 + * changing and below intr_entry check. Pairs with 437 + * smp_mb() from queue_interrupt(). 438 + */ 439 + if (!list_empty(&req->intr_entry)) { 440 + spin_lock(&fiq->waitq.lock); 441 + list_del_init(&req->intr_entry); 442 + spin_unlock(&fiq->waitq.lock); 443 + } 440 444 WARN_ON(test_bit(FR_PENDING, &req->flags)); 441 445 WARN_ON(test_bit(FR_SENT, &req->flags)); 442 446 if (test_bit(FR_BACKGROUND, &req->flags)) { ··· 470 462 fc->active_background--; 471 463 flush_bg_queue(fc); 472 464 spin_unlock(&fc->bg_lock); 465 + } else { 466 + /* Wake up waiter sleeping in request_wait_answer() */ 467 + wake_up(&req->waitq); 473 468 } 474 - wake_up(&req->waitq); 469 + 475 470 if (req->end) 476 471 req->end(fc, req); 477 472 put_request: 478 473 fuse_put_request(fc, req); 479 474 } 480 475 481 - static void queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req) 476 + static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req) 482 477 { 483 478 spin_lock(&fiq->waitq.lock); 484 - if (test_bit(FR_FINISHED, &req->flags)) { 479 + /* Check for we've sent request to interrupt this req */ 480 + if (unlikely(!test_bit(FR_INTERRUPTED, &req->flags))) { 485 481 spin_unlock(&fiq->waitq.lock); 486 - return; 482 + return -EINVAL; 487 483 } 484 + 488 485 if (list_empty(&req->intr_entry)) { 489 486 list_add_tail(&req->intr_entry, &fiq->interrupts); 487 + /* 488 + * Pairs with smp_mb() implied by test_and_set_bit() 489 + * from request_end(). 490 + */ 491 + smp_mb(); 492 + if (test_bit(FR_FINISHED, &req->flags)) { 493 + list_del_init(&req->intr_entry); 494 + spin_unlock(&fiq->waitq.lock); 495 + return 0; 496 + } 490 497 wake_up_locked(&fiq->waitq); 498 + kill_fasync(&fiq->fasync, SIGIO, POLL_IN); 491 499 } 492 500 spin_unlock(&fiq->waitq.lock); 493 - kill_fasync(&fiq->fasync, SIGIO, POLL_IN); 501 + return 0; 494 502 } 495 503 496 504 static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) ··· 1330 1306 goto err_unlock; 1331 1307 1332 1308 if (!fiq->connected) { 1333 - err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV; 1309 + err = fc->aborted ? -ECONNABORTED : -ENODEV; 1334 1310 goto err_unlock; 1335 1311 } 1336 1312 ··· 1377 1353 spin_lock(&fpq->lock); 1378 1354 clear_bit(FR_LOCKED, &req->flags); 1379 1355 if (!fpq->connected) { 1380 - err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV; 1356 + err = fc->aborted ? -ECONNABORTED : -ENODEV; 1381 1357 goto out_end; 1382 1358 } 1383 1359 if (err) { ··· 1924 1900 struct fuse_req *req; 1925 1901 struct fuse_out_header oh; 1926 1902 1903 + err = -EINVAL; 1927 1904 if (nbytes < sizeof(struct fuse_out_header)) 1928 - return -EINVAL; 1905 + goto out; 1929 1906 1930 1907 err = fuse_copy_one(cs, &oh, sizeof(oh)); 1931 1908 if (err) 1932 - goto err_finish; 1909 + goto copy_finish; 1933 1910 1934 1911 err = -EINVAL; 1935 1912 if (oh.len != nbytes) 1936 - goto err_finish; 1913 + goto copy_finish; 1937 1914 1938 1915 /* 1939 1916 * Zero oh.unique indicates unsolicited notification message ··· 1942 1917 */ 1943 1918 if (!oh.unique) { 1944 1919 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); 1945 - return err ? err : nbytes; 1920 + goto out; 1946 1921 } 1947 1922 1948 1923 err = -EINVAL; 1949 1924 if (oh.error <= -1000 || oh.error > 0) 1950 - goto err_finish; 1925 + goto copy_finish; 1951 1926 1952 1927 spin_lock(&fpq->lock); 1953 - err = -ENOENT; 1954 - if (!fpq->connected) 1955 - goto err_unlock_pq; 1928 + req = NULL; 1929 + if (fpq->connected) 1930 + req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT); 1956 1931 1957 - req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT); 1958 - if (!req) 1959 - goto err_unlock_pq; 1932 + err = -ENOENT; 1933 + if (!req) { 1934 + spin_unlock(&fpq->lock); 1935 + goto copy_finish; 1936 + } 1960 1937 1961 1938 /* Is it an interrupt reply ID? */ 1962 1939 if (oh.unique & FUSE_INT_REQ_BIT) { 1963 1940 __fuse_get_request(req); 1964 1941 spin_unlock(&fpq->lock); 1965 1942 1966 - err = -EINVAL; 1967 - if (nbytes != sizeof(struct fuse_out_header)) { 1968 - fuse_put_request(fc, req); 1969 - goto err_finish; 1970 - } 1971 - 1972 - if (oh.error == -ENOSYS) 1943 + err = 0; 1944 + if (nbytes != sizeof(struct fuse_out_header)) 1945 + err = -EINVAL; 1946 + else if (oh.error == -ENOSYS) 1973 1947 fc->no_interrupt = 1; 1974 1948 else if (oh.error == -EAGAIN) 1975 - queue_interrupt(&fc->iq, req); 1949 + err = queue_interrupt(&fc->iq, req); 1950 + 1976 1951 fuse_put_request(fc, req); 1977 1952 1978 - fuse_copy_finish(cs); 1979 - return nbytes; 1953 + goto copy_finish; 1980 1954 } 1981 1955 1982 1956 clear_bit(FR_SENT, &req->flags); ··· 2001 1977 spin_unlock(&fpq->lock); 2002 1978 2003 1979 request_end(fc, req); 2004 - 1980 + out: 2005 1981 return err ? err : nbytes; 2006 1982 2007 - err_unlock_pq: 2008 - spin_unlock(&fpq->lock); 2009 - err_finish: 1983 + copy_finish: 2010 1984 fuse_copy_finish(cs); 2011 - return err; 1985 + goto out; 2012 1986 } 2013 1987 2014 1988 static ssize_t fuse_dev_write(struct kiocb *iocb, struct iov_iter *from) ··· 2131 2109 return mask; 2132 2110 } 2133 2111 2134 - /* 2135 - * Abort all requests on the given list (pending or processing) 2136 - * 2137 - * This function releases and reacquires fc->lock 2138 - */ 2112 + /* Abort all requests on the given list (pending or processing) */ 2139 2113 static void end_requests(struct fuse_conn *fc, struct list_head *head) 2140 2114 { 2141 2115 while (!list_empty(head)) { ··· 2177 2159 * is OK, the request will in that case be removed from the list before we touch 2178 2160 * it. 2179 2161 */ 2180 - void fuse_abort_conn(struct fuse_conn *fc, bool is_abort) 2162 + void fuse_abort_conn(struct fuse_conn *fc) 2181 2163 { 2182 2164 struct fuse_iqueue *fiq = &fc->iq; 2183 2165 ··· 2193 2175 fc->connected = 0; 2194 2176 spin_unlock(&fc->bg_lock); 2195 2177 2196 - fc->aborted = is_abort; 2197 2178 fuse_set_initialized(fc); 2198 2179 list_for_each_entry(fud, &fc->devices, entry) { 2199 2180 struct fuse_pqueue *fpq = &fud->pq; ··· 2270 2253 /* Are we the last open device? */ 2271 2254 if (atomic_dec_and_test(&fc->dev_count)) { 2272 2255 WARN_ON(fc->iq.fasync != NULL); 2273 - fuse_abort_conn(fc, false); 2256 + fuse_abort_conn(fc); 2274 2257 } 2275 2258 fuse_dev_free(fud); 2276 2259 }
+20 -34
fs/fuse/dir.c
··· 149 149 args->out.args[0].value = outarg; 150 150 } 151 151 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 - 167 152 /* 168 153 * Check whether the dentry is still valid 169 154 * ··· 207 222 fuse_queue_forget(fc, forget, outarg.nodeid, 1); 208 223 goto invalid; 209 224 } 210 - spin_lock(&fc->lock); 225 + spin_lock(&fi->lock); 211 226 fi->nlookup++; 212 - spin_unlock(&fc->lock); 227 + spin_unlock(&fi->lock); 213 228 } 214 229 kfree(forget); 215 230 if (ret == -ENOMEM) ··· 385 400 struct fuse_create_in inarg; 386 401 struct fuse_open_out outopen; 387 402 struct fuse_entry_out outentry; 403 + struct fuse_inode *fi; 388 404 struct fuse_file *ff; 389 405 390 406 /* Userspace expects S_IFREG in create mode */ ··· 437 451 &outentry.attr, entry_attr_timeout(&outentry), 0); 438 452 if (!inode) { 439 453 flags &= ~(O_CREAT | O_EXCL | O_TRUNC); 440 - fuse_sync_release(ff, flags); 454 + fuse_sync_release(NULL, ff, flags); 441 455 fuse_queue_forget(fc, forget, outentry.nodeid, 1); 442 456 err = -ENOMEM; 443 457 goto out_err; ··· 448 462 fuse_dir_changed(dir); 449 463 err = finish_open(file, entry, generic_file_open); 450 464 if (err) { 451 - fuse_sync_release(ff, flags); 465 + fi = get_fuse_inode(inode); 466 + fuse_sync_release(fi, ff, flags); 452 467 } else { 453 468 file->private_data = ff; 454 469 fuse_finish_open(inode, file); ··· 658 671 struct inode *inode = d_inode(entry); 659 672 struct fuse_inode *fi = get_fuse_inode(inode); 660 673 661 - spin_lock(&fc->lock); 662 - fi->attr_version = ++fc->attr_version; 674 + spin_lock(&fi->lock); 675 + fi->attr_version = atomic64_inc_return(&fc->attr_version); 663 676 /* 664 677 * If i_nlink == 0 then unlink doesn't make sense, yet this can 665 678 * happen if userspace filesystem is careless. It would be ··· 668 681 */ 669 682 if (inode->i_nlink > 0) 670 683 drop_nlink(inode); 671 - spin_unlock(&fc->lock); 684 + spin_unlock(&fi->lock); 672 685 fuse_invalidate_attr(inode); 673 686 fuse_dir_changed(dir); 674 687 fuse_invalidate_entry_cache(entry); ··· 812 825 if (!err) { 813 826 struct fuse_inode *fi = get_fuse_inode(inode); 814 827 815 - spin_lock(&fc->lock); 816 - fi->attr_version = ++fc->attr_version; 828 + spin_lock(&fi->lock); 829 + fi->attr_version = atomic64_inc_return(&fc->attr_version); 817 830 inc_nlink(inode); 818 - spin_unlock(&fc->lock); 831 + spin_unlock(&fi->lock); 819 832 fuse_invalidate_attr(inode); 820 833 fuse_update_ctime(inode); 821 834 } else if (err == -EINTR) { ··· 1343 1356 */ 1344 1357 void fuse_set_nowrite(struct inode *inode) 1345 1358 { 1346 - struct fuse_conn *fc = get_fuse_conn(inode); 1347 1359 struct fuse_inode *fi = get_fuse_inode(inode); 1348 1360 1349 1361 BUG_ON(!inode_is_locked(inode)); 1350 1362 1351 - spin_lock(&fc->lock); 1363 + spin_lock(&fi->lock); 1352 1364 BUG_ON(fi->writectr < 0); 1353 1365 fi->writectr += FUSE_NOWRITE; 1354 - spin_unlock(&fc->lock); 1366 + spin_unlock(&fi->lock); 1355 1367 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE); 1356 1368 } 1357 1369 ··· 1371 1385 1372 1386 void fuse_release_nowrite(struct inode *inode) 1373 1387 { 1374 - struct fuse_conn *fc = get_fuse_conn(inode); 1388 + struct fuse_inode *fi = get_fuse_inode(inode); 1375 1389 1376 - spin_lock(&fc->lock); 1390 + spin_lock(&fi->lock); 1377 1391 __fuse_release_nowrite(inode); 1378 - spin_unlock(&fc->lock); 1392 + spin_unlock(&fi->lock); 1379 1393 } 1380 1394 1381 1395 static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args, ··· 1510 1524 goto error; 1511 1525 } 1512 1526 1513 - spin_lock(&fc->lock); 1527 + spin_lock(&fi->lock); 1514 1528 /* the kernel maintains i_mtime locally */ 1515 1529 if (trust_local_cmtime) { 1516 1530 if (attr->ia_valid & ATTR_MTIME) ··· 1528 1542 i_size_write(inode, outarg.attr.size); 1529 1543 1530 1544 if (is_truncate) { 1531 - /* NOTE: this may release/reacquire fc->lock */ 1545 + /* NOTE: this may release/reacquire fi->lock */ 1532 1546 __fuse_release_nowrite(inode); 1533 1547 } 1534 - spin_unlock(&fc->lock); 1548 + spin_unlock(&fi->lock); 1535 1549 1536 1550 /* 1537 1551 * Only call invalidate_inode_pages2() after removing
+191 -151
fs/fuse/file.c
··· 19 19 #include <linux/falloc.h> 20 20 #include <linux/uio.h> 21 21 22 - static const struct file_operations fuse_direct_io_file_operations; 23 - 24 22 static int fuse_send_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 25 23 int opcode, struct fuse_open_out *outargp) 26 24 { ··· 62 64 RB_CLEAR_NODE(&ff->polled_node); 63 65 init_waitqueue_head(&ff->poll_wait); 64 66 65 - spin_lock(&fc->lock); 66 - ff->kh = ++fc->khctr; 67 - spin_unlock(&fc->lock); 67 + ff->kh = atomic64_inc_return(&fc->khctr); 68 68 69 69 return ff; 70 70 } ··· 90 94 if (refcount_dec_and_test(&ff->count)) { 91 95 struct fuse_req *req = ff->reserved_req; 92 96 93 - if (ff->fc->no_open && !isdir) { 97 + if (isdir ? ff->fc->no_opendir : ff->fc->no_open) { 94 98 /* 95 99 * Drop the release request when client does not 96 100 * implement 'open' ··· 124 128 return -ENOMEM; 125 129 126 130 ff->fh = 0; 127 - ff->open_flags = FOPEN_KEEP_CACHE; /* Default for no-open */ 128 - if (!fc->no_open || isdir) { 131 + /* Default for no-open */ 132 + ff->open_flags = FOPEN_KEEP_CACHE | (isdir ? FOPEN_CACHE_DIR : 0); 133 + if (isdir ? !fc->no_opendir : !fc->no_open) { 129 134 struct fuse_open_out outarg; 130 135 int err; 131 136 ··· 135 138 ff->fh = outarg.fh; 136 139 ff->open_flags = outarg.open_flags; 137 140 138 - } else if (err != -ENOSYS || isdir) { 141 + } else if (err != -ENOSYS) { 139 142 fuse_file_free(ff); 140 143 return err; 141 144 } else { 142 - fc->no_open = 1; 145 + if (isdir) 146 + fc->no_opendir = 1; 147 + else 148 + fc->no_open = 1; 143 149 } 144 150 } 145 151 ··· 159 159 static void fuse_link_write_file(struct file *file) 160 160 { 161 161 struct inode *inode = file_inode(file); 162 - struct fuse_conn *fc = get_fuse_conn(inode); 163 162 struct fuse_inode *fi = get_fuse_inode(inode); 164 163 struct fuse_file *ff = file->private_data; 165 164 /* 166 165 * file may be written through mmap, so chain it onto the 167 166 * inodes's write_file list 168 167 */ 169 - spin_lock(&fc->lock); 168 + spin_lock(&fi->lock); 170 169 if (list_empty(&ff->write_entry)) 171 170 list_add(&ff->write_entry, &fi->write_files); 172 - spin_unlock(&fc->lock); 171 + spin_unlock(&fi->lock); 173 172 } 174 173 175 174 void fuse_finish_open(struct inode *inode, struct file *file) ··· 176 177 struct fuse_file *ff = file->private_data; 177 178 struct fuse_conn *fc = get_fuse_conn(inode); 178 179 179 - if (ff->open_flags & FOPEN_DIRECT_IO) 180 - file->f_op = &fuse_direct_io_file_operations; 181 180 if (!(ff->open_flags & FOPEN_KEEP_CACHE)) 182 181 invalidate_inode_pages2(inode->i_mapping); 183 182 if (ff->open_flags & FOPEN_NONSEEKABLE) ··· 183 186 if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) { 184 187 struct fuse_inode *fi = get_fuse_inode(inode); 185 188 186 - spin_lock(&fc->lock); 187 - fi->attr_version = ++fc->attr_version; 189 + spin_lock(&fi->lock); 190 + fi->attr_version = atomic64_inc_return(&fc->attr_version); 188 191 i_size_write(inode, 0); 189 - spin_unlock(&fc->lock); 192 + spin_unlock(&fi->lock); 190 193 fuse_invalidate_attr(inode); 191 194 if (fc->writeback_cache) 192 195 file_update_time(file); ··· 221 224 return err; 222 225 } 223 226 224 - static void fuse_prepare_release(struct fuse_file *ff, int flags, int opcode) 227 + static void fuse_prepare_release(struct fuse_inode *fi, struct fuse_file *ff, 228 + int flags, int opcode) 225 229 { 226 230 struct fuse_conn *fc = ff->fc; 227 231 struct fuse_req *req = ff->reserved_req; 228 232 struct fuse_release_in *inarg = &req->misc.release.in; 229 233 234 + /* Inode is NULL on error path of fuse_create_open() */ 235 + if (likely(fi)) { 236 + spin_lock(&fi->lock); 237 + list_del(&ff->write_entry); 238 + spin_unlock(&fi->lock); 239 + } 230 240 spin_lock(&fc->lock); 231 - list_del(&ff->write_entry); 232 241 if (!RB_EMPTY_NODE(&ff->polled_node)) 233 242 rb_erase(&ff->polled_node, &fc->polled_files); 234 243 spin_unlock(&fc->lock); ··· 252 249 253 250 void fuse_release_common(struct file *file, bool isdir) 254 251 { 252 + struct fuse_inode *fi = get_fuse_inode(file_inode(file)); 255 253 struct fuse_file *ff = file->private_data; 256 254 struct fuse_req *req = ff->reserved_req; 257 255 int opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE; 258 256 259 - fuse_prepare_release(ff, file->f_flags, opcode); 257 + fuse_prepare_release(fi, ff, file->f_flags, opcode); 260 258 261 259 if (ff->flock) { 262 260 struct fuse_release_in *inarg = &req->misc.release.in; ··· 299 295 return 0; 300 296 } 301 297 302 - void fuse_sync_release(struct fuse_file *ff, int flags) 298 + void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags) 303 299 { 304 300 WARN_ON(refcount_read(&ff->count) > 1); 305 - fuse_prepare_release(ff, flags, FUSE_RELEASE); 301 + fuse_prepare_release(fi, ff, flags, FUSE_RELEASE); 306 302 /* 307 303 * iput(NULL) is a no-op and since the refcount is 1 and everything's 308 304 * synchronous, we are fine with not doing igrab() here" ··· 333 329 return (u64) v0 + ((u64) v1 << 32); 334 330 } 335 331 332 + static struct fuse_req *fuse_find_writeback(struct fuse_inode *fi, 333 + pgoff_t idx_from, pgoff_t idx_to) 334 + { 335 + struct fuse_req *req; 336 + 337 + list_for_each_entry(req, &fi->writepages, writepages_entry) { 338 + pgoff_t curr_index; 339 + 340 + WARN_ON(get_fuse_inode(req->inode) != fi); 341 + curr_index = req->misc.write.in.offset >> PAGE_SHIFT; 342 + if (idx_from < curr_index + req->num_pages && 343 + curr_index <= idx_to) { 344 + return req; 345 + } 346 + } 347 + return NULL; 348 + } 349 + 336 350 /* 337 351 * Check if any page in a range is under writeback 338 352 * ··· 360 338 static bool fuse_range_is_writeback(struct inode *inode, pgoff_t idx_from, 361 339 pgoff_t idx_to) 362 340 { 363 - struct fuse_conn *fc = get_fuse_conn(inode); 364 341 struct fuse_inode *fi = get_fuse_inode(inode); 365 - struct fuse_req *req; 366 - bool found = false; 342 + bool found; 367 343 368 - spin_lock(&fc->lock); 369 - list_for_each_entry(req, &fi->writepages, writepages_entry) { 370 - pgoff_t curr_index; 371 - 372 - BUG_ON(req->inode != inode); 373 - curr_index = req->misc.write.in.offset >> PAGE_SHIFT; 374 - if (idx_from < curr_index + req->num_pages && 375 - curr_index <= idx_to) { 376 - found = true; 377 - break; 378 - } 379 - } 380 - spin_unlock(&fc->lock); 344 + spin_lock(&fi->lock); 345 + found = fuse_find_writeback(fi, idx_from, idx_to); 346 + spin_unlock(&fi->lock); 381 347 382 348 return found; 383 349 } ··· 608 598 struct fuse_conn *fc = get_fuse_conn(inode); 609 599 struct fuse_inode *fi = get_fuse_inode(inode); 610 600 611 - spin_lock(&fc->lock); 612 - fi->attr_version = ++fc->attr_version; 613 - spin_unlock(&fc->lock); 601 + spin_lock(&fi->lock); 602 + fi->attr_version = atomic64_inc_return(&fc->attr_version); 603 + spin_unlock(&fi->lock); 614 604 } 615 605 616 606 io->iocb->ki_complete(io->iocb, res, 0); ··· 685 675 struct fuse_conn *fc = get_fuse_conn(inode); 686 676 struct fuse_inode *fi = get_fuse_inode(inode); 687 677 688 - spin_lock(&fc->lock); 678 + spin_lock(&fi->lock); 689 679 if (attr_ver == fi->attr_version && size < inode->i_size && 690 680 !test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) { 691 - fi->attr_version = ++fc->attr_version; 681 + fi->attr_version = atomic64_inc_return(&fc->attr_version); 692 682 i_size_write(inode, size); 693 683 } 694 - spin_unlock(&fc->lock); 684 + spin_unlock(&fi->lock); 695 685 } 696 686 697 687 static void fuse_short_read(struct fuse_req *req, struct inode *inode, ··· 929 919 return err; 930 920 } 931 921 932 - static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to) 922 + static ssize_t fuse_cache_read_iter(struct kiocb *iocb, struct iov_iter *to) 933 923 { 934 924 struct inode *inode = iocb->ki_filp->f_mapping->host; 935 925 struct fuse_conn *fc = get_fuse_conn(inode); ··· 1006 996 struct fuse_inode *fi = get_fuse_inode(inode); 1007 997 bool ret = false; 1008 998 1009 - spin_lock(&fc->lock); 1010 - fi->attr_version = ++fc->attr_version; 999 + spin_lock(&fi->lock); 1000 + fi->attr_version = atomic64_inc_return(&fc->attr_version); 1011 1001 if (pos > inode->i_size) { 1012 1002 i_size_write(inode, pos); 1013 1003 ret = true; 1014 1004 } 1015 - spin_unlock(&fc->lock); 1005 + spin_unlock(&fi->lock); 1016 1006 1017 1007 return ret; 1018 1008 } ··· 1135 1125 int err = 0; 1136 1126 ssize_t res = 0; 1137 1127 1138 - if (is_bad_inode(inode)) 1139 - return -EIO; 1140 - 1141 1128 if (inode->i_size < pos + iov_iter_count(ii)) 1142 1129 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); 1143 1130 ··· 1180 1173 return res > 0 ? res : err; 1181 1174 } 1182 1175 1183 - static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from) 1176 + static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) 1184 1177 { 1185 1178 struct file *file = iocb->ki_filp; 1186 1179 struct address_space *mapping = file->f_mapping; ··· 1423 1416 ssize_t res; 1424 1417 struct inode *inode = file_inode(io->iocb->ki_filp); 1425 1418 1426 - if (is_bad_inode(inode)) 1427 - return -EIO; 1428 - 1429 1419 res = fuse_direct_io(io, iter, ppos, 0); 1430 1420 1431 1421 fuse_invalidate_atime(inode); ··· 1430 1426 return res; 1431 1427 } 1432 1428 1429 + static ssize_t fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter); 1430 + 1433 1431 static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to) 1434 1432 { 1435 - struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb); 1436 - return __fuse_direct_read(&io, to, &iocb->ki_pos); 1433 + ssize_t res; 1434 + 1435 + if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) { 1436 + res = fuse_direct_IO(iocb, to); 1437 + } else { 1438 + struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb); 1439 + 1440 + res = __fuse_direct_read(&io, to, &iocb->ki_pos); 1441 + } 1442 + 1443 + return res; 1437 1444 } 1438 1445 1439 1446 static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from) ··· 1453 1438 struct fuse_io_priv io = FUSE_IO_PRIV_SYNC(iocb); 1454 1439 ssize_t res; 1455 1440 1456 - if (is_bad_inode(inode)) 1457 - return -EIO; 1458 - 1459 1441 /* Don't allow parallel writes to the same file */ 1460 1442 inode_lock(inode); 1461 1443 res = generic_write_checks(iocb, from); 1462 - if (res > 0) 1463 - res = fuse_direct_io(&io, from, &iocb->ki_pos, FUSE_DIO_WRITE); 1444 + if (res > 0) { 1445 + if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) { 1446 + res = fuse_direct_IO(iocb, from); 1447 + } else { 1448 + res = fuse_direct_io(&io, from, &iocb->ki_pos, 1449 + FUSE_DIO_WRITE); 1450 + } 1451 + } 1464 1452 fuse_invalidate_attr(inode); 1465 1453 if (res > 0) 1466 1454 fuse_write_update_size(inode, iocb->ki_pos); 1467 1455 inode_unlock(inode); 1468 1456 1469 1457 return res; 1458 + } 1459 + 1460 + static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to) 1461 + { 1462 + struct file *file = iocb->ki_filp; 1463 + struct fuse_file *ff = file->private_data; 1464 + 1465 + if (is_bad_inode(file_inode(file))) 1466 + return -EIO; 1467 + 1468 + if (!(ff->open_flags & FOPEN_DIRECT_IO)) 1469 + return fuse_cache_read_iter(iocb, to); 1470 + else 1471 + return fuse_direct_read_iter(iocb, to); 1472 + } 1473 + 1474 + static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from) 1475 + { 1476 + struct file *file = iocb->ki_filp; 1477 + struct fuse_file *ff = file->private_data; 1478 + 1479 + if (is_bad_inode(file_inode(file))) 1480 + return -EIO; 1481 + 1482 + if (!(ff->open_flags & FOPEN_DIRECT_IO)) 1483 + return fuse_cache_write_iter(iocb, from); 1484 + else 1485 + return fuse_direct_write_iter(iocb, from); 1470 1486 } 1471 1487 1472 1488 static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req) ··· 1527 1481 wake_up(&fi->page_waitq); 1528 1482 } 1529 1483 1530 - /* Called under fc->lock, may release and reacquire it */ 1484 + /* Called under fi->lock, may release and reacquire it */ 1531 1485 static void fuse_send_writepage(struct fuse_conn *fc, struct fuse_req *req, 1532 1486 loff_t size) 1533 - __releases(fc->lock) 1534 - __acquires(fc->lock) 1487 + __releases(fi->lock) 1488 + __acquires(fi->lock) 1535 1489 { 1490 + struct fuse_req *aux, *next; 1536 1491 struct fuse_inode *fi = get_fuse_inode(req->inode); 1537 1492 struct fuse_write_in *inarg = &req->misc.write.in; 1538 1493 __u64 data_size = req->num_pages * PAGE_SIZE; 1539 1494 bool queued; 1540 - 1541 - if (!fc->connected) 1542 - goto out_free; 1543 1495 1544 1496 if (inarg->offset + data_size <= size) { 1545 1497 inarg->size = data_size; ··· 1549 1505 } 1550 1506 1551 1507 req->in.args[1].size = inarg->size; 1552 - fi->writectr++; 1553 1508 queued = fuse_request_queue_background(fc, req); 1554 - WARN_ON(!queued); 1509 + /* Fails on broken connection only */ 1510 + if (unlikely(!queued)) 1511 + goto out_free; 1512 + 1513 + fi->writectr++; 1555 1514 return; 1556 1515 1557 1516 out_free: 1558 1517 fuse_writepage_finish(fc, req); 1559 - spin_unlock(&fc->lock); 1518 + spin_unlock(&fi->lock); 1519 + 1520 + /* After fuse_writepage_finish() aux request list is private */ 1521 + for (aux = req->misc.write.next; aux; aux = next) { 1522 + next = aux->misc.write.next; 1523 + aux->misc.write.next = NULL; 1524 + fuse_writepage_free(fc, aux); 1525 + fuse_put_request(fc, aux); 1526 + } 1527 + 1560 1528 fuse_writepage_free(fc, req); 1561 1529 fuse_put_request(fc, req); 1562 - spin_lock(&fc->lock); 1530 + spin_lock(&fi->lock); 1563 1531 } 1564 1532 1565 1533 /* 1566 1534 * If fi->writectr is positive (no truncate or fsync going on) send 1567 1535 * all queued writepage requests. 1568 1536 * 1569 - * Called with fc->lock 1537 + * Called with fi->lock 1570 1538 */ 1571 1539 void fuse_flush_writepages(struct inode *inode) 1572 - __releases(fc->lock) 1573 - __acquires(fc->lock) 1540 + __releases(fi->lock) 1541 + __acquires(fi->lock) 1574 1542 { 1575 1543 struct fuse_conn *fc = get_fuse_conn(inode); 1576 1544 struct fuse_inode *fi = get_fuse_inode(inode); ··· 1602 1546 struct fuse_inode *fi = get_fuse_inode(inode); 1603 1547 1604 1548 mapping_set_error(inode->i_mapping, req->out.h.error); 1605 - spin_lock(&fc->lock); 1549 + spin_lock(&fi->lock); 1606 1550 while (req->misc.write.next) { 1607 1551 struct fuse_conn *fc = get_fuse_conn(inode); 1608 1552 struct fuse_write_in *inarg = &req->misc.write.in; ··· 1639 1583 } 1640 1584 fi->writectr--; 1641 1585 fuse_writepage_finish(fc, req); 1642 - spin_unlock(&fc->lock); 1586 + spin_unlock(&fi->lock); 1643 1587 fuse_writepage_free(fc, req); 1644 1588 } 1645 1589 ··· 1648 1592 { 1649 1593 struct fuse_file *ff = NULL; 1650 1594 1651 - spin_lock(&fc->lock); 1595 + spin_lock(&fi->lock); 1652 1596 if (!list_empty(&fi->write_files)) { 1653 1597 ff = list_entry(fi->write_files.next, struct fuse_file, 1654 1598 write_entry); 1655 1599 fuse_file_get(ff); 1656 1600 } 1657 - spin_unlock(&fc->lock); 1601 + spin_unlock(&fi->lock); 1658 1602 1659 1603 return ff; 1660 1604 } ··· 1725 1669 inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK); 1726 1670 inc_node_page_state(tmp_page, NR_WRITEBACK_TEMP); 1727 1671 1728 - spin_lock(&fc->lock); 1672 + spin_lock(&fi->lock); 1729 1673 list_add(&req->writepages_entry, &fi->writepages); 1730 1674 list_add_tail(&req->list, &fi->queued_writes); 1731 1675 fuse_flush_writepages(inode); 1732 - spin_unlock(&fc->lock); 1676 + spin_unlock(&fi->lock); 1733 1677 1734 1678 end_page_writeback(page); 1735 1679 ··· 1778 1722 { 1779 1723 struct fuse_req *req = data->req; 1780 1724 struct inode *inode = data->inode; 1781 - struct fuse_conn *fc = get_fuse_conn(inode); 1782 1725 struct fuse_inode *fi = get_fuse_inode(inode); 1783 1726 int num_pages = req->num_pages; 1784 1727 int i; 1785 1728 1786 1729 req->ff = fuse_file_get(data->ff); 1787 - spin_lock(&fc->lock); 1730 + spin_lock(&fi->lock); 1788 1731 list_add_tail(&req->list, &fi->queued_writes); 1789 1732 fuse_flush_writepages(inode); 1790 - spin_unlock(&fc->lock); 1733 + spin_unlock(&fi->lock); 1791 1734 1792 1735 for (i = 0; i < num_pages; i++) 1793 1736 end_page_writeback(data->orig_pages[i]); 1794 1737 } 1795 1738 1739 + /* 1740 + * First recheck under fi->lock if the offending offset is still under 1741 + * writeback. If yes, then iterate auxiliary write requests, to see if there's 1742 + * one already added for a page at this offset. If there's none, then insert 1743 + * this new request onto the auxiliary list, otherwise reuse the existing one by 1744 + * copying the new page contents over to the old temporary page. 1745 + */ 1796 1746 static bool fuse_writepage_in_flight(struct fuse_req *new_req, 1797 1747 struct page *page) 1798 1748 { ··· 1806 1744 struct fuse_inode *fi = get_fuse_inode(new_req->inode); 1807 1745 struct fuse_req *tmp; 1808 1746 struct fuse_req *old_req; 1809 - bool found = false; 1810 - pgoff_t curr_index; 1811 1747 1812 - BUG_ON(new_req->num_pages != 0); 1748 + WARN_ON(new_req->num_pages != 0); 1813 1749 1814 - spin_lock(&fc->lock); 1750 + spin_lock(&fi->lock); 1815 1751 list_del(&new_req->writepages_entry); 1816 - list_for_each_entry(old_req, &fi->writepages, writepages_entry) { 1817 - BUG_ON(old_req->inode != new_req->inode); 1818 - curr_index = old_req->misc.write.in.offset >> PAGE_SHIFT; 1819 - if (curr_index <= page->index && 1820 - page->index < curr_index + old_req->num_pages) { 1821 - found = true; 1822 - break; 1823 - } 1824 - } 1825 - if (!found) { 1752 + old_req = fuse_find_writeback(fi, page->index, page->index); 1753 + if (!old_req) { 1826 1754 list_add(&new_req->writepages_entry, &fi->writepages); 1827 - goto out_unlock; 1755 + spin_unlock(&fi->lock); 1756 + return false; 1828 1757 } 1829 1758 1830 1759 new_req->num_pages = 1; 1831 - for (tmp = old_req; tmp != NULL; tmp = tmp->misc.write.next) { 1832 - BUG_ON(tmp->inode != new_req->inode); 1760 + for (tmp = old_req->misc.write.next; tmp; tmp = tmp->misc.write.next) { 1761 + pgoff_t curr_index; 1762 + 1763 + WARN_ON(tmp->inode != new_req->inode); 1833 1764 curr_index = tmp->misc.write.in.offset >> PAGE_SHIFT; 1834 - if (tmp->num_pages == 1 && 1835 - curr_index == page->index) { 1836 - old_req = tmp; 1765 + if (curr_index == page->index) { 1766 + WARN_ON(tmp->num_pages != 1); 1767 + WARN_ON(!test_bit(FR_PENDING, &tmp->flags)); 1768 + swap(tmp->pages[0], new_req->pages[0]); 1769 + break; 1837 1770 } 1838 1771 } 1839 1772 1840 - if (old_req->num_pages == 1 && test_bit(FR_PENDING, &old_req->flags)) { 1841 - struct backing_dev_info *bdi = inode_to_bdi(page->mapping->host); 1773 + if (!tmp) { 1774 + new_req->misc.write.next = old_req->misc.write.next; 1775 + old_req->misc.write.next = new_req; 1776 + } 1842 1777 1843 - copy_highpage(old_req->pages[0], page); 1844 - spin_unlock(&fc->lock); 1778 + spin_unlock(&fi->lock); 1779 + 1780 + if (tmp) { 1781 + struct backing_dev_info *bdi = inode_to_bdi(new_req->inode); 1845 1782 1846 1783 dec_wb_stat(&bdi->wb, WB_WRITEBACK); 1847 1784 dec_node_page_state(new_req->pages[0], NR_WRITEBACK_TEMP); 1848 1785 wb_writeout_inc(&bdi->wb); 1849 1786 fuse_writepage_free(fc, new_req); 1850 1787 fuse_request_free(new_req); 1851 - goto out; 1852 - } else { 1853 - new_req->misc.write.next = old_req->misc.write.next; 1854 - old_req->misc.write.next = new_req; 1855 1788 } 1856 - out_unlock: 1857 - spin_unlock(&fc->lock); 1858 - out: 1859 - return found; 1789 + 1790 + return true; 1860 1791 } 1861 1792 1862 1793 static int fuse_writepages_fill(struct page *page, ··· 1858 1803 struct fuse_fill_wb_data *data = _data; 1859 1804 struct fuse_req *req = data->req; 1860 1805 struct inode *inode = data->inode; 1806 + struct fuse_inode *fi = get_fuse_inode(inode); 1861 1807 struct fuse_conn *fc = get_fuse_conn(inode); 1862 1808 struct page *tmp_page; 1863 1809 bool is_writeback; ··· 1929 1873 req->end = fuse_writepage_end; 1930 1874 req->inode = inode; 1931 1875 1932 - spin_lock(&fc->lock); 1876 + spin_lock(&fi->lock); 1933 1877 list_add(&req->writepages_entry, &fi->writepages); 1934 - spin_unlock(&fc->lock); 1878 + spin_unlock(&fi->lock); 1935 1879 1936 1880 data->req = req; 1937 1881 } ··· 1954 1898 data->orig_pages[req->num_pages] = page; 1955 1899 1956 1900 /* 1957 - * Protected by fc->lock against concurrent access by 1901 + * Protected by fi->lock against concurrent access by 1958 1902 * fuse_page_is_writeback(). 1959 1903 */ 1960 - spin_lock(&fc->lock); 1904 + spin_lock(&fi->lock); 1961 1905 req->num_pages++; 1962 - spin_unlock(&fc->lock); 1906 + spin_unlock(&fi->lock); 1963 1907 1964 1908 out_unlock: 1965 1909 unlock_page(page); ··· 2143 2087 2144 2088 static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) 2145 2089 { 2090 + struct fuse_file *ff = file->private_data; 2091 + 2092 + if (ff->open_flags & FOPEN_DIRECT_IO) { 2093 + /* Can't provide the coherency needed for MAP_SHARED */ 2094 + if (vma->vm_flags & VM_MAYSHARE) 2095 + return -ENODEV; 2096 + 2097 + invalidate_inode_pages2(file->f_mapping); 2098 + 2099 + return generic_file_mmap(file, vma); 2100 + } 2101 + 2146 2102 if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) 2147 2103 fuse_link_write_file(file); 2148 2104 2149 2105 file_accessed(file); 2150 2106 vma->vm_ops = &fuse_file_vm_ops; 2151 2107 return 0; 2152 - } 2153 - 2154 - static int fuse_direct_mmap(struct file *file, struct vm_area_struct *vma) 2155 - { 2156 - /* Can't provide the coherency needed for MAP_SHARED */ 2157 - if (vma->vm_flags & VM_MAYSHARE) 2158 - return -ENODEV; 2159 - 2160 - invalidate_inode_pages2(file->f_mapping); 2161 - 2162 - return generic_file_mmap(file, vma); 2163 2108 } 2164 2109 2165 2110 static int convert_fuse_file_lock(struct fuse_conn *fc, ··· 3171 3114 .lock = fuse_file_lock, 3172 3115 .flock = fuse_file_flock, 3173 3116 .splice_read = generic_file_splice_read, 3117 + .splice_write = iter_file_splice_write, 3174 3118 .unlocked_ioctl = fuse_file_ioctl, 3175 3119 .compat_ioctl = fuse_file_compat_ioctl, 3176 3120 .poll = fuse_file_poll, 3177 3121 .fallocate = fuse_file_fallocate, 3178 3122 .copy_file_range = fuse_copy_file_range, 3179 - }; 3180 - 3181 - static const struct file_operations fuse_direct_io_file_operations = { 3182 - .llseek = fuse_file_llseek, 3183 - .read_iter = fuse_direct_read_iter, 3184 - .write_iter = fuse_direct_write_iter, 3185 - .mmap = fuse_direct_mmap, 3186 - .open = fuse_open, 3187 - .flush = fuse_flush, 3188 - .release = fuse_release, 3189 - .fsync = fuse_fsync, 3190 - .lock = fuse_file_lock, 3191 - .flock = fuse_file_flock, 3192 - .unlocked_ioctl = fuse_file_ioctl, 3193 - .compat_ioctl = fuse_file_compat_ioctl, 3194 - .poll = fuse_file_poll, 3195 - .fallocate = fuse_file_fallocate, 3196 - /* no splice_read */ 3197 3123 }; 3198 3124 3199 3125 static const struct address_space_operations fuse_file_aops = {
+20 -8
fs/fuse/fuse_i.h
··· 96 96 union { 97 97 /* Write related fields (regular file only) */ 98 98 struct { 99 - /* Files usable in writepage. Protected by fc->lock */ 99 + /* Files usable in writepage. Protected by fi->lock */ 100 100 struct list_head write_files; 101 101 102 102 /* Writepages pending on truncate or fsync */ ··· 144 144 145 145 /** Lock for serializing lookup and readdir for back compatibility*/ 146 146 struct mutex mutex; 147 + 148 + /** Lock to protect write related fields */ 149 + spinlock_t lock; 147 150 }; 148 151 149 152 /** FUSE inode state bits */ ··· 166 163 /** Fuse connection for this file */ 167 164 struct fuse_conn *fc; 168 165 169 - /** Request reserved for flush and release */ 166 + /* 167 + * Request reserved for flush and release. 168 + * Modified under relative fuse_inode::lock. 169 + */ 170 170 struct fuse_req *reserved_req; 171 171 172 172 /** Kernel file handle guaranteed to be unique */ ··· 544 538 struct fuse_iqueue iq; 545 539 546 540 /** The next unique kernel file handle */ 547 - u64 khctr; 541 + atomic64_t khctr; 548 542 549 543 /** rbtree of fuse_files waiting for poll events indexed by ph */ 550 544 struct rb_root polled_files; ··· 629 623 630 624 /** Is open/release not implemented by fs? */ 631 625 unsigned no_open:1; 626 + 627 + /** Is opendir/releasedir not implemented by fs? */ 628 + unsigned no_opendir:1; 632 629 633 630 /** Is fsync not implemented by fs? */ 634 631 unsigned no_fsync:1; ··· 739 730 struct fuse_req *destroy_req; 740 731 741 732 /** Version counter for attribute changes */ 742 - u64 attr_version; 733 + atomic64_t attr_version; 743 734 744 735 /** Called on final put */ 745 736 void (*release)(struct fuse_conn *); ··· 777 768 static inline int invalid_nodeid(u64 nodeid) 778 769 { 779 770 return !nodeid || nodeid == FUSE_ROOT_ID; 771 + } 772 + 773 + static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 774 + { 775 + return atomic64_read(&fc->attr_version); 780 776 } 781 777 782 778 /** Device operations */ ··· 831 817 void fuse_file_free(struct fuse_file *ff); 832 818 void fuse_finish_open(struct inode *inode, struct file *file); 833 819 834 - void fuse_sync_release(struct fuse_file *ff, int flags); 820 + void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags); 835 821 836 822 /** 837 823 * Send RELEASE or RELEASEDIR request ··· 950 936 bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req); 951 937 952 938 /* Abort all requests */ 953 - void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); 939 + void fuse_abort_conn(struct fuse_conn *fc); 954 940 void fuse_wait_aborted(struct fuse_conn *fc); 955 941 956 942 /** ··· 1013 999 1014 1000 void fuse_set_nowrite(struct inode *inode); 1015 1001 void fuse_release_nowrite(struct inode *inode); 1016 - 1017 - u64 fuse_get_attr_version(struct fuse_conn *fc); 1018 1002 1019 1003 /** 1020 1004 * File-system tells the kernel to invalidate cache for the given node id.
+15 -11
fs/fuse/inode.c
··· 97 97 fi->orig_ino = 0; 98 98 fi->state = 0; 99 99 mutex_init(&fi->mutex); 100 + spin_lock_init(&fi->lock); 100 101 fi->forget = fuse_alloc_forget(); 101 102 if (!fi->forget) { 102 103 kmem_cache_free(fuse_inode_cachep, inode); ··· 164 163 struct fuse_conn *fc = get_fuse_conn(inode); 165 164 struct fuse_inode *fi = get_fuse_inode(inode); 166 165 167 - fi->attr_version = ++fc->attr_version; 166 + lockdep_assert_held(&fi->lock); 167 + 168 + fi->attr_version = atomic64_inc_return(&fc->attr_version); 168 169 fi->i_time = attr_valid; 169 170 WRITE_ONCE(fi->inval_mask, 0); 170 171 ··· 212 209 loff_t oldsize; 213 210 struct timespec64 old_mtime; 214 211 215 - spin_lock(&fc->lock); 212 + spin_lock(&fi->lock); 216 213 if ((attr_version != 0 && fi->attr_version > attr_version) || 217 214 test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) { 218 - spin_unlock(&fc->lock); 215 + spin_unlock(&fi->lock); 219 216 return; 220 217 } 221 218 ··· 230 227 */ 231 228 if (!is_wb || !S_ISREG(inode->i_mode)) 232 229 i_size_write(inode, attr->size); 233 - spin_unlock(&fc->lock); 230 + spin_unlock(&fi->lock); 234 231 235 232 if (!is_wb && S_ISREG(inode->i_mode)) { 236 233 bool inval = false; ··· 325 322 } 326 323 327 324 fi = get_fuse_inode(inode); 328 - spin_lock(&fc->lock); 325 + spin_lock(&fi->lock); 329 326 fi->nlookup++; 330 - spin_unlock(&fc->lock); 327 + spin_unlock(&fi->lock); 331 328 fuse_change_attributes(inode, attr, attr_valid, attr_version); 332 329 333 330 return inode; ··· 379 376 380 377 static void fuse_umount_begin(struct super_block *sb) 381 378 { 382 - fuse_abort_conn(get_fuse_conn_super(sb), false); 379 + fuse_abort_conn(get_fuse_conn_super(sb)); 383 380 } 384 381 385 382 static void fuse_send_destroy(struct fuse_conn *fc) ··· 622 619 atomic_set(&fc->num_waiting, 0); 623 620 fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND; 624 621 fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD; 625 - fc->khctr = 0; 622 + atomic64_set(&fc->khctr, 0); 626 623 fc->polled_files = RB_ROOT; 627 624 fc->blocked = 0; 628 625 fc->initialized = 0; 629 626 fc->connected = 1; 630 - fc->attr_version = 1; 627 + atomic64_set(&fc->attr_version, 1); 631 628 get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); 632 629 fc->pid_ns = get_pid_ns(task_active_pid_ns(current)); 633 630 fc->user_ns = get_user_ns(user_ns); ··· 972 969 FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO | 973 970 FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT | 974 971 FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL | 975 - FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS; 972 + FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS | 973 + FUSE_NO_OPENDIR_SUPPORT; 976 974 req->in.h.opcode = FUSE_INIT; 977 975 req->in.numargs = 1; 978 976 req->in.args[0].size = sizeof(*arg); ··· 1246 1242 if (fc) { 1247 1243 fuse_send_destroy(fc); 1248 1244 1249 - fuse_abort_conn(fc, false); 1245 + fuse_abort_conn(fc); 1250 1246 fuse_wait_aborted(fc); 1251 1247 1252 1248 down_write(&fc->killsb);
+2 -2
fs/fuse/readdir.c
··· 213 213 } 214 214 215 215 fi = get_fuse_inode(inode); 216 - spin_lock(&fc->lock); 216 + spin_lock(&fi->lock); 217 217 fi->nlookup++; 218 - spin_unlock(&fc->lock); 218 + spin_unlock(&fi->lock); 219 219 220 220 forget_all_cached_acls(inode); 221 221 fuse_change_attributes(inode, &o->attr,
+6 -1
include/uapi/linux/fuse.h
··· 122 122 * - add FOPEN_CACHE_DIR 123 123 * - add FUSE_MAX_PAGES, add max_pages to init_out 124 124 * - add FUSE_CACHE_SYMLINKS 125 + * 126 + * 7.29 127 + * - add FUSE_NO_OPENDIR_SUPPORT flag 125 128 */ 126 129 127 130 #ifndef _LINUX_FUSE_H ··· 160 157 #define FUSE_KERNEL_VERSION 7 161 158 162 159 /** Minor version number of this interface */ 163 - #define FUSE_KERNEL_MINOR_VERSION 28 160 + #define FUSE_KERNEL_MINOR_VERSION 29 164 161 165 162 /** The node ID of the root inode */ 166 163 #define FUSE_ROOT_ID 1 ··· 262 259 * FUSE_ABORT_ERROR: reading the device after abort returns ECONNABORTED 263 260 * FUSE_MAX_PAGES: init_out.max_pages contains the max number of req pages 264 261 * FUSE_CACHE_SYMLINKS: cache READLINK responses 262 + * FUSE_NO_OPENDIR_SUPPORT: kernel supports zero-message opendir 265 263 */ 266 264 #define FUSE_ASYNC_READ (1 << 0) 267 265 #define FUSE_POSIX_LOCKS (1 << 1) ··· 288 284 #define FUSE_ABORT_ERROR (1 << 21) 289 285 #define FUSE_MAX_PAGES (1 << 22) 290 286 #define FUSE_CACHE_SYMLINKS (1 << 23) 287 + #define FUSE_NO_OPENDIR_SUPPORT (1 << 24) 291 288 292 289 /** 293 290 * CUSE INIT request/reply flags