Viewing: ec.txt

			**************************************
			* Overview of Erasure Coding support *
			**************************************

Contents
1. Introduction
        1.1 Definitions
2. Command interface
        2.1 lfs setstripe
                2.1.1 raid set aware stripe allocation
        2.2 lfs getstripe
                2.2.1 EC raidset map
        2.3 lfs mirror resync
        2.4 lfs mirror verify
3. Stripe Layout


1. Introduction
===============
Erasure coding support in Lustre will be added in several phases.
This document describes the support in phase 0.

The implementation of EC is similar in concept to RAID-4 where these OST
objects used in a layout are divided into two separate cases;
mirrors containing OST objects holding file data, just like
existing files use RAID-0 acreoss objects in Lustre, but using a new type of
mirror containing OST objects holding parity data.

This new type of mirrors are indicated in the code by the flag
LCME_FL_PARITY and in userland indicated by the flag "parity" in the
lfs getstripe output.
Unlike other mirror types, this type of mirror does not contain
file data but instead contain parity stripes.

In this phase parity data will be manually updated after a file has
changed.
When the file is modified, any affected parity mirror will be flagged as
"stale" and the user is required to manually initiate a resync
to recompute the parities and make the parity mirror valid again.
This behavior will be improved upon in later phases.

1.1 Definitions
---------------
Stripe set:
    These are the stripes defined for the data comp.
    The number of stripes in a stripe set is data_comp->llc_stripe_count.
    Stripe sets are repeated, one after the other, until the end of the
    comp.
    Each repetition of a stripe set is called a row and contains
    'stripe_count * stripe_size = stripe_width' data bytes.
Raid set:
    The stripe set is split into smaller groups over which ec parities
    are computed.
    This is the raid set.
    The raid set covers a specific range of each row.
    A raid set covers the same range for every row.
    The stripe set is split into raid sets so that there will be
      c0 number of raid sets with k0 stripes each and
      c1 number of raid sets with k1 stripes each.
      k1 == k0 - 1
      c1 may be 0 if the stripe_count can be evenly divided by k0.
Raid stride:
    For a raid set, this is the nubmer of stripes from one row in a raid
    set until the next row for that raid set.
    The raid stride is the same for all raid sets in a comp.
    The raid stride is data_comp->llc_stripe_count.
Parity stride:
    Offset from one stripe set to the next in the parity mirror offset
    space. That is raidset_count * stripe_size (one stripe_size per
    raid set in the stripe set), which is stripe_width() for a parity
    entry. On a given parity object, consecutive stripe sets are one
    stripe_size apart. The parity component has raidset_count * p
    OST objects.


2. Command interface
====================
The command line API to manage erasure coding for files is via the
lfs mirror command.
This command can be used to set and view the erasure coding configuration
for a file. This command can also be used to resync a stale ec mirror and
recompute the parity stripes or to verify that the ec parity mirrors match
the content of the file data.


2.1 lfs setstripe
-----------------
Setstripe is used to create EC mirror for a device.

Example:
Create a file layout using 8 stripes for the data mirror and using
4+2 for the erasure code protection.

4 means we want to split the number of data stripes (8 in this case)
into smaller raid-sets of 4, or fewer, data stripes.

+2 means that we want 2 parity stripes for each raid set.

As 8 data stripes can be evenly divided by 4 (preferred raid set data size)
this will result in set of 8 data stripes will be protected as
2 groups of 4 data stripes each protected by 2 parity stripes.

  $ lfs setstripe -E -1 -S 4M -c 8 --ec 4+2 /mnt/lustre/sahlberg/file


2.1.1 raid set aware stripe allocation
-------------------------------------
For raid set aware data stripe allocation we always try to allocate the
requested number of OSTs in the -c n or -C n argument.
In the latter case, overstriping,  we allow the same OST to be used
multiple times in the stripeset as long as the OST is not reused within
the same raid set.
If there are not enough OSTs for the full request we will still allow it as
long as we have at least 75% of the requested amount.


Stripe allocation for the ec mirror
-----------------------------------
For the EC component we require one OST object per parity and raid set.
If there are not enough unique OSTs for the parity stripes
then OSTs selected for the data component will be reused as long
as they are from a different raid set.


Examples:

