diff options
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 75899a01dded..bef020451525 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -298,6 +298,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, | |||
298 | struct btrfs_path *path; | 298 | struct btrfs_path *path; |
299 | struct btrfs_key key; | 299 | struct btrfs_key key; |
300 | struct btrfs_key new_key; | 300 | struct btrfs_key new_key; |
301 | u64 ino = btrfs_ino(inode); | ||
301 | u64 search_start = start; | 302 | u64 search_start = start; |
302 | u64 disk_bytenr = 0; | 303 | u64 disk_bytenr = 0; |
303 | u64 num_bytes = 0; | 304 | u64 num_bytes = 0; |
@@ -318,14 +319,14 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, | |||
318 | 319 | ||
319 | while (1) { | 320 | while (1) { |
320 | recow = 0; | 321 | recow = 0; |
321 | ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino, | 322 | ret = btrfs_lookup_file_extent(trans, root, path, ino, |
322 | search_start, -1); | 323 | search_start, -1); |
323 | if (ret < 0) | 324 | if (ret < 0) |
324 | break; | 325 | break; |
325 | if (ret > 0 && path->slots[0] > 0 && search_start == start) { | 326 | if (ret > 0 && path->slots[0] > 0 && search_start == start) { |
326 | leaf = path->nodes[0]; | 327 | leaf = path->nodes[0]; |
327 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1); | 328 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1); |
328 | if (key.objectid == inode->i_ino && | 329 | if (key.objectid == ino && |
329 | key.type == BTRFS_EXTENT_DATA_KEY) | 330 | key.type == BTRFS_EXTENT_DATA_KEY) |
330 | path->slots[0]--; | 331 | path->slots[0]--; |
331 | } | 332 | } |
@@ -346,7 +347,7 @@ next_slot: | |||
346 | } | 347 | } |
347 | 348 | ||
348 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | 349 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
349 | if (key.objectid > inode->i_ino || | 350 | if (key.objectid > ino || |
350 | key.type > BTRFS_EXTENT_DATA_KEY || key.offset >= end) | 351 | key.type > BTRFS_EXTENT_DATA_KEY || key.offset >= end) |
351 | break; | 352 | break; |
352 | 353 | ||
@@ -592,6 +593,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | |||
592 | int del_slot = 0; | 593 | int del_slot = 0; |
593 | int recow; | 594 | int recow; |
594 | int ret; | 595 | int ret; |
596 | u64 ino = btrfs_ino(inode); | ||
595 | 597 | ||
596 | btrfs_drop_extent_cache(inode, start, end - 1, 0); | 598 | btrfs_drop_extent_cache(inode, start, end - 1, 0); |
597 | 599 | ||
@@ -600,7 +602,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | |||
600 | again: | 602 | again: |
601 | recow = 0; | 603 | recow = 0; |
602 | split = start; | 604 | split = start; |
603 | key.objectid = inode->i_ino; | 605 | key.objectid = ino; |
604 | key.type = BTRFS_EXTENT_DATA_KEY; | 606 | key.type = BTRFS_EXTENT_DATA_KEY; |
605 | key.offset = split; | 607 | key.offset = split; |
606 | 608 | ||
@@ -612,8 +614,7 @@ again: | |||
612 | 614 | ||
613 | leaf = path->nodes[0]; | 615 | leaf = path->nodes[0]; |
614 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | 616 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
615 | BUG_ON(key.objectid != inode->i_ino || | 617 | BUG_ON(key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY); |
616 | key.type != BTRFS_EXTENT_DATA_KEY); | ||
617 | fi = btrfs_item_ptr(leaf, path->slots[0], | 618 | fi = btrfs_item_ptr(leaf, path->slots[0], |
618 | struct btrfs_file_extent_item); | 619 | struct btrfs_file_extent_item); |
619 | BUG_ON(btrfs_file_extent_type(leaf, fi) != | 620 | BUG_ON(btrfs_file_extent_type(leaf, fi) != |
@@ -630,7 +631,7 @@ again: | |||
630 | other_start = 0; | 631 | other_start = 0; |
631 | other_end = start; | 632 | other_end = start; |
632 | if (extent_mergeable(leaf, path->slots[0] - 1, | 633 | if (extent_mergeable(leaf, path->slots[0] - 1, |
633 | inode->i_ino, bytenr, orig_offset, | 634 | ino, bytenr, orig_offset, |
634 | &other_start, &other_end)) { | 635 | &other_start, &other_end)) { |
635 | new_key.offset = end; | 636 | new_key.offset = end; |
636 | btrfs_set_item_key_safe(trans, root, path, &new_key); | 637 | btrfs_set_item_key_safe(trans, root, path, &new_key); |
@@ -653,7 +654,7 @@ again: | |||
653 | other_start = end; | 654 | other_start = end; |
654 | other_end = 0; | 655 | other_end = 0; |
655 | if (extent_mergeable(leaf, path->slots[0] + 1, | 656 | if (extent_mergeable(leaf, path->slots[0] + 1, |
656 | inode->i_ino, bytenr, orig_offset, | 657 | ino, bytenr, orig_offset, |
657 | &other_start, &other_end)) { | 658 | &other_start, &other_end)) { |
658 | fi = btrfs_item_ptr(leaf, path->slots[0], | 659 | fi = btrfs_item_ptr(leaf, path->slots[0], |
659 | struct btrfs_file_extent_item); | 660 | struct btrfs_file_extent_item); |
@@ -702,7 +703,7 @@ again: | |||
702 | 703 | ||
703 | ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0, | 704 | ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0, |
704 | root->root_key.objectid, | 705 | root->root_key.objectid, |
705 | inode->i_ino, orig_offset); | 706 | ino, orig_offset); |
706 | BUG_ON(ret); | 707 | BUG_ON(ret); |
707 | 708 | ||
708 | if (split == start) { | 709 | if (split == start) { |
@@ -718,7 +719,7 @@ again: | |||
718 | other_start = end; | 719 | other_start = end; |
719 | other_end = 0; | 720 | other_end = 0; |
720 | if (extent_mergeable(leaf, path->slots[0] + 1, | 721 | if (extent_mergeable(leaf, path->slots[0] + 1, |
721 | inode->i_ino, bytenr, orig_offset, | 722 | ino, bytenr, orig_offset, |
722 | &other_start, &other_end)) { | 723 | &other_start, &other_end)) { |
723 | if (recow) { | 724 | if (recow) { |
724 | btrfs_release_path(root, path); | 725 | btrfs_release_path(root, path); |
@@ -729,13 +730,13 @@ again: | |||
729 | del_nr++; | 730 | del_nr++; |
730 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, | 731 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, |
731 | 0, root->root_key.objectid, | 732 | 0, root->root_key.objectid, |
732 | inode->i_ino, orig_offset); | 733 | ino, orig_offset); |
733 | BUG_ON(ret); | 734 | BUG_ON(ret); |
734 | } | 735 | } |
735 | other_start = 0; | 736 | other_start = 0; |
736 | other_end = start; | 737 | other_end = start; |
737 | if (extent_mergeable(leaf, path->slots[0] - 1, | 738 | if (extent_mergeable(leaf, path->slots[0] - 1, |
738 | inode->i_ino, bytenr, orig_offset, | 739 | ino, bytenr, orig_offset, |
739 | &other_start, &other_end)) { | 740 | &other_start, &other_end)) { |
740 | if (recow) { | 741 | if (recow) { |
741 | btrfs_release_path(root, path); | 742 | btrfs_release_path(root, path); |
@@ -746,7 +747,7 @@ again: | |||
746 | del_nr++; | 747 | del_nr++; |
747 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, | 748 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, |
748 | 0, root->root_key.objectid, | 749 | 0, root->root_key.objectid, |
749 | inode->i_ino, orig_offset); | 750 | ino, orig_offset); |
750 | BUG_ON(ret); | 751 | BUG_ON(ret); |
751 | } | 752 | } |
752 | if (del_nr == 0) { | 753 | if (del_nr == 0) { |