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

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

Pull fuse updates from Miklos Szeredi:

- Fixes for virtiofs submounts

- Misc fixes and cleanups

* tag 'fuse-update-5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse:
virtiofs: Fix spelling mistakes
fuse: use DIV_ROUND_UP helper macro for calculations
fuse: fix illegal access to inode with reused nodeid
fuse: allow fallocate(FALLOC_FL_ZERO_RANGE)
fuse: Make fuse_fill_super_submount() static
fuse: Switch to fc_mount() for submounts
fuse: Call vfs_get_tree() for submounts
fuse: add dedicated filesystem context ops for submounts
virtiofs: propagate sync() to file server
fuse: reject internal errno
fuse: check connected before queueing on fpq->io
fuse: ignore PG_workingset after stealing
fuse: Fix infinite loop in sget_fc()
fuse: Fix crash if superblock of submount gets killed early
fuse: Fix crash in fuse_dentry_automount() error path

+161 -81
+3 -3
fs/fuse/dax.c
··· 213 213 dmap->writable = writable; 214 214 if (!upgrade) { 215 215 /* 216 - * We don't take a refernce on inode. inode is valid right now 216 + * We don't take a reference on inode. inode is valid right now 217 217 * and when inode is going away, cleanup logic should first 218 218 * cleanup dmap entries. 219 219 */ ··· 622 622 } 623 623 624 624 /* 625 - * If read beyond end of file happnes, fs code seems to return 625 + * If read beyond end of file happens, fs code seems to return 626 626 * it as hole 627 627 */ 628 628 iomap_hole: ··· 1207 1207 ret); 1208 1208 } 1209 1209 1210 - /* If number of free ranges are still below threhold, requeue */ 1210 + /* If number of free ranges are still below threshold, requeue */ 1211 1211 kick_dmap_free_worker(fcd, 1); 1212 1212 } 1213 1213
+12 -2
fs/fuse/dev.c
··· 91 91 { 92 92 /* 93 93 * lockess check of fc->connected is okay, because atomic_dec_and_test() 94 - * provides a memory barrier mached with the one in fuse_wait_aborted() 94 + * provides a memory barrier matched with the one in fuse_wait_aborted() 95 95 * to ensure no wake-up is missed. 96 96 */ 97 97 if (atomic_dec_and_test(&fc->num_waiting) && ··· 783 783 1 << PG_uptodate | 784 784 1 << PG_lru | 785 785 1 << PG_active | 786 + 1 << PG_workingset | 786 787 1 << PG_reclaim | 787 788 1 << PG_waiters))) { 788 789 dump_page(page, "fuse: trying to steal weird page"); ··· 1272 1271 goto restart; 1273 1272 } 1274 1273 spin_lock(&fpq->lock); 1274 + /* 1275 + * Must not put request on fpq->io queue after having been shut down by 1276 + * fuse_abort_conn() 1277 + */ 1278 + if (!fpq->connected) { 1279 + req->out.h.error = err = -ECONNABORTED; 1280 + goto out_end; 1281 + 1282 + } 1275 1283 list_add(&req->list, &fpq->io); 1276 1284 spin_unlock(&fpq->lock); 1277 1285 cs->req = req; ··· 1867 1857 } 1868 1858 1869 1859 err = -EINVAL; 1870 - if (oh.error <= -1000 || oh.error > 0) 1860 + if (oh.error <= -512 || oh.error > 0) 1871 1861 goto copy_finish; 1872 1862 1873 1863 spin_lock(&fpq->lock);
+9 -54
fs/fuse/dir.c
··· 252 252 if (ret == -ENOMEM) 253 253 goto out; 254 254 if (ret || fuse_invalid_attr(&outarg.attr) || 255 - inode_wrong_type(inode, outarg.attr.mode)) 255 + fuse_stale_inode(inode, outarg.generation, &outarg.attr)) 256 256 goto invalid; 257 257 258 258 forget_all_cached_acls(inode); ··· 309 309 static struct vfsmount *fuse_dentry_automount(struct path *path) 310 310 { 311 311 struct fs_context *fsc; 312 - struct fuse_mount *parent_fm = get_fuse_mount_super(path->mnt->mnt_sb); 313 - struct fuse_conn *fc = parent_fm->fc; 314 - struct fuse_mount *fm; 315 312 struct vfsmount *mnt; 316 313 struct fuse_inode *mp_fi = get_fuse_inode(d_inode(path->dentry)); 317 - struct super_block *sb; 318 - int err; 319 314 320 315 fsc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry); 321 - if (IS_ERR(fsc)) { 322 - err = PTR_ERR(fsc); 323 - goto out; 324 - } 316 + if (IS_ERR(fsc)) 317 + return ERR_CAST(fsc); 325 318 326 - err = -ENOMEM; 327 - fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL); 328 - if (!fm) 329 - goto out_put_fsc; 330 - 331 - fsc->s_fs_info = fm; 332 - sb = sget_fc(fsc, NULL, set_anon_super_fc); 333 - if (IS_ERR(sb)) { 334 - err = PTR_ERR(sb); 335 - kfree(fm); 336 - goto out_put_fsc; 337 - } 338 - fm->fc = fuse_conn_get(fc); 339 - 340 - /* Initialize superblock, making @mp_fi its root */ 341 - err = fuse_fill_super_submount(sb, mp_fi); 342 - if (err) 343 - goto out_put_sb; 344 - 345 - sb->s_flags |= SB_ACTIVE; 346 - fsc->root = dget(sb->s_root); 347 - /* We are done configuring the superblock, so unlock it */ 348 - up_write(&sb->s_umount); 349 - 350 - down_write(&fc->killsb); 351 - list_add_tail(&fm->fc_entry, &fc->mounts); 352 - up_write(&fc->killsb); 319 + /* Pass the FUSE inode of the mount for fuse_get_tree_submount() */ 320 + fsc->fs_private = mp_fi; 353 321 354 322 /* Create the submount */ 355 - mnt = vfs_create_mount(fsc); 356 - if (IS_ERR(mnt)) { 357 - err = PTR_ERR(mnt); 358 - goto out_put_fsc; 359 - } 360 - mntget(mnt); 323 + mnt = fc_mount(fsc); 324 + if (!IS_ERR(mnt)) 325 + mntget(mnt); 326 + 361 327 put_fs_context(fsc); 362 328 return mnt; 363 - 364 - out_put_sb: 365 - /* 366 - * Only jump here when fsc->root is NULL and sb is still locked 367 - * (otherwise put_fs_context() will put the superblock) 368 - */ 369 - deactivate_locked_super(sb); 370 - out_put_fsc: 371 - put_fs_context(fsc); 372 - out: 373 - return ERR_PTR(err); 374 329 } 375 330 376 331 const struct dentry_operations fuse_dentry_operations = {
+8 -6
fs/fuse/file.c
··· 645 645 * == bytes_transferred or rw == WRITE, the caller sets 'pos' to -1. 646 646 * 647 647 * An example: 648 - * User requested DIO read of 64K. It was splitted into two 32K fuse requests, 648 + * User requested DIO read of 64K. It was split into two 32K fuse requests, 649 649 * both submitted asynchronously. The first of them was ACKed by userspace as 650 650 * fully completed (req->out.args[0].size == 32K) resulting in pos == -1. The 651 651 * second request was ACKed as short, e.g. only 1K was read, resulting in ··· 1403 1403 nbytes += ret; 1404 1404 1405 1405 ret += start; 1406 - npages = (ret + PAGE_SIZE - 1) / PAGE_SIZE; 1406 + npages = DIV_ROUND_UP(ret, PAGE_SIZE); 1407 1407 1408 1408 ap->descs[ap->num_pages].offset = start; 1409 1409 fuse_page_descs_length_init(ap->descs, ap->num_pages, npages); ··· 2905 2905 }; 2906 2906 int err; 2907 2907 bool lock_inode = !(mode & FALLOC_FL_KEEP_SIZE) || 2908 - (mode & FALLOC_FL_PUNCH_HOLE); 2908 + (mode & (FALLOC_FL_PUNCH_HOLE | 2909 + FALLOC_FL_ZERO_RANGE)); 2909 2910 2910 2911 bool block_faults = FUSE_IS_DAX(inode) && lock_inode; 2911 2912 2912 - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) 2913 + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | 2914 + FALLOC_FL_ZERO_RANGE)) 2913 2915 return -EOPNOTSUPP; 2914 2916 2915 2917 if (fm->fc->no_fallocate) ··· 2926 2924 goto out; 2927 2925 } 2928 2926 2929 - if (mode & FALLOC_FL_PUNCH_HOLE) { 2927 + if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) { 2930 2928 loff_t endbyte = offset + length - 1; 2931 2929 2932 2930 err = fuse_writeback_range(inode, offset, endbyte); ··· 2966 2964 file_update_time(file); 2967 2965 } 2968 2966 2969 - if (mode & FALLOC_FL_PUNCH_HOLE) 2967 + if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) 2970 2968 truncate_pagecache_range(inode, offset, offset + length - 1); 2971 2969 2972 2970 fuse_invalidate_attr(inode);
+15 -9
fs/fuse/fuse_i.h
··· 761 761 /* Auto-mount submounts announced by the server */ 762 762 unsigned int auto_submounts:1; 763 763 764 + /* Propagate syncfs() to server */ 765 + unsigned int sync_fs:1; 766 + 764 767 /** The number of requests waiting for completion */ 765 768 atomic_t num_waiting; 766 769 ··· 868 865 static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 869 866 { 870 867 return atomic64_read(&fc->attr_version); 868 + } 869 + 870 + static inline bool fuse_stale_inode(const struct inode *inode, int generation, 871 + struct fuse_attr *attr) 872 + { 873 + return inode->i_generation != generation || 874 + inode_wrong_type(inode, attr->mode); 871 875 } 872 876 873 877 static inline void fuse_make_bad(struct inode *inode) ··· 1092 1082 int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx); 1093 1083 1094 1084 /* 1095 - * Fill in superblock for submounts 1096 - * @sb: partially-initialized superblock to fill in 1097 - * @parent_fi: The fuse_inode of the parent filesystem where this submount is 1098 - * mounted 1099 - */ 1100 - int fuse_fill_super_submount(struct super_block *sb, 1101 - struct fuse_inode *parent_fi); 1102 - 1103 - /* 1104 1085 * Remove the mount from the connection 1105 1086 * 1106 1087 * Returns whether this was the last mount 1107 1088 */ 1108 1089 bool fuse_mount_remove(struct fuse_mount *fm); 1090 + 1091 + /* 1092 + * Setup context ops for submounts 1093 + */ 1094 + int fuse_init_fs_context_submount(struct fs_context *fsc); 1109 1095 1110 1096 /* 1111 1097 * Shut down the connection (possibly sending DESTROY request).
+96 -4
fs/fuse/inode.c
··· 350 350 inode->i_generation = generation; 351 351 fuse_init_inode(inode, attr); 352 352 unlock_new_inode(inode); 353 - } else if (inode_wrong_type(inode, attr->mode)) { 354 - /* Inode has changed type, any I/O on the old should fail */ 353 + } else if (fuse_stale_inode(inode, generation, attr)) { 354 + /* nodeid was reused, any I/O on the old inode should fail */ 355 355 fuse_make_bad(inode); 356 356 iput(inode); 357 357 goto retry; ··· 503 503 err = fuse_simple_request(fm, &args); 504 504 if (!err) 505 505 convert_fuse_statfs(buf, &outarg.st); 506 + return err; 507 + } 508 + 509 + static int fuse_sync_fs(struct super_block *sb, int wait) 510 + { 511 + struct fuse_mount *fm = get_fuse_mount_super(sb); 512 + struct fuse_conn *fc = fm->fc; 513 + struct fuse_syncfs_in inarg; 514 + FUSE_ARGS(args); 515 + int err; 516 + 517 + /* 518 + * Userspace cannot handle the wait == 0 case. Avoid a 519 + * gratuitous roundtrip. 520 + */ 521 + if (!wait) 522 + return 0; 523 + 524 + /* The filesystem is being unmounted. Nothing to do. */ 525 + if (!sb->s_root) 526 + return 0; 527 + 528 + if (!fc->sync_fs) 529 + return 0; 530 + 531 + memset(&inarg, 0, sizeof(inarg)); 532 + args.in_numargs = 1; 533 + args.in_args[0].size = sizeof(inarg); 534 + args.in_args[0].value = &inarg; 535 + args.opcode = FUSE_SYNCFS; 536 + args.nodeid = get_node_id(sb->s_root->d_inode); 537 + args.out_numargs = 0; 538 + 539 + err = fuse_simple_request(fm, &args); 540 + if (err == -ENOSYS) { 541 + fc->sync_fs = 0; 542 + err = 0; 543 + } 544 + 506 545 return err; 507 546 } 508 547 ··· 948 909 .put_super = fuse_put_super, 949 910 .umount_begin = fuse_umount_begin, 950 911 .statfs = fuse_statfs, 912 + .sync_fs = fuse_sync_fs, 951 913 .show_options = fuse_show_options, 952 914 }; 953 915 ··· 1315 1275 sb->s_xattr = fuse_no_acl_xattr_handlers; 1316 1276 } 1317 1277 1318 - int fuse_fill_super_submount(struct super_block *sb, 1319 - struct fuse_inode *parent_fi) 1278 + static int fuse_fill_super_submount(struct super_block *sb, 1279 + struct fuse_inode *parent_fi) 1320 1280 { 1321 1281 struct fuse_mount *fm = get_fuse_mount_super(sb); 1322 1282 struct super_block *parent_sb = parent_fi->inode.i_sb; ··· 1352 1312 1353 1313 return 0; 1354 1314 } 1315 + 1316 + /* Filesystem context private data holds the FUSE inode of the mount point */ 1317 + static int fuse_get_tree_submount(struct fs_context *fsc) 1318 + { 1319 + struct fuse_mount *fm; 1320 + struct fuse_inode *mp_fi = fsc->fs_private; 1321 + struct fuse_conn *fc = get_fuse_conn(&mp_fi->inode); 1322 + struct super_block *sb; 1323 + int err; 1324 + 1325 + fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL); 1326 + if (!fm) 1327 + return -ENOMEM; 1328 + 1329 + fsc->s_fs_info = fm; 1330 + sb = sget_fc(fsc, NULL, set_anon_super_fc); 1331 + if (IS_ERR(sb)) { 1332 + kfree(fm); 1333 + return PTR_ERR(sb); 1334 + } 1335 + fm->fc = fuse_conn_get(fc); 1336 + 1337 + /* Initialize superblock, making @mp_fi its root */ 1338 + err = fuse_fill_super_submount(sb, mp_fi); 1339 + if (err) { 1340 + fuse_conn_put(fc); 1341 + kfree(fm); 1342 + sb->s_fs_info = NULL; 1343 + deactivate_locked_super(sb); 1344 + return err; 1345 + } 1346 + 1347 + down_write(&fc->killsb); 1348 + list_add_tail(&fm->fc_entry, &fc->mounts); 1349 + up_write(&fc->killsb); 1350 + 1351 + sb->s_flags |= SB_ACTIVE; 1352 + fsc->root = dget(sb->s_root); 1353 + 1354 + return 0; 1355 + } 1356 + 1357 + static const struct fs_context_operations fuse_context_submount_ops = { 1358 + .get_tree = fuse_get_tree_submount, 1359 + }; 1360 + 1361 + int fuse_init_fs_context_submount(struct fs_context *fsc) 1362 + { 1363 + fsc->ops = &fuse_context_submount_ops; 1364 + return 0; 1365 + } 1366 + EXPORT_SYMBOL_GPL(fuse_init_fs_context_submount); 1355 1367 1356 1368 int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) 1357 1369 {
+5 -2
fs/fuse/readdir.c
··· 200 200 if (!d_in_lookup(dentry)) { 201 201 struct fuse_inode *fi; 202 202 inode = d_inode(dentry); 203 + if (inode && get_node_id(inode) != o->nodeid) 204 + inode = NULL; 203 205 if (!inode || 204 - get_node_id(inode) != o->nodeid || 205 - inode_wrong_type(inode, o->attr.mode)) { 206 + fuse_stale_inode(inode, o->generation, &o->attr)) { 207 + if (inode) 208 + fuse_make_bad(inode); 206 209 d_invalidate(dentry); 207 210 dput(dentry); 208 211 goto retry;
+4
fs/fuse/virtio_fs.c
··· 1447 1447 fc->release = fuse_free_conn; 1448 1448 fc->delete_stale = true; 1449 1449 fc->auto_submounts = true; 1450 + fc->sync_fs = true; 1450 1451 1451 1452 /* Tell FUSE to split requests that exceed the virtqueue's size */ 1452 1453 fc->max_pages_limit = min_t(unsigned int, fc->max_pages_limit, ··· 1496 1495 static int virtio_fs_init_fs_context(struct fs_context *fsc) 1497 1496 { 1498 1497 struct fuse_fs_context *ctx; 1498 + 1499 + if (fsc->purpose == FS_CONTEXT_FOR_SUBMOUNT) 1500 + return fuse_init_fs_context_submount(fsc); 1499 1501 1500 1502 ctx = kzalloc(sizeof(struct fuse_fs_context), GFP_KERNEL); 1501 1503 if (!ctx)
+9 -1
include/uapi/linux/fuse.h
··· 181 181 * - add FUSE_OPEN_KILL_SUIDGID 182 182 * - extend fuse_setxattr_in, add FUSE_SETXATTR_EXT 183 183 * - add FUSE_SETXATTR_ACL_KILL_SGID 184 + * 185 + * 7.34 186 + * - add FUSE_SYNCFS 184 187 */ 185 188 186 189 #ifndef _LINUX_FUSE_H ··· 219 216 #define FUSE_KERNEL_VERSION 7 220 217 221 218 /** Minor version number of this interface */ 222 - #define FUSE_KERNEL_MINOR_VERSION 33 219 + #define FUSE_KERNEL_MINOR_VERSION 34 223 220 224 221 /** The node ID of the root inode */ 225 222 #define FUSE_ROOT_ID 1 ··· 512 509 FUSE_COPY_FILE_RANGE = 47, 513 510 FUSE_SETUPMAPPING = 48, 514 511 FUSE_REMOVEMAPPING = 49, 512 + FUSE_SYNCFS = 50, 515 513 516 514 /* CUSE specific operations */ 517 515 CUSE_INIT = 4096, ··· 974 970 975 971 #define FUSE_REMOVEMAPPING_MAX_ENTRY \ 976 972 (PAGE_SIZE / sizeof(struct fuse_removemapping_one)) 973 + 974 + struct fuse_syncfs_in { 975 + uint64_t padding; 976 + }; 977 977 978 978 #endif /* _LINUX_FUSE_H */