^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) FUSE: Filesystem in Userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) This program can be distributed under the terms of the GNU GPL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) See the file COPYING.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "fuse_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/fs_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/fs_parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/statfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/posix_acl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/pid_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) MODULE_DESCRIPTION("Filesystem in Userspace");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static struct kmem_cache *fuse_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct list_head fuse_conn_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) DEFINE_MUTEX(fuse_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static int set_global_limit(const char *val, const struct kernel_param *kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned max_user_bgreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) module_param_call(max_user_bgreq, set_global_limit, param_get_uint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) &max_user_bgreq, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) __MODULE_PARM_TYPE(max_user_bgreq, "uint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) MODULE_PARM_DESC(max_user_bgreq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) "Global limit for the maximum number of backgrounded requests an "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) "unprivileged user can set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned max_user_congthresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) module_param_call(max_user_congthresh, set_global_limit, param_get_uint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) &max_user_congthresh, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) __MODULE_PARM_TYPE(max_user_congthresh, "uint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MODULE_PARM_DESC(max_user_congthresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "Global limit for the maximum congestion threshold an "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) "unprivileged user can set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define FUSE_SUPER_MAGIC 0x65735546
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define FUSE_DEFAULT_BLKSIZE 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /** Maximum number of outstanding background requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define FUSE_DEFAULT_MAX_BACKGROUND 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /** Congestion starts at 75% of maximum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define FUSE_DEFAULT_CONGESTION_THRESHOLD (FUSE_DEFAULT_MAX_BACKGROUND * 3 / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #ifdef CONFIG_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static struct file_system_type fuseblk_fs_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct fuse_forget_link *fuse_alloc_forget(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return kzalloc(sizeof(struct fuse_forget_link), GFP_KERNEL_ACCOUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static struct inode *fuse_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct fuse_inode *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) fi = kmem_cache_alloc(fuse_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (!fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) fi->i_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) fi->inval_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) fi->nodeid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) fi->nlookup = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) fi->attr_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) fi->orig_ino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) fi->state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) mutex_init(&fi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) init_rwsem(&fi->i_mmap_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) spin_lock_init(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) fi->forget = fuse_alloc_forget();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!fi->forget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (IS_ENABLED(CONFIG_FUSE_DAX) && !fuse_dax_inode_alloc(sb, fi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) goto out_free_forget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return &fi->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) out_free_forget:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) kfree(fi->forget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) kmem_cache_free(fuse_inode_cachep, fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void fuse_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct fuse_inode *fi = get_fuse_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) mutex_destroy(&fi->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) kfree(fi->forget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #ifdef CONFIG_FUSE_DAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) kfree(fi->dax);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) kmem_cache_free(fuse_inode_cachep, fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static void fuse_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct fuse_inode *fi = get_fuse_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* Will write inode on close/munmap and in all other dirtiers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) WARN_ON(inode->i_state & I_DIRTY_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (inode->i_sb->s_flags & SB_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct fuse_conn *fc = get_fuse_conn(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (FUSE_IS_DAX(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) fuse_dax_inode_cleanup(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (fi->nlookup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) fuse_queue_forget(fc, fi->forget, fi->nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) fi->nlookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) fi->forget = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (S_ISREG(inode->i_mode) && !fuse_is_bad(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) WARN_ON(!list_empty(&fi->write_files));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) WARN_ON(!list_empty(&fi->queued_writes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int fuse_reconfigure(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct super_block *sb = fc->root->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (fc->sb_flags & SB_MANDLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * so that it will fit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static ino_t fuse_squash_ino(u64 ino64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ino_t ino = (ino_t) ino64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (sizeof(ino_t) < sizeof(u64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ino ^= ino64 >> (sizeof(u64) - sizeof(ino_t)) * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) u64 attr_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct fuse_conn *fc = get_fuse_conn(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct fuse_inode *fi = get_fuse_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) lockdep_assert_held(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) fi->attr_version = atomic64_inc_return(&fc->attr_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) fi->i_time = attr_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) WRITE_ONCE(fi->inval_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) inode->i_ino = fuse_squash_ino(attr->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) inode->i_mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) set_nlink(inode, attr->nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) inode->i_uid = make_kuid(fc->user_ns, attr->uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) inode->i_gid = make_kgid(fc->user_ns, attr->gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) inode->i_blocks = attr->blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) inode->i_atime.tv_sec = attr->atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) inode->i_atime.tv_nsec = attr->atimensec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* mtime from server may be stale due to local buffered write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (!fc->writeback_cache || !S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) inode->i_mtime.tv_sec = attr->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) inode->i_mtime.tv_nsec = attr->mtimensec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) inode->i_ctime.tv_sec = attr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) inode->i_ctime.tv_nsec = attr->ctimensec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (attr->blksize != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) inode->i_blkbits = ilog2(attr->blksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) inode->i_blkbits = inode->i_sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * Don't set the sticky bit in i_mode, unless we want the VFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * to check permissions. This prevents failures due to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * check in may_delete().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) fi->orig_i_mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (!fc->default_permissions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) inode->i_mode &= ~S_ISVTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) fi->orig_ino = attr->ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) u64 attr_valid, u64 attr_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct fuse_conn *fc = get_fuse_conn(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct fuse_inode *fi = get_fuse_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) bool is_wb = fc->writeback_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) loff_t oldsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct timespec64 old_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if ((attr_version != 0 && fi->attr_version > attr_version) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) old_mtime = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) fuse_change_attributes_common(inode, attr, attr_valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) oldsize = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * In case of writeback_cache enabled, the cached writes beyond EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * extend local i_size without keeping userspace server in sync. So,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * attr->size coming from server can be stale. We cannot trust it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (!is_wb || !S_ISREG(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) i_size_write(inode, attr->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!is_wb && S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) bool inval = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (oldsize != attr->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) truncate_pagecache(inode, attr->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (!fc->explicit_inval_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) inval = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) } else if (fc->auto_inval_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct timespec64 new_mtime = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .tv_sec = attr->mtime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .tv_nsec = attr->mtimensec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * Auto inval mode also checks and invalidates if mtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * has changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!timespec64_equal(&old_mtime, &new_mtime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) inval = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (inval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) invalidate_inode_pages2(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) inode->i_mode = attr->mode & S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) inode->i_size = attr->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) inode->i_mtime.tv_sec = attr->mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) inode->i_mtime.tv_nsec = attr->mtimensec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) inode->i_ctime.tv_sec = attr->ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) inode->i_ctime.tv_nsec = attr->ctimensec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) fuse_init_common(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) fuse_init_file_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) } else if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) fuse_init_dir(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) else if (S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) fuse_init_symlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) fuse_init_common(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) init_special_inode(inode, inode->i_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) new_decode_dev(attr->rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) u64 nodeid = *(u64 *) _nodeidp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (get_node_id(inode) == nodeid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static int fuse_inode_set(struct inode *inode, void *_nodeidp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) u64 nodeid = *(u64 *) _nodeidp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) get_fuse_inode(inode)->nodeid = nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) int generation, struct fuse_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) u64 attr_valid, u64 attr_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct fuse_inode *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct fuse_conn *fc = get_fuse_conn_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * Auto mount points get their node id from the submount root, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * not a unique identifier within this filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * To avoid conflicts, do not place submount points into the inode hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (fc->auto_submounts && (attr->flags & FUSE_ATTR_SUBMOUNT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) S_ISDIR(attr->mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) fuse_init_inode(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) get_fuse_inode(inode)->nodeid = nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) inode->i_flags |= S_AUTOMOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if ((inode->i_state & I_NEW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) inode->i_flags |= S_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (!fc->writeback_cache || !S_ISREG(attr->mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) inode->i_flags |= S_NOCMTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) inode->i_generation = generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) fuse_init_inode(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) } else if (fuse_stale_inode(inode, generation, attr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* nodeid was reused, any I/O on the old inode should fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) fuse_make_bad(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) fi = get_fuse_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) fi->nlookup++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) fuse_change_attributes(inode, attr, attr_valid, attr_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct inode *fuse_ilookup(struct fuse_conn *fc, u64 nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct fuse_mount **fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct fuse_mount *fm_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) WARN_ON(!rwsem_is_locked(&fc->killsb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) list_for_each_entry(fm_iter, &fc->mounts, fc_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (!fm_iter->sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) inode = ilookup5(fm_iter->sb, nodeid, fuse_inode_eq, &nodeid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) *fm = fm_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) loff_t offset, loff_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct fuse_inode *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) pgoff_t pg_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) pgoff_t pg_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) inode = fuse_ilookup(fc, nodeid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) fi = get_fuse_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) spin_lock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) fi->attr_version = atomic64_inc_return(&fc->attr_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) spin_unlock(&fi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) fuse_invalidate_attr(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) forget_all_cached_acls(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (offset >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) pg_start = offset >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) pg_end = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) pg_end = (offset + len - 1) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) invalidate_inode_pages2_range(inode->i_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) pg_start, pg_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) bool fuse_lock_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) bool locked = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (!get_fuse_conn(inode)->parallel_dirops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) mutex_lock(&get_fuse_inode(inode)->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) locked = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) void fuse_unlock_inode(struct inode *inode, bool locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) mutex_unlock(&get_fuse_inode(inode)->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static void fuse_umount_begin(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct fuse_conn *fc = get_fuse_conn_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (!fc->no_force_umount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) fuse_abort_conn(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static void fuse_send_destroy(struct fuse_mount *fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (fm->fc->conn_init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) FUSE_ARGS(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) args.opcode = FUSE_DESTROY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) args.force = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) args.nocreds = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) fuse_simple_request(fm, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static void fuse_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct fuse_mount *fm = get_fuse_mount_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) fuse_mount_put(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) stbuf->f_type = FUSE_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) stbuf->f_bsize = attr->bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) stbuf->f_frsize = attr->frsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) stbuf->f_blocks = attr->blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) stbuf->f_bfree = attr->bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) stbuf->f_bavail = attr->bavail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) stbuf->f_files = attr->files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) stbuf->f_ffree = attr->ffree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) stbuf->f_namelen = attr->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* fsid is left zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct fuse_mount *fm = get_fuse_mount_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) FUSE_ARGS(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct fuse_statfs_out outarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (!fuse_allow_current_process(fm->fc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) buf->f_type = FUSE_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) memset(&outarg, 0, sizeof(outarg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) args.in_numargs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) args.opcode = FUSE_STATFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) args.nodeid = get_node_id(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) args.out_numargs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) args.out_args[0].size = sizeof(outarg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) args.out_args[0].value = &outarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) err = fuse_simple_request(fm, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) convert_fuse_statfs(buf, &outarg.st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) OPT_SOURCE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) OPT_SUBTYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) OPT_FD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) OPT_ROOTMODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) OPT_USER_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) OPT_GROUP_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) OPT_DEFAULT_PERMISSIONS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) OPT_ALLOW_OTHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) OPT_MAX_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) OPT_BLKSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) OPT_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static const struct fs_parameter_spec fuse_fs_parameters[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) fsparam_string ("source", OPT_SOURCE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) fsparam_u32 ("fd", OPT_FD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) fsparam_u32oct ("rootmode", OPT_ROOTMODE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) fsparam_u32 ("user_id", OPT_USER_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) fsparam_u32 ("group_id", OPT_GROUP_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) fsparam_flag ("default_permissions", OPT_DEFAULT_PERMISSIONS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) fsparam_flag ("allow_other", OPT_ALLOW_OTHER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) fsparam_u32 ("max_read", OPT_MAX_READ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) fsparam_u32 ("blksize", OPT_BLKSIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) fsparam_string ("subtype", OPT_SUBTYPE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static int fuse_parse_param(struct fs_context *fc, struct fs_parameter *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct fs_parse_result result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct fuse_fs_context *ctx = fc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) int opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * Ignore options coming from mount(MS_REMOUNT) for backward
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * compatibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (fc->oldapi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return invalfc(fc, "No changes allowed in reconfigure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) opt = fs_parse(fc, fuse_fs_parameters, param, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (opt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) switch (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) case OPT_SOURCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (fc->source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return invalfc(fc, "Multiple sources specified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) fc->source = param->string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) param->string = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) case OPT_SUBTYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (ctx->subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return invalfc(fc, "Multiple subtypes specified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) ctx->subtype = param->string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) param->string = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) case OPT_FD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) ctx->fd = result.uint_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ctx->fd_present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) case OPT_ROOTMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (!fuse_valid_type(result.uint_32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return invalfc(fc, "Invalid rootmode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) ctx->rootmode = result.uint_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) ctx->rootmode_present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) case OPT_USER_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) ctx->user_id = make_kuid(fc->user_ns, result.uint_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!uid_valid(ctx->user_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return invalfc(fc, "Invalid user_id");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) ctx->user_id_present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) case OPT_GROUP_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) ctx->group_id = make_kgid(fc->user_ns, result.uint_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (!gid_valid(ctx->group_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return invalfc(fc, "Invalid group_id");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) ctx->group_id_present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) case OPT_DEFAULT_PERMISSIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ctx->default_permissions = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) case OPT_ALLOW_OTHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) ctx->allow_other = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) case OPT_MAX_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) ctx->max_read = result.uint_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) case OPT_BLKSIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (!ctx->is_bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return invalfc(fc, "blksize only supported for fuseblk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ctx->blksize = result.uint_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static void fuse_free_fc(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct fuse_fs_context *ctx = fc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) kfree(ctx->subtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) kfree(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) static int fuse_show_options(struct seq_file *m, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct super_block *sb = root->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct fuse_conn *fc = get_fuse_conn_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (fc->legacy_opts_show) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) seq_printf(m, ",user_id=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) from_kuid_munged(fc->user_ns, fc->user_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) seq_printf(m, ",group_id=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) from_kgid_munged(fc->user_ns, fc->group_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (fc->default_permissions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) seq_puts(m, ",default_permissions");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (fc->allow_other)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) seq_puts(m, ",allow_other");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (fc->max_read != ~0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) seq_printf(m, ",max_read=%u", fc->max_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (sb->s_bdev && sb->s_blocksize != FUSE_DEFAULT_BLKSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) seq_printf(m, ",blksize=%lu", sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) #ifdef CONFIG_FUSE_DAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (fc->dax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) seq_puts(m, ",dax");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) static void fuse_iqueue_init(struct fuse_iqueue *fiq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) const struct fuse_iqueue_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) void *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) memset(fiq, 0, sizeof(struct fuse_iqueue));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) spin_lock_init(&fiq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) init_waitqueue_head(&fiq->waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) INIT_LIST_HEAD(&fiq->pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) INIT_LIST_HEAD(&fiq->interrupts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) fiq->forget_list_tail = &fiq->forget_list_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) fiq->connected = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) fiq->ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) fiq->priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static void fuse_pqueue_init(struct fuse_pqueue *fpq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) spin_lock_init(&fpq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) for (i = 0; i < FUSE_PQ_HASH_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) INIT_LIST_HEAD(&fpq->processing[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) INIT_LIST_HEAD(&fpq->io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) fpq->connected = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct user_namespace *user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) memset(fc, 0, sizeof(*fc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) spin_lock_init(&fc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) spin_lock_init(&fc->bg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) spin_lock_init(&fc->passthrough_req_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) init_rwsem(&fc->killsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) refcount_set(&fc->count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) atomic_set(&fc->dev_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) init_waitqueue_head(&fc->blocked_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) fuse_iqueue_init(&fc->iq, fiq_ops, fiq_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) INIT_LIST_HEAD(&fc->bg_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) INIT_LIST_HEAD(&fc->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) INIT_LIST_HEAD(&fc->devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) idr_init(&fc->passthrough_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) atomic_set(&fc->num_waiting, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) atomic64_set(&fc->khctr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) fc->polled_files = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) fc->blocked = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) fc->initialized = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) fc->connected = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) atomic64_set(&fc->attr_version, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) fc->pid_ns = get_pid_ns(task_active_pid_ns(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) fc->user_ns = get_user_ns(user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) fc->max_pages = FUSE_DEFAULT_MAX_PAGES_PER_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) INIT_LIST_HEAD(&fc->mounts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) list_add(&fm->fc_entry, &fc->mounts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) fm->fc = fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) refcount_set(&fm->count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) EXPORT_SYMBOL_GPL(fuse_conn_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) void fuse_conn_put(struct fuse_conn *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (refcount_dec_and_test(&fc->count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct fuse_iqueue *fiq = &fc->iq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (IS_ENABLED(CONFIG_FUSE_DAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) fuse_dax_conn_free(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (fiq->ops->release)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) fiq->ops->release(fiq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) put_pid_ns(fc->pid_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) put_user_ns(fc->user_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) fc->release(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) EXPORT_SYMBOL_GPL(fuse_conn_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) refcount_inc(&fc->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) EXPORT_SYMBOL_GPL(fuse_conn_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) void fuse_mount_put(struct fuse_mount *fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) if (refcount_dec_and_test(&fm->count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (fm->fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) fuse_conn_put(fm->fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) kfree(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) EXPORT_SYMBOL_GPL(fuse_mount_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct fuse_mount *fuse_mount_get(struct fuse_mount *fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) refcount_inc(&fm->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) return fm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) EXPORT_SYMBOL_GPL(fuse_mount_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) struct fuse_attr attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) memset(&attr, 0, sizeof(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) attr.mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) attr.ino = FUSE_ROOT_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) attr.nlink = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) return fuse_iget(sb, 1, 0, &attr, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct fuse_inode_handle {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) u64 nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) u32 generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) static struct dentry *fuse_get_dentry(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) struct fuse_inode_handle *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) struct fuse_conn *fc = get_fuse_conn_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct dentry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) int err = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if (handle->nodeid == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) inode = ilookup5(sb, handle->nodeid, fuse_inode_eq, &handle->nodeid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct fuse_entry_out outarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) const struct qstr name = QSTR_INIT(".", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (!fc->export_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) err = fuse_lookup_name(sb, handle->nodeid, &name, &outarg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) &inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (err && err != -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (err || !inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) err = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (get_node_id(inode) != handle->nodeid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) goto out_iput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) err = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (inode->i_generation != handle->generation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) goto out_iput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) entry = d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) fuse_invalidate_entry_cache(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) return entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) out_iput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) static int fuse_encode_fh(struct inode *inode, u32 *fh, int *max_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct inode *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) int len = parent ? 6 : 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) u64 nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) u32 generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (*max_len < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) *max_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return FILEID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) nodeid = get_fuse_inode(inode)->nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) generation = inode->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) fh[0] = (u32)(nodeid >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) fh[1] = (u32)(nodeid & 0xffffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) fh[2] = generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) nodeid = get_fuse_inode(parent)->nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) generation = parent->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) fh[3] = (u32)(nodeid >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) fh[4] = (u32)(nodeid & 0xffffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) fh[5] = generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) *max_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return parent ? 0x82 : 0x81;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) static struct dentry *fuse_fh_to_dentry(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct fid *fid, int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct fuse_inode_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if ((fh_type != 0x81 && fh_type != 0x82) || fh_len < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) handle.nodeid = (u64) fid->raw[0] << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) handle.nodeid |= (u64) fid->raw[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) handle.generation = fid->raw[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return fuse_get_dentry(sb, &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) static struct dentry *fuse_fh_to_parent(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) struct fid *fid, int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) struct fuse_inode_handle parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (fh_type != 0x82 || fh_len < 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) parent.nodeid = (u64) fid->raw[3] << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) parent.nodeid |= (u64) fid->raw[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) parent.generation = fid->raw[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) return fuse_get_dentry(sb, &parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) static struct dentry *fuse_get_parent(struct dentry *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) struct inode *child_inode = d_inode(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) struct fuse_conn *fc = get_fuse_conn(child_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) struct fuse_entry_out outarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) const struct qstr name = QSTR_INIT("..", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (!fc->export_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) &name, &outarg, &inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (err == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) parent = d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) fuse_invalidate_entry_cache(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) static const struct export_operations fuse_export_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) .fh_to_dentry = fuse_fh_to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) .fh_to_parent = fuse_fh_to_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) .encode_fh = fuse_encode_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) .get_parent = fuse_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) static const struct super_operations fuse_super_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) .alloc_inode = fuse_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) .free_inode = fuse_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) .evict_inode = fuse_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) .write_inode = fuse_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) .drop_inode = generic_delete_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) .put_super = fuse_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) .umount_begin = fuse_umount_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) .statfs = fuse_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) .show_options = fuse_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) static void sanitize_global_limit(unsigned *limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) * The default maximum number of async requests is calculated to consume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * 1/2^13 of the total memory, assuming 392 bytes per request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (*limit == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) *limit = ((totalram_pages() << PAGE_SHIFT) >> 13) / 392;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (*limit >= 1 << 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) *limit = (1 << 16) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) static int set_global_limit(const char *val, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) rv = param_set_uint(val, kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) sanitize_global_limit((unsigned *)kp->arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) static void process_init_limits(struct fuse_conn *fc, struct fuse_init_out *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) int cap_sys_admin = capable(CAP_SYS_ADMIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) if (arg->minor < 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) sanitize_global_limit(&max_user_bgreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) sanitize_global_limit(&max_user_congthresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) spin_lock(&fc->bg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (arg->max_background) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) fc->max_background = arg->max_background;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (!cap_sys_admin && fc->max_background > max_user_bgreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) fc->max_background = max_user_bgreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) if (arg->congestion_threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) fc->congestion_threshold = arg->congestion_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) if (!cap_sys_admin &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) fc->congestion_threshold > max_user_congthresh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) fc->congestion_threshold = max_user_congthresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) spin_unlock(&fc->bg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) struct fuse_init_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) struct fuse_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) struct fuse_init_in in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) struct fuse_init_out out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) struct fuse_conn *fc = fm->fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) struct fuse_init_args *ia = container_of(args, typeof(*ia), args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) struct fuse_init_out *arg = &ia->out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) bool ok = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (error || arg->major != FUSE_KERNEL_VERSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) ok = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) unsigned long ra_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) process_init_limits(fc, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (arg->minor >= 6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) ra_pages = arg->max_readahead / PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (arg->flags & FUSE_ASYNC_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) fc->async_read = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (!(arg->flags & FUSE_POSIX_LOCKS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) fc->no_lock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) if (arg->minor >= 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) if (!(arg->flags & FUSE_FLOCK_LOCKS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) fc->no_flock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (!(arg->flags & FUSE_POSIX_LOCKS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) fc->no_flock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if (arg->flags & FUSE_ATOMIC_O_TRUNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) fc->atomic_o_trunc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (arg->minor >= 9) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) /* LOOKUP has dependency on proto version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) if (arg->flags & FUSE_EXPORT_SUPPORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) fc->export_support = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) if (arg->flags & FUSE_BIG_WRITES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) fc->big_writes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) if (arg->flags & FUSE_DONT_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) fc->dont_mask = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (arg->flags & FUSE_AUTO_INVAL_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) fc->auto_inval_data = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) else if (arg->flags & FUSE_EXPLICIT_INVAL_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) fc->explicit_inval_data = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (arg->flags & FUSE_DO_READDIRPLUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) fc->do_readdirplus = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (arg->flags & FUSE_READDIRPLUS_AUTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) fc->readdirplus_auto = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) if (arg->flags & FUSE_ASYNC_DIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) fc->async_dio = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (arg->flags & FUSE_WRITEBACK_CACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) fc->writeback_cache = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (arg->flags & FUSE_PARALLEL_DIROPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) fc->parallel_dirops = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (arg->flags & FUSE_HANDLE_KILLPRIV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) fc->handle_killpriv = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (arg->time_gran && arg->time_gran <= 1000000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) fm->sb->s_time_gran = arg->time_gran;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) if ((arg->flags & FUSE_POSIX_ACL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) fc->default_permissions = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) fc->posix_acl = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) fm->sb->s_xattr = fuse_acl_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (arg->flags & FUSE_CACHE_SYMLINKS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) fc->cache_symlinks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (arg->flags & FUSE_ABORT_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) fc->abort_err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (arg->flags & FUSE_MAX_PAGES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) fc->max_pages =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) min_t(unsigned int, FUSE_MAX_MAX_PAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) max_t(unsigned int, arg->max_pages, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (IS_ENABLED(CONFIG_FUSE_DAX) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) arg->flags & FUSE_MAP_ALIGNMENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) !fuse_dax_check_alignment(fc, arg->map_alignment)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) ok = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (arg->flags & FUSE_PASSTHROUGH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) fc->passthrough = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) /* Prevent further stacking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) fm->sb->s_stack_depth =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) FILESYSTEM_MAX_STACK_DEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) ra_pages = fc->max_read / PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) fc->no_lock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) fc->no_flock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) fm->sb->s_bdi->ra_pages =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) min(fm->sb->s_bdi->ra_pages, ra_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) fc->minor = arg->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) fc->max_write = max_t(unsigned, 4096, fc->max_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) fc->conn_init = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) kfree(ia);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (!ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) fc->conn_init = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) fc->conn_error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) fuse_set_initialized(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) wake_up_all(&fc->blocked_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) void fuse_send_init(struct fuse_mount *fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) struct fuse_init_args *ia;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) ia = kzalloc(sizeof(*ia), GFP_KERNEL | __GFP_NOFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) ia->in.major = FUSE_KERNEL_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) ia->in.minor = FUSE_KERNEL_MINOR_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) ia->in.max_readahead = fm->sb->s_bdi->ra_pages * PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) ia->in.flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_ATOMIC_O_TRUNC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) FUSE_EXPORT_SUPPORT | FUSE_BIG_WRITES | FUSE_DONT_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) FUSE_SPLICE_WRITE | FUSE_SPLICE_MOVE | FUSE_SPLICE_READ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) FUSE_FLOCK_LOCKS | FUSE_HAS_IOCTL_DIR | FUSE_AUTO_INVAL_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) FUSE_NO_OPENDIR_SUPPORT | FUSE_EXPLICIT_INVAL_DATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) FUSE_PASSTHROUGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) #ifdef CONFIG_FUSE_DAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (fm->fc->dax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) ia->in.flags |= FUSE_MAP_ALIGNMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (fm->fc->auto_submounts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) ia->in.flags |= FUSE_SUBMOUNTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) ia->args.opcode = FUSE_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) ia->args.in_numargs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) ia->args.in_args[0].size = sizeof(ia->in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) ia->args.in_args[0].value = &ia->in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) ia->args.out_numargs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) /* Variable length argument used for backward compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) with interface version < 7.5. Rest of init_out is zeroed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) by do_get_request(), so a short reply is not a problem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) ia->args.out_argvar = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) ia->args.out_args[0].size = sizeof(ia->out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) ia->args.out_args[0].value = &ia->out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) ia->args.force = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) ia->args.nocreds = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) ia->args.end = process_init_reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) if (fuse_simple_background(fm, &ia->args, GFP_KERNEL) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) process_init_reply(fm, &ia->args, -ENOTCONN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) EXPORT_SYMBOL_GPL(fuse_send_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static int free_fuse_passthrough(int id, void *p, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) struct fuse_passthrough *passthrough = (struct fuse_passthrough *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) fuse_passthrough_release(passthrough);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) void fuse_free_conn(struct fuse_conn *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) WARN_ON(!list_empty(&fc->devices));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) idr_for_each(&fc->passthrough_req, free_fuse_passthrough, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) idr_destroy(&fc->passthrough_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) kfree_rcu(fc, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) EXPORT_SYMBOL_GPL(fuse_free_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static int fuse_bdi_init(struct fuse_conn *fc, struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) char *suffix = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (sb->s_bdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) suffix = "-fuseblk";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) * sb->s_bdi points to blkdev's bdi however we want to redirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) * it to our private bdi...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) bdi_put(sb->s_bdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) sb->s_bdi = &noop_backing_dev_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) err = super_setup_bdi_name(sb, "%u:%u%s", MAJOR(fc->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) MINOR(fc->dev), suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) /* fuse does it's own writeback accounting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) sb->s_bdi->capabilities &= ~BDI_CAP_WRITEBACK_ACCT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) sb->s_bdi->capabilities |= BDI_CAP_STRICTLIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) * For a single fuse filesystem use max 1% of dirty +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) * writeback threshold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) * This gives about 1M of write buffer for memory maps on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) * machine with 1G and 10% dirty_ratio, which should be more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) * than enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) * Privileged users can raise it by writing to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) * /sys/class/bdi/<bdi>/max_ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) bdi_set_max_ratio(sb->s_bdi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct fuse_dev *fuse_dev_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) struct fuse_dev *fud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) struct list_head *pq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) fud = kzalloc(sizeof(struct fuse_dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) if (!fud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) pq = kcalloc(FUSE_PQ_HASH_SIZE, sizeof(struct list_head), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) if (!pq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) kfree(fud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) fud->pq.processing = pq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) fuse_pqueue_init(&fud->pq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) return fud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) EXPORT_SYMBOL_GPL(fuse_dev_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) void fuse_dev_install(struct fuse_dev *fud, struct fuse_conn *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) fud->fc = fuse_conn_get(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) spin_lock(&fc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) list_add_tail(&fud->entry, &fc->devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) spin_unlock(&fc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) EXPORT_SYMBOL_GPL(fuse_dev_install);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct fuse_dev *fuse_dev_alloc_install(struct fuse_conn *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) struct fuse_dev *fud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) fud = fuse_dev_alloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) if (!fud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) fuse_dev_install(fud, fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return fud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) EXPORT_SYMBOL_GPL(fuse_dev_alloc_install);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) void fuse_dev_free(struct fuse_dev *fud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) struct fuse_conn *fc = fud->fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) if (fc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) spin_lock(&fc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) list_del(&fud->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) spin_unlock(&fc->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) fuse_conn_put(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) kfree(fud->pq.processing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) kfree(fud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) EXPORT_SYMBOL_GPL(fuse_dev_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static void fuse_fill_attr_from_inode(struct fuse_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) const struct fuse_inode *fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) *attr = (struct fuse_attr){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) .ino = fi->inode.i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) .size = fi->inode.i_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) .blocks = fi->inode.i_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) .atime = fi->inode.i_atime.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) .mtime = fi->inode.i_mtime.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) .ctime = fi->inode.i_ctime.tv_sec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) .atimensec = fi->inode.i_atime.tv_nsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) .mtimensec = fi->inode.i_mtime.tv_nsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) .ctimensec = fi->inode.i_ctime.tv_nsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) .mode = fi->inode.i_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) .nlink = fi->inode.i_nlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) .uid = fi->inode.i_uid.val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) .gid = fi->inode.i_gid.val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) .rdev = fi->inode.i_rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) .blksize = 1u << fi->inode.i_blkbits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) static void fuse_sb_defaults(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) sb->s_magic = FUSE_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) sb->s_op = &fuse_super_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) sb->s_xattr = fuse_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) sb->s_maxbytes = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) sb->s_export_op = &fuse_export_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) sb->s_iflags |= SB_I_IMA_UNVERIFIABLE_SIGNATURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) if (sb->s_user_ns != &init_user_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) sb->s_iflags |= SB_I_UNTRUSTED_MOUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) sb->s_flags &= ~(SB_NOSEC | SB_I_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) * If we are not in the initial user namespace posix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) * acls must be translated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) if (sb->s_user_ns != &init_user_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) sb->s_xattr = fuse_no_acl_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) int fuse_fill_super_submount(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) struct fuse_inode *parent_fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) struct fuse_mount *fm = get_fuse_mount_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) struct super_block *parent_sb = parent_fi->inode.i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) struct fuse_attr root_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) struct inode *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) fuse_sb_defaults(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) fm->sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) WARN_ON(sb->s_bdi != &noop_backing_dev_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) sb->s_bdi = bdi_get(parent_sb->s_bdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) sb->s_xattr = parent_sb->s_xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) sb->s_time_gran = parent_sb->s_time_gran;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) sb->s_blocksize = parent_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) sb->s_blocksize_bits = parent_sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) sb->s_subtype = kstrdup(parent_sb->s_subtype, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (parent_sb->s_subtype && !sb->s_subtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) fuse_fill_attr_from_inode(&root_attr, parent_fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) root = fuse_iget(sb, parent_fi->nodeid, 0, &root_attr, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) * This inode is just a duplicate, so it is not looked up and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) * its nlookup should not be incremented. fuse_iget() does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) * that, though, so undo it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) get_fuse_inode(root)->nlookup--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) sb->s_d_op = &fuse_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) sb->s_root = d_make_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (!sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) struct fuse_dev *fud = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) struct fuse_mount *fm = get_fuse_mount_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) struct fuse_conn *fc = fm->fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) struct inode *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) struct dentry *root_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) if (sb->s_flags & SB_MANDLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) fuse_sb_defaults(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) if (ctx->is_bdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) #ifdef CONFIG_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) if (!sb_set_blocksize(sb, ctx->blksize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) sb->s_blocksize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) sb->s_blocksize_bits = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) sb->s_subtype = ctx->subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) ctx->subtype = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) if (IS_ENABLED(CONFIG_FUSE_DAX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) err = fuse_dax_conn_alloc(fc, ctx->dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (ctx->fudptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) fud = fuse_dev_alloc_install(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) if (!fud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) goto err_free_dax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) fc->dev = sb->s_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) fm->sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) err = fuse_bdi_init(fc, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) goto err_dev_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) /* Handle umasking inside the fuse code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) if (sb->s_flags & SB_POSIXACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) fc->dont_mask = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) sb->s_flags |= SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) fc->default_permissions = ctx->default_permissions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) fc->allow_other = ctx->allow_other;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) fc->user_id = ctx->user_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) fc->group_id = ctx->group_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) fc->legacy_opts_show = ctx->legacy_opts_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) fc->max_read = max_t(unsigned int, 4096, ctx->max_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) fc->destroy = ctx->destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) fc->no_control = ctx->no_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) fc->no_force_umount = ctx->no_force_umount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) root = fuse_get_root_inode(sb, ctx->rootmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) sb->s_d_op = &fuse_root_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) root_dentry = d_make_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) if (!root_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) goto err_dev_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) /* Root dentry doesn't have .d_revalidate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) sb->s_d_op = &fuse_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) mutex_lock(&fuse_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) if (ctx->fudptr && *ctx->fudptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) err = fuse_ctl_add_conn(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) list_add_tail(&fc->entry, &fuse_conn_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) sb->s_root = root_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) if (ctx->fudptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) *ctx->fudptr = fud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) mutex_unlock(&fuse_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) mutex_unlock(&fuse_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) dput(root_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) err_dev_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (fud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) fuse_dev_free(fud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) err_free_dax:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (IS_ENABLED(CONFIG_FUSE_DAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) fuse_dax_conn_free(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) EXPORT_SYMBOL_GPL(fuse_fill_super_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) struct fuse_fs_context *ctx = fsc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) struct file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) struct fuse_conn *fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) struct fuse_mount *fm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) file = fget(ctx->fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (!file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) * Require mount to happen from the same user namespace which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) * opened /dev/fuse to prevent potential attacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) if ((file->f_op != &fuse_dev_operations) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) (file->f_cred->user_ns != sb->s_user_ns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) goto err_fput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) ctx->fudptr = &file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) fc = kmalloc(sizeof(*fc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) if (!fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) goto err_fput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) fm = kzalloc(sizeof(*fm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) if (!fm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) kfree(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) goto err_fput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) fuse_conn_init(fc, fm, sb->s_user_ns, &fuse_dev_fiq_ops, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) fc->release = fuse_free_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) sb->s_fs_info = fm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) err = fuse_fill_super_common(sb, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) goto err_put_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) * atomic_dec_and_test() in fput() provides the necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) * memory barrier for file->private_data to be visible on all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) * CPUs after this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) fput(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) fuse_send_init(get_fuse_mount_super(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) err_put_conn:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) fuse_mount_put(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) err_fput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) fput(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) static int fuse_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) struct fuse_fs_context *ctx = fc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) if (!ctx->fd_present || !ctx->rootmode_present ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) !ctx->user_id_present || !ctx->group_id_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) #ifdef CONFIG_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) if (ctx->is_bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) return get_tree_bdev(fc, fuse_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) return get_tree_nodev(fc, fuse_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) static const struct fs_context_operations fuse_context_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) .free = fuse_free_fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) .parse_param = fuse_parse_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) .reconfigure = fuse_reconfigure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) .get_tree = fuse_get_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) * Set up the filesystem mount context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) static int fuse_init_fs_context(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) struct fuse_fs_context *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) ctx = kzalloc(sizeof(struct fuse_fs_context), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) ctx->max_read = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) ctx->blksize = FUSE_DEFAULT_BLKSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) ctx->legacy_opts_show = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) #ifdef CONFIG_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (fc->fs_type == &fuseblk_fs_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) ctx->is_bdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) ctx->destroy = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) fc->fs_private = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) fc->ops = &fuse_context_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) bool fuse_mount_remove(struct fuse_mount *fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) struct fuse_conn *fc = fm->fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) bool last = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) down_write(&fc->killsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) list_del_init(&fm->fc_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) if (list_empty(&fc->mounts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) last = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) up_write(&fc->killsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) return last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) EXPORT_SYMBOL_GPL(fuse_mount_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) void fuse_conn_destroy(struct fuse_mount *fm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) struct fuse_conn *fc = fm->fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) if (fc->destroy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) fuse_send_destroy(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) fuse_abort_conn(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) fuse_wait_aborted(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) if (!list_empty(&fc->entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) mutex_lock(&fuse_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) list_del(&fc->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) fuse_ctl_remove_conn(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) mutex_unlock(&fuse_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) EXPORT_SYMBOL_GPL(fuse_conn_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) static void fuse_kill_sb_anon(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) struct fuse_mount *fm = get_fuse_mount_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) bool last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (fm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) last = fuse_mount_remove(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) if (last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) fuse_conn_destroy(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) kill_anon_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) static struct file_system_type fuse_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) .name = "fuse",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) .fs_flags = FS_HAS_SUBTYPE | FS_USERNS_MOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) .init_fs_context = fuse_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) .parameters = fuse_fs_parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) .kill_sb = fuse_kill_sb_anon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) MODULE_ALIAS_FS("fuse");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) #ifdef CONFIG_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) static void fuse_kill_sb_blk(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) struct fuse_mount *fm = get_fuse_mount_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) bool last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) if (fm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) last = fuse_mount_remove(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) if (last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) fuse_conn_destroy(fm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) kill_block_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) static struct file_system_type fuseblk_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) .name = "fuseblk",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) .init_fs_context = fuse_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) .parameters = fuse_fs_parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) .kill_sb = fuse_kill_sb_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) .fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) MODULE_ALIAS_FS("fuseblk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) static inline int register_fuseblk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) return register_filesystem(&fuseblk_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) static inline void unregister_fuseblk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) unregister_filesystem(&fuseblk_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) static inline int register_fuseblk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) static inline void unregister_fuseblk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) static void fuse_inode_init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) struct inode *inode = foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) inode_init_once(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) static int __init fuse_fs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) fuse_inode_cachep = kmem_cache_create("fuse_inode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) sizeof(struct fuse_inode), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT|SLAB_RECLAIM_ACCOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) fuse_inode_init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) if (!fuse_inode_cachep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) err = register_fuseblk();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) err = register_filesystem(&fuse_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) out3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) unregister_fuseblk();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) kmem_cache_destroy(fuse_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) static void fuse_fs_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) unregister_filesystem(&fuse_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) unregister_fuseblk();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) kmem_cache_destroy(fuse_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) static struct kobject *fuse_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) static int fuse_sysfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) fuse_kobj = kobject_create_and_add("fuse", fs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) if (!fuse_kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) err = sysfs_create_mount_point(fuse_kobj, "connections");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) goto out_fuse_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) out_fuse_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) kobject_put(fuse_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) static void fuse_sysfs_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) sysfs_remove_mount_point(fuse_kobj, "connections");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) kobject_put(fuse_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) static int __init fuse_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) pr_info("init (API version %i.%i)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) INIT_LIST_HEAD(&fuse_conn_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) res = fuse_fs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) res = fuse_dev_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) goto err_fs_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) res = fuse_sysfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) goto err_dev_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) res = fuse_ctl_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) goto err_sysfs_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) sanitize_global_limit(&max_user_bgreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) sanitize_global_limit(&max_user_congthresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) err_sysfs_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) fuse_sysfs_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) err_dev_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) fuse_dev_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) err_fs_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) fuse_fs_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) static void __exit fuse_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) pr_debug("exit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) fuse_ctl_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) fuse_sysfs_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) fuse_fs_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) fuse_dev_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) module_init(fuse_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) module_exit(fuse_exit);