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

Submitted by Dmitri Monakho on Sept. 28, 2012, 3:44 p.m.


Message ID 1348847051-6746-10-git-send-email-dmonakhov@openvz.org
State Accepted, archived
Headers show

Commit Message

Dmitri Monakho Sept. 28, 2012, 3:44 p.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(-)

Patch hide | download patch | download mbox

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index c40a98d..14b7096 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2982,6 +2982,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);
@@ -3079,6 +3080,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);