aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/extents.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r--fs/ext4/extents.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index ee40b7c52c8c..ac77d8b8251d 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -429,6 +429,11 @@ corrupted:
429#define ext4_ext_check(inode, eh, depth) \ 429#define ext4_ext_check(inode, eh, depth) \
430 __ext4_ext_check(__func__, inode, eh, depth) 430 __ext4_ext_check(__func__, inode, eh, depth)
431 431
432int ext4_ext_check_inode(struct inode *inode)
433{
434 return ext4_ext_check(inode, ext_inode_hdr(inode), ext_depth(inode));
435}
436
432#ifdef EXT_DEBUG 437#ifdef EXT_DEBUG
433static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path) 438static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path)
434{ 439{
@@ -631,9 +636,6 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
631 636
632 eh = ext_inode_hdr(inode); 637 eh = ext_inode_hdr(inode);
633 depth = ext_depth(inode); 638 depth = ext_depth(inode);
634 if (ext4_ext_check(inode, eh, depth))
635 return ERR_PTR(-EIO);
636
637 639
638 /* account possible depth increase */ 640 /* account possible depth increase */
639 if (!path) { 641 if (!path) {
@@ -649,6 +651,8 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
649 i = depth; 651 i = depth;
650 /* walk through the tree */ 652 /* walk through the tree */
651 while (i) { 653 while (i) {
654 int need_to_validate = 0;
655
652 ext_debug("depth %d: num %d, max %d\n", 656 ext_debug("depth %d: num %d, max %d\n",
653 ppos, le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max)); 657 ppos, le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max));
654 658
@@ -657,10 +661,17 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
657 path[ppos].p_depth = i; 661 path[ppos].p_depth = i;
658 path[ppos].p_ext = NULL; 662 path[ppos].p_ext = NULL;
659 663
660 bh = sb_bread(inode->i_sb, path[ppos].p_block); 664 bh = sb_getblk(inode->i_sb, path[ppos].p_block);
661 if (!bh) 665 if (unlikely(!bh))
662 goto err; 666 goto err;
663 667 if (!bh_uptodate_or_lock(bh)) {
668 if (bh_submit_read(bh) < 0) {
669 put_bh(bh);
670 goto err;
671 }
672 /* validate the extent entries */
673 need_to_validate = 1;
674 }
664 eh = ext_block_hdr(bh); 675 eh = ext_block_hdr(bh);
665 ppos++; 676 ppos++;
666 BUG_ON(ppos > depth); 677 BUG_ON(ppos > depth);
@@ -668,7 +679,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
668 path[ppos].p_hdr = eh; 679 path[ppos].p_hdr = eh;
669 i--; 680 i--;
670 681
671 if (ext4_ext_check(inode, eh, i)) 682 if (need_to_validate && ext4_ext_check(inode, eh, i))
672 goto err; 683 goto err;
673 } 684 }
674 685