diff options
author | Yan Zheng <zheng.yan@oracle.com> | 2008-10-09 11:46:29 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-10-09 11:46:29 -0400 |
commit | a76a3cd40c1127ca199d4f7f37bf0d541bf44eb2 (patch) | |
tree | a91e91d9f67ce8bd314cebdacc458315d3e54275 | |
parent | a62b940160d8125016e85046e68ae621c99e751f (diff) |
Btrfs: Count space allocated to file in bytes
This patch makes btrfs count space allocated to file in bytes instead
of 512 byte sectors.
Everything else in btrfs uses a byte count instead of sector sizes or
blocks sizes, so this fits better.
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
-rw-r--r-- | fs/btrfs/ctree.h | 13 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 2 | ||||
-rw-r--r-- | fs/btrfs/file.c | 24 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 23 | ||||
-rw-r--r-- | fs/btrfs/ioctl.c | 4 | ||||
-rw-r--r-- | fs/btrfs/tree-log.c | 6 |
6 files changed, 33 insertions, 39 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 8566eb30f567..50fbcc9ec45f 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -411,7 +411,7 @@ struct btrfs_inode_item { | |||
411 | /* transid that last touched this inode */ | 411 | /* transid that last touched this inode */ |
412 | __le64 transid; | 412 | __le64 transid; |
413 | __le64 size; | 413 | __le64 size; |
414 | __le64 nblocks; | 414 | __le64 nbytes; |
415 | __le64 block_group; | 415 | __le64 block_group; |
416 | __le32 nlink; | 416 | __le32 nlink; |
417 | __le32 uid; | 417 | __le32 uid; |
@@ -1017,7 +1017,7 @@ BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); | |||
1017 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); | 1017 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); |
1018 | BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); | 1018 | BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); |
1019 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); | 1019 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); |
1020 | BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64); | 1020 | BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64); |
1021 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); | 1021 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); |
1022 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); | 1022 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); |
1023 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); | 1023 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); |
@@ -1814,15 +1814,6 @@ void btrfs_invalidate_dcache_root(struct btrfs_root *root, char *name, | |||
1814 | int btrfs_merge_bio_hook(struct page *page, unsigned long offset, | 1814 | int btrfs_merge_bio_hook(struct page *page, unsigned long offset, |
1815 | size_t size, struct bio *bio); | 1815 | size_t size, struct bio *bio); |
1816 | 1816 | ||
1817 | static inline void dec_i_blocks(struct inode *inode, u64 dec) | ||
1818 | { | ||
1819 | dec = dec >> 9; | ||
1820 | if (dec <= inode->i_blocks) | ||
1821 | inode->i_blocks -= dec; | ||
1822 | else | ||
1823 | inode->i_blocks = 0; | ||
1824 | } | ||
1825 | |||
1826 | unsigned long btrfs_force_ra(struct address_space *mapping, | 1817 | unsigned long btrfs_force_ra(struct address_space *mapping, |
1827 | struct file_ra_state *ra, struct file *file, | 1818 | struct file_ra_state *ra, struct file *file, |
1828 | pgoff_t offset, pgoff_t last_index); | 1819 | pgoff_t offset, pgoff_t last_index); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 29380467b671..69db54e09fb9 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3930,7 +3930,7 @@ next: | |||
3930 | BUG_ON(ret); | 3930 | BUG_ON(ret); |
3931 | btrfs_release_path(root, path); | 3931 | btrfs_release_path(root, path); |
3932 | 3932 | ||
3933 | inode->i_blocks += extent_len >> 9; | 3933 | inode_add_bytes(inode, extent_len); |
3934 | 3934 | ||
3935 | ext_offset = 0; | 3935 | ext_offset = 0; |
3936 | num_bytes -= extent_len; | 3936 | num_bytes -= extent_len; |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a03d1bbb19ad..18dfdf5f91d1 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -193,7 +193,7 @@ static int noinline insert_inline_extent(struct btrfs_trans_handle *trans, | |||
193 | leaf = path->nodes[0]; | 193 | leaf = path->nodes[0]; |
194 | ei = btrfs_item_ptr(leaf, path->slots[0], | 194 | ei = btrfs_item_ptr(leaf, path->slots[0], |
195 | struct btrfs_file_extent_item); | 195 | struct btrfs_file_extent_item); |
196 | inode->i_blocks += (offset + size - found_end) >> 9; | 196 | inode_add_bytes(inode, offset + size - found_end); |
197 | } | 197 | } |
198 | if (found_end < offset) { | 198 | if (found_end < offset) { |
199 | ptr = btrfs_file_extent_inline_start(ei) + found_size; | 199 | ptr = btrfs_file_extent_inline_start(ei) + found_size; |
@@ -203,7 +203,7 @@ static int noinline insert_inline_extent(struct btrfs_trans_handle *trans, | |||
203 | insert: | 203 | insert: |
204 | btrfs_release_path(root, path); | 204 | btrfs_release_path(root, path); |
205 | datasize = offset + size - key.offset; | 205 | datasize = offset + size - key.offset; |
206 | inode->i_blocks += datasize >> 9; | 206 | inode_add_bytes(inode, datasize); |
207 | datasize = btrfs_file_extent_calc_inline_size(datasize); | 207 | datasize = btrfs_file_extent_calc_inline_size(datasize); |
208 | ret = btrfs_insert_empty_item(trans, root, path, &key, | 208 | ret = btrfs_insert_empty_item(trans, root, path, &key, |
209 | datasize); | 209 | datasize); |
@@ -713,7 +713,8 @@ next_slot: | |||
713 | extent); | 713 | extent); |
714 | if (btrfs_file_extent_disk_bytenr(leaf, | 714 | if (btrfs_file_extent_disk_bytenr(leaf, |
715 | extent)) { | 715 | extent)) { |
716 | dec_i_blocks(inode, old_num - new_num); | 716 | inode_sub_bytes(inode, old_num - |
717 | new_num); | ||
717 | } | 718 | } |
718 | btrfs_set_file_extent_num_bytes(leaf, extent, | 719 | btrfs_set_file_extent_num_bytes(leaf, extent, |
719 | new_num); | 720 | new_num); |
@@ -724,14 +725,17 @@ next_slot: | |||
724 | u32 new_size; | 725 | u32 new_size; |
725 | new_size = btrfs_file_extent_calc_inline_size( | 726 | new_size = btrfs_file_extent_calc_inline_size( |
726 | inline_limit - key.offset); | 727 | inline_limit - key.offset); |
727 | dec_i_blocks(inode, (extent_end - key.offset) - | 728 | inode_sub_bytes(inode, extent_end - |
728 | (inline_limit - key.offset)); | 729 | inline_limit); |
729 | btrfs_truncate_item(trans, root, path, | 730 | btrfs_truncate_item(trans, root, path, |
730 | new_size, 1); | 731 | new_size, 1); |
731 | } | 732 | } |
732 | } | 733 | } |
733 | /* delete the entire extent */ | 734 | /* delete the entire extent */ |
734 | if (!keep) { | 735 | if (!keep) { |
736 | if (found_inline) | ||
737 | inode_sub_bytes(inode, extent_end - | ||
738 | key.offset); | ||
735 | ret = btrfs_del_item(trans, root, path); | 739 | ret = btrfs_del_item(trans, root, path); |
736 | /* TODO update progress marker and return */ | 740 | /* TODO update progress marker and return */ |
737 | BUG_ON(ret); | 741 | BUG_ON(ret); |
@@ -743,8 +747,7 @@ next_slot: | |||
743 | u32 new_size; | 747 | u32 new_size; |
744 | new_size = btrfs_file_extent_calc_inline_size( | 748 | new_size = btrfs_file_extent_calc_inline_size( |
745 | extent_end - end); | 749 | extent_end - end); |
746 | dec_i_blocks(inode, (extent_end - key.offset) - | 750 | inode_sub_bytes(inode, end - key.offset); |
747 | (extent_end - end)); | ||
748 | ret = btrfs_truncate_item(trans, root, path, | 751 | ret = btrfs_truncate_item(trans, root, path, |
749 | new_size, 0); | 752 | new_size, 0); |
750 | BUG_ON(ret); | 753 | BUG_ON(ret); |
@@ -791,9 +794,7 @@ next_slot: | |||
791 | } | 794 | } |
792 | btrfs_release_path(root, path); | 795 | btrfs_release_path(root, path); |
793 | if (disk_bytenr != 0) { | 796 | if (disk_bytenr != 0) { |
794 | inode->i_blocks += | 797 | inode_add_bytes(inode, extent_end - end); |
795 | btrfs_file_extent_num_bytes(leaf, | ||
796 | extent) >> 9; | ||
797 | } | 798 | } |
798 | } | 799 | } |
799 | 800 | ||
@@ -801,7 +802,8 @@ next_slot: | |||
801 | u64 disk_bytenr = le64_to_cpu(old.disk_bytenr); | 802 | u64 disk_bytenr = le64_to_cpu(old.disk_bytenr); |
802 | 803 | ||
803 | if (disk_bytenr != 0) { | 804 | if (disk_bytenr != 0) { |
804 | dec_i_blocks(inode, le64_to_cpu(old.num_bytes)); | 805 | inode_sub_bytes(inode, |
806 | le64_to_cpu(old.num_bytes)); | ||
805 | ret = btrfs_free_extent(trans, root, | 807 | ret = btrfs_free_extent(trans, root, |
806 | disk_bytenr, | 808 | disk_bytenr, |
807 | le64_to_cpu(old.disk_num_bytes), | 809 | le64_to_cpu(old.disk_num_bytes), |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ff0c35976657..f9df89c5fdfc 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -652,7 +652,7 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
652 | BUG_ON(ret); | 652 | BUG_ON(ret); |
653 | btrfs_release_path(root, path); | 653 | btrfs_release_path(root, path); |
654 | 654 | ||
655 | inode->i_blocks += ordered_extent->len >> 9; | 655 | inode_add_bytes(inode, ordered_extent->len); |
656 | unlock_extent(io_tree, ordered_extent->file_offset, | 656 | unlock_extent(io_tree, ordered_extent->file_offset, |
657 | ordered_extent->file_offset + ordered_extent->len - 1, | 657 | ordered_extent->file_offset + ordered_extent->len - 1, |
658 | GFP_NOFS); | 658 | GFP_NOFS); |
@@ -1104,7 +1104,7 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
1104 | inode->i_ctime.tv_sec = btrfs_timespec_sec(leaf, tspec); | 1104 | inode->i_ctime.tv_sec = btrfs_timespec_sec(leaf, tspec); |
1105 | inode->i_ctime.tv_nsec = btrfs_timespec_nsec(leaf, tspec); | 1105 | inode->i_ctime.tv_nsec = btrfs_timespec_nsec(leaf, tspec); |
1106 | 1106 | ||
1107 | inode->i_blocks = btrfs_inode_nblocks(leaf, inode_item); | 1107 | inode_set_bytes(inode, btrfs_inode_nbytes(leaf, inode_item)); |
1108 | BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item); | 1108 | BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item); |
1109 | inode->i_generation = BTRFS_I(inode)->generation; | 1109 | inode->i_generation = BTRFS_I(inode)->generation; |
1110 | inode->i_rdev = 0; | 1110 | inode->i_rdev = 0; |
@@ -1184,7 +1184,7 @@ static void fill_inode_item(struct btrfs_trans_handle *trans, | |||
1184 | btrfs_set_timespec_nsec(leaf, btrfs_inode_ctime(item), | 1184 | btrfs_set_timespec_nsec(leaf, btrfs_inode_ctime(item), |
1185 | inode->i_ctime.tv_nsec); | 1185 | inode->i_ctime.tv_nsec); |
1186 | 1186 | ||
1187 | btrfs_set_inode_nblocks(leaf, item, inode->i_blocks); | 1187 | btrfs_set_inode_nbytes(leaf, item, inode_get_bytes(inode)); |
1188 | btrfs_set_inode_generation(leaf, item, BTRFS_I(inode)->generation); | 1188 | btrfs_set_inode_generation(leaf, item, BTRFS_I(inode)->generation); |
1189 | btrfs_set_inode_transid(leaf, item, trans->transid); | 1189 | btrfs_set_inode_transid(leaf, item, trans->transid); |
1190 | btrfs_set_inode_rdev(leaf, item, inode->i_rdev); | 1190 | btrfs_set_inode_rdev(leaf, item, inode->i_rdev); |
@@ -1679,7 +1679,7 @@ search_again: | |||
1679 | num_dec = (orig_num_bytes - | 1679 | num_dec = (orig_num_bytes - |
1680 | extent_num_bytes); | 1680 | extent_num_bytes); |
1681 | if (root->ref_cows && extent_start != 0) | 1681 | if (root->ref_cows && extent_start != 0) |
1682 | dec_i_blocks(inode, num_dec); | 1682 | inode_sub_bytes(inode, num_dec); |
1683 | btrfs_mark_buffer_dirty(leaf); | 1683 | btrfs_mark_buffer_dirty(leaf); |
1684 | } else { | 1684 | } else { |
1685 | extent_num_bytes = | 1685 | extent_num_bytes = |
@@ -1690,7 +1690,7 @@ search_again: | |||
1690 | if (extent_start != 0) { | 1690 | if (extent_start != 0) { |
1691 | found_extent = 1; | 1691 | found_extent = 1; |
1692 | if (root->ref_cows) | 1692 | if (root->ref_cows) |
1693 | dec_i_blocks(inode, num_dec); | 1693 | inode_sub_bytes(inode, num_dec); |
1694 | } | 1694 | } |
1695 | root_gen = btrfs_header_generation(leaf); | 1695 | root_gen = btrfs_header_generation(leaf); |
1696 | root_owner = btrfs_header_owner(leaf); | 1696 | root_owner = btrfs_header_owner(leaf); |
@@ -1700,8 +1700,8 @@ search_again: | |||
1700 | u32 size = new_size - found_key.offset; | 1700 | u32 size = new_size - found_key.offset; |
1701 | 1701 | ||
1702 | if (root->ref_cows) { | 1702 | if (root->ref_cows) { |
1703 | dec_i_blocks(inode, item_end + 1 - | 1703 | inode_sub_bytes(inode, item_end + 1 - |
1704 | found_key.offset - size); | 1704 | new_size); |
1705 | } | 1705 | } |
1706 | size = | 1706 | size = |
1707 | btrfs_file_extent_calc_inline_size(size); | 1707 | btrfs_file_extent_calc_inline_size(size); |
@@ -1709,8 +1709,8 @@ search_again: | |||
1709 | size, 1); | 1709 | size, 1); |
1710 | BUG_ON(ret); | 1710 | BUG_ON(ret); |
1711 | } else if (root->ref_cows) { | 1711 | } else if (root->ref_cows) { |
1712 | dec_i_blocks(inode, item_end + 1 - | 1712 | inode_sub_bytes(inode, item_end + 1 - |
1713 | found_key.offset); | 1713 | found_key.offset); |
1714 | } | 1714 | } |
1715 | } | 1715 | } |
1716 | delete: | 1716 | delete: |
@@ -2514,7 +2514,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
2514 | inode->i_gid = current->fsgid; | 2514 | inode->i_gid = current->fsgid; |
2515 | inode->i_mode = mode; | 2515 | inode->i_mode = mode; |
2516 | inode->i_ino = objectid; | 2516 | inode->i_ino = objectid; |
2517 | inode->i_blocks = 0; | 2517 | inode_set_bytes(inode, 0); |
2518 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 2518 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
2519 | inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], | 2519 | inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], |
2520 | struct btrfs_inode_item); | 2520 | struct btrfs_inode_item); |
@@ -3557,7 +3557,8 @@ static int btrfs_getattr(struct vfsmount *mnt, | |||
3557 | struct inode *inode = dentry->d_inode; | 3557 | struct inode *inode = dentry->d_inode; |
3558 | generic_fillattr(inode, stat); | 3558 | generic_fillattr(inode, stat); |
3559 | stat->blksize = PAGE_CACHE_SIZE; | 3559 | stat->blksize = PAGE_CACHE_SIZE; |
3560 | stat->blocks = inode->i_blocks + (BTRFS_I(inode)->delalloc_bytes >> 9); | 3560 | stat->blocks = (inode_get_bytes(inode) + |
3561 | BTRFS_I(inode)->delalloc_bytes) >> 9; | ||
3561 | return 0; | 3562 | return 0; |
3562 | } | 3563 | } |
3563 | 3564 | ||
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 04de767a8db2..ab7a0f61ded8 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -99,7 +99,7 @@ static noinline int create_subvol(struct btrfs_root *root, char *name, | |||
99 | inode_item->generation = cpu_to_le64(1); | 99 | inode_item->generation = cpu_to_le64(1); |
100 | inode_item->size = cpu_to_le64(3); | 100 | inode_item->size = cpu_to_le64(3); |
101 | inode_item->nlink = cpu_to_le32(1); | 101 | inode_item->nlink = cpu_to_le32(1); |
102 | inode_item->nblocks = cpu_to_le64(1); | 102 | inode_item->nbytes = cpu_to_le64(root->leafsize); |
103 | inode_item->mode = cpu_to_le32(S_IFDIR | 0755); | 103 | inode_item->mode = cpu_to_le32(S_IFDIR | 0755); |
104 | 104 | ||
105 | btrfs_set_root_bytenr(&root_item, leaf->start); | 105 | btrfs_set_root_bytenr(&root_item, leaf->start); |
@@ -671,7 +671,7 @@ out: | |||
671 | btrfs_release_path(root, path); | 671 | btrfs_release_path(root, path); |
672 | if (ret == 0) { | 672 | if (ret == 0) { |
673 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | 673 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
674 | inode->i_blocks = src->i_blocks; | 674 | inode_set_bytes(inode, inode_get_bytes(src)); |
675 | btrfs_i_size_write(inode, src->i_size); | 675 | btrfs_i_size_write(inode, src->i_size); |
676 | BTRFS_I(inode)->flags = BTRFS_I(src)->flags; | 676 | BTRFS_I(inode)->flags = BTRFS_I(src)->flags; |
677 | ret = btrfs_update_inode(trans, root, inode); | 677 | ret = btrfs_update_inode(trans, root, inode); |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 88bbfd959f18..8df719a73d82 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -113,7 +113,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans, | |||
113 | inode_item->generation = cpu_to_le64(1); | 113 | inode_item->generation = cpu_to_le64(1); |
114 | inode_item->size = cpu_to_le64(3); | 114 | inode_item->size = cpu_to_le64(3); |
115 | inode_item->nlink = cpu_to_le32(1); | 115 | inode_item->nlink = cpu_to_le32(1); |
116 | inode_item->nblocks = cpu_to_le64(1); | 116 | inode_item->nbytes = cpu_to_le64(root->leafsize); |
117 | inode_item->mode = cpu_to_le32(S_IFDIR | 0755); | 117 | inode_item->mode = cpu_to_le32(S_IFDIR | 0755); |
118 | 118 | ||
119 | btrfs_set_root_bytenr(&root_item, leaf->start); | 119 | btrfs_set_root_bytenr(&root_item, leaf->start); |
@@ -598,8 +598,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
598 | ret = overwrite_item(trans, root, path, eb, slot, key); | 598 | ret = overwrite_item(trans, root, path, eb, slot, key); |
599 | BUG_ON(ret); | 599 | BUG_ON(ret); |
600 | 600 | ||
601 | /* btrfs_drop_extents changes i_blocks, update it here */ | 601 | /* btrfs_drop_extents changes i_bytes & i_blocks, update it here */ |
602 | inode->i_blocks += (extent_end - start) >> 9; | 602 | inode_add_bytes(inode, extent_end - start); |
603 | btrfs_update_inode(trans, root, inode); | 603 | btrfs_update_inode(trans, root, inode); |
604 | out: | 604 | out: |
605 | if (inode) | 605 | if (inode) |