diff mbox

[23/29] ext4: Protect extent conversion after DIO with i_dio_count

Message ID 1365456754-29373-24-git-send-email-jack@suse.cz
State Superseded, archived
Headers show

Commit Message

Jan Kara April 8, 2013, 9:32 p.m. UTC
Make sure extent conversion after DIO happens while i_dio_count is still
elevated so that inode_dio_wait() waits until extent conversion is done.
This removes the need for explicit waiting for extent conversion in some
cases.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/inode.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

Comments

Zheng Liu May 8, 2013, 7:08 a.m. UTC | #1
On Mon, Apr 08, 2013 at 11:32:28PM +0200, Jan Kara wrote:
> Make sure extent conversion after DIO happens while i_dio_count is still
> elevated so that inode_dio_wait() waits until extent conversion is done.
> This removes the need for explicit waiting for extent conversion in some
> cases.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Regards,
                                                - Zheng

> ---
>  fs/ext4/inode.c |   12 ++++++++++--
>  1 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index f8e78ce..f493ec2 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -2914,11 +2914,18 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
>  
>  	BUG_ON(iocb->private == NULL);
>  
> +	/*
> +	 * Make all waiters for direct IO properly wait also for extent
> +	 * conversion. This also disallows race between truncate() and
> +	 * overwrite DIO as i_dio_count needs to be incremented under i_mutex.
> +	 */
> +	if (rw == WRITE)
> +		atomic_inc(&inode->i_dio_count);
> +
>  	/* If we do a overwrite dio, i_mutex locking can be released */
>  	overwrite = *((int *)iocb->private);
>  
>  	if (overwrite) {
> -		atomic_inc(&inode->i_dio_count);
>  		down_read(&EXT4_I(inode)->i_data_sem);
>  		mutex_unlock(&inode->i_mutex);
>  	}
> @@ -3013,9 +3020,10 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
>  	}
>  
>  retake_lock:
> +	if (rw == WRITE)
> +		inode_dio_done(inode);
>  	/* take i_mutex locking again if we do a ovewrite dio */
>  	if (overwrite) {
> -		inode_dio_done(inode);
>  		up_read(&EXT4_I(inode)->i_data_sem);
>  		mutex_lock(&inode->i_mutex);
>  	}
> -- 
> 1.7.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index f8e78ce..f493ec2 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2914,11 +2914,18 @@  static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 
 	BUG_ON(iocb->private == NULL);
 
+	/*
+	 * Make all waiters for direct IO properly wait also for extent
+	 * conversion. This also disallows race between truncate() and
+	 * overwrite DIO as i_dio_count needs to be incremented under i_mutex.
+	 */
+	if (rw == WRITE)
+		atomic_inc(&inode->i_dio_count);
+
 	/* If we do a overwrite dio, i_mutex locking can be released */
 	overwrite = *((int *)iocb->private);
 
 	if (overwrite) {
-		atomic_inc(&inode->i_dio_count);
 		down_read(&EXT4_I(inode)->i_data_sem);
 		mutex_unlock(&inode->i_mutex);
 	}
@@ -3013,9 +3020,10 @@  static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 	}
 
 retake_lock:
+	if (rw == WRITE)
+		inode_dio_done(inode);
 	/* take i_mutex locking again if we do a ovewrite dio */
 	if (overwrite) {
-		inode_dio_done(inode);
 		up_read(&EXT4_I(inode)->i_data_sem);
 		mutex_lock(&inode->i_mutex);
 	}