diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5b0d2c7d5408..d7b7462a0e13 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -522,6 +522,10 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, | |||
522 | if (unlikely(map->m_len > INT_MAX)) | 522 | if (unlikely(map->m_len > INT_MAX)) |
523 | map->m_len = INT_MAX; | 523 | map->m_len = INT_MAX; |
524 | 524 | ||
525 | /* We can handle the block number less than EXT_MAX_BLOCKS */ | ||
526 | if (unlikely(map->m_lblk >= EXT_MAX_BLOCKS)) | ||
527 | return -EIO; | ||
528 | |||
525 | /* Lookup extent status tree firstly */ | 529 | /* Lookup extent status tree firstly */ |
526 | if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) { | 530 | if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) { |
527 | ext4_es_lru_add(inode); | 531 | ext4_es_lru_add(inode); |
@@ -2243,13 +2247,23 @@ static int mpage_map_and_submit_extent(handle_t *handle, | |||
2243 | return err; | 2247 | return err; |
2244 | } while (map->m_len); | 2248 | } while (map->m_len); |
2245 | 2249 | ||
2246 | /* Update on-disk size after IO is submitted */ | 2250 | /* |
2251 | * Update on-disk size after IO is submitted. Races with | ||
2252 | * truncate are avoided by checking i_size under i_data_sem. | ||
2253 | */ | ||
2247 | disksize = ((loff_t)mpd->first_page) << PAGE_CACHE_SHIFT; | 2254 | disksize = ((loff_t)mpd->first_page) << PAGE_CACHE_SHIFT; |
2248 | if (disksize > EXT4_I(inode)->i_disksize) { | 2255 | if (disksize > EXT4_I(inode)->i_disksize) { |
2249 | int err2; | 2256 | int err2; |
2250 | 2257 | loff_t i_size; | |
2251 | ext4_wb_update_i_disksize(inode, disksize); | 2258 | |
2259 | down_write(&EXT4_I(inode)->i_data_sem); | ||
2260 | i_size = i_size_read(inode); | ||
2261 | if (disksize > i_size) | ||
2262 | disksize = i_size; | ||
2263 | if (disksize > EXT4_I(inode)->i_disksize) | ||
2264 | EXT4_I(inode)->i_disksize = disksize; | ||
2252 | err2 = ext4_mark_inode_dirty(handle, inode); | 2265 | err2 = ext4_mark_inode_dirty(handle, inode); |
2266 | up_write(&EXT4_I(inode)->i_data_sem); | ||
2253 | if (err2) | 2267 | if (err2) |
2254 | ext4_error(inode->i_sb, | 2268 | ext4_error(inode->i_sb, |
2255 | "Failed to mark inode %lu dirty", | 2269 | "Failed to mark inode %lu dirty", |
@@ -3527,15 +3541,6 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length) | |||
3527 | } | 3541 | } |
3528 | 3542 | ||
3529 | mutex_lock(&inode->i_mutex); | 3543 | mutex_lock(&inode->i_mutex); |
3530 | /* It's not possible punch hole on append only file */ | ||
3531 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) { | ||
3532 | ret = -EPERM; | ||
3533 | goto out_mutex; | ||
3534 | } | ||
3535 | if (IS_SWAPFILE(inode)) { | ||
3536 | ret = -ETXTBSY; | ||
3537 | goto out_mutex; | ||
3538 | } | ||
3539 | 3544 | ||
3540 | /* No need to punch hole beyond i_size */ | 3545 | /* No need to punch hole beyond i_size */ |
3541 | if (offset >= inode->i_size) | 3546 | if (offset >= inode->i_size) |
@@ -3616,7 +3621,6 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length) | |||
3616 | ret = ext4_free_hole_blocks(handle, inode, first_block, | 3621 | ret = ext4_free_hole_blocks(handle, inode, first_block, |
3617 | stop_block); | 3622 | stop_block); |
3618 | 3623 | ||
3619 | ext4_discard_preallocations(inode); | ||
3620 | up_write(&EXT4_I(inode)->i_data_sem); | 3624 | up_write(&EXT4_I(inode)->i_data_sem); |
3621 | if (IS_SYNC(inode)) | 3625 | if (IS_SYNC(inode)) |
3622 | ext4_handle_sync(handle); | 3626 | ext4_handle_sync(handle); |
@@ -4423,21 +4427,20 @@ out_brelse: | |||
4423 | * | 4427 | * |
4424 | * We are called from a few places: | 4428 | * We are called from a few places: |
4425 | * | 4429 | * |
4426 | * - Within generic_file_write() for O_SYNC files. | 4430 | * - Within generic_file_aio_write() -> generic_write_sync() for O_SYNC files. |
4427 | * Here, there will be no transaction running. We wait for any running | 4431 | * Here, there will be no transaction running. We wait for any running |
4428 | * transaction to commit. | 4432 | * transaction to commit. |
4429 | * | 4433 | * |
4430 | * - Within sys_sync(), kupdate and such. | 4434 | * - Within flush work (sys_sync(), kupdate and such). |
4431 | * We wait on commit, if tol to. | 4435 | * We wait on commit, if told to. |
4432 | * | 4436 | * |
4433 | * - Within prune_icache() (PF_MEMALLOC == true) | 4437 | * - Within iput_final() -> write_inode_now() |
4434 | * Here we simply return. We can't afford to block kswapd on the | 4438 | * We wait on commit, if told to. |
4435 | * journal commit. | ||
4436 | * | 4439 | * |
4437 | * In all cases it is actually safe for us to return without doing anything, | 4440 | * In all cases it is actually safe for us to return without doing anything, |
4438 | * because the inode has been copied into a raw inode buffer in | 4441 | * because the inode has been copied into a raw inode buffer in |
4439 | * ext4_mark_inode_dirty(). This is a correctness thing for O_SYNC and for | 4442 | * ext4_mark_inode_dirty(). This is a correctness thing for WB_SYNC_ALL |
4440 | * knfsd. | 4443 | * writeback. |
4441 | * | 4444 | * |
4442 | * Note that we are absolutely dependent upon all inode dirtiers doing the | 4445 | * Note that we are absolutely dependent upon all inode dirtiers doing the |
4443 | * right thing: they *must* call mark_inode_dirty() after dirtying info in | 4446 | * right thing: they *must* call mark_inode_dirty() after dirtying info in |
@@ -4449,15 +4452,15 @@ out_brelse: | |||
4449 | * stuff(); | 4452 | * stuff(); |
4450 | * inode->i_size = expr; | 4453 | * inode->i_size = expr; |
4451 | * | 4454 | * |
4452 | * is in error because a kswapd-driven write_inode() could occur while | 4455 | * is in error because write_inode() could occur while `stuff()' is running, |
4453 | * `stuff()' is running, and the new i_size will be lost. Plus the inode | 4456 | * and the new i_size will be lost. Plus the inode will no longer be on the |
4454 | * will no longer be on the superblock's dirty inode list. | 4457 | * superblock's dirty inode list. |
4455 | */ | 4458 | */ |
4456 | int ext4_write_inode(struct inode *inode, struct writeback_control *wbc) | 4459 | int ext4_write_inode(struct inode *inode, struct writeback_control *wbc) |
4457 | { | 4460 | { |
4458 | int err; | 4461 | int err; |
4459 | 4462 | ||
4460 | if (current->flags & PF_MEMALLOC) | 4463 | if (WARN_ON_ONCE(current->flags & PF_MEMALLOC)) |
4461 | return 0; | 4464 | return 0; |
4462 | 4465 | ||
4463 | if (EXT4_SB(inode->i_sb)->s_journal) { | 4466 | if (EXT4_SB(inode->i_sb)->s_journal) { |