aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@redhat.com>2007-08-29 15:47:34 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-08-29 15:47:34 -0400
commit58176a9604c5db1784d2c979aea472b3be40b6f0 (patch)
treea0d887c81b2f174de619dfefca19674a43756971 /fs/btrfs/disk-io.c
parentb888db2bd7b67f190b32934e6a86181f262ac3ec (diff)
Btrfs: Add per-root block accounting and sysfs entries
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b2f79878d51a..c25ef0a68f18 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -294,9 +294,12 @@ static int __setup_root(int blocksize,
294 root->last_trans = 0; 294 root->last_trans = 0;
295 root->highest_inode = 0; 295 root->highest_inode = 0;
296 root->last_inode_alloc = 0; 296 root->last_inode_alloc = 0;
297 root->name = NULL;
297 memset(&root->root_key, 0, sizeof(root->root_key)); 298 memset(&root->root_key, 0, sizeof(root->root_key));
298 memset(&root->root_item, 0, sizeof(root->root_item)); 299 memset(&root->root_item, 0, sizeof(root->root_item));
299 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); 300 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
301 memset(&root->root_kobj, 0, sizeof(root->root_kobj));
302 init_completion(&root->kobj_unregister);
300 root->defrag_running = 0; 303 root->defrag_running = 0;
301 root->defrag_level = 0; 304 root->defrag_level = 0;
302 root->root_key.objectid = objectid; 305 root->root_key.objectid = objectid;
@@ -384,7 +387,8 @@ insert:
384} 387}
385 388
386struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, 389struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
387 struct btrfs_key *location) 390 struct btrfs_key *location,
391 const char *name, int namelen)
388{ 392{
389 struct btrfs_root *root; 393 struct btrfs_root *root;
390 int ret; 394 int ret;
@@ -405,6 +409,22 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
405 kfree(root); 409 kfree(root);
406 return ERR_PTR(ret); 410 return ERR_PTR(ret);
407 } 411 }
412
413 ret = btrfs_set_root_name(root, name, namelen);
414 if (ret) {
415 brelse(root->node);
416 kfree(root);
417 return ERR_PTR(ret);
418 }
419
420 ret = btrfs_sysfs_add_root(root);
421 if (ret) {
422 brelse(root->node);
423 kfree(root->name);
424 kfree(root);
425 return ERR_PTR(ret);
426 }
427
408 return root; 428 return root;
409} 429}
410 430
@@ -433,6 +453,8 @@ struct btrfs_root *open_ctree(struct super_block *sb)
433 INIT_RADIX_TREE(&fs_info->block_group_data_radix, GFP_KERNEL); 453 INIT_RADIX_TREE(&fs_info->block_group_data_radix, GFP_KERNEL);
434 INIT_LIST_HEAD(&fs_info->trans_list); 454 INIT_LIST_HEAD(&fs_info->trans_list);
435 INIT_LIST_HEAD(&fs_info->dead_roots); 455 INIT_LIST_HEAD(&fs_info->dead_roots);
456 memset(&fs_info->super_kobj, 0, sizeof(fs_info->super_kobj));
457 init_completion(&fs_info->kobj_unregister);
436 sb_set_blocksize(sb, 4096); 458 sb_set_blocksize(sb, 4096);
437 fs_info->running_transaction = NULL; 459 fs_info->running_transaction = NULL;
438 fs_info->last_trans_committed = 0; 460 fs_info->last_trans_committed = 0;
@@ -500,8 +522,10 @@ struct btrfs_root *open_ctree(struct super_block *sb)
500 522
501 fs_info->generation = btrfs_super_generation(disk_super) + 1; 523 fs_info->generation = btrfs_super_generation(disk_super) + 1;
502 ret = btrfs_find_dead_roots(tree_root); 524 ret = btrfs_find_dead_roots(tree_root);
503 if (ret) 525 if (ret) {
526 mutex_unlock(&fs_info->fs_mutex);
504 goto fail_tree_root; 527 goto fail_tree_root;
528 }
505 mutex_unlock(&fs_info->fs_mutex); 529 mutex_unlock(&fs_info->fs_mutex);
506 return tree_root; 530 return tree_root;
507 531
@@ -553,12 +577,15 @@ int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
553{ 577{
554 radix_tree_delete(&fs_info->fs_roots_radix, 578 radix_tree_delete(&fs_info->fs_roots_radix,
555 (unsigned long)root->root_key.objectid); 579 (unsigned long)root->root_key.objectid);
580 btrfs_sysfs_del_root(root);
556 if (root->inode) 581 if (root->inode)
557 iput(root->inode); 582 iput(root->inode);
558 if (root->node) 583 if (root->node)
559 brelse(root->node); 584 brelse(root->node);
560 if (root->commit_root) 585 if (root->commit_root)
561 brelse(root->commit_root); 586 brelse(root->commit_root);
587 if (root->name)
588 kfree(root->name);
562 kfree(root); 589 kfree(root);
563 return 0; 590 return 0;
564} 591}