diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index c862ee5fe79d..b3c243b9afa5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -732,11 +732,13 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, | |||
732 | err = ext4_map_blocks(handle, inode, &map, | 732 | err = ext4_map_blocks(handle, inode, &map, |
733 | create ? EXT4_GET_BLOCKS_CREATE : 0); | 733 | create ? EXT4_GET_BLOCKS_CREATE : 0); |
734 | 734 | ||
735 | /* ensure we send some value back into *errp */ | ||
736 | *errp = 0; | ||
737 | |||
735 | if (err < 0) | 738 | if (err < 0) |
736 | *errp = err; | 739 | *errp = err; |
737 | if (err <= 0) | 740 | if (err <= 0) |
738 | return NULL; | 741 | return NULL; |
739 | *errp = 0; | ||
740 | 742 | ||
741 | bh = sb_getblk(inode->i_sb, map.m_pblk); | 743 | bh = sb_getblk(inode->i_sb, map.m_pblk); |
742 | if (!bh) { | 744 | if (!bh) { |
@@ -1954,9 +1956,6 @@ out: | |||
1954 | return ret; | 1956 | return ret; |
1955 | } | 1957 | } |
1956 | 1958 | ||
1957 | static int ext4_set_bh_endio(struct buffer_head *bh, struct inode *inode); | ||
1958 | static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate); | ||
1959 | |||
1960 | /* | 1959 | /* |
1961 | * Note that we don't need to start a transaction unless we're journaling data | 1960 | * Note that we don't need to start a transaction unless we're journaling data |
1962 | * because we should have holes filled from ext4_page_mkwrite(). We even don't | 1961 | * because we should have holes filled from ext4_page_mkwrite(). We even don't |
@@ -2463,6 +2462,16 @@ static int ext4_nonda_switch(struct super_block *sb) | |||
2463 | free_blocks = EXT4_C2B(sbi, | 2462 | free_blocks = EXT4_C2B(sbi, |
2464 | percpu_counter_read_positive(&sbi->s_freeclusters_counter)); | 2463 | percpu_counter_read_positive(&sbi->s_freeclusters_counter)); |
2465 | dirty_blocks = percpu_counter_read_positive(&sbi->s_dirtyclusters_counter); | 2464 | dirty_blocks = percpu_counter_read_positive(&sbi->s_dirtyclusters_counter); |
2465 | /* | ||
2466 | * Start pushing delalloc when 1/2 of free blocks are dirty. | ||
2467 | */ | ||
2468 | if (dirty_blocks && (free_blocks < 2 * dirty_blocks) && | ||
2469 | !writeback_in_progress(sb->s_bdi) && | ||
2470 | down_read_trylock(&sb->s_umount)) { | ||
2471 | writeback_inodes_sb(sb, WB_REASON_FS_FREE_SPACE); | ||
2472 | up_read(&sb->s_umount); | ||
2473 | } | ||
2474 | |||
2466 | if (2 * free_blocks < 3 * dirty_blocks || | 2475 | if (2 * free_blocks < 3 * dirty_blocks || |
2467 | free_blocks < (dirty_blocks + EXT4_FREECLUSTERS_WATERMARK)) { | 2476 | free_blocks < (dirty_blocks + EXT4_FREECLUSTERS_WATERMARK)) { |
2468 | /* | 2477 | /* |
@@ -2471,13 +2480,6 @@ static int ext4_nonda_switch(struct super_block *sb) | |||
2471 | */ | 2480 | */ |
2472 | return 1; | 2481 | return 1; |
2473 | } | 2482 | } |
2474 | /* | ||
2475 | * Even if we don't switch but are nearing capacity, | ||
2476 | * start pushing delalloc when 1/2 of free blocks are dirty. | ||
2477 | */ | ||
2478 | if (free_blocks < 2 * dirty_blocks) | ||
2479 | writeback_inodes_sb_if_idle(sb, WB_REASON_FS_FREE_SPACE); | ||
2480 | |||
2481 | return 0; | 2483 | return 0; |
2482 | } | 2484 | } |
2483 | 2485 | ||
@@ -2879,9 +2881,6 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, | |||
2879 | { | 2881 | { |
2880 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; | 2882 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; |
2881 | ext4_io_end_t *io_end = iocb->private; | 2883 | ext4_io_end_t *io_end = iocb->private; |
2882 | struct workqueue_struct *wq; | ||
2883 | unsigned long flags; | ||
2884 | struct ext4_inode_info *ei; | ||
2885 | 2884 | ||
2886 | /* if not async direct IO or dio with 0 bytes write, just return */ | 2885 | /* if not async direct IO or dio with 0 bytes write, just return */ |
2887 | if (!io_end || !size) | 2886 | if (!io_end || !size) |
@@ -2910,24 +2909,14 @@ out: | |||
2910 | io_end->iocb = iocb; | 2909 | io_end->iocb = iocb; |
2911 | io_end->result = ret; | 2910 | io_end->result = ret; |
2912 | } | 2911 | } |
2913 | wq = EXT4_SB(io_end->inode->i_sb)->dio_unwritten_wq; | ||
2914 | 2912 | ||
2915 | /* Add the io_end to per-inode completed aio dio list*/ | 2913 | ext4_add_complete_io(io_end); |
2916 | ei = EXT4_I(io_end->inode); | ||
2917 | spin_lock_irqsave(&ei->i_completed_io_lock, flags); | ||
2918 | list_add_tail(&io_end->list, &ei->i_completed_io_list); | ||
2919 | spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); | ||
2920 | |||
2921 | /* queue the work to convert unwritten extents to written */ | ||
2922 | queue_work(wq, &io_end->work); | ||
2923 | } | 2914 | } |
2924 | 2915 | ||
2925 | static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate) | 2916 | static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate) |
2926 | { | 2917 | { |
2927 | ext4_io_end_t *io_end = bh->b_private; | 2918 | ext4_io_end_t *io_end = bh->b_private; |
2928 | struct workqueue_struct *wq; | ||
2929 | struct inode *inode; | 2919 | struct inode *inode; |
2930 | unsigned long flags; | ||
2931 | 2920 | ||
2932 | if (!test_clear_buffer_uninit(bh) || !io_end) | 2921 | if (!test_clear_buffer_uninit(bh) || !io_end) |
2933 | goto out; | 2922 | goto out; |
@@ -2946,15 +2935,7 @@ static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate) | |||
2946 | */ | 2935 | */ |
2947 | inode = io_end->inode; | 2936 | inode = io_end->inode; |
2948 | ext4_set_io_unwritten_flag(inode, io_end); | 2937 | ext4_set_io_unwritten_flag(inode, io_end); |
2949 | 2938 | ext4_add_complete_io(io_end); | |
2950 | /* Add the io_end to per-inode completed io list*/ | ||
2951 | spin_lock_irqsave(&EXT4_I(inode)->i_completed_io_lock, flags); | ||
2952 | list_add_tail(&io_end->list, &EXT4_I(inode)->i_completed_io_list); | ||
2953 | spin_unlock_irqrestore(&EXT4_I(inode)->i_completed_io_lock, flags); | ||
2954 | |||
2955 | wq = EXT4_SB(inode->i_sb)->dio_unwritten_wq; | ||
2956 | /* queue the work to convert unwritten extents to written */ | ||
2957 | queue_work(wq, &io_end->work); | ||
2958 | out: | 2939 | out: |
2959 | bh->b_private = NULL; | 2940 | bh->b_private = NULL; |
2960 | bh->b_end_io = NULL; | 2941 | bh->b_end_io = NULL; |
@@ -3029,6 +3010,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3029 | overwrite = *((int *)iocb->private); | 3010 | overwrite = *((int *)iocb->private); |
3030 | 3011 | ||
3031 | if (overwrite) { | 3012 | if (overwrite) { |
3013 | atomic_inc(&inode->i_dio_count); | ||
3032 | down_read(&EXT4_I(inode)->i_data_sem); | 3014 | down_read(&EXT4_I(inode)->i_data_sem); |
3033 | mutex_unlock(&inode->i_mutex); | 3015 | mutex_unlock(&inode->i_mutex); |
3034 | } | 3016 | } |
@@ -3054,7 +3036,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3054 | * hook to the iocb. | 3036 | * hook to the iocb. |
3055 | */ | 3037 | */ |
3056 | iocb->private = NULL; | 3038 | iocb->private = NULL; |
3057 | EXT4_I(inode)->cur_aio_dio = NULL; | 3039 | ext4_inode_aio_set(inode, NULL); |
3058 | if (!is_sync_kiocb(iocb)) { | 3040 | if (!is_sync_kiocb(iocb)) { |
3059 | ext4_io_end_t *io_end = | 3041 | ext4_io_end_t *io_end = |
3060 | ext4_init_io_end(inode, GFP_NOFS); | 3042 | ext4_init_io_end(inode, GFP_NOFS); |
@@ -3071,7 +3053,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3071 | * is a unwritten extents needs to be converted | 3053 | * is a unwritten extents needs to be converted |
3072 | * when IO is completed. | 3054 | * when IO is completed. |
3073 | */ | 3055 | */ |
3074 | EXT4_I(inode)->cur_aio_dio = iocb->private; | 3056 | ext4_inode_aio_set(inode, io_end); |
3075 | } | 3057 | } |
3076 | 3058 | ||
3077 | if (overwrite) | 3059 | if (overwrite) |
@@ -3091,7 +3073,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3091 | NULL, | 3073 | NULL, |
3092 | DIO_LOCKING); | 3074 | DIO_LOCKING); |
3093 | if (iocb->private) | 3075 | if (iocb->private) |
3094 | EXT4_I(inode)->cur_aio_dio = NULL; | 3076 | ext4_inode_aio_set(inode, NULL); |
3095 | /* | 3077 | /* |
3096 | * The io_end structure takes a reference to the inode, | 3078 | * The io_end structure takes a reference to the inode, |
3097 | * that structure needs to be destroyed and the | 3079 | * that structure needs to be destroyed and the |
@@ -3126,6 +3108,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
3126 | retake_lock: | 3108 | retake_lock: |
3127 | /* take i_mutex locking again if we do a ovewrite dio */ | 3109 | /* take i_mutex locking again if we do a ovewrite dio */ |
3128 | if (overwrite) { | 3110 | if (overwrite) { |
3111 | inode_dio_done(inode); | ||
3129 | up_read(&EXT4_I(inode)->i_data_sem); | 3112 | up_read(&EXT4_I(inode)->i_data_sem); |
3130 | mutex_lock(&inode->i_mutex); | 3113 | mutex_lock(&inode->i_mutex); |
3131 | } | 3114 | } |
@@ -4052,6 +4035,7 @@ static int ext4_do_update_inode(handle_t *handle, | |||
4052 | struct ext4_inode_info *ei = EXT4_I(inode); | 4035 | struct ext4_inode_info *ei = EXT4_I(inode); |
4053 | struct buffer_head *bh = iloc->bh; | 4036 | struct buffer_head *bh = iloc->bh; |
4054 | int err = 0, rc, block; | 4037 | int err = 0, rc, block; |
4038 | int need_datasync = 0; | ||
4055 | uid_t i_uid; | 4039 | uid_t i_uid; |
4056 | gid_t i_gid; | 4040 | gid_t i_gid; |
4057 | 4041 | ||
@@ -4102,7 +4086,10 @@ static int ext4_do_update_inode(handle_t *handle, | |||
4102 | raw_inode->i_file_acl_high = | 4086 | raw_inode->i_file_acl_high = |
4103 | cpu_to_le16(ei->i_file_acl >> 32); | 4087 | cpu_to_le16(ei->i_file_acl >> 32); |
4104 | raw_inode->i_file_acl_lo = cpu_to_le32(ei->i_file_acl); | 4088 | raw_inode->i_file_acl_lo = cpu_to_le32(ei->i_file_acl); |
4105 | ext4_isize_set(raw_inode, ei->i_disksize); | 4089 | if (ei->i_disksize != ext4_isize(raw_inode)) { |
4090 | ext4_isize_set(raw_inode, ei->i_disksize); | ||
4091 | need_datasync = 1; | ||
4092 | } | ||
4106 | if (ei->i_disksize > 0x7fffffffULL) { | 4093 | if (ei->i_disksize > 0x7fffffffULL) { |
4107 | struct super_block *sb = inode->i_sb; | 4094 | struct super_block *sb = inode->i_sb; |
4108 | if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, | 4095 | if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, |
@@ -4155,7 +4142,7 @@ static int ext4_do_update_inode(handle_t *handle, | |||
4155 | err = rc; | 4142 | err = rc; |
4156 | ext4_clear_inode_state(inode, EXT4_STATE_NEW); | 4143 | ext4_clear_inode_state(inode, EXT4_STATE_NEW); |
4157 | 4144 | ||
4158 | ext4_update_inode_fsync_trans(handle, inode, 0); | 4145 | ext4_update_inode_fsync_trans(handle, inode, need_datasync); |
4159 | out_brelse: | 4146 | out_brelse: |
4160 | brelse(bh); | 4147 | brelse(bh); |
4161 | ext4_std_error(inode->i_sb, err); | 4148 | ext4_std_error(inode->i_sb, err); |
@@ -4298,7 +4285,6 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) | |||
4298 | } | 4285 | } |
4299 | 4286 | ||
4300 | if (attr->ia_valid & ATTR_SIZE) { | 4287 | if (attr->ia_valid & ATTR_SIZE) { |
4301 | inode_dio_wait(inode); | ||
4302 | 4288 | ||
4303 | if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { | 4289 | if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { |
4304 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 4290 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
@@ -4347,8 +4333,17 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) | |||
4347 | } | 4333 | } |
4348 | 4334 | ||
4349 | if (attr->ia_valid & ATTR_SIZE) { | 4335 | if (attr->ia_valid & ATTR_SIZE) { |
4350 | if (attr->ia_size != i_size_read(inode)) | 4336 | if (attr->ia_size != i_size_read(inode)) { |
4351 | truncate_setsize(inode, attr->ia_size); | 4337 | truncate_setsize(inode, attr->ia_size); |
4338 | /* Inode size will be reduced, wait for dio in flight. | ||
4339 | * Temporarily disable dioread_nolock to prevent | ||
4340 | * livelock. */ | ||
4341 | if (orphan) { | ||
4342 | ext4_inode_block_unlocked_dio(inode); | ||
4343 | inode_dio_wait(inode); | ||
4344 | ext4_inode_resume_unlocked_dio(inode); | ||
4345 | } | ||
4346 | } | ||
4352 | ext4_truncate(inode); | 4347 | ext4_truncate(inode); |
4353 | } | 4348 | } |
4354 | 4349 | ||
@@ -4727,6 +4722,10 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) | |||
4727 | return err; | 4722 | return err; |
4728 | } | 4723 | } |
4729 | 4724 | ||
4725 | /* Wait for all existing dio workers */ | ||
4726 | ext4_inode_block_unlocked_dio(inode); | ||
4727 | inode_dio_wait(inode); | ||
4728 | |||
4730 | jbd2_journal_lock_updates(journal); | 4729 | jbd2_journal_lock_updates(journal); |
4731 | 4730 | ||
4732 | /* | 4731 | /* |
@@ -4746,6 +4745,7 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) | |||
4746 | ext4_set_aops(inode); | 4745 | ext4_set_aops(inode); |
4747 | 4746 | ||
4748 | jbd2_journal_unlock_updates(journal); | 4747 | jbd2_journal_unlock_updates(journal); |
4748 | ext4_inode_resume_unlocked_dio(inode); | ||
4749 | 4749 | ||
4750 | /* Finally we can mark the inode as dirty. */ | 4750 | /* Finally we can mark the inode as dirty. */ |
4751 | 4751 | ||
@@ -4780,6 +4780,7 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
4780 | int retries = 0; | 4780 | int retries = 0; |
4781 | 4781 | ||
4782 | sb_start_pagefault(inode->i_sb); | 4782 | sb_start_pagefault(inode->i_sb); |
4783 | file_update_time(vma->vm_file); | ||
4783 | /* Delalloc case is easy... */ | 4784 | /* Delalloc case is easy... */ |
4784 | if (test_opt(inode->i_sb, DELALLOC) && | 4785 | if (test_opt(inode->i_sb, DELALLOC) && |
4785 | !ext4_should_journal_data(inode) && | 4786 | !ext4_should_journal_data(inode) && |