6 OSTs: -c 6 --ec 3+1
---------------------
/mnt/l/sahlberg/file
  lcm_layout_gen:    2
  lcm_mirror_count:  2
  lcm_entry_count:   2
    lcme_id:             65537
    lcme_mirror_id:      1
    lcme_flags:          init
    lcme_extent.e_start: 0
    lcme_extent.e_end:   EOF
      lmm_stripe_count:  6
      lmm_stripe_size:   1048576
      lmm_pattern:       raid0
      lmm_layout_gen:    0
      lmm_stripe_offset: 0
      lmm_objects:
        -   0: { l_ost_idx:   0, l_fid: [0x240000400:0x1822:0x0] }
        -   1: { l_ost_idx:   1, l_fid: [0x280000400:0x1842:0x0] }
        -   2: { l_ost_idx:   2, l_fid: [0x2c0000400:0x1882:0x0] }
        -   3: { l_ost_idx:   3, l_fid: [0x300000400:0x1882:0x0] }
        -   4: { l_ost_idx:  10, l_fid: [0x440000400:0x1722:0x0] }
        -   5: { l_ost_idx:  11, l_fid: [0x480000400:0x1722:0x0] }
    lcme_id:             131074
    lcme_mirror_id:      2
    lcme_flags:          init,parity
    lcme_data_id:        1
    lcme_dstripe_count:  3
    lcme_cstripe_count:  1
    lcme_extent.e_start: 0
    lcme_extent.e_end:   EOF
      lmm_stripe_count:  2
      lmm_stripe_size:   1048576
      lmm_pattern:       parity
      lmm_layout_gen:    0
      lmm_stripe_offset: 3
      lmm_objects:
        -   0: { l_ost_idx:   3, l_fid: [0x300000400:0x1883:0x0] }
        -   1: { l_ost_idx:   0, l_fid: [0x240000400:0x1823:0x0] }


6 OSTs: -C 16 --ec 4+2
---------------------
4 data objects per raid set with only 6 OSTs, so the two parity
objects for each raid set must always be selected from the OSTs
that are not used for data.

  lcm_layout_gen:    2
  lcm_mirror_count:  2
  lcm_entry_count:   2
    lcme_id:             65537
    lcme_mirror_id:      1
    lcme_flags:          init
    lcme_extent.e_start: 0
    lcme_extent.e_end:   EOF
      lmm_stripe_count:  16
      lmm_stripe_size:   1048576
      lmm_pattern:       raid0
      lmm_layout_gen:    0
      lmm_stripe_offset: 0
      lmm_objects:
        -   0: { l_ost_idx:   0, l_fid: [0x240000400:0x2324:0x0] }
        -   1: { l_ost_idx:   1, l_fid: [0x280000400:0x23c4:0x0] }
        -   2: { l_ost_idx:   2, l_fid: [0x2c0000400:0x2384:0x0] }
        -   3: { l_ost_idx:   3, l_fid: [0x300000400:0x23c4:0x0] }
        -   4: { l_ost_idx:  10, l_fid: [0x440000400:0x2264:0x0] }
        -   5: { l_ost_idx:  11, l_fid: [0x480000400:0x2264:0x0] }
        -   6: { l_ost_idx:   0, l_fid: [0x240000400:0x2325:0x0] }
        -   7: { l_ost_idx:   1, l_fid: [0x280000400:0x23c5:0x0] }
        -   8: { l_ost_idx:   2, l_fid: [0x2c0000400:0x2385:0x0] }
        -   9: { l_ost_idx:   3, l_fid: [0x300000400:0x23c5:0x0] }
        -  10: { l_ost_idx:  10, l_fid: [0x440000400:0x2265:0x0] }
        -  11: { l_ost_idx:  11, l_fid: [0x480000400:0x2265:0x0] }
        -  12: { l_ost_idx:   0, l_fid: [0x240000400:0x2326:0x0] }
        -  13: { l_ost_idx:   1, l_fid: [0x280000400:0x23c6:0x0] }
        -  14: { l_ost_idx:   2, l_fid: [0x2c0000400:0x2386:0x0] }
        -  15: { l_ost_idx:   3, l_fid: [0x300000400:0x23c6:0x0] }
    lcme_id:             131074
    lcme_mirror_id:      2
    lcme_flags:          init,parity
    lcme_data_id:        0x1
    lcme_dstripe_count:  4
    lcme_cstripe_count:  2
    lcme_extent.e_start: 0
    lcme_extent.e_end:   EOF
      lmm_stripe_count:  8
      lmm_stripe_size:   1048576
      lmm_pattern:       parity
      lmm_layout_gen:    0
      lmm_stripe_offset: 10
      lmm_objects:
        -   0: { l_ost_idx:  10, l_fid: [0x440000400:0x2266:0x0] }
        -   1: { l_ost_idx:  11, l_fid: [0x480000400:0x2266:0x0] }
        -   2: { l_ost_idx:   2, l_fid: [0x2c0000400:0x2387:0x0] }
        -   3: { l_ost_idx:   3, l_fid: [0x300000400:0x23c7:0x0] }
        -   4: { l_ost_idx:   0, l_fid: [0x240000400:0x2327:0x0] }
        -   5: { l_ost_idx:   1, l_fid: [0x280000400:0x23c7:0x0] }
        -   6: { l_ost_idx:  10, l_fid: [0x440000400:0x2267:0x0] }
        -   7: { l_ost_idx:  11, l_fid: [0x480000400:0x2267:0x0] }


