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