Skip to main content

Module raid56

Module raid56 

Source
Expand description

§RAID5 / RAID6 parity computation

Self-contained math for the parity stripes that btrfs’s RAID5 and RAID6 profiles require. Two functions:

  • compute_p: byte-wise XOR over the data stripes. Used by both RAID5 and RAID6 (the “P” stripe).
  • compute_p_q: XOR plus a Reed-Solomon code over GF(2^8) using the generator x^8 + x^4 + x^3 + x^2 + 1 (0x1D). Used by RAID6.

Inputs are equal-length byte slices (one per data column of a row). The output buffers are the same length and represent the parity columns of that row.

§GF(2^8) recipe (Q stripe)

Q is computed by walking the data stripes in order and accumulating q = mul2(q) ^ data_byte, where mul2 is multiplication by 2 in GF(2^8) with reduction by the polynomial 0x1D when the high bit is set. This matches the kernel’s raid6_call and produces the same byte sequence the on-disk format expects.

The two-times multiplication table is precomputed at first use via std::sync::OnceLock; the cost is 256 byte writes once per process.

Functions§

compute_p
Compute the RAID5/RAID6 P (XOR) stripe over data_stripes.
compute_p_q
Compute the RAID6 (P, Q) parity stripes over data_stripes.