2.2 lfs getstripe
-----------------
Getstripe is used to view the layout for a file, including the ec
mirrors, if any.

The following example has file containing two mirrors,
one data mirror with 8 stripes and one parity mirror.

  $ lfs getstripe /mnt/lustre/sahlberg/file

  lcm_layout_gen:    5
  lcm_mirror_count:  2
  lcm_entry_count:   2
  lcme_id:             65537
  lcme_mirror_id:      1
  lcme_flags:          init
  lcme_extent.e_start: 0
  lcme_extent.e_end:   EOF
    lmm_stripe_count:  8
    lmm_stripe_size:   1048576
    lmm_pattern:       raid0
    lmm_layout_gen:    0
    lmm_stripe_offset: 1
    lmm_objects:
    -   0: { l_ost_idx:   1, l_fid: [0x2c0000400:0x2:0x0] }
    -   1: { l_ost_idx:   2, l_fid: [0x280000400:0x2:0x0] }
    -   2: { l_ost_idx:   3, l_fid: [0x300000400:0x2:0x0] }
    -   3: { l_ost_idx:   4, l_fid: [0x340000400:0x2:0x0] }
    -   4: { l_ost_idx:   5, l_fid: [0x380000400:0x2:0x0] }
    -   5: { l_ost_idx:   6, l_fid: [0x3c0000400:0x2:0x0] }
    -   6: { l_ost_idx:   7, l_fid: [0x400000400:0x2:0x0] }
    -   7: { l_ost_idx:   0, l_fid: [0x240000400:0x2:0x0] }

  lcme_id:             131074
  lcme_mirror_id:      2
  lcme_flags:          init,stale,parity
  lcme_data_id:        1
  lcme_dstripe_count:  4
  lcme_cstripe_count:  2
  lcme_extent.e_start: 0
  lcme_extent.e_end:   EOF
    lmm_stripe_count:  4
    lmm_stripe_size:   1048576
    lmm_pattern:       parity
    lmm_layout_gen:    0
    lmm_stripe_offset: 2
    lmm_objects:
    -   0: { l_ost_idx:   8, l_fid: [0x440000400:0x3:0x0] }
    -   1: { l_ost_idx:   9, l_fid: [0x480000400:0x3:0x0] }
    -   2: { l_ost_idx:  10, l_fid: [0x4c0000400:0x3:0x0] }
    -   3: { l_ost_idx:  11, l_fid: [0x500000400:0x3:0x0] }

lcme_dstripe_count     4
  is the preferred number of data stripes in each raid group.
  The actual number of data stripes used may be less than this.

lcme_cstripe_count    2
  is the number of parities

lcme_data_id         0x01
  is the mirror id of the data mirror that this ec mirror protects.

lcme_flags:          init,stale,parity
  means that this is a parity mirror and that it is stale.
  A stale mirror can not be used to restore missing data.


2.2.1 EC raidset map
--------------------
The --ec-map option to getstripe prints the raidset mapping between a
parity component and its linked data component: which data stripes form
each raid set, and which parity stripes protect them.

