Patchwork [1/5] ext4: allocate delalloc blocks before changing journal mode

login
register
mail settings
Submitter Yongqiang Yang
Date Nov. 15, 2011, 8:07 a.m.
Message ID <1321344474-14707-1-git-send-email-xiaoqiangnk@gmail.com>
Download mbox | patch
Permalink /patch/125723/
State Accepted
Headers show

Comments

Yongqiang Yang - Nov. 15, 2011, 8:07 a.m.
delalloc blocks should be allocated before changing journal mode,
otherwise they can not be allocated and even more truncate on
delalloc blocks could triggre BUG by flushing delalloc buffers.

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
 fs/ext4/inode.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
Toshiyuki Okajima - Dec. 9, 2011, 3:31 a.m.
(2011/11/15 17:07), Yongqiang Yang wrote:
> delalloc blocks should be allocated before changing journal mode,
> otherwise they can not be allocated and even more truncate on
> delalloc blocks could triggre BUG by flushing delalloc buffers.
> 
> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
> ---
>  fs/ext4/inode.c |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index de05e86..384f8a7 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4676,6 +4676,17 @@ 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;
> +	}
>  
>  	jbd2_journal_lock_updates(journal);
>  	jbd2_journal_flush(journal);

Though I tested your patch by my reproducer that caused a panic which you 
pointed out, a panic did not happen. 
-------------------------------------------------------------------------------
#!/bin/sh

echo "a" > /tmp/a # file under an ext4 filesystem
chattr +j /tmp/a
echo "a" >> /tmp/a
chattr -j /tmp/a
-------------------------------------------------------------------------------

So, this patch looks good to me.

Tested-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>

--
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
Theodore Ts'o - Dec. 28, 2011, 5:14 p.m.
On Tue, Nov 15, 2011 at 04:07:50PM +0800, Yongqiang Yang wrote:
> delalloc blocks should be allocated before changing journal mode,
> otherwise they can not be allocated and even more truncate on
> delalloc blocks could triggre BUG by flushing delalloc buffers.
> 
> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>

Applied, thanks.

					- Ted
--
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

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index de05e86..384f8a7 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4676,6 +4676,17 @@  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;
+	}
 
 	jbd2_journal_lock_updates(journal);
 	jbd2_journal_flush(journal);