@@ -1582,7 +1582,7 @@ static int ext4_free_hole_blocks(handle_t *handle, struct inode *inode,
level, first, count, num);
if (ret)
goto err;
- if (count > max)
+ if (count > max - first)
count -= max - first;
else
break;
@@ -1661,15 +1661,11 @@ int ext4_ind_punch_hole(struct file *file, loff_t offset, loff_t length)
}
/* Wait all existing dio works, newcomers will block on i_mutex */
- ext4_inode_block_unlocked_dio(inode);
- err = ext4_flush_unwritten_io(inode);
- if (err)
- goto out_dio;
inode_dio_wait(inode);
handle = start_transaction(inode);
if (IS_ERR(handle))
- goto out_dio;
+ goto out_mutex;
/*
* Now we need to zero out the non-page-aligned data in the
@@ -1738,6 +1734,8 @@ int ext4_ind_punch_hole(struct file *file, loff_t offset, loff_t length)
down_write(&EXT4_I(inode)->i_data_sem);
ext4_discard_preallocations(inode);
+ err = ext4_es_remove_extent(inode, first_block,
+ stop_block - first_block);
err = ext4_free_hole_blocks(handle, inode, first_block, stop_block);
ext4_discard_preallocations(inode);
@@ -1752,8 +1750,6 @@ out:
ext4_mark_inode_dirty(handle, inode);
ext4_journal_stop(handle);
-out_dio:
- ext4_inode_resume_unlocked_dio(inode);
out_mutex:
mutex_unlock(&inode->i_mutex);