Without -I, --ec-map prints the mapping for every parity component in
the file. Each section is labeled with lcme_id so the output stays
usable as YAML when multiple components are present. If the file has
no parity components, a warning is printed and stdout is left empty.
With -I, only the selected component is shown: if it is a parity
component the linked data component is used to build the map; if it
is a data component the linked parity is looked up and the same
raidset map is printed. A warning is printed if the linked
counterpart cannot be found.

If the linked data component exists but is not instantiated yet
(typical for later PFL components at create time), lcme_ec is still
printed with lcme_ec_raidset_count: 0 and lcme_ec_raidsets: [].

Example:
A file with 7 data stripes and EC 3+2 has uneven raid sets
(ec_data_count=3,2,2).

  $ lfs setstripe -E -1 -c 7 --ec 3+2 /mnt/lustre/sahlberg/file
  $ lfs getstripe --ec-map /mnt/lustre/sahlberg/file

  components:
  - lcme_id:             131074
    lcme_ec:             3+2
    lcme_ec_raidset_count: 3
    lcme_ec_raidsets:
      - 0: { ec_data_count: 3, data_stripes: "0-2", parity_stripes: "0-1" }
      - 1: { ec_data_count: 2, data_stripes: "3-4", parity_stripes: "2-3" }
      - 2: { ec_data_count: 2, data_stripes: "5-6", parity_stripes: "4-5" }

lcme_ec                 3+2
  is the configured EC geometry (same form as --ec DATA+PARITY).

lcme_ec_raidset_count    3
  is the number of raid sets the data stripe set is split into.

lcme_ec_raidsets
  lists each raid set with:
    ec_data_count   the number of data stripes in the raid set
    data_stripes    the range of data stripe indices in the raid set
    parity_stripes  the range of parity stripe indices in the parity
                    component for this raid set

The parity component also holds lcme_ec_version, the version of the
mapping between parity and data (the raid set split, the parity stripe
placement and the encoding matrix).  Version 1 is the mapping released
in 2.18.0, and a parity written before the version existed (0) uses the
same mapping.  If the parity has a later version than lfs knows, no
raid sets are listed, since lfs would compute them wrongly:

    lcme_ec:             3+2
    lcme_ec_version:     2 (unknown)
    lcme_ec_raidset_count: 0
    lcme_ec_raidsets: []

Such a parity is not used to reconstruct data, it is left stale by
'lfs mirror resync', and 'lfs mirror verify' does not check it.


2.3 lfs mirror resync
---------------------
Resync is used to re-compute the parities for stale ec mirrors.

After a successful resync the parity mirror will no longer be flagged as
stale and it can be used to restore data if an OST is lost.

Example:
  $ lfs mirror resync /mnt/lustre/sahlberg/file


2.4 lfs mirror verify
---------------------
Verify is used to check and verify that the parity data matches the expected
value.

Example:
  $ lfs mirror verify /mnt/lustre/sahlberg/file


3. Stripe Layout
================
EC parity comps match to a single instance of a data mirror so that
we can guarantee that the set of OSTs used in the data mirror will not
overlap with the set of OSTs in the ec mirror.

An EC comp must span the same region of the file as its associated data
comp and thus the llc_extend.e_start and llc_extent.e_end must match
between the two. Additionally the EC comp and its data comp must also have
the same stripe size.

EC parity uses LOV_PATTERN_PARITY. The layout is like RAID10, in that it
has the same two axes:

  - Across the raid sets of one stripe set: like RAID0.
    The raid sets are striped through the parity mirror,
    one stripe size each.

  - Within one raid set: like RAID1.
    The raid set survives the loss of any p of its k + p
    stripes, as a RAID1 of p + 1 copies survives the loss of
    any p copies; with k == 1 each parity is a copy of the
    data and this is RAID1. The p parities protect the same
    data, so they share its offset (the same object_off).
    For k > 1 each one holds a different parity and a lost
    stripe is rebuilt from any k survivors, so a RAID1
    fan-out write would be wrong.

  ec_off(row, raidset) =
      O + (row - row of e_start) * (raidset_count * stripe_size)
	+ raidset * stripe_size

O is the parity origin, defined below; when e_start is a multiple of
the stripe width, O is e_start, except when every raid set has one data
stripe (see below). The parity index (0 .. p-1) selects
which object of the raid set is written, not the offset. raidset_count
is c0 + c1 (esc_n0 + esc_n1 from ec_split_stripes()), the number of
raid sets in one row.

