diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-02-08 13:49:28 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:00 -0400 |
commit | 9069218d448ea547dbad5f1cbd537e88d6519d66 (patch) | |
tree | fafb142a36805f26678bb4e7a0ebe50d8c7f859a /fs/btrfs/file.c | |
parent | a86c12c73d982c545a37a8ecdd66528ab260b770 (diff) |
Btrfs: Fix i_blocks accounting
Now that delayed allocation accounting works, i_blocks accounting is changed
to only modify i_blocks when extents inserted or removed.
The fillattr call is changed to include the delayed allocation byte count
in the i_blocks result.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index bfa4149c053d..f89396082544 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -175,6 +175,7 @@ static int noinline insert_inline_extent(struct btrfs_trans_handle *trans, | |||
175 | leaf = path->nodes[0]; | 175 | leaf = path->nodes[0]; |
176 | ei = btrfs_item_ptr(leaf, path->slots[0], | 176 | ei = btrfs_item_ptr(leaf, path->slots[0], |
177 | struct btrfs_file_extent_item); | 177 | struct btrfs_file_extent_item); |
178 | inode->i_blocks += (offset + size - found_end) >> 9; | ||
178 | } | 179 | } |
179 | if (found_end < offset) { | 180 | if (found_end < offset) { |
180 | ptr = btrfs_file_extent_inline_start(ei) + found_size; | 181 | ptr = btrfs_file_extent_inline_start(ei) + found_size; |
@@ -184,6 +185,7 @@ static int noinline insert_inline_extent(struct btrfs_trans_handle *trans, | |||
184 | insert: | 185 | insert: |
185 | btrfs_release_path(root, path); | 186 | btrfs_release_path(root, path); |
186 | datasize = offset + size - key.offset; | 187 | datasize = offset + size - key.offset; |
188 | inode->i_blocks += datasize >> 9; | ||
187 | datasize = btrfs_file_extent_calc_inline_size(datasize); | 189 | datasize = btrfs_file_extent_calc_inline_size(datasize); |
188 | ret = btrfs_insert_empty_item(trans, root, path, &key, | 190 | ret = btrfs_insert_empty_item(trans, root, path, &key, |
189 | datasize); | 191 | datasize); |
@@ -256,7 +258,6 @@ static int noinline dirty_and_release_pages(struct btrfs_trans_handle *trans, | |||
256 | goto out_unlock; | 258 | goto out_unlock; |
257 | } | 259 | } |
258 | btrfs_set_trans_block_group(trans, inode); | 260 | btrfs_set_trans_block_group(trans, inode); |
259 | inode->i_blocks += num_bytes >> 9; | ||
260 | hint_byte = 0; | 261 | hint_byte = 0; |
261 | 262 | ||
262 | if ((end_of_last_block & 4095) == 0) { | 263 | if ((end_of_last_block & 4095) == 0) { |
@@ -410,7 +411,7 @@ int btrfs_check_file(struct btrfs_root *root, struct inode *inode) | |||
410 | if (found_key.type != BTRFS_EXTENT_DATA_KEY) | 411 | if (found_key.type != BTRFS_EXTENT_DATA_KEY) |
411 | goto out; | 412 | goto out; |
412 | 413 | ||
413 | if (found_key.offset != last_offset) { | 414 | if (found_key.offset < last_offset) { |
414 | WARN_ON(1); | 415 | WARN_ON(1); |
415 | btrfs_print_leaf(root, leaf); | 416 | btrfs_print_leaf(root, leaf); |
416 | printk("inode %lu found offset %Lu expected %Lu\n", | 417 | printk("inode %lu found offset %Lu expected %Lu\n", |
@@ -435,7 +436,7 @@ int btrfs_check_file(struct btrfs_root *root, struct inode *inode) | |||
435 | last_offset = extent_end; | 436 | last_offset = extent_end; |
436 | path->slots[0]++; | 437 | path->slots[0]++; |
437 | } | 438 | } |
438 | if (last_offset < inode->i_size) { | 439 | if (0 && last_offset < inode->i_size) { |
439 | WARN_ON(1); | 440 | WARN_ON(1); |
440 | btrfs_print_leaf(root, leaf); | 441 | btrfs_print_leaf(root, leaf); |
441 | printk("inode %lu found offset %Lu size %Lu\n", inode->i_ino, | 442 | printk("inode %lu found offset %Lu size %Lu\n", inode->i_ino, |
@@ -608,8 +609,7 @@ next_slot: | |||
608 | extent); | 609 | extent); |
609 | if (btrfs_file_extent_disk_bytenr(leaf, | 610 | if (btrfs_file_extent_disk_bytenr(leaf, |
610 | extent)) { | 611 | extent)) { |
611 | inode->i_blocks -= | 612 | dec_i_blocks(inode, old_num - new_num); |
612 | (old_num - new_num) >> 9; | ||
613 | } | 613 | } |
614 | btrfs_set_file_extent_num_bytes(leaf, extent, | 614 | btrfs_set_file_extent_num_bytes(leaf, extent, |
615 | new_num); | 615 | new_num); |
@@ -620,6 +620,8 @@ next_slot: | |||
620 | u32 new_size; | 620 | u32 new_size; |
621 | new_size = btrfs_file_extent_calc_inline_size( | 621 | new_size = btrfs_file_extent_calc_inline_size( |
622 | inline_limit - key.offset); | 622 | inline_limit - key.offset); |
623 | dec_i_blocks(inode, (extent_end - key.offset) - | ||
624 | (inline_limit - key.offset)); | ||
623 | btrfs_truncate_item(trans, root, path, | 625 | btrfs_truncate_item(trans, root, path, |
624 | new_size, 1); | 626 | new_size, 1); |
625 | } | 627 | } |
@@ -653,7 +655,7 @@ next_slot: | |||
653 | btrfs_release_path(root, path); | 655 | btrfs_release_path(root, path); |
654 | extent = NULL; | 656 | extent = NULL; |
655 | if (found_extent && disk_bytenr != 0) { | 657 | if (found_extent && disk_bytenr != 0) { |
656 | inode->i_blocks -= extent_num_bytes >> 9; | 658 | dec_i_blocks(inode, extent_num_bytes); |
657 | ret = btrfs_free_extent(trans, root, | 659 | ret = btrfs_free_extent(trans, root, |
658 | disk_bytenr, | 660 | disk_bytenr, |
659 | disk_num_bytes, | 661 | disk_num_bytes, |
@@ -674,6 +676,8 @@ next_slot: | |||
674 | u32 new_size; | 676 | u32 new_size; |
675 | new_size = btrfs_file_extent_calc_inline_size( | 677 | new_size = btrfs_file_extent_calc_inline_size( |
676 | extent_end - end); | 678 | extent_end - end); |
679 | dec_i_blocks(inode, (extent_end - key.offset) - | ||
680 | (extent_end - end)); | ||
677 | btrfs_truncate_item(trans, root, path, new_size, 0); | 681 | btrfs_truncate_item(trans, root, path, new_size, 0); |
678 | } | 682 | } |
679 | /* create bookend, splitting the extent in two */ | 683 | /* create bookend, splitting the extent in two */ |
@@ -718,6 +722,7 @@ next_slot: | |||
718 | } | 722 | } |
719 | out: | 723 | out: |
720 | btrfs_free_path(path); | 724 | btrfs_free_path(path); |
725 | btrfs_check_file(root, inode); | ||
721 | return ret; | 726 | return ret; |
722 | } | 727 | } |
723 | 728 | ||