diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-11-11 14:28:11 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-11-11 14:28:11 -0500 |
commit | 16fe4101ae265e908615702806ee3b28ab1c8370 (patch) | |
tree | da2a562d5a3566a659c33be2d2744478fc994d7c /fs | |
parent | 7bbf8ef6902d1e0102a91d22c035622443fd20ca (diff) | |
parent | 1e424a348303694fabdf8b1efbfcb1a892dfa63a (diff) |
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
ext4: partial revert to fix double brelse WARNING()
ext4: Fix return value of ext4_split_unwritten_extents() to fix direct I/O
ext4: code clean up for dio fallocate handling
ext4: skip conversion of uninit extents after direct IO if there isn't any
ext4: fix ext4_ext_direct_IO()'s return value after converting uninit extents
ext4: discard preallocation when restarting a transaction during truncate
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/ext4.h | 1 | ||||
-rw-r--r-- | fs/ext4/extents.c | 36 | ||||
-rw-r--r-- | fs/ext4/inode.c | 24 | ||||
-rw-r--r-- | fs/ext4/namei.c | 16 |
4 files changed, 45 insertions, 32 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 00d153f2f261..8825515eeddd 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -322,6 +322,7 @@ static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) | |||
322 | #define EXT4_STATE_NO_EXPAND 0x00000008 /* No space for expansion */ | 322 | #define EXT4_STATE_NO_EXPAND 0x00000008 /* No space for expansion */ |
323 | #define EXT4_STATE_DA_ALLOC_CLOSE 0x00000010 /* Alloc DA blks on close */ | 323 | #define EXT4_STATE_DA_ALLOC_CLOSE 0x00000010 /* Alloc DA blks on close */ |
324 | #define EXT4_STATE_EXT_MIGRATE 0x00000020 /* Inode is migrating */ | 324 | #define EXT4_STATE_EXT_MIGRATE 0x00000020 /* Inode is migrating */ |
325 | #define EXT4_STATE_DIO_UNWRITTEN 0x00000040 /* need convert on dio done*/ | ||
325 | 326 | ||
326 | /* Used to pass group descriptor data when online resize is done */ | 327 | /* Used to pass group descriptor data when online resize is done */ |
327 | struct ext4_new_group_input { | 328 | struct ext4_new_group_input { |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 10539e364283..715264b4bae4 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -2807,6 +2807,8 @@ fix_extent_len: | |||
2807 | * into three uninitialized extent(at most). After IO complete, the part | 2807 | * into three uninitialized extent(at most). After IO complete, the part |
2808 | * being filled will be convert to initialized by the end_io callback function | 2808 | * being filled will be convert to initialized by the end_io callback function |
2809 | * via ext4_convert_unwritten_extents(). | 2809 | * via ext4_convert_unwritten_extents(). |
2810 | * | ||
2811 | * Returns the size of uninitialized extent to be written on success. | ||
2810 | */ | 2812 | */ |
2811 | static int ext4_split_unwritten_extents(handle_t *handle, | 2813 | static int ext4_split_unwritten_extents(handle_t *handle, |
2812 | struct inode *inode, | 2814 | struct inode *inode, |
@@ -2824,7 +2826,6 @@ static int ext4_split_unwritten_extents(handle_t *handle, | |||
2824 | unsigned int allocated, ee_len, depth; | 2826 | unsigned int allocated, ee_len, depth; |
2825 | ext4_fsblk_t newblock; | 2827 | ext4_fsblk_t newblock; |
2826 | int err = 0; | 2828 | int err = 0; |
2827 | int ret = 0; | ||
2828 | 2829 | ||
2829 | ext_debug("ext4_split_unwritten_extents: inode %lu," | 2830 | ext_debug("ext4_split_unwritten_extents: inode %lu," |
2830 | "iblock %llu, max_blocks %u\n", inode->i_ino, | 2831 | "iblock %llu, max_blocks %u\n", inode->i_ino, |
@@ -2842,12 +2843,12 @@ static int ext4_split_unwritten_extents(handle_t *handle, | |||
2842 | ext4_ext_store_pblock(&orig_ex, ext_pblock(ex)); | 2843 | ext4_ext_store_pblock(&orig_ex, ext_pblock(ex)); |
2843 | 2844 | ||
2844 | /* | 2845 | /* |
2845 | * if the entire unintialized extent length less than | 2846 | * If the uninitialized extent begins at the same logical |
2846 | * the size of extent to write, there is no need to split | 2847 | * block where the write begins, and the write completely |
2847 | * uninitialized extent | 2848 | * covers the extent, then we don't need to split it. |
2848 | */ | 2849 | */ |
2849 | if (allocated <= max_blocks) | 2850 | if ((iblock == ee_block) && (allocated <= max_blocks)) |
2850 | return ret; | 2851 | return allocated; |
2851 | 2852 | ||
2852 | err = ext4_ext_get_access(handle, inode, path + depth); | 2853 | err = ext4_ext_get_access(handle, inode, path + depth); |
2853 | if (err) | 2854 | if (err) |
@@ -3048,12 +3049,18 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | |||
3048 | ret = ext4_split_unwritten_extents(handle, | 3049 | ret = ext4_split_unwritten_extents(handle, |
3049 | inode, path, iblock, | 3050 | inode, path, iblock, |
3050 | max_blocks, flags); | 3051 | max_blocks, flags); |
3051 | /* flag the io_end struct that we need convert when IO done */ | 3052 | /* |
3053 | * Flag the inode(non aio case) or end_io struct (aio case) | ||
3054 | * that this IO needs to convertion to written when IO is | ||
3055 | * completed | ||
3056 | */ | ||
3052 | if (io) | 3057 | if (io) |
3053 | io->flag = DIO_AIO_UNWRITTEN; | 3058 | io->flag = DIO_AIO_UNWRITTEN; |
3059 | else | ||
3060 | EXT4_I(inode)->i_state |= EXT4_STATE_DIO_UNWRITTEN; | ||
3054 | goto out; | 3061 | goto out; |
3055 | } | 3062 | } |
3056 | /* DIO end_io complete, convert the filled extent to written */ | 3063 | /* async DIO end_io complete, convert the filled extent to written */ |
3057 | if (flags == EXT4_GET_BLOCKS_DIO_CONVERT_EXT) { | 3064 | if (flags == EXT4_GET_BLOCKS_DIO_CONVERT_EXT) { |
3058 | ret = ext4_convert_unwritten_extents_dio(handle, inode, | 3065 | ret = ext4_convert_unwritten_extents_dio(handle, inode, |
3059 | path); | 3066 | path); |
@@ -3295,10 +3302,16 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, | |||
3295 | * To avoid unecessary convertion for every aio dio rewrite | 3302 | * To avoid unecessary convertion for every aio dio rewrite |
3296 | * to the mid of file, here we flag the IO that is really | 3303 | * to the mid of file, here we flag the IO that is really |
3297 | * need the convertion. | 3304 | * need the convertion. |
3298 | * | 3305 | * For non asycn direct IO case, flag the inode state |
3306 | * that we need to perform convertion when IO is done. | ||
3299 | */ | 3307 | */ |
3300 | if (io && flags == EXT4_GET_BLOCKS_DIO_CREATE_EXT) | 3308 | if (flags == EXT4_GET_BLOCKS_DIO_CREATE_EXT) { |
3301 | io->flag = DIO_AIO_UNWRITTEN; | 3309 | if (io) |
3310 | io->flag = DIO_AIO_UNWRITTEN; | ||
3311 | else | ||
3312 | EXT4_I(inode)->i_state |= | ||
3313 | EXT4_STATE_DIO_UNWRITTEN;; | ||
3314 | } | ||
3302 | } | 3315 | } |
3303 | err = ext4_ext_insert_extent(handle, inode, path, &newex, flags); | 3316 | err = ext4_ext_insert_extent(handle, inode, path, &newex, flags); |
3304 | if (err) { | 3317 | if (err) { |
@@ -3519,6 +3532,7 @@ retry: | |||
3519 | * | 3532 | * |
3520 | * This function is called from the direct IO end io call back | 3533 | * This function is called from the direct IO end io call back |
3521 | * function, to convert the fallocated extents after IO is completed. | 3534 | * function, to convert the fallocated extents after IO is completed. |
3535 | * Returns 0 on success. | ||
3522 | */ | 3536 | */ |
3523 | int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, | 3537 | int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, |
3524 | loff_t len) | 3538 | loff_t len) |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5c5bc5dafff8..2c8caa51addb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -193,7 +193,7 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode) | |||
193 | * so before we call here everything must be consistently dirtied against | 193 | * so before we call here everything must be consistently dirtied against |
194 | * this transaction. | 194 | * this transaction. |
195 | */ | 195 | */ |
196 | int ext4_truncate_restart_trans(handle_t *handle, struct inode *inode, | 196 | int ext4_truncate_restart_trans(handle_t *handle, struct inode *inode, |
197 | int nblocks) | 197 | int nblocks) |
198 | { | 198 | { |
199 | int ret; | 199 | int ret; |
@@ -209,6 +209,7 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode) | |||
209 | up_write(&EXT4_I(inode)->i_data_sem); | 209 | up_write(&EXT4_I(inode)->i_data_sem); |
210 | ret = ext4_journal_restart(handle, blocks_for_truncate(inode)); | 210 | ret = ext4_journal_restart(handle, blocks_for_truncate(inode)); |
211 | down_write(&EXT4_I(inode)->i_data_sem); | 211 | down_write(&EXT4_I(inode)->i_data_sem); |
212 | ext4_discard_preallocations(inode); | ||
212 | 213 | ||
213 | return ret; | 214 | return ret; |
214 | } | 215 | } |
@@ -3445,8 +3446,6 @@ out: | |||
3445 | return ret; | 3446 | return ret; |
3446 | } | 3447 | } |
3447 | 3448 | ||
3448 | /* Maximum number of blocks we map for direct IO at once. */ | ||
3449 | |||
3450 | static int ext4_get_block_dio_write(struct inode *inode, sector_t iblock, | 3449 | static int ext4_get_block_dio_write(struct inode *inode, sector_t iblock, |
3451 | struct buffer_head *bh_result, int create) | 3450 | struct buffer_head *bh_result, int create) |
3452 | { | 3451 | { |
@@ -3654,13 +3653,14 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, | |||
3654 | ext4_io_end_t *io_end = iocb->private; | 3653 | ext4_io_end_t *io_end = iocb->private; |
3655 | struct workqueue_struct *wq; | 3654 | struct workqueue_struct *wq; |
3656 | 3655 | ||
3656 | /* if not async direct IO or dio with 0 bytes write, just return */ | ||
3657 | if (!io_end || !size) | ||
3658 | return; | ||
3659 | |||
3657 | ext_debug("ext4_end_io_dio(): io_end 0x%p" | 3660 | ext_debug("ext4_end_io_dio(): io_end 0x%p" |
3658 | "for inode %lu, iocb 0x%p, offset %llu, size %llu\n", | 3661 | "for inode %lu, iocb 0x%p, offset %llu, size %llu\n", |
3659 | iocb->private, io_end->inode->i_ino, iocb, offset, | 3662 | iocb->private, io_end->inode->i_ino, iocb, offset, |
3660 | size); | 3663 | size); |
3661 | /* if not async direct IO or dio with 0 bytes write, just return */ | ||
3662 | if (!io_end || !size) | ||
3663 | return; | ||
3664 | 3664 | ||
3665 | /* if not aio dio with unwritten extents, just free io and return */ | 3665 | /* if not aio dio with unwritten extents, just free io and return */ |
3666 | if (io_end->flag != DIO_AIO_UNWRITTEN){ | 3666 | if (io_end->flag != DIO_AIO_UNWRITTEN){ |
@@ -3771,13 +3771,19 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3771 | if (ret != -EIOCBQUEUED && ret <= 0 && iocb->private) { | 3771 | if (ret != -EIOCBQUEUED && ret <= 0 && iocb->private) { |
3772 | ext4_free_io_end(iocb->private); | 3772 | ext4_free_io_end(iocb->private); |
3773 | iocb->private = NULL; | 3773 | iocb->private = NULL; |
3774 | } else if (ret > 0) | 3774 | } else if (ret > 0 && (EXT4_I(inode)->i_state & |
3775 | EXT4_STATE_DIO_UNWRITTEN)) { | ||
3776 | int err; | ||
3775 | /* | 3777 | /* |
3776 | * for non AIO case, since the IO is already | 3778 | * for non AIO case, since the IO is already |
3777 | * completed, we could do the convertion right here | 3779 | * completed, we could do the convertion right here |
3778 | */ | 3780 | */ |
3779 | ret = ext4_convert_unwritten_extents(inode, | 3781 | err = ext4_convert_unwritten_extents(inode, |
3780 | offset, ret); | 3782 | offset, ret); |
3783 | if (err < 0) | ||
3784 | ret = err; | ||
3785 | EXT4_I(inode)->i_state &= ~EXT4_STATE_DIO_UNWRITTEN; | ||
3786 | } | ||
3781 | return ret; | 3787 | return ret; |
3782 | } | 3788 | } |
3783 | 3789 | ||
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 7c8fe80bacdd..6d2c1b897fc7 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -1518,12 +1518,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, | |||
1518 | return retval; | 1518 | return retval; |
1519 | 1519 | ||
1520 | if (blocks == 1 && !dx_fallback && | 1520 | if (blocks == 1 && !dx_fallback && |
1521 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) { | 1521 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) |
1522 | retval = make_indexed_dir(handle, dentry, inode, bh); | 1522 | return make_indexed_dir(handle, dentry, inode, bh); |
1523 | if (retval == -ENOSPC) | ||
1524 | brelse(bh); | ||
1525 | return retval; | ||
1526 | } | ||
1527 | brelse(bh); | 1523 | brelse(bh); |
1528 | } | 1524 | } |
1529 | bh = ext4_append(handle, dir, &block, &retval); | 1525 | bh = ext4_append(handle, dir, &block, &retval); |
@@ -1532,10 +1528,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, | |||
1532 | de = (struct ext4_dir_entry_2 *) bh->b_data; | 1528 | de = (struct ext4_dir_entry_2 *) bh->b_data; |
1533 | de->inode = 0; | 1529 | de->inode = 0; |
1534 | de->rec_len = ext4_rec_len_to_disk(blocksize, blocksize); | 1530 | de->rec_len = ext4_rec_len_to_disk(blocksize, blocksize); |
1535 | retval = add_dirent_to_buf(handle, dentry, inode, de, bh); | 1531 | return add_dirent_to_buf(handle, dentry, inode, de, bh); |
1536 | if (retval == -ENOSPC) | ||
1537 | brelse(bh); | ||
1538 | return retval; | ||
1539 | } | 1532 | } |
1540 | 1533 | ||
1541 | /* | 1534 | /* |
@@ -1664,8 +1657,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry, | |||
1664 | if (!de) | 1657 | if (!de) |
1665 | goto cleanup; | 1658 | goto cleanup; |
1666 | err = add_dirent_to_buf(handle, dentry, inode, de, bh); | 1659 | err = add_dirent_to_buf(handle, dentry, inode, de, bh); |
1667 | if (err != -ENOSPC) | 1660 | bh = NULL; |
1668 | bh = NULL; | ||
1669 | goto cleanup; | 1661 | goto cleanup; |
1670 | 1662 | ||
1671 | journal_error: | 1663 | journal_error: |