mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hyunchul Lee <hyc.lee@gmail.com>
To: Hongling Zeng <zenghongling@kylinos.cn>
Cc: linkinjeon@kernel.org, ntfs@lists.linux.dev,
	linux-kernel@vger.kernel.org, zhongling0719@126.com
Subject: Re: [PATCH v4] ntfs: handle a failed size rollback in the write error path
Date: Wed, 21 Oct 2026 10:52:57 +0900	[thread overview]
Message-ID: <atga-YNByHiwk-y0@hyunchul-PC02> (raw)
In-Reply-To: <20261020070641.793832-1-zenghongling@kylinos.cn>

> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> index d810ca5904bd..ad032cccfb15 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -934,23 +934,46 @@ ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
>  				&ntfs_iomap_folio_ops, NULL);
>  out:
>  	if (ret < 0 && ret != -EIOCBQUEUED) {
> -		if (ni->initialized_size != old_init_size) {
> -			struct ntfs_inode *mrec_ni =
> -				ntfs_base_inode(ni);
> +		int init_err = 0;
> +		int data_err = 0;
>  
> +		if (ni->data_size != old_data_size) {
> +			struct ntfs_inode *mrec_ni = ntfs_base_inode(ni);
> +
> +			truncate_setsize(vi, old_data_size);
> +			/*
> +			 * ntfs_attr_truncate() would reject a compressed
> +			 * attribute.
> +			 */
>  			mutex_lock(&mrec_ni->mrec_lock);
> -			ntfs_attr_set_initialized_size(ni, old_init_size);
> +			data_err = __ntfs_attr_truncate_vfs(ni, old_data_size,
> +					old_data_size);
>  			mutex_unlock(&mrec_ni->mrec_lock);
> +			/* Like ntfs_setattr_size(): stay on the durable size. */
> +			if (data_err)
> +				i_size_write(vi, ni->data_size);
>  		}
> -		if (ni->data_size != old_data_size) {
> -			struct ntfs_inode *mrec_ni =
> -				ntfs_base_inode(ni);
> +		/*
> +		 * The shrink above may leave the initialized size above
> +		 * the old one; ntfs_attr_set_initialized_size() rejects
> +		 * a resident attribute.
> +		 */
> +		if (ni->initialized_size != old_init_size &&
> +		    NInoNonResident(ni)) {
> +			struct ntfs_inode *mrec_ni = ntfs_base_inode(ni);
>  
> -			truncate_setsize(vi, old_data_size);
>  			mutex_lock(&mrec_ni->mrec_lock);
> -			ntfs_attr_truncate(ni, old_data_size);
> +			init_err = ntfs_attr_set_initialized_size(ni,
> +					old_init_size);

The shrink above can clamp initialzied_size to old_data_size. If
ntfs_attr_set_initialized_size() fails, the initialized_size remains
instead of being restored to old_init_size. For a compressed file,
this can expose stale data.

Could you restore the initialized_size first and perform the shink only
if that rollback succeeds?

-- 
Thanks,
Hyunchul

  reply	other threads:[~2026-10-21  1:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20  7:06 Hongling Zeng
2026-10-21  1:52 ` Hyunchul Lee [this message]
2026-10-21  2:52   ` Hongling Zeng

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=atga-YNByHiwk-y0@hyunchul-PC02 \
    --to=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs@lists.linux.dev \
    --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®