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