[lvc-project] [PATCH 2/2] ocfs2: validate cl_bpc in allocator inodes to prevent divide-by-zero
Heming Zhao
heming.zhao at suse.com
Thu Oct 30 07:22:34 MSK 2025
On Thu, Oct 30, 2025 at 09:25:12AM +0530, Deepanshu Kartikey wrote:
> Hi Joseph,
>
> Thank you for identifying this! You're absolutely right.
>
> I see now that cluster bitmap allocators (like global_bitmap at inode 23)
> are intentionally set to cl_bpc=1 by mkfs.ocfs2, as they track clusters
> rather than blocks.
>
> I need to update my validation to skip cluster bitmap allocators.
>
> Looking at the code, I'm considering something like:
>
> if (le32_to_cpu(di->i_flags) & OCFS2_CLUSTER_FL) {
> // This is a cluster bitmap, cl_bpc=1 is correct by design
> goto skip_bpc_check;
> }
>
> However, I want to confirm: is OCFS2_CLUSTER_FL the correct flag to check,
> or should I use a different method to identify cluster bitmap allocators
> versus inode allocators?
>
> Thanks,
> Deepanshu
ocfs2 doesn't define OCFS2_CLUSTER_FL.
I used hexdump to check an ocfs2 volume. the di->i_flags is the same
for //global_bitmap and //global_inode_alloc.
the value is 0x491:
- OCFS2_CHAIN_FL | OCFS2_BITMAP_FL | OCFS2_SYSTEM_FL | OCFS2_VALID_FL
One way I considered uses the inode block number to bypass global_bitmap.
the code seems ugly (demo):
```
osb = OCFS2_SB(sb);
inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE, OCFS2_INVALID_SLOT)
if (OCFS2_I(inode)->ip_blkno != le64_to_cpu(fe->i_blkno))
goto by_pass_the_check;
```
- Heming
More information about the lvc-project
mailing list