[09/10] ext4: serialize truncate with owerwrite DIO workers V2

Message ID 1348487060-19598-10-git-send-email-dmonakhov@openvz.org
State Superseded, archived
Headers show

Commit Message

Dmitry Monakhov Sept. 24, 2012, 11:44 a.m.
Jan Kara have spotted interesting issue:
There are  potential data corruption issue with  direct IO overwrites
racing with truncate:
  dio write                      truncate_task
   ->overwrite == 1
                                 # truncate data blocks, allocate them to
                                 # other inode - bad stuff happens because
                                 # dio is still in flight.

In order to serialize with truncate dio worker should grab extra i_dio_count
reference before drop i_mutex.

Changes agains V1:
- wake up dio waiters before i_mutex.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
 fs/ext4/inode.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)


diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index d3f86e7..00c3222 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3011,6 +3011,7 @@  static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 		overwrite = *((int *)iocb->private);
 		if (overwrite) {
+			atomic_inc(&inode->i_dio_count);
@@ -3108,6 +3109,7 @@  static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 		/* take i_mutex locking again if we do a ovewrite dio */
 		if (overwrite) {
+			inode_dio_done(inode);