public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: fix race aio-dio vs freeze_fs
@ 2015-11-23 16:02 Dmitry Monakhov
  2015-11-23 16:37 ` Dmitry Monakhov
  2015-11-24 13:24 ` Jan Kara
  0 siblings, 2 replies; 8+ messages in thread
From: Dmitry Monakhov @ 2015-11-23 16:02 UTC (permalink / raw)
  To: linux-ext4; +Cc: jack, tytso, Dmitry Monakhov

After freeze_fs was revoked (from Jan Kara) pages's write-back completion
is deffered before unwritten conversion, so explicit flush_unwritten_io()
was removed here: c724585b62411
But we still may face deferred conversion for aio-dio case
# Trivial testcase
for ((i=0;i<60;i++));do fsfreeze -f /mnt ;sleep 1;fsfreeze -u /mnt;done &
fio --bs=4k --ioengine=libaio --iodepth=128 --size=1g --direct=1 \
    --runtime=60 --filename=/mnt/file --name=rand-write --rw=randwrite
NOTE: Sane testcase should be integrated to xfstests, but it requires
changes in common/* code, so let's use this this test at the moment.

In order to fix this race we have to guard journal transaction with explicit
sb_{start,end}_intwrite()  as we do with ext4_evict_inode here:8e8ad8a5

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 fs/ext4/extents.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 3a6197a..4cba944 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5040,6 +5040,12 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 	max_blocks = ((EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) -
 		      map.m_lblk);
 	/*
+	 * Protect us against freezing - AIO-DIO case. Caller didn't have to
+	 * have any protection against it
+	 */
+	sb_start_intwrite(inode->i_sb);
+
+	/*
 	 * This is somewhat ugly but the idea is clear: When transaction is
 	 * reserved, everything goes into it. Otherwise we rather start several
 	 * smaller transactions for conversion of each extent separately.
@@ -5083,6 +5089,7 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 	}
 	if (!credits)
 		ret2 = ext4_journal_stop(handle);
+	sb_end_intwrite(inode->i_sb);
 	return ret > 0 ? ret2 : ret;
 }
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-11-25 10:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-23 16:02 [PATCH] ext4: fix race aio-dio vs freeze_fs Dmitry Monakhov
2015-11-23 16:37 ` Dmitry Monakhov
2015-11-24 13:31   ` Jan Kara
2015-11-24 13:24 ` Jan Kara
2015-11-24 16:07   ` Christoph Hellwig
2015-11-25 10:25     ` Jan Kara
2015-11-24 16:55   ` Dmitry Monakhov
2015-11-25  9:19     ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox