diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-04-10 12:13:09 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-04-10 12:13:09 -0400 |
commit | 1b05da2ee6217e7d55460d04335813fec25be4ca (patch) | |
tree | 250a3e789777c7a6d17dccf0bf5a57b00ef1bdac /fs/btrfs/super.c | |
parent | c5739bba5260a59cebd20a51a55080592c8d3b07 (diff) |
Btrfs: drop the inode map tree
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/super.c')
-rw-r--r-- | fs/btrfs/super.c | 89 |
1 files changed, 13 insertions, 76 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index bbe5cabcb42e..3e8bfb0e5d7e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -45,14 +45,6 @@ static struct inode_operations btrfs_file_inode_operations; | |||
45 | static struct address_space_operations btrfs_aops; | 45 | static struct address_space_operations btrfs_aops; |
46 | static struct file_operations btrfs_file_operations; | 46 | static struct file_operations btrfs_file_operations; |
47 | 47 | ||
48 | static int check_inode(struct inode *inode) | ||
49 | { | ||
50 | struct btrfs_inode *ei = BTRFS_I(inode); | ||
51 | WARN_ON(ei->magic != 0xDEADBEEF); | ||
52 | WARN_ON(ei->magic2 != 0xDEADBEAF); | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | static void btrfs_read_locked_inode(struct inode *inode) | 48 | static void btrfs_read_locked_inode(struct inode *inode) |
57 | { | 49 | { |
58 | struct btrfs_path *path; | 50 | struct btrfs_path *path; |
@@ -66,15 +58,12 @@ static void btrfs_read_locked_inode(struct inode *inode) | |||
66 | btrfs_init_path(path); | 58 | btrfs_init_path(path); |
67 | mutex_lock(&root->fs_info->fs_mutex); | 59 | mutex_lock(&root->fs_info->fs_mutex); |
68 | 60 | ||
69 | check_inode(inode); | ||
70 | |||
71 | memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); | 61 | memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); |
72 | ret = btrfs_lookup_inode(NULL, root, path, &location, 0); | 62 | ret = btrfs_lookup_inode(NULL, root, path, &location, 0); |
73 | if (ret) { | 63 | if (ret) { |
74 | btrfs_free_path(path); | 64 | btrfs_free_path(path); |
75 | goto make_bad; | 65 | goto make_bad; |
76 | } | 66 | } |
77 | check_inode(inode); | ||
78 | inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), | 67 | inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), |
79 | path->slots[0], | 68 | path->slots[0], |
80 | struct btrfs_inode_item); | 69 | struct btrfs_inode_item); |
@@ -97,7 +86,7 @@ static void btrfs_read_locked_inode(struct inode *inode) | |||
97 | inode_item = NULL; | 86 | inode_item = NULL; |
98 | 87 | ||
99 | mutex_unlock(&root->fs_info->fs_mutex); | 88 | mutex_unlock(&root->fs_info->fs_mutex); |
100 | check_inode(inode); | 89 | |
101 | switch (inode->i_mode & S_IFMT) { | 90 | switch (inode->i_mode & S_IFMT) { |
102 | #if 0 | 91 | #if 0 |
103 | default: | 92 | default: |
@@ -121,7 +110,6 @@ static void btrfs_read_locked_inode(struct inode *inode) | |||
121 | // inode->i_op = &page_symlink_inode_operations; | 110 | // inode->i_op = &page_symlink_inode_operations; |
122 | break; | 111 | break; |
123 | } | 112 | } |
124 | check_inode(inode); | ||
125 | return; | 113 | return; |
126 | 114 | ||
127 | make_bad: | 115 | make_bad: |
@@ -272,10 +260,7 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans, | |||
272 | struct btrfs_root *root, | 260 | struct btrfs_root *root, |
273 | struct inode *inode) | 261 | struct inode *inode) |
274 | { | 262 | { |
275 | u64 objectid = inode->i_ino; | ||
276 | struct btrfs_path *path; | 263 | struct btrfs_path *path; |
277 | struct btrfs_inode_map_item *map; | ||
278 | struct btrfs_key stat_data_key; | ||
279 | int ret; | 264 | int ret; |
280 | 265 | ||
281 | clear_inode(inode); | 266 | clear_inode(inode); |
@@ -283,26 +268,11 @@ static int btrfs_free_inode(struct btrfs_trans_handle *trans, | |||
283 | path = btrfs_alloc_path(); | 268 | path = btrfs_alloc_path(); |
284 | BUG_ON(!path); | 269 | BUG_ON(!path); |
285 | btrfs_init_path(path); | 270 | btrfs_init_path(path); |
286 | ret = btrfs_lookup_inode_map(trans, root, path, objectid, -1); | ||
287 | if (ret) { | ||
288 | if (ret > 0) | ||
289 | ret = -ENOENT; | ||
290 | goto error; | ||
291 | } | ||
292 | map = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]), path->slots[0], | ||
293 | struct btrfs_inode_map_item); | ||
294 | btrfs_disk_key_to_cpu(&stat_data_key, &map->key); | ||
295 | ret = btrfs_del_item(trans, root->fs_info->inode_root, path); | ||
296 | BUG_ON(ret); | ||
297 | btrfs_release_path(root, path); | ||
298 | |||
299 | ret = btrfs_lookup_inode(trans, root, path, | 271 | ret = btrfs_lookup_inode(trans, root, path, |
300 | &BTRFS_I(inode)->location, -1); | 272 | &BTRFS_I(inode)->location, -1); |
301 | BUG_ON(ret); | 273 | BUG_ON(ret); |
302 | ret = btrfs_del_item(trans, root, path); | 274 | ret = btrfs_del_item(trans, root, path); |
303 | BUG_ON(ret); | 275 | BUG_ON(ret); |
304 | error: | ||
305 | btrfs_release_path(root, path); | ||
306 | btrfs_free_path(path); | 276 | btrfs_free_path(path); |
307 | return ret; | 277 | return ret; |
308 | } | 278 | } |
@@ -432,7 +402,6 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, | |||
432 | out: | 402 | out: |
433 | btrfs_release_path(root, path); | 403 | btrfs_release_path(root, path); |
434 | btrfs_free_path(path); | 404 | btrfs_free_path(path); |
435 | check_inode(dir); | ||
436 | return ret; | 405 | return ret; |
437 | } | 406 | } |
438 | 407 | ||
@@ -540,9 +509,7 @@ printk("adding new root for inode %lu root %p (found %p)\n", inode->i_ino, sub_r | |||
540 | btrfs_read_locked_inode(inode); | 509 | btrfs_read_locked_inode(inode); |
541 | unlock_new_inode(inode); | 510 | unlock_new_inode(inode); |
542 | } | 511 | } |
543 | check_inode(inode); | ||
544 | } | 512 | } |
545 | check_inode(dir); | ||
546 | return d_splice_alias(inode, dentry); | 513 | return d_splice_alias(inode, dentry); |
547 | } | 514 | } |
548 | 515 | ||
@@ -566,7 +533,6 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
566 | /* FIXME, use a real flag for deciding about the key type */ | 533 | /* FIXME, use a real flag for deciding about the key type */ |
567 | if (root->fs_info->tree_root == root) | 534 | if (root->fs_info->tree_root == root) |
568 | key_type = BTRFS_DIR_ITEM_KEY; | 535 | key_type = BTRFS_DIR_ITEM_KEY; |
569 | |||
570 | mutex_lock(&root->fs_info->fs_mutex); | 536 | mutex_lock(&root->fs_info->fs_mutex); |
571 | key.objectid = inode->i_ino; | 537 | key.objectid = inode->i_ino; |
572 | key.flags = 0; | 538 | key.flags = 0; |
@@ -575,9 +541,8 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
575 | path = btrfs_alloc_path(); | 541 | path = btrfs_alloc_path(); |
576 | btrfs_init_path(path); | 542 | btrfs_init_path(path); |
577 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); | 543 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); |
578 | if (ret < 0) { | 544 | if (ret < 0) |
579 | goto err; | 545 | goto err; |
580 | } | ||
581 | advance = 0; | 546 | advance = 0; |
582 | while(1) { | 547 | while(1) { |
583 | leaf = btrfs_buffer_leaf(path->nodes[0]); | 548 | leaf = btrfs_buffer_leaf(path->nodes[0]); |
@@ -601,8 +566,7 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
601 | if (btrfs_disk_key_objectid(&item->key) != key.objectid) | 566 | if (btrfs_disk_key_objectid(&item->key) != key.objectid) |
602 | break; | 567 | break; |
603 | if (key_type == BTRFS_DIR_INDEX_KEY && | 568 | if (key_type == BTRFS_DIR_INDEX_KEY && |
604 | btrfs_disk_key_offset(&item->key) > | 569 | btrfs_disk_key_offset(&item->key) > root->highest_inode) |
605 | root->fs_info->highest_inode) | ||
606 | break; | 570 | break; |
607 | if (btrfs_disk_key_type(&item->key) != key_type) | 571 | if (btrfs_disk_key_type(&item->key) != key_type) |
608 | continue; | 572 | continue; |
@@ -707,7 +671,6 @@ static void fill_inode_item(struct btrfs_inode_item *item, | |||
707 | btrfs_set_timespec_nsec(&item->ctime, inode->i_ctime.tv_nsec); | 671 | btrfs_set_timespec_nsec(&item->ctime, inode->i_ctime.tv_nsec); |
708 | btrfs_set_inode_nblocks(item, inode->i_blocks); | 672 | btrfs_set_inode_nblocks(item, inode->i_blocks); |
709 | btrfs_set_inode_generation(item, inode->i_generation); | 673 | btrfs_set_inode_generation(item, inode->i_generation); |
710 | check_inode(inode); | ||
711 | } | 674 | } |
712 | 675 | ||
713 | static int btrfs_update_inode(struct btrfs_trans_handle *trans, | 676 | static int btrfs_update_inode(struct btrfs_trans_handle *trans, |
@@ -721,7 +684,6 @@ static int btrfs_update_inode(struct btrfs_trans_handle *trans, | |||
721 | path = btrfs_alloc_path(); | 684 | path = btrfs_alloc_path(); |
722 | BUG_ON(!path); | 685 | BUG_ON(!path); |
723 | btrfs_init_path(path); | 686 | btrfs_init_path(path); |
724 | |||
725 | ret = btrfs_lookup_inode(trans, root, path, | 687 | ret = btrfs_lookup_inode(trans, root, path, |
726 | &BTRFS_I(inode)->location, 1); | 688 | &BTRFS_I(inode)->location, 1); |
727 | if (ret) { | 689 | if (ret) { |
@@ -736,11 +698,11 @@ static int btrfs_update_inode(struct btrfs_trans_handle *trans, | |||
736 | 698 | ||
737 | fill_inode_item(inode_item, inode); | 699 | fill_inode_item(inode_item, inode); |
738 | btrfs_mark_buffer_dirty(path->nodes[0]); | 700 | btrfs_mark_buffer_dirty(path->nodes[0]); |
701 | ret = 0; | ||
739 | failed: | 702 | failed: |
740 | btrfs_release_path(root, path); | 703 | btrfs_release_path(root, path); |
741 | btrfs_free_path(path); | 704 | btrfs_free_path(path); |
742 | check_inode(inode); | 705 | return ret; |
743 | return 0; | ||
744 | } | 706 | } |
745 | 707 | ||
746 | static int btrfs_write_inode(struct inode *inode, int wait) | 708 | static int btrfs_write_inode(struct inode *inode, int wait) |
@@ -757,7 +719,6 @@ static int btrfs_write_inode(struct inode *inode, int wait) | |||
757 | else | 719 | else |
758 | btrfs_end_transaction(trans, root); | 720 | btrfs_end_transaction(trans, root); |
759 | mutex_unlock(&root->fs_info->fs_mutex); | 721 | mutex_unlock(&root->fs_info->fs_mutex); |
760 | check_inode(inode); | ||
761 | return ret; | 722 | return ret; |
762 | } | 723 | } |
763 | 724 | ||
@@ -767,7 +728,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
767 | struct inode *inode; | 728 | struct inode *inode; |
768 | struct btrfs_inode_item inode_item; | 729 | struct btrfs_inode_item inode_item; |
769 | struct btrfs_root *root = BTRFS_I(dir)->root; | 730 | struct btrfs_root *root = BTRFS_I(dir)->root; |
770 | struct btrfs_key *key; | 731 | struct btrfs_key *location; |
771 | int ret; | 732 | int ret; |
772 | u64 objectid; | 733 | u64 objectid; |
773 | 734 | ||
@@ -776,8 +737,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
776 | return ERR_PTR(-ENOMEM); | 737 | return ERR_PTR(-ENOMEM); |
777 | 738 | ||
778 | BTRFS_I(inode)->root = BTRFS_I(dir)->root; | 739 | BTRFS_I(inode)->root = BTRFS_I(dir)->root; |
779 | key = &BTRFS_I(inode)->location; | ||
780 | check_inode(inode); | ||
781 | ret = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid); | 740 | ret = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid); |
782 | BUG_ON(ret); | 741 | BUG_ON(ret); |
783 | 742 | ||
@@ -788,20 +747,16 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
788 | inode->i_blocks = 0; | 747 | inode->i_blocks = 0; |
789 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 748 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
790 | fill_inode_item(&inode_item, inode); | 749 | fill_inode_item(&inode_item, inode); |
791 | 750 | location = &BTRFS_I(inode)->location; | |
792 | key->objectid = objectid; | 751 | location->objectid = objectid; |
793 | key->flags = 0; | 752 | location->flags = 0; |
794 | key->offset = 0; | 753 | location->offset = 0; |
795 | btrfs_set_key_type(key, BTRFS_INODE_ITEM_KEY); | 754 | btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY); |
796 | ret = btrfs_insert_inode_map(trans, root, objectid, key); | ||
797 | BUG_ON(ret); | ||
798 | 755 | ||
799 | ret = btrfs_insert_inode(trans, root, objectid, &inode_item); | 756 | ret = btrfs_insert_inode(trans, root, objectid, &inode_item); |
800 | BUG_ON(ret); | 757 | BUG_ON(ret); |
801 | 758 | ||
802 | insert_inode_hash(inode); | 759 | insert_inode_hash(inode); |
803 | check_inode(inode); | ||
804 | check_inode(dir); | ||
805 | return inode; | 760 | return inode; |
806 | } | 761 | } |
807 | 762 | ||
@@ -825,8 +780,6 @@ static int btrfs_add_link(struct btrfs_trans_handle *trans, | |||
825 | ret = btrfs_update_inode(trans, root, | 780 | ret = btrfs_update_inode(trans, root, |
826 | dentry->d_parent->d_inode); | 781 | dentry->d_parent->d_inode); |
827 | } | 782 | } |
828 | check_inode(inode); | ||
829 | check_inode(dentry->d_parent->d_inode); | ||
830 | return ret; | 783 | return ret; |
831 | } | 784 | } |
832 | 785 | ||
@@ -840,7 +793,6 @@ static int btrfs_add_nondir(struct btrfs_trans_handle *trans, | |||
840 | } | 793 | } |
841 | if (err > 0) | 794 | if (err > 0) |
842 | err = -EEXIST; | 795 | err = -EEXIST; |
843 | check_inode(inode); | ||
844 | return err; | 796 | return err; |
845 | } | 797 | } |
846 | 798 | ||
@@ -872,8 +824,6 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
872 | out_unlock: | 824 | out_unlock: |
873 | btrfs_end_transaction(trans, root); | 825 | btrfs_end_transaction(trans, root); |
874 | mutex_unlock(&root->fs_info->fs_mutex); | 826 | mutex_unlock(&root->fs_info->fs_mutex); |
875 | check_inode(inode); | ||
876 | check_inode(dir); | ||
877 | 827 | ||
878 | if (drop_inode) { | 828 | if (drop_inode) { |
879 | inode_dec_link_count(inode); | 829 | inode_dec_link_count(inode); |
@@ -1701,7 +1651,8 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen) | |||
1701 | ret = btrfs_update_inode(trans, root, root->inode); | 1651 | ret = btrfs_update_inode(trans, root, root->inode); |
1702 | BUG_ON(ret); | 1652 | BUG_ON(ret); |
1703 | 1653 | ||
1704 | ret = btrfs_find_free_objectid(trans, root, 0, &objectid); | 1654 | ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root, |
1655 | 0, &objectid); | ||
1705 | BUG_ON(ret); | 1656 | BUG_ON(ret); |
1706 | 1657 | ||
1707 | memset(&new_root_item, 0, sizeof(new_root_item)); | 1658 | memset(&new_root_item, 0, sizeof(new_root_item)); |
@@ -1709,13 +1660,6 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen) | |||
1709 | sizeof(new_root_item)); | 1660 | sizeof(new_root_item)); |
1710 | 1661 | ||
1711 | key.objectid = objectid; | 1662 | key.objectid = objectid; |
1712 | key.flags = 0; | ||
1713 | key.offset = 0; | ||
1714 | btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY); | ||
1715 | ret = btrfs_insert_inode_map(trans, root, objectid, &key); | ||
1716 | BUG_ON(ret); | ||
1717 | |||
1718 | key.objectid = objectid; | ||
1719 | key.offset = 1; | 1663 | key.offset = 1; |
1720 | key.flags = 0; | 1664 | key.flags = 0; |
1721 | btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); | 1665 | btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); |
@@ -1791,21 +1735,14 @@ static struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
1791 | ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS); | 1735 | ei = kmem_cache_alloc(btrfs_inode_cachep, GFP_NOFS); |
1792 | if (!ei) | 1736 | if (!ei) |
1793 | return NULL; | 1737 | return NULL; |
1794 | ei->magic = 0xDEADBEEF; | ||
1795 | ei->magic2 = 0xDEADBEAF; | ||
1796 | return &ei->vfs_inode; | 1738 | return &ei->vfs_inode; |
1797 | } | 1739 | } |
1798 | 1740 | ||
1799 | static void btrfs_destroy_inode(struct inode *inode) | 1741 | static void btrfs_destroy_inode(struct inode *inode) |
1800 | { | 1742 | { |
1801 | struct btrfs_inode *ei = BTRFS_I(inode); | ||
1802 | WARN_ON(ei->magic != 0xDEADBEEF); | ||
1803 | WARN_ON(ei->magic2 != 0xDEADBEAF); | ||
1804 | WARN_ON(!list_empty(&inode->i_dentry)); | 1743 | WARN_ON(!list_empty(&inode->i_dentry)); |
1805 | WARN_ON(inode->i_data.nrpages); | 1744 | WARN_ON(inode->i_data.nrpages); |
1806 | 1745 | ||
1807 | ei->magic = 0; | ||
1808 | ei->magic2 = 0; | ||
1809 | kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); | 1746 | kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode)); |
1810 | } | 1747 | } |
1811 | 1748 | ||