Commit | Line | Data |
---|---|---|
6cbd5570 CM |
1 | /* |
2 | * Copyright (C) 2007 Oracle. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public | |
6 | * License v2 as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public | |
14 | * License along with this program; if not, write to the | |
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
16 | * Boston, MA 021110-1307, USA. | |
17 | */ | |
18 | ||
4b82d6e4 | 19 | #include <linux/blkdev.h> |
2e635a27 | 20 | #include <linux/module.h> |
e20d96d6 | 21 | #include <linux/buffer_head.h> |
2e635a27 CM |
22 | #include <linux/fs.h> |
23 | #include <linux/pagemap.h> | |
24 | #include <linux/highmem.h> | |
25 | #include <linux/time.h> | |
26 | #include <linux/init.h> | |
27 | #include <linux/string.h> | |
28 | #include <linux/smp_lock.h> | |
29 | #include <linux/backing-dev.h> | |
4b82d6e4 | 30 | #include <linux/mount.h> |
dee26a9f | 31 | #include <linux/mpage.h> |
75dfe396 CM |
32 | #include <linux/swap.h> |
33 | #include <linux/writeback.h> | |
8fd17795 | 34 | #include <linux/statfs.h> |
08607c1b | 35 | #include <linux/compat.h> |
95e05289 | 36 | #include <linux/parser.h> |
c59f8951 | 37 | #include <linux/ctype.h> |
6da6abae | 38 | #include <linux/namei.h> |
a9218f6b | 39 | #include <linux/miscdevice.h> |
2e635a27 | 40 | #include "ctree.h" |
e20d96d6 | 41 | #include "disk-io.h" |
d5719762 | 42 | #include "transaction.h" |
2c90e5d6 | 43 | #include "btrfs_inode.h" |
c5739bba | 44 | #include "ioctl.h" |
3a686375 | 45 | #include "print-tree.h" |
5103e947 | 46 | #include "xattr.h" |
8a4b83cc | 47 | #include "volumes.h" |
2e635a27 | 48 | |
5f39d397 | 49 | #define BTRFS_SUPER_MAGIC 0x9123683E |
f254e52c | 50 | |
39279cc3 | 51 | static struct super_operations btrfs_super_ops; |
75dfe396 | 52 | |
39279cc3 | 53 | static void btrfs_put_super (struct super_block * sb) |
b18c6685 | 54 | { |
39279cc3 | 55 | struct btrfs_root *root = btrfs_sb(sb); |
58176a96 | 56 | struct btrfs_fs_info *fs = root->fs_info; |
b18c6685 | 57 | int ret; |
b18c6685 | 58 | |
39279cc3 CM |
59 | ret = close_ctree(root); |
60 | if (ret) { | |
61 | printk("close ctree returns %d\n", ret); | |
75dfe396 | 62 | } |
58176a96 | 63 | btrfs_sysfs_del_super(fs); |
39279cc3 | 64 | sb->s_fs_info = NULL; |
75dfe396 CM |
65 | } |
66 | ||
95e05289 | 67 | enum { |
8f662a76 | 68 | Opt_subvol, Opt_nodatasum, Opt_nodatacow, Opt_max_extent, |
6f568d35 | 69 | Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd, Opt_err, |
95e05289 CM |
70 | }; |
71 | ||
72 | static match_table_t tokens = { | |
73 | {Opt_subvol, "subvol=%s"}, | |
b6cda9bc | 74 | {Opt_nodatasum, "nodatasum"}, |
be20aa9d | 75 | {Opt_nodatacow, "nodatacow"}, |
21ad10cf | 76 | {Opt_nobarrier, "nobarrier"}, |
c59f8951 | 77 | {Opt_max_extent, "max_extent=%s"}, |
6f568d35 | 78 | {Opt_max_inline, "max_inline=%s"}, |
8f662a76 | 79 | {Opt_alloc_start, "alloc_start=%s"}, |
e18e4809 | 80 | {Opt_ssd, "ssd"}, |
95e05289 CM |
81 | {Opt_err, NULL} |
82 | }; | |
83 | ||
edbd8d4e | 84 | u64 btrfs_parse_size(char *str) |
c59f8951 | 85 | { |
edbd8d4e | 86 | u64 res; |
c59f8951 CM |
87 | int mult = 1; |
88 | char *end; | |
89 | char last; | |
90 | ||
91 | res = simple_strtoul(str, &end, 10); | |
92 | ||
93 | last = end[0]; | |
94 | if (isalpha(last)) { | |
95 | last = tolower(last); | |
96 | switch (last) { | |
97 | case 'g': | |
98 | mult *= 1024; | |
99 | case 'm': | |
100 | mult *= 1024; | |
101 | case 'k': | |
102 | mult *= 1024; | |
103 | } | |
104 | res = res * mult; | |
105 | } | |
106 | return res; | |
107 | } | |
108 | ||
95e05289 CM |
109 | static int parse_options (char * options, |
110 | struct btrfs_root *root, | |
111 | char **subvol_name) | |
112 | { | |
113 | char * p; | |
b6cda9bc | 114 | struct btrfs_fs_info *info = NULL; |
95e05289 | 115 | substring_t args[MAX_OPT_ARGS]; |
b6cda9bc | 116 | |
95e05289 CM |
117 | if (!options) |
118 | return 1; | |
119 | ||
be20aa9d CM |
120 | /* |
121 | * strsep changes the string, duplicate it because parse_options | |
122 | * gets called twice | |
123 | */ | |
124 | options = kstrdup(options, GFP_NOFS); | |
125 | if (!options) | |
126 | return -ENOMEM; | |
127 | ||
128 | if (root) | |
129 | info = root->fs_info; | |
130 | ||
95e05289 CM |
131 | while ((p = strsep (&options, ",")) != NULL) { |
132 | int token; | |
133 | if (!*p) | |
134 | continue; | |
135 | ||
136 | token = match_token(p, tokens, args); | |
137 | switch (token) { | |
138 | case Opt_subvol: | |
be20aa9d | 139 | if (subvol_name) { |
b6cda9bc | 140 | *subvol_name = match_strdup(&args[0]); |
be20aa9d | 141 | } |
b6cda9bc CM |
142 | break; |
143 | case Opt_nodatasum: | |
be20aa9d CM |
144 | if (info) { |
145 | printk("btrfs: setting nodatacsum\n"); | |
b6cda9bc | 146 | btrfs_set_opt(info->mount_opt, NODATASUM); |
be20aa9d CM |
147 | } |
148 | break; | |
149 | case Opt_nodatacow: | |
150 | if (info) { | |
151 | printk("btrfs: setting nodatacow\n"); | |
152 | btrfs_set_opt(info->mount_opt, NODATACOW); | |
153 | btrfs_set_opt(info->mount_opt, NODATASUM); | |
154 | } | |
95e05289 | 155 | break; |
e18e4809 CM |
156 | case Opt_ssd: |
157 | if (info) { | |
158 | printk("btrfs: use ssd allocation scheme\n"); | |
159 | btrfs_set_opt(info->mount_opt, SSD); | |
160 | } | |
161 | break; | |
21ad10cf CM |
162 | case Opt_nobarrier: |
163 | if (info) { | |
164 | printk("btrfs: turning off barriers\n"); | |
165 | btrfs_set_opt(info->mount_opt, NOBARRIER); | |
166 | } | |
167 | break; | |
c59f8951 CM |
168 | case Opt_max_extent: |
169 | if (info) { | |
170 | char *num = match_strdup(&args[0]); | |
171 | if (num) { | |
edbd8d4e CM |
172 | info->max_extent = |
173 | btrfs_parse_size(num); | |
c59f8951 CM |
174 | kfree(num); |
175 | ||
176 | info->max_extent = max_t(u64, | |
177 | info->max_extent, | |
178 | root->sectorsize); | |
179 | printk("btrfs: max_extent at %Lu\n", | |
180 | info->max_extent); | |
181 | } | |
182 | } | |
183 | break; | |
6f568d35 CM |
184 | case Opt_max_inline: |
185 | if (info) { | |
186 | char *num = match_strdup(&args[0]); | |
187 | if (num) { | |
188 | info->max_inline = | |
189 | btrfs_parse_size(num); | |
190 | kfree(num); | |
191 | ||
192 | info->max_inline = max_t(u64, | |
193 | info->max_inline, | |
194 | root->sectorsize); | |
195 | printk("btrfs: max_inline at %Lu\n", | |
196 | info->max_inline); | |
197 | } | |
198 | } | |
199 | break; | |
8f662a76 CM |
200 | case Opt_alloc_start: |
201 | if (info) { | |
202 | char *num = match_strdup(&args[0]); | |
203 | if (num) { | |
204 | info->alloc_start = | |
205 | btrfs_parse_size(num); | |
206 | kfree(num); | |
207 | printk("btrfs: allocations start at " | |
208 | "%Lu\n", info->alloc_start); | |
209 | } | |
210 | } | |
211 | break; | |
95e05289 | 212 | default: |
be20aa9d | 213 | break; |
95e05289 CM |
214 | } |
215 | } | |
be20aa9d | 216 | kfree(options); |
95e05289 CM |
217 | return 1; |
218 | } | |
219 | ||
8a4b83cc CM |
220 | static int btrfs_fill_super(struct super_block * sb, |
221 | struct btrfs_fs_devices *fs_devices, | |
222 | void * data, int silent) | |
75dfe396 | 223 | { |
39279cc3 CM |
224 | struct inode * inode; |
225 | struct dentry * root_dentry; | |
226 | struct btrfs_super_block *disk_super; | |
227 | struct btrfs_root *tree_root; | |
228 | struct btrfs_inode *bi; | |
229 | int err; | |
a429e513 | 230 | |
39279cc3 CM |
231 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
232 | sb->s_magic = BTRFS_SUPER_MAGIC; | |
233 | sb->s_op = &btrfs_super_ops; | |
5103e947 | 234 | sb->s_xattr = btrfs_xattr_handlers; |
39279cc3 | 235 | sb->s_time_gran = 1; |
a429e513 | 236 | |
8a4b83cc | 237 | tree_root = open_ctree(sb, fs_devices); |
6567e837 | 238 | |
e58ca020 | 239 | if (IS_ERR(tree_root)) { |
39279cc3 | 240 | printk("btrfs: open_ctree failed\n"); |
e58ca020 | 241 | return PTR_ERR(tree_root); |
a429e513 | 242 | } |
39279cc3 | 243 | sb->s_fs_info = tree_root; |
5f39d397 | 244 | disk_super = &tree_root->fs_info->super_copy; |
39279cc3 CM |
245 | inode = btrfs_iget_locked(sb, btrfs_super_root_dir(disk_super), |
246 | tree_root); | |
247 | bi = BTRFS_I(inode); | |
248 | bi->location.objectid = inode->i_ino; | |
249 | bi->location.offset = 0; | |
39279cc3 | 250 | bi->root = tree_root; |
b888db2b | 251 | |
39279cc3 | 252 | btrfs_set_key_type(&bi->location, BTRFS_INODE_ITEM_KEY); |
a429e513 | 253 | |
39279cc3 | 254 | if (!inode) { |
6567e837 | 255 | err = -ENOMEM; |
39279cc3 | 256 | goto fail_close; |
f254e52c | 257 | } |
39279cc3 CM |
258 | if (inode->i_state & I_NEW) { |
259 | btrfs_read_locked_inode(inode); | |
260 | unlock_new_inode(inode); | |
f254e52c | 261 | } |
f254e52c | 262 | |
39279cc3 CM |
263 | root_dentry = d_alloc_root(inode); |
264 | if (!root_dentry) { | |
265 | iput(inode); | |
266 | err = -ENOMEM; | |
267 | goto fail_close; | |
f254e52c | 268 | } |
58176a96 | 269 | |
b6cda9bc CM |
270 | parse_options((char *)data, tree_root, NULL); |
271 | ||
58176a96 JB |
272 | /* this does the super kobj at the same time */ |
273 | err = btrfs_sysfs_add_super(tree_root->fs_info); | |
274 | if (err) | |
275 | goto fail_close; | |
276 | ||
39279cc3 CM |
277 | sb->s_root = root_dentry; |
278 | btrfs_transaction_queue_work(tree_root, HZ * 30); | |
6885f308 CM |
279 | |
280 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) | |
281 | save_mount_options(sb, data); | |
282 | #endif | |
283 | ||
2619ba1f | 284 | return 0; |
39279cc3 CM |
285 | |
286 | fail_close: | |
287 | close_ctree(tree_root); | |
288 | return err; | |
2619ba1f CM |
289 | } |
290 | ||
39279cc3 | 291 | static int btrfs_sync_fs(struct super_block *sb, int wait) |
c5739bba CM |
292 | { |
293 | struct btrfs_trans_handle *trans; | |
39279cc3 | 294 | struct btrfs_root *root; |
c5739bba | 295 | int ret; |
39279cc3 | 296 | root = btrfs_sb(sb); |
2619ba1f | 297 | |
39279cc3 CM |
298 | sb->s_dirt = 0; |
299 | if (!wait) { | |
300 | filemap_flush(root->fs_info->btree_inode->i_mapping); | |
301 | return 0; | |
302 | } | |
e9d0b13b | 303 | btrfs_clean_old_snapshots(root); |
c5739bba | 304 | mutex_lock(&root->fs_info->fs_mutex); |
e9d0b13b | 305 | btrfs_defrag_dirty_roots(root->fs_info); |
c5739bba | 306 | trans = btrfs_start_transaction(root, 1); |
c5739bba | 307 | ret = btrfs_commit_transaction(trans, root); |
39279cc3 | 308 | sb->s_dirt = 0; |
c5739bba | 309 | mutex_unlock(&root->fs_info->fs_mutex); |
54aa1f4d | 310 | return ret; |
2c90e5d6 CM |
311 | } |
312 | ||
39279cc3 | 313 | static void btrfs_write_super(struct super_block *sb) |
2c90e5d6 | 314 | { |
39279cc3 | 315 | sb->s_dirt = 0; |
2c90e5d6 CM |
316 | } |
317 | ||
a061fc8d | 318 | static int btrfs_test_super(struct super_block *s, void *data) |
4b82d6e4 | 319 | { |
a061fc8d CM |
320 | struct btrfs_fs_devices *test_fs_devices = data; |
321 | struct btrfs_root *root = btrfs_sb(s); | |
4b82d6e4 | 322 | |
a061fc8d | 323 | return root->fs_info->fs_devices == test_fs_devices; |
4b82d6e4 Y |
324 | } |
325 | ||
326 | int btrfs_get_sb_bdev(struct file_system_type *fs_type, | |
327 | int flags, const char *dev_name, void *data, | |
4b82d6e4 Y |
328 | struct vfsmount *mnt, const char *subvol) |
329 | { | |
330 | struct block_device *bdev = NULL; | |
331 | struct super_block *s; | |
332 | struct dentry *root; | |
8a4b83cc | 333 | struct btrfs_fs_devices *fs_devices = NULL; |
4b82d6e4 Y |
334 | int error = 0; |
335 | ||
8a4b83cc CM |
336 | error = btrfs_scan_one_device(dev_name, flags, fs_type, &fs_devices); |
337 | if (error) | |
338 | return error; | |
4b82d6e4 | 339 | |
8a4b83cc CM |
340 | error = btrfs_open_devices(fs_devices, flags, fs_type); |
341 | if (error) | |
342 | return error; | |
343 | ||
344 | bdev = fs_devices->lowest_bdev; | |
a061fc8d CM |
345 | btrfs_lock_volumes(); |
346 | s = sget(fs_type, btrfs_test_super, set_anon_super, fs_devices); | |
347 | btrfs_unlock_volumes(); | |
4b82d6e4 Y |
348 | if (IS_ERR(s)) |
349 | goto error_s; | |
350 | ||
351 | if (s->s_root) { | |
352 | if ((flags ^ s->s_flags) & MS_RDONLY) { | |
353 | up_write(&s->s_umount); | |
354 | deactivate_super(s); | |
355 | error = -EBUSY; | |
356 | goto error_bdev; | |
357 | } | |
358 | ||
4b82d6e4 Y |
359 | } else { |
360 | char b[BDEVNAME_SIZE]; | |
361 | ||
362 | s->s_flags = flags; | |
363 | strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); | |
8a4b83cc CM |
364 | error = btrfs_fill_super(s, fs_devices, data, |
365 | flags & MS_SILENT ? 1 : 0); | |
4b82d6e4 Y |
366 | if (error) { |
367 | up_write(&s->s_umount); | |
368 | deactivate_super(s); | |
369 | goto error; | |
370 | } | |
371 | ||
788f20eb | 372 | btrfs_sb(s)->fs_info->bdev_holder = fs_type; |
4b82d6e4 Y |
373 | s->s_flags |= MS_ACTIVE; |
374 | } | |
375 | ||
376 | if (subvol) { | |
377 | root = lookup_one_len(subvol, s->s_root, strlen(subvol)); | |
378 | if (IS_ERR(root)) { | |
379 | up_write(&s->s_umount); | |
380 | deactivate_super(s); | |
381 | error = PTR_ERR(root); | |
382 | goto error; | |
383 | } | |
384 | if (!root->d_inode) { | |
385 | dput(root); | |
386 | up_write(&s->s_umount); | |
387 | deactivate_super(s); | |
388 | error = -ENXIO; | |
389 | goto error; | |
390 | } | |
391 | } else { | |
392 | root = dget(s->s_root); | |
393 | } | |
394 | ||
395 | mnt->mnt_sb = s; | |
396 | mnt->mnt_root = root; | |
397 | return 0; | |
398 | ||
399 | error_s: | |
400 | error = PTR_ERR(s); | |
401 | error_bdev: | |
8a4b83cc | 402 | btrfs_close_devices(fs_devices); |
4b82d6e4 Y |
403 | error: |
404 | return error; | |
405 | } | |
406 | /* end copy & paste */ | |
407 | ||
2e635a27 | 408 | static int btrfs_get_sb(struct file_system_type *fs_type, |
95e05289 | 409 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
2e635a27 | 410 | { |
4b82d6e4 | 411 | int ret; |
95e05289 | 412 | char *subvol_name = NULL; |
4b82d6e4 | 413 | |
95e05289 | 414 | parse_options((char *)data, NULL, &subvol_name); |
8a4b83cc | 415 | ret = btrfs_get_sb_bdev(fs_type, flags, dev_name, data, mnt, |
4b82d6e4 | 416 | subvol_name ? subvol_name : "default"); |
c59f8951 CM |
417 | if (subvol_name) |
418 | kfree(subvol_name); | |
4b82d6e4 | 419 | return ret; |
2e635a27 CM |
420 | } |
421 | ||
8fd17795 CM |
422 | static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
423 | { | |
424 | struct btrfs_root *root = btrfs_sb(dentry->d_sb); | |
4b52dff6 | 425 | struct btrfs_super_block *disk_super = &root->fs_info->super_copy; |
db94535d | 426 | int bits = dentry->d_sb->s_blocksize_bits; |
8fd17795 CM |
427 | |
428 | buf->f_namelen = BTRFS_NAME_LEN; | |
db94535d CM |
429 | buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; |
430 | buf->f_bfree = buf->f_blocks - | |
431 | (btrfs_super_bytes_used(disk_super) >> bits); | |
8fd17795 CM |
432 | buf->f_bavail = buf->f_bfree; |
433 | buf->f_bsize = dentry->d_sb->s_blocksize; | |
434 | buf->f_type = BTRFS_SUPER_MAGIC; | |
435 | return 0; | |
436 | } | |
b5133862 | 437 | |
2e635a27 CM |
438 | static struct file_system_type btrfs_fs_type = { |
439 | .owner = THIS_MODULE, | |
440 | .name = "btrfs", | |
441 | .get_sb = btrfs_get_sb, | |
a061fc8d | 442 | .kill_sb = kill_anon_super, |
2e635a27 CM |
443 | .fs_flags = FS_REQUIRES_DEV, |
444 | }; | |
a9218f6b | 445 | |
8a4b83cc CM |
446 | static long btrfs_control_ioctl(struct file *file, unsigned int cmd, |
447 | unsigned long arg) | |
448 | { | |
449 | struct btrfs_ioctl_vol_args *vol; | |
450 | struct btrfs_fs_devices *fs_devices; | |
451 | int ret; | |
452 | int len; | |
453 | ||
454 | vol = kmalloc(sizeof(*vol), GFP_KERNEL); | |
455 | if (copy_from_user(vol, (void __user *)arg, sizeof(*vol))) { | |
456 | ret = -EFAULT; | |
457 | goto out; | |
458 | } | |
459 | len = strnlen(vol->name, BTRFS_PATH_NAME_MAX); | |
460 | switch (cmd) { | |
461 | case BTRFS_IOC_SCAN_DEV: | |
462 | ret = btrfs_scan_one_device(vol->name, MS_RDONLY, | |
463 | &btrfs_fs_type, &fs_devices); | |
464 | break; | |
465 | } | |
466 | out: | |
467 | kfree(vol); | |
468 | return 0; | |
469 | } | |
470 | ||
ed0dab6b Y |
471 | static void btrfs_write_super_lockfs(struct super_block *sb) |
472 | { | |
473 | struct btrfs_root *root = btrfs_sb(sb); | |
474 | btrfs_transaction_flush_work(root); | |
475 | } | |
476 | ||
477 | static void btrfs_unlockfs(struct super_block *sb) | |
478 | { | |
479 | struct btrfs_root *root = btrfs_sb(sb); | |
480 | btrfs_transaction_queue_work(root, HZ * 30); | |
481 | } | |
2e635a27 | 482 | |
e20d96d6 | 483 | static struct super_operations btrfs_super_ops = { |
134e9731 | 484 | .delete_inode = btrfs_delete_inode, |
2da98f00 | 485 | .put_inode = btrfs_put_inode, |
e20d96d6 | 486 | .put_super = btrfs_put_super, |
d5719762 CM |
487 | .write_super = btrfs_write_super, |
488 | .sync_fs = btrfs_sync_fs, | |
6885f308 CM |
489 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) |
490 | .read_inode = btrfs_read_locked_inode, | |
491 | #else | |
492 | .show_options = generic_show_options, | |
493 | #endif | |
4730a4bc | 494 | .write_inode = btrfs_write_inode, |
b5133862 | 495 | .dirty_inode = btrfs_dirty_inode, |
2c90e5d6 CM |
496 | .alloc_inode = btrfs_alloc_inode, |
497 | .destroy_inode = btrfs_destroy_inode, | |
8fd17795 | 498 | .statfs = btrfs_statfs, |
ed0dab6b Y |
499 | .write_super_lockfs = btrfs_write_super_lockfs, |
500 | .unlockfs = btrfs_unlockfs, | |
e20d96d6 | 501 | }; |
a9218f6b CM |
502 | |
503 | static const struct file_operations btrfs_ctl_fops = { | |
504 | .unlocked_ioctl = btrfs_control_ioctl, | |
505 | .compat_ioctl = btrfs_control_ioctl, | |
506 | .owner = THIS_MODULE, | |
507 | }; | |
508 | ||
509 | static struct miscdevice btrfs_misc = { | |
510 | .minor = MISC_DYNAMIC_MINOR, | |
511 | .name = "btrfs-control", | |
512 | .fops = &btrfs_ctl_fops | |
513 | }; | |
514 | ||
515 | static int btrfs_interface_init(void) | |
516 | { | |
517 | return misc_register(&btrfs_misc); | |
518 | } | |
519 | ||
520 | void btrfs_interface_exit(void) | |
521 | { | |
522 | if (misc_deregister(&btrfs_misc) < 0) | |
523 | printk("misc_deregister failed for control device"); | |
524 | } | |
525 | ||
2e635a27 CM |
526 | static int __init init_btrfs_fs(void) |
527 | { | |
2c90e5d6 | 528 | int err; |
58176a96 JB |
529 | |
530 | err = btrfs_init_sysfs(); | |
531 | if (err) | |
532 | return err; | |
533 | ||
08607c1b | 534 | btrfs_init_transaction_sys(); |
39279cc3 | 535 | err = btrfs_init_cachep(); |
2c90e5d6 | 536 | if (err) |
2f4cbe64 | 537 | goto free_transaction_sys; |
d1310b2e CM |
538 | |
539 | err = extent_io_init(); | |
2f4cbe64 WB |
540 | if (err) |
541 | goto free_cachep; | |
542 | ||
d1310b2e CM |
543 | err = extent_map_init(); |
544 | if (err) | |
545 | goto free_extent_io; | |
546 | ||
a9218f6b | 547 | err = btrfs_interface_init(); |
2f4cbe64 WB |
548 | if (err) |
549 | goto free_extent_map; | |
a9218f6b CM |
550 | err = register_filesystem(&btrfs_fs_type); |
551 | if (err) | |
552 | goto unregister_ioctl; | |
2f4cbe64 WB |
553 | return 0; |
554 | ||
a9218f6b CM |
555 | unregister_ioctl: |
556 | btrfs_interface_exit(); | |
2f4cbe64 WB |
557 | free_extent_map: |
558 | extent_map_exit(); | |
d1310b2e CM |
559 | free_extent_io: |
560 | extent_io_exit(); | |
2f4cbe64 WB |
561 | free_cachep: |
562 | btrfs_destroy_cachep(); | |
563 | free_transaction_sys: | |
564 | btrfs_exit_transaction_sys(); | |
565 | btrfs_exit_sysfs(); | |
566 | return err; | |
2e635a27 CM |
567 | } |
568 | ||
569 | static void __exit exit_btrfs_fs(void) | |
570 | { | |
08607c1b | 571 | btrfs_exit_transaction_sys(); |
39279cc3 | 572 | btrfs_destroy_cachep(); |
a52d9a80 | 573 | extent_map_exit(); |
d1310b2e | 574 | extent_io_exit(); |
a9218f6b | 575 | btrfs_interface_exit(); |
2e635a27 | 576 | unregister_filesystem(&btrfs_fs_type); |
58176a96 | 577 | btrfs_exit_sysfs(); |
8a4b83cc | 578 | btrfs_cleanup_fs_uuids(); |
2e635a27 CM |
579 | } |
580 | ||
581 | module_init(init_btrfs_fs) | |
582 | module_exit(exit_btrfs_fs) | |
583 | ||
584 | MODULE_LICENSE("GPL"); |