aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file.c
diff options
context:
space:
mode:
authorYan Zheng <zheng.yan@oracle.com>2008-10-09 11:46:29 -0400
committerChris Mason <chris.mason@oracle.com>2008-10-09 11:46:29 -0400
commita76a3cd40c1127ca199d4f7f37bf0d541bf44eb2 (patch)
treea91e91d9f67ce8bd314cebdacc458315d3e54275 /fs/btrfs/file.c
parenta62b940160d8125016e85046e68ae621c99e751f (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>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r--fs/btrfs/file.c24
1 files changed, 13 insertions, 11 deletions
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,
203insert: 203insert:
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),