From: Jan Kara <jack@suse.cz>
To: Ted Tso <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org, Akira Fujita <a-fujita@rs.jp.nec.com>,
Jan Kara <jack@suse.cz>
Subject: Re: [PATCH] ext4: Fix deadlock when writing in ENOSPC conditions
Date: Tue, 10 Dec 2013 11:56:01 +0100 [thread overview]
Message-ID: <20131210105601.GB1543@quack.suse.cz> (raw)
In-Reply-To: <1386670181-2151-1-git-send-email-jack@suse.cz>
Please ignore the below patch. It is part of the larger series I've
submitted a bit later...
Honza
On Tue 10-12-13 11:09:41, Jan Kara wrote:
> Akira-san has been reporting rare deadlocks of his machine when running
> xfstests test 269 on ext4 filesystem. The problem turned out to be in
> ext4_da_reserve_metadata() and ext4_da_reserve_space() which called
> ext4_should_retry_alloc() while holding i_data_sem. Since
> ext4_should_retry_alloc() can force a transaction commit, this is a
> lock ordering violation and leads to deadlocks.
>
> Fix the problem by just removing the retry loops. These functions should
> just report ENOSPC to the caller (e.g. ext4_da_write_begin()) and that
> function must take care of retrying after dropping all necessary locks.
>
> Reported-and-tested-by: Akira Fujita <a-fujita@rs.jp.nec.com>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> fs/ext4/inode.c | 12 ------------
> 1 file changed, 12 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 075763474118..61d49ff22c81 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -1206,7 +1206,6 @@ static int ext4_journalled_write_end(struct file *file,
> */
> static int ext4_da_reserve_metadata(struct inode *inode, ext4_lblk_t lblock)
> {
> - int retries = 0;
> struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
> struct ext4_inode_info *ei = EXT4_I(inode);
> unsigned int md_needed;
> @@ -1218,7 +1217,6 @@ static int ext4_da_reserve_metadata(struct inode *inode, ext4_lblk_t lblock)
> * in order to allocate nrblocks
> * worse case is one extent per block
> */
> -repeat:
> spin_lock(&ei->i_block_reservation_lock);
> /*
> * ext4_calc_metadata_amount() has side effects, which we have
> @@ -1238,10 +1236,6 @@ repeat:
> ei->i_da_metadata_calc_len = save_len;
> ei->i_da_metadata_calc_last_lblock = save_last_lblock;
> spin_unlock(&ei->i_block_reservation_lock);
> - if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
> - cond_resched();
> - goto repeat;
> - }
> return -ENOSPC;
> }
> ei->i_reserved_meta_blocks += md_needed;
> @@ -1255,7 +1249,6 @@ repeat:
> */
> static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock)
> {
> - int retries = 0;
> struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
> struct ext4_inode_info *ei = EXT4_I(inode);
> unsigned int md_needed;
> @@ -1277,7 +1270,6 @@ static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock)
> * in order to allocate nrblocks
> * worse case is one extent per block
> */
> -repeat:
> spin_lock(&ei->i_block_reservation_lock);
> /*
> * ext4_calc_metadata_amount() has side effects, which we have
> @@ -1297,10 +1289,6 @@ repeat:
> ei->i_da_metadata_calc_len = save_len;
> ei->i_da_metadata_calc_last_lblock = save_last_lblock;
> spin_unlock(&ei->i_block_reservation_lock);
> - if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
> - cond_resched();
> - goto repeat;
> - }
> dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1));
> return -ENOSPC;
> }
> --
> 1.8.1.4
>
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
prev parent reply other threads:[~2013-12-10 10:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-10 10:09 [PATCH] ext4: Fix deadlock when writing in ENOSPC conditions Jan Kara
2013-12-10 10:56 ` Jan Kara [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131210105601.GB1543@quack.suse.cz \
--to=jack@suse.cz \
--cc=a-fujita@rs.jp.nec.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).