mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
	Tristan Ye <tristan.ye@oracle.com>,
	ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ocfs2: free claimed clusters when defrag move fails
Date: Thu, 9 Jul 2026 11:59:02 +0800	[thread overview]
Message-ID: <12edcc56-8f9f-4f36-b5ca-8a4ba0f3d9f3@linux.alibaba.com> (raw)
In-Reply-To: <20260708062212.715437-1-lgs201920130244@gmail.com>



On 7/8/26 2:22 PM, Guangshuo Li wrote:
> ocfs2_defrag_extent() claims new clusters before calling
> __ocfs2_move_extent(). If __ocfs2_move_extent() fails, the newly claimed
> clusters have not been attached to the inode extent tree, but the error
> path only logs the error and continues.
> 
> The following ocfs2_cow_sync_writeback() call can then overwrite the
> original error with 0, while the claimed clusters are left allocated and
> unreferenced.
> 
> Set need_free and leave through out_commit when __ocfs2_move_extent()
> fails, so the claimed clusters are released and the original error is
> returned to the caller.
> 
> Fixes: 202ee5facb2c ("Ocfs2/move_extents: defrag a range of extent.")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  fs/ocfs2/move_extents.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
> index ad1678ee7cc4..4f1745d58a88 100644
> --- a/fs/ocfs2/move_extents.c
> +++ b/fs/ocfs2/move_extents.c
> @@ -310,8 +310,11 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context,
>  
>  	ret = __ocfs2_move_extent(handle, context, cpos, new_len, phys_cpos,
>  				  new_phys_cpos, ext_flags);
> -	if (ret)
> +	if (ret) {
>  		mlog_errno(ret);
> +		need_free = 1;
> +		goto out_commit;
> +	}
>  
>  	if (partial && (new_len != *len))
>  		*len = new_len;

__ocfs2_move_extent() calls ocfs2_split_extent() partway through, which
repoints the tree at new_phys_cpos, then can still fail in
ocfs2_decrease_refcount() (-ENOMEM from ocfs2_read_refcount_block()) or
ocfs2_truncate_log_append() (-ENOSPC). Neither aborts the handle.

On those failures the new out_commit path frees new_phys_cpos/new_len and
commits, so the clusters are both referenced by the extent tree and marked
free.

Thanks,
Joseph

  reply	other threads:[~2026-07-09  3:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  6:22 Guangshuo Li
2026-07-09  3:59 ` Joseph Qi [this message]
2026-07-14  7:54   ` Guangshuo Li

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=12edcc56-8f9f-4f36-b5ca-8a4ba0f3d9f3@linux.alibaba.com \
    --to=joseph.qi@linux.alibaba.com \
    --cc=jlbec@evilplan.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=tristan.ye@oracle.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

Powered by JetHome