linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2 2/3] ext4: fix races between changing inode journal mode and ext4_writepages
@ 2016-03-02  1:21 Daeho Jeong
  0 siblings, 0 replies; 3+ messages in thread
From: Daeho Jeong @ 2016-03-02  1:21 UTC (permalink / raw)
  To: kbuild test robot, tytso@mit.edu, jack@suse.cz
  Cc: kbuild-all@01.org, linux-ext4@vger.kernel.org, daeho.jeong

Oops, This build error log is genereated when building ext4 filesystem as a module and
this is originated from that "percpu_free_rwsem()" function was not defined as an exported
function.

Could I define the "percpu_free_rwsem()" function as an exported function directly in this patch?
Or do I have to request the maintainer of percpu_rwsem to do this?

Thank you in advance. :-)

> url:    https://github.com/0day-ci/linux/commits/Daeho-Jeong/ext4-handle-unwritten-or-delalloc-buffers-before-enabling-per-file-dat> a-journaling/20160229-075117
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
> config: x86_64-randconfig-s2-02290828 (attached as .config)
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=x86_64 

> All errors (new ones prefixed by >>):

> >> ERROR: "percpu_free_rwsem" [fs/ext4/ext4.ko] undefined!

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [PATCH v2 1/3] ext4: handle unwritten or delalloc buffers before enabling per-file data journaling
@ 2016-02-28 23:48 Daeho Jeong
  2016-02-28 23:48 ` [PATCH v2 2/3] ext4: fix races between changing inode journal mode and ext4_writepages Daeho Jeong
  0 siblings, 1 reply; 3+ messages in thread
From: Daeho Jeong @ 2016-02-28 23:48 UTC (permalink / raw)
  To: tytso, jack, linux-ext4; +Cc: Daeho Jeong

We already allocate delalloc blocks before changing the inode mode into
"per-file data journal" mode to prevent delalloc blocks from remaining
not allocated, but another issue concerned with "BH_Unwritten" status
still exists. For example, by fallocate(), several buffers' status
change into "BH_Unwritten", but these buffers cannot be processed by
ext4_alloc_da_blocks(). So, they still remain in unwritten status after
per-file data journaling is enabled and they cannot be changed into
written status any more and, if they are journaled and eventually
checkpointed, these unwritten buffer will cause a kernel panic by the
below BUG_ON() function of submit_bh_wbc() when they are submitted
during checkpointing.

static int submit_bh_wbc(int rw, struct buffer_head *bh,...
{
        ...
        BUG_ON(buffer_unwritten(bh));

Moreover, when "dioread_nolock" option is enabled, the status of a
buffer is changed into "BH_Unwritten" after write_begin() completes and
the "BH_Unwritten" status will be cleared after I/O is done. Therefore,
if a buffer's status is changed into unwrutten but the buffer's I/O is
not submitted and completed, it can cause the same problem after
enabling per-file data journaling. You can easily generate this bug by
executing the following command.

./kvm-xfstests -C 10000 -m nodelalloc,dioread_nolock generic/269

To resolve these problems and define a boundary between the previous
mode and per-file data journaling mode, we need to flush and wait all
the I/O of buffers of a file before enabling per-file data journaling
of the file.

Signed-off-by: Daeho Jeong <daeho.jeong@samsung.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/inode.c |   31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9cc57c3..9ecfb76 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5378,22 +5378,29 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
 		return 0;
 	if (is_journal_aborted(journal))
 		return -EROFS;
-	/* We have to allocate physical blocks for delalloc blocks
-	 * before flushing journal. otherwise delalloc blocks can not
-	 * be allocated any more. even more truncate on delalloc blocks
-	 * could trigger BUG by flushing delalloc blocks in journal.
-	 * There is no delalloc block in non-journal data mode.
-	 */
-	if (val && test_opt(inode->i_sb, DELALLOC)) {
-		err = ext4_alloc_da_blocks(inode);
-		if (err < 0)
-			return err;
-	}
 
 	/* Wait for all existing dio workers */
 	ext4_inode_block_unlocked_dio(inode);
 	inode_dio_wait(inode);
 
+	/*
+	 * Before flushing the journal and switching inode's aops, we have
+	 * to flush all dirty data the inode has. There can be outstanding
+	 * delayed allocations, there can be unwritten extents created by
+	 * fallocate or buffered writes in dioread_nolock mode covered by
+	 * dirty data which can be converted only after flushing the dirty
+	 * data (and journalled aops don't know how to handle these cases).
+	 */
+	if (val) {
+		down_write(&EXT4_I(inode)->i_mmap_sem);
+		err = filemap_write_and_wait(inode->i_mapping);
+		if (err < 0) {
+			up_write(&EXT4_I(inode)->i_mmap_sem);
+			ext4_inode_resume_unlocked_dio(inode);
+			return err;
+		}
+	}
+
 	jbd2_journal_lock_updates(journal);
 
 	/*
@@ -5418,6 +5425,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
 	ext4_set_aops(inode);
 
 	jbd2_journal_unlock_updates(journal);
+	if (val)
+		up_write(&EXT4_I(inode)->i_mmap_sem);
 	ext4_inode_resume_unlocked_dio(inode);
 
 	/* Finally we can mark the inode as dirty. */
-- 
1.7.9.5


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

end of thread, other threads:[~2016-03-02  1:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-02  1:21 [PATCH v2 2/3] ext4: fix races between changing inode journal mode and ext4_writepages Daeho Jeong
  -- strict thread matches above, loose matches on Subject: below --
2016-02-28 23:48 [PATCH v2 1/3] ext4: handle unwritten or delalloc buffers before enabling per-file data journaling Daeho Jeong
2016-02-28 23:48 ` [PATCH v2 2/3] ext4: fix races between changing inode journal mode and ext4_writepages Daeho Jeong
2016-02-29  1:29   ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).