The parity mirror is divided into stripe-size slots counted from O,
slot = (ec_off - O) / stripe_size. Each raid set uses one slot per row,
so slot % raidset_count is the raid set.

RAID0 places data rows from file offset 0, not from e_start, so the row
and the raid set of a data offset are taken from the absolute offset,
and rows are counted from the one holding e_start. In that row the raid
sets before the one holding e_start lie wholly before e_start, and the
raid set holding e_start may start before it. Data before e_start
belongs to no stripe of the component and is taken as zero.

Zero data has zero parity, which is not stored. O is the parity offset
of slot 0: e_start minus the parity space that the zero data before
e_start would take in the row of e_start:

  c      = data stripe count, ss = stripe size, W = c * ss
  j      = e_start / ss % c        stripe of e_start in its row
  s0     = raidset(j)              raid set of e_start
  first  = first stripe of s0 in the row
  ks     = stripes in s0 (k0 or k1)
  x0     = j == first + ks - 1 ? e_start % ss : 0
  O      = e_start - x0 - s0 * ss

raidset() maps a stripe in a row to its raid set (ec_stripe_to_raidset(),
see below). For a data offset off of the component:

  row0   = e_start / W              data row of slot 0
  ec_off = O + ((off / W - row0) * raidset_count
		+ raidset(off / ss % c)) * ss + off % ss

x0 is non-zero only when e_start is unaligned and in the last stripe of
its raid set. Then in every data stripe of that raid set, bytes
[0, x0) lie before e_start and are zero, so parity [0, x0) is zero too
and is skipped. When e_start is in an earlier stripe of its raid set,
the later stripes of that raid set hold data at [0, e_start % ss), so
that parity is needed and x0 is 0. With 1 raid set of 4 stripes and
ss = 1M:

  e_start = 1.5M, in stripe 1: x0 = 0, O = 1.5M
    byte in slot          0 ........ 512K ........ 1M
    stripe 0 [0, 1M)      | zero        | zero        |
    stripe 1 [1M, 2M)     | zero        | data        |
    stripe 2 [2M, 3M)     | data        | data        |
    stripe 3 [3M, 4M)     | data        | data        |

  e_start = 3.5M, in stripe 3, the last: x0 = 512K, O = 3M
    stripes 0 .. 2        | zero        | zero        |
    stripe 3 [3M, 4M)     | zero        | data        |

When every raid set has one data stripe (k == 1, i.e. 1+N, or c == 1)
there is one parity slot per data stripe and nothing to pack, so rows
count from file offset 0 instead of the row of e_start, and O is 0, as
for RAID0:

  ec_off = off

Each parity object then holds a copy of its data object at the same
object offsets, so it can stand in for the data object.

With several raid sets, e.g. -E 4M -c 1 -E eof -S 1M -c 8 --ec 4+1:
the second component has e_start = 4M, c = 8, ss = 1M and 2 raid sets
of 4 stripes. Offset 4M is stripe j = 4, the first stripe of raid set 1,
so x0 = 0 and O = 4M - 1 * 1M = 3M:

  slot 0  [3M, 4M)   raid set 0, row 0, data [0, 4M), before e_start
  slot 1  [4M, 5M)   raid set 1, row 0, data [4M, 8M)
  slot 2  [5M, 6M)   raid set 0, row 1, data [8M, 12M)

Slots and bytes in [O, e_start) are never written; reads of the parity
object there return zero, as the data before e_start does. That range
is in the extents of earlier components, so resync and verify leave
it alone, and lfs mirror read dumps the first slot from e_start.

The parity of a component fits in [e_start, e_end) when any of these
holds (ec_parity_fits()):

  - e_start is a multiple of ss: the slot of e_start starts at e_start.
  - e_start is in the last stripe of its raid set, which includes every
    single-stripe component: x0 trims the slot of e_start, so the
    parity fits however short the component is.
  - the component is at least one stripe long, e_end >= e_start + ss,
    or ends at LUSTRE_EOF.

Then every stored parity byte protects at least one data byte of the
component, and a row of parity (raidset_count * ss) is never wider than
a row of data (c * ss), so the parity ends by e_end. Common DoM and PFL
layouts fit (--ec applies to every component):

  -E 64K -L mdt -E 1M -c 1 -S 1M -E eof -c 4 -S 4M --ec 4+2
  -E 1M -c 1 -S 1M -E 64M -c 1 -S 4M -E eof -c 4 -S 4M --ec 4+2

