diff options
Diffstat (limited to 'fs/btrfs/super.c')
-rw-r--r-- | fs/btrfs/super.c | 279 |
1 files changed, 203 insertions, 76 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 752a5463bf53..1866dff0538e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/namei.h> | 38 | #include <linux/namei.h> |
39 | #include <linux/miscdevice.h> | 39 | #include <linux/miscdevice.h> |
40 | #include <linux/magic.h> | 40 | #include <linux/magic.h> |
41 | #include <linux/slab.h> | ||
41 | #include "compat.h" | 42 | #include "compat.h" |
42 | #include "ctree.h" | 43 | #include "ctree.h" |
43 | #include "disk-io.h" | 44 | #include "disk-io.h" |
@@ -63,25 +64,26 @@ static void btrfs_put_super(struct super_block *sb) | |||
63 | } | 64 | } |
64 | 65 | ||
65 | enum { | 66 | enum { |
66 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, | 67 | Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum, |
67 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, | 68 | Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd, |
68 | Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, | 69 | Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress, |
69 | Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit, | 70 | Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit, |
70 | Opt_discard, Opt_err, | 71 | Opt_discard, Opt_err, |
71 | }; | 72 | }; |
72 | 73 | ||
73 | static match_table_t tokens = { | 74 | static match_table_t tokens = { |
74 | {Opt_degraded, "degraded"}, | 75 | {Opt_degraded, "degraded"}, |
75 | {Opt_subvol, "subvol=%s"}, | 76 | {Opt_subvol, "subvol=%s"}, |
77 | {Opt_subvolid, "subvolid=%d"}, | ||
76 | {Opt_device, "device=%s"}, | 78 | {Opt_device, "device=%s"}, |
77 | {Opt_nodatasum, "nodatasum"}, | 79 | {Opt_nodatasum, "nodatasum"}, |
78 | {Opt_nodatacow, "nodatacow"}, | 80 | {Opt_nodatacow, "nodatacow"}, |
79 | {Opt_nobarrier, "nobarrier"}, | 81 | {Opt_nobarrier, "nobarrier"}, |
80 | {Opt_max_extent, "max_extent=%s"}, | ||
81 | {Opt_max_inline, "max_inline=%s"}, | 82 | {Opt_max_inline, "max_inline=%s"}, |
82 | {Opt_alloc_start, "alloc_start=%s"}, | 83 | {Opt_alloc_start, "alloc_start=%s"}, |
83 | {Opt_thread_pool, "thread_pool=%d"}, | 84 | {Opt_thread_pool, "thread_pool=%d"}, |
84 | {Opt_compress, "compress"}, | 85 | {Opt_compress, "compress"}, |
86 | {Opt_compress_force, "compress-force"}, | ||
85 | {Opt_ssd, "ssd"}, | 87 | {Opt_ssd, "ssd"}, |
86 | {Opt_ssd_spread, "ssd_spread"}, | 88 | {Opt_ssd_spread, "ssd_spread"}, |
87 | {Opt_nossd, "nossd"}, | 89 | {Opt_nossd, "nossd"}, |
@@ -93,31 +95,6 @@ static match_table_t tokens = { | |||
93 | {Opt_err, NULL}, | 95 | {Opt_err, NULL}, |
94 | }; | 96 | }; |
95 | 97 | ||
96 | u64 btrfs_parse_size(char *str) | ||
97 | { | ||
98 | u64 res; | ||
99 | int mult = 1; | ||
100 | char *end; | ||
101 | char last; | ||
102 | |||
103 | res = simple_strtoul(str, &end, 10); | ||
104 | |||
105 | last = end[0]; | ||
106 | if (isalpha(last)) { | ||
107 | last = tolower(last); | ||
108 | switch (last) { | ||
109 | case 'g': | ||
110 | mult *= 1024; | ||
111 | case 'm': | ||
112 | mult *= 1024; | ||
113 | case 'k': | ||
114 | mult *= 1024; | ||
115 | } | ||
116 | res = res * mult; | ||
117 | } | ||
118 | return res; | ||
119 | } | ||
120 | |||
121 | /* | 98 | /* |
122 | * Regular mount options parser. Everything that is needed only when | 99 | * Regular mount options parser. Everything that is needed only when |
123 | * reading in a new superblock is parsed here. | 100 | * reading in a new superblock is parsed here. |
@@ -126,8 +103,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
126 | { | 103 | { |
127 | struct btrfs_fs_info *info = root->fs_info; | 104 | struct btrfs_fs_info *info = root->fs_info; |
128 | substring_t args[MAX_OPT_ARGS]; | 105 | substring_t args[MAX_OPT_ARGS]; |
129 | char *p, *num; | 106 | char *p, *num, *orig; |
130 | int intarg; | 107 | int intarg; |
108 | int ret = 0; | ||
131 | 109 | ||
132 | if (!options) | 110 | if (!options) |
133 | return 0; | 111 | return 0; |
@@ -140,6 +118,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
140 | if (!options) | 118 | if (!options) |
141 | return -ENOMEM; | 119 | return -ENOMEM; |
142 | 120 | ||
121 | orig = options; | ||
143 | 122 | ||
144 | while ((p = strsep(&options, ",")) != NULL) { | 123 | while ((p = strsep(&options, ",")) != NULL) { |
145 | int token; | 124 | int token; |
@@ -153,6 +132,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
153 | btrfs_set_opt(info->mount_opt, DEGRADED); | 132 | btrfs_set_opt(info->mount_opt, DEGRADED); |
154 | break; | 133 | break; |
155 | case Opt_subvol: | 134 | case Opt_subvol: |
135 | case Opt_subvolid: | ||
156 | case Opt_device: | 136 | case Opt_device: |
157 | /* | 137 | /* |
158 | * These are parsed by btrfs_parse_early_options | 138 | * These are parsed by btrfs_parse_early_options |
@@ -172,6 +152,11 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
172 | printk(KERN_INFO "btrfs: use compression\n"); | 152 | printk(KERN_INFO "btrfs: use compression\n"); |
173 | btrfs_set_opt(info->mount_opt, COMPRESS); | 153 | btrfs_set_opt(info->mount_opt, COMPRESS); |
174 | break; | 154 | break; |
155 | case Opt_compress_force: | ||
156 | printk(KERN_INFO "btrfs: forcing compression\n"); | ||
157 | btrfs_set_opt(info->mount_opt, FORCE_COMPRESS); | ||
158 | btrfs_set_opt(info->mount_opt, COMPRESS); | ||
159 | break; | ||
175 | case Opt_ssd: | 160 | case Opt_ssd: |
176 | printk(KERN_INFO "btrfs: use ssd allocation scheme\n"); | 161 | printk(KERN_INFO "btrfs: use ssd allocation scheme\n"); |
177 | btrfs_set_opt(info->mount_opt, SSD); | 162 | btrfs_set_opt(info->mount_opt, SSD); |
@@ -202,22 +187,10 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
202 | info->thread_pool_size); | 187 | info->thread_pool_size); |
203 | } | 188 | } |
204 | break; | 189 | break; |
205 | case Opt_max_extent: | ||
206 | num = match_strdup(&args[0]); | ||
207 | if (num) { | ||
208 | info->max_extent = btrfs_parse_size(num); | ||
209 | kfree(num); | ||
210 | |||
211 | info->max_extent = max_t(u64, | ||
212 | info->max_extent, root->sectorsize); | ||
213 | printk(KERN_INFO "btrfs: max_extent at %llu\n", | ||
214 | (unsigned long long)info->max_extent); | ||
215 | } | ||
216 | break; | ||
217 | case Opt_max_inline: | 190 | case Opt_max_inline: |
218 | num = match_strdup(&args[0]); | 191 | num = match_strdup(&args[0]); |
219 | if (num) { | 192 | if (num) { |
220 | info->max_inline = btrfs_parse_size(num); | 193 | info->max_inline = memparse(num, NULL); |
221 | kfree(num); | 194 | kfree(num); |
222 | 195 | ||
223 | if (info->max_inline) { | 196 | if (info->max_inline) { |
@@ -232,7 +205,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
232 | case Opt_alloc_start: | 205 | case Opt_alloc_start: |
233 | num = match_strdup(&args[0]); | 206 | num = match_strdup(&args[0]); |
234 | if (num) { | 207 | if (num) { |
235 | info->alloc_start = btrfs_parse_size(num); | 208 | info->alloc_start = memparse(num, NULL); |
236 | kfree(num); | 209 | kfree(num); |
237 | printk(KERN_INFO | 210 | printk(KERN_INFO |
238 | "btrfs: allocations start at %llu\n", | 211 | "btrfs: allocations start at %llu\n", |
@@ -262,12 +235,18 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
262 | case Opt_discard: | 235 | case Opt_discard: |
263 | btrfs_set_opt(info->mount_opt, DISCARD); | 236 | btrfs_set_opt(info->mount_opt, DISCARD); |
264 | break; | 237 | break; |
238 | case Opt_err: | ||
239 | printk(KERN_INFO "btrfs: unrecognized mount option " | ||
240 | "'%s'\n", p); | ||
241 | ret = -EINVAL; | ||
242 | goto out; | ||
265 | default: | 243 | default: |
266 | break; | 244 | break; |
267 | } | 245 | } |
268 | } | 246 | } |
269 | kfree(options); | 247 | out: |
270 | return 0; | 248 | kfree(orig); |
249 | return ret; | ||
271 | } | 250 | } |
272 | 251 | ||
273 | /* | 252 | /* |
@@ -277,12 +256,13 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
277 | * only when we need to allocate a new super block. | 256 | * only when we need to allocate a new super block. |
278 | */ | 257 | */ |
279 | static int btrfs_parse_early_options(const char *options, fmode_t flags, | 258 | static int btrfs_parse_early_options(const char *options, fmode_t flags, |
280 | void *holder, char **subvol_name, | 259 | void *holder, char **subvol_name, u64 *subvol_objectid, |
281 | struct btrfs_fs_devices **fs_devices) | 260 | struct btrfs_fs_devices **fs_devices) |
282 | { | 261 | { |
283 | substring_t args[MAX_OPT_ARGS]; | 262 | substring_t args[MAX_OPT_ARGS]; |
284 | char *opts, *p; | 263 | char *opts, *p; |
285 | int error = 0; | 264 | int error = 0; |
265 | int intarg; | ||
286 | 266 | ||
287 | if (!options) | 267 | if (!options) |
288 | goto out; | 268 | goto out; |
@@ -305,6 +285,18 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, | |||
305 | case Opt_subvol: | 285 | case Opt_subvol: |
306 | *subvol_name = match_strdup(&args[0]); | 286 | *subvol_name = match_strdup(&args[0]); |
307 | break; | 287 | break; |
288 | case Opt_subvolid: | ||
289 | intarg = 0; | ||
290 | error = match_int(&args[0], &intarg); | ||
291 | if (!error) { | ||
292 | /* we want the original fs_tree */ | ||
293 | if (!intarg) | ||
294 | *subvol_objectid = | ||
295 | BTRFS_FS_TREE_OBJECTID; | ||
296 | else | ||
297 | *subvol_objectid = intarg; | ||
298 | } | ||
299 | break; | ||
308 | case Opt_device: | 300 | case Opt_device: |
309 | error = btrfs_scan_one_device(match_strdup(&args[0]), | 301 | error = btrfs_scan_one_device(match_strdup(&args[0]), |
310 | flags, holder, fs_devices); | 302 | flags, holder, fs_devices); |
@@ -332,6 +324,110 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, | |||
332 | return error; | 324 | return error; |
333 | } | 325 | } |
334 | 326 | ||
327 | static struct dentry *get_default_root(struct super_block *sb, | ||
328 | u64 subvol_objectid) | ||
329 | { | ||
330 | struct btrfs_root *root = sb->s_fs_info; | ||
331 | struct btrfs_root *new_root; | ||
332 | struct btrfs_dir_item *di; | ||
333 | struct btrfs_path *path; | ||
334 | struct btrfs_key location; | ||
335 | struct inode *inode; | ||
336 | struct dentry *dentry; | ||
337 | u64 dir_id; | ||
338 | int new = 0; | ||
339 | |||
340 | /* | ||
341 | * We have a specific subvol we want to mount, just setup location and | ||
342 | * go look up the root. | ||
343 | */ | ||
344 | if (subvol_objectid) { | ||
345 | location.objectid = subvol_objectid; | ||
346 | location.type = BTRFS_ROOT_ITEM_KEY; | ||
347 | location.offset = (u64)-1; | ||
348 | goto find_root; | ||
349 | } | ||
350 | |||
351 | path = btrfs_alloc_path(); | ||
352 | if (!path) | ||
353 | return ERR_PTR(-ENOMEM); | ||
354 | path->leave_spinning = 1; | ||
355 | |||
356 | /* | ||
357 | * Find the "default" dir item which points to the root item that we | ||
358 | * will mount by default if we haven't been given a specific subvolume | ||
359 | * to mount. | ||
360 | */ | ||
361 | dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); | ||
362 | di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0); | ||
363 | if (!di) { | ||
364 | /* | ||
365 | * Ok the default dir item isn't there. This is weird since | ||
366 | * it's always been there, but don't freak out, just try and | ||
367 | * mount to root most subvolume. | ||
368 | */ | ||
369 | btrfs_free_path(path); | ||
370 | dir_id = BTRFS_FIRST_FREE_OBJECTID; | ||
371 | new_root = root->fs_info->fs_root; | ||
372 | goto setup_root; | ||
373 | } | ||
374 | |||
375 | btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); | ||
376 | btrfs_free_path(path); | ||
377 | |||
378 | find_root: | ||
379 | new_root = btrfs_read_fs_root_no_name(root->fs_info, &location); | ||
380 | if (IS_ERR(new_root)) | ||
381 | return ERR_PTR(PTR_ERR(new_root)); | ||
382 | |||
383 | if (btrfs_root_refs(&new_root->root_item) == 0) | ||
384 | return ERR_PTR(-ENOENT); | ||
385 | |||
386 | dir_id = btrfs_root_dirid(&new_root->root_item); | ||
387 | setup_root: | ||
388 | location.objectid = dir_id; | ||
389 | location.type = BTRFS_INODE_ITEM_KEY; | ||
390 | location.offset = 0; | ||
391 | |||
392 | inode = btrfs_iget(sb, &location, new_root, &new); | ||
393 | if (!inode) | ||
394 | return ERR_PTR(-ENOMEM); | ||
395 | |||
396 | /* | ||
397 | * If we're just mounting the root most subvol put the inode and return | ||
398 | * a reference to the dentry. We will have already gotten a reference | ||
399 | * to the inode in btrfs_fill_super so we're good to go. | ||
400 | */ | ||
401 | if (!new && sb->s_root->d_inode == inode) { | ||
402 | iput(inode); | ||
403 | return dget(sb->s_root); | ||
404 | } | ||
405 | |||
406 | if (new) { | ||
407 | const struct qstr name = { .name = "/", .len = 1 }; | ||
408 | |||
409 | /* | ||
410 | * New inode, we need to make the dentry a sibling of s_root so | ||
411 | * everything gets cleaned up properly on unmount. | ||
412 | */ | ||
413 | dentry = d_alloc(sb->s_root, &name); | ||
414 | if (!dentry) { | ||
415 | iput(inode); | ||
416 | return ERR_PTR(-ENOMEM); | ||
417 | } | ||
418 | d_splice_alias(inode, dentry); | ||
419 | } else { | ||
420 | /* | ||
421 | * We found the inode in cache, just find a dentry for it and | ||
422 | * put the reference to the inode we just got. | ||
423 | */ | ||
424 | dentry = d_find_alias(inode); | ||
425 | iput(inode); | ||
426 | } | ||
427 | |||
428 | return dentry; | ||
429 | } | ||
430 | |||
335 | static int btrfs_fill_super(struct super_block *sb, | 431 | static int btrfs_fill_super(struct super_block *sb, |
336 | struct btrfs_fs_devices *fs_devices, | 432 | struct btrfs_fs_devices *fs_devices, |
337 | void *data, int silent) | 433 | void *data, int silent) |
@@ -365,7 +461,7 @@ static int btrfs_fill_super(struct super_block *sb, | |||
365 | key.objectid = BTRFS_FIRST_FREE_OBJECTID; | 461 | key.objectid = BTRFS_FIRST_FREE_OBJECTID; |
366 | key.type = BTRFS_INODE_ITEM_KEY; | 462 | key.type = BTRFS_INODE_ITEM_KEY; |
367 | key.offset = 0; | 463 | key.offset = 0; |
368 | inode = btrfs_iget(sb, &key, tree_root->fs_info->fs_root); | 464 | inode = btrfs_iget(sb, &key, tree_root->fs_info->fs_root, NULL); |
369 | if (IS_ERR(inode)) { | 465 | if (IS_ERR(inode)) { |
370 | err = PTR_ERR(inode); | 466 | err = PTR_ERR(inode); |
371 | goto fail_close; | 467 | goto fail_close; |
@@ -377,12 +473,6 @@ static int btrfs_fill_super(struct super_block *sb, | |||
377 | err = -ENOMEM; | 473 | err = -ENOMEM; |
378 | goto fail_close; | 474 | goto fail_close; |
379 | } | 475 | } |
380 | #if 0 | ||
381 | /* this does the super kobj at the same time */ | ||
382 | err = btrfs_sysfs_add_super(tree_root->fs_info); | ||
383 | if (err) | ||
384 | goto fail_close; | ||
385 | #endif | ||
386 | 476 | ||
387 | sb->s_root = root_dentry; | 477 | sb->s_root = root_dentry; |
388 | 478 | ||
@@ -405,8 +495,8 @@ int btrfs_sync_fs(struct super_block *sb, int wait) | |||
405 | return 0; | 495 | return 0; |
406 | } | 496 | } |
407 | 497 | ||
408 | btrfs_start_delalloc_inodes(root); | 498 | btrfs_start_delalloc_inodes(root, 0); |
409 | btrfs_wait_ordered_extents(root, 0); | 499 | btrfs_wait_ordered_extents(root, 0, 0); |
410 | 500 | ||
411 | trans = btrfs_start_transaction(root, 1); | 501 | trans = btrfs_start_transaction(root, 1); |
412 | ret = btrfs_commit_transaction(trans, root); | 502 | ret = btrfs_commit_transaction(trans, root); |
@@ -426,9 +516,6 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
426 | seq_puts(seq, ",nodatacow"); | 516 | seq_puts(seq, ",nodatacow"); |
427 | if (btrfs_test_opt(root, NOBARRIER)) | 517 | if (btrfs_test_opt(root, NOBARRIER)) |
428 | seq_puts(seq, ",nobarrier"); | 518 | seq_puts(seq, ",nobarrier"); |
429 | if (info->max_extent != (u64)-1) | ||
430 | seq_printf(seq, ",max_extent=%llu", | ||
431 | (unsigned long long)info->max_extent); | ||
432 | if (info->max_inline != 8192 * 1024) | 519 | if (info->max_inline != 8192 * 1024) |
433 | seq_printf(seq, ",max_inline=%llu", | 520 | seq_printf(seq, ",max_inline=%llu", |
434 | (unsigned long long)info->max_inline); | 521 | (unsigned long long)info->max_inline); |
@@ -450,6 +537,8 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
450 | seq_puts(seq, ",notreelog"); | 537 | seq_puts(seq, ",notreelog"); |
451 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) | 538 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) |
452 | seq_puts(seq, ",flushoncommit"); | 539 | seq_puts(seq, ",flushoncommit"); |
540 | if (btrfs_test_opt(root, DISCARD)) | ||
541 | seq_puts(seq, ",discard"); | ||
453 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) | 542 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) |
454 | seq_puts(seq, ",noacl"); | 543 | seq_puts(seq, ",noacl"); |
455 | return 0; | 544 | return 0; |
@@ -472,19 +561,22 @@ static int btrfs_test_super(struct super_block *s, void *data) | |||
472 | static int btrfs_get_sb(struct file_system_type *fs_type, int flags, | 561 | static int btrfs_get_sb(struct file_system_type *fs_type, int flags, |
473 | const char *dev_name, void *data, struct vfsmount *mnt) | 562 | const char *dev_name, void *data, struct vfsmount *mnt) |
474 | { | 563 | { |
475 | char *subvol_name = NULL; | ||
476 | struct block_device *bdev = NULL; | 564 | struct block_device *bdev = NULL; |
477 | struct super_block *s; | 565 | struct super_block *s; |
478 | struct dentry *root; | 566 | struct dentry *root; |
479 | struct btrfs_fs_devices *fs_devices = NULL; | 567 | struct btrfs_fs_devices *fs_devices = NULL; |
480 | fmode_t mode = FMODE_READ; | 568 | fmode_t mode = FMODE_READ; |
569 | char *subvol_name = NULL; | ||
570 | u64 subvol_objectid = 0; | ||
481 | int error = 0; | 571 | int error = 0; |
572 | int found = 0; | ||
482 | 573 | ||
483 | if (!(flags & MS_RDONLY)) | 574 | if (!(flags & MS_RDONLY)) |
484 | mode |= FMODE_WRITE; | 575 | mode |= FMODE_WRITE; |
485 | 576 | ||
486 | error = btrfs_parse_early_options(data, mode, fs_type, | 577 | error = btrfs_parse_early_options(data, mode, fs_type, |
487 | &subvol_name, &fs_devices); | 578 | &subvol_name, &subvol_objectid, |
579 | &fs_devices); | ||
488 | if (error) | 580 | if (error) |
489 | return error; | 581 | return error; |
490 | 582 | ||
@@ -513,6 +605,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, | |||
513 | goto error_close_devices; | 605 | goto error_close_devices; |
514 | } | 606 | } |
515 | 607 | ||
608 | found = 1; | ||
516 | btrfs_close_devices(fs_devices); | 609 | btrfs_close_devices(fs_devices); |
517 | } else { | 610 | } else { |
518 | char b[BDEVNAME_SIZE]; | 611 | char b[BDEVNAME_SIZE]; |
@@ -530,25 +623,35 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, | |||
530 | s->s_flags |= MS_ACTIVE; | 623 | s->s_flags |= MS_ACTIVE; |
531 | } | 624 | } |
532 | 625 | ||
533 | if (!strcmp(subvol_name, ".")) | 626 | root = get_default_root(s, subvol_objectid); |
534 | root = dget(s->s_root); | 627 | if (IS_ERR(root)) { |
535 | else { | 628 | error = PTR_ERR(root); |
536 | mutex_lock(&s->s_root->d_inode->i_mutex); | 629 | deactivate_locked_super(s); |
537 | root = lookup_one_len(subvol_name, s->s_root, | 630 | goto error; |
631 | } | ||
632 | /* if they gave us a subvolume name bind mount into that */ | ||
633 | if (strcmp(subvol_name, ".")) { | ||
634 | struct dentry *new_root; | ||
635 | mutex_lock(&root->d_inode->i_mutex); | ||
636 | new_root = lookup_one_len(subvol_name, root, | ||
538 | strlen(subvol_name)); | 637 | strlen(subvol_name)); |
539 | mutex_unlock(&s->s_root->d_inode->i_mutex); | 638 | mutex_unlock(&root->d_inode->i_mutex); |
540 | 639 | ||
541 | if (IS_ERR(root)) { | 640 | if (IS_ERR(new_root)) { |
542 | deactivate_locked_super(s); | 641 | deactivate_locked_super(s); |
543 | error = PTR_ERR(root); | 642 | error = PTR_ERR(new_root); |
544 | goto error_free_subvol_name; | 643 | dput(root); |
644 | goto error_close_devices; | ||
545 | } | 645 | } |
546 | if (!root->d_inode) { | 646 | if (!new_root->d_inode) { |
547 | dput(root); | 647 | dput(root); |
648 | dput(new_root); | ||
548 | deactivate_locked_super(s); | 649 | deactivate_locked_super(s); |
549 | error = -ENXIO; | 650 | error = -ENXIO; |
550 | goto error_free_subvol_name; | 651 | goto error_close_devices; |
551 | } | 652 | } |
653 | dput(root); | ||
654 | root = new_root; | ||
552 | } | 655 | } |
553 | 656 | ||
554 | mnt->mnt_sb = s; | 657 | mnt->mnt_sb = s; |
@@ -563,6 +666,7 @@ error_close_devices: | |||
563 | btrfs_close_devices(fs_devices); | 666 | btrfs_close_devices(fs_devices); |
564 | error_free_subvol_name: | 667 | error_free_subvol_name: |
565 | kfree(subvol_name); | 668 | kfree(subvol_name); |
669 | error: | ||
566 | return error; | 670 | return error; |
567 | } | 671 | } |
568 | 672 | ||
@@ -607,14 +711,37 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
607 | { | 711 | { |
608 | struct btrfs_root *root = btrfs_sb(dentry->d_sb); | 712 | struct btrfs_root *root = btrfs_sb(dentry->d_sb); |
609 | struct btrfs_super_block *disk_super = &root->fs_info->super_copy; | 713 | struct btrfs_super_block *disk_super = &root->fs_info->super_copy; |
714 | struct list_head *head = &root->fs_info->space_info; | ||
715 | struct btrfs_space_info *found; | ||
716 | u64 total_used = 0; | ||
717 | u64 data_used = 0; | ||
610 | int bits = dentry->d_sb->s_blocksize_bits; | 718 | int bits = dentry->d_sb->s_blocksize_bits; |
611 | __be32 *fsid = (__be32 *)root->fs_info->fsid; | 719 | __be32 *fsid = (__be32 *)root->fs_info->fsid; |
612 | 720 | ||
721 | rcu_read_lock(); | ||
722 | list_for_each_entry_rcu(found, head, list) { | ||
723 | if (found->flags & (BTRFS_BLOCK_GROUP_DUP| | ||
724 | BTRFS_BLOCK_GROUP_RAID10| | ||
725 | BTRFS_BLOCK_GROUP_RAID1)) { | ||
726 | total_used += found->bytes_used; | ||
727 | if (found->flags & BTRFS_BLOCK_GROUP_DATA) | ||
728 | data_used += found->bytes_used; | ||
729 | else | ||
730 | data_used += found->total_bytes; | ||
731 | } | ||
732 | |||
733 | total_used += found->bytes_used; | ||
734 | if (found->flags & BTRFS_BLOCK_GROUP_DATA) | ||
735 | data_used += found->bytes_used; | ||
736 | else | ||
737 | data_used += found->total_bytes; | ||
738 | } | ||
739 | rcu_read_unlock(); | ||
740 | |||
613 | buf->f_namelen = BTRFS_NAME_LEN; | 741 | buf->f_namelen = BTRFS_NAME_LEN; |
614 | buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; | 742 | buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; |
615 | buf->f_bfree = buf->f_blocks - | 743 | buf->f_bfree = buf->f_blocks - (total_used >> bits); |
616 | (btrfs_super_bytes_used(disk_super) >> bits); | 744 | buf->f_bavail = buf->f_blocks - (data_used >> bits); |
617 | buf->f_bavail = buf->f_bfree; | ||
618 | buf->f_bsize = dentry->d_sb->s_blocksize; | 745 | buf->f_bsize = dentry->d_sb->s_blocksize; |
619 | buf->f_type = BTRFS_SUPER_MAGIC; | 746 | buf->f_type = BTRFS_SUPER_MAGIC; |
620 | 747 | ||