Commit | Line | Data |
---|---|---|
d8a5ba45 MS |
1 | /* |
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> | |
d8a5ba45 MS |
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 | spinlock_t fuse_lock; | |
26 | static kmem_cache_t *fuse_inode_cachep; | |
d8a5ba45 MS |
27 | |
28 | #define FUSE_SUPER_MAGIC 0x65735546 | |
29 | ||
30 | struct 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 | ||
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; | |
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 | ||
65 | static 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 | ||
73 | static void fuse_read_inode(struct inode *inode) | |
74 | { | |
75 | /* No op */ | |
76 | } | |
77 | ||
e5e5558e | 78 | void 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 |
91 | static 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 | ||
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); | |
e5e5558e MS |
126 | if (S_ISREG(inode->i_mode)) { |
127 | fuse_init_common(inode); | |
b6aeaded | 128 | fuse_init_file_inode(inode); |
e5e5558e MS |
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)); | |
138 | } else { | |
139 | /* Don't let user create weird files */ | |
140 | inode->i_mode = S_IFREG; | |
141 | fuse_init_common(inode); | |
b6aeaded | 142 | fuse_init_file_inode(inode); |
e5e5558e | 143 | } |
d8a5ba45 MS |
144 | } |
145 | ||
146 | static int fuse_inode_eq(struct inode *inode, void *_nodeidp) | |
147 | { | |
148 | unsigned long nodeid = *(unsigned long *) _nodeidp; | |
149 | if (get_node_id(inode) == nodeid) | |
150 | return 1; | |
151 | else | |
152 | return 0; | |
153 | } | |
154 | ||
155 | static int fuse_inode_set(struct inode *inode, void *_nodeidp) | |
156 | { | |
157 | unsigned long nodeid = *(unsigned long *) _nodeidp; | |
158 | get_fuse_inode(inode)->nodeid = nodeid; | |
159 | return 0; | |
160 | } | |
161 | ||
162 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, | |
9e6268db | 163 | int generation, struct fuse_attr *attr) |
d8a5ba45 MS |
164 | { |
165 | struct inode *inode; | |
9e6268db | 166 | struct fuse_inode *fi; |
d8a5ba45 MS |
167 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
168 | int retried = 0; | |
169 | ||
170 | retry: | |
171 | inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid); | |
172 | if (!inode) | |
173 | return NULL; | |
174 | ||
175 | if ((inode->i_state & I_NEW)) { | |
b36c31ba | 176 | inode->i_flags |= S_NOATIME|S_NOCMTIME; |
d8a5ba45 MS |
177 | inode->i_generation = generation; |
178 | inode->i_data.backing_dev_info = &fc->bdi; | |
179 | fuse_init_inode(inode, attr); | |
180 | unlock_new_inode(inode); | |
181 | } else if ((inode->i_mode ^ attr->mode) & S_IFMT) { | |
182 | BUG_ON(retried); | |
183 | /* Inode has changed type, any I/O on the old should fail */ | |
184 | make_bad_inode(inode); | |
185 | iput(inode); | |
186 | retried = 1; | |
187 | goto retry; | |
188 | } | |
189 | ||
9e6268db MS |
190 | fi = get_fuse_inode(inode); |
191 | fi->nlookup ++; | |
d8a5ba45 | 192 | fuse_change_attributes(inode, attr); |
d8a5ba45 MS |
193 | return inode; |
194 | } | |
195 | ||
196 | static void fuse_put_super(struct super_block *sb) | |
197 | { | |
198 | struct fuse_conn *fc = get_fuse_conn_super(sb); | |
199 | ||
1e9a4ed9 MS |
200 | down_write(&fc->sbput_sem); |
201 | while (!list_empty(&fc->background)) | |
202 | fuse_release_background(list_entry(fc->background.next, | |
203 | struct fuse_req, bg_entry)); | |
204 | ||
d8a5ba45 | 205 | spin_lock(&fuse_lock); |
1e9a4ed9 | 206 | fc->mounted = 0; |
d8a5ba45 | 207 | fc->user_id = 0; |
87729a55 | 208 | fc->group_id = 0; |
1e9a4ed9 | 209 | fc->flags = 0; |
334f485d MS |
210 | /* Flush all readers on this fs */ |
211 | wake_up_all(&fc->waitq); | |
1e9a4ed9 | 212 | up_write(&fc->sbput_sem); |
d8a5ba45 | 213 | fuse_release_conn(fc); |
d8a5ba45 MS |
214 | spin_unlock(&fuse_lock); |
215 | } | |
216 | ||
e5e5558e MS |
217 | static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr) |
218 | { | |
219 | stbuf->f_type = FUSE_SUPER_MAGIC; | |
220 | stbuf->f_bsize = attr->bsize; | |
de5f1202 | 221 | stbuf->f_frsize = attr->frsize; |
e5e5558e MS |
222 | stbuf->f_blocks = attr->blocks; |
223 | stbuf->f_bfree = attr->bfree; | |
224 | stbuf->f_bavail = attr->bavail; | |
225 | stbuf->f_files = attr->files; | |
226 | stbuf->f_ffree = attr->ffree; | |
227 | stbuf->f_namelen = attr->namelen; | |
228 | /* fsid is left zero */ | |
229 | } | |
230 | ||
231 | static int fuse_statfs(struct super_block *sb, struct kstatfs *buf) | |
232 | { | |
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 | ||
238 | req = fuse_get_request(fc); | |
239 | if (!req) | |
7c352bdf | 240 | return -EINTR; |
e5e5558e | 241 | |
de5f1202 | 242 | memset(&outarg, 0, sizeof(outarg)); |
e5e5558e MS |
243 | req->in.numargs = 0; |
244 | req->in.h.opcode = FUSE_STATFS; | |
245 | req->out.numargs = 1; | |
de5f1202 MS |
246 | req->out.args[0].size = |
247 | fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg); | |
e5e5558e MS |
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 | ||
d8a5ba45 MS |
257 | enum { |
258 | OPT_FD, | |
259 | OPT_ROOTMODE, | |
260 | OPT_USER_ID, | |
87729a55 | 261 | OPT_GROUP_ID, |
d8a5ba45 MS |
262 | OPT_DEFAULT_PERMISSIONS, |
263 | OPT_ALLOW_OTHER, | |
db50b96c | 264 | OPT_MAX_READ, |
d8a5ba45 MS |
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"}, | |
87729a55 | 272 | {OPT_GROUP_ID, "group_id=%u"}, |
d8a5ba45 MS |
273 | {OPT_DEFAULT_PERMISSIONS, "default_permissions"}, |
274 | {OPT_ALLOW_OTHER, "allow_other"}, | |
db50b96c | 275 | {OPT_MAX_READ, "max_read=%u"}, |
d8a5ba45 MS |
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)); | |
db50b96c | 283 | d->max_read = ~0; |
d8a5ba45 MS |
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; | |
5a533682 | 298 | d->fd_present = 1; |
d8a5ba45 MS |
299 | break; |
300 | ||
301 | case OPT_ROOTMODE: | |
302 | if (match_octal(&args[0], &value)) | |
303 | return 0; | |
304 | d->rootmode = value; | |
5a533682 | 305 | d->rootmode_present = 1; |
d8a5ba45 MS |
306 | break; |
307 | ||
308 | case OPT_USER_ID: | |
309 | if (match_int(&args[0], &value)) | |
310 | return 0; | |
311 | d->user_id = value; | |
5a533682 | 312 | d->user_id_present = 1; |
d8a5ba45 MS |
313 | break; |
314 | ||
87729a55 MS |
315 | case OPT_GROUP_ID: |
316 | if (match_int(&args[0], &value)) | |
317 | return 0; | |
318 | d->group_id = value; | |
5a533682 | 319 | d->group_id_present = 1; |
87729a55 MS |
320 | break; |
321 | ||
1e9a4ed9 MS |
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 | ||
db50b96c MS |
330 | case OPT_MAX_READ: |
331 | if (match_int(&args[0], &value)) | |
332 | return 0; | |
333 | d->max_read = value; | |
334 | break; | |
335 | ||
d8a5ba45 MS |
336 | default: |
337 | return 0; | |
338 | } | |
339 | } | |
5a533682 MS |
340 | |
341 | if (!d->fd_present || !d->rootmode_present || | |
342 | !d->user_id_present || !d->group_id_present) | |
d8a5ba45 MS |
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); | |
87729a55 | 353 | seq_printf(m, ",group_id=%u", fc->group_id); |
1e9a4ed9 MS |
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"); | |
db50b96c MS |
358 | if (fc->max_read != ~0) |
359 | seq_printf(m, ",max_read=%u", fc->max_read); | |
d8a5ba45 MS |
360 | return 0; |
361 | } | |
362 | ||
334f485d | 363 | static void free_conn(struct fuse_conn *fc) |
d8a5ba45 | 364 | { |
334f485d MS |
365 | while (!list_empty(&fc->unused_list)) { |
366 | struct fuse_req *req; | |
367 | req = list_entry(fc->unused_list.next, struct fuse_req, list); | |
368 | list_del(&req->list); | |
369 | fuse_request_free(req); | |
370 | } | |
d8a5ba45 MS |
371 | kfree(fc); |
372 | } | |
373 | ||
334f485d MS |
374 | /* Must be called with the fuse lock held */ |
375 | void fuse_release_conn(struct fuse_conn *fc) | |
376 | { | |
1e9a4ed9 MS |
377 | fc->count--; |
378 | if (!fc->count) | |
334f485d MS |
379 | free_conn(fc); |
380 | } | |
381 | ||
d8a5ba45 MS |
382 | static struct fuse_conn *new_conn(void) |
383 | { | |
384 | struct fuse_conn *fc; | |
385 | ||
386 | fc = kmalloc(sizeof(*fc), GFP_KERNEL); | |
387 | if (fc != NULL) { | |
334f485d | 388 | int i; |
d8a5ba45 | 389 | memset(fc, 0, sizeof(*fc)); |
334f485d MS |
390 | init_waitqueue_head(&fc->waitq); |
391 | INIT_LIST_HEAD(&fc->pending); | |
392 | INIT_LIST_HEAD(&fc->processing); | |
393 | INIT_LIST_HEAD(&fc->unused_list); | |
1e9a4ed9 | 394 | INIT_LIST_HEAD(&fc->background); |
334f485d | 395 | sema_init(&fc->outstanding_sem, 0); |
1e9a4ed9 | 396 | init_rwsem(&fc->sbput_sem); |
334f485d MS |
397 | for (i = 0; i < FUSE_MAX_OUTSTANDING; i++) { |
398 | struct fuse_req *req = fuse_request_alloc(); | |
399 | if (!req) { | |
400 | free_conn(fc); | |
401 | return NULL; | |
402 | } | |
403 | list_add(&req->list, &fc->unused_list); | |
404 | } | |
d8a5ba45 MS |
405 | fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; |
406 | fc->bdi.unplug_io_fn = default_unplug_io_fn; | |
334f485d | 407 | fc->reqctr = 0; |
d8a5ba45 MS |
408 | } |
409 | return fc; | |
410 | } | |
411 | ||
412 | static struct fuse_conn *get_conn(struct file *file, struct super_block *sb) | |
413 | { | |
414 | struct fuse_conn *fc; | |
415 | ||
334f485d MS |
416 | if (file->f_op != &fuse_dev_operations) |
417 | return ERR_PTR(-EINVAL); | |
d8a5ba45 MS |
418 | fc = new_conn(); |
419 | if (fc == NULL) | |
334f485d | 420 | return ERR_PTR(-ENOMEM); |
d8a5ba45 | 421 | spin_lock(&fuse_lock); |
334f485d MS |
422 | if (file->private_data) { |
423 | free_conn(fc); | |
424 | fc = ERR_PTR(-EINVAL); | |
425 | } else { | |
426 | file->private_data = fc; | |
1e9a4ed9 MS |
427 | *get_fuse_conn_super_p(sb) = fc; |
428 | fc->mounted = 1; | |
429 | fc->connected = 1; | |
430 | fc->count = 2; | |
334f485d | 431 | } |
d8a5ba45 MS |
432 | spin_unlock(&fuse_lock); |
433 | return fc; | |
434 | } | |
435 | ||
436 | static struct inode *get_root_inode(struct super_block *sb, unsigned mode) | |
437 | { | |
438 | struct fuse_attr attr; | |
439 | memset(&attr, 0, sizeof(attr)); | |
440 | ||
441 | attr.mode = mode; | |
442 | attr.ino = FUSE_ROOT_ID; | |
9e6268db | 443 | return fuse_iget(sb, 1, 0, &attr); |
d8a5ba45 MS |
444 | } |
445 | ||
446 | static struct super_operations fuse_super_operations = { | |
447 | .alloc_inode = fuse_alloc_inode, | |
448 | .destroy_inode = fuse_destroy_inode, | |
449 | .read_inode = fuse_read_inode, | |
450 | .clear_inode = fuse_clear_inode, | |
451 | .put_super = fuse_put_super, | |
e5e5558e | 452 | .statfs = fuse_statfs, |
d8a5ba45 MS |
453 | .show_options = fuse_show_options, |
454 | }; | |
455 | ||
d8a5ba45 MS |
456 | static int fuse_fill_super(struct super_block *sb, void *data, int silent) |
457 | { | |
458 | struct fuse_conn *fc; | |
459 | struct inode *root; | |
460 | struct fuse_mount_data d; | |
461 | struct file *file; | |
462 | int err; | |
463 | ||
464 | if (!parse_fuse_opt((char *) data, &d)) | |
465 | return -EINVAL; | |
466 | ||
467 | sb->s_blocksize = PAGE_CACHE_SIZE; | |
468 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; | |
469 | sb->s_magic = FUSE_SUPER_MAGIC; | |
470 | sb->s_op = &fuse_super_operations; | |
471 | sb->s_maxbytes = MAX_LFS_FILESIZE; | |
472 | ||
473 | file = fget(d.fd); | |
474 | if (!file) | |
475 | return -EINVAL; | |
476 | ||
477 | fc = get_conn(file, sb); | |
478 | fput(file); | |
334f485d MS |
479 | if (IS_ERR(fc)) |
480 | return PTR_ERR(fc); | |
d8a5ba45 | 481 | |
1e9a4ed9 | 482 | fc->flags = d.flags; |
d8a5ba45 | 483 | fc->user_id = d.user_id; |
87729a55 | 484 | fc->group_id = d.group_id; |
db50b96c MS |
485 | fc->max_read = d.max_read; |
486 | if (fc->max_read / PAGE_CACHE_SIZE < fc->bdi.ra_pages) | |
487 | fc->bdi.ra_pages = fc->max_read / PAGE_CACHE_SIZE; | |
d8a5ba45 | 488 | |
d8a5ba45 MS |
489 | err = -ENOMEM; |
490 | root = get_root_inode(sb, d.rootmode); | |
491 | if (root == NULL) | |
492 | goto err; | |
493 | ||
494 | sb->s_root = d_alloc_root(root); | |
495 | if (!sb->s_root) { | |
496 | iput(root); | |
497 | goto err; | |
498 | } | |
334f485d | 499 | fuse_send_init(fc); |
d8a5ba45 MS |
500 | return 0; |
501 | ||
502 | err: | |
503 | spin_lock(&fuse_lock); | |
d8a5ba45 MS |
504 | fuse_release_conn(fc); |
505 | spin_unlock(&fuse_lock); | |
d8a5ba45 MS |
506 | return err; |
507 | } | |
508 | ||
509 | static struct super_block *fuse_get_sb(struct file_system_type *fs_type, | |
510 | int flags, const char *dev_name, | |
511 | void *raw_data) | |
512 | { | |
513 | return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super); | |
514 | } | |
515 | ||
516 | static struct file_system_type fuse_fs_type = { | |
517 | .owner = THIS_MODULE, | |
518 | .name = "fuse", | |
519 | .get_sb = fuse_get_sb, | |
520 | .kill_sb = kill_anon_super, | |
521 | }; | |
522 | ||
523 | static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep, | |
524 | unsigned long flags) | |
525 | { | |
526 | struct inode * inode = foo; | |
527 | ||
528 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == | |
529 | SLAB_CTOR_CONSTRUCTOR) | |
530 | inode_init_once(inode); | |
531 | } | |
532 | ||
533 | static int __init fuse_fs_init(void) | |
534 | { | |
535 | int err; | |
536 | ||
537 | err = register_filesystem(&fuse_fs_type); | |
538 | if (err) | |
539 | printk("fuse: failed to register filesystem\n"); | |
540 | else { | |
541 | fuse_inode_cachep = kmem_cache_create("fuse_inode", | |
542 | sizeof(struct fuse_inode), | |
543 | 0, SLAB_HWCACHE_ALIGN, | |
544 | fuse_inode_init_once, NULL); | |
545 | if (!fuse_inode_cachep) { | |
546 | unregister_filesystem(&fuse_fs_type); | |
547 | err = -ENOMEM; | |
548 | } | |
549 | } | |
550 | ||
551 | return err; | |
552 | } | |
553 | ||
554 | static void fuse_fs_cleanup(void) | |
555 | { | |
556 | unregister_filesystem(&fuse_fs_type); | |
557 | kmem_cache_destroy(fuse_inode_cachep); | |
558 | } | |
559 | ||
560 | static int __init fuse_init(void) | |
561 | { | |
562 | int res; | |
563 | ||
564 | printk("fuse init (API version %i.%i)\n", | |
565 | FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); | |
566 | ||
567 | spin_lock_init(&fuse_lock); | |
568 | res = fuse_fs_init(); | |
569 | if (res) | |
570 | goto err; | |
571 | ||
334f485d MS |
572 | res = fuse_dev_init(); |
573 | if (res) | |
574 | goto err_fs_cleanup; | |
575 | ||
d8a5ba45 MS |
576 | return 0; |
577 | ||
334f485d MS |
578 | err_fs_cleanup: |
579 | fuse_fs_cleanup(); | |
d8a5ba45 MS |
580 | err: |
581 | return res; | |
582 | } | |
583 | ||
584 | static void __exit fuse_exit(void) | |
585 | { | |
586 | printk(KERN_DEBUG "fuse exit\n"); | |
587 | ||
588 | fuse_fs_cleanup(); | |
334f485d | 589 | fuse_dev_cleanup(); |
d8a5ba45 MS |
590 | } |
591 | ||
592 | module_init(fuse_init); | |
593 | module_exit(fuse_exit); |