From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out199-3.us.a.mail.aliyun.com (out199-3.us.a.mail.aliyun.com [47.90.199.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27D20439356 for ; Thu, 9 Jul 2026 03:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.199.3 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783569558; cv=none; b=co7egk7P+zJPYcWqIZCFcBG+FmZfu3ziSDn05i9QmcdIVJTwn6nCIIpKEztUq+7o0W7d+ccTVowcM5W+4rB2LfLg/zD8xrCzBJvU7Bj/88aoTHK9g/5PD0TXS7ZAMM3QpsW7vt8+4MeZFQee+21E0fwioog9CDNDqOohHMR9zJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783569558; c=relaxed/simple; bh=IbBIkaZF46cqMJlPORp7pYbXNvhdj6iKnPJ6S0DXL9I=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=idSnPiRJSQKSqQ+ovPM1dti6XUlGT54ABbw4wWyBD/VPWVboIYMieYoUKrZLDWtBnTFgMWx6i2C0I7xdz1j00nNHd+sqwm+sNpJdSuQbmnOzmc+bdhXiaBPp2BuZG+/eW5/OXXn1VMgi0J3gNtrxFF2pL3E+P/sUIuKyVFzwQ+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=OTIYXhg6; arc=none smtp.client-ip=47.90.199.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="OTIYXhg6" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1783569544; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=buQdi0BomK5CB74T7xDmUNZVePMYb8bI5undGI57DXk=; b=OTIYXhg6bN0PRG0Y2L4qnZwtE4SAC0EEodX9mAmOXGcOpnmGIoHr36D+1cGi5RpUPG44QUIYgd25xlhVHTF6H2QM36dlmzSnAW6mYZmaa7XQ3yYPdaAMJWV87hwVggCWyGN9yWMiPf7s3wg+AMh2UvN05nuOV2JZeb6N5BGW77E= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R921e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0X6jKSMW_1783569543; Received: from 30.221.145.97(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0X6jKSMW_1783569543 cluster:ay36) by smtp.aliyun-inc.com; Thu, 09 Jul 2026 11:59:04 +0800 Message-ID: <12edcc56-8f9f-4f36-b5ca-8a4ba0f3d9f3@linux.alibaba.com> Date: Thu, 9 Jul 2026 11:59:02 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] ocfs2: free claimed clusters when defrag move fails To: Guangshuo Li References: <20260708062212.715437-1-lgs201920130244@gmail.com> Cc: Mark Fasheh , Joel Becker , Tristan Ye , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org From: Joseph Qi In-Reply-To: <20260708062212.715437-1-lgs201920130244@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > --- > 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