12 #include <linux/slab.h>
16 #include <linux/module.h>
20 #include <linux/random.h>
21 #include <linux/sched.h>
39 "Global limit for the maximum number of backgrounded requests an "
40 "unprivileged user can set");
47 "Global limit for the maximum congestion threshold an "
48 "unprivileged user can set");
50 #define FUSE_SUPER_MAGIC 0x65735546
52 #define FUSE_DEFAULT_BLKSIZE 512
55 #define FUSE_DEFAULT_MAX_BACKGROUND 12
58 #define FUSE_DEFAULT_CONGESTION_THRESHOLD (FUSE_DEFAULT_MAX_BACKGROUND * 3 / 4)
88 fi = get_fuse_inode(inode);
114 static void fuse_destroy_inode(
struct inode *inode)
116 struct fuse_inode *fi = get_fuse_inode(inode);
123 static void fuse_evict_inode(
struct inode *inode)
129 struct fuse_inode *fi = get_fuse_inode(inode);
147 static ino_t fuse_squash_ino(
u64 ino64)
151 ino ^= ino64 >> (
sizeof(
u64) -
sizeof(
ino_t)) * 8;
159 struct fuse_inode *fi = get_fuse_inode(inode);
164 inode->
i_ino = fuse_squash_ino(attr->
ino);
198 struct fuse_inode *fi = get_fuse_inode(inode);
202 spin_lock(&fc->
lock);
203 if (attr_version != 0 && fi->
attr_version > attr_version) {
204 spin_unlock(&fc->
lock);
212 i_size_write(inode, attr->
size);
213 spin_unlock(&fc->
lock);
218 if (oldsize != attr->
size) {
231 if (!timespec_equal(&old_mtime, &new_mtime))
240 static void fuse_init_inode(
struct inode *inode,
struct fuse_attr *
attr)
255 new_decode_dev(attr->
rdev));
262 u64 nodeid = *(
u64 *) _nodeidp;
263 if (get_node_id(inode) == nodeid)
269 static int fuse_inode_set(
struct inode *inode,
void *_nodeidp)
271 u64 nodeid = *(
u64 *) _nodeidp;
272 get_fuse_inode(inode)->nodeid = nodeid;
278 u64 attr_valid,
u64 attr_version)
292 inode->
i_data.backing_dev_info = &fc->
bdi;
293 fuse_init_inode(inode, attr);
302 fi = get_fuse_inode(inode);
303 spin_lock(&fc->
lock);
305 spin_unlock(&fc->
lock);
312 loff_t
offset, loff_t len)
328 pg_end = (offset + len - 1) >> PAGE_CACHE_SHIFT;
336 static void fuse_umount_begin(
struct super_block *sb)
341 static void fuse_send_destroy(
struct fuse_conn *
fc)
353 static void fuse_bdi_destroy(
struct fuse_conn *fc)
361 spin_lock(&fc->
lock);
364 spin_unlock(&fc->
lock);
375 struct fuse_conn *fc = get_fuse_conn_super(sb);
377 fuse_send_destroy(fc);
384 fuse_bdi_destroy(fc);
406 struct fuse_conn *fc = get_fuse_conn_super(sb);
420 memset(&outarg, 0,
sizeof(outarg));
423 req->
in.h.nodeid = get_node_id(dentry->
d_inode);
424 req->
out.numargs = 1;
425 req->
out.args[0].size =
427 req->
out.args[0].value = &outarg;
429 err = req->
out.h.error;
431 convert_fuse_statfs(buf, &outarg.st);
521 if (!is_bdev ||
match_int(&args[0], &value))
538 static int fuse_show_options(
struct seq_file *
m,
struct dentry *root)
541 struct fuse_conn *fc = get_fuse_conn_super(sb);
546 seq_puts(m,
",default_permissions");
558 memset(fc, 0,
sizeof(*fc));
568 INIT_LIST_HEAD(&fc->
io);
571 INIT_LIST_HEAD(&fc->
entry);
603 static struct inode *fuse_get_root_inode(
struct super_block *sb,
unsigned mode)
606 memset(&attr, 0,
sizeof(attr));
619 static struct dentry *fuse_get_dentry(
struct super_block *sb,
622 struct fuse_conn *fc = get_fuse_conn_super(sb);
624 struct dentry *
entry;
642 if (err && err != -
ENOENT)
649 if (get_node_id(inode) != handle->
nodeid)
657 if (!IS_ERR(entry) && get_node_id(inode) !=
FUSE_ROOT_ID)
668 static int fuse_encode_fh(
struct inode *inode,
u32 *fh,
int *max_len,
669 struct inode *parent)
671 int len = parent ? 6 : 3;
675 if (*max_len < len) {
680 nodeid = get_fuse_inode(inode)->nodeid;
683 fh[0] = (
u32)(nodeid >> 32);
684 fh[1] = (
u32)(nodeid & 0xffffffff);
688 nodeid = get_fuse_inode(parent)->nodeid;
691 fh[3] = (
u32)(nodeid >> 32);
692 fh[4] = (
u32)(nodeid & 0xffffffff);
697 return parent ? 0x82 : 0x81;
700 static struct dentry *fuse_fh_to_dentry(
struct super_block *sb,
701 struct fid *
fid,
int fh_len,
int fh_type)
705 if ((fh_type != 0x81 && fh_type != 0x82) || fh_len < 3)
711 return fuse_get_dentry(sb, &handle);
714 static struct dentry *fuse_fh_to_parent(
struct super_block *sb,
715 struct fid *fid,
int fh_len,
int fh_type)
719 if (fh_type != 0x82 || fh_len < 6)
722 parent.nodeid = (
u64) fid->
raw[3] << 32;
723 parent.nodeid |= (
u64) fid->
raw[4];
724 parent.generation = fid->
raw[5];
725 return fuse_get_dentry(sb, &parent);
728 static struct dentry *fuse_get_parent(
struct dentry *
child)
730 struct inode *child_inode = child->
d_inode;
731 struct fuse_conn *fc = get_fuse_conn(child_inode);
733 struct dentry *parent;
744 &
name, &outarg, &inode);
752 if (!IS_ERR(parent) && get_node_id(inode) !=
FUSE_ROOT_ID)
759 .fh_to_dentry = fuse_fh_to_dentry,
760 .fh_to_parent = fuse_fh_to_parent,
761 .encode_fh = fuse_encode_fh,
762 .get_parent = fuse_get_parent,
766 .alloc_inode = fuse_alloc_inode,
767 .destroy_inode = fuse_destroy_inode,
768 .evict_inode = fuse_evict_inode,
770 .remount_fs = fuse_remount_fs,
771 .put_super = fuse_put_super,
772 .umount_begin = fuse_umount_begin,
773 .statfs = fuse_statfs,
774 .show_options = fuse_show_options,
777 static void sanitize_global_limit(
unsigned *
limit)
780 *limit = ((num_physpages << PAGE_SHIFT) >> 13) /
783 if (*limit >= 1 << 16)
784 *limit = (1 << 16) - 1;
795 sanitize_global_limit((
unsigned *)kp->
arg);
819 if (!cap_sys_admin &&
832 unsigned long ra_pages;
834 process_init_limits(fc, arg);
836 if (arg->
minor >= 6) {
842 if (arg->
minor >= 17) {
851 if (arg->
minor >= 9) {
868 fc->
bdi.ra_pages =
min(fc->
bdi.ra_pages, ra_pages);
891 req->
in.args[0].size =
sizeof(*arg);
892 req->
in.args[0].value =
arg;
893 req->
out.numargs = 1;
900 req->
end = process_init_reply;
904 static void fuse_free_conn(
struct fuse_conn *fc)
913 fc->
bdi.name =
"fuse";
951 static int fuse_fill_super(
struct super_block *sb,
void *data,
int silent)
957 struct dentry *root_dentry;
968 if (!parse_fuse_opt((
char *) data, &d, is_bdev))
982 sb->
s_op = &fuse_super_operations;
1004 err = fuse_bdi_init(fc, sb);
1025 root = fuse_get_root_inode(sb, d.
rootmode);
1039 goto err_free_init_req;
1052 sb->
s_root = root_dentry;
1063 fuse_send_init(fc, init_req);
1074 fuse_bdi_destroy(fc);
1083 int flags,
const char *dev_name,
1086 return mount_nodev(fs_type, flags, raw_data, fuse_fill_super);
1089 static void fuse_kill_sb_anon(
struct super_block *sb)
1091 struct fuse_conn *fc = get_fuse_conn_super(sb);
1106 .mount = fuse_mount,
1107 .kill_sb = fuse_kill_sb_anon,
1112 int flags,
const char *dev_name,
1115 return mount_bdev(fs_type, flags, dev_name, raw_data, fuse_fill_super);
1118 static void fuse_kill_sb_blk(
struct super_block *sb)
1120 struct fuse_conn *fc = get_fuse_conn_super(sb);
1134 .mount = fuse_mount_blk,
1135 .kill_sb = fuse_kill_sb_blk,
1139 static inline int register_fuseblk(
void)
1144 static inline void unregister_fuseblk(
void)
1149 static inline int register_fuseblk(
void)
1154 static inline void unregister_fuseblk(
void)
1159 static void fuse_inode_init_once(
void *
foo)
1161 struct inode *inode =
foo;
1166 static int __init fuse_fs_init(
void)
1173 fuse_inode_init_once);
1175 if (!fuse_inode_cachep)
1178 err = register_fuseblk();
1189 unregister_fuseblk();
1196 static void fuse_fs_cleanup(
void)
1199 unregister_fuseblk();
1209 static struct kobject *fuse_kobj;
1210 static struct kobject *connections_kobj;
1212 static int fuse_sysfs_init(
void)
1223 if (!connections_kobj) {
1225 goto out_fuse_unregister;
1230 out_fuse_unregister:
1236 static void fuse_sysfs_cleanup(
void)
1242 static int __init fuse_init(
void)
1250 res = fuse_fs_init();
1256 goto err_fs_cleanup;
1258 res = fuse_sysfs_init();
1260 goto err_dev_cleanup;
1264 goto err_sysfs_cleanup;
1272 fuse_sysfs_cleanup();
1281 static void __exit fuse_exit(
void)
1286 fuse_sysfs_cleanup();