[lvc-project] [PATCH 2/2] ocfs2: validate cl_bpc in allocator inodes to prevent divide-by-zero

Deepanshu Kartikey kartikey406 at gmail.com
Thu Oct 30 06:30:53 MSK 2025


Hi Joseph, Heming, and Dmitry,

Investigation complete. Here are the full test results:

**Test Setup:**
- Kernel: Custom build with cl_bpc validation patch
- Filesystems: Created with mkfs.ocfs2 -b [512|1024|2048|4096] -M
local --fs-features=metaecc

**Results:**

512-byte blocks (4KB cluster):
  inode=20: cl_bpc=8, expected=8 (cluster_bits=12, block_bits=9)  : PASS
  inode=23: cl_bpc=1, expected=8 (cluster_bits=12, block_bits=9) :FAIL
  → Validation detects corruption

1024-byte blocks (4KB cluster):
  inode=12: cl_bpc=4, expected=4 (cluster_bits=12, block_bits=10) :PASS
  inode=15: cl_bpc=1, expected=4 (cluster_bits=12, block_bits=10) :FAIL
  → Validation detects corruption

2048-byte blocks (4KB cluster):
  inode=10: cl_bpc=2, expected=2 (cluster_bits=12, block_bits=11) : PASS
  inode=13: cl_bpc=1, expected=2 (cluster_bits=12, block_bits=11): FAIL
  → Validation detects corruption

4096-byte blocks (4KB cluster):
  inode=8:  cl_bpc=1, expected=1 (cluster_bits=12, block_bits=12) : PASS
  inode=11: cl_bpc=1, expected=1 (cluster_bits=12, block_bits=12) :PASS
  → All inodes correct, mount succeeds

**Analysis:**

1. The validation calculates expected cl_bpc as:
   expected_bpc = 1 << (cluster_size_bits - block_size_bits)

   This matches the mkfs.ocfs2 source code you referenced:
   di->id2.i_chain.cl_bpc = s->cluster_size / s->blocksize

2. For non-4K block sizes, some allocator inodes (20, 12, 10, 8) have
   correct cl_bpc values, while others (23, 15, 13) consistently have
   cl_bpc=1.

3. For 4K blocks, all allocator inodes have the correct value (1).

The improved error message now includes:
  "Inode %llu has corrupted cl_bpc: ondisk=%u expected=%u
   (cluster_size_bits=%u block_size_bits=%u)"

Please advise on next steps.

Thanks,
Deepanshu



More information about the lvc-project mailing list