[64K, 1M) and [1M, 64M) have a single data stripe: x0 = e_start % ss,
O = 0, and the parity is kept in [e_start, e_end). This is the --ec 1+N
case, where ec_off is the data offset itself, as in a FLR mirror. The
eof components end at LUSTRE_EOF.

The only layout where none of these holds is a component shorter than
one stripe (e_end < e_start + ss) whose raid set continues past e_end, so
its later stripes are never reached. All the data of such a component
is in one stripe, so striping it over several OSTs gains nothing, and
it has no room for a full stripe-size parity slot from e_start. Such a
layout is refused. For example [64K, 1M) with -S 1M -c 2 --ec 2+2, one
raid set of 2 stripes:

  data    stripe 0 [0, 1M)     [0, 64K) zero, [64K, 1M) data
          stripe 1 [1M, 2M)    past e_end, never reached
  parity  slot 0 at O = 64K; byte x of the slot is byte x of each stripe
          [64K, 128K)          slot bytes [0, 64K), zero
          [128K, 1M + 64K)     slot bytes [64K, 1M), passes e_end = 1M

x0 is 0 because e_start is not in the last stripe of its raid set. O
depends only on e_start, not on e_end (see below), so the slot is not
moved back even though stripe 1 holds no data here. [1M, 4M) with
-S 4M -c 2 --ec 2+2 is refused the same way: slot 0 is [1M, 5M). The
same layouts with -c 1, or ending at least one stripe after e_start
(e.g. [64K, 2M), where slot 0 ends at 1M + 64K), fit.

ec_parity_fits() detects such a layout:
  - llapi_layout_sanity() refuses it with LSE_EC_PARITY_FIT when the
    layout is set, and lfs setstripe reports that error;
  - llapi_ec_check_comp_match() refuses to resync or verify it;
  - lod_comp_prep_create() on the MDS checks it again with the final
    data stripe count when the parity component is instantiated, also
    for lfs mirror extend --ec.

This mapping is part of the on-disk format: O depends only on e_start,
the data stripe count, k and the stripe size, all fixed once the
component is instantiated, and not on e_end. Changing it, or the split
of ec_split_stripes(), makes the parity of existing files invalid.
ec_parity_geom_init(), ec_data_to_parity() and ec_parity_to_data() in
lustre_user.h are its only implementation; the client caches O in
lsme_parity_origin.

ec_off is a position in the parity mirror, not a data-file offset:
a data row of stripe_count * stripe_size maps to
raidset_count * stripe_size of parity-mirror offsets, whatever p is,
while keeping the raid set structure visible for holes, SEEK, and
locking.

Limits: p <= k unless k == 1, k+p <= 256 and p <= 15. EC components
followed by extension space (SEL) are not tested.

As a special case, if there is only a single data stripe then we just store
a copy of the data as each parity instead of computing it,
just as if it was a normal mirror component of a single stripe.
A recovery read of such a raid set has to copy a surviving parity
instead of decoding it, as only parity 0 equals the data under the
Cauchy encode matrix.

The data stripe consist of llc_stripe_count number of stripes.
This might be a large number, much larger than what we want to compute the
erasure code data over, so we need to split it into smaller raid sets.

Example: we have a stripe set 11 data stripes:

 +-----------------+  \  <- file offset 0
 | Data stripe #0  |  |
 +-----------------+  |
 | Data stripe #1  |  |
 +-----------------+  |
 | Data stripe #2  |  |
 +-----------------+  |
 | Data stripe #3  |  |
 +-----------------+  |
 | Data stripe #4  |  |
 +-----------------+  |  Row #0 of the stripe set.
 | Data stripe #5  |  |
 +-----------------+  |
 | Data stripe #6  |  |
 +-----------------+  |
 | Data stripe #7  |  |
 +-----------------+  |
 | Data stripe #8  |  |
 +-----------------+  |
 | Data stripe #9  |  |
 +-----------------+  |
 | Data stripe #10 |  |
 +-----------------+  /
 ... Repeated until llc_extent.e_end.

Rows start at file offset 0; the component holds only the part of them
in [e_start, e_end).

Assume we want to use 4.2 erasure coding.
I.e. 2 parities for raid sets of at most 4 stripes each.

