aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2013-11-01 13:07:04 -0400
committerChris Mason <clm@fb.com>2014-01-28 16:19:29 -0500
commit6ab0a2029ceaedb78af807871820708b7353e3be (patch)
treeec9684534264d7b6d2cc0e6137ad7c7f851b1e88 /fs/btrfs/extent-tree.c
parent01e219e8069516cdb98594d417b8bb8d906ed30d (diff)
btrfs: publish allocation data in sysfs
While trying to debug ENOSPC issues, it's helpful to understand what the kernel's view of the available space is. We export this information via ioctl, but sysfs files are more easily used. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c82
1 files changed, 77 insertions, 5 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d15b4fc07554..e094d02ea76a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -35,6 +35,7 @@
35#include "locking.h" 35#include "locking.h"
36#include "free-space-cache.h" 36#include "free-space-cache.h"
37#include "math.h" 37#include "math.h"
38#include "sysfs.h"
38 39
39#undef SCRAMBLE_DELAYED_REFS 40#undef SCRAMBLE_DELAYED_REFS
40 41
@@ -3408,6 +3409,23 @@ int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr)
3408 return readonly; 3409 return readonly;
3409} 3410}
3410 3411
3412static const char *alloc_name(u64 flags)
3413{
3414 switch (flags) {
3415 case BTRFS_BLOCK_GROUP_METADATA|BTRFS_BLOCK_GROUP_DATA:
3416 return "mixed";
3417 case BTRFS_BLOCK_GROUP_METADATA:
3418 return "metadata";
3419 case BTRFS_BLOCK_GROUP_DATA:
3420 return "data";
3421 case BTRFS_BLOCK_GROUP_SYSTEM:
3422 return "system";
3423 default:
3424 WARN_ON(1);
3425 return "invalid-combination";
3426 };
3427}
3428
3411static int update_space_info(struct btrfs_fs_info *info, u64 flags, 3429static int update_space_info(struct btrfs_fs_info *info, u64 flags,
3412 u64 total_bytes, u64 bytes_used, 3430 u64 total_bytes, u64 bytes_used,
3413 struct btrfs_space_info **space_info) 3431 struct btrfs_space_info **space_info)
@@ -3463,11 +3481,21 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
3463 found->chunk_alloc = 0; 3481 found->chunk_alloc = 0;
3464 found->flush = 0; 3482 found->flush = 0;
3465 init_waitqueue_head(&found->wait); 3483 init_waitqueue_head(&found->wait);
3484
3485 ret = kobject_init_and_add(&found->kobj, &space_info_ktype,
3486 info->space_info_kobj, "%s",
3487 alloc_name(found->flags));
3488 if (ret) {
3489 kfree(found);
3490 return ret;
3491 }
3492
3466 *space_info = found; 3493 *space_info = found;
3467 list_add_rcu(&found->list, &info->space_info); 3494 list_add_rcu(&found->list, &info->space_info);
3468 if (flags & BTRFS_BLOCK_GROUP_DATA) 3495 if (flags & BTRFS_BLOCK_GROUP_DATA)
3469 info->data_sinfo = found; 3496 info->data_sinfo = found;
3470 return 0; 3497
3498 return ret;
3471} 3499}
3472 3500
3473static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) 3501static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
@@ -6152,11 +6180,29 @@ int __get_raid_index(u64 flags)
6152 return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */ 6180 return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
6153} 6181}
6154 6182
6155static int get_block_group_index(struct btrfs_block_group_cache *cache) 6183int get_block_group_index(struct btrfs_block_group_cache *cache)
6156{ 6184{
6157 return __get_raid_index(cache->flags); 6185 return __get_raid_index(cache->flags);
6158} 6186}
6159 6187
6188static const char *btrfs_raid_type_names[BTRFS_NR_RAID_TYPES] = {
6189 [BTRFS_RAID_RAID10] = "raid10",
6190 [BTRFS_RAID_RAID1] = "raid1",
6191 [BTRFS_RAID_DUP] = "dup",
6192 [BTRFS_RAID_RAID0] = "raid0",
6193 [BTRFS_RAID_SINGLE] = "single",
6194 [BTRFS_RAID_RAID5] = "raid5",
6195 [BTRFS_RAID_RAID6] = "raid6",
6196};
6197
6198const char *get_raid_name(enum btrfs_raid_types type)
6199{
6200 if (type >= BTRFS_NR_RAID_TYPES)
6201 return NULL;
6202
6203 return btrfs_raid_type_names[type];
6204}
6205
6160enum btrfs_loop_type { 6206enum btrfs_loop_type {
6161 LOOP_CACHING_NOWAIT = 0, 6207 LOOP_CACHING_NOWAIT = 0,
6162 LOOP_CACHING_WAIT = 1, 6208 LOOP_CACHING_WAIT = 1,
@@ -8340,6 +8386,8 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
8340 release_global_block_rsv(info); 8386 release_global_block_rsv(info);
8341 8387
8342 while (!list_empty(&info->space_info)) { 8388 while (!list_empty(&info->space_info)) {
8389 int i;
8390
8343 space_info = list_entry(info->space_info.next, 8391 space_info = list_entry(info->space_info.next,
8344 struct btrfs_space_info, 8392 struct btrfs_space_info,
8345 list); 8393 list);
@@ -8350,9 +8398,17 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
8350 dump_space_info(space_info, 0, 0); 8398 dump_space_info(space_info, 0, 0);
8351 } 8399 }
8352 } 8400 }
8353 percpu_counter_destroy(&space_info->total_bytes_pinned);
8354 list_del(&space_info->list); 8401 list_del(&space_info->list);
8355 kfree(space_info); 8402 for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
8403 struct kobject *kobj;
8404 kobj = &space_info->block_group_kobjs[i];
8405 if (kobj->parent) {
8406 kobject_del(kobj);
8407 kobject_put(kobj);
8408 }
8409 }
8410 kobject_del(&space_info->kobj);
8411 kobject_put(&space_info->kobj);
8356 } 8412 }
8357 return 0; 8413 return 0;
8358} 8414}
@@ -8363,6 +8419,19 @@ static void __link_block_group(struct btrfs_space_info *space_info,
8363 int index = get_block_group_index(cache); 8419 int index = get_block_group_index(cache);
8364 8420
8365 down_write(&space_info->groups_sem); 8421 down_write(&space_info->groups_sem);
8422 if (list_empty(&space_info->block_groups[index])) {
8423 struct kobject *kobj = &space_info->block_group_kobjs[index];
8424 int ret;
8425
8426 kobject_get(&space_info->kobj); /* put in release */
8427 ret = kobject_init_and_add(kobj, &btrfs_raid_ktype,
8428 &space_info->kobj,
8429 get_raid_name(index));
8430 if (ret) {
8431 pr_warn("btrfs: failed to add kobject for block cache. ignoring.\n");
8432 kobject_put(&space_info->kobj);
8433 }
8434 }
8366 list_add_tail(&cache->list, &space_info->block_groups[index]); 8435 list_add_tail(&cache->list, &space_info->block_groups[index]);
8367 up_write(&space_info->groups_sem); 8436 up_write(&space_info->groups_sem);
8368} 8437}
@@ -8803,8 +8872,11 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
8803 * are still on the list after taking the semaphore 8872 * are still on the list after taking the semaphore
8804 */ 8873 */
8805 list_del_init(&block_group->list); 8874 list_del_init(&block_group->list);
8806 if (list_empty(&block_group->space_info->block_groups[index])) 8875 if (list_empty(&block_group->space_info->block_groups[index])) {
8876 kobject_del(&block_group->space_info->block_group_kobjs[index]);
8877 kobject_put(&block_group->space_info->block_group_kobjs[index]);
8807 clear_avail_alloc_bits(root->fs_info, block_group->flags); 8878 clear_avail_alloc_bits(root->fs_info, block_group->flags);
8879 }
8808 up_write(&block_group->space_info->groups_sem); 8880 up_write(&block_group->space_info->groups_sem);
8809 8881
8810 if (block_group->cached == BTRFS_CACHE_STARTED) 8882 if (block_group->cached == BTRFS_CACHE_STARTED)