Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: guolingxing <guolingxing@tju.edu.cn>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] ext4: record writeback error when discarding pages on failed delalloc
Date: Fri, 16 Oct 2026 10:38:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-174186@kernel.org> (raw)
In-Reply-To: <20261016101605.4039217-1-guolingxing@tju.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ext4: data loss due to leaked give_up_on_write flag across writepages loop iterations
--

commit b95d276ed2e575cb01a2eaee0f04e704d2371b9a
Author: guolingxing <guolingxing@tju.edu.cn>

ext4: record writeback error when discarding pages on failed delalloc

When mpage_map_and_submit_extent() gives up on a failed block mapping,
it sets give_up_on_write so that mpage_release_unused_pages() discards
the remaining dirty folios. This commit calls mapping_set_error() when
deciding to give up on the write so that fsync() can report the
writeback failure.

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 6ede3644a738b..27640409aa97b 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -2637,6 +2637,12 @@ static int mpage_map_and_submit_extent(handle_t *handle,
>  				ext4_print_free_blocks(inode);
>  		invalidate_dirty_pages:
>  			*give_up_on_write = true;

[Severity: High]
Does ext4_do_writepages() leak this true value across loop iterations?

If this hits an -ENOSPC error, give_up_on_write is set to true. In
ext4_do_writepages(), it catches the -ENOSPC, forces a journal commit,
and executes continue to retry writing further pages:

fs/ext4/inode.c:ext4_do_writepages() {
    bool give_up_on_write = false;
    ...
    while (!mpd->scanned_until_end && wbc->nr_to_write > 0) {
        ...
        ret = mpage_map_and_submit_extent(handle, mpd,
                &give_up_on_write);
        ...
        mpage_release_unused_pages(mpd, give_up_on_write);
        ...
        if (ret == -ENOSPC && sbi->s_journal) {
            /*
             * Commit the transaction which would
             * free blocks released in the transaction
             * and try again
             */
            jbd2_journal_force_commit_nested(sbi->s_journal);
            ret = 0;
            continue;
        }
        ...
    }
}

Since give_up_on_write is initialized outside the loop, it isn't reset to
false. In the next iteration, if a transient error occurs (like -EAGAIN),
the leaked true value causes mpage_release_unused_pages() to aggressively
invalidate innocent unwritten folios, causing silent data loss.

Should give_up_on_write be reset per-iteration?

> +			/*
> +			 * Record the error so that a subsequent fsync()
> +			 * / errseq check can observe the data loss that
> +			 * discarding these dirty pages implies.
> +			 */
> +			mapping_set_error(inode->i_mapping, err);
>  			return err;
>  		}
>  		progress = 1;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261016101605.4039217-1-guolingxing@tju.edu.cn?part=1

  reply	other threads:[~2026-10-16 10:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 10:16 [PATCH] ext4: record writeback error when discarding pages on failed delalloc guolingxing
2026-10-16 10:38 ` sashiko-bot [this message]
2026-10-16 11:03 ` [PATCH v2] " guolingxing
2026-10-16 11:15   ` sashiko-bot

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=sashiko-outbox-174186@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=guolingxing@tju.edu.cn \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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