From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 66F7430148B for ; Tue, 2 Dec 2025 06:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764657595; cv=none; b=PhJJvoXDs0Xk7T9tH2nUNbTnCLLMDdMDhn+bOqOZE3evkRz7Lp3MIGKVflBPFlls6NR9sJQJsHdeTuVhb5calIf+RwpiSDGc7zvtOUH4tD1TxK4ExacuLGRxga+5Ou/pOtm5eZIyBGH0tKEY8wvFDtg2s3kbOIkYva4En28khyU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764657595; c=relaxed/simple; bh=u3tF8zKd7NcYJDtduBDGjGpk5WLn+y3aUQFW19+tjRo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nB8VyG6powfK+msHchWJ/Mpd9IA4UQO/uJCwp3ZkjMBVlVgzR1m+n45BPH17QDLGTZN+qmf09iILxrKwcWG/509GIRzj2OYcPfWmGcGHyRhGuqCF2lN/ya5NEgsRZhelM8MG3qAObP6TTK9tIUbomMLl0DVcPHaT4lk2begvZy4= 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=WegTIJbh; arc=none smtp.client-ip=209.85.128.48 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="WegTIJbh" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4779d8286d8so5707015e9.0 for ; Mon, 01 Dec 2025 22:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1764657591; x=1765262391; 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=W9MWQEkUmssQH7h8+ZJJJrAiWh1kVuLIvHyNZDUo2Ps=; b=WegTIJbhWXWv/pes+ab7Z6qQV7qErEvB795lVjVpaTHlFwBuJlesH75Q0H+q2Ny9Xl TTF67aoxfCZxmyUbZ+c4ecqykepxvsdai0ELBWYjWBApyffsq9/Y2VwB3FNOr3DWyaBn GMP1LPwnDUw1u4/HioHzYXWhUeGBVtNOszHnSEo9XpkjId4sCdCvmZ8fGXi8GtC11Qem JeLhU5cOwmxaVCQdo7SQiP/5WZMlJOFDq2Ww4w37bE5SwIzZjZUKOAOHmknPM8ZpwdHI 0k21jfQdLC2TCWn+dQ8qk0XnJlY7KpVpyVOifW7R/hRXUf9PVkDOkgdQTbs3pRrU2O9B kGJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764657591; x=1765262391; 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=W9MWQEkUmssQH7h8+ZJJJrAiWh1kVuLIvHyNZDUo2Ps=; b=fRqJ0dvp81AFJ1ehUwgYUxPNQufnze1/Yek2B9jMTYd03EmW3oOtqnGF+P4zBqx7Tl ftDCGRXRwzhOjeAnnWYd29VVI5D3TOqD41ePVoIKLj05mAA/ilxy16KFyOy6P9QL+XOL p2SFCA4c/nyFcakD2uOtV/OP+d1Ku/uHq6VNI675pFWUy9IXc/PhcwC0LKSnH+Q3sZm8 ISQBRnJrueoR2rscVjsIR+DvW9Y4x7dxhavSO+d5ryGkmXJRNUhJpRanCgw+XG8aQOrj cystrGLYx6JwkRnkonjqUtvETMGw/+PnmBllEHMgZv/zw8rysB9+QmDvjT79anc0B6z2 DmJQ== X-Forwarded-Encrypted: i=1; AJvYcCXChoITmUO/ZIRvAia1C0uI9cUl2+Q4NAK10Vx88VQkmGQi7KuyZxLJNTGq+IrmIY+X33arH9qRg4Fifr0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc6nqYArMwuDkQcdPKaw/Umeslx5Thia6J7RGa0juGjeuUgKsu IfQfEhLg14ld4t5zM67EGqFgRHcCBMUhHaTPZy5aFHpOMB21xvKXV9uWhxqECviOIhI= X-Gm-Gg: ASbGncsBmCCe3D3REIP+1rXsqYl4OWRP21M0J8jGm/qG7ZupeUCBJ3Zpyn3HCKiavib oaJ0nj9Um9PoLetdcCNChHEhvE9kSdXQq6bEY3qyoG7xlT61ZdzcK3O8o1dH7TIxgsZY7gJ0KxC pxca1GRtxfpr7EN1BBrdQBGcYcmC0T7dwfHq9kStVvlYBfbs8K8gKf43QqtTDfg72FQyn+oDmyr rtZHHy3HO610IOKnHCd9mFM8uJGEFq5SFhu+RcOobYps3yRQpBGKtKwadAiz/AisEtUcqf2iV+o Tj9yBkA5cfLPXD+FGo1h0Jdc19sy+Z55MP5w46Y3YXE9mBROV4ZcO0ZIrpboxXiHFkTSLrG45+p ZUtbNn8lSa8YDX22qIYfAjviycLuYKx9UQcghTv28+iCQ5dezyl8nMSDeuqG23h0UrxBlhKWMUo cxaq0I65Z+DOpv5nCuZdCcb8uR X-Google-Smtp-Source: AGHT+IGcvlur8Vqc4wFxgxESgRnhWsQQrDI7/x3WxwuMsMU9z1qtT26y4pxkHScpmQTRAOTFgs7e9g== X-Received: by 2002:a05:600c:b96:b0:477:9fd6:7a53 with SMTP id 5b1f17b1804b1-477c2ef91demr217790445e9.2.1764657590643; Mon, 01 Dec 2025 22:39:50 -0800 (PST) Received: from localhost.localdomain ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d15fb1430csm15702796b3a.59.2025.12.01.22.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 22:39:49 -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 RESEND v4 2/2] ocfs2: detect released suballocator BG for fh_to_[dentry|parent] Date: Tue, 2 Dec 2025 14:39:35 +0800 Message-ID: <20251202063938.9046-3-heming.zhao@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251202063938.9046-1-heming.zhao@suse.com> References: <20251202063938.9046-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: 8bit 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 = ocfs2_test_bit //unlink was called, and the bit is zero | + if (!set) //because the above *res is 0 status = -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/suballoc.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index de2f09217142..a126d83ddb1c 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 = NULL; u64 bg_blkno; - int status; + int status, quiet = 0, released; trace_ocfs2_test_suballoc_bit((unsigned long long)blkno, (unsigned int)bit); @@ -3168,11 +3168,15 @@ static int ocfs2_test_suballoc_bit(struct ocfs2_super *osb, bg_blkno = group_blkno ? group_blkno : ocfs2_which_suballoc_group(blkno, bit); - status = ocfs2_read_group_descriptor(suballoc, alloc_di, bg_blkno, - &group_bh); - if (status < 0) { + status = ocfs2_read_hint_group_descriptor(suballoc, alloc_di, bg_blkno, + &group_bh, &released); + if (released) { + quiet = 1; + status = -EINVAL; + 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; } @@ -3182,7 +3186,7 @@ static int ocfs2_test_suballoc_bit(struct ocfs2_super *osb, bail: brelse(group_bh); - 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 = 0; u64 group_blkno = 0; u16 suballoc_bit = 0, suballoc_slot = 0; struct inode *inode_alloc_inode; @@ -3244,8 +3248,12 @@ int ocfs2_test_inode_bit(struct ocfs2_super *osb, u64 blkno, int *res) status = 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 == -EINVAL) + quiet = 1; + else + mlog(ML_ERROR, "test suballoc bit failed %d\n", status); + } 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; } -- 2.43.0