Each row is then split into smaller raid sets using the
function ec_split_stripes().
This splits into 2 x 4 stripes + 1 x 3 stripes, like this:
 +-----------------+  \  <- file offset 0
 | Data stripe #0  |  |
 +-----------------+  |
 | Data stripe #1  |  |
 +-----------------+  | RAID set #0, row #0
 | Data stripe #2  |  |
 +-----------------+  |
 | Data stripe #3  |  |
 +-----------------+  /

 +-----------------+  \
 | Data stripe #4  |  |
 +-----------------+  |
 | Data stripe #5  |  |
 +-----------------+  | RAID set #1, row #0
 | Data stripe #6  |  |
 +-----------------+  |
 | Data stripe #7  |  |
 +-----------------+  /

 +-----------------+  \
 | Data stripe #8  |  |
 +-----------------+  |
 | Data stripe #9  |  | RAID set #2, row #0
 +-----------------+  |
 | Data stripe #10 |  |
 +-----------------+  /

 +-----------------+  \  <- file offset: the raid stride * stripe size
 | Data stripe #11 |  |     (stripe_width)
 +-----------------+  |
 | Data stripe #12 |  |
 +-----------------+  | RAID set #0, row #1
 | Data stripe #13 |  |
 +-----------------+  |
 | Data stripe #14 |  |
 +-----------------+  /
 ...

For a given data stripe ds, counted from file offset 0, the row it
belongs to is:
  row = ds / data_comp->llc_stripe_count

and which raid set rs it belongs to is given by ec_stripe_to_raidset():
   stripe_in_row = ds % data_comp->llc_stripe_count
   if (stripe_in_row < c0 * k0)
      rs = stripe_in_row / k0
   else
      rs = c0 + (stripe_in_row - c0 * k0) / k1


For each RAID set 2 parities are computed. Within the raid set the two
parities share one offset (RAID1-like) but hold different data, and
consecutive raid sets are one stripe size apart (RAID0-like), so the ec
comp is laid out as this (ss is the stripe size):

  offset            objects at that offset
  O + 0*ss          [Parity #0] [Parity #1]   RAID set #0, row #0
  O + 1*ss          [Parity #0] [Parity #1]   RAID set #1, row #0
  O + 2*ss          [Parity #0] [Parity #1]   RAID set #2, row #0
  O + 3*ss          [Parity #0] [Parity #1]   RAID set #0, row #1
  ...

Rows are counted here from the row of e_start (from row 0 when every
raid set has one data stripe). The slots in [O, e_start) are never
written (see above).

This uses 6 OST objects: 2 for each of the 3 RAID sets. Each pair is on
different OSTs from the other pairs, and from the data stripes they
protect. This ensures that the data and parity stripes will always be on
different OSTs, regardless of the RAID geometry used by each file.

 parity-offset = O + (row - row0) * raidset-count *
                 stripe-size + raid-set * stripe-size
 parity-object = raid-set * number-of-parities
                 + parity


If there is a hole that spans the entire raid set then we can skip
computing the parities and leave it as a hole in the ec comp as well.
Example, assume there is a hole spanning the entire RAID set #1 above.
Both of its parities live at one offset, so this leaves a single stripe
size hole:
 +---------------------------+      <- mirror offset: O
 | RAID set #0: Parity #0/#1 |      (2 objects at this offset)
 +---------------------------+
 |           hole            | No data in RAID set #1 so
 |                           | no need to store the parities either.
 +---------------------------+
 | RAID set #2: Parity #0/#1 |
 +---------------------------+
 |    hole until e_end       |
 ...

The extent offsets matches between the EC comp and the data comp
it protects.

Computations are done on whole stripes at a time.
We compute the parities for a full raid set at a time.

There is no guarantee that the raid set will be fully populated.
We could for example reach the end of the extent (llc_extent.e_end)
partially through the raid set, or we could reach EOF.
In both cases we pad the remainder of the raid set with 0 when we compute
the parity.

Example: the extent ends partway through the second stripe in raid set #2:
The raid set is padded with 0 so that we have a full set of stripes to
compute the parities over.
 +------------------------+  \
 |     Data stripe #8     |  |
 +------------------------+  |
 | Data stripe #9 | 00000 |  | RAID set #2
 +------------------------+  |
 | 0000000000000000000000 |  |
 +------------------------+  /