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