1 /* 2 FUSE: Filesystem in Userspace 3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu> 4 5 This program can be distributed under the terms of the GNU GPL. 6 See the file COPYING. 7 */ 8 9 #ifndef _FS_FUSE_I_H 10 #define _FS_FUSE_I_H 11 12 #ifndef pr_fmt 13 # define pr_fmt(fmt) "fuse: " fmt 14 #endif 15 16 #include <linux/fuse.h> 17 #include <linux/fs.h> 18 #include <linux/mount.h> 19 #include <linux/wait.h> 20 #include <linux/list.h> 21 #include <linux/spinlock.h> 22 #include <linux/mm.h> 23 #include <linux/backing-dev.h> 24 #include <linux/mutex.h> 25 #include <linux/rwsem.h> 26 #include <linux/rbtree.h> 27 #include <linux/poll.h> 28 #include <linux/workqueue.h> 29 #include <linux/kref.h> 30 #include <linux/xattr.h> 31 #include <linux/pid_namespace.h> 32 #include <linux/refcount.h> 33 #include <linux/user_namespace.h> 34 35 /** Default max number of pages that can be used in a single read request */ 36 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32 37 38 /** Bias for fi->writectr, meaning new writepages must not be sent */ 39 #define FUSE_NOWRITE INT_MIN 40 41 /** Maximum length of a filename, not including terminating null */ 42 43 /* maximum, small enough for FUSE_MIN_READ_BUFFER*/ 44 #define FUSE_NAME_LOW_MAX 1024 45 /* maximum, but needs a request buffer > FUSE_MIN_READ_BUFFER */ 46 #define FUSE_NAME_MAX (PATH_MAX - 1) 47 48 /** Number of dentries for each connection in the control filesystem */ 49 #define FUSE_CTL_NUM_DENTRIES 5 50 51 /* Frequency (in seconds) of request timeout checks, if opted into */ 52 #define FUSE_TIMEOUT_TIMER_FREQ 15 53 54 /** Frequency (in jiffies) of request timeout checks, if opted into */ 55 extern const unsigned long fuse_timeout_timer_freq; 56 57 /** Maximum of max_pages received in init_out */ 58 extern unsigned int fuse_max_pages_limit; 59 /* 60 * Default timeout (in seconds) for the server to reply to a request 61 * before the connection is aborted, if no timeout was specified on mount. 62 */ 63 extern unsigned int fuse_default_req_timeout; 64 /* 65 * Max timeout (in seconds) for the server to reply to a request before 66 * the connection is aborted. 67 */ 68 extern unsigned int fuse_max_req_timeout; 69 70 /** List of active connections */ 71 extern struct list_head fuse_conn_list; 72 73 /** Global mutex protecting fuse_conn_list and the control filesystem */ 74 extern struct mutex fuse_mutex; 75 76 /** Module parameters */ 77 extern unsigned int max_user_bgreq; 78 extern unsigned int max_user_congthresh; 79 80 /* One forget request */ 81 struct fuse_forget_link { 82 struct fuse_forget_one forget_one; 83 struct fuse_forget_link *next; 84 }; 85 86 /* Submount lookup tracking */ 87 struct fuse_submount_lookup { 88 /** Refcount */ 89 refcount_t count; 90 91 /** Unique ID, which identifies the inode between userspace 92 * and kernel */ 93 u64 nodeid; 94 95 /** The request used for sending the FORGET message */ 96 struct fuse_forget_link *forget; 97 }; 98 99 /** Container for data related to mapping to backing file */ 100 struct fuse_backing { 101 struct file *file; 102 struct cred *cred; 103 104 /** refcount */ 105 refcount_t count; 106 struct rcu_head rcu; 107 }; 108 109 /** FUSE inode */ 110 struct fuse_inode { 111 /** Inode data */ 112 struct inode inode; 113 114 /** Unique ID, which identifies the inode between userspace 115 * and kernel */ 116 u64 nodeid; 117 118 /** Number of lookups on this inode */ 119 u64 nlookup; 120 121 /** The request used for sending the FORGET message */ 122 struct fuse_forget_link *forget; 123 124 /** Time in jiffies until the file attributes are valid */ 125 u64 i_time; 126 127 /* Which attributes are invalid */ 128 u32 inval_mask; 129 130 /** The sticky bit in inode->i_mode may have been removed, so 131 preserve the original mode */ 132 umode_t orig_i_mode; 133 134 /* Cache birthtime */ 135 struct timespec64 i_btime; 136 137 /** 64 bit inode number */ 138 u64 orig_ino; 139 140 /** Version of last attribute change */ 141 u64 attr_version; 142 143 union { 144 /* read/write io cache (regular file only) */ 145 struct { 146 /* Files usable in writepage. Protected by fi->lock */ 147 struct list_head write_files; 148 149 /* Writepages pending on truncate or fsync */ 150 struct list_head queued_writes; 151 152 /* Number of sent writes, a negative bias 153 * (FUSE_NOWRITE) means more writes are blocked */ 154 int writectr; 155 156 /** Number of files/maps using page cache */ 157 int iocachectr; 158 159 /* Waitq for writepage completion */ 160 wait_queue_head_t page_waitq; 161 162 /* waitq for direct-io completion */ 163 wait_queue_head_t direct_io_waitq; 164 }; 165 166 /* readdir cache (directory only) */ 167 struct { 168 /* true if fully cached */ 169 bool cached; 170 171 /* size of cache */ 172 loff_t size; 173 174 /* position at end of cache (position of next entry) */ 175 loff_t pos; 176 177 /* version of the cache */ 178 u64 version; 179 180 /* modification time of directory when cache was 181 * started */ 182 struct timespec64 mtime; 183 184 /* iversion of directory when cache was started */ 185 u64 iversion; 186 187 /* protects above fields */ 188 spinlock_t lock; 189 } rdc; 190 }; 191 192 /** Miscellaneous bits describing inode state */ 193 unsigned long state; 194 195 /** Lock for serializing lookup and readdir for back compatibility*/ 196 struct mutex mutex; 197 198 /** Lock to protect write related fields */ 199 spinlock_t lock; 200 201 #ifdef CONFIG_FUSE_DAX 202 /* 203 * Dax specific inode data 204 */ 205 struct fuse_inode_dax *dax; 206 #endif 207 /** Submount specific lookup tracking */ 208 struct fuse_submount_lookup *submount_lookup; 209 #ifdef CONFIG_FUSE_PASSTHROUGH 210 /** Reference to backing file in passthrough mode */ 211 struct fuse_backing *fb; 212 #endif 213 }; 214 215 /** FUSE inode state bits */ 216 enum { 217 /** Advise readdirplus */ 218 FUSE_I_ADVISE_RDPLUS, 219 /** Initialized with readdirplus */ 220 FUSE_I_INIT_RDPLUS, 221 /** An operation changing file size is in progress */ 222 FUSE_I_SIZE_UNSTABLE, 223 /* Bad inode */ 224 FUSE_I_BAD, 225 /* Has btime */ 226 FUSE_I_BTIME, 227 /* Wants or already has page cache IO */ 228 FUSE_I_CACHE_IO_MODE, 229 }; 230 231 struct fuse_conn; 232 struct fuse_mount; 233 union fuse_file_args; 234 235 /** FUSE specific file data */ 236 struct fuse_file { 237 /** Fuse connection for this file */ 238 struct fuse_mount *fm; 239 240 /* Argument space reserved for open/release */ 241 union fuse_file_args *args; 242 243 /** Kernel file handle guaranteed to be unique */ 244 u64 kh; 245 246 /** File handle used by userspace */ 247 u64 fh; 248 249 /** Node id of this file */ 250 u64 nodeid; 251 252 /** Refcount */ 253 refcount_t count; 254 255 /** FOPEN_* flags returned by open */ 256 u32 open_flags; 257 258 /** Entry on inode's write_files list */ 259 struct list_head write_entry; 260 261 /* Readdir related */ 262 struct { 263 /* Dir stream position */ 264 loff_t pos; 265 266 /* Offset in cache */ 267 loff_t cache_off; 268 269 /* Version of cache we are reading */ 270 u64 version; 271 272 } readdir; 273 274 /** RB node to be linked on fuse_conn->polled_files */ 275 struct rb_node polled_node; 276 277 /** Wait queue head for poll */ 278 wait_queue_head_t poll_wait; 279 280 /** Does file hold a fi->iocachectr refcount? */ 281 enum { IOM_NONE, IOM_CACHED, IOM_UNCACHED } iomode; 282 283 #ifdef CONFIG_FUSE_PASSTHROUGH 284 /** Reference to backing file in passthrough mode */ 285 struct file *passthrough; 286 const struct cred *cred; 287 #endif 288 289 /** Has flock been performed on this file? */ 290 bool flock:1; 291 }; 292 293 /** One input argument of a request */ 294 struct fuse_in_arg { 295 unsigned size; 296 const void *value; 297 }; 298 299 /** One output argument of a request */ 300 struct fuse_arg { 301 unsigned size; 302 void *value; 303 }; 304 305 /** FUSE folio descriptor */ 306 struct fuse_folio_desc { 307 unsigned int length; 308 unsigned int offset; 309 }; 310 311 struct fuse_args { 312 uint64_t nodeid; 313 uint32_t opcode; 314 uint8_t in_numargs; 315 uint8_t out_numargs; 316 uint8_t ext_idx; 317 bool force:1; 318 bool noreply:1; 319 bool nocreds:1; 320 bool in_pages:1; 321 bool out_pages:1; 322 bool user_pages:1; 323 bool out_argvar:1; 324 bool page_zeroing:1; 325 bool page_replace:1; 326 bool may_block:1; 327 bool is_ext:1; 328 bool is_pinned:1; 329 bool invalidate_vmap:1; 330 struct fuse_in_arg in_args[4]; 331 struct fuse_arg out_args[2]; 332 void (*end)(struct fuse_mount *fm, struct fuse_args *args, int error); 333 /* Used for kvec iter backed by vmalloc address */ 334 void *vmap_base; 335 }; 336 337 struct fuse_args_pages { 338 struct fuse_args args; 339 struct folio **folios; 340 struct fuse_folio_desc *descs; 341 unsigned int num_folios; 342 }; 343 344 struct fuse_release_args { 345 struct fuse_args args; 346 struct fuse_release_in inarg; 347 struct inode *inode; 348 }; 349 350 union fuse_file_args { 351 /* Used during open() */ 352 struct fuse_open_out open_outarg; 353 /* Used during release() */ 354 struct fuse_release_args release_args; 355 }; 356 357 #define FUSE_ARGS(args) struct fuse_args args = {} 358 359 /** The request IO state (for asynchronous processing) */ 360 struct fuse_io_priv { 361 struct kref refcnt; 362 int async; 363 spinlock_t lock; 364 unsigned reqs; 365 ssize_t bytes; 366 size_t size; 367 __u64 offset; 368 bool write; 369 bool should_dirty; 370 int err; 371 struct kiocb *iocb; 372 struct completion *done; 373 bool blocking; 374 }; 375 376 #define FUSE_IO_PRIV_SYNC(i) \ 377 { \ 378 .refcnt = KREF_INIT(1), \ 379 .async = 0, \ 380 .iocb = i, \ 381 } 382 383 /** 384 * Request flags 385 * 386 * FR_ISREPLY: set if the request has reply 387 * FR_FORCE: force sending of the request even if interrupted 388 * FR_BACKGROUND: request is sent in the background 389 * FR_WAITING: request is counted as "waiting" 390 * FR_ABORTED: the request was aborted 391 * FR_INTERRUPTED: the request has been interrupted 392 * FR_LOCKED: data is being copied to/from the request 393 * FR_PENDING: request is not yet in userspace 394 * FR_SENT: request is in userspace, waiting for an answer 395 * FR_FINISHED: request is finished 396 * FR_PRIVATE: request is on private list 397 * FR_ASYNC: request is asynchronous 398 * FR_URING: request is handled through fuse-io-uring 399 */ 400 enum fuse_req_flag { 401 FR_ISREPLY, 402 FR_FORCE, 403 FR_BACKGROUND, 404 FR_WAITING, 405 FR_ABORTED, 406 FR_INTERRUPTED, 407 FR_LOCKED, 408 FR_PENDING, 409 FR_SENT, 410 FR_FINISHED, 411 FR_PRIVATE, 412 FR_ASYNC, 413 FR_URING, 414 }; 415 416 /** 417 * A request to the client 418 * 419 * .waitq.lock protects the following fields: 420 * - FR_ABORTED 421 * - FR_LOCKED (may also be modified under fc->lock, tested under both) 422 */ 423 struct fuse_req { 424 /** This can be on either pending processing or io lists in 425 fuse_conn */ 426 struct list_head list; 427 428 /** Entry on the interrupts list */ 429 struct list_head intr_entry; 430 431 /* Input/output arguments */ 432 struct fuse_args *args; 433 434 /** refcount */ 435 refcount_t count; 436 437 /* Request flags, updated with test/set/clear_bit() */ 438 unsigned long flags; 439 440 /* The request input header */ 441 struct { 442 struct fuse_in_header h; 443 } in; 444 445 /* The request output header */ 446 struct { 447 struct fuse_out_header h; 448 } out; 449 450 /** Used to wake up the task waiting for completion of request*/ 451 wait_queue_head_t waitq; 452 453 #if IS_ENABLED(CONFIG_VIRTIO_FS) 454 /** virtio-fs's physically contiguous buffer for in and out args */ 455 void *argbuf; 456 #endif 457 458 /** fuse_mount this request belongs to */ 459 struct fuse_mount *fm; 460 461 #ifdef CONFIG_FUSE_IO_URING 462 void *ring_entry; 463 void *ring_queue; 464 #endif 465 /** When (in jiffies) the request was created */ 466 unsigned long create_time; 467 }; 468 469 struct fuse_iqueue; 470 471 /** 472 * Input queue callbacks 473 * 474 * Input queue signalling is device-specific. For example, the /dev/fuse file 475 * uses fiq->waitq and fasync to wake processes that are waiting on queue 476 * readiness. These callbacks allow other device types to respond to input 477 * queue activity. 478 */ 479 struct fuse_iqueue_ops { 480 /** 481 * Send one forget 482 */ 483 void (*send_forget)(struct fuse_iqueue *fiq, struct fuse_forget_link *link); 484 485 /** 486 * Send interrupt for request 487 */ 488 void (*send_interrupt)(struct fuse_iqueue *fiq, struct fuse_req *req); 489 490 /** 491 * Send one request 492 */ 493 void (*send_req)(struct fuse_iqueue *fiq, struct fuse_req *req); 494 495 /** 496 * Clean up when fuse_iqueue is destroyed 497 */ 498 void (*release)(struct fuse_iqueue *fiq); 499 }; 500 501 /** /dev/fuse input queue operations */ 502 extern const struct fuse_iqueue_ops fuse_dev_fiq_ops; 503 504 struct fuse_iqueue { 505 /** Connection established */ 506 unsigned connected; 507 508 /** Lock protecting accesses to members of this structure */ 509 spinlock_t lock; 510 511 /** Readers of the connection are waiting on this */ 512 wait_queue_head_t waitq; 513 514 /** The next unique request id */ 515 u64 reqctr; 516 517 /** The list of pending requests */ 518 struct list_head pending; 519 520 /** Pending interrupts */ 521 struct list_head interrupts; 522 523 /** Queue of pending forgets */ 524 struct fuse_forget_link forget_list_head; 525 struct fuse_forget_link *forget_list_tail; 526 527 /** Batching of FORGET requests (positive indicates FORGET batch) */ 528 int forget_batch; 529 530 /** O_ASYNC requests */ 531 struct fasync_struct *fasync; 532 533 /** Device-specific callbacks */ 534 const struct fuse_iqueue_ops *ops; 535 536 /** Device-specific state */ 537 void *priv; 538 }; 539 540 #define FUSE_PQ_HASH_BITS 8 541 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 542 543 struct fuse_pqueue { 544 /** Connection established */ 545 unsigned connected; 546 547 /** Lock protecting accessess to members of this structure */ 548 spinlock_t lock; 549 550 /** Hash table of requests being processed */ 551 struct list_head *processing; 552 553 /** The list of requests under I/O */ 554 struct list_head io; 555 }; 556 557 /** 558 * Fuse device instance 559 */ 560 struct fuse_dev { 561 /** Fuse connection for this device */ 562 struct fuse_conn *fc; 563 564 /** Processing queue */ 565 struct fuse_pqueue pq; 566 567 /** list entry on fc->devices */ 568 struct list_head entry; 569 }; 570 571 enum fuse_dax_mode { 572 FUSE_DAX_INODE_DEFAULT, /* default */ 573 FUSE_DAX_ALWAYS, /* "-o dax=always" */ 574 FUSE_DAX_NEVER, /* "-o dax=never" */ 575 FUSE_DAX_INODE_USER, /* "-o dax=inode" */ 576 }; 577 578 static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode) 579 { 580 return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER; 581 } 582 583 struct fuse_fs_context { 584 int fd; 585 struct file *file; 586 unsigned int rootmode; 587 kuid_t user_id; 588 kgid_t group_id; 589 bool is_bdev:1; 590 bool fd_present:1; 591 bool rootmode_present:1; 592 bool user_id_present:1; 593 bool group_id_present:1; 594 bool default_permissions:1; 595 bool allow_other:1; 596 bool destroy:1; 597 bool no_control:1; 598 bool no_force_umount:1; 599 bool legacy_opts_show:1; 600 enum fuse_dax_mode dax_mode; 601 unsigned int max_read; 602 unsigned int blksize; 603 const char *subtype; 604 605 /* DAX device, may be NULL */ 606 struct dax_device *dax_dev; 607 608 /* fuse_dev pointer to fill in, should contain NULL on entry */ 609 void **fudptr; 610 }; 611 612 struct fuse_sync_bucket { 613 /* count is a possible scalability bottleneck */ 614 atomic_t count; 615 wait_queue_head_t waitq; 616 struct rcu_head rcu; 617 }; 618 619 /** 620 * A Fuse connection. 621 * 622 * This structure is created, when the root filesystem is mounted, and 623 * is destroyed, when the client device is closed and the last 624 * fuse_mount is destroyed. 625 */ 626 struct fuse_conn { 627 /** Lock protecting accessess to members of this structure */ 628 spinlock_t lock; 629 630 /** Refcount */ 631 refcount_t count; 632 633 /** Number of fuse_dev's */ 634 atomic_t dev_count; 635 636 /** Current epoch for up-to-date dentries */ 637 atomic_t epoch; 638 639 struct rcu_head rcu; 640 641 /** The user id for this mount */ 642 kuid_t user_id; 643 644 /** The group id for this mount */ 645 kgid_t group_id; 646 647 /** The pid namespace for this mount */ 648 struct pid_namespace *pid_ns; 649 650 /** The user namespace for this mount */ 651 struct user_namespace *user_ns; 652 653 /** Maximum read size */ 654 unsigned max_read; 655 656 /** Maximum write size */ 657 unsigned max_write; 658 659 /** Maximum number of pages that can be used in a single request */ 660 unsigned int max_pages; 661 662 /** Constrain ->max_pages to this value during feature negotiation */ 663 unsigned int max_pages_limit; 664 665 /** Input queue */ 666 struct fuse_iqueue iq; 667 668 /** The next unique kernel file handle */ 669 atomic64_t khctr; 670 671 /** rbtree of fuse_files waiting for poll events indexed by ph */ 672 struct rb_root polled_files; 673 674 /** Maximum number of outstanding background requests */ 675 unsigned max_background; 676 677 /** Number of background requests at which congestion starts */ 678 unsigned congestion_threshold; 679 680 /** Number of requests currently in the background */ 681 unsigned num_background; 682 683 /** Number of background requests currently queued for userspace */ 684 unsigned active_background; 685 686 /** The list of background requests set aside for later queuing */ 687 struct list_head bg_queue; 688 689 /** Protects: max_background, congestion_threshold, num_background, 690 * active_background, bg_queue, blocked */ 691 spinlock_t bg_lock; 692 693 /** Flag indicating that INIT reply has been received. Allocating 694 * any fuse request will be suspended until the flag is set */ 695 int initialized; 696 697 /** Flag indicating if connection is blocked. This will be 698 the case before the INIT reply is received, and if there 699 are too many outstading backgrounds requests */ 700 int blocked; 701 702 /** waitq for blocked connection */ 703 wait_queue_head_t blocked_waitq; 704 705 /** Connection established, cleared on umount, connection 706 abort and device release */ 707 unsigned connected; 708 709 /** Connection aborted via sysfs */ 710 bool aborted; 711 712 /** Connection failed (version mismatch). Cannot race with 713 setting other bitfields since it is only set once in INIT 714 reply, before any other request, and never cleared */ 715 unsigned conn_error:1; 716 717 /** Connection successful. Only set in INIT */ 718 unsigned conn_init:1; 719 720 /** Do readahead asynchronously? Only set in INIT */ 721 unsigned async_read:1; 722 723 /** Return an unique read error after abort. Only set in INIT */ 724 unsigned abort_err:1; 725 726 /** Do not send separate SETATTR request before open(O_TRUNC) */ 727 unsigned atomic_o_trunc:1; 728 729 /** Filesystem supports NFS exporting. Only set in INIT */ 730 unsigned export_support:1; 731 732 /** write-back cache policy (default is write-through) */ 733 unsigned writeback_cache:1; 734 735 /** allow parallel lookups and readdir (default is serialized) */ 736 unsigned parallel_dirops:1; 737 738 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 739 unsigned handle_killpriv:1; 740 741 /** cache READLINK responses in page cache */ 742 unsigned cache_symlinks:1; 743 744 /* show legacy mount options */ 745 unsigned int legacy_opts_show:1; 746 747 /* 748 * fs kills suid/sgid/cap on write/chown/trunc. suid is killed on 749 * write/trunc only if caller did not have CAP_FSETID. sgid is killed 750 * on write/truncate only if caller did not have CAP_FSETID as well as 751 * file has group execute permission. 752 */ 753 unsigned handle_killpriv_v2:1; 754 755 /* 756 * The following bitfields are only for optimization purposes 757 * and hence races in setting them will not cause malfunction 758 */ 759 760 /** Is open/release not implemented by fs? */ 761 unsigned no_open:1; 762 763 /** Is opendir/releasedir not implemented by fs? */ 764 unsigned no_opendir:1; 765 766 /** Is fsync not implemented by fs? */ 767 unsigned no_fsync:1; 768 769 /** Is fsyncdir not implemented by fs? */ 770 unsigned no_fsyncdir:1; 771 772 /** Is flush not implemented by fs? */ 773 unsigned no_flush:1; 774 775 /** Is setxattr not implemented by fs? */ 776 unsigned no_setxattr:1; 777 778 /** Does file server support extended setxattr */ 779 unsigned setxattr_ext:1; 780 781 /** Is getxattr not implemented by fs? */ 782 unsigned no_getxattr:1; 783 784 /** Is listxattr not implemented by fs? */ 785 unsigned no_listxattr:1; 786 787 /** Is removexattr not implemented by fs? */ 788 unsigned no_removexattr:1; 789 790 /** Are posix file locking primitives not implemented by fs? */ 791 unsigned no_lock:1; 792 793 /** Is access not implemented by fs? */ 794 unsigned no_access:1; 795 796 /** Is create not implemented by fs? */ 797 unsigned no_create:1; 798 799 /** Is interrupt not implemented by fs? */ 800 unsigned no_interrupt:1; 801 802 /** Is bmap not implemented by fs? */ 803 unsigned no_bmap:1; 804 805 /** Is poll not implemented by fs? */ 806 unsigned no_poll:1; 807 808 /** Do multi-page cached writes */ 809 unsigned big_writes:1; 810 811 /** Don't apply umask to creation modes */ 812 unsigned dont_mask:1; 813 814 /** Are BSD file locking primitives not implemented by fs? */ 815 unsigned no_flock:1; 816 817 /** Is fallocate not implemented by fs? */ 818 unsigned no_fallocate:1; 819 820 /** Is rename with flags implemented by fs? */ 821 unsigned no_rename2:1; 822 823 /** Use enhanced/automatic page cache invalidation. */ 824 unsigned auto_inval_data:1; 825 826 /** Filesystem is fully responsible for page cache invalidation. */ 827 unsigned explicit_inval_data:1; 828 829 /** Does the filesystem support readdirplus? */ 830 unsigned do_readdirplus:1; 831 832 /** Does the filesystem want adaptive readdirplus? */ 833 unsigned readdirplus_auto:1; 834 835 /** Does the filesystem support asynchronous direct-IO submission? */ 836 unsigned async_dio:1; 837 838 /** Is lseek not implemented by fs? */ 839 unsigned no_lseek:1; 840 841 /** Does the filesystem support posix acls? */ 842 unsigned posix_acl:1; 843 844 /** Check permissions based on the file mode or not? */ 845 unsigned default_permissions:1; 846 847 /** Allow other than the mounter user to access the filesystem ? */ 848 unsigned allow_other:1; 849 850 /** Does the filesystem support copy_file_range? */ 851 unsigned no_copy_file_range:1; 852 853 /* Send DESTROY request */ 854 unsigned int destroy:1; 855 856 /* Delete dentries that have gone stale */ 857 unsigned int delete_stale:1; 858 859 /** Do not create entry in fusectl fs */ 860 unsigned int no_control:1; 861 862 /** Do not allow MNT_FORCE umount */ 863 unsigned int no_force_umount:1; 864 865 /* Auto-mount submounts announced by the server */ 866 unsigned int auto_submounts:1; 867 868 /* Propagate syncfs() to server */ 869 unsigned int sync_fs:1; 870 871 /* Initialize security xattrs when creating a new inode */ 872 unsigned int init_security:1; 873 874 /* Add supplementary group info when creating a new inode */ 875 unsigned int create_supp_group:1; 876 877 /* Does the filesystem support per inode DAX? */ 878 unsigned int inode_dax:1; 879 880 /* Is tmpfile not implemented by fs? */ 881 unsigned int no_tmpfile:1; 882 883 /* Relax restrictions to allow shared mmap in FOPEN_DIRECT_IO mode */ 884 unsigned int direct_io_allow_mmap:1; 885 886 /* Is statx not implemented by fs? */ 887 unsigned int no_statx:1; 888 889 /** Passthrough support for read/write IO */ 890 unsigned int passthrough:1; 891 892 /* Use pages instead of pointer for kernel I/O */ 893 unsigned int use_pages_for_kvec_io:1; 894 895 /* Is link not implemented by fs? */ 896 unsigned int no_link:1; 897 898 /* Use io_uring for communication */ 899 unsigned int io_uring; 900 901 /** Maximum stack depth for passthrough backing files */ 902 int max_stack_depth; 903 904 /** The number of requests waiting for completion */ 905 atomic_t num_waiting; 906 907 /** Negotiated minor version */ 908 unsigned minor; 909 910 /** Entry on the fuse_conn_list */ 911 struct list_head entry; 912 913 /** Device ID from the root super block */ 914 dev_t dev; 915 916 /** Key for lock owner ID scrambling */ 917 u32 scramble_key[4]; 918 919 /** Version counter for attribute changes */ 920 atomic64_t attr_version; 921 922 /** Version counter for evict inode */ 923 atomic64_t evict_ctr; 924 925 /* maximum file name length */ 926 u32 name_max; 927 928 /** Called on final put */ 929 void (*release)(struct fuse_conn *); 930 931 /** 932 * Read/write semaphore to hold when accessing the sb of any 933 * fuse_mount belonging to this connection 934 */ 935 struct rw_semaphore killsb; 936 937 /** List of device instances belonging to this connection */ 938 struct list_head devices; 939 940 #ifdef CONFIG_FUSE_DAX 941 /* Dax mode */ 942 enum fuse_dax_mode dax_mode; 943 944 /* Dax specific conn data, non-NULL if DAX is enabled */ 945 struct fuse_conn_dax *dax; 946 #endif 947 948 /** List of filesystems using this connection */ 949 struct list_head mounts; 950 951 /* New writepages go into this bucket */ 952 struct fuse_sync_bucket __rcu *curr_bucket; 953 954 #ifdef CONFIG_FUSE_PASSTHROUGH 955 /** IDR for backing files ids */ 956 struct idr backing_files_map; 957 #endif 958 959 #ifdef CONFIG_FUSE_IO_URING 960 /** uring connection information*/ 961 struct fuse_ring *ring; 962 #endif 963 964 /** Only used if the connection opts into request timeouts */ 965 struct { 966 /* Worker for checking if any requests have timed out */ 967 struct delayed_work work; 968 969 /* Request timeout (in jiffies). 0 = no timeout */ 970 unsigned int req_timeout; 971 } timeout; 972 }; 973 974 /* 975 * Represents a mounted filesystem, potentially a submount. 976 * 977 * This object allows sharing a fuse_conn between separate mounts to 978 * allow submounts with dedicated superblocks and thus separate device 979 * IDs. 980 */ 981 struct fuse_mount { 982 /* Underlying (potentially shared) connection to the FUSE server */ 983 struct fuse_conn *fc; 984 985 /* 986 * Super block for this connection (fc->killsb must be held when 987 * accessing this). 988 */ 989 struct super_block *sb; 990 991 /* Entry on fc->mounts */ 992 struct list_head fc_entry; 993 struct rcu_head rcu; 994 }; 995 996 /* 997 * Empty header for FUSE opcodes without specific header needs. 998 * Used as a placeholder in args->in_args[0] for consistency 999 * across all FUSE operations, simplifying request handling. 1000 */ 1001 struct fuse_zero_header {}; 1002 1003 static inline void fuse_set_zero_arg0(struct fuse_args *args) 1004 { 1005 args->in_args[0].size = sizeof(struct fuse_zero_header); 1006 args->in_args[0].value = NULL; 1007 } 1008 1009 static inline struct fuse_mount *get_fuse_mount_super(struct super_block *sb) 1010 { 1011 return sb->s_fs_info; 1012 } 1013 1014 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 1015 { 1016 return get_fuse_mount_super(sb)->fc; 1017 } 1018 1019 static inline struct fuse_mount *get_fuse_mount(struct inode *inode) 1020 { 1021 return get_fuse_mount_super(inode->i_sb); 1022 } 1023 1024 static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 1025 { 1026 return get_fuse_mount_super(inode->i_sb)->fc; 1027 } 1028 1029 static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 1030 { 1031 return container_of(inode, struct fuse_inode, inode); 1032 } 1033 1034 static inline u64 get_node_id(struct inode *inode) 1035 { 1036 return get_fuse_inode(inode)->nodeid; 1037 } 1038 1039 static inline int invalid_nodeid(u64 nodeid) 1040 { 1041 return !nodeid || nodeid == FUSE_ROOT_ID; 1042 } 1043 1044 static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 1045 { 1046 return atomic64_read(&fc->attr_version); 1047 } 1048 1049 static inline u64 fuse_get_evict_ctr(struct fuse_conn *fc) 1050 { 1051 return atomic64_read(&fc->evict_ctr); 1052 } 1053 1054 static inline bool fuse_stale_inode(const struct inode *inode, int generation, 1055 struct fuse_attr *attr) 1056 { 1057 return inode->i_generation != generation || 1058 inode_wrong_type(inode, attr->mode); 1059 } 1060 1061 static inline void fuse_make_bad(struct inode *inode) 1062 { 1063 set_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state); 1064 } 1065 1066 static inline bool fuse_is_bad(struct inode *inode) 1067 { 1068 return unlikely(test_bit(FUSE_I_BAD, &get_fuse_inode(inode)->state)); 1069 } 1070 1071 static inline struct folio **fuse_folios_alloc(unsigned int nfolios, gfp_t flags, 1072 struct fuse_folio_desc **desc) 1073 { 1074 struct folio **folios; 1075 1076 folios = kzalloc(nfolios * (sizeof(struct folio *) + 1077 sizeof(struct fuse_folio_desc)), flags); 1078 *desc = (void *) (folios + nfolios); 1079 1080 return folios; 1081 } 1082 1083 static inline void fuse_folio_descs_length_init(struct fuse_folio_desc *descs, 1084 unsigned int index, 1085 unsigned int nr_folios) 1086 { 1087 int i; 1088 1089 for (i = index; i < index + nr_folios; i++) 1090 descs[i].length = PAGE_SIZE - descs[i].offset; 1091 } 1092 1093 static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket) 1094 { 1095 /* Need RCU protection to prevent use after free after the decrement */ 1096 rcu_read_lock(); 1097 if (atomic_dec_and_test(&bucket->count)) 1098 wake_up(&bucket->waitq); 1099 rcu_read_unlock(); 1100 } 1101 1102 /** Device operations */ 1103 extern const struct file_operations fuse_dev_operations; 1104 1105 extern const struct dentry_operations fuse_dentry_operations; 1106 1107 /** 1108 * Get a filled in inode 1109 */ 1110 struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 1111 int generation, struct fuse_attr *attr, 1112 u64 attr_valid, u64 attr_version, 1113 u64 evict_ctr); 1114 1115 int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 1116 struct fuse_entry_out *outarg, struct inode **inode); 1117 1118 /** 1119 * Send FORGET command 1120 */ 1121 void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 1122 u64 nodeid, u64 nlookup); 1123 1124 struct fuse_forget_link *fuse_alloc_forget(void); 1125 1126 /* 1127 * Initialize READ or READDIR request 1128 */ 1129 struct fuse_io_args { 1130 union { 1131 struct { 1132 struct fuse_read_in in; 1133 u64 attr_ver; 1134 } read; 1135 struct { 1136 struct fuse_write_in in; 1137 struct fuse_write_out out; 1138 bool folio_locked; 1139 } write; 1140 }; 1141 struct fuse_args_pages ap; 1142 struct fuse_io_priv *io; 1143 struct fuse_file *ff; 1144 }; 1145 1146 void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos, 1147 size_t count, int opcode); 1148 1149 1150 struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release); 1151 void fuse_file_free(struct fuse_file *ff); 1152 int fuse_finish_open(struct inode *inode, struct file *file); 1153 1154 void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, 1155 unsigned int flags); 1156 1157 /** 1158 * Send RELEASE or RELEASEDIR request 1159 */ 1160 void fuse_release_common(struct file *file, bool isdir); 1161 1162 /** 1163 * Send FSYNC or FSYNCDIR request 1164 */ 1165 int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 1166 int datasync, int opcode); 1167 1168 /** 1169 * Notify poll wakeup 1170 */ 1171 int fuse_notify_poll_wakeup(struct fuse_conn *fc, 1172 struct fuse_notify_poll_wakeup_out *outarg); 1173 1174 /** 1175 * Initialize file operations on a regular file 1176 */ 1177 void fuse_init_file_inode(struct inode *inode, unsigned int flags); 1178 1179 /** 1180 * Initialize inode operations on regular files and special files 1181 */ 1182 void fuse_init_common(struct inode *inode); 1183 1184 /** 1185 * Initialize inode and file operations on a directory 1186 */ 1187 void fuse_init_dir(struct inode *inode); 1188 1189 /** 1190 * Initialize inode operations on a symlink 1191 */ 1192 void fuse_init_symlink(struct inode *inode); 1193 1194 /** 1195 * Change attributes of an inode 1196 */ 1197 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 1198 struct fuse_statx *sx, 1199 u64 attr_valid, u64 attr_version); 1200 1201 void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 1202 struct fuse_statx *sx, 1203 u64 attr_valid, u32 cache_mask, 1204 u64 evict_ctr); 1205 1206 u32 fuse_get_cache_mask(struct inode *inode); 1207 1208 /** 1209 * Initialize the client device 1210 */ 1211 int fuse_dev_init(void); 1212 1213 /** 1214 * Cleanup the client device 1215 */ 1216 void fuse_dev_cleanup(void); 1217 1218 int fuse_ctl_init(void); 1219 void __exit fuse_ctl_cleanup(void); 1220 1221 /** 1222 * Simple request sending that does request allocation and freeing 1223 */ 1224 ssize_t __fuse_simple_request(struct mnt_idmap *idmap, 1225 struct fuse_mount *fm, 1226 struct fuse_args *args); 1227 1228 static inline ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args) 1229 { 1230 return __fuse_simple_request(&invalid_mnt_idmap, fm, args); 1231 } 1232 1233 static inline ssize_t fuse_simple_idmap_request(struct mnt_idmap *idmap, 1234 struct fuse_mount *fm, 1235 struct fuse_args *args) 1236 { 1237 return __fuse_simple_request(idmap, fm, args); 1238 } 1239 1240 int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, 1241 gfp_t gfp_flags); 1242 1243 /** 1244 * End a finished request 1245 */ 1246 void fuse_request_end(struct fuse_req *req); 1247 1248 /* Abort all requests */ 1249 void fuse_abort_conn(struct fuse_conn *fc); 1250 void fuse_wait_aborted(struct fuse_conn *fc); 1251 1252 /* Check if any requests timed out */ 1253 void fuse_check_timeout(struct work_struct *work); 1254 1255 /** 1256 * Invalidate inode attributes 1257 */ 1258 1259 /* Attributes possibly changed on data modification */ 1260 #define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS) 1261 1262 /* Attributes possibly changed on data and/or size modification */ 1263 #define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE) 1264 1265 void fuse_invalidate_attr(struct inode *inode); 1266 void fuse_invalidate_attr_mask(struct inode *inode, u32 mask); 1267 1268 void fuse_invalidate_entry_cache(struct dentry *entry); 1269 1270 void fuse_invalidate_atime(struct inode *inode); 1271 1272 u64 fuse_time_to_jiffies(u64 sec, u32 nsec); 1273 #define ATTR_TIMEOUT(o) \ 1274 fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec) 1275 1276 void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 1277 1278 /** 1279 * Acquire reference to fuse_conn 1280 */ 1281 struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 1282 1283 /** 1284 * Initialize the fuse processing queue 1285 */ 1286 void fuse_pqueue_init(struct fuse_pqueue *fpq); 1287 1288 /** 1289 * Initialize fuse_conn 1290 */ 1291 void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm, 1292 struct user_namespace *user_ns, 1293 const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv); 1294 1295 /** 1296 * Release reference to fuse_conn 1297 */ 1298 void fuse_conn_put(struct fuse_conn *fc); 1299 1300 struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc); 1301 struct fuse_dev *fuse_dev_alloc(void); 1302 void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc); 1303 void fuse_dev_free(struct fuse_dev *fud); 1304 void fuse_send_init(struct fuse_mount *fm); 1305 1306 /** 1307 * Fill in superblock and initialize fuse connection 1308 * @sb: partially-initialized superblock to fill in 1309 * @ctx: mount context 1310 */ 1311 int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx); 1312 1313 /* 1314 * Remove the mount from the connection 1315 * 1316 * Returns whether this was the last mount 1317 */ 1318 bool fuse_mount_remove(struct fuse_mount *fm); 1319 1320 /* 1321 * Setup context ops for submounts 1322 */ 1323 int fuse_init_fs_context_submount(struct fs_context *fsc); 1324 1325 /* 1326 * Shut down the connection (possibly sending DESTROY request). 1327 */ 1328 void fuse_conn_destroy(struct fuse_mount *fm); 1329 1330 /* Drop the connection and free the fuse mount */ 1331 void fuse_mount_destroy(struct fuse_mount *fm); 1332 1333 /** 1334 * Add connection to control filesystem 1335 */ 1336 int fuse_ctl_add_conn(struct fuse_conn *fc); 1337 1338 /** 1339 * Remove connection from control filesystem 1340 */ 1341 void fuse_ctl_remove_conn(struct fuse_conn *fc); 1342 1343 /** 1344 * Is file type valid? 1345 */ 1346 int fuse_valid_type(int m); 1347 1348 bool fuse_invalid_attr(struct fuse_attr *attr); 1349 1350 /** 1351 * Is current process allowed to perform filesystem operation? 1352 */ 1353 bool fuse_allow_current_process(struct fuse_conn *fc); 1354 1355 u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 1356 1357 void fuse_flush_time_update(struct inode *inode); 1358 void fuse_update_ctime(struct inode *inode); 1359 1360 int fuse_update_attributes(struct inode *inode, struct file *file, u32 mask); 1361 1362 void fuse_flush_writepages(struct inode *inode); 1363 1364 void fuse_set_nowrite(struct inode *inode); 1365 void fuse_release_nowrite(struct inode *inode); 1366 1367 /** 1368 * Scan all fuse_mounts belonging to fc to find the first where 1369 * ilookup5() returns a result. Return that result and the 1370 * respective fuse_mount in *fm (unless fm is NULL). 1371 * 1372 * The caller must hold fc->killsb. 1373 */ 1374 struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid, 1375 struct fuse_mount **fm); 1376 1377 /** 1378 * File-system tells the kernel to invalidate cache for the given node id. 1379 */ 1380 int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid, 1381 loff_t offset, loff_t len); 1382 1383 /** 1384 * File-system tells the kernel to invalidate parent attributes and 1385 * the dentry matching parent/name. 1386 * 1387 * If the child_nodeid is non-zero and: 1388 * - matches the inode number for the dentry matching parent/name, 1389 * - is not a mount point 1390 * - is a file or oan empty directory 1391 * then the dentry is unhashed (d_delete()). 1392 */ 1393 int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid, 1394 u64 child_nodeid, struct qstr *name, u32 flags); 1395 1396 int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file, 1397 bool isdir); 1398 1399 /** 1400 * fuse_direct_io() flags 1401 */ 1402 1403 /** If set, it is WRITE; otherwise - READ */ 1404 #define FUSE_DIO_WRITE (1 << 0) 1405 1406 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1407 #define FUSE_DIO_CUSE (1 << 1) 1408 1409 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1410 loff_t *ppos, int flags); 1411 long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 1412 unsigned int flags); 1413 long fuse_ioctl_common(struct file *file, unsigned int cmd, 1414 unsigned long arg, unsigned int flags); 1415 __poll_t fuse_file_poll(struct file *file, poll_table *wait); 1416 int fuse_dev_release(struct inode *inode, struct file *file); 1417 1418 bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written); 1419 1420 int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 1421 int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1422 1423 int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry, 1424 struct iattr *attr, struct file *file); 1425 1426 void fuse_set_initialized(struct fuse_conn *fc); 1427 1428 void fuse_unlock_inode(struct inode *inode, bool locked); 1429 bool fuse_lock_inode(struct inode *inode); 1430 1431 int fuse_setxattr(struct inode *inode, const char *name, const void *value, 1432 size_t size, int flags, unsigned int extra_flags); 1433 ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 1434 size_t size); 1435 ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 1436 int fuse_removexattr(struct inode *inode, const char *name); 1437 extern const struct xattr_handler * const fuse_xattr_handlers[]; 1438 1439 struct posix_acl; 1440 struct posix_acl *fuse_get_inode_acl(struct inode *inode, int type, bool rcu); 1441 struct posix_acl *fuse_get_acl(struct mnt_idmap *idmap, 1442 struct dentry *dentry, int type); 1443 int fuse_set_acl(struct mnt_idmap *, struct dentry *dentry, 1444 struct posix_acl *acl, int type); 1445 1446 /* readdir.c */ 1447 int fuse_readdir(struct file *file, struct dir_context *ctx); 1448 1449 /** 1450 * Return the number of bytes in an arguments list 1451 */ 1452 unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args); 1453 1454 /** 1455 * Get the next unique ID for a request 1456 */ 1457 u64 fuse_get_unique(struct fuse_iqueue *fiq); 1458 void fuse_free_conn(struct fuse_conn *fc); 1459 1460 /* dax.c */ 1461 1462 #define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode)) 1463 1464 ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to); 1465 ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from); 1466 int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma); 1467 int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end); 1468 int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode, 1469 struct dax_device *dax_dev); 1470 void fuse_dax_conn_free(struct fuse_conn *fc); 1471 bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi); 1472 void fuse_dax_inode_init(struct inode *inode, unsigned int flags); 1473 void fuse_dax_inode_cleanup(struct inode *inode); 1474 void fuse_dax_dontcache(struct inode *inode, unsigned int flags); 1475 bool fuse_dax_check_alignment(struct fuse_conn *fc, unsigned int map_alignment); 1476 void fuse_dax_cancel_work(struct fuse_conn *fc); 1477 1478 /* ioctl.c */ 1479 long fuse_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 1480 long fuse_file_compat_ioctl(struct file *file, unsigned int cmd, 1481 unsigned long arg); 1482 int fuse_fileattr_get(struct dentry *dentry, struct file_kattr *fa); 1483 int fuse_fileattr_set(struct mnt_idmap *idmap, 1484 struct dentry *dentry, struct file_kattr *fa); 1485 1486 /* iomode.c */ 1487 int fuse_file_cached_io_open(struct inode *inode, struct fuse_file *ff); 1488 int fuse_inode_uncached_io_start(struct fuse_inode *fi, 1489 struct fuse_backing *fb); 1490 void fuse_inode_uncached_io_end(struct fuse_inode *fi); 1491 1492 int fuse_file_io_open(struct file *file, struct inode *inode); 1493 void fuse_file_io_release(struct fuse_file *ff, struct inode *inode); 1494 1495 /* file.c */ 1496 struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid, 1497 unsigned int open_flags, bool isdir); 1498 void fuse_file_release(struct inode *inode, struct fuse_file *ff, 1499 unsigned int open_flags, fl_owner_t id, bool isdir); 1500 1501 /* passthrough.c */ 1502 static inline struct fuse_backing *fuse_inode_backing(struct fuse_inode *fi) 1503 { 1504 #ifdef CONFIG_FUSE_PASSTHROUGH 1505 return READ_ONCE(fi->fb); 1506 #else 1507 return NULL; 1508 #endif 1509 } 1510 1511 static inline struct fuse_backing *fuse_inode_backing_set(struct fuse_inode *fi, 1512 struct fuse_backing *fb) 1513 { 1514 #ifdef CONFIG_FUSE_PASSTHROUGH 1515 return xchg(&fi->fb, fb); 1516 #else 1517 return NULL; 1518 #endif 1519 } 1520 1521 #ifdef CONFIG_FUSE_PASSTHROUGH 1522 struct fuse_backing *fuse_backing_get(struct fuse_backing *fb); 1523 void fuse_backing_put(struct fuse_backing *fb); 1524 #else 1525 1526 static inline struct fuse_backing *fuse_backing_get(struct fuse_backing *fb) 1527 { 1528 return NULL; 1529 } 1530 1531 static inline void fuse_backing_put(struct fuse_backing *fb) 1532 { 1533 } 1534 #endif 1535 1536 void fuse_backing_files_init(struct fuse_conn *fc); 1537 void fuse_backing_files_free(struct fuse_conn *fc); 1538 int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map); 1539 int fuse_backing_close(struct fuse_conn *fc, int backing_id); 1540 1541 struct fuse_backing *fuse_passthrough_open(struct file *file, 1542 struct inode *inode, 1543 int backing_id); 1544 void fuse_passthrough_release(struct fuse_file *ff, struct fuse_backing *fb); 1545 1546 static inline struct file *fuse_file_passthrough(struct fuse_file *ff) 1547 { 1548 #ifdef CONFIG_FUSE_PASSTHROUGH 1549 return ff->passthrough; 1550 #else 1551 return NULL; 1552 #endif 1553 } 1554 1555 ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter); 1556 ssize_t fuse_passthrough_write_iter(struct kiocb *iocb, struct iov_iter *iter); 1557 ssize_t fuse_passthrough_splice_read(struct file *in, loff_t *ppos, 1558 struct pipe_inode_info *pipe, 1559 size_t len, unsigned int flags); 1560 ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe, 1561 struct file *out, loff_t *ppos, 1562 size_t len, unsigned int flags); 1563 ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma); 1564 1565 #ifdef CONFIG_SYSCTL 1566 extern int fuse_sysctl_register(void); 1567 extern void fuse_sysctl_unregister(void); 1568 #else 1569 #define fuse_sysctl_register() (0) 1570 #define fuse_sysctl_unregister() do { } while (0) 1571 #endif /* CONFIG_SYSCTL */ 1572 1573 #endif /* _FS_FUSE_I_H */ 1574