Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 3 | Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include "fuse_i.h" |
| 10 | |
| 11 | #include <linux/pagemap.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/file.h> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 14 | #include <linux/seq_file.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 17 | #include <linux/parser.h> |
| 18 | #include <linux/statfs.h> |
| 19 | |
| 20 | MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>"); |
| 21 | MODULE_DESCRIPTION("Filesystem in Userspace"); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 24 | static kmem_cache_t *fuse_inode_cachep; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 25 | struct list_head fuse_conn_list; |
| 26 | DEFINE_MUTEX(fuse_mutex); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 27 | |
| 28 | #define FUSE_SUPER_MAGIC 0x65735546 |
| 29 | |
| 30 | struct fuse_mount_data { |
| 31 | int fd; |
| 32 | unsigned rootmode; |
| 33 | unsigned user_id; |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 34 | unsigned group_id; |
Miklos Szeredi | 5a53368 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 35 | unsigned fd_present : 1; |
| 36 | unsigned rootmode_present : 1; |
| 37 | unsigned user_id_present : 1; |
| 38 | unsigned group_id_present : 1; |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 39 | unsigned flags; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 40 | unsigned max_read; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static struct inode *fuse_alloc_inode(struct super_block *sb) |
| 44 | { |
| 45 | struct inode *inode; |
| 46 | struct fuse_inode *fi; |
| 47 | |
| 48 | inode = kmem_cache_alloc(fuse_inode_cachep, SLAB_KERNEL); |
| 49 | if (!inode) |
| 50 | return NULL; |
| 51 | |
| 52 | fi = get_fuse_inode(inode); |
| 53 | fi->i_time = jiffies - 1; |
| 54 | fi->nodeid = 0; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 55 | fi->nlookup = 0; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 56 | fi->forget_req = fuse_request_alloc(); |
| 57 | if (!fi->forget_req) { |
| 58 | kmem_cache_free(fuse_inode_cachep, inode); |
| 59 | return NULL; |
| 60 | } |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 61 | |
| 62 | return inode; |
| 63 | } |
| 64 | |
| 65 | static void fuse_destroy_inode(struct inode *inode) |
| 66 | { |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 67 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 68 | if (fi->forget_req) |
| 69 | fuse_request_free(fi->forget_req); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 70 | kmem_cache_free(fuse_inode_cachep, inode); |
| 71 | } |
| 72 | |
| 73 | static void fuse_read_inode(struct inode *inode) |
| 74 | { |
| 75 | /* No op */ |
| 76 | } |
| 77 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 78 | void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 79 | unsigned long nodeid, u64 nlookup) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 80 | { |
| 81 | struct fuse_forget_in *inarg = &req->misc.forget_in; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 82 | inarg->nlookup = nlookup; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 83 | req->in.h.opcode = FUSE_FORGET; |
| 84 | req->in.h.nodeid = nodeid; |
| 85 | req->in.numargs = 1; |
| 86 | req->in.args[0].size = sizeof(struct fuse_forget_in); |
| 87 | req->in.args[0].value = inarg; |
| 88 | request_send_noreply(fc, req); |
| 89 | } |
| 90 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 91 | static void fuse_clear_inode(struct inode *inode) |
| 92 | { |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 93 | if (inode->i_sb->s_flags & MS_ACTIVE) { |
| 94 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 95 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 96 | fuse_send_forget(fc, fi->forget_req, fi->nodeid, fi->nlookup); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 97 | fi->forget_req = NULL; |
| 98 | } |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr) |
| 102 | { |
| 103 | if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size) |
| 104 | invalidate_inode_pages(inode->i_mapping); |
| 105 | |
| 106 | inode->i_ino = attr->ino; |
| 107 | inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777); |
| 108 | inode->i_nlink = attr->nlink; |
| 109 | inode->i_uid = attr->uid; |
| 110 | inode->i_gid = attr->gid; |
| 111 | i_size_write(inode, attr->size); |
| 112 | inode->i_blksize = PAGE_CACHE_SIZE; |
| 113 | inode->i_blocks = attr->blocks; |
| 114 | inode->i_atime.tv_sec = attr->atime; |
| 115 | inode->i_atime.tv_nsec = attr->atimensec; |
| 116 | inode->i_mtime.tv_sec = attr->mtime; |
| 117 | inode->i_mtime.tv_nsec = attr->mtimensec; |
| 118 | inode->i_ctime.tv_sec = attr->ctime; |
| 119 | inode->i_ctime.tv_nsec = attr->ctimensec; |
| 120 | } |
| 121 | |
| 122 | static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) |
| 123 | { |
| 124 | inode->i_mode = attr->mode & S_IFMT; |
| 125 | i_size_write(inode, attr->size); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 126 | if (S_ISREG(inode->i_mode)) { |
| 127 | fuse_init_common(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 128 | fuse_init_file_inode(inode); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 129 | } else if (S_ISDIR(inode->i_mode)) |
| 130 | fuse_init_dir(inode); |
| 131 | else if (S_ISLNK(inode->i_mode)) |
| 132 | fuse_init_symlink(inode); |
| 133 | else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || |
| 134 | S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { |
| 135 | fuse_init_common(inode); |
| 136 | init_special_inode(inode, inode->i_mode, |
| 137 | new_decode_dev(attr->rdev)); |
Miklos Szeredi | 39ee059 | 2006-01-06 00:19:43 -0800 | [diff] [blame] | 138 | } else |
| 139 | BUG(); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static int fuse_inode_eq(struct inode *inode, void *_nodeidp) |
| 143 | { |
| 144 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 145 | if (get_node_id(inode) == nodeid) |
| 146 | return 1; |
| 147 | else |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static int fuse_inode_set(struct inode *inode, void *_nodeidp) |
| 152 | { |
| 153 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 154 | get_fuse_inode(inode)->nodeid = nodeid; |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 159 | int generation, struct fuse_attr *attr) |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 160 | { |
| 161 | struct inode *inode; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 162 | struct fuse_inode *fi; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 163 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
| 164 | int retried = 0; |
| 165 | |
| 166 | retry: |
| 167 | inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid); |
| 168 | if (!inode) |
| 169 | return NULL; |
| 170 | |
| 171 | if ((inode->i_state & I_NEW)) { |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 172 | inode->i_flags |= S_NOATIME|S_NOCMTIME; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 173 | inode->i_generation = generation; |
| 174 | inode->i_data.backing_dev_info = &fc->bdi; |
| 175 | fuse_init_inode(inode, attr); |
| 176 | unlock_new_inode(inode); |
| 177 | } else if ((inode->i_mode ^ attr->mode) & S_IFMT) { |
| 178 | BUG_ON(retried); |
| 179 | /* Inode has changed type, any I/O on the old should fail */ |
| 180 | make_bad_inode(inode); |
| 181 | iput(inode); |
| 182 | retried = 1; |
| 183 | goto retry; |
| 184 | } |
| 185 | |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 186 | fi = get_fuse_inode(inode); |
| 187 | fi->nlookup ++; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 188 | fuse_change_attributes(inode, attr); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 189 | return inode; |
| 190 | } |
| 191 | |
Miklos Szeredi | 69a53bf | 2006-01-16 22:14:41 -0800 | [diff] [blame] | 192 | static void fuse_umount_begin(struct super_block *sb) |
| 193 | { |
| 194 | fuse_abort_conn(get_fuse_conn_super(sb)); |
| 195 | } |
| 196 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 197 | static void fuse_put_super(struct super_block *sb) |
| 198 | { |
| 199 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
| 200 | |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 201 | spin_lock(&fc->lock); |
Miklos Szeredi | 9ba7cbb | 2006-01-16 22:14:34 -0800 | [diff] [blame] | 202 | fc->connected = 0; |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 203 | fc->blocked = 0; |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 204 | spin_unlock(&fc->lock); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 205 | /* Flush all readers on this fs */ |
Jeff Dike | 385a17b | 2006-04-10 22:54:52 -0700 | [diff] [blame] | 206 | kill_fasync(&fc->fasync, SIGIO, POLL_IN); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 207 | wake_up_all(&fc->waitq); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 208 | wake_up_all(&fc->blocked_waitq); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 209 | mutex_lock(&fuse_mutex); |
| 210 | list_del(&fc->entry); |
| 211 | fuse_ctl_remove_conn(fc); |
| 212 | mutex_unlock(&fuse_mutex); |
| 213 | fuse_conn_put(fc); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 216 | static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr) |
| 217 | { |
| 218 | stbuf->f_type = FUSE_SUPER_MAGIC; |
| 219 | stbuf->f_bsize = attr->bsize; |
Miklos Szeredi | de5f120 | 2006-01-06 00:19:37 -0800 | [diff] [blame] | 220 | stbuf->f_frsize = attr->frsize; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 221 | stbuf->f_blocks = attr->blocks; |
| 222 | stbuf->f_bfree = attr->bfree; |
| 223 | stbuf->f_bavail = attr->bavail; |
| 224 | stbuf->f_files = attr->files; |
| 225 | stbuf->f_ffree = attr->ffree; |
| 226 | stbuf->f_namelen = attr->namelen; |
| 227 | /* fsid is left zero */ |
| 228 | } |
| 229 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 230 | static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf) |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 231 | { |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 232 | struct super_block *sb = dentry->d_sb; |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 233 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
| 234 | struct fuse_req *req; |
| 235 | struct fuse_statfs_out outarg; |
| 236 | int err; |
| 237 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 238 | req = fuse_get_req(fc); |
| 239 | if (IS_ERR(req)) |
| 240 | return PTR_ERR(req); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 241 | |
Miklos Szeredi | de5f120 | 2006-01-06 00:19:37 -0800 | [diff] [blame] | 242 | memset(&outarg, 0, sizeof(outarg)); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 243 | req->in.numargs = 0; |
| 244 | req->in.h.opcode = FUSE_STATFS; |
| 245 | req->out.numargs = 1; |
Miklos Szeredi | de5f120 | 2006-01-06 00:19:37 -0800 | [diff] [blame] | 246 | req->out.args[0].size = |
| 247 | fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg); |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 248 | req->out.args[0].value = &outarg; |
| 249 | request_send(fc, req); |
| 250 | err = req->out.h.error; |
| 251 | if (!err) |
| 252 | convert_fuse_statfs(buf, &outarg.st); |
| 253 | fuse_put_request(fc, req); |
| 254 | return err; |
| 255 | } |
| 256 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 257 | enum { |
| 258 | OPT_FD, |
| 259 | OPT_ROOTMODE, |
| 260 | OPT_USER_ID, |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 261 | OPT_GROUP_ID, |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 262 | OPT_DEFAULT_PERMISSIONS, |
| 263 | OPT_ALLOW_OTHER, |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 264 | OPT_MAX_READ, |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 265 | OPT_ERR |
| 266 | }; |
| 267 | |
| 268 | static match_table_t tokens = { |
| 269 | {OPT_FD, "fd=%u"}, |
| 270 | {OPT_ROOTMODE, "rootmode=%o"}, |
| 271 | {OPT_USER_ID, "user_id=%u"}, |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 272 | {OPT_GROUP_ID, "group_id=%u"}, |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 273 | {OPT_DEFAULT_PERMISSIONS, "default_permissions"}, |
| 274 | {OPT_ALLOW_OTHER, "allow_other"}, |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 275 | {OPT_MAX_READ, "max_read=%u"}, |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 276 | {OPT_ERR, NULL} |
| 277 | }; |
| 278 | |
| 279 | static int parse_fuse_opt(char *opt, struct fuse_mount_data *d) |
| 280 | { |
| 281 | char *p; |
| 282 | memset(d, 0, sizeof(struct fuse_mount_data)); |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 283 | d->max_read = ~0; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 284 | |
| 285 | while ((p = strsep(&opt, ",")) != NULL) { |
| 286 | int token; |
| 287 | int value; |
| 288 | substring_t args[MAX_OPT_ARGS]; |
| 289 | if (!*p) |
| 290 | continue; |
| 291 | |
| 292 | token = match_token(p, tokens, args); |
| 293 | switch (token) { |
| 294 | case OPT_FD: |
| 295 | if (match_int(&args[0], &value)) |
| 296 | return 0; |
| 297 | d->fd = value; |
Miklos Szeredi | 5a53368 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 298 | d->fd_present = 1; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 299 | break; |
| 300 | |
| 301 | case OPT_ROOTMODE: |
| 302 | if (match_octal(&args[0], &value)) |
| 303 | return 0; |
| 304 | d->rootmode = value; |
Miklos Szeredi | 5a53368 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 305 | d->rootmode_present = 1; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 306 | break; |
| 307 | |
| 308 | case OPT_USER_ID: |
| 309 | if (match_int(&args[0], &value)) |
| 310 | return 0; |
| 311 | d->user_id = value; |
Miklos Szeredi | 5a53368 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 312 | d->user_id_present = 1; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 313 | break; |
| 314 | |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 315 | case OPT_GROUP_ID: |
| 316 | if (match_int(&args[0], &value)) |
| 317 | return 0; |
| 318 | d->group_id = value; |
Miklos Szeredi | 5a53368 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 319 | d->group_id_present = 1; |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 320 | break; |
| 321 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 322 | case OPT_DEFAULT_PERMISSIONS: |
| 323 | d->flags |= FUSE_DEFAULT_PERMISSIONS; |
| 324 | break; |
| 325 | |
| 326 | case OPT_ALLOW_OTHER: |
| 327 | d->flags |= FUSE_ALLOW_OTHER; |
| 328 | break; |
| 329 | |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 330 | case OPT_MAX_READ: |
| 331 | if (match_int(&args[0], &value)) |
| 332 | return 0; |
| 333 | d->max_read = value; |
| 334 | break; |
| 335 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 336 | default: |
| 337 | return 0; |
| 338 | } |
| 339 | } |
Miklos Szeredi | 5a53368 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 340 | |
| 341 | if (!d->fd_present || !d->rootmode_present || |
| 342 | !d->user_id_present || !d->group_id_present) |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | |
| 345 | return 1; |
| 346 | } |
| 347 | |
| 348 | static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 349 | { |
| 350 | struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb); |
| 351 | |
| 352 | seq_printf(m, ",user_id=%u", fc->user_id); |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 353 | seq_printf(m, ",group_id=%u", fc->group_id); |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 354 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) |
| 355 | seq_puts(m, ",default_permissions"); |
| 356 | if (fc->flags & FUSE_ALLOW_OTHER) |
| 357 | seq_puts(m, ",allow_other"); |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 358 | if (fc->max_read != ~0) |
| 359 | seq_printf(m, ",max_read=%u", fc->max_read); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 360 | return 0; |
| 361 | } |
| 362 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 363 | static struct fuse_conn *new_conn(void) |
| 364 | { |
| 365 | struct fuse_conn *fc; |
| 366 | |
Miklos Szeredi | 6383bda | 2006-01-16 22:14:29 -0800 | [diff] [blame] | 367 | fc = kzalloc(sizeof(*fc), GFP_KERNEL); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 368 | if (fc) { |
Miklos Szeredi | d713311 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 369 | spin_lock_init(&fc->lock); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 370 | atomic_set(&fc->count, 1); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 371 | init_waitqueue_head(&fc->waitq); |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 372 | init_waitqueue_head(&fc->blocked_waitq); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 373 | INIT_LIST_HEAD(&fc->pending); |
| 374 | INIT_LIST_HEAD(&fc->processing); |
Miklos Szeredi | d77a1d5 | 2006-01-16 22:14:31 -0800 | [diff] [blame] | 375 | INIT_LIST_HEAD(&fc->io); |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 376 | atomic_set(&fc->num_waiting, 0); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 377 | fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; |
| 378 | fc->bdi.unplug_io_fn = default_unplug_io_fn; |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 379 | fc->reqctr = 0; |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 380 | fc->blocked = 1; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 381 | } |
| 382 | return fc; |
| 383 | } |
| 384 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 385 | void fuse_conn_put(struct fuse_conn *fc) |
| 386 | { |
| 387 | if (atomic_dec_and_test(&fc->count)) |
| 388 | kfree(fc); |
| 389 | } |
| 390 | |
| 391 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc) |
| 392 | { |
| 393 | atomic_inc(&fc->count); |
| 394 | return fc; |
| 395 | } |
| 396 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 397 | static struct inode *get_root_inode(struct super_block *sb, unsigned mode) |
| 398 | { |
| 399 | struct fuse_attr attr; |
| 400 | memset(&attr, 0, sizeof(attr)); |
| 401 | |
| 402 | attr.mode = mode; |
| 403 | attr.ino = FUSE_ROOT_ID; |
Miklos Szeredi | 9e6268d | 2005-09-09 13:10:29 -0700 | [diff] [blame] | 404 | return fuse_iget(sb, 1, 0, &attr); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static struct super_operations fuse_super_operations = { |
| 408 | .alloc_inode = fuse_alloc_inode, |
| 409 | .destroy_inode = fuse_destroy_inode, |
| 410 | .read_inode = fuse_read_inode, |
| 411 | .clear_inode = fuse_clear_inode, |
| 412 | .put_super = fuse_put_super, |
Miklos Szeredi | 69a53bf | 2006-01-16 22:14:41 -0800 | [diff] [blame] | 413 | .umount_begin = fuse_umount_begin, |
Miklos Szeredi | e5e5558 | 2005-09-09 13:10:28 -0700 | [diff] [blame] | 414 | .statfs = fuse_statfs, |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 415 | .show_options = fuse_show_options, |
| 416 | }; |
| 417 | |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 418 | static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) |
| 419 | { |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 420 | struct fuse_init_out *arg = &req->misc.init_out; |
| 421 | |
| 422 | if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION) |
| 423 | fc->conn_error = 1; |
| 424 | else { |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 425 | unsigned long ra_pages; |
| 426 | |
| 427 | if (arg->minor >= 6) { |
| 428 | ra_pages = arg->max_readahead / PAGE_CACHE_SIZE; |
| 429 | if (arg->flags & FUSE_ASYNC_READ) |
| 430 | fc->async_read = 1; |
| 431 | } else |
| 432 | ra_pages = fc->max_read / PAGE_CACHE_SIZE; |
| 433 | |
| 434 | fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages); |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 435 | fc->minor = arg->minor; |
| 436 | fc->max_write = arg->minor < 5 ? 4096 : arg->max_write; |
| 437 | } |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 438 | fuse_put_request(fc, req); |
Miklos Szeredi | 08a53cd | 2006-04-10 22:54:59 -0700 | [diff] [blame] | 439 | fc->blocked = 0; |
| 440 | wake_up_all(&fc->blocked_waitq); |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 443 | static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req) |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 444 | { |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 445 | struct fuse_init_in *arg = &req->misc.init_in; |
Miklos Szeredi | 095da6c | 2006-01-16 22:14:52 -0800 | [diff] [blame] | 446 | |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 447 | arg->major = FUSE_KERNEL_VERSION; |
| 448 | arg->minor = FUSE_KERNEL_MINOR_VERSION; |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 449 | arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE; |
| 450 | arg->flags |= FUSE_ASYNC_READ; |
Miklos Szeredi | 9b9a046 | 2006-01-16 22:14:44 -0800 | [diff] [blame] | 451 | req->in.h.opcode = FUSE_INIT; |
| 452 | req->in.numargs = 1; |
| 453 | req->in.args[0].size = sizeof(*arg); |
| 454 | req->in.args[0].value = arg; |
| 455 | req->out.numargs = 1; |
| 456 | /* Variable length arguement used for backward compatibility |
| 457 | with interface version < 7.5. Rest of init_out is zeroed |
| 458 | by do_get_request(), so a short reply is not a problem */ |
| 459 | req->out.argvar = 1; |
| 460 | req->out.args[0].size = sizeof(struct fuse_init_out); |
| 461 | req->out.args[0].value = &req->misc.init_out; |
| 462 | req->end = process_init_reply; |
| 463 | request_send_background(fc, req); |
| 464 | } |
| 465 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 466 | static u64 conn_id(void) |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 467 | { |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 468 | static u64 ctr = 1; |
Miklos Szeredi | 0720b31 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 469 | return ctr++; |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 472 | static int fuse_fill_super(struct super_block *sb, void *data, int silent) |
| 473 | { |
| 474 | struct fuse_conn *fc; |
| 475 | struct inode *root; |
| 476 | struct fuse_mount_data d; |
| 477 | struct file *file; |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 478 | struct dentry *root_dentry; |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 479 | struct fuse_req *init_req; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 480 | int err; |
| 481 | |
| 482 | if (!parse_fuse_opt((char *) data, &d)) |
| 483 | return -EINVAL; |
| 484 | |
| 485 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 486 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 487 | sb->s_magic = FUSE_SUPER_MAGIC; |
| 488 | sb->s_op = &fuse_super_operations; |
| 489 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 490 | |
| 491 | file = fget(d.fd); |
| 492 | if (!file) |
| 493 | return -EINVAL; |
| 494 | |
Miklos Szeredi | 0720b31 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 495 | if (file->f_op != &fuse_dev_operations) |
| 496 | return -EINVAL; |
| 497 | |
Miklos Szeredi | 0720b31 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 498 | fc = new_conn(); |
| 499 | if (!fc) |
| 500 | return -ENOMEM; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 501 | |
Miklos Szeredi | 1e9a4ed | 2005-09-09 13:10:31 -0700 | [diff] [blame] | 502 | fc->flags = d.flags; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 503 | fc->user_id = d.user_id; |
Miklos Szeredi | 87729a5 | 2005-09-09 13:10:34 -0700 | [diff] [blame] | 504 | fc->group_id = d.group_id; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 505 | fc->max_read = d.max_read; |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 506 | |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 507 | /* Used by get_root_inode() */ |
| 508 | sb->s_fs_info = fc; |
| 509 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 510 | err = -ENOMEM; |
| 511 | root = get_root_inode(sb, d.rootmode); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 512 | if (!root) |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 513 | goto err; |
| 514 | |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 515 | root_dentry = d_alloc_root(root); |
| 516 | if (!root_dentry) { |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 517 | iput(root); |
| 518 | goto err; |
| 519 | } |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 520 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 521 | init_req = fuse_request_alloc(); |
| 522 | if (!init_req) |
| 523 | goto err_put_root; |
| 524 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 525 | mutex_lock(&fuse_mutex); |
Miklos Szeredi | 8aa09a5 | 2006-04-26 10:49:16 +0200 | [diff] [blame] | 526 | err = -EINVAL; |
| 527 | if (file->private_data) |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 528 | goto err_unlock; |
Miklos Szeredi | 8aa09a5 | 2006-04-26 10:49:16 +0200 | [diff] [blame] | 529 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 530 | fc->id = conn_id(); |
| 531 | err = fuse_ctl_add_conn(fc); |
| 532 | if (err) |
| 533 | goto err_unlock; |
| 534 | |
| 535 | list_add_tail(&fc->entry, &fuse_conn_list); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 536 | sb->s_root = root_dentry; |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 537 | fc->connected = 1; |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 538 | file->private_data = fuse_conn_get(fc); |
| 539 | mutex_unlock(&fuse_mutex); |
Miklos Szeredi | 0720b31 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 540 | /* |
| 541 | * atomic_dec_and_test() in fput() provides the necessary |
| 542 | * memory barrier for file->private_data to be visible on all |
| 543 | * CPUs after this |
| 544 | */ |
| 545 | fput(file); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 546 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 547 | fuse_send_init(fc, init_req); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 548 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 549 | return 0; |
| 550 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 551 | err_unlock: |
| 552 | mutex_unlock(&fuse_mutex); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 553 | fuse_request_free(init_req); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 554 | err_put_root: |
| 555 | dput(root_dentry); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 556 | err: |
Miklos Szeredi | 0720b31 | 2006-04-10 22:54:55 -0700 | [diff] [blame] | 557 | fput(file); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 558 | fuse_conn_put(fc); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 559 | return err; |
| 560 | } |
| 561 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 562 | static int fuse_get_sb(struct file_system_type *fs_type, |
| 563 | int flags, const char *dev_name, |
| 564 | void *raw_data, struct vfsmount *mnt) |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 565 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 566 | return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | static struct file_system_type fuse_fs_type = { |
| 570 | .owner = THIS_MODULE, |
| 571 | .name = "fuse", |
| 572 | .get_sb = fuse_get_sb, |
| 573 | .kill_sb = kill_anon_super, |
| 574 | }; |
| 575 | |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 576 | static decl_subsys(fuse, NULL, NULL); |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 577 | static decl_subsys(connections, NULL, NULL); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 578 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 579 | static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep, |
| 580 | unsigned long flags) |
| 581 | { |
| 582 | struct inode * inode = foo; |
| 583 | |
| 584 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
| 585 | SLAB_CTOR_CONSTRUCTOR) |
| 586 | inode_init_once(inode); |
| 587 | } |
| 588 | |
| 589 | static int __init fuse_fs_init(void) |
| 590 | { |
| 591 | int err; |
| 592 | |
| 593 | err = register_filesystem(&fuse_fs_type); |
| 594 | if (err) |
| 595 | printk("fuse: failed to register filesystem\n"); |
| 596 | else { |
| 597 | fuse_inode_cachep = kmem_cache_create("fuse_inode", |
| 598 | sizeof(struct fuse_inode), |
| 599 | 0, SLAB_HWCACHE_ALIGN, |
| 600 | fuse_inode_init_once, NULL); |
| 601 | if (!fuse_inode_cachep) { |
| 602 | unregister_filesystem(&fuse_fs_type); |
| 603 | err = -ENOMEM; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | return err; |
| 608 | } |
| 609 | |
| 610 | static void fuse_fs_cleanup(void) |
| 611 | { |
| 612 | unregister_filesystem(&fuse_fs_type); |
| 613 | kmem_cache_destroy(fuse_inode_cachep); |
| 614 | } |
| 615 | |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 616 | static int fuse_sysfs_init(void) |
| 617 | { |
| 618 | int err; |
| 619 | |
| 620 | kset_set_kset_s(&fuse_subsys, fs_subsys); |
| 621 | err = subsystem_register(&fuse_subsys); |
| 622 | if (err) |
| 623 | goto out_err; |
| 624 | |
| 625 | kset_set_kset_s(&connections_subsys, fuse_subsys); |
| 626 | err = subsystem_register(&connections_subsys); |
| 627 | if (err) |
| 628 | goto out_fuse_unregister; |
| 629 | |
| 630 | return 0; |
| 631 | |
| 632 | out_fuse_unregister: |
| 633 | subsystem_unregister(&fuse_subsys); |
| 634 | out_err: |
| 635 | return err; |
| 636 | } |
| 637 | |
| 638 | static void fuse_sysfs_cleanup(void) |
| 639 | { |
| 640 | subsystem_unregister(&connections_subsys); |
| 641 | subsystem_unregister(&fuse_subsys); |
| 642 | } |
| 643 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 644 | static int __init fuse_init(void) |
| 645 | { |
| 646 | int res; |
| 647 | |
| 648 | printk("fuse init (API version %i.%i)\n", |
| 649 | FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); |
| 650 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 651 | INIT_LIST_HEAD(&fuse_conn_list); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 652 | res = fuse_fs_init(); |
| 653 | if (res) |
| 654 | goto err; |
| 655 | |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 656 | res = fuse_dev_init(); |
| 657 | if (res) |
| 658 | goto err_fs_cleanup; |
| 659 | |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 660 | res = fuse_sysfs_init(); |
| 661 | if (res) |
| 662 | goto err_dev_cleanup; |
| 663 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 664 | res = fuse_ctl_init(); |
| 665 | if (res) |
| 666 | goto err_sysfs_cleanup; |
| 667 | |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 668 | return 0; |
| 669 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 670 | err_sysfs_cleanup: |
| 671 | fuse_sysfs_cleanup(); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 672 | err_dev_cleanup: |
| 673 | fuse_dev_cleanup(); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 674 | err_fs_cleanup: |
| 675 | fuse_fs_cleanup(); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 676 | err: |
| 677 | return res; |
| 678 | } |
| 679 | |
| 680 | static void __exit fuse_exit(void) |
| 681 | { |
| 682 | printk(KERN_DEBUG "fuse exit\n"); |
| 683 | |
Miklos Szeredi | bafa965 | 2006-06-25 05:48:51 -0700 | [diff] [blame^] | 684 | fuse_ctl_cleanup(); |
Miklos Szeredi | f543f25 | 2006-01-16 22:14:35 -0800 | [diff] [blame] | 685 | fuse_sysfs_cleanup(); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 686 | fuse_fs_cleanup(); |
Miklos Szeredi | 334f485 | 2005-09-09 13:10:27 -0700 | [diff] [blame] | 687 | fuse_dev_cleanup(); |
Miklos Szeredi | d8a5ba4 | 2005-09-09 13:10:26 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | module_init(fuse_init); |
| 691 | module_exit(fuse_exit); |