From nobody Sun Dec 14 05:52:24 2025 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38E7E19CCF5 for ; Fri, 12 Dec 2025 07:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765522834; cv=none; b=G6zfAf/cHI/JmmGIR/V1L2SGqNvjpof+Bd2enD7fwnTwKtFseHDB+wPtVQ/HrjPtHL1z/r0f3hhneHrADLTKbTv7GKdYInHyMukR6fa8Iqk+x3f6RBPo7ymrtJAxoMrk/VFhXoSYYBI1ifspGgpkQMIzWPX7drRGs603B6TYPLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765522834; c=relaxed/simple; bh=MFi/erZFW/WIYd6hrvxk7ChTVOOgkAQH/Yx3B0zM2tg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t/gqbcotSbkA8PCLf7sgac/Ov8wc/lIiXOwNuKsi+y1PZAwfrdYgTxdVssKhSGVxUihd8RgctgE82SjLuZ7707RxQ4dxkrqNcJ+myVzmOeritO9K/BScIHHAyw91HDshezwH0gApqeSiMdi1O4f3Ckzelt6s1S16g9570W10uNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Gw0+acVS; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Gw0+acVS" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-477aa91e75dso962725e9.3 for ; Thu, 11 Dec 2025 23:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765522830; x=1766127630; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P05KKxYK3bHA72OQxEvz6zLFou6nxqg/1zGwgDAaaQY=; b=Gw0+acVS+Fg0W+zBs0KrJ4dqW6Qf/DV3cQTPtmBp04aWLCkZlVOXqOMEGszcQX+ijJ AfwKieOQexuy8NLocbAlu/1l+nngpIKrQLlm//RmepZhhHjZa8k0ZYDBRFwC3tLhRSXm g8GO7v+9QjC5tSz5Bs1rB6vJEICzZDq1msj6Mm7gGgqWKGmN/1PaHK8mQLu12g7D21eJ sVMoZYKwD0C+d5uG2PDGiGdeQ0Mj4nC3Ve51BIefDI7q+3hWGfAnY8unhnysSjiEImbW jYo5llnl0Lbn5I/TTBVSTUr7PpO+0IJGGUvOv/DA7K8pYvSU/l6T/jqHuDcnAX1hjNof +cbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765522830; x=1766127630; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=P05KKxYK3bHA72OQxEvz6zLFou6nxqg/1zGwgDAaaQY=; b=CpRrySmJGpyOUFqC/6mg2K09YXtLUC7aiZocvkrD9NRdOM33KgsvTe8I0UBgF52u0i stIXg/3K90l+LKKQALs8/PHIvI2++xweUNEiQDykKiGuyYWsKt7hLKR8FM4LNPO4hSb7 +/ahwvbEGvi39Co5fr0d85Tghx3kNpFbQYS3vyDHpnDpc1834lysgKrm8VGQbwlYhoRh N+YxyTLGTayxaqQ3nW3ekIghIWXS9dmZXVBxnbKAM8enno9f52q17sszXZ11c69/3B99 sixAPsAha94FdGBwLYYt6HTJm/AmXTD+FmnYkco3oRX4n55BzRWnucol9X1V/hSwcVuU VJjg== X-Forwarded-Encrypted: i=1; AJvYcCWsP8Ju/lxDBaeAHBCiOlndRhdSvgvPD4jMFFjOMX0lXXK0YphxSxop07On4UiFKEYOcsWEMbua/YBfDlo=@vger.kernel.org X-Gm-Message-State: AOJu0YyOqjnZrR5Glxvr3bZTNWz+HqONKISN4NBCZtnyJaeY597nLIKD PtYuQMPhTjajTgbzTXxR34Du2epw8ZgLQwQh7YmIFcC+B/X7Z9GyJh7aorZ3k8hNLCaV9JeM+Te qdNj1 X-Gm-Gg: AY/fxX7tj+Q1jlPbn8JbKbopDxcA98hD0ErpbaDHVCR9DSksfOdtqEXNlCKB8O+fiwj IHgO8xpUEfSvAKGzA2KjwTDa0TVUW78qKdbP8FhYYQ7LmFvl50q3oVaMnQIuBMubE9rlWaedjpR USn+j41JTT3uDiP58+4jEOy5ZhI1tRSiSqqs3gNYr4OPooMq9qwj58VkFLuqwjINcqDBN1i/aPQ KWhEKtttYBnKKmPt1gaSVy/6cEmpwhO92cfpWopmu16wbZ/7CLvjw+Ffqp+AA6jdRWhc2AEaz1A kgJciUgWBYm32xO3L9ZcArG7jnR9PLUWi4GkAkZS+KqpXi4Nd5Nr/8BM+iP/oCkoxsv1/LT48vO BVjrLtttCcx7lodQJWrClSZvwinimuQNGkZSbuG6AiX6LyJBdmn2ZIBv7oO3EpdpzzKPIM1RJ8G lGu8bFRQ1O+/c= X-Google-Smtp-Source: AGHT+IGcq+cFG+dRzA3qM2yHmEm4MsN1Q6v6Y3sCz5WR8gav4UKjPh2qadxkZdnKbKettYRNvNT71A== X-Received: by 2002:a05:600c:34cb:b0:47a:8bfa:bd5 with SMTP id 5b1f17b1804b1-47a8f92285emr5105155e9.8.1765522830237; Thu, 11 Dec 2025 23:00:30 -0800 (PST) Received: from p15.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29ee9d38c74sm44479145ad.31.2025.12.11.23.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 23:00:28 -0800 (PST) From: Heming Zhao To: joseph.qi@linux.alibaba.com, mark@fasheh.com, jlbec@evilplan.org Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, glass.su@suse.com Subject: [PATCH v5 1/2] ocfs2: give ocfs2 the ability to reclaim suballocator free bg Date: Fri, 12 Dec 2025 15:00:13 +0800 Message-ID: <20251212070016.24235-2-heming.zhao@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251212070016.24235-1-heming.zhao@suse.com> References: <20251212070016.24235-1-heming.zhao@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current ocfs2 code can't reclaim suballocator block group space. In some cases, this causes ocfs2 to hold onto a lot of space. For example, when creating lots of small files, the space is held/managed by the '//inode_alloc'. After the user deletes all the small files, the space never returns to the '//global_bitmap'. This issue prevents ocfs2 from providing the needed space even when there is enough free space in a small ocfs2 volume. This patch gives ocfs2 the ability to reclaim suballocator free space when the block group is freed. For performance reasons, this patch keeps the first suballocator block group active. Signed-off-by: Heming Zhao Reviewed-by: Su Yue --- fs/ocfs2/suballoc.c | 308 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 299 insertions(+), 9 deletions(-) diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 6ac4dcd54588..9a19f5230c8c 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c @@ -294,6 +294,74 @@ static int ocfs2_validate_group_descriptor(struct supe= r_block *sb, return ocfs2_validate_gd_self(sb, bh, 0); } =20 +/* + * The hint group descriptor (gd) may already have been released + * in _ocfs2_free_suballoc_bits(). We first check the gd signature, + * then perform the standard ocfs2_read_group_descriptor() jobs. + * + * If the gd signature is invalid, we return 'rc=3D0' and set + * '*released=3D1'. The caller is expected to handle this specific case. + * Otherwise, we return the actual error code. + * + * We treat gd signature corruption case as a release case. The + * caller ocfs2_claim_suballoc_bits() will use ocfs2_search_chain() + * to search each gd block. The code will eventually find this + * corrupted gd block - Late, but not missed. + * + * Note: + * The caller is responsible for initializing the '*released' status. + */ +static int ocfs2_read_hint_group_descriptor(struct inode *inode, + struct ocfs2_dinode *di, u64 gd_blkno, + struct buffer_head **bh, int *released) +{ + int rc; + struct buffer_head *tmp =3D *bh; + struct ocfs2_group_desc *gd; + + rc =3D ocfs2_read_block(INODE_CACHE(inode), gd_blkno, &tmp, NULL); + if (rc) + goto out; + + gd =3D (struct ocfs2_group_desc *) tmp->b_data; + if (!OCFS2_IS_VALID_GROUP_DESC(gd)) { + /* + * Invalid gd cache was set in ocfs2_read_block(), + * which will affect block_group allocation. + * Path: + * ocfs2_reserve_suballoc_bits + * ocfs2_block_group_alloc + * ocfs2_block_group_alloc_contig + * ocfs2_set_new_buffer_uptodate + */ + ocfs2_remove_from_cache(INODE_CACHE(inode), tmp); + *released =3D 1; /* we return 'rc=3D0' for this case */ + goto free_bh; + } + + /* below jobs same with ocfs2_read_group_descriptor() */ + if (!buffer_jbd(tmp)) { + rc =3D ocfs2_validate_group_descriptor(inode->i_sb, tmp); + if (rc) + goto free_bh; + } + + rc =3D ocfs2_validate_gd_parent(inode->i_sb, di, tmp, 0); + if (rc) + goto free_bh; + + /* If ocfs2_read_block() got us a new bh, pass it up. */ + if (!*bh) + *bh =3D tmp; + + return rc; + +free_bh: + brelse(tmp); +out: + return rc; +} + int ocfs2_read_group_descriptor(struct inode *inode, struct ocfs2_dinode *= di, u64 gd_blkno, struct buffer_head **bh) { @@ -1724,7 +1792,7 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_= context *ac, u32 bits_wanted, u32 min_bits, struct ocfs2_suballoc_result *res, - u16 *bits_left) + u16 *bits_left, int *released) { int ret; struct buffer_head *group_bh =3D NULL; @@ -1732,9 +1800,11 @@ static int ocfs2_search_one_group(struct ocfs2_alloc= _context *ac, struct ocfs2_dinode *di =3D (struct ocfs2_dinode *)ac->ac_bh->b_data; struct inode *alloc_inode =3D ac->ac_inode; =20 - ret =3D ocfs2_read_group_descriptor(alloc_inode, di, - res->sr_bg_blkno, &group_bh); - if (ret < 0) { + ret =3D ocfs2_read_hint_group_descriptor(alloc_inode, di, + res->sr_bg_blkno, &group_bh, released); + if (*released) { + return 0; + } else if (ret < 0) { mlog_errno(ret); return ret; } @@ -1949,6 +2019,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_all= oc_context *ac, struct ocfs2_suballoc_result *res) { int status; + int released =3D 0; u16 victim, i; u16 bits_left =3D 0; u64 hint =3D ac->ac_last_group; @@ -1975,6 +2046,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_all= oc_context *ac, goto bail; } =20 + /* the hint bg may already be released, we quiet search this group. */ res->sr_bg_blkno =3D hint; if (res->sr_bg_blkno) { /* Attempt to short-circuit the usual search mechanism @@ -1982,7 +2054,12 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_al= loc_context *ac, * allocation group. This helps us maintain some * contiguousness across allocations. */ status =3D ocfs2_search_one_group(ac, handle, bits_wanted, - min_bits, res, &bits_left); + min_bits, res, &bits_left, + &released); + if (released) { + res->sr_bg_blkno =3D 0; + goto chain_search; + } if (!status) goto set_hint; if (status < 0 && status !=3D -ENOSPC) { @@ -1990,7 +2067,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_all= oc_context *ac, goto bail; } } - +chain_search: cl =3D (struct ocfs2_chain_list *) &fe->id2.i_chain; =20 victim =3D ocfs2_find_victim_chain(cl); @@ -2102,6 +2179,12 @@ int ocfs2_claim_metadata(handle_t *handle, return status; } =20 +/* + * after ocfs2 has the ability to release block group unused space, + * the ->ip_last_used_group may be invalid. so this function returns + * ac->ac_last_group need to verify. + * refer the 'hint' in ocfs2_claim_suballoc_bits() for more details. + */ static void ocfs2_init_inode_ac_group(struct inode *dir, struct buffer_head *parent_di_bh, struct ocfs2_alloc_context *ac) @@ -2540,6 +2623,198 @@ static int ocfs2_block_group_clear_bits(handle_t *h= andle, return status; } =20 +/* + * Reclaim the suballocator managed space to main bitmap. + * This function first works on the suballocator to perform the + * cleanup rec/alloc_inode job, then switches to the main bitmap + * to reclaim released space. + * + * handle: The transaction handle + * alloc_inode: The suballoc inode + * alloc_bh: The buffer_head of suballoc inode + * group_bh: The group descriptor buffer_head of suballocator managed. + * Caller should release the input group_bh. + */ +static int _ocfs2_reclaim_suballoc_to_main(handle_t *handle, + struct inode *alloc_inode, + struct buffer_head *alloc_bh, + struct buffer_head *group_bh) +{ + int idx, status =3D 0; + int i, next_free_rec, len =3D 0; + __le16 old_bg_contig_free_bits =3D 0; + u16 start_bit; + u32 tmp_used; + u64 bg_blkno, start_blk; + unsigned int count; + struct ocfs2_chain_rec *rec; + struct buffer_head *main_bm_bh =3D NULL; + struct inode *main_bm_inode =3D NULL; + struct ocfs2_super *osb =3D OCFS2_SB(alloc_inode->i_sb); + struct ocfs2_dinode *fe =3D (struct ocfs2_dinode *) alloc_bh->b_data; + struct ocfs2_chain_list *cl =3D &fe->id2.i_chain; + struct ocfs2_group_desc *group =3D (struct ocfs2_group_desc *) group_bh->= b_data; + + idx =3D le16_to_cpu(group->bg_chain); + rec =3D &(cl->cl_recs[idx]); + + status =3D ocfs2_extend_trans(handle, + ocfs2_calc_group_alloc_credits(osb->sb, + le16_to_cpu(cl->cl_cpg))); + if (status) { + mlog_errno(status); + goto bail; + } + status =3D ocfs2_journal_access_di(handle, INODE_CACHE(alloc_inode), + alloc_bh, OCFS2_JOURNAL_ACCESS_WRITE); + if (status < 0) { + mlog_errno(status); + goto bail; + } + + /* + * Only clear the suballocator rec item in-place. + * + * If idx is not the last, we don't compress (remove the empty item) + * the cl_recs[]. If not, we need to do lots jobs. + * + * Compress cl_recs[] code example: + * if (idx !=3D cl->cl_next_free_rec - 1) + * memmove(&cl->cl_recs[idx], &cl->cl_recs[idx + 1], + * sizeof(struct ocfs2_chain_rec) * + * (cl->cl_next_free_rec - idx - 1)); + * for(i =3D idx; i < cl->cl_next_free_rec-1; i++) { + * group->bg_chain =3D "later group->bg_chain"; + * group->bg_blkno =3D xxx; + * ... ... + * } + */ + + tmp_used =3D le32_to_cpu(fe->id1.bitmap1.i_total); + fe->id1.bitmap1.i_total =3D cpu_to_le32(tmp_used - le32_to_cpu(rec->c_tot= al)); + + /* Substraction 1 for the block group itself */ + tmp_used =3D le32_to_cpu(fe->id1.bitmap1.i_used); + fe->id1.bitmap1.i_used =3D cpu_to_le32(tmp_used - 1); + + tmp_used =3D le32_to_cpu(fe->i_clusters); + fe->i_clusters =3D cpu_to_le32(tmp_used - le16_to_cpu(cl->cl_cpg)); + + spin_lock(&OCFS2_I(alloc_inode)->ip_lock); + OCFS2_I(alloc_inode)->ip_clusters -=3D le32_to_cpu(fe->i_clusters); + fe->i_size =3D cpu_to_le64(ocfs2_clusters_to_bytes(alloc_inode->i_sb, + le32_to_cpu(fe->i_clusters))); + spin_unlock(&OCFS2_I(alloc_inode)->ip_lock); + i_size_write(alloc_inode, le64_to_cpu(fe->i_size)); + alloc_inode->i_blocks =3D ocfs2_inode_sector_count(alloc_inode); + + ocfs2_journal_dirty(handle, alloc_bh); + ocfs2_update_inode_fsync_trans(handle, alloc_inode, 0); + + start_blk =3D le64_to_cpu(rec->c_blkno); + count =3D le32_to_cpu(rec->c_total) / le16_to_cpu(cl->cl_bpc); + + /* + * If the rec is the last one, let's compress the chain list by + * removing the empty cl_recs[] at the end. + */ + next_free_rec =3D le16_to_cpu(cl->cl_next_free_rec); + if (idx =3D=3D (next_free_rec - 1)) { + len++; /* the last item should be counted first */ + for (i =3D (next_free_rec - 2); i > 0; i--) { + if (cl->cl_recs[i].c_free =3D=3D cl->cl_recs[i].c_total) + len++; + else + break; + } + } + le16_add_cpu(&cl->cl_next_free_rec, -len); + + rec->c_free =3D 0; + rec->c_total =3D 0; + rec->c_blkno =3D 0; + ocfs2_remove_from_cache(INODE_CACHE(alloc_inode), group_bh); + memset(group, 0, sizeof(struct ocfs2_group_desc)); + + /* prepare job for reclaim clusters */ + main_bm_inode =3D ocfs2_get_system_file_inode(osb, + GLOBAL_BITMAP_SYSTEM_INODE, + OCFS2_INVALID_SLOT); + if (!main_bm_inode) + goto bail; /* ignore the error in reclaim path */ + + inode_lock(main_bm_inode); + + status =3D ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1); + if (status < 0) + goto free_bm_inode; /* ignore the error in reclaim path */ + + ocfs2_block_to_cluster_group(main_bm_inode, start_blk, &bg_blkno, + &start_bit); + fe =3D (struct ocfs2_dinode *) main_bm_bh->b_data; + cl =3D &fe->id2.i_chain; + /* reuse group_bh, caller will release the input group_bh */ + group_bh =3D NULL; + + /* reclaim clusters to global_bitmap */ + status =3D ocfs2_read_group_descriptor(main_bm_inode, fe, bg_blkno, + &group_bh); + if (status < 0) { + mlog_errno(status); + goto free_bm_bh; + } + group =3D (struct ocfs2_group_desc *) group_bh->b_data; + + if ((count + start_bit) > le16_to_cpu(group->bg_bits)) { + ocfs2_error(alloc_inode->i_sb, + "reclaim length (%d) beyands block group length (%d)", + count + start_bit, le16_to_cpu(group->bg_bits)); + goto free_group_bh; + } + + old_bg_contig_free_bits =3D group->bg_contig_free_bits; + status =3D ocfs2_block_group_clear_bits(handle, main_bm_inode, + group, group_bh, + start_bit, count, 0, + _ocfs2_clear_bit); + if (status < 0) { + mlog_errno(status); + goto free_group_bh; + } + + status =3D ocfs2_journal_access_di(handle, INODE_CACHE(main_bm_inode), + main_bm_bh, OCFS2_JOURNAL_ACCESS_WRITE); + if (status < 0) { + mlog_errno(status); + ocfs2_block_group_set_bits(handle, main_bm_inode, group, group_bh, + start_bit, count, + le16_to_cpu(old_bg_contig_free_bits), 1); + goto free_group_bh; + } + + idx =3D le16_to_cpu(group->bg_chain); + rec =3D &(cl->cl_recs[idx]); + + le32_add_cpu(&rec->c_free, count); + tmp_used =3D le32_to_cpu(fe->id1.bitmap1.i_used); + fe->id1.bitmap1.i_used =3D cpu_to_le32(tmp_used - count); + ocfs2_journal_dirty(handle, main_bm_bh); + +free_group_bh: + brelse(group_bh); + +free_bm_bh: + ocfs2_inode_unlock(main_bm_inode, 1); + brelse(main_bm_bh); + +free_bm_inode: + inode_unlock(main_bm_inode); + iput(main_bm_inode); + +bail: + return status; +} + /* * expects the suballoc inode to already be locked. */ @@ -2552,12 +2827,13 @@ static int _ocfs2_free_suballoc_bits(handle_t *hand= le, void (*undo_fn)(unsigned int bit, unsigned long *bitmap)) { - int status =3D 0; + int idx, status =3D 0; u32 tmp_used; struct ocfs2_dinode *fe =3D (struct ocfs2_dinode *) alloc_bh->b_data; struct ocfs2_chain_list *cl =3D &fe->id2.i_chain; struct buffer_head *group_bh =3D NULL; struct ocfs2_group_desc *group; + struct ocfs2_chain_rec *rec; __le16 old_bg_contig_free_bits =3D 0; =20 /* The alloc_bh comes from ocfs2_free_dinode() or @@ -2603,12 +2879,26 @@ static int _ocfs2_free_suballoc_bits(handle_t *hand= le, goto bail; } =20 - le32_add_cpu(&cl->cl_recs[le16_to_cpu(group->bg_chain)].c_free, - count); + idx =3D le16_to_cpu(group->bg_chain); + rec =3D &(cl->cl_recs[idx]); + + le32_add_cpu(&rec->c_free, count); tmp_used =3D le32_to_cpu(fe->id1.bitmap1.i_used); fe->id1.bitmap1.i_used =3D cpu_to_le32(tmp_used - count); ocfs2_journal_dirty(handle, alloc_bh); =20 + /* + * Reclaim suballocator free space. + * Bypass: global_bitmap, non empty rec, first rec in cl_recs[] + */ + if (ocfs2_is_cluster_bitmap(alloc_inode) || + (le32_to_cpu(rec->c_free) !=3D (le32_to_cpu(rec->c_total) - 1)) || + (le16_to_cpu(cl->cl_next_free_rec) =3D=3D 1)) { + goto bail; + } + + _ocfs2_reclaim_suballoc_to_main(handle, alloc_inode, alloc_bh, group_bh); + bail: brelse(group_bh); return status; --=20 2.43.0 From nobody Sun Dec 14 05:52:24 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DCCB3C38 for ; Fri, 12 Dec 2025 07:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765522837; cv=none; b=a8zTcExzV0TARDDyfVwdde+s/7oWIMf9tE2XfqPVinZSMVhy8EBJEiRQXonJjdnDm+RdkvJHg598GzCRqG5hmJsXjk67vG3gBkS9pe5zhY42s6BxNhqnTBEKzHO+nbby3eT54HPEgFT6g/ePcksiVm5XhDe0mvvoH1jYH09gKck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765522837; c=relaxed/simple; bh=Evs5QQATIk0sNsyehuiCaQOTsbxa/fjc0hXZd7wTlXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oxFjltH8PUyPVGVgA0d/6nDjfp9/2lpooXjWwuzTU07bHJa9FKz9gbDj9WP3VcxOFhHjs3iMCPiIllzOT8famnqk4SUHzt+y8WSNqsczEAU0du+v53OFj1r4EJuxnaYPRBxOACyNSKJk/VEYLFuv1EUpZz2H/SGJsSaMFMGAti8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=HdUIaQTB; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="HdUIaQTB" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-42b5dfa4e9eso99606f8f.0 for ; Thu, 11 Dec 2025 23:00:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765522833; x=1766127633; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GxXUWWraavNZv54vBuFyK/VfBOztE6hI+jfRRJkFQFs=; b=HdUIaQTBq7DgefDTtyISaHxSSSQp4iuyZXGKhTH7vBYWaZLVfUy+blZmMm07LMj+wp 504yZFF6AknRwM/SJTwos/+tz1/zK75A/0qjtING1Z4UwNzQtyzvbs+laDua38NQBdOU jqul8mfcC8Zi9fiL323KB4qteGvqpdSro2UOc4zPnSlPJxIKjLi9ANrJVBwLOA6xDT4o eHlVHwaSJjDgQw9KUVqM+x4eOk37i/yFzNF0ia+vmeoawVeUcgQZWlUPnCBJCTEi8YWj 9tf4iuaKstbA4EvBro4kBWOU+fofPg3l3MvjM2g6hLCiMGlQEOtYeZmYmlKJsFpydxyj bfLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765522833; x=1766127633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=GxXUWWraavNZv54vBuFyK/VfBOztE6hI+jfRRJkFQFs=; b=gh9f98mAaK4/r1UYoS8imWi49dA2eaXFIWSsrwIjg4CsFe7V/HkcCJfcxxDNeECUbh S63CjFc1vZVTBVwH6uqE9F5nlnoWhX3CrhU85+sObTu/7J+0c5W+NjHZSGku9qjjBcnt 4v8cdkQifcjwVF/3Vb1BCtC4g2HjzfFc0foja2XfejFgofvkRuuQHHpxnUCOIz5kse2s 36ZeM8FSCZr7YjVPfWLyQiFNVzSX4G24KimrR37/RH5YZp64MpRV4yeDm78/qZP8/cZs b+3h38/7uaAKSm964bFsd/xogSV+XIgmpO+EAuHkTwrroKsokkq2gv8/MFuKZf10sqm7 RlJg== X-Forwarded-Encrypted: i=1; AJvYcCVaiM7jWs/9Sxge2EizhEChgzkhG6IhssQXp8wJfkVTmAU1h3HU1eNz19fvnSjIqN9FltG9Pfc8PjS6PAg=@vger.kernel.org X-Gm-Message-State: AOJu0YymlC/XdtdBWSt4fPLZsz5byBoNNTNMG0ksmMmNnJ/XBGsVYkgr NmWf71ywBrkAW5zG2mXCH1+BohLfkIasYK+P706szEclsdi+LM0gng+w47TgfF0wGTLT9SdT8Ib a9u3M X-Gm-Gg: AY/fxX66g5kvR7a2DqrXUX032F78cEQmijugFfnMdqZbRLB6Ox95aaDLUZ78PPzBMOL fTvhrjem2ht1s42hIq/q3yySELzYcar7Z0Kw7NhhcqVlvALV6wOAG+hsbthKHBu0Q8Ao1NxtxTR /RnZvqxVHU+DnfVkzNxq+wrxv+edYaSM3kYKwe1cnbEwsEsbgVTMDMLw64hcWQbVFgxOzFSldzd YGqfP7cr3JbvUEEdfr6GxzNI67+mDxm5bCAW/ne4IOHH96ihhKmvE+d0kQ+1UnhsH4SOpEhoaqV FgyZTt57RgxYYe7EI9gImwoBvB25IkWBn4MrWOKClNPQ0t3GXD6ads83H36o+ZNS9Ya5if6llKO JMztYryEsZCzDYSVy+u0bumJkpnGUqcYFret40rf2fuPOwqau8wnKceysX5EgYqJsjtYif5+chS DacOyOw051QG8dXg+EeiiS1w== X-Google-Smtp-Source: AGHT+IFA53IyEiFb68nHZUn7/d0cwMWOehrqr8ylyNpy+E7MrSw8ju0jqjgEBSkU/GZW8iSGd9yb7A== X-Received: by 2002:a05:600c:1992:b0:477:c5a9:33ce with SMTP id 5b1f17b1804b1-47a8f904696mr5013075e9.4.1765522833258; Thu, 11 Dec 2025 23:00:33 -0800 (PST) Received: from p15.suse.cz ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29ee9d38c74sm44479145ad.31.2025.12.11.23.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 23:00:32 -0800 (PST) From: Heming Zhao To: joseph.qi@linux.alibaba.com, mark@fasheh.com, jlbec@evilplan.org Cc: Heming Zhao , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, glass.su@suse.com Subject: [PATCH v5 2/2] ocfs2: detect released suballocator BG for fh_to_[dentry|parent] Date: Fri, 12 Dec 2025 15:00:14 +0800 Message-ID: <20251212070016.24235-3-heming.zhao@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251212070016.24235-1-heming.zhao@suse.com> References: <20251212070016.24235-1-heming.zhao@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After ocfs2 gained the ability to reclaim suballocator free block group (BGs), a suballocator block group may be released. This change causes the xfstest case generic/426 to fail. generic/426 expects return value -ENOENT or -ESTALE, but the current code triggers -EROFS. Call stack before ocfs2 gained the ability to reclaim bg: ocfs2_fh_to_dentry //or ocfs2_fh_to_parent ocfs2_get_dentry + ocfs2_test_inode_bit | ocfs2_test_suballoc_bit | + ocfs2_read_group_descriptor //Since ocfs2 never releases the bg, | | //the bg block was always found. | + *res =3D ocfs2_test_bit //unlink was called, and the bit is zero | + if (!set) //because the above *res is 0 status =3D -ESTALE //the generic/426 expected return value Current call stack that triggers -EROFS: ocfs2_get_dentry ocfs2_test_inode_bit ocfs2_test_suballoc_bit ocfs2_read_group_descriptor + if reading a released bg, validation fails and triggers -EROFS How to fix: Since the read BG is already released, we must avoid triggering -EROFS. With this commit, we use ocfs2_read_hint_group_descriptor() to detect the released BG block. This approach quietly handles this type of error and returns -EINVAL, which triggers the caller's existing conversion path to -ESTALE. Signed-off-by: Heming Zhao Reviewed-by: Su Yue --- fs/ocfs2/export.c | 6 ++++-- fs/ocfs2/suballoc.c | 28 ++++++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/fs/ocfs2/export.c b/fs/ocfs2/export.c index b95724b767e1..9c2665dd24e2 100644 --- a/fs/ocfs2/export.c +++ b/fs/ocfs2/export.c @@ -74,8 +74,9 @@ static struct dentry *ocfs2_get_dentry(struct super_block= *sb, * nice */ status =3D -ESTALE; - } else + } else if (status !=3D -ESTALE) { mlog(ML_ERROR, "test inode bit failed %d\n", status); + } goto unlock_nfs_sync; } =20 @@ -162,8 +163,9 @@ static struct dentry *ocfs2_get_parent(struct dentry *c= hild) if (status < 0) { if (status =3D=3D -EINVAL) { status =3D -ESTALE; - } else + } else if (status !=3D -ESTALE) { mlog(ML_ERROR, "test inode bit failed %d\n", status); + } parent =3D ERR_PTR(status); goto bail_unlock; } diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 9a19f5230c8c..ddcfa6e001e8 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c @@ -3152,7 +3152,7 @@ static int ocfs2_test_suballoc_bit(struct ocfs2_super= *osb, struct ocfs2_group_desc *group; struct buffer_head *group_bh =3D NULL; u64 bg_blkno; - int status; + int status, quiet =3D 0, released; =20 trace_ocfs2_test_suballoc_bit((unsigned long long)blkno, (unsigned int)bit); @@ -3168,11 +3168,15 @@ static int ocfs2_test_suballoc_bit(struct ocfs2_sup= er *osb, =20 bg_blkno =3D group_blkno ? group_blkno : ocfs2_which_suballoc_group(blkno, bit); - status =3D ocfs2_read_group_descriptor(suballoc, alloc_di, bg_blkno, - &group_bh); - if (status < 0) { + status =3D ocfs2_read_hint_group_descriptor(suballoc, alloc_di, bg_blkno, + &group_bh, &released); + if (released) { + quiet =3D 1; + status =3D -ESTALE; + goto bail; + } else if (status < 0) { mlog(ML_ERROR, "read group %llu failed %d\n", - (unsigned long long)bg_blkno, status); + (unsigned long long)bg_blkno, status); goto bail; } =20 @@ -3182,7 +3186,7 @@ static int ocfs2_test_suballoc_bit(struct ocfs2_super= *osb, bail: brelse(group_bh); =20 - if (status) + if (status && (!quiet)) mlog_errno(status); return status; } @@ -3202,7 +3206,7 @@ static int ocfs2_test_suballoc_bit(struct ocfs2_super= *osb, */ int ocfs2_test_inode_bit(struct ocfs2_super *osb, u64 blkno, int *res) { - int status; + int status, quiet =3D 0; u64 group_blkno =3D 0; u16 suballoc_bit =3D 0, suballoc_slot =3D 0; struct inode *inode_alloc_inode; @@ -3244,8 +3248,12 @@ int ocfs2_test_inode_bit(struct ocfs2_super *osb, u6= 4 blkno, int *res) =20 status =3D ocfs2_test_suballoc_bit(osb, inode_alloc_inode, alloc_bh, group_blkno, blkno, suballoc_bit, res); - if (status < 0) - mlog(ML_ERROR, "test suballoc bit failed %d\n", status); + if (status < 0) { + if (status =3D=3D -ESTALE) + quiet =3D 1; + else + mlog(ML_ERROR, "test suballoc bit failed %d\n", status); + } =20 ocfs2_inode_unlock(inode_alloc_inode, 0); inode_unlock(inode_alloc_inode); @@ -3253,7 +3261,7 @@ int ocfs2_test_inode_bit(struct ocfs2_super *osb, u64= blkno, int *res) iput(inode_alloc_inode); brelse(alloc_bh); bail: - if (status) + if (status && !quiet) mlog_errno(status); return status; } --=20 2.43.0