blob: 2167fc4fcab809af4d9ca72dd00a98974708b9e4 [file] [log] [blame]
Miklos Szeredid8a5ba42005-09-09 13:10:26 -07001/*
2 FUSE: Filesystem in Userspace
Miklos Szeredid7133112006-04-10 22:54:55 -07003 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
Miklos Szeredid8a5ba42005-09-09 13:10:26 -07004
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>
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070014#include <linux/seq_file.h>
15#include <linux/init.h>
16#include <linux/module.h>
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070017#include <linux/parser.h>
18#include <linux/statfs.h>
Miklos Szeredi9c8ef562006-06-25 05:48:55 -070019#include <linux/random.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040020#include <linux/sched.h>
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070021
22MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
23MODULE_DESCRIPTION("Filesystem in Userspace");
24MODULE_LICENSE("GPL");
25
Christoph Lametere18b8902006-12-06 20:33:20 -080026static struct kmem_cache *fuse_inode_cachep;
Miklos Szeredibafa9652006-06-25 05:48:51 -070027struct list_head fuse_conn_list;
28DEFINE_MUTEX(fuse_mutex);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070029
30#define FUSE_SUPER_MAGIC 0x65735546
31
32struct fuse_mount_data {
33 int fd;
34 unsigned rootmode;
35 unsigned user_id;
Miklos Szeredi87729a52005-09-09 13:10:34 -070036 unsigned group_id;
Miklos Szeredi5a533682005-09-09 13:10:34 -070037 unsigned fd_present : 1;
38 unsigned rootmode_present : 1;
39 unsigned user_id_present : 1;
40 unsigned group_id_present : 1;
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -070041 unsigned flags;
Miklos Szeredidb50b962005-09-09 13:10:33 -070042 unsigned max_read;
Miklos Szeredid8091612006-12-06 20:35:48 -080043 unsigned blksize;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070044};
45
46static struct inode *fuse_alloc_inode(struct super_block *sb)
47{
48 struct inode *inode;
49 struct fuse_inode *fi;
50
Christoph Lametere94b1762006-12-06 20:33:17 -080051 inode = kmem_cache_alloc(fuse_inode_cachep, GFP_KERNEL);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070052 if (!inode)
53 return NULL;
54
55 fi = get_fuse_inode(inode);
Miklos Szeredi0a0898c2006-07-30 03:04:10 -070056 fi->i_time = 0;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070057 fi->nodeid = 0;
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070058 fi->nlookup = 0;
Miklos Szeredie5e55582005-09-09 13:10:28 -070059 fi->forget_req = fuse_request_alloc();
60 if (!fi->forget_req) {
61 kmem_cache_free(fuse_inode_cachep, inode);
62 return NULL;
63 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070064
65 return inode;
66}
67
68static void fuse_destroy_inode(struct inode *inode)
69{
Miklos Szeredie5e55582005-09-09 13:10:28 -070070 struct fuse_inode *fi = get_fuse_inode(inode);
71 if (fi->forget_req)
72 fuse_request_free(fi->forget_req);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070073 kmem_cache_free(fuse_inode_cachep, inode);
74}
75
76static void fuse_read_inode(struct inode *inode)
77{
78 /* No op */
79}
80
Miklos Szeredie5e55582005-09-09 13:10:28 -070081void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070082 unsigned long nodeid, u64 nlookup)
Miklos Szeredie5e55582005-09-09 13:10:28 -070083{
84 struct fuse_forget_in *inarg = &req->misc.forget_in;
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070085 inarg->nlookup = nlookup;
Miklos Szeredie5e55582005-09-09 13:10:28 -070086 req->in.h.opcode = FUSE_FORGET;
87 req->in.h.nodeid = nodeid;
88 req->in.numargs = 1;
89 req->in.args[0].size = sizeof(struct fuse_forget_in);
90 req->in.args[0].value = inarg;
91 request_send_noreply(fc, req);
92}
93
Miklos Szeredid8a5ba42005-09-09 13:10:26 -070094static void fuse_clear_inode(struct inode *inode)
95{
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -070096 if (inode->i_sb->s_flags & MS_ACTIVE) {
97 struct fuse_conn *fc = get_fuse_conn(inode);
Miklos Szeredie5e55582005-09-09 13:10:28 -070098 struct fuse_inode *fi = get_fuse_inode(inode);
Miklos Szeredi9e6268d2005-09-09 13:10:29 -070099 fuse_send_forget(fc, fi->forget_req, fi->nodeid, fi->nlookup);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700100 fi->forget_req = NULL;
101 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700102}
103
Miklos Szeredi71421252006-06-25 05:48:52 -0700104static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)
105{
106 if (*flags & MS_MANDLOCK)
107 return -EINVAL;
108
109 return 0;
110}
111
Miklos Szeredie00d2c22007-10-16 23:31:01 -0700112static void fuse_truncate(struct address_space *mapping, loff_t offset)
113{
114 /* See vmtruncate() */
115 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
116 truncate_inode_pages(mapping, offset);
117 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
118}
119
Miklos Szeredi1fb69e72007-10-18 03:06:58 -0700120
121void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
122 u64 attr_valid, u64 attr_version)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700123{
Miklos Szeredi9ffbb912006-10-17 00:10:06 -0700124 struct fuse_conn *fc = get_fuse_conn(inode);
Miklos Szerediebc14c42007-10-16 23:31:03 -0700125 struct fuse_inode *fi = get_fuse_inode(inode);
Miklos Szeredie00d2c22007-10-16 23:31:01 -0700126 loff_t oldsize;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700127
Miklos Szeredi1fb69e72007-10-18 03:06:58 -0700128 spin_lock(&fc->lock);
129 if (attr_version != 0 && fi->attr_version > attr_version) {
130 spin_unlock(&fc->lock);
131 return;
132 }
133 fi->attr_version = ++fc->attr_version;
134 fi->i_time = attr_valid;
135
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700136 inode->i_ino = attr->ino;
Miklos Szerediebc14c42007-10-16 23:31:03 -0700137 inode->i_mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700138 inode->i_nlink = attr->nlink;
139 inode->i_uid = attr->uid;
140 inode->i_gid = attr->gid;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700141 inode->i_blocks = attr->blocks;
142 inode->i_atime.tv_sec = attr->atime;
143 inode->i_atime.tv_nsec = attr->atimensec;
144 inode->i_mtime.tv_sec = attr->mtime;
145 inode->i_mtime.tv_nsec = attr->mtimensec;
146 inode->i_ctime.tv_sec = attr->ctime;
147 inode->i_ctime.tv_nsec = attr->ctimensec;
Miklos Szeredie00d2c22007-10-16 23:31:01 -0700148
Miklos Szerediebc14c42007-10-16 23:31:03 -0700149 /*
150 * Don't set the sticky bit in i_mode, unless we want the VFS
151 * to check permissions. This prevents failures due to the
152 * check in may_delete().
153 */
154 fi->orig_i_mode = inode->i_mode;
155 if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
156 inode->i_mode &= ~S_ISVTX;
157
Miklos Szeredie00d2c22007-10-16 23:31:01 -0700158 oldsize = inode->i_size;
159 i_size_write(inode, attr->size);
160 spin_unlock(&fc->lock);
161
162 if (S_ISREG(inode->i_mode) && oldsize != attr->size) {
163 if (attr->size < oldsize)
164 fuse_truncate(inode->i_mapping, attr->size);
Miklos Szeredib1009972007-10-16 23:31:01 -0700165 invalidate_inode_pages2(inode->i_mapping);
Miklos Szeredie00d2c22007-10-16 23:31:01 -0700166 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700167}
168
169static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
170{
171 inode->i_mode = attr->mode & S_IFMT;
Miklos Szeredi9ffbb912006-10-17 00:10:06 -0700172 inode->i_size = attr->size;
Miklos Szeredie5e55582005-09-09 13:10:28 -0700173 if (S_ISREG(inode->i_mode)) {
174 fuse_init_common(inode);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700175 fuse_init_file_inode(inode);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700176 } else if (S_ISDIR(inode->i_mode))
177 fuse_init_dir(inode);
178 else if (S_ISLNK(inode->i_mode))
179 fuse_init_symlink(inode);
180 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
181 S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
182 fuse_init_common(inode);
183 init_special_inode(inode, inode->i_mode,
184 new_decode_dev(attr->rdev));
Miklos Szeredi39ee0592006-01-06 00:19:43 -0800185 } else
186 BUG();
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700187}
188
189static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
190{
191 unsigned long nodeid = *(unsigned long *) _nodeidp;
192 if (get_node_id(inode) == nodeid)
193 return 1;
194 else
195 return 0;
196}
197
198static int fuse_inode_set(struct inode *inode, void *_nodeidp)
199{
200 unsigned long nodeid = *(unsigned long *) _nodeidp;
201 get_fuse_inode(inode)->nodeid = nodeid;
202 return 0;
203}
204
205struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
Miklos Szeredi1fb69e72007-10-18 03:06:58 -0700206 int generation, struct fuse_attr *attr,
207 u64 attr_valid, u64 attr_version)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700208{
209 struct inode *inode;
Miklos Szeredi9e6268d2005-09-09 13:10:29 -0700210 struct fuse_inode *fi;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700211 struct fuse_conn *fc = get_fuse_conn_super(sb);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700212
213 retry:
214 inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid);
215 if (!inode)
216 return NULL;
217
218 if ((inode->i_state & I_NEW)) {
Miklos Szeredib36c31b2005-09-09 13:10:38 -0700219 inode->i_flags |= S_NOATIME|S_NOCMTIME;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700220 inode->i_generation = generation;
221 inode->i_data.backing_dev_info = &fc->bdi;
222 fuse_init_inode(inode, attr);
223 unlock_new_inode(inode);
224 } else if ((inode->i_mode ^ attr->mode) & S_IFMT) {
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700225 /* Inode has changed type, any I/O on the old should fail */
226 make_bad_inode(inode);
227 iput(inode);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700228 goto retry;
229 }
230
Miklos Szeredi9e6268d2005-09-09 13:10:29 -0700231 fi = get_fuse_inode(inode);
Miklos Szeredi8da5ff22006-10-17 00:10:08 -0700232 spin_lock(&fc->lock);
Miklos Szeredi9e6268d2005-09-09 13:10:29 -0700233 fi->nlookup ++;
Miklos Szeredi8da5ff22006-10-17 00:10:08 -0700234 spin_unlock(&fc->lock);
Miklos Szeredi1fb69e72007-10-18 03:06:58 -0700235 fuse_change_attributes(inode, attr, attr_valid, attr_version);
236
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700237 return inode;
238}
239
Trond Myklebust8b512d92006-06-09 09:34:18 -0400240static void fuse_umount_begin(struct vfsmount *vfsmnt, int flags)
Miklos Szeredi69a53bf2006-01-16 22:14:41 -0800241{
Trond Myklebust8b512d92006-06-09 09:34:18 -0400242 if (flags & MNT_FORCE)
243 fuse_abort_conn(get_fuse_conn_super(vfsmnt->mnt_sb));
Miklos Szeredi69a53bf2006-01-16 22:14:41 -0800244}
245
Miklos Szeredi0ec7ca42006-12-06 20:35:52 -0800246static void fuse_send_destroy(struct fuse_conn *fc)
247{
248 struct fuse_req *req = fc->destroy_req;
249 if (req && fc->conn_init) {
250 fc->destroy_req = NULL;
251 req->in.h.opcode = FUSE_DESTROY;
252 req->force = 1;
253 request_send(fc, req);
254 fuse_put_request(fc, req);
255 }
256}
257
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700258static void fuse_put_super(struct super_block *sb)
259{
260 struct fuse_conn *fc = get_fuse_conn_super(sb);
261
Miklos Szeredi0ec7ca42006-12-06 20:35:52 -0800262 fuse_send_destroy(fc);
Miklos Szeredid7133112006-04-10 22:54:55 -0700263 spin_lock(&fc->lock);
Miklos Szeredi9ba7cbb2006-01-16 22:14:34 -0800264 fc->connected = 0;
Miklos Szeredi51eb01e2006-06-25 05:48:50 -0700265 fc->blocked = 0;
Miklos Szeredid7133112006-04-10 22:54:55 -0700266 spin_unlock(&fc->lock);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700267 /* Flush all readers on this fs */
Jeff Dike385a17b2006-04-10 22:54:52 -0700268 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700269 wake_up_all(&fc->waitq);
Miklos Szeredi51eb01e2006-06-25 05:48:50 -0700270 wake_up_all(&fc->blocked_waitq);
Miklos Szeredide5e3de2007-10-16 23:31:00 -0700271 wake_up_all(&fc->reserved_req_waitq);
Miklos Szeredibafa9652006-06-25 05:48:51 -0700272 mutex_lock(&fuse_mutex);
273 list_del(&fc->entry);
274 fuse_ctl_remove_conn(fc);
275 mutex_unlock(&fuse_mutex);
276 fuse_conn_put(fc);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700277}
278
Miklos Szeredie5e55582005-09-09 13:10:28 -0700279static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
280{
281 stbuf->f_type = FUSE_SUPER_MAGIC;
282 stbuf->f_bsize = attr->bsize;
Miklos Szeredide5f1202006-01-06 00:19:37 -0800283 stbuf->f_frsize = attr->frsize;
Miklos Szeredie5e55582005-09-09 13:10:28 -0700284 stbuf->f_blocks = attr->blocks;
285 stbuf->f_bfree = attr->bfree;
286 stbuf->f_bavail = attr->bavail;
287 stbuf->f_files = attr->files;
288 stbuf->f_ffree = attr->ffree;
289 stbuf->f_namelen = attr->namelen;
290 /* fsid is left zero */
291}
292
David Howells726c3342006-06-23 02:02:58 -0700293static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)
Miklos Szeredie5e55582005-09-09 13:10:28 -0700294{
David Howells726c3342006-06-23 02:02:58 -0700295 struct super_block *sb = dentry->d_sb;
Miklos Szeredie5e55582005-09-09 13:10:28 -0700296 struct fuse_conn *fc = get_fuse_conn_super(sb);
297 struct fuse_req *req;
298 struct fuse_statfs_out outarg;
299 int err;
300
Miklos Szeredie57ac682007-10-18 03:06:58 -0700301 if (!fuse_allow_task(fc, current)) {
302 buf->f_type = FUSE_SUPER_MAGIC;
303 return 0;
304 }
305
Miklos Szeredice1d5a42006-04-10 22:54:58 -0700306 req = fuse_get_req(fc);
307 if (IS_ERR(req))
308 return PTR_ERR(req);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700309
Miklos Szeredide5f1202006-01-06 00:19:37 -0800310 memset(&outarg, 0, sizeof(outarg));
Miklos Szeredie5e55582005-09-09 13:10:28 -0700311 req->in.numargs = 0;
312 req->in.h.opcode = FUSE_STATFS;
Miklos Szeredi5b35e8e2006-09-29 01:59:34 -0700313 req->in.h.nodeid = get_node_id(dentry->d_inode);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700314 req->out.numargs = 1;
Miklos Szeredide5f1202006-01-06 00:19:37 -0800315 req->out.args[0].size =
316 fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg);
Miklos Szeredie5e55582005-09-09 13:10:28 -0700317 req->out.args[0].value = &outarg;
318 request_send(fc, req);
319 err = req->out.h.error;
320 if (!err)
321 convert_fuse_statfs(buf, &outarg.st);
322 fuse_put_request(fc, req);
323 return err;
324}
325
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700326enum {
327 OPT_FD,
328 OPT_ROOTMODE,
329 OPT_USER_ID,
Miklos Szeredi87729a52005-09-09 13:10:34 -0700330 OPT_GROUP_ID,
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700331 OPT_DEFAULT_PERMISSIONS,
332 OPT_ALLOW_OTHER,
Miklos Szeredidb50b962005-09-09 13:10:33 -0700333 OPT_MAX_READ,
Miklos Szeredid8091612006-12-06 20:35:48 -0800334 OPT_BLKSIZE,
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700335 OPT_ERR
336};
337
338static match_table_t tokens = {
339 {OPT_FD, "fd=%u"},
340 {OPT_ROOTMODE, "rootmode=%o"},
341 {OPT_USER_ID, "user_id=%u"},
Miklos Szeredi87729a52005-09-09 13:10:34 -0700342 {OPT_GROUP_ID, "group_id=%u"},
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700343 {OPT_DEFAULT_PERMISSIONS, "default_permissions"},
344 {OPT_ALLOW_OTHER, "allow_other"},
Miklos Szeredidb50b962005-09-09 13:10:33 -0700345 {OPT_MAX_READ, "max_read=%u"},
Miklos Szeredid8091612006-12-06 20:35:48 -0800346 {OPT_BLKSIZE, "blksize=%u"},
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700347 {OPT_ERR, NULL}
348};
349
Miklos Szeredid8091612006-12-06 20:35:48 -0800350static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700351{
352 char *p;
353 memset(d, 0, sizeof(struct fuse_mount_data));
Miklos Szeredidb50b962005-09-09 13:10:33 -0700354 d->max_read = ~0;
Miklos Szeredid8091612006-12-06 20:35:48 -0800355 d->blksize = 512;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700356
357 while ((p = strsep(&opt, ",")) != NULL) {
358 int token;
359 int value;
360 substring_t args[MAX_OPT_ARGS];
361 if (!*p)
362 continue;
363
364 token = match_token(p, tokens, args);
365 switch (token) {
366 case OPT_FD:
367 if (match_int(&args[0], &value))
368 return 0;
369 d->fd = value;
Miklos Szeredi5a533682005-09-09 13:10:34 -0700370 d->fd_present = 1;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700371 break;
372
373 case OPT_ROOTMODE:
374 if (match_octal(&args[0], &value))
375 return 0;
Timo Savolaa5bfffac2007-04-08 16:04:00 -0700376 if (!fuse_valid_type(value))
377 return 0;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700378 d->rootmode = value;
Miklos Szeredi5a533682005-09-09 13:10:34 -0700379 d->rootmode_present = 1;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700380 break;
381
382 case OPT_USER_ID:
383 if (match_int(&args[0], &value))
384 return 0;
385 d->user_id = value;
Miklos Szeredi5a533682005-09-09 13:10:34 -0700386 d->user_id_present = 1;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700387 break;
388
Miklos Szeredi87729a52005-09-09 13:10:34 -0700389 case OPT_GROUP_ID:
390 if (match_int(&args[0], &value))
391 return 0;
392 d->group_id = value;
Miklos Szeredi5a533682005-09-09 13:10:34 -0700393 d->group_id_present = 1;
Miklos Szeredi87729a52005-09-09 13:10:34 -0700394 break;
395
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700396 case OPT_DEFAULT_PERMISSIONS:
397 d->flags |= FUSE_DEFAULT_PERMISSIONS;
398 break;
399
400 case OPT_ALLOW_OTHER:
401 d->flags |= FUSE_ALLOW_OTHER;
402 break;
403
Miklos Szeredidb50b962005-09-09 13:10:33 -0700404 case OPT_MAX_READ:
405 if (match_int(&args[0], &value))
406 return 0;
407 d->max_read = value;
408 break;
409
Miklos Szeredid8091612006-12-06 20:35:48 -0800410 case OPT_BLKSIZE:
411 if (!is_bdev || match_int(&args[0], &value))
412 return 0;
413 d->blksize = value;
414 break;
415
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700416 default:
417 return 0;
418 }
419 }
Miklos Szeredi5a533682005-09-09 13:10:34 -0700420
421 if (!d->fd_present || !d->rootmode_present ||
422 !d->user_id_present || !d->group_id_present)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700423 return 0;
424
425 return 1;
426}
427
428static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
429{
430 struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb);
431
432 seq_printf(m, ",user_id=%u", fc->user_id);
Miklos Szeredi87729a52005-09-09 13:10:34 -0700433 seq_printf(m, ",group_id=%u", fc->group_id);
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700434 if (fc->flags & FUSE_DEFAULT_PERMISSIONS)
435 seq_puts(m, ",default_permissions");
436 if (fc->flags & FUSE_ALLOW_OTHER)
437 seq_puts(m, ",allow_other");
Miklos Szeredidb50b962005-09-09 13:10:33 -0700438 if (fc->max_read != ~0)
439 seq_printf(m, ",max_read=%u", fc->max_read);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700440 return 0;
441}
442
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700443static struct fuse_conn *new_conn(void)
444{
445 struct fuse_conn *fc;
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700446 int err;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700447
Miklos Szeredi6383bda2006-01-16 22:14:29 -0800448 fc = kzalloc(sizeof(*fc), GFP_KERNEL);
Miklos Szeredif543f252006-01-16 22:14:35 -0800449 if (fc) {
Miklos Szeredid7133112006-04-10 22:54:55 -0700450 spin_lock_init(&fc->lock);
Miklos Szeredid2a85162006-10-17 00:10:11 -0700451 mutex_init(&fc->inst_mutex);
Miklos Szeredibafa9652006-06-25 05:48:51 -0700452 atomic_set(&fc->count, 1);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700453 init_waitqueue_head(&fc->waitq);
Miklos Szeredi08a53cd2006-04-10 22:54:59 -0700454 init_waitqueue_head(&fc->blocked_waitq);
Miklos Szeredide5e3de2007-10-16 23:31:00 -0700455 init_waitqueue_head(&fc->reserved_req_waitq);
Miklos Szeredi334f4852005-09-09 13:10:27 -0700456 INIT_LIST_HEAD(&fc->pending);
457 INIT_LIST_HEAD(&fc->processing);
Miklos Szeredid77a1d52006-01-16 22:14:31 -0800458 INIT_LIST_HEAD(&fc->io);
Miklos Szeredia4d27e72006-06-25 05:48:54 -0700459 INIT_LIST_HEAD(&fc->interrupts);
Miklos Szeredi095da6c2006-01-16 22:14:52 -0800460 atomic_set(&fc->num_waiting, 0);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700461 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
462 fc->bdi.unplug_io_fn = default_unplug_io_fn;
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700463 err = bdi_init(&fc->bdi);
464 if (err) {
465 kfree(fc);
466 fc = NULL;
467 goto out;
468 }
Miklos Szeredi334f4852005-09-09 13:10:27 -0700469 fc->reqctr = 0;
Miklos Szeredi08a53cd2006-04-10 22:54:59 -0700470 fc->blocked = 1;
Miklos Szeredi1fb69e72007-10-18 03:06:58 -0700471 fc->attr_version = 1;
Miklos Szeredi9c8ef562006-06-25 05:48:55 -0700472 get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700473 }
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700474out:
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700475 return fc;
476}
477
Miklos Szeredibafa9652006-06-25 05:48:51 -0700478void fuse_conn_put(struct fuse_conn *fc)
479{
Miklos Szeredid2a85162006-10-17 00:10:11 -0700480 if (atomic_dec_and_test(&fc->count)) {
Miklos Szeredi0ec7ca42006-12-06 20:35:52 -0800481 if (fc->destroy_req)
482 fuse_request_free(fc->destroy_req);
Miklos Szeredid2a85162006-10-17 00:10:11 -0700483 mutex_destroy(&fc->inst_mutex);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700484 bdi_destroy(&fc->bdi);
Miklos Szeredibafa9652006-06-25 05:48:51 -0700485 kfree(fc);
Miklos Szeredid2a85162006-10-17 00:10:11 -0700486 }
Miklos Szeredibafa9652006-06-25 05:48:51 -0700487}
488
489struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
490{
491 atomic_inc(&fc->count);
492 return fc;
493}
494
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700495static struct inode *get_root_inode(struct super_block *sb, unsigned mode)
496{
497 struct fuse_attr attr;
498 memset(&attr, 0, sizeof(attr));
499
500 attr.mode = mode;
501 attr.ino = FUSE_ROOT_ID;
Miklos Szeredi074406f2007-10-16 23:31:02 -0700502 attr.nlink = 1;
Miklos Szeredi1fb69e72007-10-18 03:06:58 -0700503 return fuse_iget(sb, 1, 0, &attr, 0, 0);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700504}
505
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800506static const struct super_operations fuse_super_operations = {
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700507 .alloc_inode = fuse_alloc_inode,
508 .destroy_inode = fuse_destroy_inode,
509 .read_inode = fuse_read_inode,
510 .clear_inode = fuse_clear_inode,
Miklos Szerediead5f0b2007-05-23 13:57:54 -0700511 .drop_inode = generic_delete_inode,
Miklos Szeredi71421252006-06-25 05:48:52 -0700512 .remount_fs = fuse_remount_fs,
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700513 .put_super = fuse_put_super,
Miklos Szeredi69a53bf2006-01-16 22:14:41 -0800514 .umount_begin = fuse_umount_begin,
Miklos Szeredie5e55582005-09-09 13:10:28 -0700515 .statfs = fuse_statfs,
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700516 .show_options = fuse_show_options,
517};
518
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800519static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
520{
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800521 struct fuse_init_out *arg = &req->misc.init_out;
522
523 if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION)
524 fc->conn_error = 1;
525 else {
Miklos Szeredi9cd68452006-02-01 03:04:40 -0800526 unsigned long ra_pages;
527
528 if (arg->minor >= 6) {
529 ra_pages = arg->max_readahead / PAGE_CACHE_SIZE;
530 if (arg->flags & FUSE_ASYNC_READ)
531 fc->async_read = 1;
Miklos Szeredi71421252006-06-25 05:48:52 -0700532 if (!(arg->flags & FUSE_POSIX_LOCKS))
533 fc->no_lock = 1;
534 } else {
Miklos Szeredi9cd68452006-02-01 03:04:40 -0800535 ra_pages = fc->max_read / PAGE_CACHE_SIZE;
Miklos Szeredi71421252006-06-25 05:48:52 -0700536 fc->no_lock = 1;
537 }
Miklos Szeredi9cd68452006-02-01 03:04:40 -0800538
539 fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages);
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800540 fc->minor = arg->minor;
541 fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
Miklos Szeredi0ec7ca42006-12-06 20:35:52 -0800542 fc->conn_init = 1;
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800543 }
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800544 fuse_put_request(fc, req);
Miklos Szeredi08a53cd2006-04-10 22:54:59 -0700545 fc->blocked = 0;
546 wake_up_all(&fc->blocked_waitq);
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800547}
548
Miklos Szeredice1d5a42006-04-10 22:54:58 -0700549static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800550{
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800551 struct fuse_init_in *arg = &req->misc.init_in;
Miklos Szeredi095da6c2006-01-16 22:14:52 -0800552
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800553 arg->major = FUSE_KERNEL_VERSION;
554 arg->minor = FUSE_KERNEL_MINOR_VERSION;
Miklos Szeredi9cd68452006-02-01 03:04:40 -0800555 arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE;
Miklos Szeredi71421252006-06-25 05:48:52 -0700556 arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS;
Miklos Szeredi9b9a0462006-01-16 22:14:44 -0800557 req->in.h.opcode = FUSE_INIT;
558 req->in.numargs = 1;
559 req->in.args[0].size = sizeof(*arg);
560 req->in.args[0].value = arg;
561 req->out.numargs = 1;
562 /* Variable length arguement used for backward compatibility
563 with interface version < 7.5. Rest of init_out is zeroed
564 by do_get_request(), so a short reply is not a problem */
565 req->out.argvar = 1;
566 req->out.args[0].size = sizeof(struct fuse_init_out);
567 req->out.args[0].value = &req->misc.init_out;
568 req->end = process_init_reply;
569 request_send_background(fc, req);
570}
571
Miklos Szeredibafa9652006-06-25 05:48:51 -0700572static u64 conn_id(void)
Miklos Szeredif543f252006-01-16 22:14:35 -0800573{
Miklos Szeredibafa9652006-06-25 05:48:51 -0700574 static u64 ctr = 1;
Miklos Szeredi0720b312006-04-10 22:54:55 -0700575 return ctr++;
Miklos Szeredif543f252006-01-16 22:14:35 -0800576}
577
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700578static int fuse_fill_super(struct super_block *sb, void *data, int silent)
579{
580 struct fuse_conn *fc;
581 struct inode *root;
582 struct fuse_mount_data d;
583 struct file *file;
Miklos Szeredif543f252006-01-16 22:14:35 -0800584 struct dentry *root_dentry;
Miklos Szeredice1d5a42006-04-10 22:54:58 -0700585 struct fuse_req *init_req;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700586 int err;
Miklos Szeredid8091612006-12-06 20:35:48 -0800587 int is_bdev = sb->s_bdev != NULL;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700588
Miklos Szeredi71421252006-06-25 05:48:52 -0700589 if (sb->s_flags & MS_MANDLOCK)
590 return -EINVAL;
591
Miklos Szeredid8091612006-12-06 20:35:48 -0800592 if (!parse_fuse_opt((char *) data, &d, is_bdev))
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700593 return -EINVAL;
594
Miklos Szeredid8091612006-12-06 20:35:48 -0800595 if (is_bdev) {
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800596#ifdef CONFIG_BLOCK
Miklos Szeredid8091612006-12-06 20:35:48 -0800597 if (!sb_set_blocksize(sb, d.blksize))
598 return -EINVAL;
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800599#endif
Miklos Szeredid8091612006-12-06 20:35:48 -0800600 } else {
601 sb->s_blocksize = PAGE_CACHE_SIZE;
602 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
603 }
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700604 sb->s_magic = FUSE_SUPER_MAGIC;
605 sb->s_op = &fuse_super_operations;
606 sb->s_maxbytes = MAX_LFS_FILESIZE;
607
608 file = fget(d.fd);
609 if (!file)
610 return -EINVAL;
611
Miklos Szeredi0720b312006-04-10 22:54:55 -0700612 if (file->f_op != &fuse_dev_operations)
613 return -EINVAL;
614
Miklos Szeredi0720b312006-04-10 22:54:55 -0700615 fc = new_conn();
616 if (!fc)
617 return -ENOMEM;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700618
Miklos Szeredi1e9a4ed2005-09-09 13:10:31 -0700619 fc->flags = d.flags;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700620 fc->user_id = d.user_id;
Miklos Szeredi87729a52005-09-09 13:10:34 -0700621 fc->group_id = d.group_id;
Miklos Szeredidb50b962005-09-09 13:10:33 -0700622 fc->max_read = d.max_read;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700623
Miklos Szeredif543f252006-01-16 22:14:35 -0800624 /* Used by get_root_inode() */
625 sb->s_fs_info = fc;
626
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700627 err = -ENOMEM;
628 root = get_root_inode(sb, d.rootmode);
Miklos Szeredif543f252006-01-16 22:14:35 -0800629 if (!root)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700630 goto err;
631
Miklos Szeredif543f252006-01-16 22:14:35 -0800632 root_dentry = d_alloc_root(root);
633 if (!root_dentry) {
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700634 iput(root);
635 goto err;
636 }
Miklos Szeredif543f252006-01-16 22:14:35 -0800637
Miklos Szeredice1d5a42006-04-10 22:54:58 -0700638 init_req = fuse_request_alloc();
639 if (!init_req)
640 goto err_put_root;
641
Miklos Szeredi0ec7ca42006-12-06 20:35:52 -0800642 if (is_bdev) {
643 fc->destroy_req = fuse_request_alloc();
644 if (!fc->destroy_req)
645 goto err_put_root;
646 }
647
Miklos Szeredibafa9652006-06-25 05:48:51 -0700648 mutex_lock(&fuse_mutex);
Miklos Szeredi8aa09a52006-04-26 10:49:16 +0200649 err = -EINVAL;
650 if (file->private_data)
Miklos Szeredibafa9652006-06-25 05:48:51 -0700651 goto err_unlock;
Miklos Szeredi8aa09a52006-04-26 10:49:16 +0200652
Miklos Szeredibafa9652006-06-25 05:48:51 -0700653 fc->id = conn_id();
654 err = fuse_ctl_add_conn(fc);
655 if (err)
656 goto err_unlock;
657
658 list_add_tail(&fc->entry, &fuse_conn_list);
Miklos Szeredif543f252006-01-16 22:14:35 -0800659 sb->s_root = root_dentry;
Miklos Szeredif543f252006-01-16 22:14:35 -0800660 fc->connected = 1;
Miklos Szeredibafa9652006-06-25 05:48:51 -0700661 file->private_data = fuse_conn_get(fc);
662 mutex_unlock(&fuse_mutex);
Miklos Szeredi0720b312006-04-10 22:54:55 -0700663 /*
664 * atomic_dec_and_test() in fput() provides the necessary
665 * memory barrier for file->private_data to be visible on all
666 * CPUs after this
667 */
668 fput(file);
Miklos Szeredif543f252006-01-16 22:14:35 -0800669
Miklos Szeredice1d5a42006-04-10 22:54:58 -0700670 fuse_send_init(fc, init_req);
Miklos Szeredif543f252006-01-16 22:14:35 -0800671
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700672 return 0;
673
Miklos Szeredibafa9652006-06-25 05:48:51 -0700674 err_unlock:
675 mutex_unlock(&fuse_mutex);
Miklos Szeredice1d5a42006-04-10 22:54:58 -0700676 fuse_request_free(init_req);
Miklos Szeredif543f252006-01-16 22:14:35 -0800677 err_put_root:
678 dput(root_dentry);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700679 err:
Miklos Szeredi0720b312006-04-10 22:54:55 -0700680 fput(file);
Miklos Szeredibafa9652006-06-25 05:48:51 -0700681 fuse_conn_put(fc);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700682 return err;
683}
684
David Howells454e2392006-06-23 02:02:57 -0700685static int fuse_get_sb(struct file_system_type *fs_type,
686 int flags, const char *dev_name,
687 void *raw_data, struct vfsmount *mnt)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700688{
David Howells454e2392006-06-23 02:02:57 -0700689 return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700690}
691
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800692static struct file_system_type fuse_fs_type = {
693 .owner = THIS_MODULE,
694 .name = "fuse",
Miklos Szeredi79c0b2d2007-05-08 00:25:43 -0700695 .fs_flags = FS_HAS_SUBTYPE,
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800696 .get_sb = fuse_get_sb,
697 .kill_sb = kill_anon_super,
698};
699
700#ifdef CONFIG_BLOCK
Miklos Szeredid6392f82006-12-06 20:35:44 -0800701static int fuse_get_sb_blk(struct file_system_type *fs_type,
702 int flags, const char *dev_name,
703 void *raw_data, struct vfsmount *mnt)
704{
705 return get_sb_bdev(fs_type, flags, dev_name, raw_data, fuse_fill_super,
706 mnt);
707}
708
Miklos Szeredid6392f82006-12-06 20:35:44 -0800709static struct file_system_type fuseblk_fs_type = {
710 .owner = THIS_MODULE,
711 .name = "fuseblk",
712 .get_sb = fuse_get_sb_blk,
713 .kill_sb = kill_block_super,
Alexey Dobriyanedad01e2007-06-16 10:16:05 -0700714 .fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE,
Miklos Szeredid6392f82006-12-06 20:35:44 -0800715};
716
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800717static inline int register_fuseblk(void)
718{
719 return register_filesystem(&fuseblk_fs_type);
720}
721
722static inline void unregister_fuseblk(void)
723{
724 unregister_filesystem(&fuseblk_fs_type);
725}
726#else
727static inline int register_fuseblk(void)
728{
729 return 0;
730}
731
732static inline void unregister_fuseblk(void)
733{
734}
735#endif
736
Miklos Szeredif543f252006-01-16 22:14:35 -0800737static decl_subsys(fuse, NULL, NULL);
Miklos Szeredibafa9652006-06-25 05:48:51 -0700738static decl_subsys(connections, NULL, NULL);
Miklos Szeredif543f252006-01-16 22:14:35 -0800739
Christoph Lameter4ba9b9d2007-10-16 23:25:51 -0700740static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo)
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700741{
742 struct inode * inode = foo;
743
Christoph Lametera35afb82007-05-16 22:10:57 -0700744 inode_init_once(inode);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700745}
746
747static int __init fuse_fs_init(void)
748{
749 int err;
750
751 err = register_filesystem(&fuse_fs_type);
752 if (err)
Miklos Szeredid6392f82006-12-06 20:35:44 -0800753 goto out;
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700754
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800755 err = register_fuseblk();
Miklos Szeredid6392f82006-12-06 20:35:44 -0800756 if (err)
757 goto out_unreg;
758
759 fuse_inode_cachep = kmem_cache_create("fuse_inode",
760 sizeof(struct fuse_inode),
761 0, SLAB_HWCACHE_ALIGN,
Paul Mundt20c2df82007-07-20 10:11:58 +0900762 fuse_inode_init_once);
Miklos Szeredid6392f82006-12-06 20:35:44 -0800763 err = -ENOMEM;
764 if (!fuse_inode_cachep)
765 goto out_unreg2;
766
767 return 0;
768
769 out_unreg2:
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800770 unregister_fuseblk();
Miklos Szeredid6392f82006-12-06 20:35:44 -0800771 out_unreg:
772 unregister_filesystem(&fuse_fs_type);
773 out:
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700774 return err;
775}
776
777static void fuse_fs_cleanup(void)
778{
779 unregister_filesystem(&fuse_fs_type);
Miklos Szeredi875d95e2006-12-06 20:35:54 -0800780 unregister_fuseblk();
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700781 kmem_cache_destroy(fuse_inode_cachep);
782}
783
Miklos Szeredif543f252006-01-16 22:14:35 -0800784static int fuse_sysfs_init(void)
785{
786 int err;
787
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700788 kobj_set_kset_s(&fuse_subsys, fs_subsys);
Miklos Szeredif543f252006-01-16 22:14:35 -0800789 err = subsystem_register(&fuse_subsys);
790 if (err)
791 goto out_err;
792
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700793 kobj_set_kset_s(&connections_subsys, fuse_subsys);
Miklos Szeredif543f252006-01-16 22:14:35 -0800794 err = subsystem_register(&connections_subsys);
795 if (err)
796 goto out_fuse_unregister;
797
798 return 0;
799
800 out_fuse_unregister:
801 subsystem_unregister(&fuse_subsys);
802 out_err:
803 return err;
804}
805
806static void fuse_sysfs_cleanup(void)
807{
808 subsystem_unregister(&connections_subsys);
809 subsystem_unregister(&fuse_subsys);
810}
811
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700812static int __init fuse_init(void)
813{
814 int res;
815
816 printk("fuse init (API version %i.%i)\n",
817 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
818
Miklos Szeredibafa9652006-06-25 05:48:51 -0700819 INIT_LIST_HEAD(&fuse_conn_list);
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700820 res = fuse_fs_init();
821 if (res)
822 goto err;
823
Miklos Szeredi334f4852005-09-09 13:10:27 -0700824 res = fuse_dev_init();
825 if (res)
826 goto err_fs_cleanup;
827
Miklos Szeredif543f252006-01-16 22:14:35 -0800828 res = fuse_sysfs_init();
829 if (res)
830 goto err_dev_cleanup;
831
Miklos Szeredibafa9652006-06-25 05:48:51 -0700832 res = fuse_ctl_init();
833 if (res)
834 goto err_sysfs_cleanup;
835
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700836 return 0;
837
Miklos Szeredibafa9652006-06-25 05:48:51 -0700838 err_sysfs_cleanup:
839 fuse_sysfs_cleanup();
Miklos Szeredif543f252006-01-16 22:14:35 -0800840 err_dev_cleanup:
841 fuse_dev_cleanup();
Miklos Szeredi334f4852005-09-09 13:10:27 -0700842 err_fs_cleanup:
843 fuse_fs_cleanup();
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700844 err:
845 return res;
846}
847
848static void __exit fuse_exit(void)
849{
850 printk(KERN_DEBUG "fuse exit\n");
851
Miklos Szeredibafa9652006-06-25 05:48:51 -0700852 fuse_ctl_cleanup();
Miklos Szeredif543f252006-01-16 22:14:35 -0800853 fuse_sysfs_cleanup();
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700854 fuse_fs_cleanup();
Miklos Szeredi334f4852005-09-09 13:10:27 -0700855 fuse_dev_cleanup();
Miklos Szeredid8a5ba42005-09-09 13:10:26 -0700856}
857
858module_init(fuse_init);
859module_exit(fuse_exit);