From: liubaolin <liubaolin12138@163.com>
To: Hongling Zeng <zenghongling@kylinos.cn>,
linkinjeon@kernel.org, hyc.lee@gmail.com
Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
zhongling0719@126.com, stable@vger.kernel.org
Subject: Re: [PATCH 2/6] ntfs: roll back the size update when the attribute lookup fails
Date: Wed, 25 Nov 2026 22:05:50 +0800 [thread overview]
Message-ID: <89ca24c7-1ba8-41e1-81ef-1b60b7cc64bd@163.com> (raw)
In-Reply-To: <20261125073547.154150-3-zenghongling@kylinos.cn>
在 2026/11/25 15:35, Hongling Zeng 写道:
> ntfs_enlarge_attribute() truncates the attribute to the end of the
> write before looking it up again, because the truncation can move the
> attribute to a different mft record. If that lookup fails, the error
> is returned but the attribute stays at the extended size, so a failed
> write extends the file.
>
> Undo the truncation before returning the error. If the rollback fails
> as well, mark the volume as having errors and synchronize i_size with
> the current data_size instead of the old snapshot.
>
> Fixes: af0db57d4293 ("ntfs: update inode operations")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> ---
> fs/ntfs/inode.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 46 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
> index 4fbdcd459652..7d7bb741455e 100644
> --- a/fs/ntfs/inode.c
> +++ b/fs/ntfs/inode.c
> @@ -3842,8 +3842,19 @@ static inline int ntfs_enlarge_attribute(struct inode *vi, s64 pos, s64 count,
> {
> struct ntfs_inode *ni = NTFS_I(vi);
> struct super_block *sb = vi->i_sb;
> + unsigned long flags;
> + s64 old_data_size;
> int ret;
>
> + /*
> + * Snapshot the old data_size under size_lock: it is the rollback
> + * target, the other sizes are updated by ntfs_attr_truncate()
> + * itself
> + */
> + read_lock_irqsave(&ni->size_lock, flags);
> + old_data_size = ni->data_size;
> + read_unlock_irqrestore(&ni->size_lock, flags);
> +
> if (pos + count <= ni->initialized_size)
> return 0;
>
> @@ -3853,7 +3864,7 @@ static inline int ntfs_enlarge_attribute(struct inode *vi, s64 pos, s64 count,
> if (NInoCompressed(ni))
> return -EOPNOTSUPP;
>
> - if (pos + count > ni->data_size) {
> + if (pos + count > old_data_size) {
> ret = ntfs_attr_truncate(ni, pos + count);
> if (ret) {
> ntfs_debug("Failed to truncate attribute");
> @@ -3865,7 +3876,40 @@ static inline int ntfs_enlarge_attribute(struct inode *vi, s64 pos, s64 count,
> CASE_SENSITIVE,
> 0, NULL, 0, ctx);
> if (ret) {
> - ntfs_error(sb, "Failed to look up attr %#x", ni->type);
> + int rollback_err;
> +
> + /*
> + * The truncation already happened, so undo it
> + * before returning the error
> + */
> + rollback_err = ntfs_attr_truncate(ni, old_data_size);
Hi Hongling,
Thanks for sending this patch series.
Could this rollback deadlock with writeback?
ntfs_inode_attr_pwrite() holds mrec_ni->mrec_lock when calling
ntfs_enlarge_attribute(). For a non-resident attribute, the rollback
can reach ntfs_non_resident_attr_shrink() and truncate_inode_pages(),
which may wait for a folio lock.
Meanwhile, iomap writeback can hold that folio lock and wait for the
same mrec_lock in ntfs_write_iomap_begin_non_resident():
rollback: mrec_lock -> folio lock
writeback: folio lock -> mrec_lock
The folio containing the old EOF may already be dirty from an earlier
write, so this does not require the failed write to have copied any
data.
Could we avoid waiting for folios while holding mrec_lock, without
allowing concurrent writes to interfere with the rollback?
Thanks,
Baolin.
> + if (rollback_err) {
> + s64 current_data_size;
> +
> + /*
> + * Rollback failed, the sizes may be
> + * inconsistent. Mark the volume as having
> + * errors and sync i_size with the current
> + * data_size
> + */
> + read_lock_irqsave(&ni->size_lock, flags);
> + current_data_size = ni->data_size;
> + read_unlock_irqrestore(&ni->size_lock, flags);
> +
> + i_size_write(vi, current_data_size);
> + NVolSetErrors(ni->vol);
> + ntfs_error(sb,
> + "Failed to look up attr %#x and "
> + "roll back the size update: %d",
> + ni->type, rollback_err);
> + } else {
> + /*
> + * Rollback succeeded, the sizes were updated
> + * by ntfs_attr_truncate() itself
> + */
> + ntfs_error(sb, "Failed to look up attr %#x",
> + ni->type);
> + }
> return ret;
> }
> }
next prev parent reply other threads:[~2026-11-25 14:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 7:35 [PATCH 0/6] ntfs: synchronize the in-memory size handling Hongling Zeng
2026-11-25 7:35 ` [PATCH 1/6] ntfs: mark the record dirtied by a resident write at iomap begin Hongling Zeng
2026-11-25 7:35 ` [PATCH 2/6] ntfs: roll back the size update when the attribute lookup fails Hongling Zeng
2026-11-25 14:05 ` liubaolin [this message]
2026-11-25 7:35 ` [PATCH 3/6] ntfs: read initialized_size under size_lock in the iomap paths Hongling Zeng
2026-11-25 14:07 ` liubaolin
2026-11-25 7:35 ` [PATCH 4/6] ntfs: update the in-memory sizes under the size lock Hongling Zeng
2026-11-25 14:08 ` liubaolin
2026-11-25 7:35 ` [PATCH 5/6] ntfs: serialize the mmap write fault initialized size update Hongling Zeng
2026-11-25 14:08 ` liubaolin
2026-11-25 7:35 ` [PATCH 6/6] ntfs: read initialized_size under size_lock in the mmap prepare path Hongling Zeng
2026-11-25 14:08 ` liubaolin
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=89ca24c7-1ba8-41e1-81ef-1b60b7cc64bd@163.com \
--to=liubaolin12138@163.com \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zenghongling@kylinos.cn \
--cc=zhongling0719@126.com \
/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
all inboxes | Powered by JetHome®