blob: 0b75c73386e9733b8e0182c4c76b8c94c31672f7 [file] [log] [blame]
Miklos Szeredid8a5ba42005-09-09 13:10:26 -07001/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 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>
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070018#include <linux/parser.h>
19#include <linux/statfs.h>
20
21MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
22MODULE_DESCRIPTION("Filesystem in Userspace");
23MODULE_LICENSE("GPL");
24
25spinlock_t fuse_lock;
26static kmem_cache_t *fuse_inode_cachep;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070027
28#define FUSE_SUPER_MAGIC 0x65735546
29
30struct fuse_mount_data {
31 int fd;
32 unsigned rootmode;
33 unsigned user_id;
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -070034 unsigned flags;
Miklos Szeredidb50b962005-09-09 13:10:33 -070035 unsigned max_read;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070036};
37
38static struct inode *fuse_alloc_inode(struct super_block *sb)
39{
40 struct inode *inode;
41 struct fuse_inode *fi;
42
43 inode = kmem_cache_alloc(fuse_inode_cachep, SLAB_KERNEL);
44 if (!inode)
45 return NULL;
46
47 fi = get_fuse_inode(inode);
48 fi->i_time = jiffies - 1;
49 fi->nodeid = 0;
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070050 fi->nlookup = 0;
Miklos Szeredie5e55582005-09-09 13:10:28 -070051 fi->forget_req = fuse_request_alloc();
52 if (!fi->forget_req) {
53 kmem_cache_free(fuse_inode_cachep, inode);
54 return NULL;
55 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070056
57 return inode;
58}
59
60static void fuse_destroy_inode(struct inode *inode)
61{
Miklos Szeredie5e55582005-09-09 13:10:28 -070062 struct fuse_inode *fi = get_fuse_inode(inode);
63 if (fi->forget_req)
64 fuse_request_free(fi->forget_req);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070065 kmem_cache_free(fuse_inode_cachep, inode);
66}
67
68static void fuse_read_inode(struct inode *inode)
69{
70 /* No op */
71}
72
Miklos Szeredie5e55582005-09-09 13:10:28 -070073void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070074 unsigned long nodeid, u64 nlookup)
Miklos Szeredie5e55582005-09-09 13:10:28 -070075{
76 struct fuse_forget_in *inarg = &req->misc.forget_in;
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070077 inarg->nlookup = nlookup;
Miklos Szeredie5e55582005-09-09 13:10:28 -070078 req->in.h.opcode = FUSE_FORGET;
79 req->in.h.nodeid = nodeid;
80 req->in.numargs = 1;
81 req->in.args[0].size = sizeof(struct fuse_forget_in);
82 req->in.args[0].value = inarg;
83 request_send_noreply(fc, req);
84}
85
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070086static void fuse_clear_inode(struct inode *inode)
87{
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -070088 if (inode->i_sb->s_flags & MS_ACTIVE) {
89 struct fuse_conn *fc = get_fuse_conn(inode);
Miklos Szeredie5e55582005-09-09 13:10:28 -070090 struct fuse_inode *fi = get_fuse_inode(inode);
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070091 fuse_send_forget(fc, fi->forget_req, fi->nodeid, fi->nlookup);
Miklos Szeredie5e55582005-09-09 13:10:28 -070092 fi->forget_req = NULL;
93 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070094}
95
96void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
97{
98 if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size)
99 invalidate_inode_pages(inode->i_mapping);
100
101 inode->i_ino = attr->ino;
102 inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777);
103 inode->i_nlink = attr->nlink;
104 inode->i_uid = attr->uid;
105 inode->i_gid = attr->gid;
106 i_size_write(inode, attr->size);
107 inode->i_blksize = PAGE_CACHE_SIZE;
108 inode->i_blocks = attr->blocks;
109 inode->i_atime.tv_sec = attr->atime;
110 inode->i_atime.tv_nsec = attr->atimensec;
111 inode->i_mtime.tv_sec = attr->mtime;
112 inode->i_mtime.tv_nsec = attr->mtimensec;
113 inode->i_ctime.tv_sec = attr->ctime;
114 inode->i_ctime.tv_nsec = attr->ctimensec;
115}
116
117static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
118{
119 inode->i_mode = attr->mode & S_IFMT;
120 i_size_write(inode, attr->size);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700121 if (S_ISREG(inode->i_mode)) {
122 fuse_init_common(inode);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700123 fuse_init_file_inode(inode);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700124 } else if (S_ISDIR(inode->i_mode))
125 fuse_init_dir(inode);
126 else if (S_ISLNK(inode->i_mode))
127 fuse_init_symlink(inode);
128 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
129 S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
130 fuse_init_common(inode);
131 init_special_inode(inode, inode->i_mode,
132 new_decode_dev(attr->rdev));
133 } else {
134 /* Don't let user create weird files */
135 inode->i_mode = S_IFREG;
136 fuse_init_common(inode);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700137 fuse_init_file_inode(inode);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700138 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700139}
140
141static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
142{
143 unsigned long nodeid = *(unsigned long *) _nodeidp;
144 if (get_node_id(inode) == nodeid)
145 return 1;
146 else
147 return 0;
148}
149
150static int fuse_inode_set(struct inode *inode, void *_nodeidp)
151{
152 unsigned long nodeid = *(unsigned long *) _nodeidp;
153 get_fuse_inode(inode)->nodeid = nodeid;
154 return 0;
155}
156
157struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
Miklos Szeredi9e6268d2005-09-09 13:10:29 -0700158 int generation, struct fuse_attr *attr)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700159{
160 struct inode *inode;
Miklos Szeredi9e6268d2005-09-09 13:10:29 -0700161 struct fuse_inode *fi;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700162 struct fuse_conn *fc = get_fuse_conn_super(sb);
163 int retried = 0;
164
165 retry:
166 inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid);
167 if (!inode)
168 return NULL;
169
170 if ((inode->i_state & I_NEW)) {
171 inode->i_generation = generation;
172 inode->i_data.backing_dev_info = &fc->bdi;
173 fuse_init_inode(inode, attr);
174 unlock_new_inode(inode);
175 } else if ((inode->i_mode ^ attr->mode) & S_IFMT) {
176 BUG_ON(retried);
177 /* Inode has changed type, any I/O on the old should fail */
178 make_bad_inode(inode);
179 iput(inode);
180 retried = 1;
181 goto retry;
182 }
183
Miklos Szeredi9e6268d2005-09-09 13:10:29 -0700184 fi = get_fuse_inode(inode);
185 fi->nlookup ++;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700186 fuse_change_attributes(inode, attr);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700187 return inode;
188}
189
190static void fuse_put_super(struct super_block *sb)
191{
192 struct fuse_conn *fc = get_fuse_conn_super(sb);
193
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700194 down_write(&fc->sbput_sem);
195 while (!list_empty(&fc->background))
196 fuse_release_background(list_entry(fc->background.next,
197 struct fuse_req, bg_entry));
198
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700199 spin_lock(&fuse_lock);
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700200 fc->mounted = 0;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700201 fc->user_id = 0;
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700202 fc->flags = 0;
Miklos Szeredi334f4852005-09-09 13:10:27 -0700203 /* Flush all readers on this fs */
204 wake_up_all(&fc->waitq);
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700205 up_write(&fc->sbput_sem);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700206 fuse_release_conn(fc);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700207 spin_unlock(&fuse_lock);
208}
209
Miklos Szeredie5e55582005-09-09 13:10:28 -0700210static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
211{
212 stbuf->f_type = FUSE_SUPER_MAGIC;
213 stbuf->f_bsize = attr->bsize;
214 stbuf->f_blocks = attr->blocks;
215 stbuf->f_bfree = attr->bfree;
216 stbuf->f_bavail = attr->bavail;
217 stbuf->f_files = attr->files;
218 stbuf->f_ffree = attr->ffree;
219 stbuf->f_namelen = attr->namelen;
220 /* fsid is left zero */
221}
222
223static int fuse_statfs(struct super_block *sb, struct kstatfs *buf)
224{
225 struct fuse_conn *fc = get_fuse_conn_super(sb);
226 struct fuse_req *req;
227 struct fuse_statfs_out outarg;
228 int err;
229
230 req = fuse_get_request(fc);
231 if (!req)
232 return -ERESTARTSYS;
233
234 req->in.numargs = 0;
235 req->in.h.opcode = FUSE_STATFS;
236 req->out.numargs = 1;
237 req->out.args[0].size = sizeof(outarg);
238 req->out.args[0].value = &outarg;
239 request_send(fc, req);
240 err = req->out.h.error;
241 if (!err)
242 convert_fuse_statfs(buf, &outarg.st);
243 fuse_put_request(fc, req);
244 return err;
245}
246
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700247enum {
248 OPT_FD,
249 OPT_ROOTMODE,
250 OPT_USER_ID,
251 OPT_DEFAULT_PERMISSIONS,
252 OPT_ALLOW_OTHER,
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700253 OPT_KERNEL_CACHE,
Miklos Szeredidb50b962005-09-09 13:10:33 -0700254 OPT_MAX_READ,
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700255 OPT_ERR
256};
257
258static match_table_t tokens = {
259 {OPT_FD, "fd=%u"},
260 {OPT_ROOTMODE, "rootmode=%o"},
261 {OPT_USER_ID, "user_id=%u"},
262 {OPT_DEFAULT_PERMISSIONS, "default_permissions"},
263 {OPT_ALLOW_OTHER, "allow_other"},
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700264 {OPT_KERNEL_CACHE, "kernel_cache"},
Miklos Szeredidb50b962005-09-09 13:10:33 -0700265 {OPT_MAX_READ, "max_read=%u"},
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700266 {OPT_ERR, NULL}
267};
268
269static int parse_fuse_opt(char *opt, struct fuse_mount_data *d)
270{
271 char *p;
272 memset(d, 0, sizeof(struct fuse_mount_data));
273 d->fd = -1;
Miklos Szeredidb50b962005-09-09 13:10:33 -0700274 d->max_read = ~0;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700275
276 while ((p = strsep(&opt, ",")) != NULL) {
277 int token;
278 int value;
279 substring_t args[MAX_OPT_ARGS];
280 if (!*p)
281 continue;
282
283 token = match_token(p, tokens, args);
284 switch (token) {
285 case OPT_FD:
286 if (match_int(&args[0], &value))
287 return 0;
288 d->fd = value;
289 break;
290
291 case OPT_ROOTMODE:
292 if (match_octal(&args[0], &value))
293 return 0;
294 d->rootmode = value;
295 break;
296
297 case OPT_USER_ID:
298 if (match_int(&args[0], &value))
299 return 0;
300 d->user_id = value;
301 break;
302
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700303 case OPT_DEFAULT_PERMISSIONS:
304 d->flags |= FUSE_DEFAULT_PERMISSIONS;
305 break;
306
307 case OPT_ALLOW_OTHER:
308 d->flags |= FUSE_ALLOW_OTHER;
309 break;
310
311 case OPT_KERNEL_CACHE:
312 d->flags |= FUSE_KERNEL_CACHE;
313 break;
314
Miklos Szeredidb50b962005-09-09 13:10:33 -0700315 case OPT_MAX_READ:
316 if (match_int(&args[0], &value))
317 return 0;
318 d->max_read = value;
319 break;
320
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700321 default:
322 return 0;
323 }
324 }
325 if (d->fd == -1)
326 return 0;
327
328 return 1;
329}
330
331static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
332{
333 struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb);
334
335 seq_printf(m, ",user_id=%u", fc->user_id);
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700336 if (fc->flags & FUSE_DEFAULT_PERMISSIONS)
337 seq_puts(m, ",default_permissions");
338 if (fc->flags & FUSE_ALLOW_OTHER)
339 seq_puts(m, ",allow_other");
340 if (fc->flags & FUSE_KERNEL_CACHE)
341 seq_puts(m, ",kernel_cache");
Miklos Szeredidb50b962005-09-09 13:10:33 -0700342 if (fc->max_read != ~0)
343 seq_printf(m, ",max_read=%u", fc->max_read);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700344 return 0;
345}
346
Miklos Szeredi334f4852005-09-09 13:10:27 -0700347static void free_conn(struct fuse_conn *fc)
348{
349 while (!list_empty(&fc->unused_list)) {
350 struct fuse_req *req;
351 req = list_entry(fc->unused_list.next, struct fuse_req, list);
352 list_del(&req->list);
353 fuse_request_free(req);
354 }
355 kfree(fc);
356}
357
358/* Must be called with the fuse lock held */
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700359void fuse_release_conn(struct fuse_conn *fc)
360{
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700361 fc->count--;
362 if (!fc->count)
Miklos Szeredi334f4852005-09-09 13:10:27 -0700363 free_conn(fc);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700364}
365
366static struct fuse_conn *new_conn(void)
367{
368 struct fuse_conn *fc;
369
370 fc = kmalloc(sizeof(*fc), GFP_KERNEL);
371 if (fc != NULL) {
Miklos Szeredi334f4852005-09-09 13:10:27 -0700372 int i;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700373 memset(fc, 0, sizeof(*fc));
Miklos Szeredi334f4852005-09-09 13:10:27 -0700374 init_waitqueue_head(&fc->waitq);
375 INIT_LIST_HEAD(&fc->pending);
376 INIT_LIST_HEAD(&fc->processing);
377 INIT_LIST_HEAD(&fc->unused_list);
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700378 INIT_LIST_HEAD(&fc->background);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700379 sema_init(&fc->outstanding_sem, 0);
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700380 init_rwsem(&fc->sbput_sem);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700381 for (i = 0; i < FUSE_MAX_OUTSTANDING; i++) {
382 struct fuse_req *req = fuse_request_alloc();
383 if (!req) {
384 free_conn(fc);
385 return NULL;
386 }
387 list_add(&req->list, &fc->unused_list);
388 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700389 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
390 fc->bdi.unplug_io_fn = default_unplug_io_fn;
Miklos Szeredi334f4852005-09-09 13:10:27 -0700391 fc->reqctr = 0;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700392 }
393 return fc;
394}
395
396static struct fuse_conn *get_conn(struct file *file, struct super_block *sb)
397{
398 struct fuse_conn *fc;
399
Miklos Szeredi334f4852005-09-09 13:10:27 -0700400 if (file->f_op != &fuse_dev_operations)
401 return ERR_PTR(-EINVAL);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700402 fc = new_conn();
403 if (fc == NULL)
Miklos Szeredi334f4852005-09-09 13:10:27 -0700404 return ERR_PTR(-ENOMEM);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700405 spin_lock(&fuse_lock);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700406 if (file->private_data) {
407 free_conn(fc);
408 fc = ERR_PTR(-EINVAL);
409 } else {
410 file->private_data = fc;
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700411 *get_fuse_conn_super_p(sb) = fc;
412 fc->mounted = 1;
413 fc->connected = 1;
414 fc->count = 2;
Miklos Szeredi334f4852005-09-09 13:10:27 -0700415 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700416 spin_unlock(&fuse_lock);
417 return fc;
418}
419
420static struct inode *get_root_inode(struct super_block *sb, unsigned mode)
421{
422 struct fuse_attr attr;
423 memset(&attr, 0, sizeof(attr));
424
425 attr.mode = mode;
426 attr.ino = FUSE_ROOT_ID;
Miklos Szeredi9e6268d2005-09-09 13:10:29 -0700427 return fuse_iget(sb, 1, 0, &attr);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700428}
429
430static struct super_operations fuse_super_operations = {
431 .alloc_inode = fuse_alloc_inode,
432 .destroy_inode = fuse_destroy_inode,
433 .read_inode = fuse_read_inode,
434 .clear_inode = fuse_clear_inode,
435 .put_super = fuse_put_super,
Miklos Szeredie5e55582005-09-09 13:10:28 -0700436 .statfs = fuse_statfs,
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700437 .show_options = fuse_show_options,
438};
439
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700440static int fuse_fill_super(struct super_block *sb, void *data, int silent)
441{
442 struct fuse_conn *fc;
443 struct inode *root;
444 struct fuse_mount_data d;
445 struct file *file;
446 int err;
447
448 if (!parse_fuse_opt((char *) data, &d))
449 return -EINVAL;
450
451 sb->s_blocksize = PAGE_CACHE_SIZE;
452 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
453 sb->s_magic = FUSE_SUPER_MAGIC;
454 sb->s_op = &fuse_super_operations;
455 sb->s_maxbytes = MAX_LFS_FILESIZE;
456
457 file = fget(d.fd);
458 if (!file)
459 return -EINVAL;
460
461 fc = get_conn(file, sb);
462 fput(file);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700463 if (IS_ERR(fc))
464 return PTR_ERR(fc);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700465
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700466 fc->flags = d.flags;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700467 fc->user_id = d.user_id;
Miklos Szeredidb50b962005-09-09 13:10:33 -0700468 fc->max_read = d.max_read;
469 if (fc->max_read / PAGE_CACHE_SIZE < fc->bdi.ra_pages)
470 fc->bdi.ra_pages = fc->max_read / PAGE_CACHE_SIZE;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700471
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700472 err = -ENOMEM;
473 root = get_root_inode(sb, d.rootmode);
474 if (root == NULL)
475 goto err;
476
477 sb->s_root = d_alloc_root(root);
478 if (!sb->s_root) {
479 iput(root);
480 goto err;
481 }
Miklos Szeredi334f4852005-09-09 13:10:27 -0700482 fuse_send_init(fc);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700483 return 0;
484
485 err:
486 spin_lock(&fuse_lock);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700487 fuse_release_conn(fc);
488 spin_unlock(&fuse_lock);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700489 return err;
490}
491
492static struct super_block *fuse_get_sb(struct file_system_type *fs_type,
493 int flags, const char *dev_name,
494 void *raw_data)
495{
496 return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super);
497}
498
499static struct file_system_type fuse_fs_type = {
500 .owner = THIS_MODULE,
501 .name = "fuse",
502 .get_sb = fuse_get_sb,
503 .kill_sb = kill_anon_super,
504};
505
506static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep,
507 unsigned long flags)
508{
509 struct inode * inode = foo;
510
511 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
512 SLAB_CTOR_CONSTRUCTOR)
513 inode_init_once(inode);
514}
515
516static int __init fuse_fs_init(void)
517{
518 int err;
519
520 err = register_filesystem(&fuse_fs_type);
521 if (err)
522 printk("fuse: failed to register filesystem\n");
523 else {
524 fuse_inode_cachep = kmem_cache_create("fuse_inode",
525 sizeof(struct fuse_inode),
526 0, SLAB_HWCACHE_ALIGN,
527 fuse_inode_init_once, NULL);
528 if (!fuse_inode_cachep) {
529 unregister_filesystem(&fuse_fs_type);
530 err = -ENOMEM;
531 }
532 }
533
534 return err;
535}
536
537static void fuse_fs_cleanup(void)
538{
539 unregister_filesystem(&fuse_fs_type);
540 kmem_cache_destroy(fuse_inode_cachep);
541}
542
543static int __init fuse_init(void)
544{
545 int res;
546
547 printk("fuse init (API version %i.%i)\n",
548 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
549
550 spin_lock_init(&fuse_lock);
551 res = fuse_fs_init();
552 if (res)
553 goto err;
554
Miklos Szeredi334f4852005-09-09 13:10:27 -0700555 res = fuse_dev_init();
556 if (res)
557 goto err_fs_cleanup;
558
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700559 return 0;
560
Miklos Szeredi334f4852005-09-09 13:10:27 -0700561 err_fs_cleanup:
562 fuse_fs_cleanup();
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700563 err:
564 return res;
565}
566
567static void __exit fuse_exit(void)
568{
569 printk(KERN_DEBUG "fuse exit\n");
570
571 fuse_fs_cleanup();
Miklos Szeredi334f4852005-09-09 13:10:27 -0700572 fuse_dev_cleanup();
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700573}
574
575module_init(fuse_init);
576module_exit(fuse_exit);