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